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
194 lines (188 loc) · 7.9 KB
/
stat.php
File metadata and controls
194 lines (188 loc) · 7.9 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
<?php require $_SERVER['DOCUMENT_ROOT'] . "/lib/tmphpuser.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"/>
<link rel="shortcut icon" type="image/png" href="/favicon.png">
<title>Traveler Statistics</title>
<style type="text/css">
table.rankingstable {
margin: auto;
width: 90%;
}
#usertable {
width: 100%;
margin: auto;
margin-bottom: 20px;
}
#usertable td {
text-align: center;
}
</style>
<?php require $_SERVER['DOCUMENT_ROOT'] . "/lib/tmphpfuncs.php" ?>
<?php tm_common_js(); ?>
</head>
<body>
<?php require $_SERVER['DOCUMENT_ROOT'] . "/lib/tmheader.php"; ?>
<h1>Traveler Statistics</h1>
<?php tm_user_select_form("\"\""); ?>
<table style="margin: auto">
<?php
$totalMileage = round(tm_sum_column("overallMileageByRegion", "activeMileage"), 2);
$totalPreviewMileage = round(tm_sum_column("overallMileageByRegion", "activePreviewMileage"), 2);
// if ($tmuser == TM_NO_USER) {
// echo "<form id=\"userselect\" action=\"\"><p>\n";
// echo "<label>Current User: </label>\n";
// tm_user_select();
// echo "<input type=\"submit\" value=\"Select User\" />\n";
// echo "</p></form>\n";
// }else{
echo <<<HTML
<tr><td colspan="2">
<table class="gratable" id="usertable">
<thead>
<tr><th colspan="5">Current User</th></tr>
<tr><th>User</th><th>Active Distance Traveled</th><th>Rank</th><th>Active + Preview Distance Traveled</th><th>Rank</th></tr>
</thead><tbody>
HTML;
echo "<tr onClick=\"window.document.location='/user?u={$tmuser}';\">";
$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 = tmdb_query($sql);
$row = tm_fetch_user_row_with_rank($res, 'clinchedMileage');
echo "<td>{$row['traveler']}</td>";
$style = 'style="background-color: '.tm_color_for_amount_traveled($row['clinchedMileage'],$totalMileage).';"';
echo "<td ".$style.">".tm_convert_distance($row['clinchedMileage'])." of ".tm_convert_distance($totalMileage)." ";
tm_echo_units();
echo " ({$row['percentage']}%)</td>";
echo "<td>{$row['rank']}</td>";
$sql = <<<SQL
SELECT
traveler,
ROUND(SUM(COALESCE(co.activePreviewMileage, 0)), 2) AS clinchedMileage,
round(SUM(coalesce(co.activePreviewMileage, 0)) / $totalPreviewMileage * 100, 2) AS percentage
FROM clinchedOverallMileageByRegion co
GROUP BY co.traveler ORDER BY clinchedMileage DESC;
SQL;
$res = tmdb_query($sql);
$row = tm_fetch_user_row_with_rank($res, 'clinchedMileage');
$style = 'style="background-color: '.tm_color_for_amount_traveled($row['clinchedMileage'],$totalPreviewMileage).';"';
echo "<td ".$style.">".tm_convert_distance($row['clinchedMileage'])." of ".tm_convert_distance($totalPreviewMileage)." ";
tm_echo_units();
echo " ({$row['percentage']}%)</td>";
echo "<td>{$row['rank']}</td>";
echo <<<HTML
</tr>
</tbody></table>
</td></tr>
HTML;
// }
?>
<tr>
<td>
<table class="sortable gratable rankingstable">
<thead>
<tr>
<th colspan="5">Travels in Active Systems</th>
</tr>
<tr>
<th>Rank</th>
<th>Username</th>
<th>Distance Traveled (<?php tm_echo_units(); ?>)</th>
<th>%</th>
</tr>
</thead>
<tbody>
<?php
$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 = tmdb_query($sql);
$rank = 1;
while ($row = $res->fetch_assoc()) {
if ($row['traveler'] == $tmuser) {
$highlight = 'user-highlight';
} else {
$highlight = '';
}
$print_distance = tm_convert_distance($row['clinchedMileage']);
$style = 'style="text-align: right; background-color: '.tm_color_for_amount_traveled($row['clinchedMileage'],$totalMileage).';"';
echo <<<HTML
<tr class="$highlight" onClick="window.document.location='/user?u={$row['traveler']}';">
<td style="text-align: right;">{$rank}</td><td>{$row['traveler']}</td><td {$style}>{$print_distance}</td><td {$style} data-sort="{$row['percentage']}">{$row['percentage']}%</td>
</tr>
HTML;
$rank++;
}
$res->free();
?>
</tbody>
</table>
</td>
<td>
<table class="sortable gratable rankingstable">
<thead>
<tr>
<th colspan="5">Travels in Active and Preview Systems</th>
</tr>
<tr>
<th>Rank</th>
<th>Username</th>
<th>Distance Traveled (<?php tm_echo_units(); ?>)</th>
<th>%</th>
</tr>
</thead>
<tbody>
<?php
$sql = <<<SQL
SELECT
traveler,
ROUND(SUM(COALESCE(co.activePreviewMileage, 0)), 2) AS clinchedMileage,
round(SUM(coalesce(co.activePreviewMileage, 0)) / $totalPreviewMileage * 100, 2) AS percentage
FROM clinchedOverallMileageByRegion co
GROUP BY co.traveler ORDER BY clinchedMileage DESC;
SQL;
$res = tmdb_query($sql);
$rank = 1;
while ($row = $res->fetch_assoc()) {
if ($row['traveler'] == $tmuser) {
$highlight = 'user-highlight';
} else {
$highlight = '';
}
$print_distance = tm_convert_distance($row['clinchedMileage']);
$style = 'style="text-align: right; background-color: '.tm_color_for_amount_traveled($row['clinchedMileage'],$totalPreviewMileage).';"';
echo <<<HTML
<tr class="$highlight" onClick="window.document.location='/user?u={$row['traveler']}';">
<td style="text-align: right;">{$rank}</td><td>{$row['traveler']}</td><td {$style}>{$print_distance}</td><td {$style} data-sort="{$row['percentage']}">{$row['percentage']}%</td>
</tr>
HTML;
$rank++;
}
$res->free();
?>
</tbody>
</table>
</td>
</tr>
</table>
</body>
<?php require $_SERVER['DOCUMENT_ROOT'] . "/lib/tmfooter.php"; ?>
</html>