utstats /html/pages/admin/editgamestype.php

Language PHP Lines 229
MD5 Hash 072e33ee322f7594902a863584ac2b47 Estimated Cost $4,281 (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
<?php
if (empty($import_adminkey) or isset($_REQUEST['import_adminkey']) or $import_adminkey != $adminkey) die('bla');
	
$sql_server = "SELECT id, servername, serverip FROM uts_match GROUP BY servername, serverip ORDER BY servername ASC";
$q_server = mysql_query($sql_server) or die(mysql_error());
$servernames  = array('0' => '');
$serverips = array('0' => '*');
while ($r_server = mysql_fetch_array($q_server)) {
	$servernames[$r_server['id']] = $r_server['servername'];
	$serverips[$r_server['id']] = $r_server['serverip'];
}

$sql_games = "SELECT id, gamename, name FROM uts_games ORDER BY gamename ASC";
$q_games = mysql_query($sql_games) or die(mysql_error());
$gamedisplaynames = array('0' => '');
$gamenames = array('0' => '*');
while ($r_games = mysql_fetch_array($q_games)) {
	$gamenames[$r_games['id']] = $r_games['gamename'];
	$gamedisplaynames[$r_games['id']] = $r_games['name'];
}


if (isset($_REQUEST['submit'])) {
	mysql_query("	INSERT	INTO	uts_gamestype
							SET	serverip = '". my_addslashes($_REQUEST['serverip']) ."',
									gamename = '". my_addslashes($_REQUEST['gamename']) ."',
									mutator = '". my_addslashes($_REQUEST['mutator']) ."',
									gid = '". my_addslashes($_REQUEST['gid']) ."'
					") or die(mysql_error());
	
	if (isset($_REQUEST['update'])) {
		echo'<br><table border="0" cellpadding="1" cellspacing="2" width="600">
				<tr>
					<td class="smheading" align="center" colspan="2">Updating...</td>
				</tr>
				
				
				
				<tr>
					<td class="smheading" align="left" width="200">Updating Player Records</td>';
		$where = 'WHERE 1';
		if ($_REQUEST['serverip'] != '*') {
			$where .= " AND m.serverip = '". my_addslashes($_REQUEST['serverip']) ."'";
		}
		if ($_REQUEST['gamename'] != '*') {
			$gids = array_keys($gamenames, my_stripslashes($_REQUEST['gamename']));
			$where .= " AND m.gid IN (".implode(',', $gids).")";
		}
		if ($_REQUEST['mutator'] != '*') {
			$where .= " AND m.mutators LIKE '%".my_addslashes($_REQUEST['mutator'])."%'";
		}
		
		mysql_query("UPDATE uts_player p, uts_match m SET p.gid = '". my_addslashes($_REQUEST['gid']) ."' $where AND m.id = p.matchid;") or die(mysql_error());
		echo'<td class="grey" align="left" width="400">Done (updated '.mysql_affected_rows().' records)</td>
				</tr>
				
				
				
				
				<tr>
					<td class="smheading" align="left" width="200">Updating Matches</td>';
		mysql_query("UPDATE uts_match m SET m.gid = '". my_addslashes($_REQUEST['gid']) ."' $where;") or die(mysql_error());
		echo'<td class="grey" align="left" width="400">Done (updated '.mysql_affected_rows().' matches)</td>
				</tr>
				
				
				
				
				
				<tr>
					<td class="smheading" align="left" width="200">Re-Calcuating Rankings</td>';
		
		if ($_REQUEST['gamename'] != '*') {
			$gids[] = $_REQUEST['gid'];
			$where = "WHERE gid IN (".implode(',', $gids).")";
		} else {
			$where = 'WHERE 1';
		}
		mysql_query("DELETE FROM uts_rank $where;") or die(mysql_error());
		
		$sql_nrank = "SELECT SUM(p.gametime) AS time, p.pid, p.gid, SUM(p.rank) AS rank, COUNT(p.matchid) AS matches FROM uts_player p, uts_pinfo pi $where AND pi.id = p.pid AND pi.banned <> 'Y' GROUP BY p.gid, p.pid";
		$q_nrank = mysql_query($sql_nrank) or die(mysql_error());
		$num_ranks = 0;
		while ($r_nrank = mysql_fetch_array($q_nrank)) {
			mysql_query("INSERT INTO uts_rank SET time = '${r_nrank['time']}', pid = ${r_nrank['pid']}, gid = ${r_nrank['gid']}, rank = '${r_nrank['rank']}', prevrank = '${r_nrank['rank']}', matches = ${r_nrank['matches']}") or die(mysql_error());
			$num_ranks++;
		}
		echo'<td class="grey" align="left" width="400">Done (recalculated '.$num_ranks.' rankings)</td>
				</tr>
				<tr>
					<td class="smheading" align="center" colspan="2">Update finished..</td>
				</tr>
			  </table>';
	}
}

if (isset($_REQUEST['del'])) {
	mysql_query("	DELETE 	FROM	uts_gamestype
						WHERE		id = '". my_addslashes($_REQUEST['del']) ."'
					") or die(mysql_error());
}



echo'<br><table border="0" cellpadding="1" cellspacing="2" width="600">
<tr>
	<td class="medheading" align="center" colspan="8">Current Mappings</td>
</tr>
<tr>
	<td class="smheading" width="130">&nbsp;Server IP</td>
	<td class="smheading" width="20"></td>
	<td class="smheading" width="130">&nbsp;Game Name</td>
	<td class="smheading" width="20"></td>
	<td class="smheading" width="130">&nbsp;Mutatorlist contains</td>
	<td class="smheading" width="20"></td>
	<td class="smheading" width="130">&nbsp;Game</td>
	<td class="smheading" width="20"></td>
</tr>';






$sql_gamestype = "SELECT id, serverip, gamename, mutator, gid FROM uts_gamestype ORDER BY id ASC;";
$q_gamestype = mysql_query($sql_gamestype) or die(mysql_error());
$i = 0;
while ($r_gamestype = mysql_fetch_array($q_gamestype)) {
	$i++;
	$class = ($i%2) ? 'grey' : 'grey2';
	echo '<tr>';
	echo '<td class="'.$class.'">&nbsp;'.htmlentities($r_gamestype['serverip']).'</td>';
	echo '<td class="smheading" align="center">+</td>';
	echo '<td class="'.$class.'">&nbsp;'.htmlentities($r_gamestype['gamename']).'</td>';
	echo '<td class="smheading" align="center">+</td>';
	echo '<td class="'.$class.'">&nbsp;'.htmlentities($r_gamestype['mutator']).'</td>';
	echo '<td class="smheading" align="center">=</td>';
	echo '<td class="'.$class.'">&nbsp;'.htmlentities($gamedisplaynames[$r_gamestype['gid']]).'</td>';
	echo '<td class="'.$class.'" align="center">';
		echo '<a href="'.$_SERVER['PHP_SELF'].'?action='.$action.'&amp;key='.$adminkey.'&amp;del='.$r_gamestype['id'].'">';
		echo '<img src="images/del.png" border="0" width="16" height="16" title="Delete" alt="Delete" />';
		echo '</a>';
	echo '</td>';
	echo '</tr>';
}

echo '</tr></table>';








echo'<br><table border="0" cellpadding="1" cellspacing="2" width="600">
<tr>
	<td class="medheading" align="center" colspan="2">Add new gamestype</td>
</tr>
<form action="'.$_SERVER['PHP_SELF'].'" method="POST">
<input type="hidden" name="key" value="'.$adminkey.'">
<input type="hidden" name="action" value="'.$action.'">
';

$class='grey';
echo '<tr>';
echo '<td class="smheading" width="170">If server =</td>';
echo '<td class="'.$class.'">';
echo '<select class="searchform" name="serverip">';
foreach($serverips as $id => $bla) {
	echo '<option value="'.$serverips[$id].'">'. $serverips[$id]; 
	if (!empty($servernames[$id])) echo ' ('. $servernames[$id] .')';
	echo '</option>';
	}
echo '</select>';
echo '</td></tr>';


echo '<tr><td class="smheading" nowrap>and gamename =</td>';
echo '<td class="'.$class.'">';

echo '<select class="searchform" name="gamename">';
foreach($gamenames as $id => $bla) {
	if ($gamenames[$id] == '(user defined)') continue;
	echo '<option value="'.$gamenames[$id].'">'. $gamenames[$id]; 
	if (!empty($gamedisplaynames[$id])) echo ' ('. $gamedisplaynames[$id] .')';
	echo '</option>';
}
echo '</select>';
echo '</td></tr>';


echo '<tr><td class="smheading" nowrap>and mutatorlist contains</td>';
echo '<td class="'.$class.'">';
echo '<input type="text" class="searchform" name="mutator" value="*"> <span class="text2">(case insensitive substring)</span>';
echo '</td></tr>';


echo '<tr><td class="smheading" nowrap>==&gt; assume gametype:</td>';
echo '<td class="'.$class.'">';
	
echo '<select class="searchform" name="gid">';
foreach($gamenames as $id => $bla) {
	if ($gamenames[$id] == '*') continue;
	echo '<option value="'.$id.'">'. $gamenames[$id]; 
	if (!empty($gamedisplaynames[$id])) echo ' ['. $gamedisplaynames[$id] .']';
	echo '</option>';
}
echo '</select>';
echo '</td></tr>';

echo '<tr><td class="smheading">Update existing matches:</td>';
echo '<td class="'.$class.'">';
echo '<input type="checkbox" checked name="update"> <span class="text2">(this cannot be undone easily!)</span>';
echo '</td></tr>';


echo '<tr>';
echo '<td class="'.$class.'" colspan="2" align="center"><input class="searchformb" type="Submit" name="submit" value="Add"></td>';
echo '</tr>';

echo'</form>
	<tr>
	<td class="smheading" align="center" colspan="2"><a class="grey" href="./admin.php?key='.$_REQUEST[key].'">Go Back To Admin Page</a></td>
</tr>
</table>';
	
?>
Back to Top