-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddUserToGroup.php
78 lines (76 loc) · 2.61 KB
/
addUserToGroup.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
<?php
require 'security.php';
require 'database.php';
require 'generalNotificationFuncs.php';
$name = $_POST["name"];
$gid = $_POST["gid"];
$oid = $_POST["oid"];
if (!empty($name)) {
$db = new Database();
$stmt = $db->prepare("SELECT userID FROM users WHERE username = :un");
$stmt->bindValue(":un", $name, SQLITE3_TEXT);
$result = $stmt->execute();
$temp = $result->fetchArray();
if ($temp) {
$uid = $temp[0];
//Check user in group.
$stmt = $db->prepare("SELECT userID FROM groupUserRel WHERE userID = :uid AND groupID = :gid");
$stmt->bindValue(":uid", $uid, SQLITE3_INTEGER);
$stmt->bindValue(":gid", $gid, SQLITE3_INTEGER);
$result = $stmt->execute();
$temp = $result->fetchArray();
if (!$temp) {
$stmt = $db->prepare("SELECT * FROM notifications
INNER JOIN notiGroup USING(notiID)
WHERE userID = :uid AND groupID = :gid AND typeID = 2");
$stmt->bindValue(":uid", $uid, SQLITE3_INTEGER);
$stmt->bindValue(":gid", $gid, SQLITE3_INTEGER);
$result = $stmt->execute();
$temp = $result->fetchArray();
if (!$temp) {
//Check to see if the user has already requested to join.
$stmt = $db->prepare("SELECT notifications.notiID FROM notifications
INNER JOIN notiGroup USING(notiID)
WHERE userID = :oid AND groupID = :gid AND typeID = 17");
$stmt->bindValue(":oid", $oid, SQLITE3_INTEGER);
$stmt->bindValue(":gid", $gid, SQLITE3_INTEGER);
$result = $stmt->execute();
$temp = $result->fetchArray();
if($temp) {
//Mark that notification as read because we're dealing with it.
$stmt = $db->prepare("UPDATE notifications SET checked=1 WHERE notiID = :nid");
$stmt->bindValue(":nid", $temp[0], SQLITE3_INTEGER);
$stmt->execute();
//Then add to group.
$stmt = $db->prepare("INSERT INTO groupUserRel(groupID, userID) VALUES(:gid, :uid)");
$stmt->bindValue(":uid", $uid, SQLITE3_INTEGER);
$stmt->bindValue(":gid", $gid, SQLITE3_INTEGER);
$stmt->execute();
$stmt = $db->prepare("INSERT INTO notifications(userID, typeID) VALUES(:uid, 3)");
$stmt->bindValue(":uid", $uid, SQLITE3_INTEGER);
$stmt->execute();
$liid = $db->lastInsertRowID();
notiLumpGroup($db, $liid, $gid);
echo 2;
} else {
$stmt = $db->prepare("INSERT INTO notifications(userID, typeID) VALUES(:uid, 2)");
$stmt->bindValue(":uid", $uid, SQLITE3_INTEGER);
$stmt->execute();
$liid = $db->lastInsertRowID();
notiLumpGroup($db, $liid, $gid);
notiLumpUser($db, $liid, $oid);
echo 3;
}
} else {
echo 1;
}
} else {
echo 4;
}
} else {
echo 0;
}
exit();
}
?>
<?php include "wrongTurn.php"; ?>