utstats /html/includes/functions_admin.php

Language PHP Lines 332
MD5 Hash 13734658f37ca178ed73bbc1c12e4f28 Estimated Cost $6,170 (why?)
Repository https://github.com/graywh/utstats.git View Raw File View Project SPDX
  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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
<?php

/*
$options['title'] = 'Test';
//$options['requireconfirmation'] = false;


$options['vars'][$i]['name'] = 'var_game';
$options['vars'][$i]['type'] = 'game';
$options['vars'][$i]['prompt'] = 'Choose game:';
$options['vars'][$i]['caption'] = 'Game:';
//$options['vars'][$i]['extraoption'] = 'extra';


$options['vars'][$i]['name'] = 'var_srv';
$options['vars'][$i]['type'] = 'server';
$options['vars'][$i]['prompt'] = 'Choose server:';
$options['vars'][$i]['caption'] = 'Server:';
//$options['vars'][$i]['wheregid'] = 'var_game';


$options['vars'][$i]['name'] = 'var_match';
$options['vars'][$i]['type'] = 'match';
$options['vars'][$i]['prompt'] = 'Choose Match:';
$options['vars'][$i]['caption'] = 'Match:';
//$options['vars'][$i]['whereserver'] = 'var_srv';
//$options['vars'][$i]['wheregid'] = 'var_game';
//$options['vars'][$i]['whereplayer'] = 'var_player';
$options['vars'][$i]['exclude'] = 'var_match';


$options['vars'][$i]['name'] = 'var_plr';
$options['vars'][$i]['type'] = 'player';
$options['vars'][$i]['prompt'] = 'Choose player';
$options['vars'][$i]['caption'] = 'Player:';
//$options['vars'][$i]['wherematch'] = 'var_match';
//$options['vars'][$i]['whereserver'] = 'var_server';
//$options['vars'][$i]['wheregid'] = 'var_game';


$options['vars'][$i]['name'] = 'sure';
$options['vars'][$i]['type'] = 'static';
$options['vars'][$i]['options'] = 'No|Yes';
$options['vars'][$i]['exitif'] = 'No';
$options['vars'][$i]['prompt'] = 'Are you sure?';
$options['vars'][$i]['caption'] = 'Sure:';


$options['vars'][$i]['name'] = 'ip_from';
$options['vars'][$i]['type'] = 'text';
$options['vars'][$i]['prompt'] = 'Enter the IP you want to search from:';
$options['vars'][$i]['caption'] = 'IP from:';
$options['vars'][$i]['initialvalue'] = 'ip_from';

*/


