public static function index()
 {
     Controller::requirePermissions(["AdminAccessDashboard"]);
     if (!empty($_POST)) {
         Setting::set("info_box_content", $_POST["info"]);
     }
     View::load("acp/index.twig", ["organizationCount" => count(Organization::get()), "teamCount" => count(Team::get()), "unassignedTeams" => Team::get(null, null, null, false, false), "info" => Setting::get("info_box_content"), "mismatches" => Match::get(null, null, null, null, null, Match::STATUS_MISMATCH)]);
 }
 public static function delete()
 {
     Controller::requireFields("get", ["id"], "/acp/team");
     Controller::requirePermissions(["AdminAccessDashboard", "AdminTeams", "AdminPlayers", "PerformDeletionOperations"]);
     $team = current(TeamModel::get($_GET["id"]));
     $team->delete();
     Controller::addAlert(new Alert("success", "Team deleted successfully"));
     Controller::redirect("/acp/team");
 }
 public static function logout()
 {
     if (array_key_exists("target", $_GET) && $_GET["target"] == "all") {
         UserModel::logoutAll();
     } else {
         UserModel::logout();
     }
     Controller::redirect("");
 }
 public static function delete()
 {
     Controller::requirePermissions(["AdminAccessDashboard", "AdminUsers", "PerformDeletionOperations"]);
     if (!array_key_exists("id", $_GET)) {
         Controller::redirect("/acp/user");
     }
     $users = UserModel::get($_GET["id"]);
     if (!empty($users)) {
         current($users)->delete();
         Controller::addAlert(new Alert("success", "User deleted successfully"));
     } else {
         Controller::addAlert(new Alert("danger", "The user you attempted to delete does not exist"));
     }
     Controller::redirect("/acp/user");
 }
 public static function delete()
 {
     Controller::requirePermissions(["AdminAccessDashboard"]);
     $fixture = current(FixtureModel::get($_GET["id"]));
     if (!$fixture) {
         Controller::addAlert(new Alert("success", "The specified fixture does not exist"));
         Controller::redirect("/acp/league");
     }
     $league = $fixture->getLeague();
     // check permissions
     $visitor = UserModel::getVisitor();
     if ($visitor->id != $league->managerId) {
         Controller::requirePermissions(["AdminAllLeagues"]);
     }
     $fixture->delete();
     Controller::addAlert(new Alert("success", "Fixture deleted successfully"));
     Controller::redirect("/acp/league/manage?id=" . $league->id);
 }
 public static function delete()
 {
     Controller::requirePermissions(["AdminAccessDashboard"]);
     if (!array_key_exists("id", $_GET)) {
         Controller::redirect("/acp/league");
     }
     $section = current(LeagueSectionModel::get($_GET["id"]));
     // check permissions
     $visitor = User::getVisitor();
     if ($visitor->id != $section->getLeague()->managerId) {
         Controller::requirePermissions(["AdminAllLeagues"]);
     }
     try {
         $section->delete();
         Controller::addAlert(new Alert("success", "League section deleted successfully"));
     } catch (ObjectCannotBeDeletedException $e) {
         Controller::addAlert(new Alert("danger", "You cannot delete a section which has teams assigned to it. Please reassign the teams to an alternative section first"));
     }
     Controller::redirect("/acp/league/manage?id=" . $section->getLeague()->id);
 }
 public static function delete()
 {
     Controller::requirePermissions(["AdminAccessDashboard", "AdminUserGroups", "PerformDeletionOperations"]);
     if (!array_key_exists("id", $_GET)) {
         Controller::redirect("/acp/group");
     }
     $group = current(UserGroupModel::get($_GET["id"]));
     if (!$group) {
         Controller::addAlert(new Alert("danger", "The specified group does not exist"));
     } else {
         if ($group->special) {
             Controller::addAlert(new Alert("danger", "The specified group is a special group and cannot be deleted as it would break core functionality"));
         } else {
             if (($count = count($group->getUsers())) > 0) {
                 Controller::addAlert(new Alert("danger", "There are " . $count . " users currently in " . "the specified group, you must assign them to a different group before you can delete this group"));
             } else {
                 $group->delete();
                 Controller::addAlert(new Alert("success", "User group deleted successfully"));
             }
         }
     }
     Controller::redirect("/acp/group");
 }
