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

/functions/confirmwin.php

https://bitbucket.org/verax/to-ladder
PHP | 858 lines | 714 code | 112 blank | 32 comment | 92 complexity | a29d92607e15cdae420d3f9ade9f0698 MD5 | raw file
  1. <?
  2. function confirm_win(){
  3. global $dir, $file, $url, $out, $plyr;
  4. $tablehead=table_head("show","100%","","center");
  5. $tablefoot=table_foot("show");
  6. $bannerhead=table_head("show","488","80","center");
  7. $bannerfoot=table_foot("show");
  8. $out[body]=$out[body]."
  9. <center>
  10. $bannerhead
  11. $out[banner]
  12. $bannerfoot
  13. </center>
  14. <br>
  15. $tablehead
  16. <center>
  17. <table width='100%' border='0' bordercolor='#000000' cellspacing='0' cellpadding='2'>
  18. <tr class='altcolor'>
  19. <td width='100%' valign='top' align='center' colspan='6'>
  20. <strong>Unconfirmed Wins on your teams - Unconfirmed matches expire in 24 hours</strong><br>
  21. </td>
  22. </tr>
  23. <tr>
  24. <td width='15%' valign='center' align='center'>Confirm</td>
  25. <td width='15%' valign='center' align='center'>Losing Team</td>
  26. <td width='15%' valign='center' align='center'>Winning Team</td>
  27. <td width='15%' valign='center' align='center'>Ladder</td>
  28. <td width='15%' valign='center' align='center'>Reported By</td>
  29. <td width='25%' valign='center' align='center'>Reported Time</td>
  30. </tr>";
  31. $teamson=mysql_query("SELECT teamid,status FROM teammembers WHERE playerid='$plyr[id]'");
  32. while(list($teamid,$status)=mysql_fetch_row($teamson)){
  33. $unconfirmedwins=mysql_query("SELECT matchid,ladderid,loserid,loseralias,reportedby,reportedip,DATE_FORMAT(reporteddate, '%M %d, %l:%i %p') FROM matchdbval WHERE winnerid='$teamid' ORDER by reporteddate");
  34. while(list($matchid,$ladderid,$loserid,$loseralias,$reportedby,$reportedip,$reporteddate)=mysql_fetch_row($unconfirmedwins)){
  35. if($ladderid!="$lastladderid"){
  36. $ladinfo=mysql_query("SELECT laddername FROM ladders WHERE id='$ladderid'");
  37. $linfo=mysql_fetch_array($ladinfo);
  38. $teaminfo=mysql_query("SELECT teamname FROM teams WHERE id='$teamid'");
  39. $tinfo=mysql_fetch_array($teaminfo);
  40. $out[body]=$out[body]."
  41. <tr class='altcolor'>
  42. </tr>";
  43. }
  44. if($reportedby=="0"){
  45. $reporter[alias]="Unknown";
  46. }else{
  47. $reported=mysql_query("SELECT alias FROM users WHERE id='$reportedby'");
  48. $reporter=mysql_fetch_array($reported);
  49. }
  50. $out[body]=$out[body]."
  51. <tr>
  52. <td width='15%' valign='center' align='center' class='catfont'>[<a href='?action=confirmwin&matchid=$matchid'><b>Confirm</b></a>]</td>
  53. <td width='15%' valign='center' align='center'><b><a href='$url[base]/$file[teams]?teamid=$loserid'>$loseralias</a></b></td>
  54. <td width='15%' valign='center' align='center'><b><a href='$url[base]/$file[teams]?teamid=$teamid'>$tinfo[teamname]</a></b></td>
  55. <td width='15%' valign='center' align='center'><b><a href='$url[base]/$file[ladder]?ladderid=$ladderid'>$linfo[laddername]</a></b></td>
  56. <td width='15%' valign='center' align='center'><b><a href='$url[base]/$file[players]?playerid=$reportedby'>$reporter[alias]</a></b></td>
  57. <td width='25%' valign='center' align='center'><b>$reporteddate</b></td>
  58. </tr>";
  59. $foundwins=1;
  60. }
  61. $lastladderid="$ladderid";
  62. }
  63. if(!$foundwins){
  64. $out[body]=$out[body]."
  65. <tr>
  66. <td width='100%' valign='center' align='center' colspan='6'><b>There are no unconfirmed wins</b></td>
  67. </tr>";
  68. }
  69. $out[body]=$out[body]."</table>
  70. $tablefoot
  71. <br>";
  72. // UNCONFIRMED LOSSES
  73. $out[body]=$out[body]."
  74. $tablehead
  75. <center>
  76. <table width='100%' border='0' bordercolor='#000000' cellspacing='0' cellpadding='2'>
  77. <tr class='altcolor'>
  78. <td width='100%' valign='top' align='center' colspan='5'>
  79. <strong>Unconfirmed Losses on your teams - Unconfirmed matches expire in 24 hours</strong><br>
  80. </td>
  81. </tr>
  82. <tr>
  83. <td width='20%' valign='center' align='center'>Winning Team</td>
  84. <td width='20%' valign='center' align='center'>Losing Team</td>
  85. <td width='20%' valign='center' align='center'>Ladder</td>
  86. <td width='20%' valign='center' align='center'>Reported By</td>
  87. <td width='20%' valign='center' align='center'>Reported Time</td>
  88. </tr>";
  89. $lastladderid="";
  90. $teamsonb=mysql_query("SELECT teamid,status FROM teammembers WHERE playerid='$plyr[id]'");
  91. while(list($teamid,$status)=mysql_fetch_row($teamsonb)){
  92. $unconfirmedlosses=mysql_query("SELECT matchid,ladderid,winnerid,reportedby,reportedip,DATE_FORMAT(reporteddate, '%M %d, %l:%i %p') FROM matchdbval WHERE loserid='$teamid' ORDER by reporteddate");
  93. while(list($matchid,$ladderid,$winnerid,$reportedby,$reportedip,$reporteddate)=mysql_fetch_row($unconfirmedlosses)){
  94. if($ladderid!="$lastladderid"){
  95. $ladinfo=mysql_query("SELECT laddername FROM ladders WHERE id='$ladderid'");
  96. $linfo=mysql_fetch_array($ladinfo);
  97. $teaminfo=mysql_query("SELECT teamname FROM teams WHERE id='$teamid'");
  98. $tinfo=mysql_fetch_array($teaminfo);
  99. $out[body]=$out[body]."
  100. <tr class='altcolor'>
  101. </tr>";
  102. }
  103. $loserteaminfo=mysql_query("SELECT teamname FROM teams WHERE id='$winnerid'");
  104. $ltinfo=mysql_fetch_array($loserteaminfo);
  105. if($reportedby=="0"){
  106. $reporter[alias]="Unknown";
  107. }else{
  108. $reported=mysql_query("SELECT alias FROM users WHERE id='$reportedby'");
  109. $reporter=mysql_fetch_array($reported);
  110. }
  111. $out[body]=$out[body]."
  112. <tr>
  113. <td width='20%' valign='center' align='center'><a href='$url[base]/$file[teams]?teamid=$winnerid'><b>$ltinfo[teamname]</a></b></td>
  114. <td width='20%' valign='center' align='center'><a href='$url[base]/$file[teams]?teamid=$teamid'><b>$tinfo[teamname]</a></b></td>
  115. <td width='20%' valign='center' align='center'><a href='$url[base]/$file[ladder]?ladderid=$ladderid'><b>$linfo[laddername]</a></b></td>
  116. <td width='20%' valign='center' align='center'><a href='$url[base]/$file[players]?playerid=$reportedby'><b>$reporter[alias]</a></b></td>
  117. <td width='20%' valign='center' align='center'><b>$reporteddate</b></td>
  118. </tr>";
  119. $foundlosses=1;
  120. }
  121. $lastladderid="$ladderid";
  122. }
  123. if(!$foundlosses){
  124. $out[body]=$out[body]."
  125. <tr>
  126. <td width='100%' valign='center' align='center' colspan='5'><b>There are no unconfirmed losse</b>s</td>
  127. </tr>";
  128. }
  129. $out[body]=$out[body]."</table>
  130. $tablefoot";
  131. include("$dir[curtheme]");
  132. }
  133. function confirm_winb($matchid){
  134. global $dir, $file, $url, $out, $plyr;
  135. $matchinfo=mysql_query("SELECT *,DATE_FORMAT(reporteddate, '%M %d, %l:%i %p') FROM matchdbval WHERE matchid='$matchid'");
  136. $match=mysql_fetch_array($matchinfo);
  137. if(!$match[matchid]){
  138. include("$dir[func]/error.php");
  139. display_error("Unknown Match ID.<br>");
  140. }
  141. //CHECK IF CAN CONFIRM/REPORT
  142. if (mysql_num_rows(mysql_query("SELECT status FROM teammembers WHERE teamid='$match[winnerid]' AND playerid='$plyr[id]' AND status <='4'")) < 1){
  143. include("$dir[func]/error.php");
  144. display_error("You are not allowed to report losses for this team.<br>");
  145. }
  146. $ladderinfo=mysql_query("SELECT laddername FROM ladders WHERE id='$match[ladderid]'");
  147. $linfo=mysql_fetch_array($ladderinfo);
  148. if(!$linfo[laddername]){
  149. include("$dir[func]/error.php");
  150. display_error("Unknown ladder.<br>");
  151. }
  152. $winnerinfo=mysql_query("SELECT teamname FROM teams WHERE id='$match[winnerid]'");
  153. $wtinfo=mysql_fetch_array($winnerinfo);
  154. if(!$wtinfo[teamname]){
  155. include("$dir[func]/error.php");
  156. display_error("Unable to find your team.<br>");
  157. }
  158. $tablehead=table_head("show","100%","","center");
  159. $tablefoot=table_foot("show");
  160. $bannerhead=table_head("show","488","80","center");
  161. $bannerfoot=table_foot("show");
  162. $out[body]=$out[body]."
  163. <center>
  164. $bannerhead
  165. $out[banner]
  166. $bannerfoot
  167. </center>
  168. <br>
  169. $tablehead
  170. <center>
  171. <table width='100%' border='0' bordercolor='#000000' cellspacing='0' cellpadding='2'>
  172. <tr class='altcolor'>
  173. <td width='100%' valign='top' align='center'>
  174. <strong>Confirm this win - $linfo[laddername]</strong><br>
  175. </td>
  176. </tr>
  177. <tr>
  178. <td width='100%' valign='center' align='center'>
  179. Winner: <a href='$url[base]/$file[teams]?teamid=$match[winnerid]'>$wtinfo[teamname]</a><br>
  180. Loser: <a href='$url[base]/$file[teams]?teamid=$match[loserid]'>$match[loseralias]</a><br>
  181. Winners Rank: $match[wrank]<br>
  182. Losers Rank: $match[lrank]<br>
  183. <br>
  184. Losers Comments:<br>$match[lcomment]<br>
  185. <br>
  186. Match was reported $match[15]</td>
  187. </tr>
  188. <form method='post'>
  189. <tr class='altcolor'>
  190. <td width='100%' valign='top' align='center'>
  191. <input type='hidden' name='matchid' value='$match[matchid]'>
  192. <input type='hidden' name='action' value='confirmwinc'>
  193. <input type='submit' name='' value='Confirm Win'>
  194. </td></form>
  195. </tr>
  196. </table>
  197. $tablefoot";
  198. include("$dir[curtheme]");
  199. }
  200. function confirm_winc($matchid){
  201. global $dir, $file, $url, $out, $plyr, $misc;
  202. $matchinfo=mysql_query("SELECT * FROM matchdbval WHERE matchid='$matchid'");
  203. $match=mysql_fetch_array($matchinfo);
  204. if(!$match[matchid]){
  205. include("$dir[func]/error.php");
  206. display_error("Unknown Match ID.<br>");
  207. }
  208. //CHECK IF CAN CONFIRM/REPORT
  209. if (mysql_num_rows(mysql_query("SELECT status FROM teammembers WHERE teamid='$match[winnerid]' AND playerid='$plyr[id]' AND status <='4'")) < 1){
  210. include("$dir[func]/error.php");
  211. display_error("You are not allowed to report losses for this team.<br>");
  212. }
  213. $ladderinfo=mysql_query("SELECT laddername FROM ladders WHERE id='$match[ladderid]'");
  214. $linfo=mysql_fetch_array($ladderinfo);
  215. if(!$linfo[laddername]){
  216. include("$dir[func]/error.php");
  217. display_error("Unknown ladder.<br>");
  218. }
  219. $winnerinfo=mysql_query("SELECT teamname FROM teams WHERE id='$match[winnerid]'");
  220. $wtinfo=mysql_fetch_array($winnerinfo);
  221. if(!$wtinfo[teamname]){
  222. include("$dir[func]/error.php");
  223. display_error("Unable to find your team.<br>");
  224. }
  225. $tablehead=table_head("show","100%","","center");
  226. $tablefoot=table_foot("show");
  227. $bannerhead=table_head("show","488","80","center");
  228. $bannerfoot=table_foot("show");
  229. $out[body]=$out[body]."
  230. <center>
  231. $bannerhead
  232. $out[banner]
  233. $bannerfoot
  234. </center>
  235. <br>
  236. $tablehead
  237. <center>
  238. <table width='100%' border='0' bordercolor='#ffffff' cellspacing='0' cellpadding='2'>
  239. <form method='post'>
  240. <tr class='altcolorc'>
  241. <td width='100%' align='center' border='0' bordercolor='#ffffff'>
  242. <strong>Confirm this win</strong><br>
  243. </td>
  244. </tr>
  245. <tr><td>
  246. <table width=80% align='center' class='altcolorc'>
  247. ";
  248. $altcolora="#000033";
  249. $altcolorb="#000020";
  250. $winnersmembers=mysql_query("SELECT playerid,status FROM teammembers WHERE teamid='$match[winnerid]' ORDER by status");
  251. while(list($playerid,$status)=mysql_fetch_row($winnersmembers)){
  252. $memberinfo=mysql_query("SELECT alias FROM users WHERE id='$playerid'");
  253. $minfo=mysql_fetch_array($memberinfo);
  254. if($altladrow=="$altcolora"){
  255. $altladrow="$altcolorb";
  256. }else{
  257. $altladrow="$altcolora";
  258. }
  259. $out[body]=$out[body]."
  260. <tr bgcolor='$altladrow'>
  261. <td width='50%' align='left'>
  262. <a href='$url[base]/$file[players]?playerid=$playerid' target='new'>
  263. $minfo[alias]</a></td>
  264. <td width='50%' valign='center' align='right'>";
  265. if($status < 6){
  266. $out[body]=$out[body]."Played in Match:
  267. <input type='checkbox' name='member[$playerid]' value='1'>
  268. <input type='hidden' name='kills[$playerid]' value='0' maxlength='2' size='5'>";
  269. }else{
  270. $status=member_status($status);
  271. $out[body]=$out[body]."$status";
  272. }
  273. $out[body]=$out[body]."
  274. </td>
  275. </tr>";
  276. }
  277. $out[body]=$out[body]."
  278. </table>";
  279. if($match[maps]){
  280. $out[body]=$out[body]."
  281. <tr><td>
  282. <table width=80% align='center' class='altcolorc'>
  283. <tr class='altcolorc'>
  284. <td width='100%' valign='top' align='center' colspan='3'>
  285. <strong>Map Results</strong><br>
  286. </td>
  287. </tr>
  288. ";
  289. $mapsplayed=split(",",$match[maps]);
  290. while(list($mapnum,$mapid)=each($mapsplayed)){
  291. $mapnum=($mapnum+1);
  292. if($mapid){
  293. $mapplayedinfo=mysql_query("SELECT mapname FROM maps WHERE id='$mapid'");
  294. $mapinfo=mysql_fetch_array($mapplayedinfo);
  295. if($altladrow=="$altcolora"){
  296. $altladrow="$altcolorb";
  297. }else{
  298. $altladrow="$altcolora";
  299. }
  300. if(!$mapinfo[mapname]){
  301. $mapinfo[mapname]="Unknown";
  302. }
  303. $out[body]=$out[body]."
  304. <tr bgcolor=$altladrow>
  305. <td width='33%' valign='center' align='left'>
  306. #$mapnum Map Played</td>
  307. <td width='33%' valign='center' align='center'>$mapinfo[mapname]</td>
  308. <td width='33%' valign='center' align='right'>Won: <input type='checkbox' name='map[$mapnum]' value='1'></td>
  309. </tr>
  310. ";
  311. }
  312. }
  313. $out[body]=$out[body]."
  314. </table></td></tr>
  315. ";
  316. }
  317. $out[body]=$out[body]."
  318. <tr class='altcolorc'>
  319. <td width='100%' valign='top' align='center'>
  320. <strong>Final Score</strong><br>
  321. </td>
  322. </tr>
  323. <tr>
  324. <td width='100%' valign='center' align='center'>
  325. <table width='100%' border='0' cellspacing='0' cellpadding='0'>
  326. <tr>
  327. <td width='50%' valign='center' align='center'>$wtinfo[teamname] <input type='text' name='wfscore' value='' size='3' maxlength='3'>&nbsp;</td>
  328. <td width='50%' valign='center' align='center'>$match[loseralias] <input type='text' name='lfscore' value='' size='3' maxlength='3'> $ltinfo[teamname]</td>
  329. </tr>
  330. </table>";
  331. if($misc[winnercomment]=="yes"){
  332. $out[body]=$out[body]."</td>
  333. </tr>
  334. <tr class='altcolorc'>
  335. <td width='100%' valign='top' align='center'>
  336. <strong>Comment on this match</strong><br>
  337. </td>
  338. </tr>
  339. <tr>
  340. <td width='100%' valign='center' align='center'>
  341. <tr>
  342. <td width='100%' valign='center' align='center'>
  343. <input type='text' name='wcomment' maxlength='50' size='50'><br>
  344. <small>50 Characters Max</small>
  345. </td>
  346. </tr>";
  347. }
  348. $out[body]=$out[body]."
  349. <tr>
  350. <td width='100%' valign='top' align='center'>
  351. <BR>
  352. <input type='hidden' name='matchid' value='$match[matchid]'>
  353. <input type='hidden' name='action' value='confirmwind'>
  354. <input type='submit' name='' value='Confirm Win'>
  355. </td></form>
  356. </tr>
  357. </table>
  358. $tablefoot";
  359. include("$dir[curtheme]");
  360. }
  361. function confirm_wind($matchid,$member,$map,$wfscore,$lfscore,$wcomment,$kills){
  362. global $dir, $file, $url, $out, $plyr, $misc;
  363. if(!$matchid){
  364. include("$dir[func]/error.php");
  365. display_error("Invalid Match ID.<br>");
  366. }
  367. if((!$wfscore) || ($wfscore <= $lfscore)){
  368. include("$dir[func]/error.php");
  369. display_error("Invalid Final Score.<br>");
  370. }
  371. $matchinfo=mysql_query("SELECT * FROM matchdbval WHERE matchid='$matchid'");
  372. $match=mysql_fetch_array($matchinfo);
  373. if(!$match[matchid]){
  374. include("$dir[func]/error.php");
  375. display_error("Unknown Match ID.<br>");
  376. }
  377. //CHECK IF CAN CONFIRM/REPORT
  378. if (mysql_num_rows(mysql_query("SELECT status FROM teammembers WHERE teamid='$match[winnerid]' AND playerid='$plyr[id]' AND status <='4'")) < 1){
  379. include("$dir[func]/error.php");
  380. display_error("You are not allowed to report losses for this team.<br>");
  381. }
  382. $ladderinfo=mysql_query("SELECT * FROM ladders WHERE id='$match[ladderid]'");
  383. $linfo=mysql_fetch_array($ladderinfo);
  384. if(!$linfo[laddername]){
  385. include("$dir[func]/error.php");
  386. display_error("Unknown ladder.<br>");
  387. }
  388. $winnerinfo=mysql_query("SELECT teamname FROM teams WHERE id='$match[winnerid]'");
  389. $wtinfo=mysql_fetch_array($winnerinfo);
  390. if(!$wtinfo[teamname]){
  391. include("$dir[func]/error.php");
  392. display_error("Unable to find your team.<br>");
  393. }
  394. if(!$member){
  395. include("$dir[func]/error.php");
  396. display_error("You must select the members that played.<br>");
  397. }
  398. include("$dir[func]/checkdata.php");
  399. $wfscore=change_numbersonly($wfscore);
  400. if($lfscore==""){
  401. $lfscore=0;
  402. }else{
  403. $lfscore=change_numbersonly($lfscore);
  404. }
  405. if((!$wfscore) || (!$lfscore) && ($lfscore!="0")){
  406. include("$dir[func]/error.php");
  407. display_error("Invalid Final Score.<br>");
  408. }
  409. if($wcomment){
  410. $wcomment=wordwrap($wcomment,20," ",1);
  411. $wcomment=change_censor($wcomment);
  412. $wcomment=change_charecters($wcomment);
  413. }
  414. while(list($memberid,$played)=each($member)){
  415. if($played){
  416. $memberid=change_numbersonly($memberid);
  417. $kills[$memberid]=change_numbersonly($kills[$memberid]);
  418. $membersplayed=$membersplayed."$memberid|$kills[$memberid],";
  419. $totalkills=($totalkills + $kills[$memberid]);
  420. }
  421. }
  422. if($map){
  423. while(list($maporder,$wonmap)=each($map)){
  424. if($wonmap){
  425. $mapsplayed=$mapsplayed."$maporder,";
  426. }
  427. }
  428. }
  429. if(!$membersplayed){
  430. include("$dir[func]/error.php");
  431. display_error("You must select the members that played.<br>");
  432. }
  433. //CHECK FOR CHALLENGE OR IF OPEN PLAY IS ALLOWED
  434. $thechallenge=mysql_query("SELECT * FROM challenges WHERE challenger='$match[winnerid]' AND challenged='$match[loserid]' AND finalizedby > '0' OR challenger='$match[loserid]' AND challenged='$match[winnerid]' AND finalizedby > '0'");
  435. $chall=mysql_fetch_array($thechallenge);
  436. if($chall[challid]){
  437. if($misc[challranking] < 2){
  438. if($match[winnerid]=="$chall[challenger]"){
  439. $wtempnewrank="$chall[challengedrank]";
  440. }else{
  441. $wtempnewrank=0;
  442. }
  443. }
  444. else if($misc[challranking] > 1){
  445. if($match[winnerid]=="$chall[challenger]"){
  446. $wtempnewrank=($chall[challengedrank] / 2 - 0.5);
  447. }else{
  448. $wtempnewrank=0;
  449. }
  450. }
  451. else{
  452. $wtempnewrank=0;
  453. }
  454. }else{
  455. if($linfo[openplay] < 1){
  456. include("$dir[func]/error.php");
  457. display_error("Open play is not allowed on this ladder.<br>All matches must be scheduled challenges.<br>");
  458. }
  459. }
  460. //CLEAN MATCH DB
  461. clean_matchdb($matchid);
  462. $tday=date("Y-m-d H:i:s");
  463. $ip=getenv("REMOTE_ADDR");
  464. //REPORT MATCH TO MATCH DATABASE
  465. mysql_query("INSERT INTO matchdb VALUES (
  466. '$match[matchid]',
  467. '$match[winnerid]',
  468. '$match[loserid]',
  469. '$wtinfo[teamname]',
  470. '$match[loseralias]',
  471. '$match[ladderid]',
  472. '$linfo[laddername]',
  473. '$match[wrank]',
  474. '$match[lrank]',
  475. '$wfscore',
  476. '$lfscore',
  477. '$membersplayed',
  478. '$match[losersmembers]',
  479. '$match[maps]',
  480. '$mapsplayed',
  481. '$wcomment',
  482. '$match[lcomment]',
  483. '$match[points]',
  484. '$totalkills|$match[skill]',
  485. '$match[reportedby]',
  486. '$match[reporteddate]',
  487. '$match[reportedip]',
  488. '$plyr[id]',
  489. '$tday',
  490. '$ip');");
  491. //UPDATE WINNER TEAM PLAYER SCORES
  492. $membersplayed=split(",",$membersplayed);
  493. while(list($num,$playerid)=each($membersplayed)){
  494. $playerid=split("\|",$playerid);
  495. if($playerid[0]){
  496. mysql_query("UPDATE users SET
  497. matcheswon=matcheswon+1,
  498. points=points+$match[points],
  499. skill=skill+$playerid[1]
  500. WHERE id='$playerid[0]'");
  501. }
  502. }
  503. //UPDATE LOSER TEAM PLAYER SCORES
  504. $losersmembers=split(",",$match[losersmembers]);
  505. while(list($num,$losersid)=each($losersmembers)){
  506. $losersid=split("\|",$losersid);
  507. if($losersid[0]){
  508. mysql_query("UPDATE users SET
  509. matcheslost=matcheslost+1,
  510. skill=skill+$losersid[1]
  511. WHERE id='$losersid[0]'");
  512. }
  513. }
  514. //GET WINNERS LADDER STATS
  515. $winnerladder=mysql_query("SELECT * FROM ladder_$match[ladderid] WHERE id='$match[winnerid]'");
  516. $wlinfo=mysql_fetch_array($winnerladder);
  517. //GET LOSERS LADDER STATS
  518. $loserladder=mysql_query("SELECT * FROM ladder_$match[ladderid] WHERE id='$match[loserid]'");
  519. $llinfo=mysql_fetch_array($loserladder);
  520. //GET TOTAL RANKERS
  521. $totalranked=mysql_query("SELECT COUNT(*) FROM ladder_$match[ladderid] WHERE rank > '0'");
  522. $totalranks=mysql_fetch_array($totalranked);
  523. $totalranks="$totalranks[0]";
  524. if(!$chall[challid]){
  525. //Winner moves half way up to losers position
  526. if($misc[ranking] < 2){
  527. //UPDATE LADDER RANKS
  528. //IF BOTH TEAMS ARE ALREADY RANKED
  529. if(($match[wrank] > 0) && ($match[lrank] > 0)){
  530. $wtempnewrank=($match[wrank] + $match[lrank]);
  531. $wtempnewrank=($wtempnewrank / 2 - 0.5);
  532. if($wtempnewrank > $totalranks){
  533. $wtempnewrank="$totalranks";
  534. }
  535. }
  536. else if($match[wrank] < 1){
  537. $wtempnewrank=($totalranks + 1);
  538. }else{
  539. $wtempnewrank="";
  540. }
  541. //Winner takes losers position
  542. }else if($misc[ranking] > 1){
  543. //UPDATE LADDER RANKS
  544. //IF BOTH TEAMS ARE ALREADY RANKED
  545. if(($match[wrank] > 0) && ($match[lrank] > 0)){
  546. $wtempnewrank=$match[lrank];
  547. }
  548. else if($match[wrank] < 1){
  549. $wtempnewrank=($totalranks + 1);
  550. }else{
  551. $wtempnewrank="";
  552. }
  553. }else{
  554. $wtempnewrank="";
  555. }
  556. }
  557. $wtempnewrank=round($wtempnewrank);
  558. //IF RANK IS BETTER THAN CURRENT RANK UPDATE LADDER
  559. include("$dir[func]/rankadjust.php");
  560. if(($wtempnewrank) && ($wtempnewrank > 0)){
  561. if(($wtempnewrank < $wlinfo[rank]) || ($wlinfo[rank] < 1)){
  562. update_teamranks($match[ladderid],$match[winnerid],$wtempnewrank);
  563. $updatedrank="$wtempnewrank";
  564. }
  565. }
  566. //UPDATE WINNERS LADDER STATS
  567. if($updatedrank){
  568. $newlastrank="$wlinfo[rank]";
  569. if(($updatedrank < $wlinfo[bestrank]) || ($wlinfo[bestrank] < 1)){
  570. $newbestrank="$updatedrank";
  571. }else{
  572. $newbestrank="$wlinfo[bestrank]";
  573. }
  574. }else{
  575. $newlastrank="$wlinfo[lastrank]";
  576. $newbestrank="$wlinfo[bestrank]";
  577. }
  578. $newwins=($wlinfo[wins] + 1);
  579. $newgames=($newwins + $wlinfo[losses]);
  580. $newpercent=round($newwins / $newgames * 100);
  581. $newstreak=($wlinfo[streak] + 1);
  582. if($newstreak < 1){
  583. $newstreak="1";
  584. }
  585. if($newstreak > $wlinfo[beststreak]){
  586. $newbeststreak="$newstreak";
  587. }else{
  588. $newbeststreak="$wlinfo[beststreak]";
  589. }
  590. if($llinfo[rank] > 0){
  591. $newpoints=($totalranks - $llinfo[rank]);
  592. $newpoints=round($newpoints / 10);
  593. }
  594. if($newpoints < 10){
  595. $newpoints="10";
  596. }
  597. //CHANGED SKILL TO KILLS
  598. //$newskill=($wlinfo[skill] + $match[skill]);
  599. $newskill=($wlinfo[skill] + $totalkills);
  600. $newpoints=($newpoints + $wlinfo[points]);
  601. mysql_query("UPDATE ladder_$match[ladderid] SET
  602. lastmatch='$tday',
  603. lastplayed='$match[loserid]',
  604. statusdisplay='',
  605. lastrank='$newlastrank',
  606. bestrank='$newbestrank',
  607. wins='$newwins',
  608. games='$newgames',
  609. percent='$newpercent',
  610. streak='$newstreak',
  611. beststreak='$newbeststreak',
  612. points='$newpoints',
  613. skill='$newskill'
  614. WHERE id='$match[winnerid]'");
  615. //UPDATE LOSERS LADDER STATS
  616. $newlastrank="$llinfo[rank]";
  617. if(($llinfo[rank] < $llinfo[bestrank]) || ($llinfo[bestrank]=="0")){
  618. $newbestrank="$llinfo[rank]";
  619. }else{
  620. $newbestrank="$llinfo[bestrank]";
  621. }
  622. if($llinfo[rank] > $llinfo[worstrank]){
  623. $newworstrank="$llinfo[rank]";
  624. }else{
  625. $newworstrank="$llinfo[worstrank]";
  626. }
  627. $newlosses=($llinfo[losses] + 1);
  628. $newgames=($newlosses + $llinfo[wins]);
  629. $newpercent=round($llinfo[wins] / $newgames * 100);
  630. $newstreak=($llinfo[streak] - 1);
  631. if($newstreak > 0){
  632. $newstreak="-1";
  633. }
  634. if($newstreak < $llinfo[worststreak]){
  635. $newworststreak="$newstreak";
  636. }else{
  637. $newworststreak="$llinfo[worststreak]";
  638. }
  639. $newskill=($llinfo[skill] + $match[skill]);
  640. mysql_query("UPDATE ladder_$match[ladderid] SET
  641. lastmatch='$tday',
  642. lastplayed='$match[winnerid]',
  643. statusdisplay='',
  644. lastrank='$newlastrank',
  645. bestrank='$newbestrank',
  646. worstrank='$newworstrank',
  647. losses='$newlosses',
  648. games='$newgames',
  649. percent='$newpercent',
  650. streak='$newstreak',
  651. worststreak='$newworststreak',
  652. skill='$newskill'
  653. WHERE id='$match[loserid]'");
  654. //DELETE UNVALIDATED MATCH
  655. mysql_query("DELETE FROM matchdbval WHERE matchid='$matchid'");
  656. if($chall[challid]){
  657. //DELETE CHALLENGE
  658. mysql_query("DELETE FROM challenges WHERE challid='$chall[challid]'");
  659. }
  660. //CLEAN LADDER - INACTIVITY
  661. if($linfo[inactivedrop] > 0){
  662. //SECOND WARNING - DELETE TEAMS
  663. if($linfo[inactivedaysb] > 0){
  664. $dropdateb=date("Y-m-d H:i:s",time()-60*60*24*$linfo[inactivedaysb]);
  665. $inactivedropb=mysql_query("SELECT id FROM ladder_$match[ladderid] WHERE joindate < '$dropdateb' AND lastmatch < '$dropdateb'");
  666. while(list($dropidb)=mysql_fetch_row($inactivedropb)){
  667. // REMOVE ALL RECORDS OF TEAM FROM LADDER SYSTEM
  668. mysql_query("DELETE FROM teammembers WHERE teamid='$dropidb'");
  669. mysql_query("DELETE FROM teams WHERE id='$dropidb'");
  670. mysql_query("DELETE FROM ladder_$match[ladderid] WHERE id='$dropidb'");
  671. mysql_query("DELETE FROM challenges WHERE challenger='$dropidb'");
  672. mysql_query("DELETE FROM challenges WHERE challenged='$dropidb'");
  673. mysql_query("DELETE FROM teammembersinv WHERE teamid='$dropidb'");
  674. }
  675. }
  676. //FIRST DROP TO (admin set amount) RANKS
  677. if($linfo[inactivedaysa] > 0){
  678. $dropdatea=date("Y-m-d H:i:s",time()-60*60*24*$linfo[inactivedaysa]);
  679. $inactivedropa=mysql_query("SELECT id,rank FROM ladder_$match[ladderid] WHERE joindate < '$dropdatea' AND statusdate < '$dropdatea' AND lastmatch < '$dropdatea' AND rank > '0' ORDER by rank");
  680. while(list($dropida,$dropranka)=mysql_fetch_row($inactivedropa)){
  681. $teamsdropped++;
  682. if($teamsdropped < 25){
  683. $droptoa=($dropranka + $linfo[inactivedrop]);
  684. if($droptoa > $totalranks){
  685. $droptoa="$totalranks";
  686. }
  687. mysql_query("UPDATE ladder_$match[ladderid] SET rank='$droptoa' WHERE id='$dropida'");
  688. mysql_query("UPDATE ladder_$match[ladderid] SET status='69', statusdisplay='Dropped for Inactivity', statusdate='$tday' WHERE id='$dropida'");
  689. }
  690. }
  691. }
  692. }
  693. //CHECK FOR DUPLICATE RANKS AND ADJUST RANKS
  694. //RETURN (1) IF ADJUSTED
  695. $ranksadjusted=rank_checkadjust($match[ladderid]);
  696. $tablehead=table_head("show","100%","","center");
  697. $tablefoot=table_foot("show");
  698. $bannerhead=table_head("show","488","80","center");
  699. $bannerfoot=table_foot("show");
  700. $out[body]=$out[body]."
  701. <center>
  702. $bannerhead
  703. $out[banner]
  704. $bannerfoot
  705. </center>
  706. <br>
  707. $tablehead
  708. <table width='100%' border='0' bordercolor='#000000' cellspacing='0' cellpadding='2'>
  709. <tr class='altcolor'>
  710. <td width='100%' valign='top' align='center'>
  711. <strong>Your win has been recorded</strong><br>
  712. </td>
  713. </tr>
  714. <tr>
  715. <td width='100%' valign='center' align='left'>
  716. <br><ul>
  717. Ladder: <a href='$url[base]/$file[ladder]?ladderid=$match[ladderid]'>$linfo[laddername]</a><br>
  718. Winner: <a href='$url[base]/$file[teams]?teamid=$match[winnerid]'>$wtinfo[teamname]</a><br>
  719. Loser: <a href='$url[base]/$file[teams]?teamid=$match[loserid]'>$match[loseralias]</a>
  720. </ul></td>
  721. </tr>
  722. <tr class='altcolor'>
  723. <td width='100%' valign='top' align='center'>
  724. <strong><a href='$url[base]/$file[match]?matchid=$match[matchid]'>View the Match</a></strong><br>
  725. </td>
  726. </tr>
  727. </table>
  728. $tablefoot";
  729. include("$dir[curtheme]");
  730. }
  731. function clean_matchdb($matchid){
  732. $deletedate=date("Y-m-d H:i:s",time()-60*60*24*30);
  733. mysql_query("DELETE FROM matchdb WHERE reportdate < '$deletedate' OR matchid='$matchid'");
  734. }
  735. function member_status($status){
  736. if($status=="1"){ $status="Leader"; }
  737. if($status=="2"){ $status="Co-Leader"; }
  738. if($status=="3"){ $status="Captain"; }
  739. if($status=="4"){ $status="Co-Captain"; }
  740. if($status=="5"){ $status="Member"; }
  741. if($status=="6"){ $status="Training"; }
  742. if($status=="7"){ $status="Inactive"; }
  743. if($status=="8"){ $status="Suspended"; }
  744. return($status);
  745. }
  746. ?>