PageRenderTime 60ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 0ms

/tournament.php

https://bitbucket.org/verax/to-ladder
PHP | 664 lines | 624 code | 38 blank | 2 comment | 27 complexity | 544c0d09aaac91b70c79385c1df65d87 MD5 | raw file
  1. <?
  2. $indexloaded=1;
  3. include("config/config.php");
  4. include("$dir[func]/global.php");
  5. include("$dir[func]/loginforms.php");
  6. if($tourney[id]){
  7. $tinfo=mysql_query("SELECT * FROM tourneys WHERE tid='$tourney[id]'");
  8. $tinfo=mysql_fetch_array($tinfo);
  9. }else{
  10. $defaultz=mysql_query("SELECT * FROM defaults2 WHERE line='1'");
  11. $tinfo=mysql_fetch_array($defaultz);
  12. $tinfo[name]="Tournament";
  13. }
  14. if(($action)&&(!$tinfo[tid])&&($action != 'default')){
  15. include("$dir[func]/error.php");
  16. display_error("Unknown Tournament ID<br><br><a href='./tournament.php'>Click Here for the Tournament List</a>");
  17. }
  18. if((!$action)&&($tinfo[tid])){
  19. $action="details";
  20. }
  21. switch($action){
  22. case "details":
  23. tourney_details($tourney);
  24. break;
  25. case "signup":
  26. tourney_signup();
  27. break;
  28. case "tourney_signup_2":
  29. tourney_signup_2($signup);
  30. break;
  31. case "players":
  32. tourney_players();
  33. break;
  34. case "playerinfo":
  35. tourney_playerinfo($player);
  36. break;
  37. case "brackets":
  38. tourney_brackets();
  39. break;
  40. default:
  41. tourney_list($search,$order);
  42. break;
  43. }
  44. //START FUNCTIONS
  45. function characters($text){
  46. $text=str_replace(";", "", $text);
  47. $text=htmlspecialchars("$text");
  48. $text=str_replace("#", "", $text);
  49. $text=str_replace("|", "", $text);
  50. $text=str_replace("'", "&acute;", $text);
  51. $text=eregi_replace("( ){2,}", " ", $text);
  52. $text=trim($text);
  53. return($text);
  54. }
  55. function tourney_list($search,$order){
  56. global $tinfo, $dir, $url, $out, $plyr, $site, $uinfo, $misc,$file;
  57. if($search[type]==1){
  58. $searchfield=characters($search[field]);
  59. $searchfield="%".$searchfield."%";
  60. $maxresults="25";
  61. $searchinfo=mysql_query("SELECT tid FROM tourneys WHERE name LIKE '$searchfield' LIMIT $maxresults");
  62. while(list($tid)=mysql_fetch_row($searchinfo)) {
  63. $searchresult[$tid]="1";
  64. }
  65. }
  66. if($order == "tid_up"){
  67. $tidsort = "tid_down";
  68. }else{
  69. $tidsort = "tid_up";
  70. }
  71. if($order == "name_up"){
  72. $namesort = "name_down";
  73. }else{
  74. $namesort = "name_up";
  75. }
  76. if($order == "ladderid_up"){
  77. $laddersort = "ladderid_down";
  78. }else{
  79. $laddersort = "ladderid_up";
  80. }
  81. if($order == "open_up"){
  82. $opensort = "open_down";
  83. }else{
  84. $opensort = "open_up";
  85. }
  86. if($search){
  87. $link1 = "<a>";
  88. $link2 = "<a>";
  89. $link3 = "<a>";
  90. }else{
  91. $link1 = "<a href='$url[base]/$file[tournament]?action=default&order=$tidsort'>";
  92. $link2 = "<a href='$url[base]/$file[tournament]?action=default&order=$namesort'>";
  93. $link3 = "<a href='$url[base]/$file[tournament]?action=default&order=$laddersort'>";
  94. $link4 = "<a href='$url[base]/$file[tournament]?action=default&order=$opensort'>";
  95. }
  96. $tablehead=table_head("show","80%","","left");
  97. $tablefoot=table_foot("show");
  98. $bannerhead=table_head("show","488","80","center");
  99. $bannerfoot=table_foot("show");
  100. $out[body]=$out[body]."
  101. <center>
  102. $bannerhead
  103. $out[banner]
  104. $bannerfoot <br>
  105. $tablehead &nbsp; &nbsp;<strong>
  106. &nbsp; &nbsp;<strong><font class='catfont'>Tournaments</font></strong>
  107. <hr class='catfont' size='1'>
  108. <center>
  109. <table width='690' border='0' cellpadding='1' cellspacing='1'>
  110. <tr class='altcolor'>
  111. <td align='center' width='60'><b>$link1 TID</a></b></td>
  112. <td align='left' width='280'><b>$link2 Tournament</a></b></td>
  113. <td align='center' width='70'><b>$link4 Status</b></td>
  114. <td align='center' width='70'><b>$link3 Ladder</a></b></td>
  115. <td align='center' width='70'><b>Signups</b></td>
  116. <td align='center' width='70'><b>Details</b></td>
  117. <td align='center' width='70'><b>Brackets</b></td>
  118. <td align='center' width='70'><b>Signup</b></td>
  119. </tr>
  120. ";
  121. if($order == "name_up"){
  122. $order = "name";
  123. }else if ($order == "name_down"){
  124. $order = "name desc";
  125. }else if ($order == "tid_up"){
  126. $order = "tid";
  127. }else if ($order == "tid_down"){
  128. $order = "tid desc";
  129. }else if ($order == "ladderid_down"){
  130. $order = "ladderid";
  131. }else if ($order == "ladderid_up"){
  132. $order = "ladderid desc";
  133. }else if ($order == "open_down"){
  134. $order = "open";
  135. }else if ($order == "open_up"){
  136. $order = "open desc";
  137. }else{
  138. $order = "tid desc";
  139. }
  140. $tourneylist=mysql_query("SELECT tid,size,active,name,ladderid,open FROM tourneys ORDER BY $order");
  141. $altcolora="' class='altcolora";
  142. $altcolorb="' class='altcolorb";
  143. while(list($tid,$size,$active,$name,$ladderid,$open)=mysql_fetch_row($tourneylist)){
  144. if(($search[type]==1)&&($searchresult[$tid])){
  145. $resultmatch="1";
  146. $showmainlink="1";
  147. }
  148. elseif(($search[type]==2)&&($search[field]==$tid)){
  149. $resultmatch="1";
  150. $showmainlink="1";
  151. }
  152. elseif(($search[type]==3)&&($search[field]==$ladderid)){
  153. $resultmatch="1";
  154. $showmainlink="1";
  155. }
  156. elseif(($search[type]==1)||($search[type]==2)||($search[type]==3)){
  157. $resultmatch="";
  158. $showmainlink="1";
  159. }
  160. else{
  161. $resultmatch="1";
  162. $showmainlink="";
  163. }
  164. if($altladrow=="$altcolora"){
  165. $altladrow="$altcolorb";
  166. }else{
  167. $altladrow="$altcolora";
  168. }
  169. $signups=0;
  170. $tourneyreports=mysql_query("SELECT pid FROM players2 WHERE tid='$tid'");
  171. while(list($pid)=mysql_fetch_row($tourneyreports)){
  172. $signups++;
  173. }
  174. if($signups>0){
  175. $signuplink ="<a href='$site[homeurl]/$file[tournament]?tourney[id]=$tid&action=players'>";
  176. }else{
  177. $signuplink ="<a>";
  178. }
  179. if($open > 0){
  180. $open = "Open";
  181. }else{
  182. $open = "Closed";
  183. }
  184. if($resultmatch){
  185. $out[body]=$out[body]."
  186. <tr bgcolor='$altladrow'>
  187. <td align='center' width='60'>$searchresulta $tid $searchresultb</td>
  188. <td align='left' width='280'>$searchresulta $name $searchresultb</td>
  189. <td align='center' width='70'>$open</td>
  190. <td align='center' width='70'>$searchresulta <a href='$site[homeurl]/$file[ladder]?ladderid=$ladderid'> $ladderid</a> $searchresultb</td>
  191. <td align='center' width='70'> $signuplink $signups</a></td>
  192. <td align='center' width='70'><a href='$site[homeurl]/$file[tournament]?tourney[id]=$tid&action=details'>Details</a></td>
  193. <td align='center' width='70'><a href='$site[homeurl]/$file[tournament]?tourney[id]=$tid&action=brackets'>Brackets</a></td>
  194. <td align='center' width='70'><a href='$site[homeurl]/$file[tournament]?tourney[id]=$tid&action=signup'>Signup</a></td>
  195. </tr>
  196. ";
  197. }
  198. }
  199. if($showmainlink){
  200. $out[body]=$out[body]."
  201. <tr>
  202. <td align='right' width='500' colspan='5'><br><a href='./tournament.php'><b>List All Tournaments</b></a></td>
  203. </tr>
  204. ";
  205. }
  206. $out[body]=$out[body]."
  207. <tr class='altcolor'><td width='100%' colspan='8'>&nbsp;</td></tr>
  208. </table>
  209. <br>
  210. <form method='post'>
  211. Search For <input type='text' name='search[field]' value=''>
  212. In <select name='search[type]'>
  213. <option value='1'>Tournament Names</option>
  214. <option value='2'>Tournament ID's</option>
  215. <option value='3'>Ladder ID's</option>
  216. </select> &nbsp;
  217. <input type='submit' name='' value='Search &gt;&gt;'>
  218. </form>
  219. $tablefoot";
  220. include("$dir[curtheme]");
  221. }
  222. function tourney_search($search){
  223. }
  224. function tourney_details($tourney){
  225. global $tinfo,$dir, $url, $out, $plyr, $site, $uinfo, $misc;
  226. $SearchArray = array("\n","&lt;","&gt;");
  227. $ReplaceArray = array("<br>","<",">");
  228. $tinfo[details]=str_replace($SearchArray,$ReplaceArray,$tinfo[details]);
  229. $UrlSearchArray = array("/([^]_a-z0-9-=\"'\/])((https?|ftp|news):\/\/|www\.)([^ \r\n\(\)\*\^\$!`\"'\|\[\]\{\};<>]*)/si","/^((https?|ftp|news):\/\/|www\.)([^ \r\n\(\)\*\^\$!`\"'\|\[\]\{\};<>]*)/si",);
  230. $UrlReplaceArray = array("\\1<a href='\\2\\4' target='new'>\\2\\4</a>","<a href='\\2' target='new'>\\1\\3</a>");
  231. $tinfo[details]=preg_replace($UrlSearchArray,$UrlReplaceArray,$tinfo[details]);
  232. $tablehead=table_head("show","70%","","left");
  233. $tablefoot=table_foot("show");
  234. $bannerhead=table_head("show","488","80","center");
  235. $bannerfoot=table_foot("show");
  236. $out[body]=$out[body]."
  237. <center>
  238. $bannerhead
  239. $out[banner]
  240. $bannerfoot <br>
  241. $tablehead &nbsp; &nbsp;<strong>
  242. <left>
  243. <b>$tinfo[name] Details</b><br>
  244. <hr class='catfont' size='1'>
  245. <center>
  246. <table width='100%' border='0' cellpadding='1' cellspacing='1' align='left'>
  247. <td align='left' width='100%'><b>Tournament Directors: $tinfo[directors] </b><br><br> $tinfo[details]</td>
  248. </tr>
  249. </table>
  250. <br>
  251. $tablefoot";
  252. include("$dir[curtheme]");
  253. }
  254. function tourney_signup(){
  255. global $tinfo,$dir, $url, $out, $plyr, $site, $uinfo, $misc;
  256. if($tinfo[active]){
  257. if(!$plyr[id]){
  258. include("$dir[func]/error.php");
  259. display_error("You are not logged in.<br>");
  260. }
  261. $check = mysql_query("SELECT id FROM ladders WHERE id = '$tinfo[ladderid]'");
  262. if(!($checkb = mysql_fetch_array($check))){
  263. include("$dir[func]/error.php");
  264. display_error("This tournament is no longer valid.<br>");
  265. }
  266. $teamson = mysql_query("SELECT teamid FROM teammembers WHERE playerid = '$plyr[id]' AND status < 3");
  267. while($row = mysql_fetch_array($teamson)){
  268. $check = mysql_query("SELECT id FROM ladder_$tinfo[ladderid] WHERE id ='$row[teamid]'");
  269. if($checkb = mysql_fetch_array($check)){
  270. $name = mysql_fetch_array(mysql_query("SELECT teamname FROM teams WHERE id ='$checkb[id]'"));
  271. $team = $name[teamname];
  272. }
  273. }
  274. if(!$team){
  275. include("$dir[func]/error.php");
  276. display_error("You are not logged in as the team leader<br> or co-team leader of any team on this ladder!.<br>");
  277. }
  278. if($tinfo[open] < 1){
  279. include("$dir[func]/error.php");
  280. display_error("Tournament is now closed for signups.<br>");
  281. }
  282. $tablehead=table_head("show","80%","","left");
  283. $tablefoot=table_foot("show");
  284. $bannerhead=table_head("show","488","80","center");
  285. $bannerfoot=table_foot("show");
  286. $out[body]=$out[body]."
  287. <center>
  288. $bannerhead
  289. $out[banner]
  290. $bannerfoot <br>
  291. $tablehead &nbsp; &nbsp;<strong>
  292. <center>
  293. <table width='600' border='1' bordercolor='#000000' cellspacing='0' cellpadding='2'>
  294. <tr class='altcolor'>
  295. <form method='post'>
  296. <td width='100%' valign='top' align='center' colspan='2'>
  297. <strong>$tinfo[name] Signup</strong><br>
  298. </td></tr>
  299. <tr class='altcolora'>";
  300. $out[body]=$out[body]."
  301. <form method='post'>
  302. <td align='left' width='200'><b>Name</b></td>
  303. <td align='center' width='200'>$team</td>
  304. </tr>
  305. ";
  306. if($tinfo[field1]){
  307. $out[body]=$out[body]."
  308. <tr class='altcolorb'>
  309. <td align='left' width='200'><b>$tinfo[field1]</b></td>
  310. <td align='center' width='200'><input type='text' name='signup[field1]' value='' size='30' maxlength='100'></td>
  311. </tr>
  312. ";
  313. }
  314. if($tinfo[field2]){
  315. $out[body]=$out[body]."
  316. <tr class='altcolora'>
  317. <td align='left' width='200'><b>$tinfo[field2]</b></td>
  318. <td align='center' width='200'><input type='text' name='signup[field2]' value='' size='30' maxlength='100'></td>
  319. </tr>
  320. ";
  321. }
  322. if($tinfo[field3]){
  323. $out[body]=$out[body]."
  324. <tr class='altcolorb'>
  325. <td align='left' width='200'><b>$tinfo[field3]</b></td>
  326. <td align='center' width='200'><input type='text' name='signup[field3]' value='' size='30' maxlength='100'></td>
  327. </tr>
  328. ";
  329. }
  330. $out[body]=$out[body]."
  331. <tr class='altcolor'>
  332. <td align='center' width='600' colspan='2'>
  333. <input type='hidden' name='signup[name]' value='$team'>
  334. <input type='hidden' name='action' value='tourney_signup_2'>
  335. <input type='submit' name='' value='Signup'></td>
  336. </tr>
  337. </form>
  338. </table>
  339. ";
  340. }else{
  341. $out[body]=$out[body]."
  342. <br><b>Signups are currently disabled</b><br>
  343. ";
  344. }
  345. $out[body]=$out[body]."
  346. <br>
  347. $tablefoot";
  348. include("$dir[curtheme]");
  349. }
  350. function tourney_signup_2($signup){
  351. global $tinfo, $dir, $url, $out, $plyr, $site, $uinfo, $misc;
  352. while(list($varib,$value)=each($signup)){
  353. $signup[$varib]=characters($value);
  354. if(!$signup[$varib]){
  355. include("$dir[func]/error.php");
  356. display_error("All fields are required.");
  357. }
  358. }
  359. if(mysql_num_rows(mysql_query("SELECT pid FROM players2 WHERE tid='$tinfo[tid]' AND name='$signup[name]'"))){
  360. include("$dir[func]/error.php");
  361. display_error("Your team is already in this tournament.");
  362. }
  363. $playerip = getenv("REMOTE_ADDR");
  364. if($misc[tourneyip] == 'no'){
  365. if(mysql_num_rows(mysql_query("SELECT pid FROM players2 WHERE tid='$tinfo[tid]' AND ipaddress='$playerip'"))){
  366. include("$dir[func]/error.php");
  367. display_error("Your IP Adddress is already in use on this tournament.");
  368. }
  369. }
  370. $teamid=mysql_query("SELECT id,teamemail FROM teams WHERE teamname='$signup[name]'");
  371. $team=mysql_fetch_array($teamid);
  372. $timeStamp = date("YmdHis");
  373. mysql_query("INSERT INTO players2 VALUES ('$team[id]','$tinfo[tid]','$playerip',' $timeStamp','$signup[name]','$team[teamemail]','$tinfo[field1]','$tinfo[field2]','$tinfo[field3]')");
  374. $tablehead=table_head("show","70%","","left");
  375. $tablefoot=table_foot("show");
  376. $bannerhead=table_head("show","488","80","center");
  377. $bannerfoot=table_foot("show");
  378. $out[body]=$out[body]."
  379. <center>
  380. $bannerhead
  381. $out[banner]
  382. $bannerfoot <br>
  383. $tablehead &nbsp; &nbsp;<strong>
  384. <center>
  385. <font class='catfont'>You have been added to the player signups!<br>
  386. Entering the tournament does not guarantee you a spot.</b><br>
  387. <br>
  388. </center>
  389. $tablefoot";
  390. include("$dir[curtheme]");
  391. }
  392. function tourney_players(){
  393. global $tinfo,$dir,$url,$out,$file;
  394. $tablehead=table_head("show","60%","","left");
  395. $tablefoot=table_foot("show");
  396. $bannerhead=table_head("show","488","80","center");
  397. $bannerfoot=table_foot("show");
  398. $out[body]=$out[body]."
  399. <center>
  400. $bannerhead
  401. $out[banner]
  402. $bannerfoot <br>
  403. $tablehead &nbsp; &nbsp;<strong>
  404. <center>
  405. <b>$tinfo[name] Players</b><br>
  406. <br>
  407. <table width='250' border='0' cellpadding='1' cellspacing='1'>
  408. <tr class='altcolor'>
  409. <td align='center' width='50'><b>#</b></td>
  410. <td align='center' width='200'><b>Name</b></td>
  411. </tr>
  412. ";
  413. $tourneyreports=mysql_query("SELECT pid,name FROM players2 WHERE tid='$tinfo[tid]' ORDER BY joined");
  414. while(list($pid,$name)=mysql_fetch_row($tourneyreports)){
  415. $count++;
  416. if($altcolorv == 'altcolorb'){
  417. $altcolorv = 'altcolora';
  418. }else{
  419. $altcolorv = 'altcolorb';
  420. }
  421. $out[body]=$out[body]."
  422. <tr class=$altcolorv>
  423. <td align='center' width='50'>$count</td>
  424. <td align='center' width='200'><a href='$url[base]/$file[teams]?teamid=$pid'>$name</a></td>
  425. </tr>
  426. ";
  427. }
  428. $out[body]=$out[body]."
  429. <tr class='altcolor'><td colspan='2'><br></td></tr>
  430. </table>
  431. <br>
  432. $tablefoot";
  433. include("$dir[curtheme]");
  434. }
  435. function tourney_brackets(){
  436. global $tinfo,$dir, $url, $out, $plyr, $site, $uinfo, $misc, $file;
  437. $brackets=mysql_query("SELECT bid,pid,name FROM brackets2 WHERE tid='$tinfo[tid]' ORDER BY bid");
  438. while(list($bid,$pid,$name)=mysql_fetch_row($brackets)){
  439. if($pid){
  440. $bracket[$bid]="<font type='arial' size='2'><a href='$url[base]/$file[teams]?teamid=$pid'>$name</a></font>";
  441. }else{
  442. $bracket[$bid]="$name";
  443. }
  444. $pid="";
  445. }
  446. $brackets="$tinfo[size]";
  447. $spots=($brackets * 2 - 1);
  448. $temp_rows="$brackets";
  449. while($temp_rows > 1){
  450. $rowcount++;
  451. if($rowcount > 1){
  452. $temp_rows=($temp_rows / 2);
  453. }
  454. $listrows.="-> $temp_rows";
  455. $rows="$rowcount";
  456. }
  457. $rowwidths=round(100 / $rows - 0.5);
  458. $actualrows=($rows * 2);
  459. ////////////////////////////////
  460. $tablehead=table_head("show","100%","","left");
  461. $tablefoot=table_foot("show");
  462. $bannerhead=table_head("show","488","80","center");
  463. $bannerfoot=table_foot("show");
  464. $out[body]=$out[body]."
  465. <center>
  466. $bannerhead
  467. $out[banner]
  468. $bannerfoot <br>
  469. $tablehead &nbsp; &nbsp;<strong>
  470. <table width='100%' border='1' bordercolor='#000000' cellspacing='0' cellpadding='2'>
  471. <tr class ='altcolor'>
  472. <td width='100%' valign='top' align='center'>
  473. <b>$tinfo[name] Brackets</b><br>
  474. </td></tr></table>
  475. <br><br>
  476. <table border='0' width='100%' cellspacing='0' cellpadding='0'>
  477. <tr>
  478. ";
  479. $counter="$brackets";
  480. while($counter > 1){
  481. if($round){
  482. $counter=($counter / 2);
  483. }
  484. $lastcb="$countbrackets";
  485. $countbrackets="";
  486. $game="";
  487. $round++;
  488. $finals=($rows - 1);
  489. $winner=($rows);
  490. $roundgamesay="Round $round Games";
  491. if($round=="$winner"){
  492. $roundgamesay="Winner!";
  493. }
  494. if($round=="$finals"){
  495. $roundgamesay="Finals";
  496. }
  497. $out[body]=$out[body]."
  498. <td align='center' valign='center' width='$rowwidths%' colspan='2'><b>$roundgamesay</b><br>
  499. <table border='0' width='100%' bordercolor='#FF0000' cellspacing='0' cellpadding='0'>
  500. ";
  501. $spacesetcount="";
  502. while($countbrackets < $counter){
  503. $countbrackets++;
  504. $spot++;
  505. $spacesetcount++;
  506. if($spacesetcount=="4"){
  507. $spacesetcount="";
  508. }
  509. $bracketid="$round"."_"."$countbrackets";
  510. $out[body]=$out[body]."
  511. <tr class='altcolor'>
  512. <td align='left' valign='center' width='100%' class='altcolor'>$bracket[$bracketid]</td>
  513. <td align='left' valign='center' width='100%'>&nbsp;</td>
  514. </tr>
  515. ";
  516. if($countbrackets < $counter){
  517. $spacecounter++;
  518. $spacecounter=($spacecounter + 1);
  519. if($spacecounter==2){
  520. $roundx2p1=($lastroundx2p1 * 2 + 1);
  521. if($round==1){
  522. $roundx2p1="1";
  523. }
  524. while($countspaces < $roundx2p1){
  525. $countspaces++;
  526. $spacecentercount++;
  527. $spacecenterword="";
  528. $alignspacer1="left";
  529. $spacecentercountcheck=($lastroundx2p1 + 1);
  530. if($spacecentercount=="$spacecentercountcheck"){
  531. $spacecenterwordcount++;
  532. if(($spacecenterwordcount==1)||($spacecenterwordcount==3)){
  533. $actualgamecount++;
  534. $spacecenterword="<b>Game $actualgamecount</b>";
  535. $alignspacer1="center";
  536. if($spacecenterwordcount==3){
  537. $spacecenterwordcount="";
  538. $spacecenterwordcount++;
  539. }
  540. }
  541. }
  542. $out[body]=$out[body]."
  543. <tr>
  544. <td align='$alignspacer1' valign='center'>&nbsp; $spacecenterword</td>
  545. <td align='left' valign='center' class='altcolor'>&nbsp;</td>
  546. </tr>
  547. ";
  548. }
  549. $spacecounter="";
  550. $countspaces="";
  551. $spacecentercount="";
  552. }
  553. }
  554. }
  555. $spacecenterwordcount="";
  556. $actualgamecount="";
  557. $lastroundx2p1="$roundx2p1";
  558. $out[body]=$out[body]."
  559. </table>
  560. </td>
  561. ";
  562. }
  563. $out[body]=$out[body]."
  564. </tr>
  565. </table><br><br>
  566. <table width='100%' border='1' bordercolor='#000000' cellspacing='0' cellpadding='2'>
  567. <tr class ='altcolor'>
  568. <td width='100%' valign='top' align='center'>
  569. <br>
  570. </td></tr></table>
  571. <br>
  572. $tablefoot";
  573. include("$dir[curtheme]");
  574. }
  575. ?>