PageRenderTime 25ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/html/pages/admin/recalcflags.php

https://github.com/graywh/utstats
PHP | 72 lines | 56 code | 13 blank | 3 comment | 9 complexity | 9b63f3d526420a4bc3113a9a803aa927 MD5 | raw file
  1. <?php
  2. if (empty($import_adminkey) or isset($_REQUEST['import_adminkey']) or $import_adminkey != $adminkey) die('bla');
  3. $options['title'] = 'Recalculate Countryflags';
  4. $options['requireconfirmation'] = false;
  5. $i = 0;
  6. $options['vars'][$i]['name'] = 'start';
  7. $options['vars'][$i]['type'] = 'static';
  8. $options['vars'][$i]['options'] = 'No|Yes';
  9. $options['vars'][$i]['exitif'] = 'No';
  10. $options['vars'][$i]['prompt'] = 'Are you sure';
  11. $options['vars'][$i]['caption'] = 'Sure:';
  12. $i++;
  13. $results = adminselect($options);
  14. if ($results['start'] != 'Yes') {
  15. include('pages/admin/main.php');
  16. exit;
  17. }
  18. @ignore_user_abort(true);
  19. @set_time_limit(0);
  20. include("includes/geoip.inc");
  21. /* Opens the database file */
  22. $gi = geoip_open("GeoIP.dat",GEOIP_STANDARD);
  23. echo'<br><table border="0" cellpadding="1" cellspacing="2" width="600">
  24. <tr>
  25. <td class="smheading" align="center" colspan="2">Recalculating Countryflags</td>
  26. </tr>';
  27. echo'</tr>
  28. <tr>
  29. <td class="smheading" align="left">Recalculating Rankings:</td>';
  30. echo'<td class="grey" align="left">';
  31. echo'Recalculating pinfo table...<br>';
  32. /* update pinfo table */
  33. $sql_pids = mysql_query("SELECT uts_pinfo.id as pid, uts_pinfo.country as country, uts_player.ip as ip FROM uts_pinfo, uts_player WHERE uts_pinfo.id = uts_player.pid GROUP BY uts_player.pid;") or die(mysql_error());
  34. while($sql_pid = mysql_fetch_array($sql_pids))
  35. {
  36. $playercountry = strtolower(geoip_country_code_by_addr($gi,long2ip($sql_pid['ip'])));
  37. if ($playercountry != $sql_pid['country'] )
  38. {
  39. mysql_query("UPDATE uts_pinfo SET country = '$playercountry' WHERE id = '".$sql_pid['pid']."'") or die(mysql_error());
  40. }
  41. }
  42. echo'Recalculating player table...<br>';
  43. /* update player table */
  44. $sql_pids = mysql_query("SELECT pid, ip, country FROM uts_player");
  45. while ($sql_pid = mysql_fetch_array($sql_pids))
  46. {
  47. $playercountry = strtolower(geoip_country_code_by_addr($gi,long2ip($sql_pid['ip'])));
  48. if ($playercountry != $sql_pid['country'])
  49. {
  50. mysql_query("UPDATE uts_player SET country = '$playercountry' WHERE pid = '".$sql_pid['pid']."'") or die(mysql_error());
  51. }
  52. }
  53. echo 'Done</td>
  54. </tr>
  55. <tr>
  56. <td class="smheading" align="center" colspan="2">Countryflags recalculated - <a href="./admin.php?key='.$_REQUEST[key].'">Go Back To Admin Page</a></td>
  57. </tr></table>';
  58. ?>