PageRenderTime 209ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/inc/tourney_system.inc.php

https://github.com/eb/phptourney
PHP | 836 lines | 628 code | 90 blank | 118 comment | 142 complexity | 9add9fe3b58d9cc02fef3fe5a2007e90 MD5 | raw file
Possible License(s): LGPL-2.0
  1. <?php
  2. ////////////////////////////////////////////////////////////////////////////////
  3. // Tourney System functions - Tourney System related functions
  4. //
  5. // $Id: tourney_system.inc.php,v 1.1 2006/03/16 00:05:17 eb Exp $
  6. //
  7. // Copyright (c) 2004 A.Beisler <eb@subdevice.org> http://www.subdevice.org/
  8. //
  9. // This program is free software; you can redistribute it and/or modify
  10. // it under the terms of the GNU General Public License as published by
  11. // the Free Software Foundation; either version 2 of the License, or
  12. // (at your option) any later version.
  13. //
  14. // This program is distributed in the hope that it will be useful,
  15. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. // GNU General Public License for more details.
  18. //
  19. // You should have received a copy of the GNU General Public License
  20. // along with this program; if not, write to the Free Software
  21. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  22. ////////////////////////////////////////////////////////////////////////////////
  23. //================================================================================
  24. // function insertWinnerMatch
  25. // insert winners next round match
  26. //================================================================================
  27. function insertWinnerMatch(& $match, $id_winner)
  28. {
  29. global $cfg;
  30. if (hasNextWinnerMatch($match))
  31. {
  32. $winner_bracket = getNextWinnerBracket($match);
  33. $winner_round = getNextWinnerRound($match);
  34. $winner_match = getNextWinnerMatch($match);
  35. $winner_player = getNextWinnerPlayer($match);
  36. dbQuery("UPDATE `{$cfg['db_table_prefix']}matches` SET " .
  37. "`id_$winner_player` = $id_winner " .
  38. "WHERE `id_season` = {$match['id_season']} " .
  39. "AND `bracket` = '$winner_bracket' " .
  40. "AND `round` = $winner_round " .
  41. "AND `match` = $winner_match");
  42. $matches_ref = dbQuery("SELECT * FROM `{$cfg['db_table_prefix']}matches` " .
  43. "WHERE `id_season` = {$match['id_season']} " .
  44. "AND `bracket` = '$winner_bracket' " .
  45. "AND `round` = $winner_round " .
  46. "AND `match` = $winner_match");
  47. $matches_row = dbFetch($matches_ref);
  48. return($matches_row);
  49. }
  50. elseif ($match['bracket'] == "gf" and $match['match'] == 1 and $match['id_player1'] == $id_winner)
  51. {
  52. dbQuery("UPDATE `{$cfg['db_table_prefix']}matches` SET " .
  53. "`id_player1` = 0 " .
  54. "WHERE `id_season` = {$match['id_season']} " .
  55. "AND `bracket` = 'gf' " .
  56. "AND `round` = 1 " .
  57. "AND `match` = 2");
  58. }
  59. return(NULL);
  60. }
  61. //================================================================================
  62. // function insertLoserMatch
  63. // insert losers next round match
  64. //================================================================================
  65. function insertLoserMatch(& $match, $id_loser)
  66. {
  67. global $cfg;
  68. if (hasNextLoserMatch($match))
  69. {
  70. $loser_bracket = getNextLoserBracket($match);
  71. $loser_round = getNextLoserRound($match);
  72. $loser_match = getNextLoserMatch($match);
  73. $loser_player = getNextLoserPlayer($match);
  74. dbQuery("UPDATE `{$cfg['db_table_prefix']}matches` SET " .
  75. "`id_$loser_player` = $id_loser " .
  76. "WHERE `id_season` = {$match['id_season']} " .
  77. "AND `bracket` = '$loser_bracket' " .
  78. "AND `round` = $loser_round " .
  79. "AND `match` = $loser_match");
  80. $matches_ref = dbQuery("SELECT * FROM `{$cfg['db_table_prefix']}matches` " .
  81. "WHERE `id_season` = {$match['id_season']} " .
  82. "AND `bracket` = '$loser_bracket' " .
  83. "AND `round` = $loser_round " .
  84. "AND `match` = $loser_match");
  85. $matches_row = dbFetch($matches_ref);
  86. return($matches_row);
  87. }
  88. elseif ($match['bracket'] == "gf" and $match['match'] == 1 and $match['id_player2'] == $id_loser)
  89. {
  90. dbQuery("UPDATE `{$cfg['db_table_prefix']}matches` SET " .
  91. "`id_player2` = 0 " .
  92. "WHERE `id_season` = {$match['id_season']} " .
  93. "AND `bracket` = 'gf' " .
  94. "AND `round` = 1 " .
  95. "AND `match` = 2");
  96. }
  97. return(NULL);
  98. }
  99. //================================================================================
  100. // function getWinnerMatch
  101. // get winners next round match
  102. //================================================================================
  103. function getWinnerMatch(& $match)
  104. {
  105. global $cfg;
  106. if (hasNextWinnerMatch($match))
  107. {
  108. $winner_bracket = getNextWinnerBracket($match);
  109. $winner_round = getNextWinnerRound($match);
  110. $winner_match = getNextWinnerMatch($match);
  111. $winner_player = getNextWinnerPlayer($match);
  112. $matches_ref = dbQuery("SELECT * FROM `{$cfg['db_table_prefix']}matches` " .
  113. "WHERE `id_season` = {$_REQUEST['sid']} " .
  114. "AND `bracket` = '$winner_bracket' " .
  115. "AND `round` = $winner_round " .
  116. "AND `match` = $winner_match");
  117. if ($matches_row = dbFetch($matches_ref))
  118. {
  119. return($matches_row);
  120. }
  121. else
  122. {
  123. return(NULL);
  124. }
  125. }
  126. return(NULL);
  127. }
  128. //================================================================================
  129. // function getLoserMatch
  130. // get losers next round match
  131. //================================================================================
  132. function getLoserMatch(& $match)
  133. {
  134. global $cfg;
  135. if (hasNextLoserMatch($match))
  136. {
  137. $loser_bracket = getNextLoserBracket($match);
  138. $loser_round = getNextLoserRound($match);
  139. $loser_match = getNextLoserMatch($match);
  140. $loser_player = getNextLoserPlayer($match);
  141. $matches_ref = dbQuery("SELECT * FROM `{$cfg['db_table_prefix']}matches` " .
  142. "WHERE `id_season` = {$_REQUEST['sid']} " .
  143. "AND `bracket` = '$loser_bracket' " .
  144. "AND `round` = $loser_round " .
  145. "AND `match` = $loser_match");
  146. if ($matches_row = dbFetch($matches_ref))
  147. {
  148. return($matches_row);
  149. }
  150. else
  151. {
  152. return(NULL);
  153. }
  154. }
  155. return(NULL);
  156. }
  157. //================================================================================
  158. // function isLastMatch
  159. // checks whether the given match is an editable match
  160. //================================================================================
  161. function isLastMatch(& $match)
  162. {
  163. global $cfg;
  164. $next_winner_match_played = false;
  165. if (hasNextWinnerMatch($match))
  166. {
  167. $winner_bracket = getNextWinnerBracket($match);
  168. $winner_round = getNextWinnerRound($match);
  169. $winner_match = getNextWinnerMatch($match);
  170. $matches_ref = dbQuery("SELECT * FROM `{$cfg['db_table_prefix']}matches` " .
  171. "WHERE `id_season` = {$match['id_season']} " .
  172. "AND `bracket` = '$winner_bracket' " .
  173. "AND `round` = $winner_round " .
  174. "AND `match` = $winner_match " .
  175. "AND `submitted` <> '0000-00-00 00:00:00'");
  176. if (dbNumRows($matches_ref) == 1)
  177. {
  178. $next_winner_match_played = true;
  179. }
  180. }
  181. $next_loser_match_played = false;
  182. if (hasNextLoserMatch($match))
  183. {
  184. $loser_bracket = getNextLoserBracket($match);
  185. $loser_round = getNextLoserRound($match);
  186. $loser_match = getNextLoserMatch($match);
  187. $matches_ref = dbQuery("SELECT * FROM `{$cfg['db_table_prefix']}matches` " .
  188. "WHERE `id_season` = {$match['id_season']} " .
  189. "AND `bracket` = '$loser_bracket' " .
  190. "AND `round` = $loser_round " .
  191. "AND `match` = $loser_match " .
  192. "AND `submitted` <> '0000-00-00 00:00:00'");
  193. if (dbNumRows($matches_ref) == 1)
  194. {
  195. $next_loser_match_played = true;
  196. }
  197. }
  198. if ($next_winner_match_played or $next_loser_match_played)
  199. {
  200. return(false);
  201. }
  202. else
  203. {
  204. return(true);
  205. }
  206. }
  207. //================================================================================
  208. // function hasNextWinnerMatch
  209. // checks whether the winner of the given match has another match
  210. //================================================================================
  211. function hasNextWinnerMatch(& $match)
  212. {
  213. global $season;
  214. if ($match['bracket'] == "q")
  215. {
  216. return(true);
  217. }
  218. elseif ($match['bracket'] == "lb" and $match['round'] <= getNumLBRounds($season))
  219. {
  220. return(true);
  221. }
  222. elseif ($match['bracket'] == "wb" and $match['round'] < getNumWBRounds($season))
  223. {
  224. return(true);
  225. } elseif ($match['bracket'] == "wb" and
  226. $match['round'] == getNumWBRounds($season) and
  227. $season['double_elimination'] != "") {
  228. return(true);
  229. }
  230. elseif ($match['bracket'] == "gf" and $match['match'] == 1 and $match['id_player2'] == winnerOf($match))
  231. {
  232. return(true);
  233. }
  234. else
  235. {
  236. return(false);
  237. }
  238. }
  239. //================================================================================
  240. // function hasNextLoserMatch
  241. // checks whether the loser of the given match has another match
  242. //================================================================================
  243. function hasNextLoserMatch(& $match)
  244. {
  245. global $season;
  246. if ($match['bracket'] == "wb" and
  247. $season['double_elimination'] != "" and
  248. $season['single_elimination'] / pow(2, $match['round'] - 1) <= $season['double_elimination']) {
  249. return(true);
  250. }
  251. elseif ($match['bracket'] == "gf" and $match['match'] == 1 and $match['id_player2'] == winnerOf($match))
  252. {
  253. return(true);
  254. }
  255. else
  256. {
  257. return(false);
  258. }
  259. }
  260. //================================================================================
  261. // function getNextWinnerBracket
  262. // returns the bracket of the winners next match
  263. //================================================================================
  264. function getNextWinnerBracket(& $match)
  265. {
  266. global $season;
  267. if ($match['bracket'] == "q")
  268. {
  269. return("wb");
  270. }
  271. elseif ($match['bracket'] == "wb" and $match['round'] < getNumWBRounds($season))
  272. {
  273. return("wb");
  274. } elseif ($match['bracket'] == "wb" and
  275. $match['round'] == getNumWBRounds($season) and
  276. $season['double_elimination'] != "") {
  277. return("gf");
  278. }
  279. elseif ($match['bracket'] == "lb" and $match['round'] < getNumLBRounds($season))
  280. {
  281. return("lb");
  282. } elseif ($match['bracket'] == "lb" and
  283. $match['round'] == getNumLBRounds($season)) {
  284. return("gf");
  285. }
  286. elseif ($match['bracket'] == "gf" and $match['id_player2'] == winnerOf($match))
  287. {
  288. return("gf");
  289. }
  290. }
  291. //================================================================================
  292. // function get_next_losers_bracket
  293. // returns the bracket of the losers next match
  294. //================================================================================
  295. function getNextLoserBracket(& $match)
  296. {
  297. global $season;
  298. if ($match['bracket'] == "wb" and
  299. $season['double_elimination'] != "" and
  300. $season['single_elimination'] / pow(2, $match['round'] - 1) <= $season['double_elimination']) {
  301. return("lb");
  302. }
  303. elseif ($match['bracket'] == "gf" and $match['id_player2'] == winnerOf($match))
  304. {
  305. return("gf");
  306. }
  307. }
  308. //================================================================================
  309. // function getNextWinnerRound
  310. // returns the round of the winners next match
  311. //================================================================================
  312. function getNextWinnerRound(& $match)
  313. {
  314. global $season;
  315. if ($match['bracket'] == "q")
  316. {
  317. return(1);
  318. }
  319. elseif ($match['bracket'] == "wb" and $match['round'] < getNumWBRounds($season))
  320. {
  321. return($match['round'] + 1);
  322. } elseif ($match['bracket'] == "wb" and
  323. $match['round'] == getNumWBRounds($season) and
  324. $season['double_elimination'] != "") {
  325. return(1);
  326. }
  327. elseif ($match['bracket'] == "lb" and $match['round'] < getNumLBRounds($season))
  328. {
  329. return($match['round'] + 1);
  330. } elseif ($match['bracket'] == "lb" and
  331. $match['round'] == getNumLBRounds($season)) {
  332. return(1);
  333. }
  334. elseif ($match['bracket'] == "gf" and $match['id_player2'] == winnerOf($match))
  335. {
  336. return(1);
  337. }
  338. }
  339. //================================================================================
  340. // function getNextLoserRound
  341. // returns the round of the losers next match
  342. //================================================================================
  343. function getNextLoserRound(& $match)
  344. {
  345. global $season;
  346. if ($match['bracket'] == "wb" and
  347. $season['double_elimination'] != "" and
  348. $season['single_elimination'] / pow(2, $match['round'] - 1) <= $season['double_elimination']) {
  349. if ($season['single_elimination'] / pow(2, $match['round'] - 1) == $season['double_elimination'])
  350. {
  351. return(1);
  352. }
  353. else
  354. {
  355. return(($match['round'] - $season['single_elimination'] / $season['double_elimination']) * 2);
  356. }
  357. }
  358. elseif ($match['bracket'] == "wb" and $season['double_elimination'] != "")
  359. {
  360. return(1);
  361. }
  362. elseif ($match['bracket'] == "gf" and $match['id_player2'] == winnerOf($match))
  363. {
  364. return(1);
  365. }
  366. }
  367. //================================================================================
  368. // function getNextWinnerMatch
  369. // returns the match of the winners next match
  370. //================================================================================
  371. function getNextWinnerMatch(& $match)
  372. {
  373. global $season;
  374. if ($match['bracket'] == "q")
  375. {
  376. return($match['match']);
  377. }
  378. elseif ($match['bracket'] == "wb" and $match['round'] < getNumWBRounds($season))
  379. {
  380. if (1 & $match['match'])
  381. {
  382. return(($match['match'] + 1) / 2);
  383. }
  384. else
  385. {
  386. return($match['match'] / 2);
  387. }
  388. } elseif ($match['bracket'] == "wb" and
  389. $match['round'] == getNumWBRounds($season) and
  390. $season['double_elimination'] != "") {
  391. return(1);
  392. }
  393. elseif ($match['bracket'] == "lb" and $match['round'] < getNumLBRounds($season))
  394. {
  395. if (1 & $match['round'])
  396. {
  397. return($match['match']);
  398. }
  399. else
  400. {
  401. if (1 & $match['match'])
  402. {
  403. return(($match['match'] + 1) / 2);
  404. }
  405. else
  406. {
  407. return($match['match'] / 2);
  408. }
  409. }
  410. } elseif ($match['bracket'] == "lb" and
  411. $match['round'] == getNumLBRounds($season)) {
  412. return(1);
  413. }
  414. elseif ($match['bracket'] == "gf" and $match['id_player2'] == winnerOf($match))
  415. {
  416. return(2);
  417. }
  418. }
  419. //================================================================================
  420. // function getNextLoserMatch
  421. // returns the match of the losers next match
  422. //================================================================================
  423. function getNextLoserMatch(& $match)
  424. {
  425. global $season;
  426. if ($match['bracket'] == "wb" and
  427. $season['double_elimination'] != "" and
  428. $season['single_elimination'] / pow(2, $match['round'] - 1) <= $season['double_elimination']) {
  429. $lb_round = $match['round'] - log10($season['single_elimination']) / log10(2) + log10($season['double_elimination']) / log10(2);
  430. if ($lb_round == 1)
  431. {
  432. if (1 & $match['match'])
  433. {
  434. return(($match['match'] + 1) / 2);
  435. }
  436. else
  437. {
  438. return($match['match'] / 2);
  439. }
  440. }
  441. else
  442. {
  443. return(getDblElDrop($lb_round, $match['match']));
  444. }
  445. }
  446. elseif ($match['bracket'] == "gf" and $match['id_player2'] == winnerOf($match))
  447. {
  448. return(2);
  449. }
  450. }
  451. //================================================================================
  452. // function getNextWinnerPlayer
  453. // returns the player of the winners next match
  454. //================================================================================
  455. function getNextWinnerPlayer(& $match)
  456. {
  457. global $season;
  458. if ($match['bracket'] == "q")
  459. {
  460. return("player2");
  461. }
  462. elseif ($match['bracket'] == "wb" and $match['round'] < getNumWBRounds($season))
  463. {
  464. if (1 & $match['match'])
  465. {
  466. return("player1");
  467. }
  468. else
  469. {
  470. return("player2");
  471. }
  472. } elseif ($match['bracket'] == "wb" and
  473. $match['round'] == getNumWBRounds($season) and
  474. $season['double_elimination'] != "") {
  475. return("player1");
  476. }
  477. elseif ($match['bracket'] == "lb" and $match['round'] < getNumLBRounds($season))
  478. {
  479. if (1 & $match['round'])
  480. {
  481. return("player2");
  482. }
  483. else
  484. {
  485. if (1 & $match['match'])
  486. {
  487. return("player1");
  488. }
  489. else
  490. {
  491. return("player2");
  492. }
  493. }
  494. } elseif ($match['bracket'] == "lb" and
  495. $match['round'] == getNumLBRounds($season)) {
  496. return("player2");
  497. }
  498. elseif ($match['bracket'] == "gf" and $match['id_player2'] == winnerOf($match))
  499. {
  500. return("player2");
  501. }
  502. }
  503. //================================================================================
  504. // function getNextLoserPlayer
  505. // returns the player of the losers next match
  506. //================================================================================
  507. function getNextLoserPlayer(& $match)
  508. {
  509. global $season;
  510. if ($match['bracket'] == "wb" and
  511. $season['double_elimination'] != "" and
  512. $season['single_elimination'] / pow(2, $match['round'] - 1) <= $season['double_elimination']) {
  513. if ($match['round'] == $season['single_elimination'] / $season['double_elimination'])
  514. {
  515. if (1 & $match['match'])
  516. {
  517. return("player1");
  518. }
  519. else
  520. {
  521. return("player2");
  522. }
  523. }
  524. else
  525. {
  526. return("player1");
  527. }
  528. }
  529. elseif ($match['bracket'] == "gf" and $match['id_player2'] == winnerOf($match))
  530. {
  531. return("player1");
  532. }
  533. }
  534. //================================================================================
  535. // function getSeeding
  536. // returns the seeding of a given exponent of 2
  537. //================================================================================
  538. function getSeeding($number)
  539. {
  540. $counter = 0;
  541. $range[0] = array(1, $number);
  542. $matches[$counter++] = 1;
  543. for ($i = 0; $i < log10($number) / log10(2); ++$i)
  544. {
  545. $temp = $range;
  546. $index = 0;
  547. for ($j = $counter - 1; $j >= 0; --$j)
  548. {
  549. foreach($temp as $current) {
  550. if ($current[0] == $matches[$j])
  551. {
  552. $range[$index++] = $current;
  553. }
  554. }
  555. }
  556. $temp = $range;
  557. $array_size = count($temp);
  558. for ($k = 0; $k < $array_size; ++$k)
  559. {
  560. $start = $temp[$k][0];
  561. $end = $temp[$k][0] + ($temp[$k][1] - $temp[$k][0] + 1) / 2 - 1;
  562. $range[$k * 2] = array($start, $end);
  563. $start = $temp[$k][0] + ($temp[$k][1] - $temp[$k][0] + 1) / 2;
  564. $end = $temp[$k][1];
  565. $range[$k * 2 + 1] = array($start, $end);
  566. $matches[$counter++] = $start;
  567. }
  568. }
  569. return($matches);
  570. }
  571. //================================================================================
  572. // function getDblElDrop
  573. // returns the drop to the LB
  574. // thx to frode nilsen for the code-segment
  575. //================================================================================
  576. function getDblElDrop($round, $match)
  577. {
  578. global $season;
  579. $roundSize = $season['double_elimination'] / 2;
  580. $roundIndex = $match - 1;
  581. $roundNr = $round - 1;
  582. $key = $roundSize / 2;
  583. $nr = $roundIndex * (1 << $roundNr);
  584. for ($i = 1; $i <= $roundNr; $i++)
  585. {
  586. for ($a = $key, $b = 1; $a > 0; $a >>= 1, $b <<= 1)
  587. {
  588. if ($i % $b == 0)
  589. {
  590. if (($nr & $a) > 0) $nr -= $a;
  591. else $nr += $a;
  592. }
  593. }
  594. }
  595. $nr >>= $roundNr;
  596. return($nr + 1);
  597. }
  598. //================================================================================
  599. // function getNumWBRounds
  600. // returns the number of winners bracket rounds of a given season
  601. //================================================================================
  602. function getNumWBRounds(& $season)
  603. {
  604. $num_participants = $season['single_elimination'];
  605. $num_wb_rounds = log10($num_participants) / log10(2);
  606. return($num_wb_rounds);
  607. }
  608. //================================================================================
  609. // function getNumLBRounds
  610. // returns the number of losers bracket rounds of a given season divided by 2
  611. //================================================================================
  612. function getNumLBRounds(& $season)
  613. {
  614. $num_participants = $season['double_elimination'];
  615. $num_lb_rounds = (log10($num_participants) / log10(2) - 1) * 2;
  616. return($num_lb_rounds);
  617. }
  618. //================================================================================
  619. // function getNumWBMatches
  620. // returns the number of matches in a winners bracket round of a given season
  621. //================================================================================
  622. function getNumWBMatches(& $season, $i)
  623. {
  624. $num_participants = $season['single_elimination'];
  625. $num_wb_matches = $num_participants / pow(2, $i);
  626. return($num_wb_matches);
  627. }
  628. //================================================================================
  629. // function getNumLBMatches
  630. // returns the number of matches in a losers bracket round of a given season
  631. //================================================================================
  632. function getNumLBMatches(& $season, $i)
  633. {
  634. if ((1 & $i))
  635. {
  636. $i = ($i + 1) / 2;
  637. }
  638. else
  639. {
  640. $i = $i / 2;
  641. }
  642. $num_participants = $season['double_elimination'];
  643. $num_lb_matches = $num_participants / pow(2, $i);
  644. return($num_lb_matches);
  645. }
  646. //================================================================================
  647. // function isAfterPreDeadline
  648. // checks whether a given round is after the pre-deadline
  649. //================================================================================
  650. function isAfterPreDeadline(& $season, $bracket, $round) {
  651. global $cfg;
  652. $today = getdate();
  653. $year = $today['year'];
  654. $month = $today['mon'];
  655. $day = $today['mday'];
  656. $pre_deadline_round = $round - 1;
  657. $deadlines_ref = dbQuery("SELECT * FROM `{$cfg['db_table_prefix']}deadlines` " .
  658. "WHERE `id_season` = {$season['id']} " .
  659. "AND `round` = '$bracket$pre_deadline_round'");
  660. if (dbNumRows($deadlines_ref) == 0)
  661. {
  662. return(true);
  663. }
  664. else
  665. {
  666. $deadlines_row = dbFetch($deadlines_ref);
  667. $deadline = $deadlines_row['deadline'];
  668. preg_match("/(\d\d\d\d)-\d\d-\d\d/", $deadlines_row['deadline'], $matches);
  669. $d_year = $matches[1];
  670. preg_match("/\d\d\d\d-(\d\d)-\d\d/", $deadlines_row['deadline'], $matches);
  671. $d_month = $matches[1];
  672. preg_match("/\d\d\d\d-\d\d-(\d\d)/", $deadlines_row['deadline'], $matches);
  673. $d_day = $matches[1];
  674. if ($year > $d_year or
  675. $year == $d_year and $month > $d_month or
  676. $year == $d_year and $month == $d_month and $day > $d_day)
  677. {
  678. return(true);
  679. }
  680. else
  681. {
  682. return(false);
  683. }
  684. }
  685. }
  686. //================================================================================
  687. // function isBeforePostDeadline
  688. // checks whether a given round is before the post-deadline
  689. //================================================================================
  690. function isBeforePostDeadline(& $season, $bracket, $round)
  691. {
  692. global $cfg;
  693. $today = getdate();
  694. $year = $today['year'];
  695. $month = $today['mon'];
  696. $day = $today['mday'];
  697. $post_deadline_round = $round;
  698. $deadlines_ref = dbQuery("SELECT * FROM `{$cfg['db_table_prefix']}deadlines` " .
  699. "WHERE `id_season` = {$season['id']} " .
  700. "AND `round` = '$bracket$post_deadline_round'");
  701. if (dbNumRows($deadlines_ref) == 0)
  702. {
  703. return(true);
  704. }
  705. else
  706. {
  707. $deadlines_row = dbFetch($deadlines_ref);
  708. $deadline = $deadlines_row['deadline'];
  709. preg_match("/(\d\d\d\d)-\d\d-\d\d/", $deadlines_row['deadline'], $matches);
  710. $d_year = $matches[1];
  711. preg_match("/\d\d\d\d-(\d\d)-\d\d/", $deadlines_row['deadline'], $matches);
  712. $d_month = $matches[1];
  713. preg_match("/\d\d\d\d-\d\d-(\d\d)/", $deadlines_row['deadline'], $matches);
  714. $d_day = $matches[1];
  715. if ($year < $d_year or
  716. $year == $d_year and $month < $d_month or
  717. $year == $d_year and $month == $d_month and $day <= $d_day) {
  718. return(true);
  719. }
  720. else
  721. {
  722. return(false);
  723. }
  724. }
  725. }
  726. //================================================================================
  727. // function winnerOf
  728. // returns the player-id of the winner of the given match
  729. //================================================================================
  730. function winnerOf(& $match)
  731. {
  732. global $cfg;
  733. if ($match['confirmed'] == "0000-00-00 00:00:00")
  734. {
  735. return(NULL);
  736. }
  737. if ($match['score_p1'] > $match['score_p2'])
  738. {
  739. return($match['id_player1']);
  740. }
  741. elseif ($match['score_p1'] < $match['score_p2'])
  742. {
  743. return($match['id_player2']);
  744. }
  745. }
  746. ?>