PageRenderTime 52ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/php/matches/view_graphic.php

https://github.com/eb/phptourney
PHP | 956 lines | 761 code | 92 blank | 103 comment | 116 complexity | a3a6e79f336c14ce07da3a77c057eb74 MD5 | raw file
Possible License(s): LGPL-2.0
  1. <?php
  2. define("TOP_OFFSET", 100);
  3. define("LEFT_OFFSET", 100);
  4. define("ROW_HEIGHT", 13);
  5. define("ROUND_WIDTH", 100);
  6. define("CON_WIDTH", 10);
  7. // template blocks
  8. $content_tpl->set_block("F_CONTENT", "B_NO_BRACKET", "H_NO_BRACKET");
  9. $content_tpl->set_block("F_CONTENT", "B_BRACKET", "H_BRACKET");
  10. $content_tpl->set_block("F_CONTENT", "B_MATCH", "H_MATCH");
  11. $content_tpl->set_block("F_CONTENT", "B_MATCH_PLAYER", "H_MATCH_PLAYER");
  12. $content_tpl->set_block("F_CONTENT", "B_MATCH_WINNER", "H_MATCH_WINNER");
  13. $content_tpl->set_block("F_CONTENT", "B_MATCH_WO", "H_MATCH_WO");
  14. $content_tpl->set_block("F_CONTENT", "B_MATCH_BYE", "H_MATCH_BYE");
  15. $content_tpl->set_block("F_CONTENT", "B_MATCH_OUT", "H_MATCH_OUT");
  16. $content_tpl->set_block("F_CONTENT", "B_CON", "H_CON");
  17. if ($season['status'] == "bracket" or $season['status'] == "running" or $season['status'] == "finished")
  18. {
  19. $matches = getAllMatches($season);
  20. $qualification = $season['qualification'];
  21. $single_elimination = $season['single_elimination'];
  22. $double_elimination = $season['double_elimination'];
  23. $num_wb_rounds = getNumWBRounds($season);
  24. $num_lb_rounds = getNumLBRounds($season);
  25. ////////////////////////////////////////////////////////////////////////////////
  26. // qualification
  27. ////////////////////////////////////////////////////////////////////////////////
  28. if ($qualification == 1)
  29. {
  30. # q();
  31. # q_con();
  32. }
  33. ////////////////////////////////////////////////////////////////////////////////
  34. // single elimination
  35. ////////////////////////////////////////////////////////////////////////////////
  36. if ($double_elimination == "")
  37. {
  38. for ($i = 0; $i < $num_wb_rounds; $i++)
  39. {
  40. wb($i);
  41. # wb_con($i + 1);
  42. }
  43. # se_winner($i - 1);
  44. }
  45. ////////////////////////////////////////////////////////////////////////////////
  46. // double elimination
  47. ////////////////////////////////////////////////////////////////////////////////
  48. else
  49. {
  50. for ($i = 0; $i < $num_wb_rounds; $i++)
  51. {
  52. $num_players = $single_elimination / pow(2, $i);
  53. if ($num_players > $double_elimination)
  54. {
  55. wb($i);
  56. # wb_con($i + 1);
  57. }
  58. elseif ($num_players == $double_elimination)
  59. {
  60. wb($i);
  61. # wb_con($i + 1);
  62. }
  63. elseif ($num_players == $double_elimination / 2)
  64. {
  65. wb($i);
  66. # lb($i);
  67. # wb_con($i + 1);
  68. # lb_el_con($i + 1);
  69. }
  70. else
  71. {
  72. # wb_empty($i);
  73. # lb_el($i);
  74. # wb_empty_con($i);
  75. # lb_con($i);
  76. wb($i);
  77. # lb($i);
  78. # wb_con($i + 1);
  79. # lb_el_con($i + 1);
  80. }
  81. }
  82. # wb_empty($i - 1);
  83. # lb_el($i);
  84. # gf_con($i - 1);
  85. # gf($i - 1);
  86. # if (true) {
  87. # gf2_con($i - 1);
  88. # gf($i - 1);
  89. # }
  90. # gf2_con($i - 1);
  91. # gf_winner($i - 1);
  92. }
  93. $content_tpl->parse("H_BRACKET", "B_BRACKET");
  94. }
  95. else
  96. {
  97. $content_tpl->parse("H_NO_BRACKET", "B_NO_BRACKET");
  98. }
  99. ################################################################################
  100. #
  101. #
  102. ################################################################################
  103. function q() {
  104. global $single_elimination;
  105. global $rounds;
  106. global $brackets;
  107. global $matches_q;
  108. $bracket = & $brackets[count($brackets) - 1];
  109. for ($j = 0; $j < $single_elimination / 2; $j++)
  110. {
  111. if ($matches_q[$j])
  112. {
  113. # $winner = winner_is($_REQUEST['sid'], "q", 0, $j + 1);
  114. if ($winner == "p1")
  115. {
  116. array_push($bracket, "SPACE");
  117. array_push($bracket, "MATCH_WINNER1");
  118. array_push($bracket, "FIRST_MATCH");
  119. array_push($bracket, "MATCH_PLAYER2");
  120. }
  121. elseif ($winner == "p2")
  122. {
  123. array_push($bracket, "SPACE");
  124. array_push($bracket, "MATCH_PLAYER1");
  125. array_push($bracket, "FIRST_MATCH");
  126. array_push($bracket, "MATCH_WINNER2");
  127. }
  128. else
  129. {
  130. array_push($bracket, "SPACE");
  131. array_push($bracket, "MATCH_PLAYER1");
  132. array_push($bracket, "FIRST_MATCH");
  133. array_push($bracket, "MATCH_PLAYER2");
  134. }
  135. }
  136. else
  137. {
  138. array_push($bracket, "SPACE");
  139. array_push($bracket, "SPACE");
  140. array_push($bracket, "SPACE_MATCH");
  141. array_push($bracket, "SPACE");
  142. }
  143. }
  144. }
  145. ################################################################################
  146. #
  147. #
  148. ################################################################################
  149. function q_con() {
  150. global $single_elimination;
  151. global $rounds;
  152. global $brackets;
  153. global $matches_q;
  154. $bracket = & $brackets[count($brackets) - 1];
  155. for ($j = 0; $j < $single_elimination / 2; $j++)
  156. {
  157. if ($matches_q[$j])
  158. {
  159. array_push($bracket, "CON_SPACE");
  160. array_push($bracket, "CON_SPACE");
  161. array_push($bracket, "CON_HOR");
  162. array_push($bracket, "CON_SPACE");
  163. }
  164. else
  165. {
  166. array_push($bracket, "CON_SPACE");
  167. array_push($bracket, "CON_SPACE");
  168. array_push($bracket, "CON_SPACE");
  169. array_push($bracket, "CON_SPACE");
  170. }
  171. }
  172. }
  173. ################################################################################
  174. #
  175. #
  176. ################################################################################
  177. function wb($i) {
  178. global $season;
  179. global $qualification;
  180. global $single_elimination;
  181. global $content_tpl;
  182. global $matches;
  183. $bracket = & $brackets[count($brackets) - 1];
  184. $num_matches = $single_elimination / pow(2, $i) / 2;
  185. $num_spaces = (pow(2, $i) * 4 - 4) / 2;
  186. $top = TOP_OFFSET;
  187. $left = LEFT_OFFSET + $i * (ROUND_WIDTH + CON_WIDTH * 3);
  188. for ($j = 0; $j < $num_matches; $j++)
  189. {
  190. $match_key = "wb-" . ($i + 1) . "-" . ($j + 1);
  191. for ($k = 0; $k < $num_spaces; $k++)
  192. {
  193. $top += ROW_HEIGHT;
  194. }
  195. $content_tpl->set_var("I_TOP", $top);
  196. $content_tpl->set_var("I_LEFT", $left);
  197. $content_tpl->set_var("I_PLAYER1", "");
  198. $content_tpl->set_var("I_PLAYER2", "");
  199. if ($matches[$match_key]['confirmed'] != "0000-00-00 00:00:00")
  200. {
  201. $content_tpl->set_var("I_SCORE", $matches[$match_key]['score1']);
  202. $content_tpl->set_var("I_PLAYER", $matches[$match_key]['player1']);
  203. if ($matches[$match_key]['wo'] == $matches[$match_key]['id_player1'])
  204. {
  205. $content_tpl->parse("I_PLAYER1", "B_MATCH_WO");
  206. }
  207. elseif ($matches[$match_key]['bye'] == 1 and $matches[$match_key]['id_player1'] > 0)
  208. {
  209. $content_tpl->parse("I_PLAYER1", "B_MATCH_BYE");
  210. }
  211. elseif ($matches[$match_key]['out'] == 1)
  212. {
  213. $content_tpl->parse("I_PLAYER1", "B_MATCH_OUT");
  214. }
  215. elseif ($matches[$match_key]['score1'] > $matches[$match_key]['score2'])
  216. {
  217. $content_tpl->parse("I_PLAYER1", "B_MATCH_WINNER");
  218. }
  219. else
  220. {
  221. $content_tpl->parse("I_PLAYER1", "B_MATCH_PLAYER");
  222. }
  223. $content_tpl->set_var("I_SCORE", $matches[$match_key]['score2']);
  224. $content_tpl->set_var("I_PLAYER", $matches[$match_key]['player2']);
  225. if ($matches[$match_key]['wo'] == $matches[$match_key]['id_player2'])
  226. {
  227. $content_tpl->parse("I_PLAYER2", "B_MATCH_WO");
  228. }
  229. elseif ($matches[$match_key]['bye'] == 1 and $matches[$match_key]['id_player2'] > 0)
  230. {
  231. $content_tpl->parse("I_PLAYER2", "B_MATCH_BYE");
  232. }
  233. elseif ($matches[$match_key]['out'] == 1)
  234. {
  235. $content_tpl->parse("I_PLAYER2", "B_MATCH_OUT");
  236. }
  237. elseif ($matches[$match_key]['score1'] < $matches[$match_key]['score2'])
  238. {
  239. $content_tpl->parse("I_PLAYER2", "B_MATCH_WINNER");
  240. }
  241. else
  242. {
  243. $content_tpl->parse("I_PLAYER2", "B_MATCH_PLAYER");
  244. }
  245. }
  246. else
  247. {
  248. $content_tpl->set_var("I_SCORE", $matches[$match_key]['score1']);
  249. $content_tpl->set_var("I_PLAYER", "gna");
  250. # $content_tpl->parse("I_PLAYER1", "B_MATCH_PLAYER");
  251. $content_tpl->parse("I_PLAYER1", "B_MATCH_PLAYER");
  252. $content_tpl->set_var("I_SCORE", $matches[$match_key]['score2']);
  253. # $content_tpl->set_var("I_PLAYER", $matches[$match_key]['player2']);
  254. $content_tpl->set_var("I_PLAYER", "bla");
  255. $content_tpl->parse("I_PLAYER2", "B_MATCH_PLAYER");
  256. }
  257. $content_tpl->set_var("I_ID_SEASON", $season['id']);
  258. $content_tpl->set_var("I_ID_MATCH", $matches[$match_key]['id']);
  259. $content_tpl->set_var("I_MATCH_KEY", $match_key);
  260. $content_tpl->parse("I_MATCHES", "B_MATCH", true);
  261. $top += ROW_HEIGHT * 3;
  262. for ($k = 0; $k < $num_spaces; $k++)
  263. {
  264. $top += ROW_HEIGHT;
  265. }
  266. $top += ROW_HEIGHT;
  267. }
  268. }
  269. ################################################################################
  270. #
  271. #
  272. ################################################################################
  273. function se_winner($i) {
  274. global $single_elimination;
  275. global $rounds;
  276. global $brackets;
  277. $bracket = & $brackets[count($brackets) - 1];
  278. $num_matches = $single_elimination / pow(2, $i) / 2;
  279. $num_spaces = (pow(2, $i) * 4 - 4) / 2;
  280. for ($j = 1; $j <= $num_matches; $j++)
  281. {
  282. for ($k = 0; $k < $num_spaces; $k++)
  283. {
  284. array_push($bracket, "SPACE");
  285. }
  286. array_push($bracket, "SPACE");
  287. array_push($bracket, "WINNER");
  288. array_push($bracket, "SPACE");
  289. for ($k = 0; $k < $num_spaces; $k++)
  290. {
  291. array_push($bracket, "SPACE");
  292. }
  293. array_push($bracket, "SPACE");
  294. }
  295. }
  296. ################################################################################
  297. #
  298. #
  299. ################################################################################
  300. function lb($i) {
  301. global $single_elimination;
  302. global $double_elimination;
  303. global $rounds;
  304. global $brackets;
  305. $bracket = & $brackets[count($brackets) - 1];
  306. $num_wb_rounds = log10($single_elimination) / log10(2);
  307. $num_lb_rounds = log10($double_elimination) / log10(2);
  308. $num_lb_round = $i - ($num_wb_rounds - $num_lb_rounds);
  309. $num_matches = $double_elimination / 2 / pow(2, $num_lb_round);
  310. $bottom_space = ($num_lb_round - 1) * 2 + (pow(2, $num_lb_round - 1) - 1) * 4;
  311. $normal_space = (pow(2, $num_lb_round) - 2) * 4;
  312. $top_space = $normal_space - $bottom_space;
  313. for ($k = 0; $k < $top_space; $k++)
  314. {
  315. array_push($bracket, "SPACE");
  316. }
  317. for ($k = 1; $k <= $num_matches; $k++)
  318. {
  319. array_push($bracket, "SPACE");
  320. array_push($bracket, "LOSER");
  321. array_push($bracket, "SPACE");
  322. array_push($bracket, "SPACE");
  323. array_push($bracket, "MATCH_PLAYER1");
  324. array_push($bracket, "MATCH");
  325. array_push($bracket, "MATCH_PLAYER2");
  326. array_push($bracket, "SPACE");
  327. if ($k != $num_matches)
  328. {
  329. for ($j = 0; $j < $normal_space; $j++){
  330. array_push($bracket, "SPACE");
  331. }
  332. }
  333. }
  334. for ($k = 0; $k < $bottom_space; $k++)
  335. {
  336. array_push($bracket, "SPACE");
  337. }
  338. }
  339. ################################################################################
  340. #
  341. #
  342. ################################################################################
  343. function lb_el($i) {
  344. global $single_elimination;
  345. global $double_elimination;
  346. global $rounds;
  347. global $brackets;
  348. $bracket = & $brackets[count($brackets) - 1];
  349. $num_wb_rounds = log10($single_elimination) / log10(2);
  350. $num_lb_rounds = log10($double_elimination) / log10(2);
  351. $num_lb_round = $i - ($num_wb_rounds - $num_lb_rounds);
  352. $num_matches = $double_elimination / pow(2, $num_lb_round);
  353. $bottom_space = ($num_lb_round - 2) * 2 + (pow(2, $num_lb_round - 2) - 1) * 4;
  354. $normal_space = (pow(2, $num_lb_round - 1) - 2) * 4;
  355. $top_space = $normal_space - $bottom_space;
  356. $top_space += 2;
  357. $normal_space +=4;
  358. $bottom_space += 2;
  359. for ($k = 0; $k < $top_space; $k++)
  360. {
  361. array_push($bracket, "SPACE");
  362. }
  363. for ($k = 1; $k <= $num_matches; $k++)
  364. {
  365. array_push($bracket, "MATCH_PLAYER1");
  366. array_push($bracket, "MATCH");
  367. array_push($bracket, "MATCH_PLAYER2");
  368. array_push($bracket, "SPACE");
  369. if ($k != $num_matches)
  370. {
  371. for ($j = 0; $j < $normal_space; $j++){
  372. array_push($bracket, "SPACE");
  373. }
  374. }
  375. }
  376. for ($k = 0; $k < $bottom_space; $k++)
  377. {
  378. array_push($bracket, "SPACE");
  379. }
  380. }
  381. ################################################################################
  382. #
  383. #
  384. ################################################################################
  385. function wb_empty($i) {
  386. global $single_elimination;
  387. global $rounds;
  388. global $brackets;
  389. $bracket = & $brackets[count($brackets) - 1];
  390. $num_matches = $single_elimination / pow(2, $i) / 2;
  391. $num_spaces = (pow(2, $i) * 4 - 4) / 2;
  392. for ($j = 1; $j <= $num_matches; $j++)
  393. {
  394. for ($k = 0; $k < $num_spaces; $k++)
  395. {
  396. array_push($bracket, "SPACE");
  397. }
  398. array_push($bracket, "SPACE");
  399. array_push($bracket, "EMPTY");
  400. array_push($bracket, "SPACE");
  401. for ($k = 0; $k < $num_spaces; $k++)
  402. {
  403. array_push($bracket, "SPACE");
  404. }
  405. array_push($bracket, "SPACE");
  406. }
  407. }
  408. ################################################################################
  409. #
  410. #
  411. ################################################################################
  412. function wb_con($i) {
  413. global $single_elimination;
  414. global $rounds;
  415. global $brackets;
  416. $bracket = & $brackets[count($brackets) - 1];
  417. $num_matches = $single_elimination / pow(2, $i) / 2;
  418. $num_spaces = (pow(2, $i) * 4 - 4) / 2;
  419. $num_vers = pow(2, $i) - 1;
  420. if ($num_matches < 1)
  421. {
  422. for ($j = 1; $j <= $single_elimination * 2; $j++)
  423. {
  424. if ($j == $single_elimination)
  425. {
  426. array_push($bracket, "CON_HOR");
  427. }
  428. else
  429. {
  430. array_push($bracket, "CON_SPACE");
  431. }
  432. }
  433. }
  434. for ($j = 1; $j <= $num_matches; $j++)
  435. {
  436. for ($k = 0; $k < $num_spaces - $num_vers; $k++)
  437. {
  438. array_push($bracket, "CON_SPACE");
  439. }
  440. array_push($bracket, "CON_TOP");
  441. for ($l = 0; $l < $num_vers; $l++)
  442. {
  443. array_push($bracket, "CON_VER");
  444. }
  445. array_push($bracket, "CON_MIDDLE");
  446. for ($l = 0; $l < $num_vers; $l++)
  447. {
  448. array_push($bracket, "CON_VER");
  449. }
  450. array_push($bracket, "CON_BOTTOM");
  451. for ($k = 0; $k < $num_spaces - $num_vers; $k++)
  452. {
  453. array_push($bracket, "CON_SPACE");
  454. }
  455. array_push($bracket, "CON_SPACE");
  456. }
  457. }
  458. ################################################################################
  459. #
  460. #
  461. ################################################################################
  462. function wb_empty_con($i) {
  463. global $single_elimination;
  464. global $rounds;
  465. global $brackets;
  466. $bracket = & $brackets[count($brackets) - 1];
  467. $bracket = array();
  468. $num_matches = $single_elimination / pow(2, $i) / 2;
  469. $num_spaces = (pow(2, $i) * 4 - 4) / 2;
  470. for ($j = 1; $j <= $num_matches; $j++)
  471. {
  472. for ($k = 0; $k < $num_spaces; $k++)
  473. {
  474. array_push($bracket, "CON_SPACE");
  475. }
  476. array_push($bracket, "CON_SPACE");
  477. array_push($bracket, "CON_HOR");
  478. array_push($bracket, "CON_SPACE");
  479. for ($k = 0; $k < $num_spaces; $k++)
  480. {
  481. array_push($bracket, "CON_SPACE");
  482. }
  483. array_push($bracket, "CON_SPACE");
  484. }
  485. }
  486. ################################################################################
  487. #
  488. #
  489. ################################################################################
  490. function lb_con($i) {
  491. global $single_elimination;
  492. global $double_elimination;
  493. global $rounds;
  494. global $brackets;
  495. $bracket = & $brackets[count($brackets) - 1];
  496. $num_matches = $single_elimination / pow(2, $i) / 2;
  497. $num_wb_rounds = log10($single_elimination) / log10(2);
  498. $num_lb_rounds = log10($double_elimination) / log10(2);
  499. $num_lb_round = $i - ($num_wb_rounds - $num_lb_rounds);
  500. $num_spaces = pow(2, $num_lb_round + 1) - 1;
  501. $num_vers = pow(2, $num_lb_round) - 1;
  502. $num_top_spaces = $num_vers - ($num_lb_round - 2) * 2;
  503. $num_bottom_spaces = $num_spaces - $num_top_spaces;
  504. if ($num_lb_round == 1)
  505. {
  506. for ($j = 1; $j <= $num_matches; $j++)
  507. {
  508. array_push($bracket, "CON_SPACE");
  509. array_push($bracket, "CON_SPACE");
  510. array_push($bracket, "CON_SPACE");
  511. array_push($bracket, "CON_SPACE");
  512. array_push($bracket, "CON_TOP");
  513. array_push($bracket, "CON_MIDDLE");
  514. array_push($bracket, "CON_BOTTOM");
  515. array_push($bracket, "CON_SPACE");
  516. }
  517. }
  518. else
  519. {
  520. for ($j = 1; $j <= $num_matches; $j++)
  521. {
  522. for ($k = 1; $k <= $num_top_spaces; $k++)
  523. {
  524. array_push($bracket, "CON_SPACE");
  525. }
  526. array_push($bracket, "CON_TOP");
  527. for ($k = 1; $k <= $num_vers; $k++)
  528. {
  529. array_push($bracket, "CON_VER");
  530. }
  531. array_push($bracket, "CON_MIDDLE");
  532. for ($k = 1; $k <= $num_vers; $k++)
  533. {
  534. array_push($bracket, "CON_VER");
  535. }
  536. array_push($bracket, "CON_BOTTOM");
  537. for ($k = 1; $k <= $num_bottom_spaces; $k++)
  538. {
  539. array_push($bracket, "CON_SPACE");
  540. }
  541. }
  542. }
  543. }
  544. ################################################################################
  545. #
  546. #
  547. ################################################################################
  548. function lb_el_con($i) {
  549. global $single_elimination;
  550. global $double_elimination;
  551. global $rounds;
  552. global $brackets;
  553. $bracket = & $brackets[count($brackets) - 1];
  554. $num_matches = $single_elimination / pow(2, $i);
  555. $num_wb_rounds = log10($single_elimination) / log10(2);
  556. $num_lb_rounds = log10($double_elimination) / log10(2);
  557. $num_lb_round = $i - ($num_wb_rounds - $num_lb_rounds);
  558. $num_spaces = pow(2, $num_lb_round + 1) - 5;
  559. $num_top_spaces = ($num_spaces + 1) / 2 - 1 - ($num_lb_round - 2) * 2;
  560. $num_bottom_spaces = $num_spaces - $num_top_spaces;
  561. for ($j = 1; $j <= $num_matches; $j++)
  562. {
  563. for ($k = 1; $k <= $num_top_spaces; $k++)
  564. {
  565. array_push($bracket, "CON_SPACE");
  566. }
  567. array_push($bracket, "CON_TOP");
  568. array_push($bracket, "CON_VER");
  569. array_push($bracket, "CON_MIDDLE");
  570. array_push($bracket, "CON_VER");
  571. array_push($bracket, "CON_BOTTOM");
  572. for ($k = 1; $k <= $num_bottom_spaces; $k++)
  573. {
  574. array_push($bracket, "CON_SPACE");
  575. }
  576. }
  577. }
  578. ################################################################################
  579. #
  580. #
  581. ################################################################################
  582. function lb_finale($i) {
  583. global $single_elimination;
  584. global $double_elimination;
  585. global $rounds;
  586. global $brackets;
  587. $bracket = & $brackets[count($brackets) - 1];
  588. $num_wb_rounds = log10($single_elimination) / log10(2);
  589. $num_lb_rounds = log10($double_elimination) / log10(2);
  590. $num_lb_round = $i - ($num_wb_rounds - $num_lb_rounds);
  591. $num_matches = $double_elimination / pow(2, $num_lb_round);
  592. $bottom_space = ($num_lb_round - 2) * 2 + (pow(2, $num_lb_round - 2) - 1) * 4;
  593. $normal_space = (pow(2, $num_lb_round - 1) - 2) * 4;
  594. $top_space = $normal_space - $bottom_space;
  595. $top_space += 2;
  596. $normal_space +=4;
  597. $bottom_space += 2;
  598. for ($k = 0; $k < $top_space; $k++)
  599. {
  600. array_push($bracket, "SPACE");
  601. }
  602. for ($k = 1; $k <= $num_matches; $k++)
  603. {
  604. array_push($bracket, "MATCH_PLAYER1");
  605. array_push($bracket, "MATCH");
  606. array_push($bracket, "MATCH_PLAYER2");
  607. array_push($bracket, "SPACE");
  608. if ($k != $num_matches)
  609. {
  610. for ($j = 0; $j < $normal_space; $j++){
  611. array_push($bracket, "SPACE");
  612. }
  613. }
  614. }
  615. for ($k = 0; $k < $bottom_space; $k++)
  616. {
  617. array_push($bracket, "SPACE");
  618. }
  619. }
  620. ################################################################################
  621. #
  622. #
  623. ################################################################################
  624. function gf($i) {
  625. global $single_elimination;
  626. global $double_elimination;
  627. global $rounds;
  628. global $brackets;
  629. $bracket = & $brackets[count($brackets) - 1];
  630. $num_matches = $single_elimination / pow(2, $i) / 2;
  631. $num_spaces = (pow(2, $i) * 4 - 4) / 2;
  632. for ($j = 1; $j <= $num_matches; $j++)
  633. {
  634. for ($k = 0; $k < $num_spaces; $k++)
  635. {
  636. array_push($bracket, "SPACE");
  637. }
  638. array_push($bracket, "SPACE");
  639. array_push($bracket, "SPACE");
  640. array_push($bracket, "SPACE");
  641. for ($k = 0; $k < $num_spaces - 1; $k++)
  642. {
  643. array_push($bracket, "SPACE");
  644. }
  645. array_push($bracket, "MATCH_PLAYER1");
  646. array_push($bracket, "MATCH");
  647. array_push($bracket, "MATCH_PLAYER2");
  648. }
  649. $i++;
  650. $num_wb_rounds = log10($single_elimination) / log10(2);
  651. $num_lb_rounds = log10($double_elimination) / log10(2);
  652. $num_lb_round = $i - ($num_wb_rounds - $num_lb_rounds);
  653. $num_matches = $double_elimination / pow(2, $num_lb_round);
  654. $bottom_space = ($num_lb_round - 2) * 2 + (pow(2, $num_lb_round - 2) - 1) * 4;
  655. $normal_space = (pow(2, $num_lb_round - 1) - 2) * 4;
  656. $top_space = $normal_space - $bottom_space;
  657. $top_space += 2;
  658. $normal_space +=4;
  659. $bottom_space += 2;
  660. for ($k = 0; $k < $top_space - 1; $k++)
  661. {
  662. array_push($bracket, "SPACE");
  663. }
  664. for ($k = 1; $k <= $num_matches; $k++)
  665. {
  666. array_push($bracket, "SPACE");
  667. array_push($bracket, "SPACE");
  668. array_push($bracket, "SPACE");
  669. array_push($bracket, "SPACE");
  670. if ($k != $num_matches)
  671. {
  672. for ($j = 0; $j < $normal_space; $j++){
  673. array_push($bracket, "SPACE");
  674. }
  675. }
  676. }
  677. for ($k = 0; $k < $bottom_space; $k++)
  678. {
  679. array_push($bracket, "SPACE");
  680. }
  681. }
  682. ################################################################################
  683. #
  684. #
  685. ################################################################################
  686. function gf_con($i) {
  687. global $single_elimination;
  688. global $double_elimination;
  689. global $rounds;
  690. global $brackets;
  691. $bracket = & $brackets[count($brackets) - 1];
  692. $num_matches = $single_elimination / pow(2, $i) / 2;
  693. $num_spaces = (pow(2, $i) * 4 - 4) / 2;
  694. for ($j = 1; $j <= $num_matches; $j++)
  695. {
  696. for ($k = 0; $k < $num_spaces; $k++)
  697. {
  698. array_push($bracket, "CON_SPACE");
  699. }
  700. array_push($bracket, "CON_SPACE");
  701. array_push($bracket, "CON_TOP");
  702. array_push($bracket, "CON_VER");
  703. for ($k = 0; $k < $num_spaces; $k++)
  704. {
  705. array_push($bracket, "CON_VER");
  706. }
  707. array_push($bracket, "CON_MIDDLE");
  708. }
  709. $i++;
  710. $num_wb_rounds = log10($single_elimination) / log10(2);
  711. $num_lb_rounds = log10($double_elimination) / log10(2);
  712. $num_lb_round = $i - ($num_wb_rounds - $num_lb_rounds);
  713. $num_matches = $double_elimination / pow(2, $num_lb_round);
  714. $bottom_space = ($num_lb_round - 2) * 2 + (pow(2, $num_lb_round - 2) - 1) * 4;
  715. $normal_space = (pow(2, $num_lb_round - 1) - 2) * 4;
  716. $top_space = $normal_space - $bottom_space;
  717. $top_space += 2;
  718. $normal_space +=4;
  719. $bottom_space += 2;
  720. for ($k = 0; $k < $top_space; $k++)
  721. {
  722. array_push($bracket, "CON_VER");
  723. }
  724. for ($k = 1; $k <= $num_matches; $k++)
  725. {
  726. array_push($bracket, "CON_VER");
  727. array_push($bracket, "CON_BOTTOM");
  728. array_push($bracket, "CON_SPACE");
  729. array_push($bracket, "CON_SPACE");
  730. if ($k != $num_matches)
  731. {
  732. for ($j = 0; $j < $normal_space; $j++){
  733. array_push($bracket, "CON_SPACE");
  734. }
  735. }
  736. }
  737. for ($k = 0; $k < $bottom_space; $k++)
  738. {
  739. array_push($bracket, "CON_SPACE");
  740. }
  741. }
  742. ################################################################################
  743. #
  744. #
  745. ################################################################################
  746. function gf2_con($i) {
  747. global $single_elimination;
  748. global $double_elimination;
  749. global $rounds;
  750. global $brackets;
  751. $bracket = & $brackets[count($brackets) - 1];
  752. $num_matches = $single_elimination / pow(2, $i) / 2;
  753. $num_spaces = (pow(2, $i) * 4 - 4) / 2;
  754. for ($j = 1; $j <= $num_matches; $j++)
  755. {
  756. for ($k = 0; $k < $num_spaces; $k++)
  757. {
  758. array_push($bracket, "CON_SPACE");
  759. }
  760. array_push($bracket, "CON_SPACE");
  761. array_push($bracket, "CON_SPACE");
  762. array_push($bracket, "CON_SPACE");
  763. for ($k = 0; $k < $num_spaces; $k++)
  764. {
  765. array_push($bracket, "CON_SPACE");
  766. }
  767. array_push($bracket, "CON_HOR");
  768. }
  769. $i++;
  770. $num_wb_rounds = log10($single_elimination) / log10(2);
  771. $num_lb_rounds = log10($double_elimination) / log10(2);
  772. $num_lb_round = $i - ($num_wb_rounds - $num_lb_rounds);
  773. $num_matches = $double_elimination / pow(2, $num_lb_round);
  774. $bottom_space = ($num_lb_round - 2) * 2 + (pow(2, $num_lb_round - 2) - 1) * 4;
  775. $normal_space = (pow(2, $num_lb_round - 1) - 2) * 4;
  776. $top_space = $normal_space - $bottom_space;
  777. $top_space += 2;
  778. $normal_space +=4;
  779. $bottom_space += 2;
  780. for ($k = 0; $k < $top_space; $k++)
  781. {
  782. array_push($bracket, "CON_SPACE");
  783. }
  784. for ($k = 1; $k <= $num_matches; $k++)
  785. {
  786. array_push($bracket, "CON_SPACE");
  787. array_push($bracket, "CON_SPACE");
  788. array_push($bracket, "CON_SPACE");
  789. array_push($bracket, "CON_SPACE");
  790. if ($k != $num_matches)
  791. {
  792. for ($j = 0; $j < $normal_space; $j++){
  793. array_push($bracket, "CON_SPACE");
  794. }
  795. }
  796. }
  797. for ($k = 0; $k < $bottom_space; $k++)
  798. {
  799. array_push($bracket, "CON_SPACE");
  800. }
  801. }
  802. ################################################################################
  803. #
  804. #
  805. ################################################################################
  806. function gf_winner($i) {
  807. global $single_elimination;
  808. global $double_elimination;
  809. global $rounds;
  810. global $brackets;
  811. $bracket = & $brackets[count($brackets) - 1];
  812. $num_matches = $single_elimination / pow(2, $i) / 2;
  813. $num_spaces = (pow(2, $i) * 4 - 4) / 2;
  814. for ($j = 1; $j <= $num_matches; $j++)
  815. {
  816. for ($k = 0; $k < $num_spaces; $k++)
  817. {
  818. array_push($bracket, "SPACE");
  819. }
  820. array_push($bracket, "SPACE");
  821. array_push($bracket, "SPACE");
  822. array_push($bracket, "SPACE");
  823. for ($k = 0; $k < $num_spaces - 1; $k++)
  824. {
  825. array_push($bracket, "SPACE");
  826. }
  827. array_push($bracket, "SPACE");
  828. array_push($bracket, "WINNER");
  829. array_push($bracket, "SPACE");
  830. }
  831. $i++;
  832. $num_wb_rounds = log10($single_elimination) / log10(2);
  833. $num_lb_rounds = log10($double_elimination) / log10(2);
  834. $num_lb_round = $i - ($num_wb_rounds - $num_lb_rounds);
  835. $num_matches = $double_elimination / pow(2, $num_lb_round);
  836. $bottom_space = ($num_lb_round - 2) * 2 + (pow(2, $num_lb_round - 2) - 1) * 4;
  837. $normal_space = (pow(2, $num_lb_round - 1) - 2) * 4;
  838. $top_space = $normal_space - $bottom_space;
  839. $top_space += 2;
  840. $normal_space +=4;
  841. $bottom_space += 2;
  842. for ($k = 0; $k < $top_space - 1; $k++)
  843. {
  844. array_push($bracket, "SPACE");
  845. }
  846. for ($k = 1; $k <= $num_matches; $k++)
  847. {
  848. array_push($bracket, "SPACE");
  849. array_push($bracket, "SPACE");
  850. array_push($bracket, "SPACE");
  851. array_push($bracket, "SPACE");
  852. if ($k != $num_matches)
  853. {
  854. for ($j = 0; $j < $normal_space; $j++){
  855. array_push($bracket, "SPACE");
  856. }
  857. }
  858. }
  859. for ($k = 0; $k < $bottom_space; $k++)
  860. {
  861. array_push($bracket, "SPACE");
  862. }
  863. }
  864. ?>