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); } }