This repository has been archived by the owner on Nov 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathajax.php
76 lines (53 loc) · 2.26 KB
/
ajax.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
<?php
require_once("includes/bootstrap.php");
if ($login_ok === false) {
header('HTTP/1.1 403 forbidden');
exit;
}
global $db, $db_tb_incomings;
$action = getVar('action');
if ($action === 'getIncomings') {
getIncomings((int)getVar('timestamp'));
} elseif ($action === 'setSaved') {
if (getVar('state') === 'true') {
$saved = 1;
} else {
$saved = 0;
}
$coords = $db->escape(getVar('coords'));
$result = $db->db_update($db_tb_incomings, array('saved' => $saved, 'savedUpdateTime' => CURRENT_UNIX_TIME ), "WHERE koords_to = '$coords'");
if ($result === true) {
include('ajax/getIncomingsTables.php');
echo json_encode(array('result' => 'success', 'time' => CURRENT_UNIX_TIME, 'tables' => getIncomingsTables()));
}
} elseif ($action === 'setRecalled') {
if (getVar('state') === 'true') {
$recalled = 1;
} else {
$recalled = 0;
}
$coords = $db->escape(getVar('coords'));
$result = $db->db_update($db_tb_incomings, array('recalled' => $recalled, 'recalledUpdateTime' => CURRENT_UNIX_TIME), "WHERE koords_to = '$coords'");
if ($result === true) {
include('ajax/getIncomingsTables.php');
echo json_encode(array('result' => 'success', 'time' => CURRENT_UNIX_TIME, 'tables' => getIncomingsTables()));
}
} elseif ($action === 'getOnlineUsers') {
include('ajax/getOnlineUsers.php');
echo json_encode(array('result' => 'success', 'time' => CURRENT_UNIX_TIME, 'data' => getOnlineUsers()));
}
function getIncomings($timestamp)
{
global $db, $db_tb_incomings;
$sql = "SELECT COUNT(*) AS newEntries FROM `{$db_tb_incomings}` WHERE (`listedtime`>{$timestamp} OR `savedUpdateTime`>{$timestamp} OR `recalledUpdateTime`>{$timestamp}) ORDER BY `arrivaltime` ASC";
$result = $db->db_query($sql)
or error(GENERAL_ERROR, 'Could not query incomings information.', '', __FILE__, __LINE__, $sql);
$row = $db->db_fetch_array($result);
if (empty($row['newEntries'])) {
//es sind keine aktuelleren Einträge da
header('HTTP/1.1 304 Not Modified');
} else {
include_once('ajax/getIncomingsTables.php');
echo json_encode(array('result' => 'success', 'time' => CURRENT_UNIX_TIME, 'tables' => getIncomingsTables()));
}
}