PageRenderTime 48ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/html/pages/dpmatch.php

https://github.com/graywh/utstats
PHP | 102 lines | 88 code | 14 blank | 0 comment | 9 complexity | ae285980d68b058598cdd38813571b3f MD5 | raw file
  1. <?php
  2. if (empty($import_adminkey) or isset($_REQUEST['import_adminkey']) or $import_adminkey != $adminkey) die('bla');
  3. $options['title'] = 'Delete Player from Match';
  4. $i = 0;
  5. $options['vars'][$i]['name'] = 'pid';
  6. $options['vars'][$i]['type'] = 'player';
  7. $options['vars'][$i]['prompt'] = 'Choose the player you want to delete from a match:';
  8. $options['vars'][$i]['caption'] = 'Player to delete:';
  9. $i++;
  10. $options['vars'][$i]['name'] = 'mid';
  11. $options['vars'][$i]['type'] = 'match';
  12. $options['vars'][$i]['whereplayer'] = 'pid';
  13. $options['vars'][$i]['prompt'] = 'Choose the match you want to delete the player from:';
  14. $options['vars'][$i]['caption'] = 'Match:';
  15. $i++;
  16. $results = adminselect($options);
  17. $matchid = $results['mid'];
  18. $pid = $results['pid'];
  19. echo'<br><table border="0" cellpadding="1" cellspacing="2" width="600">
  20. <tr>
  21. <td class="smheading" align="center" colspan="2">Delete Player From Match ID '.$matchid.'</td>
  22. </tr>';
  23. echo'<tr>
  24. <td class="smheading" align="left" width="200">Amending Players Rank:</td>';
  25. $q_radjust = small_query("SELECT pid, gid, rank FROM uts_player WHERE id = $pid");
  26. if (!$q_radjust) {
  27. $sql_crank = false;
  28. } else {
  29. $rank_pid = $q_radjust[pid];
  30. $rank_gid = $q_radjust[gid];
  31. $rank = $q_radjust[rank];
  32. $sql_crank = small_query("SELECT id, rank, matches FROM uts_rank WHERE pid = $rank_pid AND gid = '$rank_gid'");
  33. }
  34. if (!$sql_crank) {
  35. echo'<td class="grey" align="left" width="400">Player not in rankings</td>';
  36. } else {
  37. $rid = $sql_crank[id];
  38. $newrank = $sql_crank[rank]-$rank;
  39. $oldrank = $sql_crank[rank];
  40. $matchcount = $sql_crank[matches]-1;
  41. mysql_query("UPDATE uts_rank SET rank = $newrank, prevrank = $oldrank, matches = $matchcount WHERE id = $rid") or die(mysql_error());
  42. mysql_query("DELETE FROM uts_rank WHERE matches = 0") or die(mysql_error());
  43. echo'<td class="grey" align="left" width="400">Done</td>';
  44. }
  45. echo'</tr>
  46. <tr>
  47. <td class="smheading" align="left">Removing Kill Matrix Entries:</td>';
  48. $q_match = mysql_query("SELECT matchid, playerid FROM uts_player WHERE pid = '$pid' and matchid = '$matchid'") or die(mysql_error());
  49. while ($r_match = mysql_fetch_array($q_match)) {
  50. mysql_query("DELETE FROM uts_killsmatrix WHERE matchid = '${r_match['matchid']}' AND (killer = '${r_match['playerid']}' OR victim = '${r_match['playerid']}')") or die(mysql_error());
  51. }
  52. echo'<td class="grey" align="left">Done</td>
  53. </tr>
  54. <tr>
  55. <td class="smheading" align="left" width="200">Removing Player Weapon Stats:</td>';
  56. mysql_query("DELETE FROM uts_weaponstats WHERE matchid = $matchid AND pid = $pid") or die(mysql_error());
  57. echo'<td class="grey" align="left" width="400">Done</td>
  58. </tr>
  59. <tr>
  60. <td class="smheading" align="left" width="200">Removing Player From Match:</td>';
  61. mysql_query("DELETE FROM uts_player WHERE matchid = $matchid AND pid = $pid") or die(mysql_error());
  62. echo'<td class="grey" align="left" width="400">Done</td>
  63. </tr>
  64. <tr>
  65. <td class="smheading" align="left" width="200">Amending Player Weapon Stats:</td>';
  66. mysql_query("DELETE FROM uts_weaponstats WHERE matchid IN ('$matchid','0') AND pid = '$pid'") or die(mysql_error());
  67. $q_weaponstats = mysql_query("SELECT SUM(kills) AS kills, SUM(shots) AS shots, SUM(hits) as hits, SUM(damage) as damage, AVG(acc) AS acc FROM uts_weaponstats WHERE pid = '$pid' GROUP BY weapon") or die(mysql_error());
  68. while ($r_weaponstats = mysql_fetch_array($q_weaponstats)) {
  69. mysql_query("INSERT INTO uts_weaponstats SET matchid='0', pid='$pid', kills='${r_weaponstats['kills']}', shots='${r_weaponstats['shots']}', hits='${r_weaponstats['hits']}', damage='${r_weaponstats['damage']}', acc='${r_weaponstats['acc']}'") or die(mysql_error());
  70. }
  71. echo'<td class="grey" align="left" width="400">Done</td>
  72. </tr>
  73. <tr>
  74. <td class="smheading" align="left" width="200">Amending Global Weapon Stats:</td>';
  75. mysql_query("DELETE FROM uts_weaponstats WHERE matchid='0' AND pid='0'") or die(mysql_error());
  76. $q_weaponstats = mysql_query("SELECT weapon, SUM(kills) AS kills, SUM(shots) AS shots, SUM(hits) as hits, SUM(damage) as damage, AVG(acc) AS acc FROM uts_weaponstats WHERE matchid = '0' GROUP BY weapon") or die(mysql_error());
  77. while ($r_weaponstats = mysql_fetch_array($q_weaponstats)) {
  78. mysql_query("INSERT INTO uts_weaponstats SET matchid='0', pid='0', weapon='${r_weaponstats['weapon']}', kills='${r_weaponstats['kills']}', shots='${r_weaponstats['shots']}', hits='${r_weaponstats['hits']}', damage='${r_weaponstats['damage']}', acc='${r_weaponstats['acc']}'") or die(mysql_error());
  79. }
  80. echo'<td class="grey" align="left" width="400">Done</td>
  81. </tr>
  82. <tr>
  83. <td class="smheading" align="center" colspan="2">Match Deleted - <a href="./admin.php?key='.$_REQUEST[key].'">Go Back To Admin Page</a></td>
  84. </tr></table>';
  85. ?>