utstats /html/pages/admin/dmatch.php

Language PHP Lines 177
MD5 Hash bf3fc65f08fcd4f4c2bd0996695614fe Estimated Cost $3,867 (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
<?php
if (empty($import_adminkey) or isset($_REQUEST['import_adminkey']) or $import_adminkey != $adminkey) die('bla');
	
$options['title'] = 'Delete match';
$i = 0;
$options['vars'][$i]['name'] = 'server';
$options['vars'][$i]['type'] = 'server';
$options['vars'][$i]['prompt'] = 'Choose the server where the match took place:';
$options['vars'][$i]['caption'] = 'Server:';
$i++;
$options['vars'][$i]['name'] = 'mid';
$options['vars'][$i]['type'] = 'match';
$options['vars'][$i]['whereserver'] = 'server';
$options['vars'][$i]['prompt'] = 'Choose the match to delete:';
$options['vars'][$i]['caption'] = 'Match to delete:';
$i++;

$results = adminselect($options);


$matchid = $results['mid'];

echo'<br><table border="0" cellpadding="1" cellspacing="2" width="600">
<tr>
	<td class="smheading" align="center" colspan="2">Deleting Match ID '.$matchid.'</td>
</tr>
<tr>
	<td class="smheading" align="left" width="200">Adjusting Rankings</td>';
$sql_radjust = "SELECT pid, gid, rank FROM uts_player WHERE matchid = $matchid";
$q_radjust = mysql_query($sql_radjust) or die(mysql_error());
$pids = array();
while ($r_radjust = mysql_fetch_array($q_radjust))
{

	$pid = $r_radjust['pid'];
	$pids[] = $pid;
	$gid = $r_radjust['gid'];
	$rank = $r_radjust['rank'];

	$sql_crank = small_query("SELECT id, rank, matches FROM uts_rank WHERE pid = $pid AND gid = $gid");
	if (!$sql_crank) continue;
	
	$rid = $sql_crank['id'];
	$newrank = $sql_crank['rank']-$rank;
	$oldrank = $sql_crank['rank'];
	$matchcount = $sql_crank['matches']-1;

	mysql_query("UPDATE uts_rank SET rank = $newrank, prevrank = $oldrank, matches = $matchcount WHERE id = $rid") or die(mysql_error());
	mysql_query("DELETE FROM uts_rank WHERE matches = 0") or die(mysql_error());
}
	echo'<td class="grey" align="left" width="400">Done</td>
</tr>
<tr>
	<td class="smheading" align="left" width="200">Removing Match Record:</td>';
mysql_query("DELETE FROM uts_match WHERE id = $matchid") or die(mysql_error());
	echo'<td class="grey" align="left" width="400">Done</td>
</tr>
<tr>
	<td class="smheading" align="left" width="200">Removing Player Records:</td>';
mysql_query("DELETE FROM uts_player WHERE matchid = $matchid") or die(mysql_error());
	echo'<td class="grey" align="left" width="400">Done</td>
</tr>
<tr>
	<td class="smheading" align="left" width="200">Removing Kill Matrix Entries:</td>';
mysql_query("DELETE FROM uts_killsmatrix WHERE matchid = $matchid") or die(mysql_error());
	echo'<td class="grey" align="left" width="400">Done</td>
</tr>
<tr>
	<td class="smheading" align="left" width="200">Removing Weapon Stats:</td>';
mysql_query("DELETE FROM uts_weaponstats WHERE matchid = $matchid") or die(mysql_error());
	echo'<td class="grey" align="left" width="400">Done</td>
</tr>
<tr>
	<td class="smheading" align="left" width="200">Amending Player Weapon Stats:</td>';
foreach($pids as $pid)
{
	// Update the player's weapon statistics (matchid 0)
	mysql_query("	REPLACE	uts_weaponstats
					SELECT	0 AS matchid,
							pid,
							weapon,
							SUM(kills) AS kills,
							SUM(shots) AS shots,
							SUM(hits) AS hits,
							SUM(damage) AS damage,
							LEAST(ROUND(10000*SUM(hits)/SUM(shots))/100, 100) AS acc
					FROM	uts_weaponstats
					WHERE	pid = '$pid'
						AND weapon > 0
						AND matchid > 0
					GROUP BY weapon;"
	) or die(mysql_error());

	// Update the player's match statistics (weapon 0)
	mysql_query("	REPLACE	uts_weaponstats
					SELECT	matchid,
							pid,
							0 AS weapon,
							SUM(kills) AS kills,
							SUM(shots) AS shots,
							SUM(hits) AS hits,
							SUM(damage) AS damage,
							LEAST(ROUND(10000*SUM(hits)/SUM(shots))/100, 100) AS acc
					FROM	uts_weaponstats
					WHERE	matchid > 0
						AND	pid = '$pid'
						AND weapon > 0
					GROUP BY matchid;"
	) or die(mysql_error());

	// Update the player's match entry in uts_player
	mysql_query("	UPDATE	uts_player AS p,
							uts_weaponstats AS w
					SET 	p.accuracy = w.acc
					WHERE	w.matchid = p.matchid
						AND	p.pid = '$pid'
						AND	w.pid = p.pid
						AND	w.weapon = 0;"
	) or die(mysql_error());

	// Update the player's career statistics (weapon 0, match 0)
	mysql_query("	REPLACE	uts_weaponstats
					SELECT	0 AS matchid,
							'$pid' AS pid,
							0 AS weapon,
							SUM(kills) AS kills,
							SUM(shots) AS shots,
							SUM(hits) AS hits,
							SUM(damage) AS damage,
							LEAST(ROUND(10000*SUM(hits)/SUM(shots))/100, 100) AS acc
					FROM	uts_weaponstats
					WHERE	matchid > 0
						AND	pid = '$pid'
						AND weapon > 0;"
	) or die(mysql_error());
}
	echo'<td class="grey" align="left" width="400">Done</td>
</tr>
<tr>
	<td class="smheading" align="left" width="200">Amending Global Weapon Stats:</td>';
mysql_query("	REPLACE uts_weaponstats
				SELECT	0 AS matchid,
						0 AS pid,
						weapon,
						SUM(kills) AS kills,
						SUM(shots) AS shots,
						SUM(hits) AS hits,
						SUM(damage) AS damage,
						LEAST(ROUND(10000*SUM(hits)/SUM(shots))/100, 100) AS acc
				FROM	uts_weaponstats
				WHERE	matchid > 0
					AND	pid > 0
					AND weapon > 0
				GROUP BY weapon;"
) or die(mysql_error());
mysql_query("	REPLACE uts_weaponstats
				SELECT	0 AS matchid,
						0 AS pid,
						0 AS weapon,
						SUM(kills) AS kills,
						SUM(shots) AS shots,
						SUM(hits) AS hits,
						SUM(damage) AS damage,
						LEAST(ROUND(10000*SUM(hits)/SUM(shots))/100, 100) AS acc
				FROM	uts_weaponstats
				WHERE	matchid > 0
					AND	pid > 0
					AND weapon > 0;"
) or die(mysql_error());
	echo'<td class="grey" align="left" width="400">Done</td>
</tr>
<tr>
	<td class="smheading" align="center" colspan="2">Match Deleted - <a href="./admin.php?key='.$_REQUEST[key].'">Go Back To Admin Page</a></td>
</tr></table>';

?>
Back to Top