-
Notifications
You must be signed in to change notification settings - Fork 1
/
actions.inc.php
243 lines (224 loc) · 6.94 KB
/
actions.inc.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
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
<?php
/**
* actions overview file
* display the complete game actions sorted by actions count
* @package HLStats
* @author Johannes 'Banana' Keßler
* @copyright Johannes 'Banana' Keßler
*/
/**
*
* Original development:
* +
* + HLStats - Real-time player and clan rankings and statistics for Half-Life
* + http://sourceforge.net/projects/hlstats/
* +
* + Copyright (C) 2001 Simon Garner
* +
*
* Additional development:
* +
* + UA HLStats Team
* + http://www.unitedadmins.com
* + 2004 - 2007
* +
*
*
* Current development:
* +
* + Johannes 'Banana' Keßler
* + http://hlstats.sourceforge.net
* + 2007 - 2010
* +
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
// the initial row color
$rcol = "row-dark";
// the actions array which holds the data to display and the page count
$actions['data'] = array();
$actions['pages'] = array();
// the current page to display
$page = 1;
if (isset($_GET["page"])) {
$check = validateInput($_GET['page'],'digit');
if($check === true) {
$page = $_GET['page'];
}
}
// the current element to sort by for the query
$sort = 'obj_count';
if (isset($_GET["sort"])) {
$check = validateInput($_GET['sort'],'nospace');
if($check === true) {
$sort = $_GET['sort'];
}
}
// the default next sort order
$newSort = "ASC";
// the default sort order for the query
$sortorder = 'DESC';
if (isset($_GET["sortorder"])) {
$check = validateInput($_GET['sortorder'],'nospace');
if($check === true) {
$sortorder = $_GET['sortorder'];
}
if($_GET["sortorder"] == "ASC") {
$newSort = "DESC";
}
}
// query to get the total actions count for this game
$queryActionsCount = mysql_query("SELECT COUNT(*) ac
FROM ".DB_PREFIX."_Actions, ".DB_PREFIX."_Events_PlayerActions
WHERE ".DB_PREFIX."_Events_PlayerActions.actionId = ".DB_PREFIX."_Actions.id
AND ".DB_PREFIX."_Actions.game='".mysql_escape_string($game)."'");
$result = mysql_fetch_assoc($queryActionsCount);
// get the total actions count for this game
$totalactions = $result['ac'];
mysql_free_result($queryActionsCount);
if(!empty($totalactions)) {
// query to get the data from the db with the given options
$queryStr = "SELECT SQL_CALC_FOUND_ROWS
".DB_PREFIX."_Actions.code,
".DB_PREFIX."_Actions.description,
COUNT(".DB_PREFIX."_Events_PlayerActions.id) AS obj_count,
".DB_PREFIX."_Actions.reward_player AS obj_bonus
FROM ".DB_PREFIX."_Actions, ".DB_PREFIX."_Events_PlayerActions, ".DB_PREFIX."_Players
WHERE ".DB_PREFIX."_Events_PlayerActions.playerId = ".DB_PREFIX."_Players.playerId
AND ".DB_PREFIX."_Players.game='".mysql_escape_string($game)."'
AND ".DB_PREFIX."_Events_PlayerActions.actionId = ".DB_PREFIX."_Actions.id
AND ".DB_PREFIX."_Actions.game='".mysql_escape_string($game)."'
AND ".DB_PREFIX."_Players.hideranking = 0
GROUP BY ".DB_PREFIX."_Actions.id
ORDER BY ".$sort." ".$sortorder;
// calculate the limit
if($page === 1) {
$queryStr .=" LIMIT 0,50";
}
else {
$start = 50*($page-1);
$queryStr .=" LIMIT ".$start.",50";
}
$query = mysql_query($queryStr);
if(mysql_num_rows($query) > 0) {
while($result = mysql_fetch_assoc($query)) {
$actions['data'][] = $result;
}
}
mysql_freeresult($query);
// query to get the total rows which would be fetched without the LIMIT
// works only if the $queryStr has SQL_CALC_FOUND_ROWS
$query = mysql_query("SELECT FOUND_ROWS() AS 'rows'");
$result = mysql_fetch_assoc($query);
$actions['pages'] = (int)ceil($result['rows']/50);
mysql_freeresult($query);
}
pageHeader(
array($gamename, l("Action Statistics")),
array($gamename=>"%s?game=$game", l("Action Statistics")=>"")
);
?>
<div id="sidebar">
<h1><?php echo l('Options'); ?></h1>
<div class="left-box">
<ul class="sidemenu">
<li>
<a href="<?php echo "index.php?game=$game"; ?>"><?php echo l('Back to game overview'); ?></a>
</li>
</ul>
</div>
</div>
<div id="main">
<h1>
<?php echo l("Action Statistics"); ?> |
<?php echo l('From a total of'); ?> <b><?php echo $totalactions; ?></b> <?php echo l('actions'); ?> (<?php echo l('Last'); ?> <?php echo DELETEDAYS; ?> <?php echo l('days'); ?>)
</h1>
<table cellpadding="0" cellspacing="0" border="1" width="100%">
<tr>
<th class="<?php echo $rcol; ?>"><?php echo l('Rank'); ?></th>
<th class="<?php echo $rcol; ?>">
<a href="index.php?<?php echo makeQueryString(array('sort'=>'code','sortorder'=>$newSort)); ?>">
<?php echo l('Action'); ?>
</a>
<?php if($sort == "code") { ?>
<img src="hlstatsimg/<?php echo $sortorder; ?>.gif" alt="Sorting" width="7" height="7" />
<?php } ?>
</th>
<th class="<?php echo $rcol; ?>">
<a href="index.php?<?php echo makeQueryString(array('sort'=>'obj_count','sortorder'=>$newSort)); ?>">
<?php echo l('Achieved'); ?>
</a>
<?php if($sort == "obj_count") { ?>
<img src="hlstatsimg/<?php echo $sortorder; ?>.gif" alt="Sorting" width="7" height="7" />
<?php } ?>
</th>
<th class="<?php echo $rcol; ?>">
<a href="index.php?<?php echo makeQueryString(array('sort'=>'obj_bonus','sortorder'=>$newSort)); ?>">
<?php echo l('Skill Bonus'); ?>
</a>
<?php if($sort == "obj_bonus") { ?>
<img src="hlstatsimg/<?php echo $sortorder; ?>.gif" alt="Sorting" width="7" height="7" />
<?php } ?>
</th>
</tr>
<?php
if(!empty($actions['data'])) {
if($page > 1) {
$rank = ($page - 1) * (50 + 1);
}
else {
$rank = 1;
}
foreach($actions['data'] as $k=>$entry) {
toggleRowClass($rcol);
echo '<tr>',"\n";
echo '<td class="',$rcol,'">';
echo $rank+$k;
echo '</td>',"\n";
echo '<td class="',$rcol,'">';
echo '<a href="index.php?mode=actioninfo&action=',$entry['code'],'&game=',$game,'">';
echo $entry['description'];
echo '</a>';
echo '</td>',"\n";
echo '<td class="',$rcol,'">';
echo $entry['obj_count'];
echo '</td>',"\n";
echo '<td class="',$rcol,'">';
echo $entry['obj_bonus'];
echo '</td>',"\n";
echo '</tr>';
}
echo '<tr><td colspan="4" align="right">';
if($actions['pages'] > 1) {
for($i=1;$i<=$actions['pages'];$i++) {
if($page == ($i)) {
echo "[",$i,"]";
}
else {
echo "<a href='index.php?",makeQueryString(array('page'=>$i)),"'>[",$i,"]</a>";
}
}
}
else {
echo "[1]";
}
echo '</td></tr>';
}
else {
echo '<tr><td colspan="4">',l('No data recorded'),'</td></tr>';
}
?>
</table>
</div>