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 edit()
 {
     Controller::requirePermissions(["AdminAccessDashboard", "AdminUsers"]);
     if (empty($_POST)) {
         View::load("acp/user_edit.twig", ["object" => current(UserModel::get($_GET["id"])), "groups" => UserGroup::get(), "organizations" => Organization::get()]);
     } else {
         UserModel::update($_POST["id"], $_POST["email"], $_POST["full-name"], $_POST["phone-number"], $_POST["password"], $_POST["group"], $_POST["organization"]);
     }
     Controller::addAlert(new Alert("success", "User updated successfully"));
     Controller::redirect("/acp/user");
 }
 public static function register()
 {
     Controller::requirePermissions(["RegisterTeamsForOwnOrganization", "RegisterTeamsForAnyOrganization"], "any");
     if (empty($_POST)) {
         $teams = User::getVisitor()->organizationId ? TeamModel::get(null, User::getVisitor()->organizationId) : null;
         View::load("team/register_form.twig", ["organizations" => Organization::get(), "designations" => TeamModel::getValidDesignations(), "leagues" => League::get(), "teams" => $teams]);
     } else {
         // add the team
         if (User::getVisitor()->checkPermissions(["RegisterTeamsForAnyOrganization"])) {
             $organizationId = $_POST["organization-id"];
         } else {
             $organizationId = User::getVisitor()->organizationId;
         }
         try {
             if (ALLOW_TEAM_REGISTRANTS_TO_SELECT_LEAGUE) {
                 $teamId = TeamModel::add($organizationId, $_POST["designation"], User::getVisitor()->id, $_POST["league-id"]);
             } else {
                 $teamId = TeamModel::add($organizationId, $_POST["designation"], User::getVisitor()->id);
             }
         } catch (DuplicateException $e) {
             Controller::addAlert(new Alert("danger", "You cannot register more than one team with the same name. " . "To edit an existing team please use the edit button beside the team in the Registered Teams box."));
             Controller::redirect("/team/register");
         }
         // add the players
         $exemptsAdded = 0;
         for ($i = 1; array_key_exists("player" . $i, $_POST); $i++) {
             if ($_POST["player" . $i]) {
                 if (isset($_POST["player" . $i . "e"])) {
                     if ($exemptsAdded < MAX_EXEMPTS) {
                         $makeExempt = true;
                         $exemptsAdded++;
                     } else {
                         $makeExempt = false;
                         Controller::addAlert(new Alert("warning", "You attempted to star " . $_POST["player" . $i] . " but you had already starred " . MAX_EXEMPTS . " other players, which is the maxmimum allowed, thus " . $_POST["player" . $i] . "was not starred"));
                     }
                 } else {
                     $makeExempt = false;
                 }
                 try {
                     Player::add($_POST["player" . $i], $teamId, $makeExempt);
                 } catch (DuplicateException $e) {
                     Controller::addAlert(new Alert("info", "You entered the name " . $_POST["player" . $i] . " more than once, only the first entry was" . "added to the database"));
                 }
             }
         }
         Controller::addAlert(new Alert("success", "You have successfully registered your team and its details are shown below. You can come back to this area up until the freeze date and make changes."));
         Controller::redirect("/team/edit?id=" . $teamId);
     }
 }
 public static function delete()
 {
     Controller::requirePermissions(["AdminAccessDashboard", "AdminOrganizations", "PerformDeletionOperations"]);
     if (!array_key_exists("id", $_GET)) {
         Controller::redirect("/acp/organization");
     }
     $orgs = OrganizationModel::get($_GET["id"]);
     if (!empty($orgs)) {
         current($orgs)->delete();
         Controller::addAlert(new Alert("success", "Organization deleted successfully"));
     } else {
         Controller::addAlert(new Alert("danger", "The organization you attempted to delete does not exist"));
     }
     Controller::redirect("/acp/organization");
 }