PageRenderTime 50ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/functions/challengefinalize.php

https://bitbucket.org/verax/to-ladder
PHP | 324 lines | 280 code | 35 blank | 9 comment | 30 complexity | 21c2d2d45378c80e9e46ee0436a6259f MD5 | raw file
  1. <?
  2. if(!IsSet($indexloaded)){
  3. header("Location: ./index.php");
  4. }
  5. function challenge_finalize($challid){
  6. global $dir, $file, $url, $out, $plyr;
  7. if(!$challid){
  8. include("$dir[func]/error.php");
  9. display_error("Invalid Challenge ID.<br>");
  10. }
  11. //FIND AND DELETE/AWARD WINS FOR UNFINALIZED CHALLENGES
  12. include("$dir[func]/challengeforfeit.php");
  13. check_unrespondedchallenges();
  14. $challengeinfo=mysql_query("SELECT * FROM challenges WHERE challid='$challid'");
  15. $chall=mysql_fetch_array($challengeinfo);
  16. if(!$chall[challenger]){
  17. include("$dir[func]/error.php");
  18. display_error("Unknown Challenge ID.<br>");
  19. }
  20. if($chall[finalizedby] > 0){
  21. include("$dir[func]/error.php");
  22. display_error("This match has already been finalized.<br>");
  23. }
  24. if($chall[respondedby] < 1){
  25. include("$dir[func]/error.php");
  26. display_error("This match hasnt been responed to yet.<br>");
  27. }
  28. if(mysql_num_rows(mysql_query("SELECT teamid FROM teammembers WHERE playerid='$plyr[id]' AND teamid='$chall[challenger]' AND status <= '3'")) < 1){
  29. include("$dir[func]/error.php");
  30. display_error("You cannot finalize challenges for this team.<br>");
  31. }
  32. $challengerinfo=mysql_query("SELECT teamname FROM teams WHERE id='$chall[challenger]'");
  33. $chgrnfo=mysql_fetch_array($challengerinfo);
  34. if(!$chgrnfo[teamname]){
  35. include("$dir[func]/error.php");
  36. display_error("Unable to find your team.<br>");
  37. }
  38. $challengedinfo=mysql_query("SELECT teamname FROM teams WHERE id='$chall[challenged]' ");
  39. $chgdnfo=mysql_fetch_array($challengedinfo);
  40. if(!$chgdnfo[teamname]){
  41. include("$dir[func]/error.php");
  42. display_error("Unable to find the challenged teams information.<br>");
  43. }
  44. $ladderinfo=mysql_query("SELECT * FROM ladders WHERE id='$chall[ladderid]'");
  45. $linfo=mysql_fetch_array($ladderinfo);
  46. //GET SELECTED TIMES
  47. $availmatchtimes=split(",",$chall[matchtimes]);
  48. while(list($countimes,$matchtimes)=each($availmatchtimes)){
  49. if($matchtimes){
  50. $countimes=($countimes+1);
  51. $timesavailable=$timesavailable."<option value='$countimes'>$matchtimes</a>";
  52. $matchtimesfound=1;
  53. }
  54. }
  55. if($matchtimesfound){
  56. $timeoptions=$timeoptions."
  57. <tr class='altcolora'>
  58. <td width='50%' valign='center' align='left'>
  59. <font face='veradna,arial' size='2' color='#FFFFFF'>Match Time</font></td>
  60. <td width='50%' valign='center' align='center'>
  61. <select name='time'>$timesavailable</select></td>
  62. </tr>";
  63. }else{
  64. include("$dir[func]/error.php");
  65. display_error("Invalid match times.<br>Contact Staff.<br>");
  66. }
  67. //GET SELECTED MAPS
  68. $availmatchmaps=split(",",$chall[matchmaps]);
  69. while(list($countmaps,$matchmaps)=each($availmatchmaps)){
  70. if($matchmaps){
  71. $countmaps=($countmaps+1);
  72. $mapsinfo=mysql_query("SELECT mapname FROM maps WHERE id='$matchmaps'");
  73. $minfo=mysql_fetch_array($mapsinfo);
  74. $maplist=$maplist."
  75. <tr class='altcolora'>
  76. <td width='50%' valign='center' align='left'>
  77. <font face='veradna,arial' size='2' color='#FFFFFF'>#$countmaps
  78. <a href='$url[base]/$file[maps]?mapid=$matchmaps' target='top'>$minfo[mapname]</a></font></td>
  79. <td width='50%' valign='center' align='center'>
  80. Play <input type='checkbox' name='map[$countmaps]' value='$matchmaps'></td>
  81. </tr>";
  82. $matchmapsfound=1;
  83. }
  84. }
  85. $out[body]=$out[body]."
  86. <br><br><br>
  87. <table width='80%' border='1' bordercolor='#000000' cellspacing='5' cellpadding='2' align='center'>
  88. <tr class='altcolor'>
  89. <td width='100%' valign='top' align='center'>
  90. <font class='catfont'><strong>$chgrnfo[teamname] vs $chgdnfo[teamname]</strong></font></td>
  91. </tr>
  92. <tr>
  93. <td width='100%' valign='top' align='left'>
  94. <form method='post'>
  95. <table width='100%' border='0' cellspacing='0' cellpadding='0' valign='top' align='center'>
  96. <tr>
  97. <td width='100%' valign='top' align='left'>
  98. <li><b>Your teams comments:</b> $chall[challengercomment]<br>
  99. <li><b>Comments from the challenged team:</b> $chall[challengedcomment]</td>
  100. </tr>
  101. </table>
  102. </td>
  103. </tr>
  104. <tr class='altcolor'>
  105. <td width='100%' valign='top' align='center'>
  106. <font class='catfont'><strong>Select the time you want to have the match</strong></font></td>
  107. </tr>
  108. <tr>
  109. <td width='100%' valign='top' align='left'>
  110. <table width='100%' border='0' cellspacing='0' cellpadding='0' valign='top' align='center'>
  111. $timeoptions
  112. </table>
  113. </td>
  114. </tr>";
  115. if($chall[matchmaps]){
  116. $out[body]=$out[body]."
  117. <tr class='altcolor'>
  118. <td width='100%' valign='top' align='center'>
  119. <font class='catfont'><strong>Select $linfo[mapscanaccept] of the maps below to play in the match</strong></font></td>
  120. </tr>
  121. <tr>
  122. <td width='100%' valign='top' align='left'>
  123. <table width='100%' border='0' cellspacing='0' cellpadding='0' valign='top' align='center'>
  124. $maplist
  125. </table>
  126. <br>
  127. </td>
  128. </tr>";
  129. }
  130. $out[body]=$out[body]."
  131. <tr class='altcolor'>
  132. <td width='100%' valign='top' align='center'>
  133. <table width='100%' border='0' cellspacing='0' cellpadding='0'>
  134. <tr>
  135. <td width='50%' valign='top' align='center'>
  136. <input type='hidden' name='challid' value='$challid'>
  137. <input type='hidden' name='action' value='finalizeb'>
  138. <input type='submit' name='' value='Accept Challenge'>
  139. </td>
  140. </form>
  141. <script language='javascript'>var forfeit='Are you sure you want to FORFEIT and recieve a LOSS to $chgdnfo[teamname]';</script>
  142. <form method='post'>
  143. <td width='50%' valign='top' align='center'>
  144. <input type='hidden' name='challid' value='$challid'>
  145. <input type='hidden' name='action' value='forfeit'>
  146. <input type='submit' name='' value='Forfeit Challenge' onClick='return confirm(forfeit);'>
  147. </td>
  148. </form>
  149. </tr>
  150. </table>
  151. </td>
  152. </tr>
  153. </table>";
  154. include("$dir[curtheme]");
  155. }
  156. function challenge_finalizeb($challid,$time,$maps){
  157. global $dir, $file, $url, $out, $plyr;
  158. if(!$challid){
  159. include("$dir[func]/error.php");
  160. display_error("Invalid Challenge ID.<br>");
  161. }
  162. if(!$time){
  163. include("$dir[func]/error.php");
  164. display_error("Invalid Match Time.<br>");
  165. }
  166. if ($chall[matchmaps]){
  167. if(!$maps){
  168. include("$dir[func]/error.php");
  169. display_error("You need to select the maps to play.<br>");
  170. }
  171. }
  172. $challengeinfo=mysql_query("SELECT * FROM challenges WHERE challid='$challid'");
  173. $chall=mysql_fetch_array($challengeinfo);
  174. if(!$chall[challenger]){
  175. include("$dir[func]/error.php");
  176. display_error("Unknown Challenge ID.<br>");
  177. }
  178. if($chall[finalizedby] > 0){
  179. include("$dir[func]/error.php");
  180. display_error("This match has already been finalized.<br>");
  181. }
  182. if($chall[respondedby] < 1){
  183. include("$dir[func]/error.php");
  184. display_error("This match hasnt been responed to yet.<br>");
  185. }
  186. if(mysql_num_rows(mysql_query("SELECT teamid FROM teammembers WHERE playerid='$plyr[id]' AND teamid='$chall[challenger]' AND status <= '3'")) < 1){
  187. include("$dir[func]/error.php");
  188. display_error("You cannot finalize challenges for this team.<br>");
  189. }
  190. $challengerinfo=mysql_query("SELECT teamname,teamemail FROM teams WHERE id='$chall[challenger]' ");
  191. $chgrnfo=mysql_fetch_array($challengerinfo);
  192. if(!$chgrnfo[teamname]){
  193. include("$dir[func]/error.php");
  194. display_error("Unable to find your team.<br>");
  195. }
  196. $challengedinfo=mysql_query("SELECT teamname,teamemail FROM teams WHERE id='$chall[challenged]'");
  197. $chgdnfo=mysql_fetch_array($challengedinfo);
  198. if(!$chgdnfo[teamname]){
  199. include("$dir[func]/error.php");
  200. display_error("Unable to find the challenged teams information.<br>");
  201. }
  202. $ladderinfo=mysql_query("SELECT * FROM ladders WHERE id='$chall[ladderid]'");
  203. $linfo=mysql_fetch_array($ladderinfo);
  204. //GET SELECTED TIME
  205. $availmatchtimes=split(",",$chall[matchtimes]);
  206. while(list($countimes,$matchtimes)=each($availmatchtimes)){
  207. if($matchtimes){
  208. $countimes=($countimes+1);
  209. if($countimes=="$time"){
  210. $finalmatchtime="$matchtimes";
  211. $matchtimesfound=1;
  212. }
  213. }
  214. }
  215. if(!$matchtimesfound){
  216. include("$dir[func]/error.php");
  217. display_error("Invalid match time.<br>");
  218. }
  219. if($maps){
  220. while(list($mapcount,$mapplay)=each($maps)){
  221. $countmaps=($countmaps +1);
  222. $finalmaps=$finalmaps."$mapplay,";
  223. }
  224. }
  225. if($chall[matchmaps]){
  226. if($countmaps!=$linfo[mapscanaccept]){
  227. include("$dir[func]/error.php");
  228. display_error("You must select $linfo[mapscanaccept] of the available maps.<br>");
  229. }
  230. }
  231. //FINALIZE CHALLENGE
  232. $tday=date("Y-m-d H:i:s");
  233. mysql_query("UPDATE challenges SET
  234. finaltime='$finalmatchtime',
  235. finalmaps='$finalmaps',
  236. finalizedby='$plyr[id]',
  237. finalizedtime='$tday'
  238. WHERE challid='$challid'");
  239. //Tuesday Jul 17 @ 07 pm Eastern Standard Time
  240. $stmatch=split(" ",$finalmatchtime);
  241. //UPDATE CHALLENGER
  242. mysql_query("UPDATE ladder_$chall[ladderid] SET
  243. statusdisplay='<a href=$url[base]/$file[match]?challid=$challid>Upcoming Match $stmatch[1] $stmatch[2]</a>'
  244. WHERE id='$chall[challenger]'");
  245. //UPDATE CHALLENGED
  246. mysql_query("UPDATE ladder_$chall[ladderid] SET
  247. statusdisplay='<a href=$url[base]/$file[match]?challid=$challid>Upcoming Match $stmatch[1] $stmatch[2]</a>'
  248. WHERE id='$chall[challenged]'");
  249. //SEND EMAIL TO CHALLENGED
  250. $emailbody="$site[shortname] Challenge Information,\n
  251. The challenge has been finalized and the match set!\n
  252. Challenging Team: $chgrnfo[teamname]
  253. $url[base]/$file[teams]?teamid=$chall[challenger]
  254. Challenged Team: $chgdnfo[teamname]
  255. $url[base]/$file[teams]?teamid=$chall[challenged]
  256. Ladder: $linfo[laddername]
  257. $url[base]/$file[ladder]?ladderid=$chall[ladderid]\n
  258. Go to the following url to view the details of this challenge.
  259. $url[base]/$file[match]?challid=$challid";
  260. include("$dir[func]/email.php");
  261. send_email($chgrnfo[teamname],$chgrnfo[teamemail],"Match Set","$emailbody");
  262. send_email($chgdnfo[teamname],$chgdnfo[teamemail],"Match Set","$emailbody");
  263. $out[body]=$out[body]."
  264. <br><br>
  265. <table width='100%' border='1' bordercolor='#000000' cellspacing='0' cellpadding='2'>
  266. <tr class='altcolor'>
  267. <td width='100%' valign='top' align='center'>
  268. <strong>The Challenge has been finalized</strong><br>
  269. </td>
  270. </tr>
  271. <tr>
  272. <td width='100%' valign='center' align='left'>
  273. <br><ul>
  274. Ladder: <a href='$url[base]/$file[ladder]?ladderid=$chall[ladderid]'>$linfo[laddername]</a><br>
  275. Challenger: <a href='$url[base]/$file[teams]?teamid=$chall[challenger]'>$chgrnfo[teamname]</a><br>
  276. Challenger Rank: $chall[challengerrank]<br>
  277. Challenged: <a href='$url[base]/$file[teams]?teamid=$chall[challenged]'>$chgdnfo[teamname]</a><br>
  278. Challenged Rank: $chall[challengedrank]<br>
  279. </ul></td>
  280. </tr>
  281. <tr class='altcolor'>
  282. <td width='100%' valign='top' align='center'>
  283. <strong><a href='$url[base]/$file[match]?challid=$challid'>View the challenge</a></strong><br>
  284. </td>
  285. </tr>
  286. </table>";
  287. include("$dir[curtheme]");
  288. }
  289. ?>