require_once __DIR__ . "/config.php";
if (!defined("ORGANIZATION_WORD")) {
    define("ORGANIZATION_WORD", "organization");
}
require_once __DIR__ . "/app/Autoloader.php";
require_once __DIR__ . "/vendor/autoload.php";
use sma\Autoloader;
use sma\Router;
use sma\Controller;
use sma\Installer;
date_default_timezone_set(TIMEZONE);
ini_set("display_errors", DISPLAY_ERRORS ? "On" : "Off");
error_reporting(E_ALL);
if (!array_key_exists("PATH_INFO", $_SERVER)) {
    $_SERVER["PATH_INFO"] = "";
}
Autoloader::setup();
Twig_Autoloader::register();
Controller::loadAlertsFromCookie();
$dbStatus = Installer::getDatabaseStatus();
if (strpos($_SERVER["PATH_INFO"], "install") === false) {
    if ($dbStatus == Installer::DATABASE_STATUS_NOT_INSTALLED) {
        Controller::redirect("/install/install");
    } else {
        if ($dbStatus == Installer::DATABASE_STATUS_NOT_UP_TO_DATE) {
            Controller::redirect("/install/upgrade");
        }
    }
}
Router::setRoutes(["/install/install" => ["Installer", "install"], "/install/upgrade" => ["Installer", "upgrade"], "/install" => ["Installer", "index"], "/download/trigger" => ["Download", "trigger"], "/league" => ["League", "index"], "/user/login" => ["User", "login"], "/user/logout" => ["User", "logout"], "/user" => ["User", "index"], "/team/register" => ["Team", "register"], "/team/edit" => ["Team", "edit"], "/team/addplayer" => ["Team", "addplayer"], "/team/updateplayer" => ["Team", "updateplayer"], "/match/submitted" => ["Match", "submitted"], "/match/submit" => ["Match", "submit"], "/match/record" => ["Match", "record"], "/ajax/teams" => ["Ajax", "teams"], "/ajax/players" => ["Ajax", "players"], "/acp/match/manage" => ["acp\\Match", "manage"], "/acp/match/delete" => ["acp\\Match", "delete"], "/acp/match/correct" => ["acp\\Match", "correct"], "/acp/match/alter" => ["acp\\Match", "alter"], "/acp/match" => ["acp\\Match", "index"], "/acp/organization/add" => ["acp\\Organization", "add"], "/acp/organization/edit" => ["acp\\Organization", "edit"], "/acp/organization/delete" => ["acp\\Organization", "delete"], "/acp/organization" => ["acp\\Organization", "index"], "/acp/user/add" => ["acp\\User", "add"], "/acp/user/edit" => ["acp\\User", "edit"], "/acp/user/delete" => ["acp\\User", "delete"], "/acp/user" => ["acp\\User", "index"], "/acp/group/add" => ["acp\\UserGroup", "add"], "/acp/group/manage" => ["acp\\UserGroup", "manage"], "/acp/group/delete" => ["acp\\UserGroup", "delete"], "/acp/group" => ["acp\\UserGroup", "index"], "/acp/league/add" => ["acp\\League", "add"], "/acp/league/manage" => ["acp\\League", "manage"], "/acp/league/delete" => ["acp\\League", "delete"], "/acp/league" => ["acp\\League", "index"], "/acp/section/add" => ["acp\\LeagueSection", "add"], "/acp/section/delete" => ["acp\\LeagueSection", "delete"], "/acp/team/assign" => ["acp\\Team", "assign"], "/acp/team/manage" => ["acp\\Team", "manage"], "/acp/team/delete" => ["acp\\Team", "delete"], "/acp/team" => ["acp\\Team", "index"], "/acp/player/add" => ["acp\\Player", "add"], "/acp/player/delete" => ["acp\\Player", "delete"], "/acp/player/update" => ["acp\\Player", "update"], "/acp/player/exempt" => ["acp\\Player", "exempt"], "/acp/fixture/add" => ["acp\\Fixture", "add"], "/acp/fixture/delete" => ["acp\\Fixture", "delete"], "/acp" => ["acp\\Dashboard", "index"], "" => ["Index", "index"]]);
Router::route();
 /**
  * Register global variables
  *
  * @param Twig_Environment $twig twig environment
  * @return Twig_Environment twig environment
  */
 private static function registerGlobalVariables($twig)
 {
     $twig->addGlobal("base_url", BASE_URL);
     $twig->addGlobal("base_links_url", BASE_LINKS_URL);
     $twig->addGlobal("base_view_url", BASE_VIEW_URL);
     $twig->addGlobal("base_assets_url", BASE_ASSETS_URL);
     $twig->addGlobal("site_name", SITE_NAME);
     $twig->addGlobal("show_request_times", SHOW_REQUEST_TIMES);
     $alerts = Controller::getAlerts();
     if (!empty($alerts)) {
         $twig->addGlobal("alerts", $alerts);
     }
     if (Installer::getDatabaseStatus() == Installer::DATABASE_STATUS_INSTALLED) {
         $twig->addGlobal("visitor", User::getVisitor());
     }
     return $twig;
 }
 public static function updateplayer()
 {
     Controller::requireFields("get", ["id"], "/acp/team");
     $player = current(Player::get($_GET["id"]));
     if (!User::getVisitor()->checkPermissions(["RegisterTeamsForAnyOrganization"])) {
         Controller::requirePermissions(["RegisterTeamsForOwnOrganization"]);
         if ($player->getTeam()->organizationId != User::getVisitor()->organizationId) {
             ErrorHandler::forbidden();
         }
     }
     if ($_GET["exempt"] == 1 && !$player->exempt) {
         if ($player->getTeam()->getNumberOfExemptPlayers() >= MAX_EXEMPTS) {
             Controller::addAlert(new Alert("danger", "You have already starred the maximum number of players"));
             Controller::redirect("/team/edit?id=" . $player->getTeam()->id);
         }
     }
     Player::update($player->id, null, (bool) $_GET["exempt"]);
     Controller::addAlert(new Alert("success", "Player updated successfully"));
     Controller::redirect("/team/edit?id=" . $player->getTeam()->id);
 }
 public static function alter()
 {
     Controller::requirePermissions(["AdminAccessDashboard", "AdminMatches"]);
     $id = $_POST["id"];
     $match = current(MatchModel::get($_POST["id"]));
     if (array_key_exists("date", $_POST)) {
         try {
             $id = $match->correctDate($match->id, $_POST["date"]);
             Controller::addAlert(new Alert("success", "Correction completed"));
         } catch (DuplicateException $e) {
             Controller::addAlert(new Alert("danger", "The report cannot be moved to the specified date as there is already another report filed for the team for the match on that date"));
         }
     } else {
         if (array_key_exists("home_team_id", $_POST)) {
             try {
                 $homeTeamId = $_POST["home_team_id"] != 0 ? $_POST["home_team_id"] : null;
                 $awayTeamId = $_POST["away_team_id"] != 0 ? $_POST["away_team_id"] : null;
                 $id = $match->correctTeams($match->id, $homeTeamId, $awayTeamId);
                 Controller::addAlert(new Alert("success", "Correction completed"));
             } catch (DuplicateException $e) {
                 Controller::addAlert(new Alert("danger", "The report cannot be updated with those team(s) as there is already another report filed for the team for the match on that date"));
             }
         }
     }
     Controller::redirect("/acp/match/manage?id=" . $id);
 }
 public static function index()
 {
     Controller::redirect("/install/install");
 }
 public static function submitted()
 {
     Controller::requirePermissions(["SubmitMatchReports"]);
     $visitor = User::getVisitor();
     $teams = Team::get(null, $visitor->organizationId);
     $teamIds = [];
     foreach ($teams as $team) {
         $teamIds[] = $team->id;
     }
     $reports = MatchReport::get(null, null, null, $teamIds, 25);
     View::load("match/submitted.twig", ["organizationReports" => $reports, "userReports" => MatchReport::get(null, null, $visitor->id, null, 25)]);
 }