58 lines
2.1 KiB
PHP
58 lines
2.1 KiB
PHP
<?php
|
|
|
|
require_once "../config.php";
|
|
|
|
if (isset($_SESSION["team"]) || !isset($_SESSION["user"]) || ($_SESSION["role"] != Role::PARTICIPANT && $_SESSION["role"] != Role::ENCADRANT))
|
|
require_once "../403.php";
|
|
|
|
if (isset($_POST["submitted"])) {
|
|
$error_message = joinTeam();
|
|
}
|
|
|
|
function joinTeam() {
|
|
global $YEAR, $MAIL_ADDRESS, $access_code;
|
|
|
|
$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.";
|
|
|
|
/** @var User $user */
|
|
$user = $_SESSION["user"];
|
|
$team = Team::fromAccessCode($access_code);
|
|
if ($team === null)
|
|
return "Ce code d'accès est invalide.";
|
|
|
|
if ($team->getValidationStatus() != ValidationStatus::NOT_READY)
|
|
return "Cette équipe est déjà en cours de validation ou validée, vous ne pouvez pas la rejoindre.";
|
|
|
|
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)
|
|
break;
|
|
}
|
|
|
|
if ($_SESSION["role"] == Role::PARTICIPANT && $i == 7 || $_SESSION["role"] == Role::ENCADRANT && $i == 3)
|
|
return "Il n'y a plus de place pour vous dans l'équipe.";
|
|
|
|
$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());
|
|
|
|
$msg = "Bonjour " . $user->getFirstName() . " " . $user->getSurname() . ",\r\n\r\n";
|
|
$msg .= "Vous venez de rejoindre l'équipe « " . $team->getName() . " » (" . $team->getTrigram() . ") pour le TFJM² de " . $tournament->getId() . " et nous vous en remercions.\r\n\r\n";
|
|
$msg .= "Cordialement,\r\n\r\nL'organisation du TFJM² $YEAR";
|
|
mail($_SESSION["email"], "Équipe rejointe TFJM² $YEAR", $msg, "From: $MAIL_ADDRESS\r\n");
|
|
|
|
return false;
|
|
}
|
|
|
|
require_once "../views/header.php";
|
|
require_once "../views/rejoindre_equipe.php";
|
|
require_once "../views/footer.php";
|