-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.php
55 lines (49 loc) · 1.59 KB
/
index.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
<?php
require_once("mysql.inc.php");
# get requested report (defaults to all)
$date = false;
$date_start = "2011-05-02";
$date_end = "2011-05-28";
$report = "all";
if (!empty($_GET['report'])) {
$report = $_GET['report'];
if ($report == 'today') {
$date = date("Y-m-d", mktime());
} else if ( $report == 'week' ) {
$daysFromMonday = date("N", mktime()) - 1;
$monday = mktime() - ($daysFromMonday * 3600 * 24);
$date_start = date("Y-m-d", $monday);
$date_end = date("Y-m-d", $monday + (3600 * 24 * 6));
} else if ( $report == 'lastweek' ) {
$daysFromSunday = date("N", mktime());
$sunday = mktime() - ($daysFromSunday * 3600 * 24);
$date_end = date("Y-m-d", $sunday);
$date_start = date("Y-m-d", $sunday - ( 6 * 3600 * 24 ));
}
$date = strtotime($report);
}
if ($date) {
$date_start = date("Y-m-d",$date);
$date_end = date("Y-m-d",$date);
}
$stmt = $mysqli->prepare("SELECT author_github as author, count(ticket_id) as count FROM rewards_leaderboard WHERE closed_on >= ? and closed_on <= ? GROUP BY author_github ORDER BY count");
$stmt->bind_param("ss", $date_start, $date_end);
$stmt->execute() or die("Couldn't get data");
$stmt->bind_result($author, $count);
$commits = array();
while($stmt->fetch()) {
$commits[] = array('author'=>$author, 'count' => $count);
}
function count_cmp($a, $b)
{
if ($a['count'] == $b['count']) {
return 0;
}
return ($a['count'] < $b['count']) ? 1 : -1;
}
usort($commits, "count_cmp");
# return the proper output
header('Content-type: text/html');
# TODO: use a templating language (e.g. h2o) instead of
# hard-coding it in the php.
include('index.tmpl');