mirror of
https://gitlab.com/animath/si/plateforme-corres2math.git
synced 2025-06-25 07:40:29 +02:00
Suppression de contenu inutile pour les correspondances
This commit is contained in:
@ -52,7 +52,7 @@ class NewTeam {
|
||||
$_SESSION["team"] = Team::fromTrigram($this->trigram);
|
||||
$_SESSION["user"]->setTeamId($_SESSION["team"]->getId());
|
||||
|
||||
Mailer::sendAddTeamMail($_SESSION["user"], $_SESSION["team"], $this->problem);
|
||||
Mailer::sendAddTeamMail($_SESSION["user"], $_SESSION["team"]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,57 +0,0 @@
|
||||
<?php
|
||||
|
||||
if (!isset($_SESSION["role"]) || $_SESSION["role"] != Role::ADMIN)
|
||||
require_once "server_files/403.php";
|
||||
|
||||
$has_error = false;
|
||||
$error_message = null;
|
||||
|
||||
if (isset($_POST["submitted"])) {
|
||||
$orga = new NewOrganizer($_POST);
|
||||
try {
|
||||
$orga->makeVerifications();
|
||||
$orga->register();
|
||||
}
|
||||
catch (AssertionError $e) {
|
||||
$has_error = true;
|
||||
$error_message = $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
class NewOrganizer {
|
||||
public $surname;
|
||||
public $first_name;
|
||||
public $email;
|
||||
public $admin;
|
||||
public $password;
|
||||
|
||||
public function __construct($data)
|
||||
{
|
||||
foreach ($data as $key => $value)
|
||||
$this->$key = htmlspecialchars($value);
|
||||
}
|
||||
|
||||
public function makeVerifications()
|
||||
{
|
||||
ensure($this->surname != null && $this->surname != "", "Le nom est invalide.");
|
||||
ensure($this->first_name != null && $this->first_name != "", "Le prénom est invalide.");
|
||||
ensure(filter_var($this->email, FILTER_VALIDATE_EMAIL), "L'adresse e-mail est invalide.");
|
||||
$this->email = strtolower($this->email);
|
||||
ensure(!userExists($this->email), "Cette adresse e-mail est déjà utilisée.");
|
||||
$this->admin = $this->admin == "on" ? true : false;
|
||||
}
|
||||
|
||||
public function register() {
|
||||
global $DB, $YEAR;
|
||||
|
||||
$this->password = genRandomPhrase(16, true);
|
||||
|
||||
$req = $DB->prepare("INSERT INTO `users`(`email`, `pwd_hash`, `surname`, `first_name`, `role`, `year`)
|
||||
VALUES (?, ?, ?, ?, ?, ?);");
|
||||
$req->execute([$this->email, password_hash($this->password, PASSWORD_BCRYPT), $this->surname, $this->first_name, $this->admin ? "ADMIN" : "ORGANIZER", $YEAR]);
|
||||
|
||||
Mailer::sendAddOrganizerMail($this);
|
||||
}
|
||||
}
|
||||
|
||||
require_once "server_files/views/ajouter_organisateur.php";
|
@ -1,99 +0,0 @@
|
||||
<?php
|
||||
|
||||
if (!isset($_SESSION["role"]) || $_SESSION["role"] != Role::ADMIN)
|
||||
require_once "server_files/403.php";
|
||||
|
||||
$orgas_response = $DB->query("SELECT `id`, `surname`, `first_name` FROM `users` WHERE (`role` = 'ORGANIZER' OR `role` = 'ADMIN') AND `year` = '$YEAR';");
|
||||
|
||||
$has_error = false;
|
||||
$error_message = null;
|
||||
|
||||
if (isset($_POST["submitted"])) {
|
||||
$tournament = new NewTournament($_POST);
|
||||
try {
|
||||
$tournament->makeVerifications();
|
||||
$tournament->register();
|
||||
}
|
||||
catch (AssertionError $e) {
|
||||
$has_error = true;
|
||||
$error_message = $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
class NewTournament {
|
||||
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 $tournament;
|
||||
|
||||
public function __construct($data)
|
||||
{
|
||||
foreach ($data as $key => $value)
|
||||
$this->$key = ($key == "organizers" ? $value : htmlspecialchars($value));
|
||||
}
|
||||
|
||||
public function makeVerifications()
|
||||
{
|
||||
global $FINAL;
|
||||
|
||||
ensure($this->name != null && $this->name != "", "Le nom est invalide.");
|
||||
ensure(!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.");
|
||||
|
||||
$this->final = $this->final ? 1 : 0;
|
||||
|
||||
ensure(!$this->final || $FINAL == NULL, "Une finale nationale est déjà enregistrée.");
|
||||
}
|
||||
|
||||
public function register()
|
||||
{
|
||||
global $DB, $YEAR;
|
||||
|
||||
$req = $DB->prepare("INSERT INTO `tournaments` (`name`, `size`, `place`, `price`, `description`,
|
||||
`date_start`, `date_end`, `date_inscription`, `date_solutions`, `date_syntheses`, `final`, `year`)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);");
|
||||
$req->execute([$this->name, $this->size, $this->place, $this->price, $this->description, $this->date_start, $this->date_end,
|
||||
"$this->date_inscription $this->time_inscription", "$this->date_solutions $this->time_solutions", "$this->date_syntheses $this->time_syntheses", $this->final ? 1 : 0, $YEAR]);
|
||||
|
||||
$this->tournament = Tournament::fromName($this->name);
|
||||
|
||||
/** @var User $organizer */
|
||||
foreach ($this->organizers as $organizer) {
|
||||
$this->tournament->addOrganizer($organizer);
|
||||
Mailer::sendAddOrganizerForTournamentMail($organizer, $this->tournament);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
require_once "server_files/views/ajouter_tournoi.php";
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
if (!isset($_SESSION["user_id"]) || $_SESSION["role"] != Role::ORGANIZER && $_SESSION["role"] != Role::ADMIN)
|
||||
if (!isset($_SESSION["user_id"]) || $_SESSION["role"] != Role::ADMIN)
|
||||
require_once "server_files/403.php";
|
||||
|
||||
$trigram = htmlspecialchars($_GET["trigram"]);
|
||||
@ -15,9 +15,7 @@ if (isset($_POST["validate"])) {
|
||||
}
|
||||
|
||||
if (isset($_POST["download_zip"])) {
|
||||
$final = isset($_POST["final"]);
|
||||
|
||||
$file_name = getZipFile(DocumentType::PARENTAL_CONSENT, $tournament->getId(), $team->getId());
|
||||
$file_name = getZipFile(DocumentType::PHOTO_CONSENT, $team->getProblem(), $team->getId());
|
||||
|
||||
header("Content-Type: application/zip");
|
||||
header("Content-Disposition: attachment; filename=\"Documents de l'équipe " . $team->getTrigram() . ".zip\"");
|
||||
@ -28,7 +26,6 @@ if (isset($_POST["download_zip"])) {
|
||||
exit();
|
||||
}
|
||||
|
||||
$documents = $tournament->getAllDocuments($team->getId());
|
||||
$documents_final = null;
|
||||
$documents = Document::getAllDocuments($team->getId());
|
||||
|
||||
require_once "server_files/views/equipe.php";
|
||||
|
@ -6,7 +6,7 @@ if (!isset($_SESSION["role"]))
|
||||
$id = $_GET["id"];
|
||||
$user = User::fromId($id);
|
||||
|
||||
if ($_SESSION["role"] != Role::ORGANIZER && $_SESSION["role"] != Role::ADMIN) {
|
||||
if ($_SESSION["role"] != Role::ADMIN) {
|
||||
if ($user->getId() != $_SESSION["user_id"] && ($user->getTeamId() == null || $user->getTeamId() != $_SESSION["user"]->getTeamId()))
|
||||
require_once "server_files/403.php";
|
||||
}
|
||||
@ -17,7 +17,7 @@ if ($user === null)
|
||||
$team = Team::fromId($user->getTeamId());
|
||||
|
||||
if ($team != null) {
|
||||
//$documents = $user->getAllDocuments($team->getTournamentId());
|
||||
$documents = $user->getAllDocuments($team->getProblem());
|
||||
}
|
||||
|
||||
require_once "server_files/views/informations.php";
|
||||
|
@ -33,7 +33,7 @@ if (isset($_POST["team_edit"])) {
|
||||
}
|
||||
|
||||
if (isset($_POST["request_validation"])) {
|
||||
if (!canValidate($team, $tournament))
|
||||
if (!canValidate($team))
|
||||
$error_message = "Votre équipe ne peut pas demander la validation : il manque soit des participants, soit des documents.";
|
||||
else
|
||||
$_SESSION["team"]->setValidationStatus(ValidationStatus::WAITING);
|
||||
@ -47,7 +47,7 @@ if (isset($_SESSION["user_id"]) && isset($_SESSION["team"]) && $_SESSION["team"]
|
||||
$user = $_SESSION["user"];
|
||||
$team = $_SESSION["team"];
|
||||
|
||||
//$documents = $user->getAllDocuments($team->getTournamentId());
|
||||
$documents = $user->getAllDocuments($team->getProblem());
|
||||
}
|
||||
else
|
||||
require_once "server_files/403.php";
|
||||
@ -75,7 +75,7 @@ class SendDocument
|
||||
|
||||
public function sendDocument()
|
||||
{
|
||||
global $LOCAL_PATH, $DB, $FINAL;
|
||||
global $LOCAL_PATH, $DB;
|
||||
|
||||
do
|
||||
$id = genRandomPhrase(64);
|
||||
@ -84,9 +84,9 @@ class SendDocument
|
||||
if (!rename($this->file["tmp_name"], "$LOCAL_PATH/files/$id"))
|
||||
throw new AssertionError("Une erreur est survenue lors de l'envoi du fichier.");
|
||||
|
||||
$req = $DB->prepare("INSERT INTO `documents`(`file_id`, `user`, `team`, `tournament`, `type`)
|
||||
$req = $DB->prepare("INSERT INTO `documents`(`file_id`, `user`, `team`, `problem`, `type`)
|
||||
VALUES (?, ?, ?, ?, ?);");
|
||||
$req->execute([$id, $_SESSION["user_id"], $_SESSION["team"]->getId(), $_SESSION["team"]->isSelectedForFinal() ? $FINAL->getId() : $_SESSION["team"]->getTournamentId(), $this->type]);
|
||||
$req->execute([$id, $_SESSION["user_id"], $_SESSION["team"]->getId(), $_SESSION["team"]->getProblem(), $this->type]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -94,9 +94,9 @@ class MyTeam
|
||||
{
|
||||
public $name;
|
||||
public $trigram;
|
||||
public $tournament_id;
|
||||
public $problem;
|
||||
/** @var Team */
|
||||
private $team;
|
||||
private $tournament;
|
||||
|
||||
public function __construct($data)
|
||||
{
|
||||
@ -105,7 +105,6 @@ class MyTeam
|
||||
|
||||
$this->trigram = strtoupper($this->trigram);
|
||||
$this->team = $_SESSION["team"];
|
||||
$this->tournament = Tournament::fromId($this->tournament_id);
|
||||
}
|
||||
|
||||
public function makeVerifications()
|
||||
@ -114,8 +113,8 @@ class MyTeam
|
||||
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(preg_match("#^[1-4]$#", $this->problem), "Le problème 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.");
|
||||
}
|
||||
|
||||
@ -125,9 +124,7 @@ class MyTeam
|
||||
|
||||
$this->team->setName($this->name);
|
||||
$this->team->setTrigram($this->trigram);
|
||||
$this->team->setTournamentId($this->tournament_id);
|
||||
|
||||
$_SESSION["tournament"] = $this->tournament;
|
||||
$this->team->setProblem($this->problem);
|
||||
|
||||
header("Location: $URL_BASE/mon_equipe");
|
||||
}
|
||||
|
@ -35,8 +35,8 @@ class JoinTeam
|
||||
ensure($this->team != null, "Ce code d'accès est invalide.");
|
||||
ensure($this->team->getValidationStatus() == ValidationStatus::NOT_READY, "Cette équipe est déjà validée ou en cours de validation, vous ne pouvez pas la rejoindre.");
|
||||
|
||||
for ($i = 1; $i <= $_SESSION["role"] == Role::PARTICIPANT ? 6 : 2; ++$i) {
|
||||
if (($_SESSION["role"] == Role::PARTICIPANT ? $this->team->getParticipants()[$i - 1] : $this->team->getEncadrants()[$i - 1]) == NULL)
|
||||
for ($i = 1; $i <= $_SESSION["role"] == Role::PARTICIPANT ? 6 : 1; ++$i) {
|
||||
if (($_SESSION["role"] == Role::PARTICIPANT ? $this->team->getParticipants()[$i - 1] : $this->team->getEncadrantId()) == NULL)
|
||||
break;
|
||||
}
|
||||
|
||||
@ -52,14 +52,13 @@ class JoinTeam
|
||||
$user->setTeamId($this->team->getId());
|
||||
|
||||
if ($_SESSION["role"] == Role::ENCADRANT)
|
||||
$this->team->setEncadrant($this->min_null_index, $user->getId());
|
||||
$this->team->setEncadrant($user->getId());
|
||||
else
|
||||
$this->team->setParticipant($this->min_null_index, $user->getId());
|
||||
|
||||
$_SESSION["team"] = $this->team;
|
||||
$tournament = $_SESSION["tournament"] = Tournament::fromId($this->team->getTournamentId());
|
||||
|
||||
Mailer::sendJoinTeamMail($user, $this->team, $tournament);
|
||||
Mailer::sendJoinTeamMail($user, $this->team);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,72 +0,0 @@
|
||||
<?php
|
||||
|
||||
if (!isset($_SESSION["team"]))
|
||||
require_once "server_files/403.php";
|
||||
|
||||
/**
|
||||
* @var Team $team
|
||||
* @var Tournament $tournament
|
||||
*/
|
||||
$team = $_SESSION["team"];
|
||||
$tournament = Tournament::fromId($team->getTournamentId());
|
||||
|
||||
$has_error = false;
|
||||
$error_message = null;
|
||||
|
||||
if (isset($_POST["send_solution"])) {
|
||||
$save_solution = new SaveSolution();
|
||||
try {
|
||||
$save_solution->makeVerifications();
|
||||
$save_solution->saveSolution();
|
||||
} catch (AssertionError $e) {
|
||||
$has_error = true;
|
||||
$error_message = $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
$solutions = $tournament->getAllSolutions($team->getId());
|
||||
$solutions_final = null;
|
||||
if ($team->isSelectedForFinal())
|
||||
$solutions_final = $FINAL->getAllSolutions($team->getId());
|
||||
|
||||
class SaveSolution
|
||||
{
|
||||
private $problem;
|
||||
private $file;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->file = $_FILES["document"];
|
||||
$this->problem = htmlspecialchars($_POST["problem"]);
|
||||
}
|
||||
|
||||
public function makeVerifications()
|
||||
{
|
||||
global $LOCAL_PATH;
|
||||
|
||||
ensure(preg_match("#[1-9]#", $this->problem), "Le numéro du problème est invalide.");
|
||||
ensure($this->file["size"] <= 2e6, "Le fichier doit peser moins que 2 Mo.");
|
||||
ensure(!$this->file["error"], "Une erreur est survenue.");
|
||||
ensure(finfo_file(finfo_open(FILEINFO_MIME_TYPE), $this->file["tmp_name"]) == "application/pdf", "Le fichier doit être au format PDF.");
|
||||
ensure(is_dir("$LOCAL_PATH/files") || mkdir("$LOCAL_PATH/files"), "Un problème est survenue dans l'envoi du fichier. Veuillez contacter l'administrateur du serveur.");
|
||||
}
|
||||
|
||||
public function saveSolution()
|
||||
{
|
||||
global $LOCAL_PATH, $DB, $team, $tournament, $FINAL;
|
||||
|
||||
do
|
||||
$id = genRandomPhrase(64);
|
||||
while (file_exists("$LOCAL_PATH/files/$id"));
|
||||
|
||||
if (!rename($this->file["tmp_name"], "$LOCAL_PATH/files/$id"))
|
||||
throw new AssertionError("Une erreur est survenue lors de l'envoi du fichier.");
|
||||
|
||||
$req = $DB->prepare("INSERT INTO `solutions`(`file_id`, `team`, `tournament`, `problem`) VALUES (?, ?, ?, ?);");
|
||||
$req->execute([$id, $team->getId(), $team->isSelectedForFinal() ? $FINAL->getId() : $tournament->getId(), $this->problem]);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
require_once "server_files/views/solutions.php";
|
@ -1,24 +0,0 @@
|
||||
<?php
|
||||
|
||||
if (!isset($_SESSION["role"]) || $_SESSION["role"] != Role::ADMIN && $_SESSION["role"] != Role::ORGANIZER)
|
||||
require_once "server_files/403.php";
|
||||
|
||||
if (isset($_POST["download_zip"])) {
|
||||
$id = $_POST["tournament"];
|
||||
$tournament = Tournament::fromId($id);
|
||||
|
||||
$file_name = getZipFile(DocumentType::SOLUTION, $id);
|
||||
|
||||
header("Content-Type: application/zip");
|
||||
header("Content-Disposition: attachment; filename=\"Solutions du tournoi de " . $tournament->getName() . ".zip\"");
|
||||
header("Content-Length: " . strval(filesize($file_name)));
|
||||
|
||||
readfile($file_name);
|
||||
|
||||
exit();
|
||||
}
|
||||
|
||||
$user = $_SESSION["user"];
|
||||
$tournaments = $_SESSION["role"] == Role::ADMIN ? Tournament::getAllTournaments() : $user->getOrganizedTournaments();
|
||||
|
||||
require_once "server_files/views/solutions_orga.php";
|
@ -1,68 +0,0 @@
|
||||
<?php
|
||||
|
||||
if (!isset($_SESSION["team"]))
|
||||
require_once "server_files/403.php";
|
||||
|
||||
/**
|
||||
* @var Team $team
|
||||
* @var Tournament $tournament
|
||||
*/
|
||||
$team = $_SESSION["team"];
|
||||
$tournament = Tournament::fromId($team->getTournamentId());
|
||||
|
||||
if (isset($_POST["send_synthesis"])) {
|
||||
$save_synthesis = new SaveSynthesis();
|
||||
try {
|
||||
$save_synthesis->makeVerifications();
|
||||
$save_synthesis->saveSynthesis();
|
||||
} catch (AssertionError $e) {
|
||||
$has_error = true;
|
||||
$error_message = $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
$syntheses = $tournament->getAllSyntheses($team->getId());
|
||||
$syntheses_final = null;
|
||||
if ($team->isSelectedForFinal())
|
||||
$syntheses_final = $FINAL->getAllSyntheses($team->getId());
|
||||
|
||||
class SaveSynthesis
|
||||
{
|
||||
private $dest;
|
||||
private $file;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->file = $_FILES["document"];
|
||||
$this->dest = DestType::fromName(strtoupper(htmlspecialchars($_POST["problem"])));
|
||||
}
|
||||
|
||||
public function makeVerifications()
|
||||
{
|
||||
global $LOCAL_PATH;
|
||||
|
||||
ensure($this->dest != DestType::DEFENSEUR, "Le destinataire est invalide.");
|
||||
ensure($this->file["size"] <= 2e6, "Le fichier doit peser moins que 2 Mo.");
|
||||
ensure(!$this->file["error"], "Une erreur est survenue.");
|
||||
ensure(finfo_file(finfo_open(FILEINFO_MIME_TYPE), $this->file["tmp_name"]) == "application/pdf", "Le fichier doit être au format PDF.");
|
||||
ensure(is_dir("$LOCAL_PATH/files") || mkdir("$LOCAL_PATH/files"), "Un problème est survenue dans l'envoi du fichier. Veuillez contacter l'administrateur du serveur.");
|
||||
}
|
||||
|
||||
public function saveSynthesis()
|
||||
{
|
||||
global $LOCAL_PATH, $DB, $team, $tournament, $FINAL;
|
||||
do
|
||||
$id = genRandomPhrase(64);
|
||||
while (file_exists("$LOCAL_PATH/files/$id"));
|
||||
|
||||
if (!rename($this->file["tmp_name"], "$LOCAL_PATH/files/$id"))
|
||||
throw new AssertionError("Une erreur est survenue lors de l'envoi du fichier.");
|
||||
|
||||
$req = $DB->prepare("INSERT INTO `syntheses`(`file_id`, `team`, `tournament`, `dest`) VALUES (?, ?, ?, ?);");
|
||||
$req->execute([$id, $team->getId(), $team->isSelectedForFinal() ? $FINAL->getId() : $tournament->getId(), $this->dest]);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
require_once "server_files/views/syntheses.php";
|
@ -1,22 +0,0 @@
|
||||
<?php if (!isset($_SESSION["role"]) || $_SESSION["role"] != Role::ADMIN && $_SESSION["role"] != Role::ORGANIZER)
|
||||
require_once "server_files/403.php";
|
||||
|
||||
if (isset($_POST["download_zip"])) {
|
||||
$id = $_POST["tournament"];
|
||||
$tournament = Tournament::fromId($id);
|
||||
|
||||
$file_name = getZipFile(DocumentType::SYNTHESIS, $id);
|
||||
|
||||
header("Content-Type: application/zip");
|
||||
header("Content-Disposition: attachment; filename=\"Notes de syntèses du tournoi de " . $tournament->getName() . ".zip\"");
|
||||
header("Content-Length: " . filesize($file_name));
|
||||
|
||||
readfile($file_name);
|
||||
|
||||
exit();
|
||||
}
|
||||
|
||||
$user = $_SESSION["user"];
|
||||
$tournaments = $_SESSION["role"] == Role::ADMIN ? Tournament::getAllTournaments() : $user->getOrganizedTournaments();
|
||||
|
||||
require_once "server_files/views/syntheses_orga.php";
|
@ -1,120 +0,0 @@
|
||||
<?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();
|
||||
$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";
|
@ -1,5 +0,0 @@
|
||||
<?php
|
||||
|
||||
$tournaments = Tournament::getAllTournaments();
|
||||
|
||||
require_once "server_files/views/tournois.php";
|
@ -10,64 +10,22 @@ if (!isset($_SESSION["user_id"]))
|
||||
|
||||
$id = htmlspecialchars($_GET["file_id"]);
|
||||
|
||||
$type = DocumentType::SOLUTION;
|
||||
$file = Solution::fromId($id);
|
||||
if ($file === null) {
|
||||
$type = DocumentType::SYNTHESIS;
|
||||
$file = Synthesis::fromId($id);
|
||||
|
||||
if ($file === null) {
|
||||
$file = Document::fromId($id);
|
||||
$type = DocumentType::PARENTAL_CONSENT;
|
||||
}
|
||||
}
|
||||
$file = Document::fromId($id);
|
||||
|
||||
if ($file !== null) {
|
||||
$team = Team::fromId($file->getTeamId());
|
||||
$tournament = Tournament::fromId($file->getTournamentId());
|
||||
$team = Team::fromId($file->getTeamId());;
|
||||
$trigram = $team->getTrigram();
|
||||
|
||||
if ($_SESSION["role"] == Role::ORGANIZER && !$tournament->organize($_SESSION["user_id"]))
|
||||
$user = User::fromId($file->getUserId());
|
||||
$type = $file->getType();
|
||||
|
||||
if (($_SESSION["role"] == Role::PARTICIPANT || $_SESSION["role"] == Role::ENCADRANT) && $user->getId() != $_SESSION["user_id"])
|
||||
require_once "server_files/403.php";
|
||||
|
||||
if ($type == DocumentType::SOLUTION) {
|
||||
$problem = $file->getProblem();
|
||||
$name = "Problème $problem $trigram.pdf";
|
||||
|
||||
if (($_SESSION["role"] == Role::PARTICIPANT || $_SESSION["role"] == Role::ENCADRANT) && (!isset($_SESSION["team"]) || $_SESSION["team"]->getId() != $team->getId()))
|
||||
require_once "server_files/403.php";
|
||||
}
|
||||
else if ($type == DocumentType::SYNTHESIS) {
|
||||
$dest = $file->getDest();
|
||||
$name = "Note de synthèse $trigram pour " . ($dest == DestType::OPPOSANT ? "l'opposant" : "le rapporteur") . ".pdf";
|
||||
|
||||
if (($_SESSION["role"] == Role::PARTICIPANT || $_SESSION["role"] == Role::ENCADRANT) && (!isset($_SESSION["team"]) || $_SESSION["team"]->getId() != $team->getId()))
|
||||
require_once "server_files/403.php";
|
||||
}
|
||||
else {
|
||||
$user = User::fromId($file->getUserId());
|
||||
$type = $file->getType();
|
||||
|
||||
if (($_SESSION["role"] == Role::PARTICIPANT || $_SESSION["role"] == Role::ENCADRANT) && $user->getId() != $_SESSION["user_id"])
|
||||
require_once "server_files/403.php";
|
||||
|
||||
$surname = $user->getSurname();
|
||||
$first_name = $user->getFirstName();
|
||||
switch ($type) {
|
||||
case DocumentType::PARENTAL_CONSENT:
|
||||
$name = "Autorisation parentale";
|
||||
break;
|
||||
case DocumentType::PHOTO_CONSENT:
|
||||
$name = "Autorisation de droit à l'image";
|
||||
break;
|
||||
case DocumentType::SANITARY_PLUG:
|
||||
$name = "Fiche sanitaire";
|
||||
break;
|
||||
}
|
||||
$name .= " de $first_name $surname.pdf";
|
||||
}
|
||||
}
|
||||
else
|
||||
$surname = $user->getSurname();
|
||||
$first_name = $user->getFirstName();
|
||||
$name = "Autorisation de droit à l'image de $first_name $surname.pdf";
|
||||
} else
|
||||
require_once "server_files/404.php";
|
||||
|
||||
header("Content-Type: application/pdf");
|
||||
|
Reference in New Issue
Block a user