-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandleNotification.php
115 lines (105 loc) · 3.87 KB
/
handleNotification.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php
session_start();
$uid = $_SESSION["uid"];
require 'database.php';
require "generalNotificationFuncs.php";
$nid = $_POST["nid"];
$nType = $_POST["nType"];
$nReply = $_POST["nReply"];
$bid = $_POST["bid"];
$gid = $_POST["gid"];
$suid = $_POST["suid"];
if (!empty($nid)) {
$db = new Database();
if (!empty($nType)) {
switch ($nType) {
case 2: //Group Invite
$ownerID = getGroupOwner($db, $gid);
if($nReply != 0) {
$stmt = $db->prepare("INSERT INTO groupUserRel(userID, groupID) VALUES(:uid, :gid)");
$stmt->bindValue(":uid", $uid, SQLITE3_INTEGER);
$stmt->bindValue(":gid", $gid, SQLITE3_INTEGER);
$stmt->execute();
//Build Notifications
$stmt = $db->prepare("INSERT INTO notifications(userID, typeID) VALUES(:oid, 3)");
} else {
//Invite Rejected, tell owner
$stmt = $db->prepare("INSERT INTO notifications(userID, typeID) VALUES(:oid, 16)");
}
$stmt->bindValue(":oid", $ownerID, SQLITE3_INTEGER);
$stmt->execute();
$liid = $db->lastInsertRowID();
notiLumpGroup($db, $liid, $gid);
notiLumpUser($db, $liid, $uid);
break;
case 7: //Contribution Invite
$ownerID = getBillOwner($db, $bid);
if ($nReply != 0) {
$stmt = $db->prepare("INSERT INTO billContributors(billID, userID)
VALUES(:bid, :uid)");
$stmt->bindValue(":bid", $bid, SQLITE3_INTEGER);
$stmt->bindValue(":uid", $uid, SQLITE3_INTEGER);
$stmt->execute();
//Build Notifications
$stmt = $db->prepare("INSERT INTO notifications(userID, typeID) VALUES(:oid, 3)");
} else {
//Invite Rejected, tell the owner.
$stmt = $db->prepare("INSERT INTO notifications(userID, typeID) VALUES(:oid, 16)");
}
$stmt->bindValue(":oid", $ownerID, SQLITE3_INTEGER);
$stmt->execute();
$liid = $db->lastInsertRowID();
notiLumpBill($db, $liid, $bid);
notiLumpUser($db, $liid, $uid);
break;
case 15: //Contribute As Group Invite
$ownerID = getBillOwner($db, $bid);
if ($nReply != 0) {
$stmt = $db->prepare("INSERT INTO billContributors(billID, userID, groupID)
VALUES(:bid, :uid, :gid)");
$stmt->bindValue(":bid", $bid, SQLITE3_INTEGER);
$stmt->bindValue(":uid", $uid, SQLITE3_INTEGER);
$stmt->bindValue(":gid", $gid, SQLITE3_INTEGER);
$stmt->execute();
//Build Notifications
$stmt = $db->prepare("INSERT INTO notifications(userID, typeID) VALUES(:oid, 3)");
} else {
//Invite Rejected, tell the owner.
$stmt = $db->prepare("INSERT INTO notifications(userID, typeID) VALUES(:oid, 16)");
}
$stmt->bindValue(":oid", $ownerID, SQLITE3_INTEGER);
$stmt->execute();
$liid = $db->lastInsertRowID();
notiLumpBill($db, $liid, $bid);
notiLumpUser($db, $liid, $uid);
notiLumpGroup($db, $liid, $gid);
break;
case 17: //Group Membership Requested
//This is the owner accepting/rejecting someone wanting to join
//Therefore $uid is the owner id, and $suid is who we need to target the end noti to.
if ($nReply != 0) {
$stmt = $db->prepare("INSERT INTO groupUserRel(userID, groupID) VALUES(:suid, :gid)");
$stmt->bindValue(":suid", $suid, SQLITE3_INTEGER);
$stmt->bindValue(":gid", $gid, SQLITE3_INTEGER);
$stmt->execute();
//Build Notifications.
$stmt = $db->prepare("INSERT INTO notifications(userID, typeID) VALUES(:suid, 3)");
} else {
//Tell suid that their request is rejetced.
$stmt = $db->prepare("INSERT INTO notifications(userID, typeID) VALUES(:suid, 16)");
}
$stmt->bindValue(":suid", $suid, SQLITE3_INTEGER);
$stmt->execute();
$liid = $db->lastInsertRowID();
notiLumpGroup($db, $liid, $gid);
break;
}
}
//Just mark as read.
$stmt = $db->prepare("UPDATE notifications SET checked = 1 WHERE notiID = :nid");
$stmt->bindValue(":nid", $nid, SQLITE3_INTEGER);
$stmt->execute();
exit();
}
?>
<?php include "wrongTurn.php"; ?>