-
Notifications
You must be signed in to change notification settings - Fork 2
/
scanner.php
93 lines (79 loc) · 3.55 KB
/
scanner.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
require_once 'inc/standard.php';
$DB = $GLOBALS['DB'];
foreach ($_GET as $key => $value) {
//echo '$user[\''.$key.'\'] = '.$value.';<br>';
$scan[$key] = trim(strip_tags($value));
}
if($scan['barcode'] && $scan['eid'])
{
$barcode = new Barcode($scan['barcode']);
$scanner = new Scanner();
$event = new Event($scan['eid']);
$errors = 1;
if(!$event->exists())
{
$errors++;
$output['message']['text'] = 'This event does not exist';
$output['message']['status'] = 'error';
}
if(!$barcode->exists())
{
$errors++;
$output['message']['text'] = 'The barcode <strong>#'.$barcode->code.'</strong> does not exist. Try scanning again.';
$output['message']['status'] = 'error';
}
if($scanner->exists($barcode->code, $scan['eid']))
{
$errors++;
$form = '<form action="register.php" method="GET"><input type="text" name="ucinetid" placeholder="UCInetID"><input type="submit"></form>'; //todo associate barcode if the took one with out registering.
$name = ($barcode->getName()) ? 'The user <strong>'.$barcode->getName().'</strong>':'The barcode <strong>#'.$barcode->code.'</strong>';
$extra = ($barcode->getName()) ? 'Nice Try.':'Please register this user\'s UCInetID below: '.$form;
$output['message']['text'] = $name.' has already been scanned. '.$extra;
$output['message']['status'] = 'error';
}
if($scanner->alreadyExists($barcode->getUCInetID(), $scan['eid']))
{
$errors++;
$form = '<form action="register.php" method="GET"><input type="text" name="ucinetid" placeholder="UCInetID"><input type="submit"></form>'; //todo associate barcode if the took one with out registering.
$name = ($barcode->getUCInetID()) ? 'The user <strong>'.$barcode->getUCInetID().'</strong>':'The barcode <strong>#'.$barcode->code.'</strong>';
$extra = ($barcode->getUCInetID()) ? 'Nice Try.':'Please register this user\'s UCInetID below: '.$form;
$output['message']['text'] = $name.' has already been scanned. '.$extra;
$output['message']['status'] = 'error';
}
if($errors == 1)
{
$scanner->scan($barcode->code, $scan['eid'], $_SESSION['ucinetid']);
$form = '<form action="register.php" method="GET"><input type="text" name="ucinetid" placeholder="UCInetID"><input type="submit"></form>'; //todo associate barcode if they took one with out registering.
$name = ($barcode->getName()) ? 'The user <strong>'.$barcode->getName().'</strong>':'The barcode <strong>#'.$barcode->code.'</strong>';
$welcome = ($barcode->getName()) ? 'Welcome.':'Please register this user\'s UCInetID below: '.$form;
$output['message']['text'] = $name.' has been scanned in'.$welcome;
$output['message']['status'] = 'success';
$sql = 'SELECT scans.*, users.name, users.ucinetid, users.major, users.level
FROM scans LEFT JOIN users
ON scans.barcode = users.barcode
WHERE scans.eid = "'.$scan['eid'].'"
AND scans.barcode = "'.$scan['barcode'].'"
ORDER BY date DESC, time DESC';
$sql = 'SELECT barcodes.barcode, scans.*, users.name, users.ucinetid, users.major, users.level
FROM scans
LEFT JOIN barcodes
LEFT JOIN users
ON barcodes.ucinetid = users.ucinetid
ON barcodes.barcode = scans.barcode
WHERE scans.eid = "'.$scan['eid'].'"
AND scans.barcode = "'.$scan['barcode'].'"
ORDER BY scans.date DESC, scans.time DESC';
$DB->query($sql);
$output['scan'] = $DB->resultToArray();
}
unset($scanner);
unset($barcode);
unset($event);
}
else{
$output['message']['text'] = 'Must provide barcode id and event id';
$output['message']['status'] = 'error';
}
echo json_encode($output);
?>