-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddGeneralContributor.php
77 lines (75 loc) · 2.33 KB
/
addGeneralContributor.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
<?php
require 'database.php';
require 'security.php';
require 'generalNotificationFuncs.php';
$username = h($_POST["name"]);
$bid = $_POST["bid"];
$gid = $_POST["gid"];
$exitEarly = false;
if (!empty($username)) {
$db = new Database();
$stmt = $db->prepare("SELECT userID FROM users WHERE username = :un");
$stmt->bindValue(":un", $username, SQLITE3_TEXT);
$result = $stmt->execute();
$temp = $result->fetchArray();
if ($temp) {
$uid = $temp["userID"];
$retArray['uid'] = $uid;
$stmt = $db->prepare("SELECT userID FROM billContributors
WHERE userID = :uid AND billID = :bid");
$stmt->bindValue(":uid", $uid, SQLITE3_INTEGER);
$stmt->bindValue(":bid", $bid, SQLITE3_INTEGER);
$result = $stmt->execute();
$temp = $result->fetchArray();
if (!$temp) {
//Check they haven't already been invited.
$retArray['already'] = 0;
$stmt = $db->prepare("SELECT * FROM notifications
INNER JOIN notiBill ON notifications.notiID = notiBill.notiID
WHERE userID = :uid AND billID = :bid AND typeID IN (7, 15)");
$stmt->bindValue(":uid", $uid, SQLITE3_INTEGER);
$stmt->bindValue(":bid", $bid, SQLITE3_INTEGER);
$result = $stmt->execute();
$temp = $result->fetchArray();
if (!$temp) {
$retArray['invited'] = 0;
if ($gid != 0) {
$stmt = $db->prepare("SELECT groupID FROM groups WHERE userID = :uid");
$stmt->bindValue(":uid", $uid, SQLITE3_INTEGER);
$result = $stmt->execute();
$found = false;
while($item = $result->fetchArray())
$found = $found || ($gid == $item["groupID"]);
if ($found) {
$retArray['groupFind'] = 1;
} else {
$retArray['groupFind'] = 0;
$exitEarly = true;
}
}
if (!$exitEarly) {
$stmt = $db->prepare("INSERT INTO notifications(userID, typeID) VALUES(:uid, :type)");
$stmt->bindValue(":uid", $uid, SQLITE3_INTEGER);
if ($gid != 0) $stmt->bindValue(":type", 15, SQLITE3_INTEGER);
else $stmt->bindValue(":type", 7, SQLITE3_INTEGER);
$stmt->execute();
$liid = $db->lastInsertRowID();
notiLumpBill($db, $liid, $bid);
if ($gid != 0)
notiLumpGroup($db, $liid, $gid);
}
} else {
$retArray['invited'] = 1;
}
} else {
$retArray['already'] = 1;
}
} else {
$retArray['uid'] = 0;
}
$output = json_encode($retArray);
echo $output;
exit();
}
?>
<?php include "wrongTurn.php"; ?>