PageRenderTime 39ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/functions/challengerespond.php

https://bitbucket.org/verax/to-ladder
PHP | 363 lines | 328 code | 13 blank | 22 comment | 9 complexity | aefad09c428a369accbcfbc9247b583d MD5 | raw file
  1. <?
  2. function challenge_respond($challid){
  3. global $dir, $file, $url, $out, $plyr;
  4. if(!$challid){
  5. include("$dir[func]/error.php");
  6. display_error("Invalid Challenge ID.<br>");
  7. }
  8. $challengeinfo=mysql_query("SELECT * FROM challenges WHERE challid='$challid'");
  9. $chall=mysql_fetch_array($challengeinfo);
  10. if(!$chall[challenger]){
  11. include("$dir[func]/error.php");
  12. display_error("Unknown Challenge ID.<br>");
  13. }
  14. if($chall[finalizedby] > 0){
  15. include("$dir[func]/error.php");
  16. display_error("This match has already been finalized.<br>");
  17. }
  18. if($chall[respondedby] > 0){
  19. include("$dir[func]/error.php");
  20. display_error("This match has already been responed to.<br>");
  21. }
  22. if(mysql_num_rows(mysql_query("SELECT teamid FROM teammembers WHERE playerid='$plyr[id]' AND teamid='$chall[challenged]' AND status <= '3'")) < 1){
  23. include("$dir[func]/error.php");
  24. display_error("You cannot respond to challenges for this team.<br>");
  25. }
  26. $challengerinfo=mysql_query("SELECT teamname FROM teams WHERE id='$chall[challenger]'");
  27. $chgrnfo=mysql_fetch_array($challengerinfo);
  28. if(!$chgrnfo[teamname]){
  29. include("$dir[func]/error.php");
  30. display_error("Unable to find challengers team.<br>");
  31. }
  32. $challengedinfo=mysql_query("SELECT teamname FROM teams WHERE id='$chall[challenged]'");
  33. $chgdnfo=mysql_fetch_array($challengedinfo);
  34. if(!$chgdnfo[teamname]){
  35. include("$dir[func]/error.php");
  36. display_error("Unable to find your teams information.<br>");
  37. }
  38. $ladderinfo=mysql_query("SELECT * FROM ladders WHERE id='$chall[ladderid]'");
  39. $linfo=mysql_fetch_array($ladderinfo);
  40. /*
  41. INFO NEEDED
  42. -> from ladders
  43. playdays
  44. timescangive
  45. mapscangive
  46. starthour
  47. endhour
  48. timezone
  49. finalizehours
  50. -> to challenges
  51. matchtimes
  52. matchmaps
  53. challengedcomment
  54. respondedby
  55. respondedtime
  56. */
  57. //GET DAYS MATCH CAN BE ON
  58. $finalizehours=$linfo[finalizehours];
  59. $playdays=$linfo[playdays];
  60. $spreadhours=24;
  61. $starthours=($finalizehours + $spreadhours);
  62. while($countdays < $playdays){
  63. $thisday=date("l M d", mktime(date("H")+$starthours,date("i"),date("s"),date("m"),date("d")+$countdays,date("Y")));
  64. //$challengedays=$challengedays."<option>$thisday</option>";
  65. //GET CHALLENGABLE HOURS
  66. $hour="$linfo[starthour]";
  67. $stophour=($linfo[endhour] + 1);
  68. while(($hour < $stophour) && ($hour < 25)){
  69. $thishour=date("g a", mktime($hour,1,1,1,1,1));
  70. $challengetimes=$challengetimes."<option>$thisday @ $thishour $linfo[timezone]</option>";
  71. $hour++;
  72. }
  73. $countdays++;
  74. }
  75. //HOW MANY TIME CHALLENGER CAN GIVE
  76. $counttimes=1;
  77. $timescount=($linfo[timescangive] + 1);
  78. while($counttimes < $timescount){
  79. $timeoptions=$timeoptions."
  80. <tr class='altcolora'>
  81. <td width='50%' valign='center' align='left'>
  82. <font face='veradna,arial' size='2' color='#FFFFFF'>Match Time Option #$counttimes</font></td>
  83. <td width='50%' valign='center' align='center'>
  84. <select name='time[$counttimes]'>$challengetimes</select></td>
  85. </tr>";
  86. $counttimes++;
  87. }
  88. //MAPS AVAILABLE
  89. $mapsplayed=mysql_query("SELECT id,mapname FROM maps WHERE ladderid='$chall[ladderid]' ORDER by mapname");
  90. while(list($mapid,$mapname)=mysql_fetch_row($mapsplayed)){
  91. $maps=$maps."<option value='$mapid'>$mapname</option>";
  92. }
  93. $mapnum=1;
  94. while($mapnum <= $linfo[mapscangive]){
  95. $maplist=$maplist."
  96. <tr class='altcolora'>
  97. <td width='50%' valign='center' align='left'>
  98. <font face='veradna,arial' size='2' color='#FFFFFF'>Map Option #$mapnum</font></td>
  99. <td width='50%' valign='center' align='center'>
  100. <select name='map[$mapnum]'>$maps</select></td>
  101. </tr>";
  102. $mapnum++;
  103. }
  104. $out[body]=$out[body]."
  105. <br><br>
  106. <table width='80%' border='1' bordercolor='#000000' cellspacing=5' cellpadding='2' align='center'>
  107. <tr class='altcolor'>
  108. <td width='100%' valign='top' align='center'>
  109. <font class='catfont'><strong>$chgrnfo[teamname] vs $chgdnfo[teamname]</strong></font></td>
  110. </tr>
  111. <tr>
  112. <td width='100%' valign='top' align='left'>
  113. <form method='post'>
  114. <table width='100%' border='0' cellspacing='0' cellpadding='0' valign='top' align='center'>
  115. <tr>
  116. <td width='100%' valign='top' align='left'>
  117. <li><b>Comments from the challenger:</b> $chall[challengercomment]</td>
  118. </tr>
  119. </table>
  120. </td>
  121. </tr>
  122. <tr class='altcolor'>
  123. <td width='100%' valign='top' align='center'>
  124. <font class='catfont'><strong>Select match times for the challenger to pick from</strong></font></td>
  125. </tr>
  126. <tr>
  127. <td width='100%' valign='top' align='left'>
  128. <table width='100%' border='0' cellspacing='0' cellpadding='0' valign='top' align='center'>
  129. $timeoptions
  130. </table>
  131. </td>
  132. </tr>";
  133. if(($linfo[minmaps] > 0)&&($linfo[maxmaps] > 0)){
  134. $out[body]=$out[body]."
  135. <tr class='altcolor'>
  136. <td width='100%' valign='top' align='center'>
  137. <font class='catfont'><strong>Select Maps for the challenger to pick from</strong></font></td>
  138. </tr>
  139. <tr>
  140. <td width='100%' valign='top' align='left'>
  141. <table width='100%' border='0' cellspacing='0' cellpadding='0' valign='top' align='center'>
  142. $maplist
  143. </table>
  144. </td>
  145. </tr>
  146. ";
  147. }
  148. $out[body]=$out[body]."
  149. <tr class='altcolor'>
  150. <td width='100%' valign='top' align='center'>
  151. <font class='catfont'><strong>Server/Host and Misc. Information</strong></font></td>
  152. </tr>
  153. <tr>
  154. <td width='100%' valign='top' align='center'>
  155. <textarea name='comment' rows='5' cols='50' maxlength='200'>
  156. </textarea><br>
  157. 200 Characters Max
  158. </td>
  159. </tr>
  160. <tr class='altcolor'>
  161. <td width='100%' valign='top' align='center'>
  162. <table width='100%' border='0' cellspacing='0' cellpadding='0'>
  163. <tr>
  164. <td width='50%' valign='top' align='center'>
  165. <input type='hidden' name='challid' value='$challid'>
  166. <input type='hidden' name='action' value='respondb'>
  167. <input type='submit' name='' value='Accept Challenge'>
  168. </td>
  169. </form>
  170. <script language='javascript'>var forfeit='Are you sure you want to FORFEIT and recieve a LOSS to $chgrnfo[teamname]';</script>
  171. <form method='post'>
  172. <td width='50%' valign='top' align='center'>
  173. <input type='hidden' name='challid' value='$challid'>
  174. <input type='hidden' name='action' value='forfeit'>
  175. <input type='submit' name='' value='Forfeit Challenge' onClick='return confirm(forfeit);'>
  176. </td>
  177. </form>
  178. </tr>
  179. </table>
  180. </td>
  181. </tr>
  182. </table>";
  183. include("$dir[curtheme]");
  184. }
  185. function challenge_respondb($challid,$time,$map,$comment){
  186. global $dir, $file, $url, $out, $plyr;
  187. if(!$challid){
  188. include("$dir[func]/error.php");
  189. display_error("Invalid Challenge ID.<br>");
  190. }
  191. $challengeinfo=mysql_query("SELECT * FROM challenges WHERE challid='$challid'");
  192. $chall=mysql_fetch_array($challengeinfo);
  193. if(!$chall[challenger]){
  194. include("$dir[func]/error.php");
  195. display_error("Unknown Challenge ID.<br>");
  196. }
  197. if($chall[finalizedby] > 0){
  198. include("$dir[func]/error.php");
  199. display_error("This match has already been finalized.<br>");
  200. }
  201. if($chall[respondedby] > 0){
  202. include("$dir[func]/error.php");
  203. display_error("This match has already been responed to.<br>");
  204. }
  205. if(mysql_num_rows(mysql_query("SELECT teamid FROM teammembers WHERE playerid='$plyr[id]' AND teamid='$chall[challenged]' AND status <= '3'")) < 1){
  206. include("$dir[func]/error.php");
  207. display_error("You cannot respond to challenges for this team.<br>");
  208. }
  209. $challengerinfo=mysql_query("SELECT teamname,teamemail FROM teams WHERE id='$chall[challenger]'");
  210. $chgrnfo=mysql_fetch_array($challengerinfo);
  211. if(!$chgrnfo[teamname]){
  212. include("$dir[func]/error.php");
  213. display_error("Unable to find challengers team.<br>");
  214. }
  215. $challengedinfo=mysql_query("SELECT teamname FROM teams WHERE id='$chall[challenged]'");
  216. $chgdnfo=mysql_fetch_array($challengedinfo);
  217. if(!$chgdnfo[teamname]){
  218. include("$dir[func]/error.php");
  219. display_error("Unable to find your teams information.<br>");
  220. }
  221. $ladderinfo=mysql_query("SELECT * FROM ladders WHERE id='$chall[ladderid]'");
  222. $linfo=mysql_fetch_array($ladderinfo);
  223. if(!$linfo[laddername]){
  224. include("$dir[func]/error.php");
  225. display_error("Invalid Ladder.<br>");
  226. }
  227. include("$dir[func]/checkdata.php");
  228. //GET ARRAY OF TIMES AND CHECK FOR DUPLICATES
  229. while(list($timenum,$timeday)=each($time)){
  230. $timeday=change_charecters($timeday);
  231. //STRIP ANY COMMAS
  232. $timeday=str_replace(",", "", $timeday);
  233. $secondtime="$firsttime";
  234. $thirdtime="$secondtimeb";
  235. if(($firsttime=="$timeday") || ($thirdtime=="$timeday")){
  236. include("$dir[func]/error.php");
  237. display_error("You must select different times and dates.<br>");
  238. }else{
  239. $matchtimes=$matchtimes."$timeday,";
  240. }
  241. $firsttime="$timeday";
  242. $secondtimeb="$secondtime";
  243. }
  244. //GET ARRAY OF MAPS AND CHECK FOR DUPLICATES
  245. if($map){
  246. while(list($mapnum,$mapid)=each($map)){
  247. $mapid=change_numbersonly($mapid);
  248. $secondmap="$firstmap";
  249. $thirdmap="$secondmapb";
  250. if(($firstmap=="$mapid") || ($thirdmap=="$mapid")){
  251. include("$dir[func]/error.php");
  252. display_error("You must select different maps.<br>");
  253. }else{
  254. $matchmaps=$matchmaps."$mapid,";
  255. }
  256. $firstmap="$mapid";
  257. $secondmapb="$secondmap";
  258. }
  259. }
  260. if(($linfo[minmaps]>0)&&($linfo[maxmaps]>0)){
  261. if(!$matchmaps){
  262. include("$dir[func]/error.php");
  263. display_error("You must select what maps to play.<br>");
  264. }
  265. }
  266. if($comment){
  267. $comment=wordwrap($comment,20," ",1);
  268. $comment=change_censor($comment);
  269. $comment=change_charecters($comment);
  270. }
  271. //Update Challenge
  272. $tday=date("Y-m-d H:i:s");
  273. mysql_query("UPDATE challenges SET
  274. matchtimes='$matchtimes',
  275. matchmaps='$matchmaps',
  276. challengedcomment='$comment',
  277. respondedby='$plyr[id]',
  278. respondedtime='$tday'
  279. WHERE challid='$challid'");
  280. //Update Challenger
  281. mysql_query("UPDATE ladder_$chall[ladderid] SET
  282. statusdisplay='<a href=$url[base]/$file[match]?challid=$challid>Challenge accepted</a>'
  283. WHERE id='$chall[challenger]'");
  284. //Update Challenged
  285. mysql_query("UPDATE ladder_$chall[ladderid] SET
  286. statusdisplay='<a href=$url[base]/$file[match]?challid=$challid>Accepted challenge</a>'
  287. WHERE id='$chall[challenged]'");
  288. //SEND EMAIL TO CHALLENGER
  289. $emailbody="$site[shortname] Challenge Information,\n
  290. Your challenge has been accepted!\n
  291. Your Team: $chgrnfo[teamname]
  292. $url[base]/$file[teams]?teamid=$chall[challenger]
  293. Challenged Team: $chgdnfo[teamname]
  294. $url[base]/$file[teams]?teamid=$chall[challenged]
  295. Ladder: $linfo[laddername]
  296. $url[base]/$file[ladder]?ladderid=$chall[ladderid]\n
  297. You must finalize this challenge within $linfo[finalizehours] hours.
  298. If you do not respond you will recieve and automatic forfeit loss.\n
  299. Go to the following url to finalize this challenge
  300. or click on finalize challenge at the top of the ladder
  301. $url[base]/$file[match]?action=finalize&challid=$challid";
  302. include("$dir[func]/email.php");
  303. send_email($chgrnfo[teamname],$chgrnfo[teamemail],"Challenge Response","$emailbody");
  304. $out[body]=$out[body]."
  305. <br><br>
  306. <table width='100%' border='1' bordercolor='#000000' cellspacing='0' cellpadding='2'>
  307. <tr class='altcolor'>
  308. <td width='100%' valign='top' align='center'>
  309. <strong>The Challenge has been updated</strong><br>
  310. </td>
  311. </tr>
  312. <tr>
  313. <td width='100%' valign='center' align='left'>
  314. <br><ul>
  315. Ladder: <a href='$url[base]/$file[ladder]?ladderid=$chall[ladderid]'>$linfo[laddername]</a><br>
  316. Challenger: <a href='$url[base]/$file[teams]?teamid=$chall[challenger]'>$chgrnfo[teamname]</a><br>
  317. Challenger Rank: $chall[challengerrank]<br>
  318. Challenged: <a href='$url[base]/$file[teams]?teamid=$chall[challenged]'>$chgdnfo[teamname]</a><br>
  319. Challenged Rank: $chall[challengedrank]<br>
  320. </ul></td>
  321. </tr>
  322. <tr class='altcolor'>
  323. <td width='100%' valign='top' align='center'>
  324. <strong><a href='$url[base]/$file[match]?challid=$challid'>View the challenge</a></strong><br>
  325. </td>
  326. </tr>
  327. </table>";
  328. include("$dir[curtheme]");
  329. }
  330. ?>