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();
$orgas_response = $DB->query("SELECT `id`, `surname`, `first_name` FROM `users` WHERE (`role` = 'ORGANIZER' OR `role` = 'ADMIN') AND `year` = '$YEAR';");
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(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");
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();
}
}
require_once "server_files/views/tournoi.php";