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

/html/includes/functions_admin.php

https://github.com/graywh/utstats
PHP | 332 lines | 247 code | 32 blank | 53 comment | 82 complexity | 13734658f37ca178ed73bbc1c12e4f28 MD5 | raw file
  1. <?php
  2. /*
  3. $options['title'] = 'Test';
  4. //$options['requireconfirmation'] = false;
  5. $options['vars'][$i]['name'] = 'var_game';
  6. $options['vars'][$i]['type'] = 'game';
  7. $options['vars'][$i]['prompt'] = 'Choose game:';
  8. $options['vars'][$i]['caption'] = 'Game:';
  9. //$options['vars'][$i]['extraoption'] = 'extra';
  10. $options['vars'][$i]['name'] = 'var_srv';
  11. $options['vars'][$i]['type'] = 'server';
  12. $options['vars'][$i]['prompt'] = 'Choose server:';
  13. $options['vars'][$i]['caption'] = 'Server:';
  14. //$options['vars'][$i]['wheregid'] = 'var_game';
  15. $options['vars'][$i]['name'] = 'var_match';
  16. $options['vars'][$i]['type'] = 'match';
  17. $options['vars'][$i]['prompt'] = 'Choose Match:';
  18. $options['vars'][$i]['caption'] = 'Match:';
  19. //$options['vars'][$i]['whereserver'] = 'var_srv';
  20. //$options['vars'][$i]['wheregid'] = 'var_game';
  21. //$options['vars'][$i]['whereplayer'] = 'var_player';
  22. $options['vars'][$i]['exclude'] = 'var_match';
  23. $options['vars'][$i]['name'] = 'var_plr';
  24. $options['vars'][$i]['type'] = 'player';
  25. $options['vars'][$i]['prompt'] = 'Choose player';
  26. $options['vars'][$i]['caption'] = 'Player:';
  27. //$options['vars'][$i]['wherematch'] = 'var_match';
  28. //$options['vars'][$i]['whereserver'] = 'var_server';
  29. //$options['vars'][$i]['wheregid'] = 'var_game';
  30. $options['vars'][$i]['name'] = 'sure';
  31. $options['vars'][$i]['type'] = 'static';
  32. $options['vars'][$i]['options'] = 'No|Yes';
  33. $options['vars'][$i]['exitif'] = 'No';
  34. $options['vars'][$i]['prompt'] = 'Are you sure?';
  35. $options['vars'][$i]['caption'] = 'Sure:';
  36. $options['vars'][$i]['name'] = 'ip_from';
  37. $options['vars'][$i]['type'] = 'text';
  38. $options['vars'][$i]['prompt'] = 'Enter the IP you want to search from:';
  39. $options['vars'][$i]['caption'] = 'IP from:';
  40. $options['vars'][$i]['initialvalue'] = 'ip_from';
  41. */
  42. function adminselect(&$options) {
  43. $i = !empty($_REQUEST['step']) ? $_REQUEST['step'] : 0;
  44. if (isset($_REQUEST['back'])) {
  45. if (isset($_REQUEST['cur_var'])) unset($_REQUEST[$_REQUEST['cur_var']]);
  46. $i -= 2;
  47. }
  48. if (isset($_REQUEST['noop'])) {
  49. if (isset($_REQUEST['cur_var'])) unset($_REQUEST[$_REQUEST['cur_var']]);
  50. $i -= 1;
  51. }
  52. if (!isset($_REQUEST['noop'])) {
  53. if (isset($_REQUEST['playerfilter'])) unset($_REQUEST['playerfilter']);
  54. }
  55. $step = $i + 1;
  56. $maxsteps = count($options['vars']);
  57. if (!isset($options['requireconfirmation']) or $options['requireconfirmation']) $maxsteps++;
  58. if (!isset($_REQUEST['values']) or empty($_REQUEST['values'])) {
  59. $values = array();
  60. } else {
  61. $valtmp = explode(',', $_REQUEST['values']);
  62. foreach($valtmp as $valtmp2) {
  63. $valtmp3 = explode('=>', $valtmp2);
  64. $values[$valtmp3[0]] = $valtmp3[1];
  65. }
  66. }
  67. if (isset($_REQUEST['submit']) and isset($_REQUEST['cur_var'])) {
  68. $values[$_REQUEST['cur_var']] = $_REQUEST[$_REQUEST['cur_var']];
  69. unset($_REQUEST[$_REQUEST['cur_var']]);
  70. if (isset($options['vars'][$i - 1]['exitif']) and $options['vars'][$i - 1]['exitif'] == $values[$_REQUEST['cur_var']]) $i = $maxsteps;
  71. }
  72. if ($i == $maxsteps) return($values);
  73. echo '<table border="0" cellpadding="1" cellspacing="0" width="716">
  74. <tbody>
  75. <tr><td class="heading">'.htmlentities($options['title']).'</td></tr>
  76. <tr><td class="smheading">Step '.$step.' of '.$maxsteps.'</td></tr>
  77. </tbody></table><br>';
  78. if ($step != $maxsteps and !isset($options['vars'][$i])) die("Something went wrong :(");
  79. echo '<form action="'. $_SERVER['PHP_SELF'] .'" method="POST">';
  80. echo '<table border="0" cellpadding="1" cellspacing="2" width="600">';
  81. if ($step == $maxsteps) {
  82. echo '<tr><td colspan="2" class="medheading">Please Confirm!</td></tr>';
  83. }
  84. foreach($options['vars'] as $num => $var) {
  85. if ((!isset($values[$var['name']]) and $num != $i) or $num > $i) continue;
  86. echo '<tr><td class="smheading" width="150">';
  87. if ($num == $i or !isset($var['caption'])) {
  88. echo htmlentities($var['prompt']);
  89. } else {
  90. echo htmlentities($var['caption']);
  91. }
  92. echo '</td>';
  93. echo '<td class="grey" width="400">';
  94. if ($num != $i) {
  95. if (isset($var['extraoption']) and $values[$var['name']] == $var['extraoption']) {
  96. echo htmlentities($values[$var['name']]);
  97. } else {
  98. switch($var['type']) {
  99. case 'game':
  100. $r_game = small_query("SELECT gamename, name FROM uts_games WHERE id = '". $values[$var['name']] ."'");
  101. echo htmlentities($r_game['name']) .' ('. htmlentities($r_game['gamename']) .')';
  102. break;
  103. case 'server':
  104. $r_server = small_query("SELECT servername, serverip FROM uts_match WHERE id = '". $values[$var['name']] ."'");
  105. echo htmlentities($r_server['servername']) .' ('. $r_server['serverip'] .')';
  106. break;
  107. case 'player':
  108. $r_player = small_query("SELECT name FROM uts_pinfo WHERE id = '". $values[$var['name']] ."'");
  109. echo htmlentities($r_player['name']);
  110. break;
  111. case 'match':
  112. $r_match = small_query("SELECT id, time, serverip, mapfile FROM uts_match WHERE id = '". $values[$var['name']] ."'");
  113. echo htmlentities($r_match['id'].': '.mdate2($r_match['time']).' ('.un_ut($r_match['mapfile']).' on '.$r_match['serverip'].')');
  114. break;
  115. case 'static':
  116. case 'text':
  117. echo htmlentities($values[$var['name']]);
  118. break;
  119. default:
  120. echo 'Show: Don\'tknow what to do with type '. $var['type'];
  121. }
  122. }
  123. } else {
  124. if (isset($var['initialvalue']) and isset($values[$var['initialvalue']])) $values[$var['name']] = $values[$var['initialvalue']];
  125. echo '<input type="hidden" name="cur_var" value="'.$var['name'].'">';
  126. switch($var['type']) {
  127. case 'game':
  128. echo '<select class="searchform" name="'. $var['name'] .'">';
  129. if (isset($var['extraoption'])) {
  130. if (isset($var['exclude']) and $var['extraoption'] == $values[$var['exclude']]) {
  131. } else {
  132. echo '<option value="'.$var['extraoption'].'">'.$var['extraoption'].'</option>';
  133. }
  134. }
  135. $sql_game = "SELECT id, gamename, name FROM uts_games ORDER BY name ASC";
  136. $q_game = mysql_query($sql_game) or die(mysql_error());
  137. while ($r_game = mysql_fetch_array($q_game)) {
  138. if (isset($var['exclude']) and $r_game['id'] == $values[$var['exclude']]) continue;
  139. $selected = (isset($values[$var['name']]) and $r_game['id'] == $values[$var['name']]) ? 'selected' : '';
  140. echo '<option '.$selected.' value="'.$r_game['id'].'">'. htmlentities($r_game['name'] .' ('. $r_game['gamename'] .')') .'</option>';
  141. }
  142. echo '</select>';
  143. break;
  144. case 'server':
  145. echo '<select class="searchform" name="'. $var['name'] .'">';
  146. if (isset($var['extraoption'])) {
  147. if (isset($var['exclude']) and $var['extraoption'] == $values[$var['exclude']]) {
  148. } else {
  149. echo '<option value="'.$var['extraoption'].'">'.$var['extraoption'].'</option>';
  150. }
  151. }
  152. $sql_server = "SELECT id, servername, serverip FROM uts_match GROUP BY servername, serverip ORDER BY servername ASC";
  153. if (isset($var['wheregid'])) {
  154. $sql_server = "SELECT id, servername, serverip FROM uts_match WHERE gid = '". $values[$var['wheregid']] ."' GROUP BY servername, serverip ORDER BY servername ASC";
  155. }
  156. $q_server = mysql_query($sql_server) or die(mysql_error());
  157. while ($r_server = mysql_fetch_array($q_server)) {
  158. if (isset($var['exclude']) and $r_server['id'] == $values[$var['exclude']]) continue;
  159. $selected = (isset($values[$var['name']]) and $r_server['id'] == $values[$var['name']]) ? 'selected' : '';
  160. echo '<option '.$selected.' value="'.$r_server['id'].'">'. htmlentities($r_server['servername'] .' ('. $r_server['serverip'] .')').'</option>';
  161. }
  162. echo '</select>';
  163. break;
  164. case 'player':
  165. echo '<select class="searchform" name="'. $var['name'] .'">';
  166. if (isset($var['extraoption'])) {
  167. if (isset($var['exclude']) and $var['extraoption'] == $values[$var['exclude']]) {
  168. } else {
  169. echo '<option value="'.$var['extraoption'].'">'.$var['extraoption'].'</option>';
  170. }
  171. }
  172. $where_extra = '';
  173. if (isset($var['whereisbanned'])) {
  174. $where_extra .= " AND pi.banned = '". $var['whereisbanned'] ."' ";
  175. }
  176. if (!empty($_REQUEST['playerfilter'])) {
  177. $where_extra .= " AND pi.name LIKE '%". my_addslashes($_REQUEST['playerfilter']) ."%' ";
  178. }
  179. $sql_player = "SELECT pi.id, pi.name FROM uts_pinfo pi WHERE 1 $where_extra ORDER BY pi.name ASC";
  180. if (isset($var['wherematch'])) {
  181. $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";
  182. }
  183. if (isset($var['whereserver'])) {
  184. $r_server = small_query("SELECT servername, serverip FROM uts_match WHERE id = '". $values[$var['whereserver']] ."'");
  185. $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";
  186. }
  187. if (isset($var['wheregid'])) {
  188. $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";
  189. }
  190. $q_player = mysql_query($sql_player) or die(mysql_error());
  191. while ($r_player = mysql_fetch_array($q_player)) {
  192. if (isset($var['exclude']) and $r_player['id'] == $values[$var['exclude']]) continue;
  193. $selected = (isset($values[$var['name']]) and $r_player['id'] == $values[$var['name']]) ? 'selected' : '';
  194. echo '<option '.$selected.' value="'.$r_player['id'].'">'. htmlentities($r_player['name']) .'</option>';
  195. }
  196. echo '</select>';
  197. echo '&nbsp;&nbsp;&nbsp;&nbsp;';
  198. echo 'Filter: <input class="searchform" type="text" name="playerfilter" value="'. (empty($_REQUEST['playerfilter']) ? '' : $_REQUEST['playerfilter']) .'" size="6">';
  199. echo ' <input class="searchform" type="Submit" name="noop" value="apply">';
  200. break;
  201. case 'match':
  202. echo '<select class="searchform" name="'. $var['name'] .'">';
  203. if (isset($var['extraoption'])) {
  204. if (isset($var['exclude']) and $var['extraoption'] == $values[$var['exclude']]) {
  205. } else {
  206. echo '<option value="'.$var['extraoption'].'">'.$var['extraoption'].'</option>';
  207. }
  208. }
  209. $sql_match = "SELECT id, time, serverip, mapfile FROM uts_match ORDER BY time DESC";
  210. if (isset($var['whereserver'])) {
  211. $r_server = small_query("SELECT servername, serverip FROM uts_match WHERE id = '". $values[$var['whereserver']] ."'");
  212. $sql_match = "SELECT id, time, serverip, mapfile FROM uts_match WHERE serverip = '".$r_server['serverip']."' ORDER BY time DESC";
  213. }
  214. if (isset($var['wheregid'])) {
  215. $sql_match = "SELECT id, time, serverip, mapfile FROM uts_match WHERE gid = '". $values[$var['wheregid']] ."' ORDER BY time DESC";
  216. }
  217. if (isset($var['whereplayer'])) {
  218. $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";
  219. }
  220. $q_match = mysql_query($sql_match) or die(mysql_error());
  221. while ($r_match = mysql_fetch_array($q_match)) {
  222. if (isset($var['exclude']) and $r_match['id'] == $values[$var['exclude']]) continue;
  223. $selected = (isset($values[$var['name']]) and $r_match['id'] == $values[$var['name']]) ? 'selected' : '';
  224. 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>';
  225. }
  226. echo '</select>';
  227. break;
  228. case 'static':
  229. echo '<select class="searchform" name="'. $var['name'] .'">';
  230. if (isset($var['extraoption'])) {
  231. if (isset($var['exclude']) and $var['extraoption'] == $values[$var['exclude']]) {
  232. } else {
  233. echo '<option value="'.$var['extraoption'].'">'.$var['extraoption'].'</option>';
  234. }
  235. }
  236. $sopts = explode('|', $var['options']);
  237. foreach($sopts as $sval) {
  238. $selected = (isset($values[$var['name']]) and $sval == $values[$var['name']]) ? 'selected' : '';
  239. echo '<option '.$selected.' value="'.$sval.'">'. htmlentities($sval) .'</option>';
  240. }
  241. echo '</select>';
  242. break;
  243. case 'text':
  244. $pval = (isset($values[$var['name']])) ? $values[$var['name']] : '';
  245. echo '<input type="text" class="searchform" name="'. $var['name'] .'" value="'. $pval .'">';
  246. break;
  247. default:
  248. echo 'Select: Don\'tknow what to do with type '. $var['type'];
  249. }
  250. }
  251. echo '</td></tr>';
  252. }
  253. $valstr = '';
  254. foreach($values as $key => $value) {
  255. if (empty($key)) continue;
  256. if (!empty($valstr)) $valstr .= ',';
  257. $valstr .= "$key=>$value";
  258. }
  259. $_REQUEST['step'] = '';
  260. $_REQUEST['values'] = '';
  261. foreach($_REQUEST as $key => $value) {
  262. if (isset($_COOKIE[$key])) continue;
  263. switch($key){
  264. case 'step':
  265. $value = $step; break;
  266. case 'values':
  267. $value = $valstr; break;
  268. case 'submit':
  269. case 'back':
  270. case 'cur_var':
  271. case 'playerfilter':
  272. case 'noop':
  273. continue 2;
  274. }
  275. echo '<input type="hidden" name="'.$key.'" value="'.$value.'">';
  276. }
  277. echo '<tr><td>';
  278. if ($step != 1) echo '<input class="searchformb" type="submit" name="back" value="&lt;&lt; Back">';
  279. echo '</td>';
  280. $caption = ($step == $maxsteps) ? 'Finish' : 'Next &gt;&gt;';
  281. echo '<td align="right"><input class="searchformb" type="submit" name="submit" value="'.$caption.'"></td></tr>';
  282. echo '</table>';
  283. echo '</form>';
  284. require('includes/footer.php');
  285. exit;
  286. }
  287. ?>