This repository has been archived by the owner on Nov 28, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
rfid-checkin.php
57 lines (54 loc) · 1.8 KB
/
rfid-checkin.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
<?php
header("content-type:text/plain");
include('adodb/adodb.inc.php');
$db = NewADOConnection('mysql');
$db->Connect("10.0.0.5", "checkin", "weeeeee", "rfidcheckin");
if (!$db) {
header("Internal Server Error", true, 500);
echo "Failed to connect to MySQL.\n";
exit;
}
if(array_key_exists('id',$_GET) and strlen($_GET['id']) == 12 ) {
if(
$db->Execute(
"INSERT INTO log (timestamp,id) values(NOW(),?)",
array($_GET['id'])
) !== false
) {
$res = $db->Execute("select dayofyear(timestamp) as day, id from log where dayofyear(timestamp) = dayofyear(now()) group by id;");
header("OK", true, 200);
print $res->RecordCount();
} else {
header("Internal Server Error", true, 500);
print "Error inserting checkin to database";
}
} else if(array_key_exists('report',$_GET)) {
switch( $_GET['report'] ) {
case 'daily':
$res = $db->Execute("select date(timestamp) as day, id from log where dayofyear(timestamp) >= dayofyear(now()) - 30 group by dayofyear(timestamp), id;");
if( ! $res ) {
print $db->ErrorMsg();
die();
}
while( $row = $res->FetchRow() ) {
$data[$row['day']]++;
}
print json_encode($data);
print "\n";
break;
case 'last':
$res = $db->Execute("select id from log order by timestamp DESC limit 1;");
if( ! $res ) {
print $db->ErrorMsg();
die();
}
while( $row = $res->FetchRow() ) {
print json_encode(array('last_id_seen' => $row['id']));
}
print "\n";
break;
}
} else {
header("Bad Request", true, 400);
print "Error invalid request";
}