mirror of
https://gitlab.com/animath/si/plateforme.git
synced 2024-11-27 00:07:11 +00:00
92 lines
2.6 KiB
PHP
92 lines
2.6 KiB
PHP
<?php
|
|
|
|
if (isset($_POST["leave_team"])) {
|
|
quitTeam();
|
|
exit();
|
|
}
|
|
|
|
$tournaments = Tournament::getAllTournaments(false, true);
|
|
|
|
$has_error = false;
|
|
$error_message = null;
|
|
|
|
if (isset($_POST["team_edit"])) {
|
|
$my_team = new MyTeam($_POST);
|
|
try {
|
|
$my_team->makeVerifications();
|
|
$my_team->updateTeam();
|
|
}
|
|
catch (AssertionError $e) {
|
|
$has_error = true;
|
|
$error_message = $e->getMessage();
|
|
}
|
|
}
|
|
|
|
if (isset($_POST["request_validation"])) {
|
|
if (!canValidate($team, $tournament))
|
|
$error_message = "Votre équipe ne peut pas demander la validation : il manque soit des participants, soit des documents.";
|
|
else
|
|
$_SESSION["team"]->setValidationStatus(ValidationStatus::WAITING);
|
|
}
|
|
|
|
if (isset($_SESSION["user_id"]) && isset($_SESSION["team"]) && $_SESSION["team"] !== null) {
|
|
/**
|
|
* @var User $user
|
|
* @var Team $team
|
|
*/
|
|
$user = $_SESSION["user"];
|
|
$team = $_SESSION["team"];
|
|
|
|
$tournament = Tournament::fromId($team->getTournamentId());
|
|
$documents = $user->getAllDocuments($team->getTournamentId());
|
|
if ($team->isSelectedForFinal())
|
|
$documents_final = $user->getAllDocuments($FINAL->getId());
|
|
}
|
|
else
|
|
require_once "server_files/403.php";
|
|
|
|
class MyTeam
|
|
{
|
|
public $name;
|
|
public $trigram;
|
|
public $tournament_id;
|
|
private $team;
|
|
private $tournament;
|
|
|
|
public function __construct($data)
|
|
{
|
|
foreach ($data as $key => $value)
|
|
$this->$key = htmlspecialchars($value);
|
|
|
|
$this->trigram = strtoupper($this->trigram);
|
|
$this->team = $_SESSION["team"];
|
|
$this->tournament = Tournament::fromId($this->tournament_id);
|
|
}
|
|
|
|
public function makeVerifications()
|
|
{
|
|
ensure($this->name != "" && $this->name != null, "Veuillez spécifier un nom d'équipe.");
|
|
ensure($this->name == $this->team->getName() || !teamExists($this->name), "Une équipe existe déjà avec ce nom.");
|
|
ensure(preg_match("#^[A-Z]{3}$#", $this->trigram), "Le trigramme n'est pas valide.");
|
|
ensure($this->trigram == $this->team->getTrigram() || !trigramExists($this->trigram), "Une équipe a déjà choisi ce trigramme.");
|
|
ensure($this->tournament != null, "Le tournoi indiqué n'existe pas.");
|
|
ensure(date("Y-m-d H:i:s") <= $this->tournament->getInscriptionDate(), "Les inscriptions sont terminées.");
|
|
ensure($this->team->getValidationStatus() == ValidationStatus::NOT_READY, "Votre équipe est déjà validée ou en cours de validation.");
|
|
}
|
|
|
|
public function updateTeam()
|
|
{
|
|
global $URL_BASE;
|
|
|
|
$this->team->setName($this->name);
|
|
$this->team->setTrigram($this->trigram);
|
|
$this->team->setTournamentId($this->tournament_id);
|
|
|
|
$_SESSION["tournament"] = $this->tournament;
|
|
|
|
header("Location: $URL_BASE/mon-equipe");
|
|
}
|
|
}
|
|
|
|
require_once "server_files/views/mon_equipe.php";
|