-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathupdates.php
More file actions
49 lines (39 loc) · 1.47 KB
/
updates.php
File metadata and controls
49 lines (39 loc) · 1.47 KB
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
<?php
// ------------------------
// CHECK SERVER FOR UPDATES
// ------------------------
// UPDATE CHECK
// check database for new messages, friends, and debts
function update_check($user_id,$timestamp) {
global $db;
$result = array();
$result["new_friend"] = false;
$result["new_debt"] = false;
$result["new_message"] = false;
// check for any unconfirmed friends since timestamp
$statement = $db->prepare("SELECT timestamp FROM friends WHERE friend2 = ? AND confirmed = 1 AND timestamp > ?");
$statement->bind_param("ii",$user_id,$timestamp);
if ( $statement->execute() ) {
$statement->store_result();
if ( $statement->num_rows > 0 ) $result["new_friend"] = true;
}
$statement->close();
// check for any debts created since timestamp
$statement = $db->prepare("SELECT debt_id FROM debts WHERE (borrower_id = ? OR lender_id = ?) AND paid = false AND date > ?");
$statement->bind_param("iii",$user_id,$user_id,$timestamp);
if ( $statement->execute() ) {
$statement->store_result();
if ( $statement->num_rows > 0 ) $result["new_debt"] = true;
}
$statement->close();
// check for any unread messages since timestamp
$statement = $db->prepare("SELECT message_id FROM messages WHERE user_id = ? AND viewed = false AND date_created > ?");
$statement->bind_param("ii",$user_id,$timestamp);
if ( $statement->execute() ) {
$statement->store_result();
if ( $statement->num_rows > 0 ) $result["new_message"] = true;
}
$statement->close();
return $result;
}
?>