/tournament.php
PHP | 664 lines | 624 code | 38 blank | 2 comment | 27 complexity | 544c0d09aaac91b70c79385c1df65d87 MD5 | raw file
- <?
- $indexloaded=1;
- include("config/config.php");
- include("$dir[func]/global.php");
- include("$dir[func]/loginforms.php");
- if($tourney[id]){
- $tinfo=mysql_query("SELECT * FROM tourneys WHERE tid='$tourney[id]'");
- $tinfo=mysql_fetch_array($tinfo);
- }else{
-
- $defaultz=mysql_query("SELECT * FROM defaults2 WHERE line='1'");
- $tinfo=mysql_fetch_array($defaultz);
- $tinfo[name]="Tournament";
- }
-
- if(($action)&&(!$tinfo[tid])&&($action != 'default')){
- include("$dir[func]/error.php");
- display_error("Unknown Tournament ID<br><br><a href='./tournament.php'>Click Here for the Tournament List</a>");
- }
-
- if((!$action)&&($tinfo[tid])){
- $action="details";
- }
-
- switch($action){
- case "details":
- tourney_details($tourney);
- break;
- case "signup":
- tourney_signup();
- break;
- case "tourney_signup_2":
- tourney_signup_2($signup);
- break;
- case "players":
- tourney_players();
- break;
- case "playerinfo":
- tourney_playerinfo($player);
- break;
- case "brackets":
- tourney_brackets();
- break;
- default:
- tourney_list($search,$order);
- break;
- }
-
- //START FUNCTIONS
- function characters($text){
- $text=str_replace(";", "", $text);
- $text=htmlspecialchars("$text");
- $text=str_replace("#", "", $text);
- $text=str_replace("|", "", $text);
- $text=str_replace("'", "´", $text);
- $text=eregi_replace("( ){2,}", " ", $text);
-
- $text=trim($text);
- return($text);
- }
-
- function tourney_list($search,$order){
- global $tinfo, $dir, $url, $out, $plyr, $site, $uinfo, $misc,$file;
- if($search[type]==1){
- $searchfield=characters($search[field]);
- $searchfield="%".$searchfield."%";
- $maxresults="25";
- $searchinfo=mysql_query("SELECT tid FROM tourneys WHERE name LIKE '$searchfield' LIMIT $maxresults");
- while(list($tid)=mysql_fetch_row($searchinfo)) {
- $searchresult[$tid]="1";
- }
-
- }
-
- if($order == "tid_up"){
- $tidsort = "tid_down";
- }else{
-
- $tidsort = "tid_up";
- }
-
- if($order == "name_up"){
- $namesort = "name_down";
- }else{
-
- $namesort = "name_up";
- }
-
- if($order == "ladderid_up"){
- $laddersort = "ladderid_down";
- }else{
-
- $laddersort = "ladderid_up";
- }
-
- if($order == "open_up"){
- $opensort = "open_down";
- }else{
-
- $opensort = "open_up";
- }
-
-
- if($search){
- $link1 = "<a>";
- $link2 = "<a>";
- $link3 = "<a>";
- }else{
-
- $link1 = "<a href='$url[base]/$file[tournament]?action=default&order=$tidsort'>";
- $link2 = "<a href='$url[base]/$file[tournament]?action=default&order=$namesort'>";
- $link3 = "<a href='$url[base]/$file[tournament]?action=default&order=$laddersort'>";
- $link4 = "<a href='$url[base]/$file[tournament]?action=default&order=$opensort'>";
- }
-
- $tablehead=table_head("show","80%","","left");
- $tablefoot=table_foot("show");
- $bannerhead=table_head("show","488","80","center");
- $bannerfoot=table_foot("show");
- $out[body]=$out[body]."
- <center>
- $bannerhead
- $out[banner]
- $bannerfoot <br>
- $tablehead <strong>
- <strong><font class='catfont'>Tournaments</font></strong>
- <hr class='catfont' size='1'>
- <center>
- <table width='690' border='0' cellpadding='1' cellspacing='1'>
- <tr class='altcolor'>
- <td align='center' width='60'><b>$link1 TID</a></b></td>
- <td align='left' width='280'><b>$link2 Tournament</a></b></td>
- <td align='center' width='70'><b>$link4 Status</b></td>
- <td align='center' width='70'><b>$link3 Ladder</a></b></td>
- <td align='center' width='70'><b>Signups</b></td>
- <td align='center' width='70'><b>Details</b></td>
- <td align='center' width='70'><b>Brackets</b></td>
- <td align='center' width='70'><b>Signup</b></td>
- </tr>
- ";
- if($order == "name_up"){
- $order = "name";
- }else if ($order == "name_down"){
-
- $order = "name desc";
- }else if ($order == "tid_up"){
-
- $order = "tid";
- }else if ($order == "tid_down"){
-
- $order = "tid desc";
- }else if ($order == "ladderid_down"){
-
- $order = "ladderid";
- }else if ($order == "ladderid_up"){
-
- $order = "ladderid desc";
- }else if ($order == "open_down"){
-
- $order = "open";
- }else if ($order == "open_up"){
-
- $order = "open desc";
-
- }else{
-
- $order = "tid desc";
- }
-
- $tourneylist=mysql_query("SELECT tid,size,active,name,ladderid,open FROM tourneys ORDER BY $order");
- $altcolora="' class='altcolora";
- $altcolorb="' class='altcolorb";
- while(list($tid,$size,$active,$name,$ladderid,$open)=mysql_fetch_row($tourneylist)){
- if(($search[type]==1)&&($searchresult[$tid])){
- $resultmatch="1";
- $showmainlink="1";
- }
-
- elseif(($search[type]==2)&&($search[field]==$tid)){
- $resultmatch="1";
- $showmainlink="1";
- }
-
- elseif(($search[type]==3)&&($search[field]==$ladderid)){
- $resultmatch="1";
- $showmainlink="1";
- }
-
- elseif(($search[type]==1)||($search[type]==2)||($search[type]==3)){
- $resultmatch="";
- $showmainlink="1";
- }
-
- else{
- $resultmatch="1";
- $showmainlink="";
- }
-
- if($altladrow=="$altcolora"){
- $altladrow="$altcolorb";
- }else{
-
- $altladrow="$altcolora";
- }
-
- $signups=0;
- $tourneyreports=mysql_query("SELECT pid FROM players2 WHERE tid='$tid'");
- while(list($pid)=mysql_fetch_row($tourneyreports)){
- $signups++;
- }
-
- if($signups>0){
- $signuplink ="<a href='$site[homeurl]/$file[tournament]?tourney[id]=$tid&action=players'>";
- }else{
-
- $signuplink ="<a>";
- }
- if($open > 0){
- $open = "Open";
- }else{
- $open = "Closed";
- }
-
- if($resultmatch){
- $out[body]=$out[body]."
- <tr bgcolor='$altladrow'>
- <td align='center' width='60'>$searchresulta $tid $searchresultb</td>
- <td align='left' width='280'>$searchresulta $name $searchresultb</td>
- <td align='center' width='70'>$open</td>
- <td align='center' width='70'>$searchresulta <a href='$site[homeurl]/$file[ladder]?ladderid=$ladderid'> $ladderid</a> $searchresultb</td>
- <td align='center' width='70'> $signuplink $signups</a></td>
- <td align='center' width='70'><a href='$site[homeurl]/$file[tournament]?tourney[id]=$tid&action=details'>Details</a></td>
- <td align='center' width='70'><a href='$site[homeurl]/$file[tournament]?tourney[id]=$tid&action=brackets'>Brackets</a></td>
- <td align='center' width='70'><a href='$site[homeurl]/$file[tournament]?tourney[id]=$tid&action=signup'>Signup</a></td>
- </tr>
- ";
- }
-
- }
-
- if($showmainlink){
- $out[body]=$out[body]."
- <tr>
- <td align='right' width='500' colspan='5'><br><a href='./tournament.php'><b>List All Tournaments</b></a></td>
- </tr>
- ";
- }
-
- $out[body]=$out[body]."
- <tr class='altcolor'><td width='100%' colspan='8'> </td></tr>
- </table>
- <br>
- <form method='post'>
- Search For <input type='text' name='search[field]' value=''>
- In <select name='search[type]'>
- <option value='1'>Tournament Names</option>
- <option value='2'>Tournament ID's</option>
- <option value='3'>Ladder ID's</option>
- </select>
- <input type='submit' name='' value='Search >>'>
- </form>
- $tablefoot";
- include("$dir[curtheme]");
- }
-
- function tourney_search($search){
- }
-
- function tourney_details($tourney){
- global $tinfo,$dir, $url, $out, $plyr, $site, $uinfo, $misc;
- $SearchArray = array("\n","<",">");
- $ReplaceArray = array("<br>","<",">");
- $tinfo[details]=str_replace($SearchArray,$ReplaceArray,$tinfo[details]);
- $UrlSearchArray = array("/([^]_a-z0-9-=\"'\/])((https?|ftp|news):\/\/|www\.)([^ \r\n\(\)\*\^\$!`\"'\|\[\]\{\};<>]*)/si","/^((https?|ftp|news):\/\/|www\.)([^ \r\n\(\)\*\^\$!`\"'\|\[\]\{\};<>]*)/si",);
-
- $UrlReplaceArray = array("\\1<a href='\\2\\4' target='new'>\\2\\4</a>","<a href='\\2' target='new'>\\1\\3</a>");
- $tinfo[details]=preg_replace($UrlSearchArray,$UrlReplaceArray,$tinfo[details]);
- $tablehead=table_head("show","70%","","left");
- $tablefoot=table_foot("show");
- $bannerhead=table_head("show","488","80","center");
- $bannerfoot=table_foot("show");
- $out[body]=$out[body]."
- <center>
- $bannerhead
- $out[banner]
- $bannerfoot <br>
- $tablehead <strong>
- <left>
- <b>$tinfo[name] Details</b><br>
- <hr class='catfont' size='1'>
- <center>
-
- <table width='100%' border='0' cellpadding='1' cellspacing='1' align='left'>
- <td align='left' width='100%'><b>Tournament Directors: $tinfo[directors] </b><br><br> $tinfo[details]</td>
- </tr>
- </table>
- <br>
- $tablefoot";
- include("$dir[curtheme]");
- }
-
- function tourney_signup(){
- global $tinfo,$dir, $url, $out, $plyr, $site, $uinfo, $misc;
- if($tinfo[active]){
- if(!$plyr[id]){
- include("$dir[func]/error.php");
- display_error("You are not logged in.<br>");
- }
-
- $check = mysql_query("SELECT id FROM ladders WHERE id = '$tinfo[ladderid]'");
-
- if(!($checkb = mysql_fetch_array($check))){
- include("$dir[func]/error.php");
- display_error("This tournament is no longer valid.<br>");
- }
-
-
- $teamson = mysql_query("SELECT teamid FROM teammembers WHERE playerid = '$plyr[id]' AND status < 3");
- while($row = mysql_fetch_array($teamson)){
- $check = mysql_query("SELECT id FROM ladder_$tinfo[ladderid] WHERE id ='$row[teamid]'");
- if($checkb = mysql_fetch_array($check)){
- $name = mysql_fetch_array(mysql_query("SELECT teamname FROM teams WHERE id ='$checkb[id]'"));
- $team = $name[teamname];
- }
-
- }
-
- if(!$team){
- include("$dir[func]/error.php");
- display_error("You are not logged in as the team leader<br> or co-team leader of any team on this ladder!.<br>");
- }
-
- if($tinfo[open] < 1){
- include("$dir[func]/error.php");
- display_error("Tournament is now closed for signups.<br>");
- }
-
- $tablehead=table_head("show","80%","","left");
- $tablefoot=table_foot("show");
- $bannerhead=table_head("show","488","80","center");
- $bannerfoot=table_foot("show");
- $out[body]=$out[body]."
- <center>
- $bannerhead
- $out[banner]
- $bannerfoot <br>
- $tablehead <strong>
- <center>
- <table width='600' border='1' bordercolor='#000000' cellspacing='0' cellpadding='2'>
- <tr class='altcolor'>
- <form method='post'>
- <td width='100%' valign='top' align='center' colspan='2'>
- <strong>$tinfo[name] Signup</strong><br>
- </td></tr>
- <tr class='altcolora'>";
- $out[body]=$out[body]."
- <form method='post'>
-
- <td align='left' width='200'><b>Name</b></td>
- <td align='center' width='200'>$team</td>
- </tr>
- ";
- if($tinfo[field1]){
- $out[body]=$out[body]."
- <tr class='altcolorb'>
- <td align='left' width='200'><b>$tinfo[field1]</b></td>
- <td align='center' width='200'><input type='text' name='signup[field1]' value='' size='30' maxlength='100'></td>
- </tr>
- ";
- }
-
- if($tinfo[field2]){
- $out[body]=$out[body]."
- <tr class='altcolora'>
- <td align='left' width='200'><b>$tinfo[field2]</b></td>
- <td align='center' width='200'><input type='text' name='signup[field2]' value='' size='30' maxlength='100'></td>
- </tr>
- ";
- }
-
- if($tinfo[field3]){
- $out[body]=$out[body]."
- <tr class='altcolorb'>
- <td align='left' width='200'><b>$tinfo[field3]</b></td>
- <td align='center' width='200'><input type='text' name='signup[field3]' value='' size='30' maxlength='100'></td>
- </tr>
- ";
- }
-
- $out[body]=$out[body]."
- <tr class='altcolor'>
- <td align='center' width='600' colspan='2'>
- <input type='hidden' name='signup[name]' value='$team'>
- <input type='hidden' name='action' value='tourney_signup_2'>
- <input type='submit' name='' value='Signup'></td>
- </tr>
- </form>
- </table>
- ";
- }else{
-
- $out[body]=$out[body]."
- <br><b>Signups are currently disabled</b><br>
- ";
- }
-
- $out[body]=$out[body]."
- <br>
- $tablefoot";
- include("$dir[curtheme]");
- }
-
- function tourney_signup_2($signup){
- global $tinfo, $dir, $url, $out, $plyr, $site, $uinfo, $misc;
- while(list($varib,$value)=each($signup)){
- $signup[$varib]=characters($value);
- if(!$signup[$varib]){
- include("$dir[func]/error.php");
- display_error("All fields are required.");
- }
-
- }
-
- if(mysql_num_rows(mysql_query("SELECT pid FROM players2 WHERE tid='$tinfo[tid]' AND name='$signup[name]'"))){
- include("$dir[func]/error.php");
- display_error("Your team is already in this tournament.");
- }
-
- $playerip = getenv("REMOTE_ADDR");
- if($misc[tourneyip] == 'no'){
- if(mysql_num_rows(mysql_query("SELECT pid FROM players2 WHERE tid='$tinfo[tid]' AND ipaddress='$playerip'"))){
- include("$dir[func]/error.php");
- display_error("Your IP Adddress is already in use on this tournament.");
- }
- }
-
- $teamid=mysql_query("SELECT id,teamemail FROM teams WHERE teamname='$signup[name]'");
- $team=mysql_fetch_array($teamid);
- $timeStamp = date("YmdHis");
- mysql_query("INSERT INTO players2 VALUES ('$team[id]','$tinfo[tid]','$playerip',' $timeStamp','$signup[name]','$team[teamemail]','$tinfo[field1]','$tinfo[field2]','$tinfo[field3]')");
- $tablehead=table_head("show","70%","","left");
- $tablefoot=table_foot("show");
- $bannerhead=table_head("show","488","80","center");
- $bannerfoot=table_foot("show");
- $out[body]=$out[body]."
- <center>
- $bannerhead
- $out[banner]
- $bannerfoot <br>
- $tablehead <strong>
- <center>
- <font class='catfont'>You have been added to the player signups!<br>
- Entering the tournament does not guarantee you a spot.</b><br>
- <br>
- </center>
- $tablefoot";
- include("$dir[curtheme]");
- }
-
- function tourney_players(){
- global $tinfo,$dir,$url,$out,$file;
- $tablehead=table_head("show","60%","","left");
- $tablefoot=table_foot("show");
- $bannerhead=table_head("show","488","80","center");
- $bannerfoot=table_foot("show");
- $out[body]=$out[body]."
- <center>
- $bannerhead
- $out[banner]
- $bannerfoot <br>
- $tablehead <strong>
- <center>
- <b>$tinfo[name] Players</b><br>
- <br>
- <table width='250' border='0' cellpadding='1' cellspacing='1'>
- <tr class='altcolor'>
- <td align='center' width='50'><b>#</b></td>
- <td align='center' width='200'><b>Name</b></td>
- </tr>
- ";
- $tourneyreports=mysql_query("SELECT pid,name FROM players2 WHERE tid='$tinfo[tid]' ORDER BY joined");
- while(list($pid,$name)=mysql_fetch_row($tourneyreports)){
- $count++;
- if($altcolorv == 'altcolorb'){
- $altcolorv = 'altcolora';
- }else{
- $altcolorv = 'altcolorb';
- }
- $out[body]=$out[body]."
- <tr class=$altcolorv>
- <td align='center' width='50'>$count</td>
- <td align='center' width='200'><a href='$url[base]/$file[teams]?teamid=$pid'>$name</a></td>
- </tr>
- ";
- }
-
- $out[body]=$out[body]."
- <tr class='altcolor'><td colspan='2'><br></td></tr>
- </table>
- <br>
- $tablefoot";
- include("$dir[curtheme]");
- }
-
- function tourney_brackets(){
- global $tinfo,$dir, $url, $out, $plyr, $site, $uinfo, $misc, $file;
- $brackets=mysql_query("SELECT bid,pid,name FROM brackets2 WHERE tid='$tinfo[tid]' ORDER BY bid");
- while(list($bid,$pid,$name)=mysql_fetch_row($brackets)){
- if($pid){
- $bracket[$bid]="<font type='arial' size='2'><a href='$url[base]/$file[teams]?teamid=$pid'>$name</a></font>";
- }else{
-
- $bracket[$bid]="$name";
- }
-
- $pid="";
- }
-
- $brackets="$tinfo[size]";
- $spots=($brackets * 2 - 1);
- $temp_rows="$brackets";
- while($temp_rows > 1){
- $rowcount++;
- if($rowcount > 1){
- $temp_rows=($temp_rows / 2);
- }
-
- $listrows.="-> $temp_rows";
- $rows="$rowcount";
- }
-
- $rowwidths=round(100 / $rows - 0.5);
- $actualrows=($rows * 2);
- ////////////////////////////////
- $tablehead=table_head("show","100%","","left");
- $tablefoot=table_foot("show");
- $bannerhead=table_head("show","488","80","center");
- $bannerfoot=table_foot("show");
- $out[body]=$out[body]."
- <center>
- $bannerhead
- $out[banner]
- $bannerfoot <br>
- $tablehead <strong>
- <table width='100%' border='1' bordercolor='#000000' cellspacing='0' cellpadding='2'>
- <tr class ='altcolor'>
- <td width='100%' valign='top' align='center'>
- <b>$tinfo[name] Brackets</b><br>
- </td></tr></table>
- <br><br>
- <table border='0' width='100%' cellspacing='0' cellpadding='0'>
- <tr>
- ";
- $counter="$brackets";
- while($counter > 1){
- if($round){
- $counter=($counter / 2);
- }
-
- $lastcb="$countbrackets";
- $countbrackets="";
- $game="";
- $round++;
- $finals=($rows - 1);
- $winner=($rows);
- $roundgamesay="Round $round Games";
- if($round=="$winner"){
- $roundgamesay="Winner!";
- }
-
- if($round=="$finals"){
- $roundgamesay="Finals";
- }
-
- $out[body]=$out[body]."
- <td align='center' valign='center' width='$rowwidths%' colspan='2'><b>$roundgamesay</b><br>
- <table border='0' width='100%' bordercolor='#FF0000' cellspacing='0' cellpadding='0'>
- ";
- $spacesetcount="";
- while($countbrackets < $counter){
- $countbrackets++;
- $spot++;
- $spacesetcount++;
- if($spacesetcount=="4"){
- $spacesetcount="";
- }
-
- $bracketid="$round"."_"."$countbrackets";
- $out[body]=$out[body]."
- <tr class='altcolor'>
- <td align='left' valign='center' width='100%' class='altcolor'>$bracket[$bracketid]</td>
- <td align='left' valign='center' width='100%'> </td>
- </tr>
- ";
- if($countbrackets < $counter){
- $spacecounter++;
- $spacecounter=($spacecounter + 1);
- if($spacecounter==2){
- $roundx2p1=($lastroundx2p1 * 2 + 1);
- if($round==1){
- $roundx2p1="1";
- }
-
- while($countspaces < $roundx2p1){
- $countspaces++;
- $spacecentercount++;
- $spacecenterword="";
- $alignspacer1="left";
- $spacecentercountcheck=($lastroundx2p1 + 1);
- if($spacecentercount=="$spacecentercountcheck"){
- $spacecenterwordcount++;
- if(($spacecenterwordcount==1)||($spacecenterwordcount==3)){
- $actualgamecount++;
- $spacecenterword="<b>Game $actualgamecount</b>";
- $alignspacer1="center";
- if($spacecenterwordcount==3){
- $spacecenterwordcount="";
- $spacecenterwordcount++;
- }
-
- }
-
- }
-
- $out[body]=$out[body]."
- <tr>
- <td align='$alignspacer1' valign='center'> $spacecenterword</td>
- <td align='left' valign='center' class='altcolor'> </td>
- </tr>
- ";
- }
-
- $spacecounter="";
- $countspaces="";
- $spacecentercount="";
- }
-
- }
-
- }
-
- $spacecenterwordcount="";
- $actualgamecount="";
- $lastroundx2p1="$roundx2p1";
- $out[body]=$out[body]."
- </table>
- </td>
- ";
- }
-
- $out[body]=$out[body]."
- </tr>
- </table><br><br>
- <table width='100%' border='1' bordercolor='#000000' cellspacing='0' cellpadding='2'>
- <tr class ='altcolor'>
- <td width='100%' valign='top' align='center'>
- <br>
- </td></tr></table>
- <br>
- $tablefoot";
- include("$dir[curtheme]");
- }
-
- ?>