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

/modules/tournament2/submit_result.php

http://lansuite.googlecode.com/
PHP | 239 lines | 161 code | 43 blank | 35 comment | 65 complexity | 11181bc8b49d209ab431fafe8b1b7591 MD5 | raw file
Possible License(s): LGPL-3.0, AGPL-1.0, LGPL-2.1
  1. <?php
  2. include_once("inc/classes/class_gd.php");
  3. $gd = new gd;
  4. include_once("modules/tournament2/class_tournament.php");
  5. $tfunc = new tfunc;
  6. $qacc = $_GET["qacc"];
  7. $tournamentid = $_GET["tournamentid"];
  8. $gameid1 = $_GET["gameid1"];
  9. $gameid2 = $_GET["gameid2"];
  10. $score_team1 = $_POST["score_team1"];
  11. $score_team2 = $_POST["score_team2"];
  12. $score_comment = $_POST["score_comment"];
  13. ## Ueberschreibungsabfrage
  14. if($_GET["qacc"] == 1)
  15. {
  16. $score_team1 = $_GET["score_team1"];
  17. $score_team2 = $_GET["score_team2"];
  18. $score_comment = $_GET["score_comment"];
  19. }
  20. ########## Infos holen
  21. $tournament = $db->qry_first("SELECT name, teamplayer, over18, status, mode, mapcycle, UNIX_TIMESTAMP(starttime) AS starttime, max_games, game_duration, break_duration, tournamentid FROM %prefix%tournament_tournaments WHERE tournamentid = %int%", $tournamentid);
  22. $map = explode("\n", $tournament["mapcycle"]);
  23. if ($map[0] == "") $map[0] = t('unbekannt');
  24. $games = $db->qry_first("SELECT COUNT(*) AS anz FROM %prefix%t2_games WHERE (tournamentid = %int%) AND (round=0) GROUP BY round", $tournamentid);
  25. $team_anz = $games["anz"];
  26. $team1 = $db->qry_first("SELECT games.group_nr, games.round, games.position, games.score, games.comment, games.server_id, teams.name, teams.teamid, teams.disqualified, user.userid, user.username
  27. FROM %prefix%t2_games AS games
  28. LEFT JOIN %prefix%t2_teams AS teams ON games.leaderid = teams.leaderid
  29. LEFT JOIN %prefix%user AS user ON user.userid = teams.leaderid
  30. WHERE (teams.tournamentid = %int%) AND (games.gameid = %int%)
  31. ", $tournamentid, $gameid1);
  32. $team2 = $db->qry_first("SELECT games.round, games.position, games.score, games.comment, games.server_id, teams.name, teams.teamid, teams.disqualified, user.userid, user.username
  33. FROM %prefix%t2_games AS games
  34. LEFT JOIN %prefix%t2_teams AS teams ON games.leaderid = teams.leaderid
  35. LEFT JOIN %prefix%user AS user ON user.userid = teams.leaderid
  36. WHERE (teams.tournamentid = %int%) AND (games.gameid = %int%)
  37. ", $tournamentid, $gameid2);
  38. ########## Einschränkungen prüfen
  39. if ($tournament["name"] == "") {
  40. $func->error(t('Du musst zuerst ein Turnier auswählen!'), "index.php?mod=tournament2&action=details&tournamentid=$tournamentid");
  41. } elseif (abs($team1['position'] - $team2['position']) != 1) {
  42. $func->error(t('Diese Spielkonstellation existiert nicht!'. $team1['position']. $team2['position']));
  43. ########## Keine Einschränkungen gefunden
  44. } else {
  45. switch ($_GET["step"]) {
  46. default:
  47. include_once("modules/seating/class_seat.php");
  48. $seat2 = new seat2();
  49. unset($_SESSION['tournament_submit_result_blocker']);
  50. if ($func->isModActive('server')) {
  51. //Server auslesen
  52. $selections = array();
  53. $selections['0'] = t('Kein Server zugewiesen');
  54. $res = $db->qry("SELECT * FROM %prefix%server WHERE party_id = %int%", $party->party_id);
  55. while ($row = $db->fetch_array($res)) $selections[$row['serverid']] = $row['caption'];
  56. $db->free_result($res);
  57. }
  58. $dsp->NewContent(t('Details der Partie %1 vs %2', $team1['name'], $team2['name']), t('Hier siehst du Details zu dieser Partie und kannst das Ergebnis eintragen.'));
  59. // Write Start and Enddate for each round
  60. $round_start = $tfunc->GetGameStart($tournament, $team1['round'],$team1['group_nr']);
  61. $round_end = $tfunc->GetGameEnd($tournament, $team1['round'],$team1['group_nr']);
  62. $dsp->AddDoubleRow(t('Spielzeit'), $func->unixstamp2date($round_start, "datetime") ." - ". $func->unixstamp2date($round_end, "datetime"));
  63. $dsp->AddDoubleRow(t('Map'), $map[(abs(floor($team1['round'])) % count($map))]);
  64. if ($func->isModActive('server')) $dsp->AddDoubleRow(t('Server'), '<a href="index.php?mod=server&action=show_details&serverid='.$team1['server_id'].'">'.$selections[$team1['server_id']].'</a>');
  65. if($func->isModActive('server') and $auth['type'] >= 2) {
  66. include_once('inc/classes/class_masterform.php');
  67. $mf = new masterform();
  68. $mf->AddField(t('Server Zuweisen'), 'server_id', IS_SELECTION, $selections, FIELD_OPTIONAL);
  69. if ($mf->SendForm("index.php?mod=tournament2&action=submit_result&step=1&tournamentid=".$tournamentid."&gameid1=".$gameid1."&gameid2=".$gameid2, 't2_games', 'gameid', $gameid1)) {
  70. $db->qry("UPDATE %prefix%t2_games SET server_id = %int% WHERE gameid = %int%", $_POST['server_id'], $gameid2);
  71. }
  72. }
  73. $dsp->AddHRuleRow();
  74. $dsp->AddSingleRow("<b>".t('Ergebnis melden')."</b>");
  75. $dsp->SetForm("index.php?mod=tournament2&action=submit_result&step=2&tournamentid=$tournamentid&gameid1=$gameid1&gameid2=$gameid2", '', '', 'multipart/form-data');
  76. // Write Team 1
  77. $disqualify_link = "";
  78. /* // Disquallifiy droped, due to errors
  79. if ($auth["type"] > 1 and $tournament['status'] == "process") {
  80. if ($team1['disqualified']) $disqualify_link = "<font color=\"#ff0000\">".t('Disqualifiziert')."</font> ". $dsp->FetchSpanButton(t('Disqualifizieren rückgängig'), "index.php?mod=tournament2&action=disqualify&teamid={$team1['teamid']}&step=10");
  81. else $disqualify_link = $dsp->FetchSpanButton(t('Disqualifizieren'), "index.php?mod=tournament2&action=disqualify&teamid={$team1['teamid']}");
  82. }
  83. */
  84. $dsp->AddFieldSetStart(t('Team'). ' 1'. $tfunc->button_team_details($team1['teamid'], $tournamentid) . " ". $disqualify_link);
  85. $dsp->AddDoubleRow(t('Teamleiter'), $dsp->FetchUserIcon($team1['userid'], $team1['username']) . " (".t('Platz').": ". $seat2->SeatNameLink($team1['userid'], '', '') .")");
  86. $dsp->AddTextFieldRow("score_team1", t('Punktzahl'), (int) $team1["score"], "");
  87. $dsp->AddFieldSetEnd();
  88. // Write Team 2
  89. $disqualify_link = "";
  90. /* // Disquallifiy droped, due to errors
  91. if ($auth["type"] > 1 and $tournament['status'] == "process") {
  92. if ($team2['disqualified']) $disqualify_link = "<font color=\"#ff0000\">".t('Disqualifiziert')."</font> ". $dsp->FetchSpanButton(t('Disqualifizieren rückgängig'), "index.php?mod=tournament2&action=disqualify&teamid={$team2['teamid']}&step=10");
  93. else $disqualify_link = $dsp->FetchSpanButton(t('Disqualifizieren'), "index.php?mod=tournament2&action=disqualify&teamid={$team2['teamid']}");
  94. }
  95. */
  96. $dsp->AddFieldSetStart(t('Team'). ' 2'. $tfunc->button_team_details($team2['teamid'], $tournamentid) . " ". $disqualify_link);
  97. $dsp->AddDoubleRow(t('Teamleiter'), $dsp->FetchUserIcon($team2['userid'], $team2['username']) . " (".t('Platz').": ". $seat2->SeatNameLink($team2['userid'], '', '') .")");
  98. $dsp->AddTextFieldRow("score_team2", t('Punktzahl'), (int) $team2["score"], "");
  99. $dsp->AddFieldSetEnd();
  100. // Write Comment
  101. $dsp->AddFieldSetStart(t('Anmerkungen'));
  102. $dsp->AddFileSelectRow('screenshot', t('Screenshot anhängen'), '', '', '', 1);
  103. if (file_exists('ext_inc/tournament_screenshots/'. $_GET['gameid1'] .'.png'))
  104. $dsp->AddDoubleRow(t('Aktuelles Bild'), '<img src="ext_inc/tournament_screenshots/'. $_GET['gameid1'] .'.png" />');
  105. if ($team1['comment'] != "") $score_comment = $team1['comment'];
  106. $dsp->AddTextAreaPlusRow("score_comment", t('Bemerkung'), $score_comment, "", "", "", 1);
  107. $dsp->AddFieldSetEnd();
  108. $dsp->AddFormSubmitRow(t('Ergebnis'));
  109. $dsp->AddFieldsetStart('Log');
  110. include_once('modules/mastersearch2/class_mastersearch2.php');
  111. $ms2 = new mastersearch2('t2_games');
  112. $ms2->query['from'] = "%prefix%log AS l LEFT JOIN %prefix%user AS u ON l.userid = u.userid";
  113. $ms2->query['where'] = "(sort_tag = 'Turnier Ergebnise' AND target_id = ". (int)$_GET['gameid1'] .')';
  114. $ms2->AddResultField('', 'l.description');
  115. $ms2->AddSelect('u.userid');
  116. $ms2->AddResultField('', 'u.username', 'UserNameAndIcon');
  117. $ms2->AddResultField('', 'UNIX_TIMESTAMP(l.date) AS date', 'MS2GetDate');
  118. $ms2->PrintSearch('index.php?mod=tournament2&action=submit_result&step=1&tournamentid='. $_GET['tournamentid'] .'&gameid1='. $_GET['gameid1'] .'&gameid2='. $_GET['gameid2'], 'logid');
  119. $dsp->AddFieldsetEnd();
  120. $buttons = "";
  121. $buttons .= $dsp->FetchSpanButton(t('Paarungen'), "index.php?mod=tournament2&action=games&step=2&tournamentid=$tournamentid");
  122. $buttons .= " ". $dsp->FetchSpanButton(t('Spielbaum'), "index.php?mod=tournament2&action=tree&step=2&tournamentid=$tournamentid");
  123. $dsp->AddDoubleRow("", $buttons);
  124. break;
  125. // Formular in Datenbank eintragen
  126. case 2:
  127. ## Berechtigungsprüfung
  128. $berechtigt = 0;
  129. if ($auth["type"] > 1) $berechtigt = 1; // Admin always
  130. if ($cfg["t_only_loser_submit"]) {
  131. // Check only Looser
  132. if (($team1['userid'] == $auth["userid"]) && ($score_team1 < $score_team2)) $berechtigt = 1;
  133. if (($team2['userid'] == $auth["userid"]) && ($score_team1 > $score_team2)) $berechtigt = 1;
  134. } else {
  135. // Only Playing Team
  136. if ($team1['userid'] == $auth["userid"]) $berechtigt = 1;
  137. if ($team2['userid'] == $auth["userid"]) $berechtigt = 1;
  138. }
  139. ## Wurde Ergebnis schon eingetragen?
  140. $not_new = 0;
  141. if (($tournament["mode"] == "single") || ($tournament["mode"] == "double")) {
  142. $score = $db->qry_first("SELECT score FROM %prefix%t2_games WHERE (gameid = %int% OR gameid = %int%) AND score != 0", $gameid1, $gameid2);
  143. if ($score['score']) $not_new = 1;
  144. }
  145. if ($_SESSION['tournament_submit_result_blocker']) {
  146. $func->error("NO_REFRESH", "index.php?mod=tournament2&action=submit_result&step=1&tournamentid=$tournamentid&gameid1=$gameid1&gameid2=$gameid2");
  147. } elseif ($tournament["status"] != "process") {
  148. $func->information(t('Dieses Turnier ist bereits beendet, oder noch nicht gestartet!'), "index.php?mod=tournament2&action=submit_result&step=1&tournamentid=$tournamentid&gameid1=$gameid1&gameid2=$gameid2");
  149. } elseif (($score_team1 == "") && ($score_team2 == "")) {
  150. $func->information(t('Bitte gib ein Ergebnis ein'), "index.php?mod=tournament2&action=submit_result&step=1&tournamentid=$tournamentid&gameid1=$gameid1&gameid2=$gameid2");
  151. } elseif (($score_team1 < 0) || ($score_team2 < 0)) {
  152. $func->information(t('Das Ergebnis muss eine possitive Zahl sein'), "index.php?mod=tournament2&action=submit_result&step=1&tournamentid=$tournamentid&gameid1=$gameid1&gameid2=$gameid2");
  153. } elseif (($score_team1 == $score_team2) && (
  154. ($tournament["mode"] == "single") || ($tournament["mode"] == "double")
  155. || (($tournament["mode"] == "groups") && ($team1["group_nr"] == 0))
  156. )) {
  157. $func->information(t('Ein Spiel darf nicht unentschieden enden! Es muss ein Sieger ausgemacht werden.'), "index.php?mod=tournament2&action=submit_result&step=1&tournamentid=$tournamentid&gameid1=$gameid1&gameid2=$gameid2");
  158. } elseif (($score_team1 == $score_team2) && ($tournament["mode"] == "liga") && ($score_team1 == 0)){
  159. $func->information(t('Ein Spiel darf nicht 0:0 enden! Das würde bedeuten, es wäre nicht gespielt worden. Für Unentschieden bitte mindestens 1:1 eintragen.'), "index.php?mod=tournament2&action=submit_result&step=1&tournamentid=$tournamentid&gameid1=$gameid1&gameid2=$gameid2");
  160. } elseif (!$berechtigt) {
  161. if ($cfg["t_only_loser_submit"]) {
  162. $func->information(t('Nur der Teamleiter des Verliererteams und Turnieradmins dürfen ein Ergebnis eintragen'), "index.php?mod=tournament2&action=submit_result&step=1&tournamentid=$tournamentid&gameid1=$gameid1&gameid2=$gameid2");
  163. } else {
  164. $func->information(t('Nur Teilnehmer des Aktuellen Spiels und Turnieradmins dürfen ein Ergebnis eintragen'), "index.php?mod=tournament2&action=submit_result&step=1&tournamentid=$tournamentid&gameid1=$gameid1&gameid2=$gameid2");
  165. }
  166. } elseif (($not_new) && ($auth["type"] <= 1)) {
  167. $func->information(t('Es wurde bereits ein Ergebnis für diese Partie eingetragen. Das Ergebnis kann nur noch von Turnieradmins editiert werden. Melden dich daher für Änderungen bei diesen.'), "index.php?mod=tournament2&action=submit_result&step=1&tournamentid=$tournamentid&gameid1=$gameid1&gameid2=$gameid2");
  168. } else {
  169. // Upload Screenshot
  170. $old_file = $func->FileUpload('screenshot', 'ext_inc/tournament_screenshots/');
  171. if ($old_file) {
  172. unlink('ext_inc/tournament_screenshots/'. $_GET['gameid1'] .'.png');
  173. $gd->CreateThumb($old_file, 'ext_inc/tournament_screenshots/'. $_GET['gameid1'] .'.png', 800, 600);
  174. }
  175. if (($not_new) && ($qacc != 1)){
  176. $func->question(t('ACHTUNG: Zu diesem Turnier wurde bereits ein Ergebnis eingetragen. Wurde noch keine der Folgepartien dieses Spieles gespielt, so kann ohne Probleme fortgefahren werden. Wurden diese hingegen bereits gespielt, so solltest du dir im Klaren darüber sein, dass die beiden Folgepartien dadurch teilweise überschrieben werden und das Ergebnis dort auf 0 (noch nicht gespielt) gesetzt wird, sodass du alle aus dieser Partie resultierenden Partien erneut eintragen musst!'), "index.php?mod=tournament2&action=submit_result&step=2&gameid1=$gameid1&gameid2=$gameid2&tournamentid=$tournamentid&qacc=1&score_team1=$score_team1&score_team2=$score_team2&score_comment=$score_comment", "index.php?mod=tournament2&action=submit_result&step=1&gameid1=$gameid1&gameid2=$gameid2&tournamentid=$tournamentid");
  177. } else {
  178. $_SESSION["tournament_submit_result_blocker"] = TRUE;
  179. $tfunc->SubmitResult($tournamentid, $gameid1, $gameid2, $score_team1, $score_team2, $score_comment);
  180. $func->confirmation(t('Danke! Das Ergebnis wurde erfolgreich gemeldet.'), "index.php?mod=tournament2&action=submit_result&step=1&tournamentid=$tournamentid&gameid1=$gameid1&gameid2=$gameid2");
  181. /*
  182. $cronjob->load_job("cron_tmod");
  183. if($tournament['mode'] == "groups"){
  184. $cronjob->loaded_class->add_job($_GET["tournamentid"],$team1["group_nr"]);
  185. }else{
  186. $cronjob->loaded_class->add_job($_GET["tournamentid"],"");
  187. }
  188. */
  189. }
  190. }
  191. break;
  192. case 3:
  193. break;
  194. } // Switch
  195. }
  196. ?>