2019-09-05 17:07:41 +00:00
|
|
|
<?php
|
|
|
|
|
2019-09-06 23:33:05 +00:00
|
|
|
if (isset($_SESSION["team"]) || !isset($_SESSION["user"]) || ($_SESSION["role"] != Role::PARTICIPANT && $_SESSION["role"] != Role::ENCADRANT))
|
2019-09-07 11:42:36 +00:00
|
|
|
require_once "server_files/403.php";
|
2019-09-06 23:33:05 +00:00
|
|
|
|
2019-09-05 17:07:41 +00:00
|
|
|
if (isset($_POST["submitted"])) {
|
|
|
|
$error_message = joinTeam();
|
|
|
|
}
|
|
|
|
|
|
|
|
function joinTeam() {
|
2019-09-08 10:45:48 +00:00
|
|
|
global $access_code;
|
2019-09-05 17:07:41 +00:00
|
|
|
|
|
|
|
$access_code = htmlspecialchars($_POST["access_code"]);
|
|
|
|
|
|
|
|
if (!isset($access_code) || strlen($access_code) != 6)
|
|
|
|
return "Le code d'accès doit comporter 6 caractères.";
|
2019-09-06 23:33:05 +00:00
|
|
|
|
|
|
|
/** @var User $user */
|
|
|
|
$user = $_SESSION["user"];
|
|
|
|
$team = Team::fromAccessCode($access_code);
|
|
|
|
if ($team === null)
|
2019-09-05 17:07:41 +00:00
|
|
|
return "Ce code d'accès est invalide.";
|
|
|
|
|
2019-09-06 23:33:05 +00:00
|
|
|
if ($team->getValidationStatus() != ValidationStatus::NOT_READY)
|
2019-09-05 17:07:41 +00:00
|
|
|
return "Cette équipe est déjà en cours de validation ou validée, vous ne pouvez pas la rejoindre.";
|
|
|
|
|
2019-09-06 23:33:05 +00:00
|
|
|
for ($i = 1; $i <= $_SESSION["role"] == Role::PARTICIPANT ? 6 : 2; ++$i) {
|
|
|
|
if (($_SESSION["role"] == Role::PARTICIPANT ? $team->getParticipants()[$i - 1] : $team->getEncadrants()[$i - 1]) == NULL)
|
2019-09-05 17:07:41 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-09-06 23:33:05 +00:00
|
|
|
if ($_SESSION["role"] == Role::PARTICIPANT && $i == 7 || $_SESSION["role"] == Role::ENCADRANT && $i == 3)
|
2019-09-05 17:07:41 +00:00
|
|
|
return "Il n'y a plus de place pour vous dans l'équipe.";
|
|
|
|
|
2019-09-06 23:33:05 +00:00
|
|
|
$user->setTeamId($team->getId());
|
|
|
|
|
|
|
|
if ($_SESSION["role"] == Role::ENCADRANT)
|
|
|
|
$team->setEncadrant($i, $user->getId());
|
|
|
|
else
|
|
|
|
$team->setParticipant($i, $user->getId());
|
|
|
|
|
|
|
|
$_SESSION["team"] = $team;
|
|
|
|
$tournament = $_SESSION["tournament"] = Tournament::fromId($team->getTournamentId());
|
2019-09-05 17:07:41 +00:00
|
|
|
|
2019-09-08 10:45:48 +00:00
|
|
|
Mailer::sendJoinTeamMail($user, $team, $tournament);
|
2019-09-05 17:07:41 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-09-07 11:42:36 +00:00
|
|
|
require_once "server_files/views/rejoindre_equipe.php";
|