示例#1
0
function findRow($round, $matchup, $match, $style = 'elimination')
{
    switch ($style) {
        case 'elimination':
            if ($round == 1) {
                $row = $matchup * 4 - 3 + 2 * $match;
            } else {
                if ($match == 0) {
                    $rowTop = findRow($round - 1, 2 * $matchup - 1, 0, $style);
                    $rowBottom = findRow($round - 1, 2 * $matchup - 1, 1, $style);
                } else {
                    $rowTop = findRow($round - 1, 2 * $matchup, 0, $style);
                    $rowBottom = findRow($round - 1, 2 * $matchup, 1, $style);
                }
                $row = ($rowBottom - $rowTop) / 2 + $rowTop;
            }
            break;
        case 'round-robin':
            $row = $matchup * 4 - 3 + 2 * $match;
            break;
        default:
            $row = 0;
    }
    return $row;
}
示例#2
0
    function brackets($scheduleNextMatches = false, $delete_match_id = 0, $style = '')
    {
        global $sql;
        global $time;
        global $pref;
        global $tp;
        global $gold_obj;
        $this->updateFields();
        $type = $this->fields['Type'];
        $competition_type = $this->getCompetitionType();
        $format = $this->fields['Format'];
        $event_id = $this->fields['EventID'];
        $teams = $this->getTeams();
        //var_dump($teams);
        $results = unserialize($this->getFieldHTML('Results'));
        $update_results = false;
        // TODO: check for error (return false)
        $rounds = unserialize($this->getFieldHTML('Rounds'));
        $matchups = $this->getMatchups();
        $nbrRounds = count($matchups);
        $nbrRows = 4 * count($matchups[1]);
        /* */
        $brackets = array();
        $content = array();
        // Initialize grid
        for ($row = 1; $row <= $nbrRows; $row++) {
            for ($column = 1; $column <= $nbrRounds; $column++) {
                $brackets[$row][2 * $column - 1] = '<td class="grid empty"></td>';
                $brackets[$row][2 * $column] = '<td class="grid border-none"></td>';
            }
        }
        $rowspan = 1;
        for ($round = 1; $round <= $nbrRounds; $round++) {
            $nbrMatchups = count($matchups[$round]);
            $rounds[$round]['nbrMatchups'] = 0;
            if ($round < $nbrRounds) {
                for ($matchup = 1; $matchup <= $nbrMatchups; $matchup++) {
                    if (!isset($results[$round][$matchup]['matchs'])) {
                        $results[$round][$matchup]['winner'] = 'not played';
                        $results[$round][$matchup]['bye'] = false;
                    }
                    if (!isset($results[$round][$matchup]['winner'])) {
                        $results[$round][$matchup]['winner'] = 'not played';
                    }
                    if (!isset($results[$round][$matchup]['bye'])) {
                        $results[$round][$matchup]['bye'] = false;
                    }
                    if (!isset($matchups[$round][$matchup]['deleted'])) {
                        $matchups[$round][$matchup]['deleted'] = false;
                    }
                    /* Nbr of matches in the matchup */
                    $nbr_matchs = count($results[$round][$matchup]['matchs']);
                    $matchup_deleted = false;
                    for ($match = 0; $match < 2; $match++) {
                        $matchupString = $matchups[$round][$matchup][$match];
                        $content[$round][$matchup][$match] = $matchupString == '' ? 'E' : $matchupString;
                        if ($matchupString == '') {
                            $row = findRow($round, $matchup, $match, $style);
                            $matchupsRows[$round][$matchup][$match] = $row;
                        } else {
                            if ($matchupString[0] == 'T') {
                                $row = findRow($round, $matchup, $match, $style);
                                $matchupsRows[$round][$matchup][$match] = $row;
                                $team = substr($matchupString, 1);
                                if (empty($teams[$team - 1])) {
                                    $content[$round][$matchup][$match] = 'E';
                                }
                            }
                            if ($matchupString[0] == 'W') {
                                $matchupArray = explode(',', substr($matchupString, 1));
                                $matchupRound = $matchupArray[0];
                                $matchupMatchup = $matchupArray[1];
                                // Get result of matchup
                                $winner = $results[$matchupRound][$matchupMatchup]['winner'];
                                $bye = $results[$matchupRound][$matchupMatchup]['bye'];
                                $deleted = $matchups[$matchupRound][$matchupMatchup]['deleted'];
                                $rowTop = $matchupsRows[$matchupRound][$matchupMatchup][0];
                                $rowBottom = $matchupsRows[$matchupRound][$matchupMatchup][1];
                                $row = ($rowBottom - $rowTop) / 2 + $rowTop;
                                // If result is not a bye, we draw the grid
                                if ($bye != true) {
                                    $brackets[$rowTop][2 * $round - 2] = '<td class="grid border-top"></td>';
                                    $brackets[$rowBottom][2 * $round - 2] = '<td class="grid border-bottom"></td>';
                                    for ($i = $rowTop + 1; $i < $rowBottom; $i++) {
                                        $brackets[$i][2 * $round - 2] = '<td class="grid border-vertical"></td>';
                                    }
                                    for ($i = $rowTop + 2; $i < $rowBottom; $i++) {
                                        $brackets[$i][2 * $round - 3] = '';
                                    }
                                    $brackets[$row][2 * $round - 2] = '<td class="grid border-middle"></td>';
                                }
                                $matchupsRows[$round][$matchup][$match] = $row;
                                if ($winner == 'top') {
                                    $content[$round][$matchup][$match] = $content[$matchupRound][$matchupMatchup][0];
                                } else {
                                    if ($winner == 'bottom') {
                                        $content[$round][$matchup][$match] = $content[$matchupRound][$matchupMatchup][1];
                                    } else {
                                        // Not played
                                        // Detect if match has been previously scheduled and needs to be deleted
                                        if ($nbr_matchs > 0) {
                                            $deleted = true;
                                        }
                                    }
                                }
                                if ($deleted == true) {
                                    $matchup_deleted = true;
                                }
                            }
                            if ($matchupString[0] == 'L' || $matchupString[0] == 'P') {
                                $matchupArray = explode(',', substr($matchupString, 1));
                                $matchupRound = $matchupArray[0];
                                $matchupMatchup = $matchupArray[1];
                                // Get result of matchup
                                $winner = $results[$matchupRound][$matchupMatchup]['winner'];
                                $bye = $results[$matchupRound][$matchupMatchup]['bye'];
                                $deleted = $matchups[$matchupRound][$matchupMatchup]['deleted'];
                                $row = findRow($round, $matchup, $match, $style);
                                $matchupsRows[$round][$matchup][$match] = $row;
                                if ($winner == 'top') {
                                    $loser = $content[$matchupRound][$matchupMatchup][1];
                                    if ($loser[0] == 'T') {
                                        $team = substr($loser, 1);
                                        //echo "M$round,$matchup: L2: $team,".$teams[$team-1]['loss'].'<br>';
                                        if ($teams[$team - 1]['loss'] > 1) {
                                            $content[$round][$matchup][$match] = 'N';
                                        } else {
                                            $content[$round][$matchup][$match] = $loser;
                                        }
                                    } else {
                                        $content[$round][$matchup][$match] = 'E';
                                    }
                                } else {
                                    if ($winner == 'bottom') {
                                        $loser = $content[$matchupRound][$matchupMatchup][0];
                                        if ($loser[0] == 'T') {
                                            $team = substr($loser, 1);
                                            //echo "M$round,$matchup: L2: $team,".$teams[$team-1]['loss'].'<br>';
                                            if ($teams[$team - 1]['loss'] > 1) {
                                                $content[$round][$matchup][$match] = 'N';
                                            } else {
                                                $content[$round][$matchup][$match] = $loser;
                                            }
                                        } else {
                                            $content[$round][$matchup][$match] = 'E';
                                        }
                                    } else {
                                        // Not played
                                        // Detect if match has been previously scheduled and needs to be deleted
                                        if ($nbr_matchs > 0) {
                                            $deleted = true;
                                        }
                                    }
                                }
                                if ($deleted == true) {
                                    $matchup_deleted = true;
                                }
                            }
                        }
                        switch ($content[$round][$matchup][$match]) {
                            case 'E':
                                $results[$round][$matchup]['winner'] = $match == 0 ? 'bottom' : 'top';
                                $results[$round][$matchup]['bye'] = true;
                                break;
                            case 'N':
                                $results[$round][$matchup]['winner'] = $match == 0 ? 'bottom' : 'top';
                                break;
                            case 'F':
                                $results[$round][$matchup]['winner'] = $match == 0 ? 'bottom' : 'top';
                                break;
                        }
                    }
                    // for(match)
                    /* Match deletion*/
                    if ($nbr_matchs > 0) {
                        $match_deleted = false;
                        for ($match = 0; $match < $nbr_matchs; $match++) {
                            if ($results[$round][$matchup]['matchs'][$match]['match_id'] == $delete_match_id || $match_deleted == true || $matchup_deleted == true) {
                                /*
                                var_dump($results[$round][$matchup]);
                                var_dump($delete_match_id);
                                var_dump($match_deleted);
                                var_dump($matchup_deleted);
                                */
                                $update_results = true;
                                $current_match_id = $results[$round][$matchup]['matchs'][$match]['match_id'];
                                echo "match " . $current_match_id . " deleted (M{$round},{$matchup},{$match})<br>";
                                $current_match = new Match($current_match_id);
                                $current_match->deleteMatchScores();
                                $results[$round][$matchup]['winner'] = 'not played';
                                $results[$round][$matchup]['topWins'] = 0;
                                $results[$round][$matchup]['bottomWins'] = 0;
                                $results[$round][$matchup]['winner'] = 'not played';
                                unset($results[$round][$matchup]['matchs'][$match]);
                                $match_deleted = true;
                                if ($this->getField('Status') == 'finished' && $competition_type == 'Tournament') {
                                    // if tournament was finished, we need to remove awards
                                    $this->setFieldDB('Status', 'active');
                                    // Find who got the award for winning the tournament
                                    switch ($type) {
                                        case "One Player Tournament":
                                            $q = "SELECT " . TBL_PLAYERS . ".*, " . TBL_GAMERS . ".*, " . TBL_EVENTS . ".*, " . TBL_AWARDS . ".*" . " FROM " . TBL_PLAYERS . ", " . TBL_GAMERS . ", " . TBL_EVENTS . ", " . TBL_AWARDS . " WHERE (" . TBL_PLAYERS . ".PlayerID = " . TBL_AWARDS . ".Player)" . "   AND (" . TBL_PLAYERS . ".Gamer = " . TBL_GAMERS . ".GamerID)" . "   AND (" . TBL_PLAYERS . ".Event = '{$event_id}')" . "   AND (" . TBL_AWARDS . ".Type = 'PlayerWonTournament')";
                                            $result = $sql->db_Query($q);
                                            $pid = mysql_result($result, 0, TBL_PLAYERS . ".PlayerID");
                                            $uid = mysql_result($result, 0, TBL_GAMERS . ".User");
                                            $aid = mysql_result($result, 0, TBL_AWARDS . ".AwardID");
                                            $q = "DELETE FROM " . TBL_AWARDS . " WHERE (" . TBL_AWARDS . ".AwardID = '{$aid}')";
                                            $result = $sql->db_Query($q);
                                            // gold
                                            if (is_gold_system_active() && $this->getField('GoldWinningEvent') > 0) {
                                                $gold_param['gold_user_id'] = $uid;
                                                $gold_param['gold_who_id'] = 0;
                                                $gold_param['gold_amount'] = $this->getField('GoldWinningEvent');
                                                $gold_param['gold_type'] = EB_L1;
                                                $gold_param['gold_action'] = "debit";
                                                $gold_param['gold_plugin'] = "ebattles";
                                                $gold_param['gold_log'] = EB_GOLD_L8 . ": event=" . $event_id . ", user="******"Clan Tournament":
                                            $q = "SELECT " . TBL_TEAMS . ".*, " . TBL_DIVISIONS . ".*, " . TBL_EVENTS . ".*, " . TBL_AWARDS . ".*" . " FROM " . TBL_TEAMS . ", " . TBL_DIVISIONS . ", " . TBL_EVENTS . ", " . TBL_AWARDS . " WHERE (" . TBL_TEAMS . ".TeamID = " . TBL_AWARDS . ".Team)" . "   AND (" . TBL_TEAMS . ".Division = " . TBL_DIVISIONS . ".DivisionID)" . "   AND (" . TBL_TEAMS . ".Event = '{$event_id}')" . "   AND (" . TBL_AWARDS . ".Type = 'TeamWonTournament')";
                                            $result = $sql->db_Query($q);
                                            $pid = mysql_result($result, 0, TBL_TEAMS . ".TeamID");
                                            $uid = mysql_result($result, 0, TBL_DIVISIONS . ".Captain");
                                            $aid = mysql_result($result, 0, TBL_AWARDS . ".AwardID");
                                            $q = "DELETE FROM " . TBL_AWARDS . " WHERE (" . TBL_AWARDS . ".AwardID = '{$aid}')";
                                            $result = $sql->db_Query($q);
                                            // gold
                                            if (is_gold_system_active() && $this->getField('GoldWinningEvent') > 0) {
                                                $gold_param['gold_user_id'] = $uid;
                                                $gold_param['gold_who_id'] = 0;
                                                $gold_param['gold_amount'] = $this->getField('GoldWinningEvent');
                                                $gold_param['gold_type'] = EB_L1;
                                                $gold_param['gold_action'] = "debit";
                                                $gold_param['gold_plugin'] = "ebattles";
                                                $gold_param['gold_log'] = EB_GOLD_L8 . ": event=" . $event_id . ", user="******"SELECT " . TBL_MATCHS . ".*, " . TBL_SCORES . ".*, " . TBL_PLAYERS . ".*, " . TBL_USERS . ".*" . " FROM " . TBL_MATCHS . ", " . TBL_SCORES . ", " . TBL_PLAYERS . ", " . TBL_GAMERS . ", " . TBL_USERS . " WHERE (" . TBL_MATCHS . ".MatchID = '{$current_match_id}')" . " AND (" . TBL_SCORES . ".MatchID = " . TBL_MATCHS . ".MatchID)" . " AND (" . TBL_PLAYERS . ".PlayerID = " . TBL_SCORES . ".Player)" . " AND (" . TBL_PLAYERS . ".Gamer = " . TBL_GAMERS . ".GamerID)" . " AND (" . TBL_USERS . ".user_id = " . TBL_GAMERS . ".User)" . " ORDER BY " . TBL_SCORES . ".Player_Rank, " . TBL_SCORES . ".Player_MatchTeam";
                                                break;
                                            case 'Teams':
                                                $q = "SELECT " . TBL_MATCHS . ".*, " . TBL_SCORES . ".*, " . TBL_CLANS . ".*, " . TBL_TEAMS . ".*, " . TBL_DIVISIONS . ".*" . " FROM " . TBL_MATCHS . ", " . TBL_SCORES . ", " . TBL_CLANS . ", " . TBL_TEAMS . ", " . TBL_DIVISIONS . " WHERE (" . TBL_MATCHS . ".MatchID = '{$current_match_id}')" . " AND (" . TBL_SCORES . ".MatchID = " . TBL_MATCHS . ".MatchID)" . " AND (" . TBL_TEAMS . ".TeamID = " . TBL_SCORES . ".Team)" . " AND (" . TBL_CLANS . ".ClanID = " . TBL_DIVISIONS . ".Clan)" . " AND (" . TBL_TEAMS . ".Division = " . TBL_DIVISIONS . ".DivisionID)" . " ORDER BY " . TBL_SCORES . ".Player_Rank, " . TBL_SCORES . ".Player_MatchTeam";
                                                break;
                                            default:
                                        }
                                        $result = $sql->db_Query($q);
                                        $numScores = mysql_numrows($result);
                                        if ($numScores > 0) {
                                            for ($i = 0; $i < $numScores; $i++) {
                                                switch ($this->getMatchPlayersType()) {
                                                    case 'Players':
                                                        $pid = mysql_result($result, $i, TBL_PLAYERS . ".PlayerID");
                                                        break;
                                                    case 'Teams':
                                                        $pid = mysql_result($result, $i, TBL_TEAMS . ".TeamID");
                                                        break;
                                                    default:
                                                }
                                                $pscoreid = mysql_result($result, $i, TBL_SCORES . ".ScoreID");
                                                $prank = mysql_result($result, $i, TBL_SCORES . ".Player_Rank");
                                                $pscore = mysql_result($result, $i, TBL_SCORES . ".Player_Score");
                                                $pMatchTeam = mysql_result($result, $i, TBL_SCORES . ".Player_MatchTeam");
                                                $teamTop = substr($content[$round][$matchup][0], 1);
                                                $teamBottom = substr($content[$round][$matchup][1], 1);
                                                $results[$round][$matchup]['matchs'][$match]['scores'][$i] = $pscore;
                                                if ($i == 0) {
                                                    $teamTopID = $teams[$teamTop - 1]['PlayerID'];
                                                    $teamBottomID = $teams[$teamBottom - 1]['PlayerID'];
                                                    if ($teamTopID == $pid) {
                                                        $current_match_winner = 'top';
                                                    } else {
                                                        $current_match_winner = 'bottom';
                                                    }
                                                    $results[$round][$matchup]['matchs'][$match]['winner'] = $current_match_winner;
                                                }
                                            }
                                        }
                                    }
                                }
                                // match not played
                                $matchupWinnerID = 0;
                                if ($current_match_winner == 'top') {
                                    $results[$round][$matchup]['topWins'] += 1;
                                    if ($results[$round][$matchup]['topWins'] == ($rounds[$round]['BestOf'] + 1) / 2) {
                                        $results[$round][$matchup]['winner'] = 'top';
                                        $matchupWinnerID = $teamTopID;
                                        //echo "Match $matchs, top won<br>";
                                    }
                                }
                                // winner==top
                                if ($current_match_winner == 'bottom') {
                                    $results[$round][$matchup]['bottomWins'] += 1;
                                    if ($results[$round][$matchup]['bottomWins'] == ($rounds[$round]['BestOf'] + 1) / 2) {
                                        $results[$round][$matchup]['winner'] = 'bottom';
                                        $matchupWinnerID = $teamBottomID;
                                        //echo "Match $matchs, bottom won<br>";
                                    }
                                }
                                // winner==bottom
                                if ($matchupWinnerID != 0) {
                                    if ($round == $nbrRounds - 1 && $competition_type == 'Tournament') {
                                        // player has won the tournament
                                        $this->setFieldDB('Status', 'finished');
                                        // Award: player wins tournament
                                        switch ($type) {
                                            case "One Player Tournament":
                                                $q_Award = "INSERT INTO " . TBL_AWARDS . "(Player,Type,timestamp)\r\n\t\t\t\t\t\t\t\t\t\t\tVALUES ({$matchupWinnerID},'PlayerWonTournament',{$time})";
                                                $result_Award = $sql->db_Query($q_Award);
                                                // gold
                                                if (is_gold_system_active() && $this->getField('GoldWinningEvent') > 0) {
                                                    // find player's user_id
                                                    $q = "SELECT " . TBL_PLAYERS . ".*, " . TBL_GAMERS . ".*" . " FROM " . TBL_PLAYERS . ", " . TBL_GAMERS . " WHERE (" . TBL_PLAYERS . ".PlayerID = '{$matchupWinnerID}')" . "   AND (" . TBL_PLAYERS . ".Gamer = " . TBL_GAMERS . ".GamerID)";
                                                    $result = $sql->db_Query($q);
                                                    $uid = mysql_result($result, 0, TBL_GAMERS . ".User");
                                                    $gold_param['gold_user_id'] = $uid;
                                                    $gold_param['gold_who_id'] = 0;
                                                    $gold_param['gold_amount'] = $this->getField('GoldWinningEvent');
                                                    $gold_param['gold_type'] = EB_L1;
                                                    $gold_param['gold_action'] = "credit";
                                                    $gold_param['gold_plugin'] = "ebattles";
                                                    $gold_param['gold_log'] = EB_GOLD_L8 . ": event=" . $event_id . ", user="******"Clan Tournament":
                                                $q_Award = "INSERT INTO " . TBL_AWARDS . "(Team,Type,timestamp)\r\n\t\t\t\t\t\t\t\t\t\t\tVALUES ({$matchupWinnerID},'TeamWonTournament',{$time})";
                                                $result_Award = $sql->db_Query($q_Award);
                                                // gold
                                                if (is_gold_system_active() && $this->getField('GoldWinningEvent') > 0) {
                                                    // find team captain
                                                    $q = "SELECT " . TBL_TEAMS . ".*, " . TBL_DIVISIONS . ".*" . " FROM " . TBL_TEAMS . ", " . TBL_DIVISIONS . " WHERE (" . TBL_TEAMS . ".TeamID = '{$matchupWinnerID}')" . "   AND (" . TBL_TEAMS . ".Division = " . TBL_DIVISIONS . ".DivisionID)";
                                                    $result = $sql->db_Query($q);
                                                    $uid = mysql_result($result, 0, TBL_DIVISIONS . ".Captain");
                                                    $gold_param['gold_user_id'] = $uid;
                                                    $gold_param['gold_who_id'] = 0;
                                                    $gold_param['gold_amount'] = $this->getField('GoldWinningEvent');
                                                    $gold_param['gold_type'] = EB_L1;
                                                    $gold_param['gold_action'] = "credit";
                                                    $gold_param['gold_plugin'] = "ebattles";
                                                    $gold_param['gold_log'] = EB_GOLD_L8 . ": event=" . $event_id . ", user="******"M$round,$matchup: L1: $team,".$teams[$team-1]['loss'].'<br>';
                            }
                        } else {
                            if ($results[$round][$matchup]['winner'] == 'bottom') {
                                $brackets[$matchupsRows[$round][$matchup][0]][2 * $round - 1] = html_bracket_team_cell($teams, $content[$round][$matchup][0], $topWins, 'loser');
                                $brackets[$matchupsRows[$round][$matchup][1]][2 * $round - 1] = html_bracket_team_cell($teams, $content[$round][$matchup][1], $bottomWins, 'winner');
                                $loser = $content[$round][$matchup][0];
                                if ($loser[0] == 'T') {
                                    $team = substr($loser, 1);
                                    $teams[$team - 1]['loss'] += 1;
                                    //echo "M$round,$matchup: L1: $team,".$teams[$team-1]['loss'].'<br>';
                                }
                            } else {
                                $brackets[$matchupsRows[$round][$matchup][0]][2 * $round - 1] = html_bracket_team_cell($teams, $content[$round][$matchup][0], $topWins);
                                $brackets[$matchupsRows[$round][$matchup][1]][2 * $round - 1] = html_bracket_team_cell($teams, $content[$round][$matchup][1], $bottomWins);
                            }
                        }
                        $matchup_string = '';
                        if ($nbr_matchs > 0) {
                            $tbl = array();
                            for ($match = 0; $match < $nbr_matchs; $match++) {
                                $match_id = $results[$round][$matchup]['matchs'][$match]['match_id'];
                                $match_winner = $results[$round][$matchup]['matchs'][$match]['winner'];
                                $score_0 = $results[$round][$matchup]['matchs'][$match]['scores'][0];
                                $score_1 = $results[$round][$matchup]['matchs'][$match]['scores'][1];
                                $score_0_str = '&nbsp;';
                                $score_1_str = '&nbsp;';
                                if ($this->getField('AllowScore') == TRUE) {
                                    if (isset($score_0)) {
                                        $score_0_str = $score_0;
                                    }
                                    if (isset($score_1)) {
                                        $score_1_str = $score_1;
                                    }
                                }
                                switch ($match_winner) {
                                    case 'top':
                                        $class_str = 'match-winner';
                                        $score_str = $score_0_str;
                                        $match_link_str = '<a href="' . e_PLUGIN . 'ebattles/matchinfo.php?matchid=' . $match_id . '"><div class="' . $class_str . '" title="' . EB_MATCH_L1 . ' ' . ($match + 1) . '">' . $score_str . '</div></a>';
                                        $tbl[$match][0] = '<td>' . $match_link_str . '</td>';
                                        $class_str = 'match-loser';
                                        $score_str = $score_1_str;
                                        $match_link_str = '<a href="' . e_PLUGIN . 'ebattles/matchinfo.php?matchid=' . $match_id . '"><div class="' . $class_str . '" title="' . EB_MATCH_L1 . ' ' . ($match + 1) . '">' . $score_str . '</div></a>';
                                        $tbl[$match][1] = '<td>' . $match_link_str . '</td>';
                                        break;
                                    case 'bottom':
                                        $class_str = 'match-loser';
                                        $score_str = $score_1_str;
                                        $match_link_str = '<a href="' . e_PLUGIN . 'ebattles/matchinfo.php?matchid=' . $match_id . '"><div class="' . $class_str . '" title="' . EB_MATCH_L1 . ' ' . ($match + 1) . '">' . $score_str . '</div></a>';
                                        $tbl[$match][0] = '<td>' . $match_link_str . '</td>';
                                        $class_str = 'match-winner';
                                        $score_str = $score_0_str;
                                        $match_link_str = '<a href="' . e_PLUGIN . 'ebattles/matchinfo.php?matchid=' . $match_id . '"><div class="' . $class_str . '" title="' . EB_MATCH_L1 . ' ' . ($match + 1) . '">' . $score_str . '</div></a>';
                                        $tbl[$match][1] = '<td>' . $match_link_str . '</td>';
                                        break;
                                    default:
                                        $class_str = 'match-not-played';
                                        $matchObj = new Match($match_id);
                                        $permissions = $matchObj->get_permissions(USERID);
                                        $userclass = $permissions['userclass'];
                                        $can_report = $permissions['can_report'];
                                        $can_approve = $permissions['can_approve'];
                                        $can_delete = $permissions['can_delete'];
                                        $can_edit = $permissions['can_edit'];
                                        $match_link_str = '';
                                        $tbl[$match][0] = '';
                                        if ($can_approve == 1) {
                                            $match_link_str = ' <a href="' . e_PLUGIN . 'ebattles/matchinfo.php?matchid=' . $match_id . '"><img class="eb_image" src="' . e_PLUGIN . 'ebattles/images/exclamation.png" alt="' . EB_MATCH_L13 . '" title="' . EB_MATCH_L13 . '"/></a>';
                                            $tbl[$match][0] .= '<td rowspan="2" class="' . $class_str . '"><div class="' . $class_str . '" title="' . EB_MATCH_L1 . ' ' . ($match + 1) . '">' . $match_link_str . '</div></td>';
                                        }
                                        /*
                                        if($can_edit == 1)
                                        {
                                        	if($matchObj->getField('Status') == 'scheduled')
                                        	{
                                        		$match_link_str = ebImageLink('matchschedulededit', EB_MATCHR_L46, '', e_PLUGIN.'ebattles/matchreport.php?eventid='.$event_id.'&amp;matchid='.$match_id.'&amp;actionid=matchschedulededit&amp;userclass='.$userclass, 'page_white_edit.png', '', 'matchreport_link', '', EB_MATCHR_L46.' '.($match+1));
                                        		$tbl[$match][0] .= '<td rowspan="2" class="'.$class_str.'"><div class="'.$class_str.'">'.$match_link_str.'</div></td>';
                                        	}
                                        	else
                                        	{
                                        		$match_link_str = ebImageLink('matchedit', EB_MATCHR_L46, '', e_PLUGIN.'ebattles/matchreport.php?eventid='.$event_id.'&amp;matchid='.$match_id.'&amp;actionid=matchedit&amp;userclass='.$userclass, 'page_white_edit.png', '', 'matchreport_link', '', EB_MATCHR_L46.' '.($match+1));
                                        		$tbl[$match][0] .= '<td rowspan="2" class="'.$class_str.'"><div class="'.$class_str.'">'.$match_link_str.'</div></td>';
                                        	}		
                                        }
                                        */
                                        if ($can_report == 1) {
                                            $match_link_str = ebImageLink('matchscheduledreport', EB_MATCHR_L32, '', e_PLUGIN . 'ebattles/matchreport.php?eventid=' . $event_id . '&amp;matchid=' . $match_id . '&amp;actionid=matchscheduledreport&amp;userclass=' . $userclass, 'report.png', '', 'matchreport_link', '', EB_MATCHR_L32 . ' ' . ($match + 1));
                                            $tbl[$match][0] .= '<td rowspan="2" class="' . $class_str . '"><div class="' . $class_str . '" title="' . EB_MATCH_L1 . ' ' . ($match + 1) . '">' . $match_link_str . '</div></td>';
                                        }
                                        $tbl[$match][1] = '';
                                        break;
                                }
                            }
                            $matchup_string = '<table class="brackets-matchup"><tbody>';
                            $matchup_string .= '<tr>';
                            for ($match = 0; $match < $nbr_matchs; $match++) {
                                $matchup_string .= $tbl[$match][0];
                            }
                            $matchup_string .= '</tr>';
                            $matchup_string .= '<tr>';
                            for ($match = 0; $match < $nbr_matchs; $match++) {
                                $matchup_string .= $tbl[$match][1];
                            }
                            $matchup_string .= '</tr>';
                            $matchup_string .= '</tbody></table>';
                            //echo $tbl_str;
                        }
                        switch ($style) {
                            case 'elimination':
                                $brackets[$matchupsRows[$round][$matchup][0] + 1][2 * $round - 1] = '<td rowspan="' . $rowspan . '" class="match-details" title="' . EB_EVENT_L102 . ' ' . $round . ',' . $matchup . '">
							' . $matchup_string . '
							</td>';
                                break;
                            case 'round-robin':
                                $brackets[$matchupsRows[$round][$matchup][1] + 1][2 * $round - 1] = '<td rowspan="1" class="match-details" title="' . EB_EVENT_L102 . ' ' . $round . ',' . $matchup . '">
							' . $matchup_string . '
							</td>';
                                break;
                        }
                        $rounds[$round]['nbrMatchups']++;
                    }
                    // if(content!='E')
                    if ($scheduleNextMatches == true && $content[$round][$matchup][0][0] == 'T' && $content[$round][$matchup][1][0] == 'T' && $results[$round][$matchup]['winner'] == 'not played') {
                        $update_results = true;
                        $current_match = $results[$round][$matchup]['matchs'][$nbr_matchs - 1];
                        //var_dump($current_match);
                        if (!isset($current_match) || $current_match['winner'] != 'not played') {
                            /*
                            echo 'M'.$round.','.$matchup.':<br>';
                            var_dump($results[$round][$matchup]);
                            var_dump($content[$round][$matchup]);
                            */
                            // Need to schedule the next match
                            // Create Match ------------------------------------------
                            $reported_by = $this->getField('Owner');
                            $time_reported = $time;
                            $comments = '';
                            $time_scheduled = $time_reported;
                            $q = "INSERT INTO " . TBL_MATCHS . "(Event,ReportedBy,TimeReported, Comments, Status, TimeScheduled)\r\n\t\t\t\t\t\t\tVALUES ({$event_id},'{$reported_by}', {$time_reported}, '{$comments}', 'scheduled', {$time_scheduled})";
                            $result = $sql->db_Query($q);
                            $last_id = mysql_insert_id();
                            $match_id = $last_id;
                            // Create Scores ------------------------------------------
                            $teamTop = substr($content[$round][$matchup][0], 1);
                            $teamBottom = substr($content[$round][$matchup][1], 1);
                            switch ($this->getMatchPlayersType()) {
                                case 'Players':
                                    $playerTopID = $teams[$teamTop - 1]['PlayerID'];
                                    $playerBottomID = $teams[$teamBottom - 1]['PlayerID'];
                                    $teamTopID = 0;
                                    $teamBottomID = 0;
                                    break;
                                case 'Teams':
                                    $playerTopID = 0;
                                    $playerBottomID = 0;
                                    $teamTopID = $teams[$teamTop - 1]['PlayerID'];
                                    $teamBottomID = $teams[$teamBottom - 1]['PlayerID'];
                                    break;
                            }
                            $q = "INSERT INTO " . TBL_SCORES . "(MatchID,Player,Team,Player_MatchTeam,Player_Rank)\r\n\t\t\t\t\t\t\tVALUES ({$match_id},{$playerTopID},{$teamTopID},1,1)\r\n\t\t\t\t\t\t\t";
                            $result = $sql->db_Query($q);
                            $q = "INSERT INTO " . TBL_SCORES . "(MatchID,Player,Team,Player_MatchTeam,Player_Rank)\r\n\t\t\t\t\t\t\tVALUES ({$match_id},{$playerBottomID},{$teamBottomID},2,2)\r\n\t\t\t\t\t\t\t";
                            $result = $sql->db_Query($q);
                            $match_array = array();
                            $match_array['winner'] = 'not played';
                            $match_array['match_id'] = $match_id;
                            $results[$round][$matchup]['matchs'][$nbr_matchs] = $match_array;
                            if ($nbr_matchs == 0) {
                                // Send notification to all the players.
                                $fromid = 0;
                                $subject = SITENAME . " " . EB_MATCHR_L52;
                                switch ($this->getMatchPlayersType()) {
                                    case 'Players':
                                        $q_Players = "SELECT DISTINCT " . TBL_USERS . ".*" . " FROM " . TBL_MATCHS . ", " . TBL_SCORES . ", " . TBL_PLAYERS . ", " . TBL_GAMERS . ", " . TBL_USERS . " WHERE (" . TBL_MATCHS . ".MatchID = '{$match_id}')" . " AND (" . TBL_SCORES . ".MatchID = " . TBL_MATCHS . ".MatchID)" . " AND (" . TBL_PLAYERS . ".PlayerID = " . TBL_SCORES . ".Player)" . " AND (" . TBL_PLAYERS . ".Gamer = " . TBL_GAMERS . ".GamerID)" . " AND (" . TBL_GAMERS . ".User = "******".user_id)";
                                        $result_Players = $sql->db_Query($q_Players);
                                        $numPlayers = mysql_numrows($result_Players);
                                        break;
                                    case 'Teams':
                                        $q_Players = "SELECT DISTINCT " . TBL_USERS . ".*" . " FROM " . TBL_MATCHS . ", " . TBL_SCORES . ", " . TBL_TEAMS . ", " . TBL_PLAYERS . ", " . TBL_GAMERS . ", " . TBL_USERS . " WHERE (" . TBL_MATCHS . ".MatchID = '{$match_id}')" . " AND (" . TBL_SCORES . ".MatchID = " . TBL_MATCHS . ".MatchID)" . " AND (" . TBL_TEAMS . ".TeamID = " . TBL_SCORES . ".Team)" . " AND (" . TBL_PLAYERS . ".Team = " . TBL_TEAMS . ".TeamID)" . " AND (" . TBL_PLAYERS . ".Gamer = " . TBL_GAMERS . ".GamerID)" . " AND (" . TBL_GAMERS . ".User = "******".user_id)";
                                        $result_Players = $sql->db_Query($q_Players);
                                        $numPlayers = mysql_numrows($result_Players);
                                        break;
                                    default:
                                }
                                if ($numPlayers > 0) {
                                    for ($j = 0; $j < $numPlayers; $j++) {
                                        $pname = mysql_result($result_Players, $j, TBL_USERS . ".user_name");
                                        $pemail = mysql_result($result_Players, $j, TBL_USERS . ".user_email");
                                        $message = EB_MATCHR_L53 . $pname . EB_MATCHR_L54 . EB_MATCHR_L55 . $this->getField('Name') . EB_MATCHR_L56;
                                        $sendto = mysql_result($result_Players, $j, TBL_USERS . ".user_id");
                                        $sendtoemail = mysql_result($result_Players, $j, TBL_USERS . ".user_email");
                                        if (check_class($pref['eb_pm_notifications_class'])) {
                                            // Send PM
                                            sendNotification($sendto, $subject, $message, $fromid);
                                        }
                                        if (check_class($pref['eb_email_notifications_class'])) {
                                            // Send email
                                            require_once e_HANDLER . "mail.php";
                                            sendemail($sendtoemail, $subject, $message);
                                        }
                                    }
                                }
                            }
                            // if(nbr_matchs==0)
                        }
                        // create match
                    }
                    // schedule next match
                    /*
                    echo 'M'.$round.','.$matchup.':<br>';
                    var_dump($results[$round][$matchup]);
                    var_dump($content[$round][$matchup]);
                    echo '- matchup: top='.$matchups[$round][$matchup][0].', bottom='.$matchups[$round][$matchup][1].'<br>';
                    echo '- content: top='.$content[$round][$matchup][0].', bottom='.$content[$round][$matchup][1].'<br>';
                    echo '- winner='.$results[$round][$matchup]['winner'].', bye='.$results[$round][$matchup]['bye'].'<br>';
                    */
                }
                // for(matchup)
            } else {
                /* Last round, no match */
                for ($matchup = 1; $matchup <= $nbrMatchups; $matchup++) {
                    if (!isset($results[$round][$matchup]['winner'])) {
                        $results[$round][$matchup]['winner'] = '';
                    }
                    if (!isset($results[$round][$matchup]['bye'])) {
                        $results[$round][$matchup]['bye'] = false;
                    }
                    $match = 0;
                    $matchupString = $matchups[$round][$matchup][$match];
                    $content[$round][$matchup][$match] = $matchupString == '' ? 'E' : $matchupString;
                    if ($matchupString[$match] = 'W') {
                        $matchupArray = explode(',', substr($matchupString, 1));
                        $matchupRound = $matchupArray[0];
                        $matchupMatchup = $matchupArray[1];
                        $winner = $results[$matchupRound][$matchupMatchup]['winner'];
                        $bye = $results[$matchupRound][$matchupMatchup]['bye'];
                        $rowTop = $matchupsRows[$matchupRound][$matchupMatchup][0];
                        $rowBottom = $matchupsRows[$matchupRound][$matchupMatchup][1];
                        $row = ($rowBottom - $rowTop) / 2 + $rowTop;
                        if ($bye != true) {
                            $brackets[$rowTop][2 * $round - 2] = '<td class="grid border-top"></td>';
                            $brackets[$rowBottom][2 * $round - 2] = '<td class="grid border-bottom"></td>';
                            for ($i = $rowTop + 1; $i < $rowBottom; $i++) {
                                $brackets[$i][2 * $round - 2] = '<td class="grid border-vertical"></td>';
                            }
                            for ($i = $rowTop + 2; $i < $rowBottom; $i++) {
                                $brackets[$i][2 * $round - 3] = '';
                            }
                            $brackets[$row][2 * $round - 2] = '<td class="grid border-middle"></td>';
                        }
                        $matchupsRows[$round][$matchup][$match] = $rowTop;
                        if ($winner == 'top') {
                            $content[$round][$matchup][$match] = $content[$matchupRound][$matchupMatchup][0];
                        } else {
                            if ($winner == 'bottom') {
                                $content[$round][$matchup][$match] = $content[$matchupRound][$matchupMatchup][1];
                            }
                        }
                        $topWins = $results[$round][$matchup]['topWins'];
                        $bottomWins = $results[$round][$matchup]['bottomWins'];
                        if ($topWins > $bottomWins) {
                            $topWins .= '+';
                            $bottomWins .= '-';
                        }
                        if ($topWins < $bottomWins) {
                            $topWins .= '-';
                            $bottomWins .= '+';
                        }
                        if ($content[$round][$matchup][0][0] != 'E') {
                            $brackets[$row][2 * $round - 1] = html_bracket_team_cell($teams, $content[$round][$matchup][$match], $topWins, 'victor');
                        } else {
                            $brackets[$row][2 * $round - 1] = html_bracket_team_cell($teams, $content[$round][$matchup][$match], $bottomWins);
                        }
                    }
                }
                // for(matchup)
            }
            $rowspan = 2 * $rowspan + 1;
        }
        $bracket_html = '<div id="panel_brackets">';
        $bracket_html .= '<div id="brackets_frame" style="height: 400px;">';
        $bracket_html .= '<div id="brackets">';
        $bracket_html .= '<table class="brackets">';
        $bracket_html .= '<thead><tr>';
        for ($i = 1; $i < $nbrRounds; $i++) {
            if ($rounds[$i]['nbrMatchups'] != 0) {
                $bracket_html .= '<th colspan="2" title="' . EB_EVENTM_L146 . ' ' . $rounds[$i]['BestOf'] . '">';
                $bracket_html .= $rounds[$i]['Title'] . '<br />';
                $bracket_html .= '<div class="smalltext">' . EB_EVENTM_L146 . ' ' . $rounds[$i]['BestOf'] . '</div>';
                $bracket_html .= '</th>';
            } else {
                $bracket_html .= '<th colspan="2"></th>';
            }
        }
        $bracket_html .= '</tr></thead>';
        $bracket_html .= '<tbody>';
        for ($row = 1; $row <= $nbrRows; $row++) {
            $bracket_html .= '<tr>';
            for ($column = 1; $column <= 2 * $nbrRounds; $column++) {
                $bracket_html .= $brackets[$row][$column];
            }
            $bracket_html .= '</tr>';
        }
        $bracket_html .= '</tbody>';
        $bracket_html .= '</table>';
        $bracket_html .= '</div>';
        // brackets
        $bracket_html .= '</div>';
        // brackets_frame
        $bracket_html .= '<div class="clearer"></div>';
        $bracket_html .= '</div>';
        // panel-brackets
        /*
        echo "rounds:<br>";
        var_dump($rounds);
        echo "matchups:<br>";
        var_dump($matchups);
        echo "results:<br>";
        var_dump($results);
        echo "content:<br>";
        var_dump($content);
        echo "teams:<br>";
        var_dump($teams);
        */
        if ($update_results == true) {
            $this->updateResults($results);
            $this->updateFieldDB('Results');
        }
        return array($bracket_html);
    }
    printf("[031] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
}
findRow(32, $link, $id, $label_b);
class foo
{
    public $foo;
    function foo()
    {
        $this->foo =& $this->bar;
    }
}
class bar extends foo
{
    public $bar = 'v';
}
$bar = new bar();
$id++;
$label =& $GLOBALS['bar']->foo;
if (true !== ($tmp = mysqli_stmt_bind_param($stmt, "is", $id, $label))) {
    printf("[033] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
}
if (true !== mysqli_stmt_execute($stmt)) {
    printf("[034] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
}
findRow(35, $link, $id, $label);
mysqli_stmt_close($stmt);
mysqli_close($link);
print "done!";
error_reporting(0);
$test_table_name = 'test_mysqli_stmt_bind_param_references_table_1';
require_once "clean_table.inc";
示例#4
0
function find($inFindCol, $inFind = '', $inOb = '', $inFindFrom = 0, $inFindForward = true, $inFullText = true)
{
    global $table;
    // build order by clause
    $desc = (bool) getPostString("desc");
    if (!$inOb) {
        $inOb = getOrderBy();
    }
    if ($inOb) {
        $inOb = "`" . $inOb . "`";
    }
    $orderby = $inOb ? " ORDER BY {$inOb} " . ($desc ? " DESC" : "") : "";
    // update inputs from post
    if (!$inFind) {
        $inFind = getPostString('findText');
    }
    if (!$inFindCol) {
        $inFindCol = getPostString('findCol');
    }
    if (empty($inFindFrom)) {
        $inFindFrom = getPostString('findFrom');
    }
    $ff = getPostString('findForward');
    if ($ff) {
        $inFindForward = strtolower($ff) == 'true' ? true : false;
    }
    $ft = getPostString('findFullText');
    if ($ft) {
        $inFullText = strtolower($ft) == 'true' ? true : false;
    }
    // get find data
    $f = findData($inFindCol, $inFind, $orderby, $inFullText);
    $pk = getPk();
    // execute query
    $where = buildFindWhere($f, $pk->index, 'f');
    $query = "SELECT Row, f FROM (SELECT @row := @row + 1 AS Row, {$pk->name} as f FROM `{$table}` {$orderby}) AS tempTable {$where}";
    mysql_query('SET @row = -1;');
    if (!($result = mysql_query($query))) {
        error("failed to perform query: {$query}. " . mysql_error());
    }
    // return row number
    return findRow(getArray($result), $inFindFrom, $inFindForward);
}
示例#5
0
    $maps = array();
    //$r = ceil(strlen($map)/$width);
    for ($i = 0; $i < strlen($map); $i += 3) {
        $ss = substr($map, $i, 3);
        $maps[] = $ss;
    }
    return $maps;
}
class response
{
    var $map;
    var $moves;
}
if (strlen($map) == $width * $width) {
    $p_row = findRow($map, $width, "p");
    $p_column = findColumn($map, $width, "p");
    $w_row = findRow($map, $width, "w");
    $w_column = findColumn($map, $width, "w");
    $f_row = findRow($map, $width, "f");
    $f_column = findColumn($map, $width, "f");
    $move1 = findDirection($p_row, $p_column, $w_row, $w_column);
    $move2 = findDirection($w_row, $w_column, $f_row, $f_column);
    $all_move = array_merge($move1, $move2);
    //print_r($all_move);
    header('Content-type: application/json');
    $maps = getMaps($map, $width);
    $response = new response();
    $response->map = $maps;
    $response->moves = $all_move;
    echo json_encode($response);
}