-
Notifications
You must be signed in to change notification settings - Fork 1
/
checkins.php
57 lines (52 loc) · 1.35 KB
/
checkins.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
<?
require_once('lib/accept.php');
$content_type = parse_accept_headers();
require_once('db-connect-string.php');
pg_connect($db_connect_string);
$res = pg_query('SELECT COUNT(*) AS count, a.date FROM (SELECT DISTINCT account, date::DATE FROM checkins ORDER BY date ASC) a GROUP BY a.date ORDER BY a.date');
$entries = array();
while ($row = pg_fetch_assoc($res))
$entries[] = $row;
if ($content_type == 'text/html')
{
header("Content-Type: $content_type; charset=utf-8");
?>
<!DOCTYPE html>
<title>p2k12 accounts</title>
<style>
body { font-family: sans-serif; }
table { border-spacing: 0; border-collapse: collapse; }
th { text-align: left; background: #eee; }
th, td { border: 1px solid #ccc; padding: 2px 10px; white-space: nowrap; }
td { text-align: right; }
</style>
<p>Check-ins became mandatory at 2012-04-19.</p>
<table>
<?
foreach ($entries as $row)
{
if ($row['date'] == '2012-04-19')
{
?>
<tr>
<td colspan='2' style='border-top:2px solid black; padding: 0;'>
<?
}
?>
<tr>
<td><?=$row['date']?>
<td><?=$row['count']?>
<?
}
}
else if ($content_type == 'application/json')
{
header("Content-Type: $content_type; charset=utf-8");
echo json_encode($entries);
}
else
{
header('HTTP/1.1 406 Not Acceptable');
header("Content-Type: text/plain; charset=utf-8");
echo "No acceptable content types supported.\n";
}