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 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 login()
 {
     if (UserModel::getVisitor()->id != 0) {
         Controller::redirect(array_key_exists("r", $_GET) ? urlencode($_GET["r"]) : "");
     }
     if (empty($_POST)) {
         View::load("user/login.twig", ["redirectTo" => array_key_exists("r", $_GET) ? urlencode($_GET["r"]) : ""]);
     } else {
         if (isset($_POST["register"]) && $_POST["register"]) {
             Controller::redirect(ForumsFactory::getForumsInstance()->getRegistrationPage(isset($_POST["email"]) ? $_POST["email"] : null), true);
         }
         try {
             UserModel::attemptLogin($_POST["email"], $_POST["password"], isset($_POST["remember-me"]));
             Controller::addAlert(new Alert("success", "You have been logged in successfully"));
             Controller::redirect(array_key_exists("r", $_GET) ? $_GET["r"] : "");
         } catch (Exception $e) {
             Controller::addAlert(new Alert("danger", "The login credentials you entered were incorrect, please try again"));
             Controller::redirect("/user/login");
         }
     }
 }
 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");
 }
 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 submit()
 {
     Controller::requirePermissions(["SubmitMatchReports"]);
     if (empty($_POST)) {
         View::load("match/submit.twig", ["leagues" => League::get(), "players" => Player::get()]);
     } else {
         // basic input validation
         Controller::requireFields("post", ["date", "league", "reporter-team", "reporter-score", "opposing-team", "opposing-score"], "/match/submit");
         $datetime = DateTime::createFromFormat("Y-m-d", $_POST["date"]);
         $epoch = $datetime->getTimestamp();
         if ($datetime === false || array_sum($datetime->getLastErrors()) || $epoch > time() || time() - $epoch > 3600 * 24 * 365) {
             Controller::addAlert(new Alert("danger", "You did not enter a valid date, please try again."));
             Controller::redirect("/match/submit");
         }
         // check authorization of user to file reports on behalf of reporting team
         $reporterTeam = current(Team::get($_POST["reporter-team"]));
         $visitor = User::getVisitor();
         if ($visitor->organizationId != $reporterTeam->organizationId) {
             Controller::requirePermissions(["SubmitMatchReportsForAnyTeam"]);
         }
         // start determining the data for insertion
         if ($_POST["location"] == "home") {
             // reporting team is home
             $homeTeamId = $_POST["reporter-team"];
             $homeScore = $_POST["reporter-score"];
             $awayTeamId = $_POST["opposing-team"];
             $awayScore = $_POST["opposing-score"];
         } else {
             $awayTeamId = $_POST["reporter-team"];
             $awayScore = $_POST["reporter-score"];
             $homeTeamId = $_POST["opposing-team"];
             $homeScore = $_POST["opposing-score"];
         }
         // transaction
         Database::getConnection()->beginTransaction();
         // attempt to pull an existing match record or add a new one
         $match = current(MatchModel::get(null, $_POST["date"], $_POST["league"], $homeTeamId, $awayTeamId));
         if ($match) {
             $matchId = $match->id;
         } else {
             $matchId = MatchModel::add($_POST["date"], $_POST["league"], $homeTeamId, $awayTeamId);
         }
         try {
             MatchReport::add($matchId, $_POST["reporter-team"], $visitor->id, $homeScore, $awayScore);
         } catch (DuplicateException $e) {
             Database::getConnection()->rollBack();
             Controller::addAlert(new Alert("danger", "You have already submitted a report for that match!"));
             Controller::redirect("/match/submit");
         }
         if (!$match) {
             $match = current(MatchModel::get($matchId));
         }
         $players = $reporterTeam->getPlayers();
         foreach ($players as $player) {
             if (array_key_exists("player" . $player->id, $_POST)) {
                 $match->addParticipatingPlayer($reporterTeam->id, $player->id);
             }
         }
         for ($i = 1; $i <= 8; $i++) {
             if (array_key_exists("additional-player" . $i, $_POST) && $_POST["additional-player" . $i]) {
                 $match->addParticipatingPlayer($reporterTeam->id, null, $_POST["additional-player" . $i]);
             }
         }
         // commit
         Database::getConnection()->commit();
         // attempt reconciliation
         $matches = MatchModel::get($matchId);
         current($matches)->attemptReportReconciliation();
         Controller::addAlert(new Alert("success", "Match report submitted successfully!"));
         Controller::redirect("/match/record?id=" . $matchId);
     }
 }