Ejemplo n.º 1
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);
    }
Ejemplo n.º 2
0
 function match_players_update()
 {
     global $sql;
     global $gold_obj;
     global $pref;
     // Get event info
     $event_id = $this->fields['Event'];
     $event = new Event($event_id);
     $type = $event->getField('Type');
     $competition_type = $event->getCompetitionType();
     $G2_r0 = $event->getField('G2_default_r');
     // Update Teams with scores
     $tdeltaELO = array();
     $tdeltaTS_mu = array();
     $tdeltaTS_sigma = array();
     $tdeltaG2_mu = array();
     $tdeltaG2_phi = array();
     $tdeltaG2_sigma = array();
     $tdeltaGamesPlayed = array();
     $tdeltaWins = array();
     $tdeltaDraws = array();
     $tdeltaLosses = array();
     $tdeltaScore = array();
     $tdeltaOppScore = array();
     $tdeltaPoints = array();
     $tdeltaForfeits = array();
     $tnbrPlayers = array();
     $q = "SELECT DISTINCT " . TBL_PLAYERS . ".Team" . " FROM " . TBL_MATCHS . ", " . TBL_SCORES . ", " . TBL_PLAYERS . " WHERE (" . TBL_MATCHS . ".MatchID = '" . $this->fields['MatchID'] . "')" . " AND (" . TBL_SCORES . ".MatchID = " . TBL_MATCHS . ".MatchID)" . " AND (" . TBL_PLAYERS . ".PlayerID = " . TBL_SCORES . ".Player)" . " AND (" . TBL_PLAYERS . ".Team > 0)";
     $result_Teams = $sql->db_Query($q);
     $numTeams = mysql_numrows($result_Teams);
     for ($team = 0; $team < $numTeams; $team++) {
         $tid = mysql_result($result_Teams, $team, TBL_PLAYERS . ".Team");
         $tdeltaELO[$tid] = 0;
         $tdeltaTS_mu[$tid] = 0;
         $tdeltaTS_sigma[$tid] = 0;
         $tdeltaG2_mu[$tid] = 0;
         $tdeltaG2_phi[$tid] = 0;
         $tdeltaG2_sigma[$tid] = 0;
         $tdeltaGamesPlayed[$tid] = 0;
         $tdeltaWins[$tid] = 0;
         $tdeltaDraws[$tid] = 0;
         $tdeltaLosses[$tid] = 0;
         $tdeltaScore[$tid] = 0;
         $tdeltaOppScore[$tid] = 0;
         $tdeltaPoints[$tid] = 0;
         $tdeltaForfeits[$tid] = 0;
         $tnbrPlayers[$tid] = 0;
     }
     // Update Players with scores
     $q = "SELECT " . TBL_MATCHS . ".*, " . TBL_SCORES . ".*, " . TBL_PLAYERS . ".*, " . TBL_USERS . ".*" . " FROM " . TBL_MATCHS . ", " . TBL_SCORES . ", " . TBL_PLAYERS . ", " . TBL_GAMERS . ", " . TBL_USERS . " WHERE (" . TBL_MATCHS . ".MatchID = '" . $this->fields['MatchID'] . "')" . " 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)";
     $result = $sql->db_Query($q);
     $numPlayers = mysql_numrows($result);
     for ($i = 0; $i < $numPlayers; $i++) {
         $time_reported = mysql_result($result, $i, TBL_MATCHS . ".TimeReported");
         $mStatus = mysql_result($result, $i, TBL_MATCHS . ".Status");
         $pid = mysql_result($result, $i, TBL_PLAYERS . ".PlayerID");
         $puid = mysql_result($result, $i, TBL_USERS . ".user_id");
         $gamer_id = mysql_result($result, $i, TBL_PLAYERS . ".Gamer");
         $gamer = new Gamer($gamer_id);
         $pName = $gamer->getField('Name');
         $pteam = mysql_result($result, $i, TBL_PLAYERS . ".Team");
         $pELO = mysql_result($result, $i, TBL_PLAYERS . ".ELORanking");
         $pTS_mu = mysql_result($result, $i, TBL_PLAYERS . ".TS_mu");
         $pTS_sigma = mysql_result($result, $i, TBL_PLAYERS . ".TS_sigma");
         $pG2_r = mysql_result($result, $i, TBL_PLAYERS . ".G2_r");
         $pG2_RD = mysql_result($result, $i, TBL_PLAYERS . ".G2_RD");
         $pG2_sigma = mysql_result($result, $i, TBL_PLAYERS . ".G2_sigma");
         $pG2_mu = g2_from_g1_rating($pG2_r, $G2_r0, G2_qinv);
         $pG2_phi = g2_from_g1_deviation($pG2_RD, G2_qinv);
         $pGamesPlayed = mysql_result($result, $i, TBL_PLAYERS . ".GamesPlayed");
         $pWins = mysql_result($result, $i, TBL_PLAYERS . ".Win");
         $pDraws = mysql_result($result, $i, TBL_PLAYERS . ".Draw");
         $pLosses = mysql_result($result, $i, TBL_PLAYERS . ".Loss");
         $pStreak = mysql_result($result, $i, TBL_PLAYERS . ".Streak");
         $pStreak_Best = mysql_result($result, $i, TBL_PLAYERS . ".Streak_Best");
         $pStreak_Worst = mysql_result($result, $i, TBL_PLAYERS . ".Streak_Worst");
         $pScore = mysql_result($result, $i, TBL_PLAYERS . ".Score");
         $pOppScore = mysql_result($result, $i, TBL_PLAYERS . ".ScoreAgainst");
         $pPoints = mysql_result($result, $i, TBL_PLAYERS . ".Points");
         $pForfeits = mysql_result($result, $i, TBL_PLAYERS . ".Forfeits");
         $scoreid = mysql_result($result, $i, TBL_SCORES . ".ScoreID");
         $pdeltaELO = mysql_result($result, $i, TBL_SCORES . ".Player_deltaELO");
         $pdeltaTS_mu = mysql_result($result, $i, TBL_SCORES . ".Player_deltaTS_mu");
         $pdeltaTS_sigma = mysql_result($result, $i, TBL_SCORES . ".Player_deltaTS_sigma");
         $pdeltaG2_mu = mysql_result($result, $i, TBL_SCORES . ".Player_deltaG2_mu");
         $pdeltaG2_phi = mysql_result($result, $i, TBL_SCORES . ".Player_deltaG2_phi");
         $pdeltaG2_sigma = mysql_result($result, $i, TBL_SCORES . ".Player_deltaG2_sigma");
         $pdeltaGamesPlayed = 1;
         $pdeltaWins = mysql_result($result, $i, TBL_SCORES . ".Player_Win");
         $pdeltaDraws = mysql_result($result, $i, TBL_SCORES . ".Player_Draw");
         $pdeltaLosses = mysql_result($result, $i, TBL_SCORES . ".Player_Loss");
         $pdeltaScore = mysql_result($result, $i, TBL_SCORES . ".Player_Score");
         $pdeltaOppScore = mysql_result($result, $i, TBL_SCORES . ".Player_ScoreAgainst");
         $pdeltaPoints = mysql_result($result, $i, TBL_SCORES . ".Player_Points");
         $pdeltaForfeits = mysql_result($result, $i, TBL_SCORES . ".Player_Forfeit");
         $pELO += $pdeltaELO;
         $pTS_mu += $pdeltaTS_mu;
         $pTS_sigma *= $pdeltaTS_sigma;
         $pG2_mu += $pdeltaG2_mu;
         $pG2_phi *= $pdeltaG2_phi;
         $pG2_sigma *= $pdeltaG2_sigma;
         $pG2_r = g2_to_g1_rating($pG2_mu, $G2_r0, G2_qinv);
         $pG2_RD = g2_to_g1_deviation($pG2_phi, G2_qinv);
         $pGamesPlayed += $pdeltaGamesPlayed;
         $pWins += $pdeltaWins;
         $pDraws += $pdeltaDraws;
         $pLosses += $pdeltaLosses;
         $pScore += $pdeltaScore;
         $pOppScore += $pdeltaOppScore;
         $pPoints += $pdeltaPoints;
         $pForfeits += $pdeltaForfeits;
         if ($pteam != 0) {
             $tdeltaELO[$pteam] += $pdeltaELO;
             $tdeltaTS_mu[$pteam] += $pdeltaTS_mu;
             $tdeltaTS_sigma[$pteam] += $pdeltaTS_sigma;
             $tdeltaG2_mu[$pteam] += $pdeltaG2_mu;
             $tdeltaG2_phi[$pteam] += $pdeltaG2_phi;
             $tdeltaG2_sigma[$pteam] += $pdeltaG2_sigma;
             $tdeltaGamesPlayed[$pteam] += 1;
             $tdeltaWins[$pteam] += $pdeltaWins;
             $tdeltaDraws[$pteam] += $pdeltaDraws;
             $tdeltaLosses[$pteam] += $pdeltaLosses;
             $tdeltaScore[$pteam] += $pdeltaScore;
             $tdeltaOppScore[$pteam] += $pdeltaOppScore;
             $tdeltaPoints[$pteam] += $pdeltaPoints;
             $tdeltaForfeits[$pteam] += $pdeltaForfeits;
             $tnbrPlayers[$pteam] += 1;
         }
         $output .= "Player: {$pName} - {$pid}, new ELO: {$pELO}<br />";
         $output .= "Games played: {$pGamesPlayed}<br>";
         $output .= "Match id: " . $this->fields['MatchID'] . "<br />";
         $gain = mysql_result($result, $i, TBL_SCORES . ".Player_Win") - mysql_result($result, $i, TBL_SCORES . ".Player_Loss");
         if ($gain * $pStreak >= 0) {
             // same sign
             $pStreak += $gain;
         } else {
             // opposite sign
             $pStreak = $gain;
         }
         if ($pStreak > $pStreak_Best) {
             $pStreak_Best = $pStreak;
         }
         if ($pStreak < $pStreak_Worst) {
             $pStreak_Worst = $pStreak;
         }
         if ($competition_type == 'Ladder') {
             if ($pStreak == 5) {
                 // Award: player wins 5 games in a row
                 $q4 = "INSERT INTO " . TBL_AWARDS . "(Player,Type,timestamp)\r\n\t\t\t\t\tVALUES ({$pid},'PlayerStreak5',{$time_reported})";
                 $result4 = $sql->db_Query($q4);
             }
             if ($pStreak == 10) {
                 // Award: player wins 10 games in a row
                 $q4 = "INSERT INTO " . TBL_AWARDS . "(Player,Type,timestamp)\r\n\t\t\t\t\tVALUES ({$pid},'PlayerStreak10',{$time_reported})";
                 $result4 = $sql->db_Query($q4);
             }
             if ($pStreak == 25) {
                 // Award: player wins 25 games in a row
                 $q4 = "INSERT INTO " . TBL_AWARDS . "(Player,Type,timestamp)\r\n\t\t\t\t\tVALUES ({$pid},'PlayerStreak25',{$time_reported})";
                 $result4 = $sql->db_Query($q4);
             }
         }
         // Update database.
         // Reset rank delta after a match.
         $q_3 = "UPDATE " . TBL_PLAYERS . " SET ELORanking = '" . floatToSQL($pELO) . "'," . "     TS_mu = '" . floatToSQL($pTS_mu) . "'," . "     TS_sigma = '" . floatToSQL($pTS_sigma) . "'," . "     G2_r = '" . floatToSQL($pG2_r) . "'," . "     G2_RD = '" . floatToSQL($pG2_RD) . "'," . "     G2_sigma = '" . floatToSQL($pG2_sigma) . "'," . "     GamesPlayed = {$pGamesPlayed}," . "     Loss = {$pLosses}," . "     Win = {$pWins}," . "     Draw = {$pDraws}," . "     Score = {$pScore}," . "     ScoreAgainst = {$pOppScore}," . "     Points = {$pPoints}," . "     Forfeits = {$pForfeits}," . "     Streak = {$pStreak}," . "     Streak_Best = {$pStreak_Best}," . "     Streak_Worst = {$pStreak_Worst}," . "     RankDelta = 0" . " WHERE (PlayerID = '{$pid}')";
         $result_3 = $sql->db_Query($q_3);
         // gold
         if (is_gold_system_active() && $pref['eb_gold_playmatch'] > 0) {
             $gold_param['gold_user_id'] = $puid;
             $gold_param['gold_who_id'] = 0;
             $gold_param['gold_amount'] = $pref['eb_gold_playmatch'];
             $gold_param['gold_type'] = EB_L1;
             $gold_param['gold_action'] = "credit";
             $gold_param['gold_plugin'] = "ebattles";
             $gold_param['gold_log'] = EB_GOLD_L9 . ": event=" . $event_id . ", user="******"SELECT DISTINCT " . TBL_PLAYERS . ".Team, " . TBL_TEAMS . ".*" . " FROM " . TBL_MATCHS . ", " . TBL_SCORES . ", " . TBL_PLAYERS . ", " . TBL_TEAMS . " WHERE (" . TBL_MATCHS . ".MatchID = '" . $this->fields['MatchID'] . "')" . " AND (" . TBL_SCORES . ".MatchID = " . TBL_MATCHS . ".MatchID)" . " AND (" . TBL_PLAYERS . ".PlayerID = " . TBL_SCORES . ".Player)" . " AND (" . TBL_TEAMS . ".TeamID = " . TBL_PLAYERS . ".Team)" . " AND (" . TBL_PLAYERS . ".Team > 0)";
     $result_Teams = $sql->db_Query($q);
     $numTeams = mysql_numrows($result_Teams);
     for ($team = 0; $team < $numTeams; $team++) {
         $tid = mysql_result($result_Teams, $team, TBL_PLAYERS . ".Team");
         $tPoints = mysql_result($result_Teams, $team, TBL_TEAMS . ".Points");
         $tForfeits = mysql_result($result_Teams, $team, TBL_TEAMS . ".Forfeits");
         $tELO = mysql_result($result_Teams, $team, TBL_TEAMS . ".ELORanking");
         $tTS_mu = mysql_result($result_Teams, $team, TBL_TEAMS . ".TS_mu");
         $tTS_sigma = mysql_result($result_Teams, $team, TBL_TEAMS . ".TS_sigma");
         $tG2_r = mysql_result($result_Teams, $team, TBL_TEAMS . ".G2_r");
         $tG2_RD = mysql_result($result_Teams, $team, TBL_TEAMS . ".G2_RD");
         $tG2_sigma = mysql_result($result_Teams, $team, TBL_TEAMS . ".G2_sigma");
         $tG2_mu = g2_from_g1_rating($tG2_r, $G2_r0, G2_qinv);
         $tG2_phi = g2_from_g1_deviation($tG2_RD, G2_qinv);
         $tGamesPlayed = mysql_result($result_Teams, $team, TBL_TEAMS . ".GamesPlayed");
         $tWins = mysql_result($result_Teams, $team, TBL_TEAMS . ".Win");
         $tDraws = mysql_result($result_Teams, $team, TBL_TEAMS . ".Draw");
         $tLosses = mysql_result($result_Teams, $team, TBL_TEAMS . ".Loss");
         $tScore = mysql_result($result_Teams, $team, TBL_TEAMS . ".Score");
         $tOppScore = mysql_result($result_Teams, $team, TBL_TEAMS . ".ScoreAgainst");
         $tdeltaELO[$tid] /= $tnbrPlayers[$tid];
         $tdeltaTS_mu[$tid] /= $tnbrPlayers[$tid];
         $tdeltaTS_sigma[$tid] /= $tnbrPlayers[$tid];
         $tdeltaG2_mu[$tid] /= $tnbrPlayers[$tid];
         $tdeltaG2_phi[$tid] /= $tnbrPlayers[$tid];
         $tdeltaG2_sigma[$tid] /= $tnbrPlayers[$tid];
         $tdeltaGamesPlayed[$tid] /= $tnbrPlayers[$tid];
         $tdeltaWins[$tid] /= $tnbrPlayers[$tid];
         $tdeltaDraws[$tid] /= $tnbrPlayers[$tid];
         $tdeltaLosses[$tid] /= $tnbrPlayers[$tid];
         $tdeltaScore[$tid] /= $tnbrPlayers[$tid];
         $tdeltaOppScore[$tid] /= $tnbrPlayers[$tid];
         $tdeltaPoints[$tid] /= $tnbrPlayers[$tid];
         $tdeltaForfeits[$tid] /= $tnbrPlayers[$tid];
         $tELO += $tdeltaELO[$tid];
         $tTS_mu += $tdeltaTS_mu[$tid];
         $tTS_sigma *= $tdeltaTS_sigma[$tid];
         $tG2_mu += $tdeltaG2_mu[$tid];
         $tG2_phi *= $tdeltaG2_phi[$tid];
         $tG2_sigma *= $tdeltaG2_sigma[$tid];
         $tG2_r = g2_to_g1_rating($tG2_mu, $G2_r0, G2_qinv);
         $tG2_RD = g2_to_g1_deviation($tG2_phi, G2_qinv);
         $tGamesPlayed += $tdeltaGamesPlayed[$tid];
         $tWins += $tdeltaWins[$tid];
         $tDraws += $tdeltaDraws[$tid];
         $tLosses += $tdeltaLosses[$tid];
         $tScore += $tdeltaScore[$tid];
         $tOppScore += $tdeltaOppScore[$tid];
         $tPoints += $tdeltaPoints[$tid];
         $tForfeits += $tdeltaForfeits[$tid];
         $output .= "Team: {$tid}<br />";
         $output .= "delta ELO: {$tdeltaELO[$tid]}<br />";
         $output .= "delta TS mu: {$tdeltaTS_mu[$tid]}<br />";
         $output .= "delta TS sigma: {$tdeltaTS_sigma[$tid]}<br />";
         $output .= "delta G2 mu: {$tdeltaG2_mu[$tid]}<br />";
         $output .= "delta G2 phi: {$tdeltaG2_phi[$tid]}<br />";
         $output .= "delta G2 sigma: {$tdeltaG2_sigma[$tid]}<br />";
         $output .= "Games played: {$tdeltaGamesPlayed[$tid]}<br />";
         $output .= "Match id: " . $this->fields['MatchID'] . "<br />";
         $q_update = "UPDATE " . TBL_TEAMS . " SET ELORanking = '" . floatToSQL($tELO) . "'," . "     TS_mu = '" . floatToSQL($tTS_mu) . "'," . "     TS_sigma = '" . floatToSQL($tTS_sigma) . "'," . "     G2_r = '" . floatToSQL($tG2_r) . "'," . "     G2_RD = '" . floatToSQL($tG2_RD) . "'," . "     G2_sigma = '" . floatToSQL($tG2_sigma) . "'," . "     GamesPlayed = {$tGamesPlayed}," . "     Loss = {$tLosses}," . "     Win = {$tWins}," . "     Draw = {$tDraws}," . "     Score = {$tScore}," . "     ScoreAgainst = {$tOppScore}," . "     Points = {$tPoints}," . "     Forfeits = {$tForfeits}," . "     RankDelta = 0" . " WHERE (TeamID = '{$tid}')";
         $result_update = $sql->db_Query($q_update);
     }
     $q = "UPDATE " . TBL_MATCHS . " SET Status = 'active' WHERE (MatchID = '" . $this->fields['MatchID'] . "')";
     $result = $sql->db_Query($q);
     //echo "$output";
     //exit;
 }
Ejemplo n.º 3
0
$numMods = mysql_numrows($result);
$text .= '<td class="eb_td eb_tdc1">' . EB_EVENT_L41 . '</td>';
$text .= '<td class="eb_td">';
if ($numMods > 0) {
    $text .= '<ul>';
    for ($i = 0; $i < $numMods; $i++) {
        $modid = mysql_result($result, $i, TBL_USERS . ".user_id");
        $modname = mysql_result($result, $i, TBL_USERS . ".user_name");
        $text .= '<li><a href="' . e_PLUGIN . 'ebattles/userinfo.php?user='******'">' . $modname . '</a></li>';
    }
    $text .= '</ul>';
}
$text .= '</td></tr>';
$text .= '<tr><td class="eb_td eb_tdc1">' . EB_EVENT_L82 . '</td><td class="eb_td">' . $event->eventStatusToString() . '</td></tr>';
// Gold
if (is_gold_system_active()) {
    if ($event->getField('GoldEntryFee') > 0) {
        $text .= '<tr><td class="eb_td eb_tdc1">' . EB_EVENT_L96 . '</td><td class="eb_td">' . $gold_obj->formation($event->getField('GoldEntryFee')) . '</td></tr>';
    }
    if ($event->getField('GoldWinningEvent') > 0) {
        $text .= '<tr><td class="eb_td eb_tdc1">' . EB_EVENT_L97 . '</td><td class="eb_td">' . $gold_obj->formation($event->getField('GoldWinningEvent')) . '</td></tr>';
    }
}
$time_comment = $event->eventStatusToTimeComment();
$text .= '<tr><td class="eb_td eb_tdc1">' . EB_EVENT_L42 . '</td><td class="eb_td">' . $date_start . '</td></tr>';
$text .= '<tr><td class="eb_td eb_tdc1"></td><td class="eb_td">' . $time_comment . '</td></tr>';
$text .= '<tr><td class="eb_td eb_tdc1">' . EB_EVENTM_L36 . '</td><td class="eb_td">' . $tp->toHTML($event->getField('Description'), true) . '</td></tr>';
$text .= '<tr><td class="eb_td eb_tdc1">' . EB_EVENT_L44 . '</td><td class="eb_td">' . $tp->toHTML($event->getField('Rules'), true) . '</td></tr>';
$text .= '</tbody></table>';
$text .= '</div>';
// tabs-1 "Info"
Ejemplo n.º 4
0
     if ($nbr_players_rank_3 == 1) {
         $pid = mysql_result($result, 0, TBL_PLAYERS . ".PlayerID");
         $q_Awards = "INSERT INTO " . TBL_AWARDS . "(Player,Type,timestamp)\r\n\t\t\tVALUES ({$pid},'PlayerRankThird',{$time})";
         $result_Awards = $sql->db_Query($q_Awards);
     }
 }
 if ($type == "Clan Ladder" || $type == "Team Ladder") {
     $q = "SELECT " . TBL_TEAMS . ".*" . " FROM " . TBL_TEAMS . " WHERE (" . TBL_TEAMS . ".Event = '{$event_id}')" . "AND (" . TBL_TEAMS . ".Rank = '1')";
     $result = $sql->db_Query($q);
     $nbr_teams_rank_1 = mysql_numrows($result);
     if ($nbr_teams_rank_1 == 1) {
         $pid = mysql_result($result, 0, TBL_TEAMS . ".TeamID");
         $q_Awards = "INSERT INTO " . TBL_AWARDS . "(Team,Type,timestamp)\r\n\t\t\tVALUES ({$pid},'TeamRankFirst',{$time}+2)";
         $result_Awards = $sql->db_Query($q_Awards);
         // gold
         if (is_gold_system_active() && $event->getField('GoldWinningEvent') > 0) {
             // find team captain
             $q = "SELECT " . TBL_TEAMS . ".*, " . TBL_DIVISIONS . ".*" . " FROM " . TBL_TEAMS . ", " . TBL_DIVISIONS . " WHERE (" . TBL_TEAMS . ".TeamID = '{$pid}')" . "   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'] = $event->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=" . $uid;
             $gold_param['gold_forum'] = 0;
             $gold_obj->gold_modify($gold_param);
         }
     }
Ejemplo n.º 5
0
            header("Location: eventinfo.php?eventid={$event_id}");
        }
    } else {
        $error_str = EB_EVENT_L100;
    }
}
if (isset($_POST['teamjoinevent'])) {
    if ($event->getField('password') == "" || $_POST['joinEventPassword'] == $event->getField('password')) {
        $div_id = $_POST['division'];
        // Check gold here.
        if (is_gold_system_active() && $gold_obj->gold_balance(USERID) < $event->getField('GoldEntryFee')) {
            $error_str .= EB_EVENT_L98 . " {$GOLD_PREF['gold_currency_name']}" . "</br>";
            $error_str .= EB_EVENT_L99 . $gold_obj->formation($gold_obj->gold_balance(USERID)) . "</br>";
        } else {
            $event->eventAddDivision($div_id, FALSE);
            if (is_gold_system_active() && $event->getField('GoldEntryFee') > 0) {
                $gold_param['gold_user_id'] = USERID;
                $gold_param['gold_who_id'] = 0;
                $gold_param['gold_amount'] = $event->getField('GoldEntryFee');
                $gold_param['gold_type'] = EB_L1;
                $gold_param['gold_action'] = "debit";
                $gold_param['gold_plugin'] = "ebattles";
                $gold_param['gold_log'] = EB_GOLD_L7 . ": event=" . $event_id . ", div=" . $div_id;
                $gold_param['gold_forum'] = 0;
                $gold_obj->gold_modify($gold_param);
            }
            header("Location: eventinfo.php?eventid={$event_id}");
        }
    } else {
        $error_str = EB_EVENT_L100;
    }