function adminselect(&$options) {
	$i = !empty($_REQUEST['step']) ? $_REQUEST['step'] : 0;
	if (isset($_REQUEST['back'])) {
		if (isset($_REQUEST['cur_var'])) unset($_REQUEST[$_REQUEST['cur_var']]);
		$i -= 2;
	}
	if (isset($_REQUEST['noop'])) {
		if (isset($_REQUEST['cur_var'])) unset($_REQUEST[$_REQUEST['cur_var']]);
		$i -= 1;
	}
	if (!isset($_REQUEST['noop'])) {
		if (isset($_REQUEST['playerfilter'])) unset($_REQUEST['playerfilter']);
	}
	$step = $i + 1;
	$maxsteps = count($options['vars']);
	if (!isset($options['requireconfirmation']) or $options['requireconfirmation']) $maxsteps++;
	if (!isset($_REQUEST['values']) or empty($_REQUEST['values'])) {
		$values = array();
	} else {
		$valtmp = explode(',', $_REQUEST['values']);
		foreach($valtmp as $valtmp2) {
			$valtmp3 = explode('=>', $valtmp2);
			$values[$valtmp3[0]] = $valtmp3[1];
		}
	}
	if (isset($_REQUEST['submit']) and isset($_REQUEST['cur_var'])) {
		$values[$_REQUEST['cur_var']] = $_REQUEST[$_REQUEST['cur_var']];
		unset($_REQUEST[$_REQUEST['cur_var']]);
		if (isset($options['vars'][$i - 1]['exitif']) and $options['vars'][$i - 1]['exitif'] == $values[$_REQUEST['cur_var']]) $i = $maxsteps;
	}
	if ($i == $maxsteps) return($values);
	echo '<table border="0" cellpadding="1" cellspacing="0" width="716">
			<tbody>
			<tr><td class="heading">'.htmlentities($options['title']).'</td></tr>
			<tr><td class="smheading">Step '.$step.' of '.$maxsteps.'</td></tr>
			</tbody></table><br>';
	if ($step != $maxsteps and !isset($options['vars'][$i])) die("Something went wrong :(");
	
	echo '<form action="'. $_SERVER['PHP_SELF'] .'" method="POST">';

	echo '<table border="0" cellpadding="1" cellspacing="2" width="600">';
	if ($step == $maxsteps) {
		echo '<tr><td colspan="2" class="medheading">Please Confirm!</td></tr>';
	}

	foreach($options['vars'] as $num => $var) {	
		if ((!isset($values[$var['name']]) and $num != $i) or $num > $i) continue;
		echo '<tr><td class="smheading" width="150">';
		
		if ($num == $i or !isset($var['caption'])) {
			echo htmlentities($var['prompt']);
		} else {
			echo htmlentities($var['caption']);
		}
		
		echo '</td>';
		
		echo '<td class="grey" width="400">';
		if ($num != $i) {
			if (isset($var['extraoption']) and $values[$var['name']] == $var['extraoption']) {
				echo htmlentities($values[$var['name']]);
			} else {
				switch($var['type']) {
					case 'game':
						$r_game = small_query("SELECT gamename, name FROM uts_games WHERE id = '". $values[$var['name']] ."'");
						echo htmlentities($r_game['name']) .' ('. htmlentities($r_game['gamename']) .')';
						break;
					case 'server':
						$r_server = small_query("SELECT servername, serverip FROM uts_match WHERE id = '". $values[$var['name']] ."'");
						echo htmlentities($r_server['servername']) .' ('. $r_server['serverip'] .')';
						break;
					case 'player':
						$r_player = small_query("SELECT name FROM uts_pinfo WHERE id = '". $values[$var['name']] ."'");
						echo htmlentities($r_player['name']);
						break;
					case 'match':
						$r_match = small_query("SELECT id, time, serverip, mapfile FROM uts_match WHERE id = '". $values[$var['name']] ."'");
						echo htmlentities($r_match['id'].': '.mdate2($r_match['time']).' ('.un_ut($r_match['mapfile']).' on '.$r_match['serverip'].')');
						break;
					case 'static':
					case 'text':
						echo htmlentities($values[$var['name']]);
						break;
					default:
						echo 'Show: Don\'tknow what to do with type '. $var['type'];
				}
			}
		} else {
			if (isset($var['initialvalue']) and isset($values[$var['initialvalue']])) $values[$var['name']] = $values[$var['initialvalue']];
			echo '<input type="hidden" name="cur_var" value="'.$var['name'].'">';
			switch($var['type']) {
				case 'game':
					echo '<select class="searchform" name="'. $var['name'] .'">';
					if (isset($var['extraoption'])) {
						if (isset($var['exclude']) and $var['extraoption'] == $values[$var['exclude']]) {
						} else {
							echo '<option value="'.$var['extraoption'].'">'.$var['extraoption'].'</option>';
						}
					}
					
					$sql_game = "SELECT id, gamename, name FROM uts_games ORDER BY name ASC";
					$q_game = mysql_query($sql_game) or die(mysql_error());
					while ($r_game = mysql_fetch_array($q_game)) {
						if (isset($var['exclude']) and $r_game['id'] == $values[$var['exclude']]) continue;
						$selected = (isset($values[$var['name']]) and $r_game['id'] == $values[$var['name']]) ? 'selected' : '';
						echo '<option '.$selected.' value="'.$r_game['id'].'">'. htmlentities($r_game['name'] .' ('. $r_game['gamename'] .')') .'</option>';
					}
					echo '</select>';
					break;

				
				case 'server':
					echo '<select class="searchform" name="'. $var['name'] .'">';
					if (isset($var['extraoption'])) {
						if (isset($var['exclude']) and $var['extraoption'] == $values[$var['exclude']]) {
						} else {
							echo '<option value="'.$var['extraoption'].'">'.$var['extraoption'].'</option>';
						}
					}
					
					$sql_server = "SELECT id, servername, serverip FROM uts_match GROUP BY servername, serverip ORDER BY servername ASC";
					if (isset($var['wheregid'])) {
						$sql_server = "SELECT id, servername, serverip FROM uts_match WHERE gid = '". $values[$var['wheregid']] ."' GROUP BY servername, serverip ORDER BY servername ASC";
					}
					$q_server = mysql_query($sql_server) or die(mysql_error());
					while ($r_server = mysql_fetch_array($q_server)) {
						if (isset($var['exclude']) and $r_server['id'] == $values[$var['exclude']]) continue;
						$selected = (isset($values[$var['name']]) and $r_server['id'] == $values[$var['name']]) ? 'selected' : '';
						echo '<option '.$selected.' value="'.$r_server['id'].'">'. htmlentities($r_server['servername'] .' ('. $r_server['serverip'] .')').'</option>';
					}
					echo '</select>';
					break;
				
				case 'player':
					echo '<select class="searchform" name="'. $var['name'] .'">';
					if (isset($var['extraoption'])) {
						if (isset($var['exclude']) and $var['extraoption'] == $values[$var['exclude']]) {
						} else {
							echo '<option value="'.$var['extraoption'].'">'.$var['extraoption'].'</option>';
						}
					}
					
					$where_extra = '';
					if (isset($var['whereisbanned'])) {
						$where_extra .= " AND pi.banned = '". $var['whereisbanned'] ."' ";
					}
					if (!empty($_REQUEST['playerfilter'])) {
						$where_extra .= " AND pi.name LIKE '%". my_addslashes($_REQUEST['playerfilter']) ."%' ";
					}

					$sql_player = "SELECT pi.id, pi.name FROM uts_pinfo pi WHERE 1 $where_extra ORDER BY pi.name ASC";
					if (isset($var['wherematch'])) {
						$sql_player = "SELECT pi.id, pi.name FROM uts_player p, uts_pinfo pi WHERE p.pid = pi.id AND p.matchid = '". $values[$var['wherematch']] ."' $where_extra GROUP BY p.id ORDER BY pi.name ASC";
					}
					if (isset($var['whereserver'])) {
						$r_server = small_query("SELECT servername, serverip FROM uts_match WHERE id = '". $values[$var['whereserver']] ."'");
						$sql_player = "SELECT DISTINCT pi.id, pi.name FROM uts_match m, uts_player p, uts_pinfo pi WHERE m.serverip = '".$r_server['serverip']."' AND  p.matchid = m.id AND  p.pid = pi.id $where_extra GROUP BY p.id ORDER BY pi.name ASC";
					}
					if (isset($var['wheregid'])) {
						$sql_player = "SELECT pi.id, pi.name FROM uts_player p, uts_pinfo pi WHERE p.pid = pi.id AND p.gid = '". $values[$var['wheregid']] ."' $where_extra GROUP BY p.id ORDER BY pi.name ASC";
					}
					$q_player = mysql_query($sql_player) or die(mysql_error());
					while ($r_player = mysql_fetch_array($q_player)) {
						if (isset($var['exclude']) and $r_player['id'] == $values[$var['exclude']]) continue;
						$selected = (isset($values[$var['name']]) and $r_player['id'] == $values[$var['name']]) ? 'selected' : '';
						echo '<option '.$selected.' value="'.$r_player['id'].'">'. htmlentities($r_player['name']) .'</option>';
					}
					echo '</select>';
					echo '&nbsp;&nbsp;&nbsp;&nbsp;';
					echo 'Filter: <input class="searchform" type="text" name="playerfilter" value="'. (empty($_REQUEST['playerfilter']) ? '' : $_REQUEST['playerfilter']) .'" size="6">';
					echo '  <input class="searchform" type="Submit" name="noop" value="apply">';
					break;
				
				case 'match':
					echo '<select class="searchform" name="'. $var['name'] .'">';
					if (isset($var['extraoption'])) {
						if (isset($var['exclude']) and $var['extraoption'] == $values[$var['exclude']]) {
						} else {
							echo '<option value="'.$var['extraoption'].'">'.$var['extraoption'].'</option>';
						}
					}
					
					$sql_match = "SELECT id, time, serverip, mapfile FROM uts_match ORDER BY time DESC";
					if (isset($var['whereserver'])) {
						$r_server = small_query("SELECT servername, serverip FROM uts_match WHERE id = '". $values[$var['whereserver']] ."'");
						$sql_match = "SELECT id, time, serverip, mapfile FROM uts_match WHERE serverip = '".$r_server['serverip']."' ORDER BY time DESC";
					}
					if (isset($var['wheregid'])) {
						$sql_match = "SELECT id, time, serverip, mapfile FROM uts_match WHERE gid = '". $values[$var['wheregid']] ."' ORDER BY time DESC";
					}
					if (isset($var['whereplayer'])) {
						$sql_match = "SELECT m.id AS id, m.time AS time, m.serverip AS serverip, m.mapfile AS mapfile FROM uts_match m, uts_player p WHERE pid = '". $values[$var['whereplayer']] ."' AND p.matchid = m.id ORDER BY time DESC";
					}
					$q_match = mysql_query($sql_match) or die(mysql_error());
					while ($r_match = mysql_fetch_array($q_match)) {
						if (isset($var['exclude']) and $r_match['id'] == $values[$var['exclude']]) continue;
						$selected = (isset($values[$var['name']]) and $r_match['id'] == $values[$var['name']]) ? 'selected' : '';
						echo '<option '.$selected.' value="'.$r_match['id'].'">'. htmlentities($r_match['id'].': '.mdate2($r_match['time']).' ('.un_ut($r_match['mapfile']).' on '.$r_match['serverip'].')').'</option>';
					}
					echo '</select>';
					break;
					
				case 'static':
					echo '<select class="searchform" name="'. $var['name'] .'">';
					if (isset($var['extraoption'])) {
						if (isset($var['exclude']) and $var['extraoption'] == $values[$var['exclude']]) {
						} else {
							echo '<option value="'.$var['extraoption'].'">'.$var['extraoption'].'</option>';
						}
					}
					
					$sopts = explode('|', $var['options']);
					foreach($sopts as $sval) {
						$selected = (isset($values[$var['name']]) and $sval == $values[$var['name']]) ? 'selected' : '';
						echo '<option '.$selected.' value="'.$sval.'">'. htmlentities($sval) .'</option>';
					}
					echo '</select>';
					break;
					
				case 'text':
					$pval = (isset($values[$var['name']])) ? $values[$var['name']] : '';
					echo '<input type="text" class="searchform" name="'. $var['name'] .'" value="'. $pval .'">';
					break;
					
					
				default:
					echo 'Select: Don\'tknow what to do with type '. $var['type'];
			}
		}
		echo '</td></tr>';
	}
	
	$valstr = '';
	foreach($values as $key => $value) {
		if (empty($key)) continue;
		if (!empty($valstr)) $valstr .= ',';
		$valstr .= "$key=>$value";
	}
	
	
	$_REQUEST['step'] = '';
	$_REQUEST['values'] = '';
	foreach($_REQUEST as $key => $value) {
		if (isset($_COOKIE[$key])) continue;
		switch($key){
			case 'step':
				$value = $step; break;
			case 'values':
				$value = $valstr; break;
			case 'submit':
			case 'back':
			case 'cur_var':
			case 'playerfilter':
			case 'noop':
				continue 2;
		}
		echo '<input type="hidden" name="'.$key.'" value="'.$value.'">';
	}
	
	echo '<tr><td>';
	if ($step != 1) echo '<input class="searchformb" type="submit" name="back" value="&lt;&lt; Back">';
	echo '</td>';
	$caption = ($step == $maxsteps) ? 'Finish' : 'Next &gt;&gt;';
	echo '<td align="right"><input class="searchformb" type="submit" name="submit" value="'.$caption.'"></td></tr>';
	
	echo '</table>';

	
	echo '</form>';
	require('includes/footer.php');
	exit;
}


?>
Back to Top