160 lines
5.5 KiB
PHP
160 lines
5.5 KiB
PHP
<?php
|
|
|
|
$tournament_name = htmlspecialchars($_GET["name"]);
|
|
$tournament = Tournament::fromName($tournament_name);
|
|
|
|
if ($tournament === null)
|
|
require_once "server_files/404.php";
|
|
|
|
if (isset($_GET["modifier"]) && $_SESSION["role"] != Role::ADMIN && !$tournament->organize($_SESSION["user_id"]))
|
|
require_once "server_files/403.php";
|
|
|
|
$has_error = false;
|
|
$error_message = null;
|
|
|
|
if (isset($_POST["edit_tournament"])) {
|
|
$update_tournament = new UpdateTournament($_POST);
|
|
try {
|
|
$update_tournament->makeVerifications();
|
|
$update_tournament->updateTournament();
|
|
} catch (AssertionError $e) {
|
|
$has_error = true;
|
|
$error_message = $e->getMessage();
|
|
}
|
|
}
|
|
|
|
$orgas = $tournament->getOrganizers();
|
|
$teams = $tournament->getAllTeams();
|
|
|
|
class UpdateTournament
|
|
{
|
|
public $name;
|
|
public $organizers;
|
|
public $size;
|
|
public $place;
|
|
public $price;
|
|
public $date_start;
|
|
public $date_end;
|
|
public $date_inscription;
|
|
public $time_inscription;
|
|
public $date_solutions;
|
|
public $time_solutions;
|
|
public $date_syntheses;
|
|
public $time_syntheses;
|
|
public $description;
|
|
public $final;
|
|
|
|
public function __construct($data)
|
|
{
|
|
global $tournament;
|
|
|
|
foreach ($data as $key => $value)
|
|
$this->$key = ($key == "organizers" ? $value : htmlspecialchars($value));
|
|
|
|
if ($_SESSION["role"] != Role::ADMIN) {
|
|
$this->organizers = [];
|
|
/** @var User $organizer */
|
|
foreach ($tournament->getOrganizers() as $organizer)
|
|
$this->organizers[] = $organizer->getId();
|
|
}
|
|
}
|
|
|
|
public function makeVerifications()
|
|
{
|
|
global $tournament;
|
|
|
|
ensure($this->name != null && $this->name != "", "Le nom est invalide.");
|
|
ensure($this->name == $tournament->getName() || !tournamentExists($this->name), "Un tournoi existe déjà avec ce nom.");
|
|
ensure(sizeof($this->organizers) > 0, "Aucun organisateur n'a été choisi.");
|
|
|
|
$orgas = [];
|
|
foreach ($this->organizers as $orga_id) {
|
|
$orga = User::fromId($orga_id);
|
|
ensure($orga != null, "Un organisateur spécifié n'existe pas.");
|
|
ensure($orga->getRole() == Role::ORGANIZER || $orga->getRole() == Role::ADMIN, "Une personne indiquée ne peut pas organiser de tournoi.");
|
|
$orgas[] = $orga;
|
|
}
|
|
$this->organizers = $orgas;
|
|
|
|
ensure(preg_match("#[0-9]*#", $this->size), "Le nombre d'équipes indiqué n'est pas un nombre valide.");
|
|
$this->size = intval($this->size);
|
|
ensure($this->size >= 3 && $this->size <= 15, "Un tournoi doit avoir au moins 3 et au plus 15 équipes.");
|
|
|
|
ensure(preg_match("#[0-9]*#", $this->price), "Le tarif pour les participants n'est pas un entier valide.");
|
|
$this->price = intval($this->price);
|
|
ensure($this->price >= 0, "Le TFJM² ne va pas payer les élèves pour venir.");
|
|
ensure($this->price <= 50, "Soyons raisonnable sur le prix.");
|
|
|
|
ensure(dateWellFormed($this->date_start), "La date de début n'est pas valide.");
|
|
ensure(dateWellFormed($this->date_end), "La date de fin n'est pas valide.");
|
|
ensure(dateWellFormed($this->date_inscription . " " . $this->time_inscription), "La date de clôture des inscriptions n'est pas valide.");
|
|
ensure(dateWellFormed($this->date_solutions . " " . $this->time_solutions), "La date limite de remise des solutions n'est pas valide.");
|
|
ensure(dateWellFormed($this->date_syntheses . " " . $this->time_syntheses), "La date limite de remise des notes de synthèse n'est pas valide.");
|
|
}
|
|
|
|
public function updateTournament()
|
|
{
|
|
global $URL_BASE, $tournament;
|
|
|
|
$tournament->setName($this->name);
|
|
$tournament->setSize($this->size);
|
|
$tournament->setPlace($this->place);
|
|
$tournament->setPrice($this->price);
|
|
$tournament->setStartDate($this->date_start);
|
|
$tournament->setEndDate($this->date_end);
|
|
$tournament->setInscriptionDate("$this->date_inscription $this->time_inscription");
|
|
$tournament->setSolutionsDate("$this->date_solutions $this->time_solutions");
|
|
$tournament->setSynthesesDate("$this->date_syntheses $this->time_syntheses");
|
|
$tournament->setDescription($this->description);
|
|
|
|
foreach ($this->organizers as $organizer) {
|
|
if (!$tournament->organize($organizer->getId()))
|
|
Mailer::sendAddOrganizerForTournamentMail($organizer, $tournament);
|
|
}
|
|
|
|
$tournament->clearOrganizers();
|
|
/** @var User $organizer */
|
|
foreach ($this->organizers as $organizer)
|
|
$tournament->addOrganizer($organizer);
|
|
|
|
header("Location: $URL_BASE/tournoi/" . $this->name);
|
|
exit();
|
|
}
|
|
}
|
|
|
|
if ($_SESSION["role"] == Role::ORGANIZER || $_SESSION["role"] == Role::ADMIN) {
|
|
$emails = [];
|
|
$emails_validated = [];
|
|
foreach ($tournament->getOrganizers() as $organizer) {
|
|
$emails[] = $organizer->getEmail();
|
|
$emails_validated[] = $organizer->getEmail();
|
|
}
|
|
|
|
foreach ($teams as $team) {
|
|
foreach ($team->getEncadrants() as $encadrant_id) {
|
|
$encadrant = User::fromId($encadrant_id);
|
|
if ($encadrant != null) {
|
|
$emails[] = $encadrant->getEmail();
|
|
if ($team->getValidationStatus() == ValidationStatus::VALIDATED)
|
|
$emails_validated[] = $encadrant->getEmail();
|
|
}
|
|
}
|
|
|
|
foreach ($team->getParticipants() as $participant_id) {
|
|
$participant = User::fromId($participant_id);
|
|
if ($participant != null) {
|
|
$emails[] = $participant->getEmail();
|
|
if ($team->getValidationStatus() == ValidationStatus::VALIDATED)
|
|
$emails_validated[] = $participant->getEmail();
|
|
if ($participant->getResponsibleEmail() != null) {
|
|
$emails[] = $participant->getResponsibleEmail();
|
|
if ($team->getValidationStatus() == ValidationStatus::VALIDATED)
|
|
$emails_validated[] = $participant->getResponsibleEmail();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
require_once "server_files/views/tournoi.php";
|