function EnterResult($tid, $round, $match, $score1, $score2) { $result1 = dbquery("SELECT * FROM " . DB_T_MATCHES . " WHERE match_round='" . $round . "' AND match_match='" . $match . "' AND match_tour='" . $tid . "'"); $data1 = dbarray($result1); if ($score1 > $score2) { $winner = $data1['match_pl1']; $looser = $data1['match_pl2']; } else { $winner = $data1['match_pl2']; $looser = $data1['match_pl1']; } $result = dbquery("UPDATE " . DB_T_MATCHES . " SET match_score1='" . $score1 . "', match_score2='" . $score2 . "', match_winner='" . $winner . "', match_played='1' WHERE match_round='" . $round . "' AND match_match='" . $match . "' AND match_tour='" . $tid . "'"); $pl = dbcount("(player_id)", DB_T_PLAYERS, "player_tour='" . $tid . "' AND player_checkin='1'"); $max = getMaxPl($pl); $rounds = log($max) / log(2); if ($round == $rounds) { //fin12 $set_w1 = dbquery("UPDATE " . DB_T_TOURS . " SET tour_w1='" . $winner . "', tour_w2='" . $looser . "' WHERE tour_id='" . $tid . "'"); $check_f = dbarray(dbquery("SELECT tour_w3, tour_w4 FROM " . DB_T_TOURS . " WHERE tour_id='" . $tid . "'")); if ($check_f['tour_w3'] != "0" && $check_f['tour_w4'] != "0") { $fin = dbquery("UPDATE " . DB_T_TOURS . " SET tour_finished='1' WHERE tour_id='" . $tid . "'"); } } elseif ($round == $rounds + 1) { //fin34 $set_w3 = dbquery("UPDATE " . DB_T_TOURS . " SET tour_w3='" . $winner . "', tour_w4='" . $looser . "' WHERE tour_id='" . $tid . "'"); $check_f = dbarray(dbquery("SELECT tour_w1, tour_w2 FROM " . DB_T_TOURS . " WHERE tour_id='" . $tid . "'")); if ($check_f['tour_w1'] != "0" && $check_f['tour_w2'] != "0") { $fin = dbquery("UPDATE " . DB_T_TOURS . " SET tour_finished='1' WHERE tour_id='" . $tid . "'"); } } else { //just enter if ($match % 2 == 1) { $nextround = $round + 1; $nextmatch = ($match + 1) / 2; $result2 = dbquery("UPDATE " . DB_T_MATCHES . " SET match_pl1='" . $winner . "' WHERE match_round='" . $nextround . "' AND match_match='" . $nextmatch . "' AND match_tour='" . $tid . "'"); if ($round == $rounds - 1) { //looser to fin34 $x = $rounds + 1; $result3 = dbquery("UPDATE " . DB_T_MATCHES . " SET match_pl1='" . $looser . "' WHERE match_round='" . $x . "' AND match_match='1' AND match_tour='" . $tid . "'"); } } if ($match % 2 == 0) { $nextround = $round + 1; $nextmatch = $match / 2; $result2 = dbquery("UPDATE " . DB_T_MATCHES . " SET match_pl2='" . $winner . "' WHERE match_round='" . $nextround . "' AND match_match='" . $nextmatch . "' AND match_tour='" . $tid . "'"); if ($round == $rounds - 1) { //looser to fin34 $x = $rounds + 1; $result2 = dbquery("UPDATE " . DB_T_MATCHES . " SET match_pl2='" . $looser . "' WHERE match_round='" . $x . "' AND match_match='1' AND match_tour='" . $tid . "'"); } } } }
$mres = "Your next match: \n" . $opp_link . " - <a href='" . BASEDIR . "tourney.php?p=result&id=" . $nm['match_id'] . "'>go to match</a>"; } else { $mres = "No more matches to play for you."; } } else { $mres = "You don't take part in this tourney."; } } opentable("Tourney info"); echo "<table width='100%'><tr><td class='tbl2' width='50%'><strong>" . $tour['tour_name'] . "</strong> - <a href='" . BASEDIR . "tourney.php?p=viewtour&id=" . $tour['tour_id'] . "'>view more</a></td><td class='tbl2'>" . $mres . "</td></tr></table>"; closetable(); opentable("Brackets"); //mini info $bye = bye(); $pl = dbcount("(player_id)", DB_T_PLAYERS, "player_tour='" . $tid . "' AND player_checkin='1'"); $max = getMaxPl($pl); $rounds = log($max) / log(2); $f_heigth = array(1 => 0, 33, 98, 227, 482); $m_heigth = array(1 => 30, 94, 222, 478, 990); $wi = 100 / ($rounds + 1); $ro = $max; echo "<table width='100%'><tr>"; for ($x = 1; $x <= $rounds; $x++) { echo "<td class='tbl2' align='center' width='" . $wi . "%'><strong>1/" . $ro . "</strong></td>"; $ro = $ro / 2; } echo "<td class='tbl2' align='center' width='" . $wi . "'><strong>winner</strong></td>"; echo "</tr></table>"; echo "<table><tr valign='top'>"; for ($i = 1; $i <= $rounds; $i++) { echo "<td><table width='170'><tr><td height='" . $f_heigth[$i] . "'></td></tr>";
$byete = dbquery("INSERT INTO " . DB_T_PLAYERS . " (player_user, player_tour, player_checkin) VALUES ('" . bye() . "', '" . $tid . "', '1')"); $pl2 = bye(); } $ins_pl = dbquery("UPDATE " . DB_T_MATCHES . " SET match_pl1='" . $pl1 . "', match_pl2='" . $pl2 . "' WHERE match_tour='" . $tid . "' AND match_round='1' AND match_match='" . $i . "'"); } $upd_t = dbquery("UPDATE " . DB_T_TOURS . " SET tour_grid='1' WHERE tour_id='" . $tid . "'"); clearByes($tid); } $result = dbquery("SELECT * FROM " . DB_T_TOURS . " WHERE tour_id='" . $_GET['id'] . "'"); if (dbrows($result)) { $tour = dbarray($result); $now = time() + ($settings['timeoffset'] + $settings['serveroffset']) * 3600; if ($tour['tour_date'] < $now) { $pl = dbcount("(player_id)", DB_T_PLAYERS, "player_tour='" . $_GET['id'] . "' AND player_checkin='1'"); if ($pl > 0) { $max = getMaxPl($pl, $tour['tour_maxpl']); $free = $max - $pl; opentable("Create brackets"); echo "You have " . $pl . " registered, and you need for " . $free . " freeslots."; $pl_options = "<option value='0'>freeslot</option>"; $players = dbquery("SELECT tpl.*, tu.user_name FROM " . DB_T_PLAYERS . " tpl LEFT JOIN " . DB_USERS . " tu ON tu.user_id=tpl.player_user WHERE player_tour='" . $_GET['id'] . "' AND player_checkin='1'"); while ($player = dbarray($players)) { $pl_options .= "<option value='" . $player['player_user'] . "'>" . $player['user_name'] . "</option>"; } echo "<form name='ghcfdg' method='post'><table width='100%'>"; for ($i = 1; $i <= $max; $i++) { echo "<tr><td class='tbl2'>Player " . $i . " <select name='pl" . $i . "'>" . $pl_options . "</select></td></tr>"; } echo "<tr><td class='tbl2'><input type='hidden' name='tid' value='" . $_GET['id'] . "' /><input type='hidden' name='pl' value='" . $pl . "' /><input type='hidden' name='max' value='" . $max . "' /><input type='hidden' name='free' value='" . $free . "' /><input type='submit' class='button' name='cr_bracket' value='create' /></td></tr>"; echo "</table></form>"; closetable();