forked from TravelMapping/Web
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstat.php
More file actions
127 lines (124 loc) · 4.61 KB
/
stat.php
File metadata and controls
127 lines (124 loc) · 4.61 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<?php
include $_SERVER['DOCUMENT_ROOT']."/login.php";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--
A rankings page.
URL Params:
u - the user, to show highlighting on page.
-->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" type="text/css" href="/css/travelMapping.css"/>
<!-- jQuery -->
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<!-- TableSorter -->
<script src="/lib/jquery.tablesorter.min.js"></script>
<title>Traveler Statistics</title>
<style type="text/css">
#rankingstable {
width: 33%;
float: left;
margin: auto;
}
</style>
</head>
<body>
<script type="text/javascript">
$(document).ready(function () {
$(".rankingstable").tablesorter({
sortList: [[0,0]],
headers: {0: {sorter: false}}
});
$('td').filter(function() {
return this.innerHTML.match(/^[0-9\s\.,%]+$/);
}).css('text-align','right');
});
</script>
<?php require $_SERVER['DOCUMENT_ROOT']."/lib/tmheader.php"; ?>
<h1>Traveler Statistics</h1>
<table style="margin: auto">
<tr><td>
<table class="gratable tablesorter" id="rankingstable">
<thead>
<tr><th colspan="5">Traveler Mileage in Active Systems</th></tr>
<tr><th class="sortable">Rank</th><th class="sortable">Username</th><th class="sortable">Miles Traveled</th><th class="sortable">%</th></tr>
</thead>
<tbody>
<?php
$dbname = "TravelMapping";
$db = new mysqli("localhost","travmap","clinch",$dbname) or die("Failed to connect to database");
$sql = "SELECT sum(o.activeMileage) as totalMileage FROM overallMileageByRegion o";
$totalMileage = $db->query($sql)->fetch_assoc()['totalMileage'];
$sql = <<<SQL
SELECT
traveler,
ROUND(SUM(COALESCE(co.activeMileage, 0)), 2) AS clinchedMileage,
round(SUM(coalesce(co.activeMileage, 0)) / $totalMileage * 100, 2) AS percentage
FROM clinchedOverallMileageByRegion co
GROUP BY co.traveler ORDER BY clinchedMileage DESC;
SQL;
$res = $db->query($sql);
$rank = 1;
while ($row = $res->fetch_assoc()) {
if($row['traveler'] == $user) {
$highlight = 'user-highlight';
} else {
$highlight = '';
}
echo <<<HTML
<tr class="$highlight" onClick="window.document.location='/user?u={$row['traveler']}';">
<td>{$rank}</td><td>{$row['traveler']}</td><td>{$row['clinchedMileage']}</td><td>{$row['percentage']}%</td>
</tr>
HTML;
$rank++;
}
?>
</tbody>
</table>
</td>
<td>
<table class="gratable tablesorter" id="rankingstable">
<thead>
<tr><th colspan="5">Traveler Mileage in Active and Preview Systems</th></tr>
<tr><th class="sortable">Rank</th><th class="sortable">Username</th><th class="sortable">Miles Traveled</th><th class="sortable">%</th></tr>
</thead>
<tbody>
<?php
$dbname = "TravelMapping";
$db = new mysqli("localhost","travmap","clinch",$dbname) or die("Failed to connect to database");
$sql = "SELECT sum(o.activePreviewMileage) as totalMileage FROM overallMileageByRegion o";
$totalMileage = $db->query($sql)->fetch_assoc()['totalMileage'];
$sql = <<<SQL
SELECT
traveler,
ROUND(SUM(COALESCE(co.activePreviewMileage, 0)), 2) AS clinchedMileage,
round(SUM(coalesce(co.activePreviewMileage, 0)) / $totalMileage * 100, 2) AS percentage
FROM clinchedOverallMileageByRegion co
GROUP BY co.traveler ORDER BY clinchedMileage DESC;
SQL;
$res = $db->query($sql);
$rank = 1;
while ($row = $res->fetch_assoc()) {
if($row['traveler'] == $user) {
$highlight = 'user-highlight';
} else {
$highlight = '';
}
echo <<<HTML
<tr class="$highlight" onClick="window.document.location='/user?u={$row['traveler']}';">
<td>{$rank}</td><td>{$row['traveler']}</td><td>{$row['clinchedMileage']}</td><td>{$row['percentage']}%</td>
</tr>
HTML;
$rank++;
}
?>
</tbody>
</table>
</td>
</tr>
</table>
</body>
<?php require $_SERVER['DOCUMENT_ROOT']."/lib/tmfooter.php"; ?>
</html>