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 = ' '; $score_1_str = ' '; 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.'&matchid='.$match_id.'&actionid=matchschedulededit&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.'&matchid='.$match_id.'&actionid=matchedit&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 . '&matchid=' . $match_id . '&actionid=matchscheduledreport&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); }
/** * displayUserInfo - Displays user information */ function displayUserInfo($req_user, $profile_link) { global $pref; global $sql; $text = '<tr><td>'; if ($pref['eb_links_showmatchsplayed'] == 1) { /* Display Active Matches */ $q = "SELECT count(*) " . " FROM " . TBL_MATCHS . ", " . TBL_SCORES . ", " . TBL_PLAYERS . ", " . TBL_GAMERS . " WHERE (" . TBL_SCORES . ".MatchID = " . TBL_MATCHS . ".MatchID)" . " AND (" . TBL_MATCHS . ".Status = 'active')" . " AND ((" . TBL_PLAYERS . ".PlayerID = " . TBL_SCORES . ".Player)" . " OR ((" . TBL_PLAYERS . ".Team = " . TBL_SCORES . ".Team)" . " AND (" . TBL_PLAYERS . ".Team != 0)))" . " AND (" . TBL_PLAYERS . ".Gamer = " . TBL_GAMERS . ".GamerID)" . " AND (" . TBL_GAMERS . ".User = '******')"; $result = $sql->db_Query($q); $numMatches = mysql_result($result, 0); if ($numMatches > 0) { $text .= $numMatches . ' ' . EB_EVENT_L59; $text .= '<br />'; } } if ($pref['eb_links_showmatchstoapprove'] == 1) { /* Display Matches which need user approval */ $matchArray = array(); // events owned $q = "SELECT DISTINCT " . TBL_MATCHS . ".*" . " FROM " . TBL_MATCHS . ", " . TBL_EVENTS . " WHERE (" . TBL_EVENTS . ".Owner = '{$req_user}')" . " AND (" . TBL_MATCHS . ".Event = " . TBL_EVENTS . ".EventID)" . " AND (" . TBL_MATCHS . ".Status = 'pending')"; $result = $sql->db_Query($q); $numMatches = mysql_numrows($result); for ($match = 0; $match < $numMatches; $match++) { // For each match played by user $matchArray[] = mysql_result($result, $match, TBL_MATCHS . ".MatchID"); } // events mod $q = "SELECT DISTINCT " . TBL_MATCHS . ".*" . " FROM " . TBL_MATCHS . ", " . TBL_EVENTMODS . " WHERE (" . TBL_EVENTMODS . ".User = '******')" . " AND (" . TBL_MATCHS . ".Event = " . TBL_EVENTMODS . ".Event)" . " AND (" . TBL_MATCHS . ".Status = 'pending')"; $result = $sql->db_Query($q); $numMatches = mysql_numrows($result); for ($match = 0; $match < $numMatches; $match++) { // For each match played by user $matchArray[] = mysql_result($result, $match, TBL_MATCHS . ".MatchID"); } // opps // Check if you can approve the match, for each of the pending match $q = "SELECT DISTINCT " . TBL_MATCHS . ".*" . " FROM " . TBL_MATCHS . ", " . TBL_SCORES . ", " . TBL_PLAYERS . ", " . TBL_GAMERS . " WHERE (" . TBL_MATCHS . ".Status = 'pending')" . " AND (" . TBL_SCORES . ".MatchID = " . TBL_MATCHS . ".MatchID)" . " AND ((" . TBL_PLAYERS . ".PlayerID = " . TBL_SCORES . ".Player)" . " OR ((" . TBL_PLAYERS . ".Team = " . TBL_SCORES . ".Team)" . " AND (" . TBL_PLAYERS . ".Team != 0)))" . " AND (" . TBL_PLAYERS . ".Gamer = " . TBL_GAMERS . ".GamerID)" . " AND (" . TBL_GAMERS . ".User = '******')" . " ORDER BY " . TBL_MATCHS . ".TimeReported DESC"; $result = $sql->db_Query($q); $numMatches = mysql_numrows($result); for ($match = 0; $match < $numMatches; $match++) { // For each match played by user $match_id = mysql_result($result, $match, TBL_MATCHS . ".MatchID"); $matchObj = new Match($match_id); $permissions = $matchObj->get_permissions(USERID); $userclass = $permissions['userclass']; $can_approve = $permissions['can_approve']; if ($can_approve == 1) { $matchArray[] = $match_id; } } $numMatches = count(array_unique($matchArray)); if ($numMatches > 0) { // $text .= '<span class="badge">'.$numMatches.'</span> '.EB_EVENT_L73; $text .= '<span style="background-color:red; color:white; font-family: Helvetica,Arial,sans-serif; font-size: 9px; line-height: 18px; font-weight: bold; padding:3px 6px; margin:1px; -moz-border-radius: 10px; -khtml-border-radius: 10px; -webkit-border-radius: 10px; border-radius: 10px;">' . $numMatches . '</span>'; $text .= '<a href="' . $profile_link . '#tabs-4">'; $text .= ' ' . EB_EVENT_L73; $text .= '</a>'; $text .= '<br />'; } } if ($pref['eb_links_showmatchspending'] == 1) { /* Display Pending Matches */ $q = "SELECT DISTINCT " . TBL_MATCHS . ".*" . " FROM " . TBL_MATCHS . ", " . TBL_SCORES . ", " . TBL_PLAYERS . ", " . TBL_GAMERS . " WHERE (" . TBL_MATCHS . ".Status = 'pending')" . " AND (" . TBL_SCORES . ".MatchID = " . TBL_MATCHS . ".MatchID)" . " AND ((" . TBL_PLAYERS . ".PlayerID = " . TBL_SCORES . ".Player)" . " OR ((" . TBL_PLAYERS . ".Team = " . TBL_SCORES . ".Team)" . " AND (" . TBL_PLAYERS . ".Team != 0)))" . " AND (" . TBL_PLAYERS . ".Gamer = " . TBL_GAMERS . ".GamerID)" . " AND (" . TBL_GAMERS . ".User = '******')" . " ORDER BY " . TBL_MATCHS . ".TimeReported DESC"; $result = $sql->db_Query($q); $numMatches = mysql_numrows($result); if ($numMatches > 0) { $text .= $numMatches . ' ' . EB_EVENT_L64; $text .= '<br />'; } } if ($pref['eb_links_showmatchesscheduled'] == 1) { /* Display Scheduled Matches */ $q = "SELECT DISTINCT " . TBL_MATCHS . ".*" . " FROM " . TBL_MATCHS . ", " . TBL_SCORES . ", " . TBL_PLAYERS . ", " . TBL_GAMERS . " WHERE (" . TBL_MATCHS . ".Status = 'scheduled')" . " AND (" . TBL_SCORES . ".MatchID = " . TBL_MATCHS . ".MatchID)" . " AND ((" . TBL_PLAYERS . ".PlayerID = " . TBL_SCORES . ".Player)" . " OR ((" . TBL_PLAYERS . ".Team = " . TBL_SCORES . ".Team)" . " AND (" . TBL_PLAYERS . ".Team != 0)))" . " AND (" . TBL_PLAYERS . ".Gamer = " . TBL_GAMERS . ".GamerID)" . " AND (" . TBL_GAMERS . ".User = '******')" . " ORDER BY " . TBL_MATCHS . ".TimeReported DESC"; $result = $sql->db_Query($q); $numMatches = mysql_numrows($result); if ($numMatches > 0) { // $text .= '<span class="badge">'.$numMatches.'</span> '.EB_EVENT_L70; $text .= '<span style="background-color:red; color:white; font-family: Helvetica,Arial,sans-serif; font-size: 9px; line-height: 18px; font-weight: bold; padding:3px 6px; margin:1px; -moz-border-radius: 10px; -khtml-border-radius: 10px; -webkit-border-radius: 10px; border-radius: 10px;">' . $numMatches . '</span>'; $text .= '<a href="' . $profile_link . '#tabs-4">'; $text .= ' ' . EB_EVENT_L70; $text .= '</a>'; $text .= '<br />'; } } if ($pref['eb_links_showchallengesrequested'] == 1) { /* Display Requested Challenges */ $q = "SELECT DISTINCT " . TBL_CHALLENGES . ".*" . " FROM " . TBL_CHALLENGES . " WHERE (" . TBL_CHALLENGES . ".Status = 'requested')" . " AND (" . TBL_CHALLENGES . ".ReportedBy = '{$req_user}')" . " ORDER BY " . TBL_CHALLENGES . ".TimeReported DESC"; $result = $sql->db_Query($q); $numChallenges = mysql_numrows($result); if ($numChallenges > 0) { $text .= $numChallenges . ' ' . EB_EVENT_L66; $text .= '<br />'; } } if ($pref['eb_links_showchallengesunconfirmed'] == 1) { /* Display Unconfirmed Challenges */ $q = "SELECT DISTINCT " . TBL_CHALLENGES . ".*" . " FROM " . TBL_CHALLENGES . ", " . TBL_PLAYERS . ", " . TBL_GAMERS . " WHERE (" . TBL_CHALLENGES . ".Status = 'requested')" . " AND ((" . TBL_PLAYERS . ".PlayerID = " . TBL_CHALLENGES . ".ChallengedPlayer)" . " OR ((" . TBL_PLAYERS . ".Team = " . TBL_CHALLENGES . ".ChallengedTeam)" . " AND (" . TBL_PLAYERS . ".Team != 0)))" . " AND (" . TBL_PLAYERS . ".Gamer = " . TBL_GAMERS . ".GamerID)" . " AND (" . TBL_GAMERS . ".User = '******')" . " ORDER BY " . TBL_CHALLENGES . ".TimeReported DESC"; $result = $sql->db_Query($q); $numChallenges = mysql_numrows($result); if ($numChallenges > 0) { // $text .= '<span class="badge">'.$numChallenges.'</span> '.EB_EVENT_L67; $text .= '<span style="background-color:red; color:white; font-family: Helvetica,Arial,sans-serif; font-size: 9px; line-height: 18px; font-weight: bold; padding:3px 6px; margin:1px; -moz-border-radius: 10px; -khtml-border-radius: 10px; -webkit-border-radius: 10px; border-radius: 10px;">' . $numChallenges . '</span>'; $text .= '<a href="' . $profile_link . '#tabs-4">'; $text .= ' ' . EB_EVENT_L67; $text .= '</a>'; } } $text .= '</td></tr>'; return $text; }
if (!isset($_POST['rank1'])) { $_POST['rank1'] = 'Team #1'; } if (!isset($_POST['rank2'])) { $_POST['rank2'] = 'Team #2'; } if (!isset($_POST['forfeit2'])) { $_POST['forfeit2'] = 1; } break; } } if ($match_id) { $match = new Match($match_id); //------------ event permissions -------------- $match_permissions = $match->get_permissions(USERID); $can_report_scheduled = $match_permissions['can_report']; $can_edit = $match_permissions['can_edit']; // If match_id is not null, fill up the form information from the database switch ($event->getMatchPlayersType()) { case 'Players': $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 = '{$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 = '{$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 (!isset($_POST['nbr_players'])) {