-
Notifications
You must be signed in to change notification settings - Fork 1
/
notifications.php
41 lines (39 loc) · 1.05 KB
/
notifications.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
<?php
require_once 'config.php';
require_once 'functions.php';
session_assert_valid();
$dbh = db_connect();
$method = $_SERVER['REQUEST_METHOD'];
if ($method == 'POST') {
$sth = $dbh->prepare('INSERT INTO notifications
(message, priority, location)
VALUES (?, ?, ?)');
$sth->execute(array(
$_REQUEST['message'],
$_REQUEST['priority'],
$_REQUEST['location']
));
} elseif ($method == 'GET') {
ignore_user_abort(false);
$sql = 'SELECT MAX(datetime) FROM notifications';
$sth = $dbh->prepare($sql);
$sth->execute();
$old = $sth->fetchColumn();
$sth->closeCursor();
$last = $old;
while ($last == $old) {
usleep(1000);
$sth->execute();
$last = $sth->fetchColumn();
$sth->closeCursor();
}
$sth = $dbh->prepare('SELECT * FROM notifications
WHERE isunread = true AND datetime > ?
ORDER BY datetime');
$sth->execute(array($old));
while ($row = $sth->fetch(PDO::FETCH_ASSOC)) {
print_r($row);
}
$sth->closeCursor();
}
?>