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

/modules/tournament2/games.php

http://lansuite.googlecode.com/
PHP | 274 lines | 208 code | 49 blank | 17 comment | 85 complexity | c382ab7b0110cb9c9c296cbb4141c83b MD5 | raw file
Possible License(s): LGPL-3.0, AGPL-1.0, LGPL-2.1
  1. <?php
  2. $tournamentid = (int)$_GET["tournamentid"];
  3. include_once("modules/tournament2/class_tournament.php");
  4. $tfunc = new tfunc;
  5. function WriteGame() {
  6. global $spieler1, $gameid1, $score1, $spieler1_id, $i, $tournamentid, $game, $dsp, $auth, $lang;
  7. if ($spieler1 == "") {
  8. $spieler1 = $game['name'];
  9. $gameid1 = $game['gameid'];
  10. $score1 = $game['score'];
  11. $spieler1_id = $game['leaderid'];
  12. } else {
  13. $i++;
  14. $spieler2 = $game['name'];
  15. $gameid2 = $game['gameid'];
  16. $score2 = $game['score'];
  17. $spieler2_id = $game['leaderid'];
  18. // Set Colour
  19. if (($spieler1_id == 0) && ($spieler2_id != 0)) $spieler2 = "<font color=\"#006600\">$spieler2</font>";
  20. elseif (($spieler2_id == 0) && ($spieler1_id != 0)) $spieler1 = "<font color=\"#006600\">$spieler1</font>";
  21. elseif (($score1 > 0) || ($score2 > 0)) {
  22. if ($score1 > $score2) {
  23. $spieler1 = "<font color=\"#006600\">$spieler1</font>";
  24. $spieler2 = "<font color=\"#660000\">$spieler2</font>";
  25. }
  26. elseif ($score1 < $score2) {
  27. $spieler1 = "<font color=\"#660000\">$spieler1</font>";
  28. $spieler2 = "<font color=\"#006600\">$spieler2</font>";
  29. }
  30. }
  31. // Mark own team
  32. if ($spieler1_id == $auth["userid"]) $spieler1 = "<b>$spieler1</b>";
  33. if ($spieler2_id == $auth["userid"]) $spieler2 = "<b>$spieler2</b>";
  34. $score_output = "";
  35. if (($spieler1_id != 0) && ($spieler2_id != 0)) {
  36. if (($score1 == 0) && ($score2 == 0)) $score_output = "- : - ";
  37. else $score_output = "$score1 : $score2 ";
  38. $score_output .= $dsp->FetchSpanButton(t('Details'), "index.php?mod=tournament2&action=submit_result&step=1&tournamentid=$tournamentid&gameid1=$gameid1&gameid2=$gameid2");
  39. }
  40. $dsp->AddDoubleRow(t('Paarung')." $i", "$spieler1 vs $spieler2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$score_output");
  41. $spieler1 = "";
  42. }
  43. }
  44. function WriteRoundHeadline($headline, $akt_round){
  45. global $tournament, $dsp, $func, $lang, $map, $tfunc;
  46. $round_start = $func->unixstamp2date($tfunc->GetGameStart($tournament, $akt_round), "time");
  47. $round_end = $func->unixstamp2date($tfunc->GetGameEnd($tournament, $akt_round), "time");
  48. $dsp->AddSingleRow("<b>$headline ".t('Runde')." ". abs($akt_round) ."</b>"
  49. .HTML_NEWLINE. t('Zeit') .": ". $round_start ." - ". $round_end
  50. .HTML_NEWLINE. t('Map') .": ". $map[(abs(floor($akt_round)) % count($map))]
  51. );
  52. }
  53. function WritePairs ($bracket, $max_pos) {
  54. global $dsp, $db, $tournamentid, $tfunc, $akt_round, $lang, $func, $map, $tournament, $i, $game;
  55. WriteRoundHeadline("$bracket-Bracket - ", $akt_round);
  56. $spieler1 = "";
  57. $i = 0;
  58. for ($akt_pos = 0; $akt_pos <= $max_pos-1; $akt_pos++) {
  59. $game = $db->qry_first("SELECT teams.name, teams.teamid, games.leaderid, games.gameid, games.score
  60. FROM %prefix%t2_games AS games
  61. LEFT JOIN %prefix%t2_teams AS teams ON (games.tournamentid = teams.tournamentid) AND (games.leaderid = teams.leaderid)
  62. WHERE (games.tournamentid = %int%)
  63. AND (games.group_nr = 0) AND (games.round = %string%) AND (games.position = %string%)
  64. GROUP BY games.gameid
  65. ", $tournamentid, $akt_round, $akt_pos);
  66. // Set Playernames
  67. if ($game == 0) $game['name'] = "<i>".t('Noch Unbekannt')."</i>";
  68. elseif ($game['leaderid'] == 0) $game['name'] = "<i><font color=\"#000088\">".t('Freilos')."</font></i>";
  69. else $game['name'] .= $tfunc->button_team_details($game['teamid'], $tournamentid);
  70. WriteGame();
  71. }
  72. }
  73. if (!$tournamentid) $func->error(t('Du hast kein Turnier ausgewählt!'));
  74. else {
  75. switch($_GET["step"]) {
  76. case 1:
  77. include_once('modules/tournament2/search.inc.php');
  78. break;
  79. default:
  80. // Check if roundtime has exceeded and set awaiting scores randomly
  81. $tfunc->CheckTimeExceed($tournamentid);
  82. $tournament = $db->qry_first("SELECT *, UNIX_TIMESTAMP(starttime) AS starttime FROM %prefix%tournament_tournaments WHERE tournamentid = %int%", $tournamentid);
  83. // Get Maparray
  84. $map = explode("\r\n", $tournament["mapcycle"]);
  85. if ($map[0] == "") $map[0] = t('unbekannt');
  86. // Check Errors
  87. if ($tournament["mode"] == "open") {
  88. $func->error(t('Dieses Turnier wurde noch nicht generiert. Die Paarungen sind noch nicht bekannt.'), "index.php?mod=tournament2&action=games&step=1");
  89. break;
  90. }
  91. // Set Modename
  92. if ($tournament['mode'] == "single") $modus = t('Single-Elimination');
  93. if ($tournament['mode'] == "double") $modus = t('Double-Elimination');
  94. if ($tournament['mode'] == "liga") $modus = t('Liga');
  95. if ($tournament['mode'] == "groups") $modus = t('Gruppenspiele + KO');
  96. if ($tournament['mode'] == "all") $modus = t('Alle in einem');
  97. // Start Output
  98. $dsp->NewContent(t('Turnier %1 (%2) - Paarungen', $tournament['name'], $modus), t('Hier siehst du eine Liste aller Paarungen dieses Turniers'));
  99. switch ($tournament['mode']){
  100. case 'all':
  101. // Update score, if submitted
  102. if ($_GET['step'] == 10) {
  103. foreach ($_POST['team_score'] as $gameid => $team_score) if ($gameid) {
  104. if (!is_numeric($team_score)) $team_score_error[$gameid] = t('Bitte gib eine Zahl ein');
  105. else $db->qry("UPDATE %prefix%t2_games
  106. SET score = %string%
  107. WHERE gameid = %int%", $team_score, $gameid);
  108. }
  109. }
  110. // Finish tournament
  111. if ($_GET['step'] == 11) {
  112. $db->qry("UPDATE %prefix%tournament_tournaments SET status='closed' WHERE tournamentid = %int%", $tournamentid);
  113. $func->confirmation(t('Turnier wurde beendet'), '');
  114. }
  115. // Unfinish tournament
  116. if ($_GET['step'] == 12) {
  117. $db->qry("UPDATE %prefix%tournament_tournaments SET status='process' WHERE tournamentid = %int%", $tournamentid);
  118. $func->confirmation(t('Turnier wurde wiedereröffnet'), '');
  119. }
  120. // Show players and scores
  121. $games = $db->qry("SELECT teams.name, teams.teamid, games.leaderid, games.score, games.gameid
  122. FROM %prefix%t2_games AS games
  123. LEFT JOIN %prefix%t2_teams AS teams ON (games.tournamentid = teams.tournamentid) AND (games.leaderid = teams.leaderid)
  124. WHERE games.tournamentid = %int%
  125. ORDER BY games.position
  126. ", $tournamentid);
  127. $dsp->SetForm("index.php?mod=tournament2&action=games&step=10&tournamentid=$tournamentid");
  128. while ($game = $db->fetch_array($games)) {
  129. $dsp->AddTextFieldRow('team_score['. $game['gameid'] .']', $game['name'] .' '. $tfunc->button_team_details($game['teamid'], $tournamentid), $game['score'], $team_score_error[$game['gameid']]);
  130. }
  131. $db->free_result($games);
  132. $dsp->AddFormSubmitRow(t('Speichern'));
  133. if ($tournament['status'] == 'process') $dsp->AddDoubleRow('', $dsp->FetchSpanButton(t('Beenden'), "index.php?mod=tournament2&action=games&step=11&tournamentid=$tournamentid"));
  134. elseif ($tournament['status'] == 'closed') $dsp->AddDoubleRow('', $dsp->FetchSpanButton(t('Beenden rückgängig'), "index.php?mod=tournament2&action=games&step=12&tournamentid=$tournamentid"));
  135. break;
  136. case "liga":
  137. case "groups":
  138. $games = $db->qry("SELECT teams.name, teams.teamid, games.leaderid, games.gameid, games.score, games.group_nr, games.round, games.position, games.leaderid
  139. FROM %prefix%t2_games AS games
  140. LEFT JOIN %prefix%t2_teams AS teams ON (games.tournamentid = teams.tournamentid) AND (games.leaderid = teams.leaderid)
  141. WHERE (games.tournamentid = %int%) AND (games.group_nr > 0)
  142. GROUP BY games.gameid
  143. ORDER BY games.group_nr, games.round, games.position
  144. ", $tournamentid);
  145. $last_round = -1;
  146. while ($game = $db->fetch_array($games)){
  147. // Write Round Headline
  148. if ($last_round != $game['round']) {
  149. ($tournament['mode'] == "groups")? $group_out = t('Gruppe')." {$game['group_nr']},"
  150. : $group_out = '';
  151. WriteRoundHeadline($group_out, $game['round']);
  152. $spieler1 = "";
  153. $i = 0;
  154. }
  155. $last_round = $game['round'];
  156. // Set Playernames
  157. if ($game['leaderid'] == 0) $game['name'] = "<i>".t('Spielfrei')."</i>";
  158. else $game['name'] .= $tfunc->button_team_details($game['teamid'], $tournamentid);
  159. WriteGame();
  160. }
  161. $db->free_result($games);
  162. break;
  163. } // END: Switch $tournament['mode']
  164. switch ($tournament['mode']){
  165. case "single":
  166. case "double":
  167. case "groups":
  168. // Get $team_anz
  169. if ($tournament['mode'] == "groups") {
  170. $games = $db->qry("SELECT gameid
  171. FROM %prefix%t2_games
  172. WHERE (tournamentid = %int%) AND (group_nr > 0)
  173. GROUP BY group_nr
  174. ", $tournamentid);
  175. $team_anz = 2 * $db->num_rows($games);
  176. $db->free_result($games);
  177. } else {
  178. $games = $db->qry_first("SELECT COUNT(*) AS anz
  179. FROM %prefix%t2_games
  180. WHERE (tournamentid = %int%) AND (round = 0) AND (group_nr = 0)
  181. GROUP BY round
  182. ", $tournamentid);
  183. $team_anz = $games["anz"];
  184. }
  185. $akt_round = 0;
  186. WritePairs("Winner", $team_anz);
  187. $akt_round = 1;
  188. if ($tournament['mode'] == "double") $limit_round = 2;
  189. else $limit_round = 4;
  190. for ($z = $team_anz/2; $z >= $limit_round; $z/=2) {
  191. WritePairs("Winner", $z);
  192. if ($tournament['mode'] == "double") {
  193. $akt_round*=-1;
  194. $akt_round+=0.5;
  195. WritePairs("Loser", $z);
  196. $akt_round-=0.5;
  197. WritePairs("Loser", $z);
  198. $akt_round*=-1;
  199. }
  200. $akt_round++;
  201. }
  202. if ($tournament['mode'] == "single") WritePairs("Winner", 4);
  203. else WritePairs("Winner", 2);
  204. // Write Winner
  205. $akt_round++;
  206. $dsp->AddSingleRow("<b>". t('Turnier-Sieger') ."</b>");
  207. $game = $db->qry_first("SELECT teams.name, teams.teamid
  208. FROM %prefix%t2_games AS games
  209. LEFT JOIN %prefix%t2_teams AS teams ON (games.tournamentid = teams.tournamentid) AND (games.leaderid = teams.leaderid)
  210. WHERE (games.tournamentid = %int%) AND (games.round = %string%) AND (games.position = 0) AND (games.group_nr = 0)
  211. GROUP BY games.gameid
  212. ", $tournamentid, $akt_round);
  213. if ($game == 0) $game['name'] = "<i>".t('Noch Unbekannt')."</i>";
  214. else $game['name'] .= $tfunc->button_team_details($game['teamid'], $tournamentid);
  215. $dsp->AddDoubleRow(t('Sieger'), $game['name']);
  216. break;
  217. } // END: Switch $tournament['mode']
  218. // Finalize Output
  219. if ($func->internal_referer) $dsp->AddBackButton($func->internal_referer, "tournament2/games");
  220. else $dsp->AddBackButton("index.php?mod=tournament2&action=games&step=1", "tournament2/games");
  221. $dsp->AddContent();
  222. break;
  223. } // END: Switch Step
  224. }
  225. ?>