-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbarcodeAccess.php
51 lines (39 loc) · 1.23 KB
/
barcodeAccess.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
<?php
require('api.php');
$user = $GLOBALS['user'];
$orderId = $_POST['orderId'];
$timeShown = $_POST['timeShown'];
if (!isset($orderId) || !isset($timeShown)) {
result(false, "Not the correct stuff inputted");
exit();
}
if ($user == null) {
result(false, "Not logged into a delivery account");
exit();
}
if ($user->deliverer == 0) {
result(false, "Not on a delivery account");
exit();
}
$delivererId = $user->id;
$db = new db();
$stmt = $db->prepare("SELECT COUNT(id) as count FROM `Orders` WHERE id=? AND deliverer=?");
$stmt->bind_param("ii", $orderId, $delivererId);
$db->exec();
$results = $db->get();
if ($results->fetch_assoc()['count'] == 0) {
result(false, "Not an order");
exit();
}
$stmt = $db->prepare("INSERT INTO `BarcodeUsage` (`id`, `order_id`, `time_shown`, `time_occurred`) VALUES (NULL, ?, ?, CURRENT_TIMESTAMP)");
$stmt->bind_param("ii", $orderId, $timeShown);
$db->exec();
$stmt = $db->prepare("SELECT count(id) as count from `BarcodeUsage` WHERE order_id?");
$stmt->bind_param("i",$orderId);
$db->exec();
$result = $db->get();
if ($result->fetch_assoc()['count'] >= 2) {
sendMessage("Message from server: Your barcode was used more than once", $orderId, $delivererId);
}
echo result(true);
?>