diff --git a/dispatcher.php b/dispatcher.php index 388a7e7..3dbcbd3 100644 --- a/dispatcher.php +++ b/dispatcher.php @@ -6,7 +6,6 @@ require_once "server_files/classes/Document.php"; require_once "server_files/classes/Role.php"; require_once "server_files/classes/SchoolClass.php"; require_once "server_files/classes/Team.php"; -require_once "server_files/classes/Tournament.php"; require_once "server_files/classes/User.php"; require_once "server_files/classes/ValidationStatus.php"; require_once "server_files/services/mail.php"; @@ -26,8 +25,6 @@ $ROUTES = []; $ROUTES["^(|accueil|index|accueil\.php|accueil\.html|accueil\.py|index\.php|index\.html|index\.py)$"] = ["server_files/controllers/index.php"]; $ROUTES["^ajouter_equipe$"] = ["server_files/controllers/ajouter_equipe.php"]; -$ROUTES["^ajouter_organisateur$"] = ["server_files/controllers/ajouter_organisateur.php"]; -$ROUTES["^ajouter_tournoi$"] = ["server_files/controllers/ajouter_tournoi.php"]; $ROUTES["^confirmer_mail/([a-z0-9]*)/?$"] = ["server_files/controllers/confirmer_mail.php", "token"]; $ROUTES["^connexion/(confirmation-mail)/?$"] = ["server_files/controllers/connexion.php", "confirmation-mail"]; $ROUTES["^connexion/(mdp_oublie)/?$"] = ["server_files/controllers/connexion.php", "mdp_oublie"]; @@ -42,13 +39,6 @@ $ROUTES["^mon_compte/?$"] = ["server_files/controllers/mon_compte.php"]; $ROUTES["^mon_equipe/(modifier)/?$"] = ["server_files/controllers/mon_equipe.php", "modifier"]; $ROUTES["^mon_equipe/?$"] = ["server_files/controllers/mon_equipe.php"]; $ROUTES["^rejoindre_equipe/?$"] = ["server_files/controllers/rejoindre_equipe.php"]; -$ROUTES["^solutions/?$"] = ["server_files/controllers/solutions.php"]; -$ROUTES["^solutions_orga/?$"] = ["server_files/controllers/solutions_orga.php"]; -$ROUTES["^syntheses/?$"] = ["server_files/controllers/syntheses.php"]; -$ROUTES["^syntheses_orga/?$"] = ["server_files/controllers/syntheses_orga.php"]; -$ROUTES["^tournoi/(.*)/(modifier)/?$"] = ["server_files/controllers/tournoi.php", "name", "modifier"]; -$ROUTES["^tournoi/(.*)/?$"] = ["server_files/controllers/tournoi.php", "name"]; -$ROUTES["^tournois/?$"] = ["server_files/controllers/tournois.php"]; # Assets files diff --git a/server_files/classes/Document.php b/server_files/classes/Document.php index 020eeab..5876e7d 100644 --- a/server_files/classes/Document.php +++ b/server_files/classes/Document.php @@ -5,7 +5,7 @@ class Document private $file_id; private $user_id; private $team_id; - private $tournament_id; + private $problem; private $type; private $uploaded_at; private $version; @@ -37,7 +37,7 @@ class Document $this->file_id = $data["file_id"]; $this->user_id = $data["user"]; $this->team_id = $data["team"]; - $this->tournament_id = $data["tournament"]; + $this->problem = $data["problem"]; $this->type = DocumentType::fromName($data["type"]); $this->uploaded_at = $data["uploaded_at"]; $this->version = isset($data["version"]) ? $data["version"] : 1; @@ -58,9 +58,9 @@ class Document return $this->team_id; } - public function getTournamentId() + public function getProblem() { - return $this->tournament_id; + return $this->problem; } public function getType() @@ -77,242 +77,48 @@ class Document { return $this->version; } -} -class Solution -{ - private $file_id; - private $team_id; - private $tournament_id; - private $problem; - private $uploaded_at; - private $version; - private function __construct() {} - public static function fromId($id) + public function getAllDocuments($problem) { global $DB; - $req = $DB->prepare("SELECT * FROM `solutions` WHERE `file_id` = ?;"); - $req->execute([htmlspecialchars($id)]); - $data = $req->fetch(); + $req = $DB->query("SELECT * FROM `documents` AS `t1` " + . "INNER JOIN (SELECT `user`, `type`, `problem`, MAX(`uploaded_at`) AS `last_upload`, COUNT(`team`) AS `version` FROM `documents` GROUP BY `problem`, `type`, `user`) `t2` " + . "ON `t1`.`user` = `t2`.`user` AND `t1`.`type` = `t2`.`type` AND `t1`.`problem` = `t2`.`problem` " + . "WHERE `t1`.`uploaded_at` = `t2`.`last_upload` AND `t1`.`problem` = $problem ORDER BY `t1`.`type`;"); - if ($data === false) - return null; + $docs = []; - return self::fromData($data); - } + while (($data = $req->fetch()) !== false) + $docs[] = Document::fromData($data); - public static function fromData($data) - { - $sol = new Solution(); - $sol->fill($data); - return $sol; - } - - private function fill($data) - { - $this->file_id = $data["file_id"]; - $this->team_id = $data["team"]; - $this->tournament_id = $data["tournament"]; - $this->problem = $data["problem"]; - $this->uploaded_at = $data["uploaded_at"]; - $this->version = isset($data["version"]) ? $data["version"] : 1; - } - - public function getFileId() - { - return $this->file_id; - } - - public function getTeamId() - { - return $this->team_id; - } - - public function getTournamentId() - { - return $this->tournament_id; - } - - public function getProblem() - { - return $this->problem; - } - - public function getUploadedAt() - { - return $this->uploaded_at; - } - - public function getVersion() - { - return $this->version; - } -} - -class Synthesis -{ - private $file_id; - private $team_id; - private $tournament_id; - private $dest; - private $uploaded_at; - private $version; - - private function __construct() {} - - public static function fromId($id) - { - global $DB; - $req = $DB->prepare("SELECT * FROM `syntheses` WHERE `file_id` = ?;"); - $req->execute([htmlspecialchars($id)]); - $data = $req->fetch(); - - if ($data === false) - return null; - - return self::fromData($data); - } - - public static function fromData($data) - { - $synthese = new Synthesis(); - $synthese->fill($data); - return $synthese; - } - - private function fill($data) - { - $this->file_id = $data["file_id"]; - $this->team_id = $data["team"]; - $this->tournament_id = $data["tournament"]; - $this->dest = DestType::fromName($data["dest"]); - $this->uploaded_at = $data["uploaded_at"]; - $this->version = isset($data["version"]) ? $data["version"] : 1; - } - - public function getFileId() - { - return $this->file_id; - } - - public function getTeamId() - { - return $this->team_id; - } - - public function getTournamentId() - { - return $this->tournament_id; - } - - public function getDest() - { - return $this->dest; - } - - public function getUploadedAt() - { - return $this->uploaded_at; - } - - public function getVersion() - { - return $this->version; - } -} - -class DestType -{ - const DEFENSEUR = 0; - const OPPOSANT = 1; - const RAPPORTEUR = 2; - - public static function getTranslatedName($status) { - switch ($status) { - case self::OPPOSANT: - return "Opposant"; - case self::RAPPORTEUR: - return "Rapporteur"; - default: - return "Défenseur"; - } - } - - public static function getName($status) { - switch ($status) { - case self::OPPOSANT: - return "OPPOSANT"; - case self::RAPPORTEUR: - return "RAPPORTEUR"; - default: - return "DEFENSEUR"; - } - } - - public static function fromName($name) { - switch ($name) { - case "OPPOSANT": - return self::OPPOSANT; - case "RAPPORTEUR": - return self::RAPPORTEUR; - default: - return self::DEFENSEUR; - } + return $docs; } } class DocumentType { - const PARENTAL_CONSENT = 0; - const PHOTO_CONSENT = 1; - const SANITARY_PLUG = 2; - const SOLUTION = 3; - const SYNTHESIS = 4; + const PHOTO_CONSENT = 0; public static function getTranslatedName($type) { switch ($type) { - case self::PARENTAL_CONSENT: - return "Autorisation parentale"; - case self::PHOTO_CONSENT: - return "Autorisation de droit à l'image"; - case self::SANITARY_PLUG: - return "Fiche sanitaire"; - case self::SOLUTION: - return "Solution"; default: - return "Note de synthèse"; + return "Autorisation de droit à l'image"; } } public static function getName($type) { switch ($type) { - case self::PARENTAL_CONSENT: - return "PARENTAL_CONSENT"; - case self::PHOTO_CONSENT: - return "PHOTO_CONSENT"; - case self::SANITARY_PLUG: - return "SANITARY_PLUG"; - case self::SOLUTION: - return "SOLUTION"; default: - return "SYNTHESIS"; + return "PHOTO_CONSENT"; } } public static function fromName($name) { switch ($name) { - case "PARENTAL_CONSENT": - return self::PARENTAL_CONSENT; - case "PHOTO_CONSENT": - return self::PHOTO_CONSENT; - case "SANITARY_PLUG": - return self::SANITARY_PLUG; - case "SOLUTION": - return self::SOLUTION; default: - return self::SYNTHESIS; + return self::PHOTO_CONSENT; } } } \ No newline at end of file diff --git a/server_files/classes/Role.php b/server_files/classes/Role.php index 5fa557a..e60aa68 100644 --- a/server_files/classes/Role.php +++ b/server_files/classes/Role.php @@ -4,15 +4,12 @@ class Role { const PARTICIPANT = 0; const ENCADRANT = 1; - const ORGANIZER = 2; - const ADMIN = 3; + const ADMIN = 2; public static function getTranslatedName($role) { switch ($role) { case self::ENCADRANT: return "Encadrant"; - case self::ORGANIZER: - return "Organisateur"; case self::ADMIN: return "Administrateur"; default: @@ -24,8 +21,6 @@ class Role switch ($role) { case self::ENCADRANT: return "ENCADRANT"; - case self::ORGANIZER: - return "ORGANIZER"; case self::ADMIN: return "ADMIN"; default: @@ -37,8 +32,6 @@ class Role switch ($name) { case "ENCADRANT": return self::ENCADRANT; - case "ORGANIZER": - return self::ORGANIZER; case "ADMIN": return self::ADMIN; default: diff --git a/server_files/classes/Tournament.php b/server_files/classes/Tournament.php deleted file mode 100644 index e404e7d..0000000 --- a/server_files/classes/Tournament.php +++ /dev/null @@ -1,357 +0,0 @@ -prepare("SELECT * FROM `tournaments` WHERE `id` = ?;"); - $req->execute([htmlspecialchars($id)]); - $data = $req->fetch(); - - if ($data === false) - return null; - - $tournament = new Tournament(); - $tournament->fill($data); - return $tournament; - } - - public static function fromName($name) - { - global $DB, $YEAR; - $req = $DB->prepare("SELECT * FROM `tournaments` WHERE `name` = ? AND `year` = $YEAR;"); - $req->execute([htmlspecialchars($name)]); - $data = $req->fetch(); - - if ($data === false) - return null; - - $tournament = new Tournament(); - $tournament->fill($data); - return $tournament; - } - - public static function getFinalTournament() - { - global $DB, $YEAR; - $req = $DB->query("SELECT * FROM `tournaments` WHERE `final` AND `year` = $YEAR;"); - $data = $req->fetch(); - - if ($data === false) - return null; - - $tournament = new Tournament(); - $tournament->fill($data); - return $tournament; - } - - public static function getAllTournaments($include_final = true, $only_future = false) - { - global $DB, $YEAR; - $sql = "SELECT * FROM `tournaments` WHERE "; - if (!$include_final) - $sql .= "`final` = 0 AND "; - if ($only_future) - $sql .= "`date_start` > CURRENT_DATE AND "; - $sql .= "`year` = $YEAR ORDER BY `date_start`, `name`;"; - $req = $DB->query($sql); - - $tournaments = []; - - while (($data = $req->fetch()) !== false) { - $tournament = new Tournament(); - $tournament->fill($data); - $tournaments[] = $tournament; - } - - return $tournaments; - } - - private function fill($data) - { - $this->id = $data["id"]; - $this->name = $data["name"]; - $this->size = $data["size"]; - $this->place = $data["place"]; - $this->price = $data["price"]; - $this->description = $data["description"]; - $this->date_start = $data["date_start"]; - $this->date_end = $data["date_end"]; - $this->date_inscription = $data["date_inscription"]; - $this->date_solutions = $data["date_solutions"]; - $this->date_syntheses = $data["date_syntheses"]; - $this->final = $data["final"] == true; - $this->year = $data["year"]; - - global $DB; - $req = $DB->prepare("SELECT `organizer` FROM `organizers` WHERE `tournament` = ?;"); - $req->execute([$this->id]); - - while (($data = $req->fetch()) !== false) - $this->organizers[] = User::fromId($data["organizer"]); - } - - public function getId() - { - return $this->id; - } - - public function getName() - { - return $this->name; - } - - public function setName($name) - { - global $DB; - $this->name = $name; - $DB->prepare("UPDATE `tournaments` SET `name` = ? WHERE `id` = ?;")->execute([$name, $this->id]); - } - - public function getSize() - { - return $this->size; - } - - public function setSize($size) - { - global $DB; - $this->size = $size; - $DB->prepare("UPDATE `tournaments` SET `size` = ? WHERE `id` = ?;")->execute([$size, $this->id]); - } - - public function getPlace() - { - return $this->place; - } - - public function setPlace($place) - { - global $DB; - $this->place = $place; - $DB->prepare("UPDATE `tournaments` SET `place` = ? WHERE `id` = ?;")->execute([$place, $this->id]); - } - - public function getPrice() - { - return $this->price; - } - - public function setPrice($price) - { - global $DB; - $this->price = $price; - $DB->prepare("UPDATE `tournaments` SET `price` = ? WHERE `id` = ?;")->execute([$price, $this->id]); - } - - public function getDescription() - { - return $this->description; - } - - public function setDescription($desc) - { - global $DB; - $this->description = $desc; - $DB->prepare("UPDATE `tournaments` SET `description` = ? WHERE `id` = ?;")->execute([$desc, $this->id]); - } - - public function getStartDate() - { - return $this->date_start; - } - - public function setStartDate($date) - { - global $DB; - $this->date_start = $date; - $DB->prepare("UPDATE `tournaments` SET `date_start` = ? WHERE `id` = ?;")->execute([$date, $this->id]); - } - - public function getEndDate() - { - return $this->date_end; - } - - public function setEndDate($date) - { - global $DB; - $this->date_end = $date; - $DB->prepare("UPDATE `tournaments` SET `date_end` = ? WHERE `id` = ?;")->execute([$date, $this->id]); - } - - public function getInscriptionDate() - { - return $this->date_inscription; - } - - public function setInscriptionDate($date) - { - global $DB; - $this->date_inscription = $date; - $DB->prepare("UPDATE `tournaments` SET `date_inscription` = ? WHERE `id` = ?;")->execute([$date, $this->id]); - } - - public function getSolutionsDate() - { - return $this->date_solutions; - } - - public function setSolutionsDate($date) - { - global $DB; - $this->date_solutions = $date; - $DB->prepare("UPDATE `tournaments` SET `date_solutions` = ? WHERE `id` = ?;")->execute([$date, $this->id]); - } - - public function getSynthesesDate() - { - return $this->date_syntheses; - } - - public function setSynthesesDate($date) - { - global $DB; - $this->date_syntheses = $date; - $DB->prepare("UPDATE `tournaments` SET `date_syntheses` = ? WHERE `id` = ?;")->execute([$date, $this->id]); - } - - public function isFinal() - { - return $this->final; - } - - public function setFinal($final) - { - global $DB; - $this->final = $final; - $DB->prepare("UPDATE `tournaments` SET `final` = ? WHERE `id` = ?;")->execute([$final, $this->id]); - } - - public function getAllTeams() - { - global $DB, $YEAR; - if ($this->final) - $req = $DB->query("SELECT `id` FROM `teams` WHERE `final_selection` AND `year` = $YEAR;"); - else - $req = $DB->query("SELECT `id` FROM `teams` WHERE `tournament` = $this->id AND `year` = $YEAR;"); - - $teams = []; - - while (($data = $req->fetch()) !== false) - $teams[] = Team::fromId($data["id"]); - - return $teams; - } - - public function getOrganizers() - { - return $this->organizers; - } - - public function organize($user_id) - { - foreach ($this->organizers as $organizer) { - if ($organizer->getId() == $user_id) - return true; - } - - return false; - } - - public function addOrganizer(User $user) - { - global $DB; - - $this->organizers[] = $user; - - $req = $DB->prepare("INSERT INTO `organizers`(`organizer`, `tournament`) VALUES(?, ?);"); - $req->execute([$user->getId(), $this->id]); - } - - public function clearOrganizers() - { - global $DB; - - $this->organizers = []; - - $req = $DB->prepare("DELETE FROM `organizers` WHERE `tournament` = ?;"); - $req->execute([$this->id]); - } - - public function getYear() - { - return $this->year; - } - - public function getAllDocuments($team_id = -1) - { - global $DB; - - $req = $DB->query("SELECT * FROM `documents` AS `t1` " - . "INNER JOIN (SELECT `user`, `type`, `tournament`, MAX(`uploaded_at`) AS `last_upload`, COUNT(`team`) AS `version` FROM `documents` GROUP BY `tournament`, `team`, `type`, `user`) `t2` " - . "ON `t1`.`user` = `t2`.`user` AND `t1`.`type` = `t2`.`type` AND `t1`.`tournament` = `t2`.`tournament` " - . "WHERE `t1`.`uploaded_at` = `t2`.`last_upload` AND `t1`.`tournament` = $this->id " . ($team_id == -1 ? "" : "AND `t1`.`team` = $team_id") . " ORDER BY `t1`.`team`, `t1`.`type`;"); - - $docs = []; - - while (($data = $req->fetch()) !== false) - $docs[] = Document::fromData($data); - - return $docs; - } - - public function getAllSolutions($team_id = -1) - { - global $DB; - - $req = $DB->query("SELECT * FROM `solutions` AS `t1` " - . "INNER JOIN (SELECT `team`, `problem`, `tournament`, MAX(`uploaded_at`) AS `last_upload`, COUNT(`team`) AS `version` FROM `solutions` GROUP BY `tournament`, `team`, `problem`) `t2` " - . "ON `t1`.`team` = `t2`.`team` AND `t1`.`problem` = `t2`.`problem` AND `t1`.`tournament` = `t2`.`tournament` " - . "WHERE `t1`.`uploaded_at` = `t2`.`last_upload` AND `t1`.`tournament` = $this->id " . ($team_id == -1 ? "" : "AND `t1`.`team` = $team_id") . " ORDER BY `t1`.`team`, `t1`.`problem`;"); - - $sols = []; - - while (($data = $req->fetch()) !== false) - $sols[] = Solution::fromData($data); - - return $sols; - } - - public function getAllSyntheses($team_id = -1) - { - global $DB; - - $req = $DB->query("SELECT * FROM `syntheses` AS `t1` " - . "INNER JOIN (SELECT `team`, `dest`, `tournament`, MAX(`uploaded_at`) AS `last_upload`, COUNT(`team`) AS `version` FROM `syntheses` GROUP BY `tournament`, `team`, `dest`) `t2` " - . "ON `t1`.`team` = `t2`.`team` AND `t1`.`dest` = `t2`.`dest` AND `t1`.`tournament` = `t2`.`tournament` " - . "WHERE `t1`.`uploaded_at` = `t2`.`last_upload` AND `t1`.`tournament` = $this->id " . ($team_id == -1 ? "" : "AND `t1`.`team` = $team_id") . " ORDER BY `t1`.`team`, `t1`.`dest`;"); - - $syntheses = []; - - while (($data = $req->fetch()) !== false) - $syntheses[] = Synthesis::fromData($data); - - return $syntheses; - } -} \ No newline at end of file diff --git a/server_files/classes/User.php b/server_files/classes/User.php index 442f309..61e0309 100644 --- a/server_files/classes/User.php +++ b/server_files/classes/User.php @@ -220,13 +220,13 @@ class User return $this->inscription_date; } - public function getAllDocuments($tournament_id) + public function getAllDocuments($problem) { global $DB; $req = $DB->query("SELECT * FROM `documents` AS `t1` " - . "INNER JOIN (SELECT `user`, `type`, `tournament`, MAX(`uploaded_at`) AS `last_upload`, COUNT(`team`) AS `version` FROM `documents` GROUP BY `tournament`, `type`, `user`) `t2` " - . "ON `t1`.`user` = `t2`.`user` AND `t1`.`type` = `t2`.`type` AND `t1`.`tournament` = `t2`.`tournament` " - . "WHERE `t1`.`uploaded_at` = `t2`.`last_upload` AND `t1`.`tournament` = $tournament_id AND `t1`.`user` = $this->id ORDER BY `t1`.`type`;"); + . "INNER JOIN (SELECT `user`, `type`, `problem`, MAX(`uploaded_at`) AS `last_upload`, COUNT(`team`) AS `version` FROM `documents` GROUP BY `problem`, `type`, `user`) `t2` " + . "ON `t1`.`user` = `t2`.`user` AND `t1`.`type` = `t2`.`type` AND `t1`.`problem` = `t2`.`problem` " + . "WHERE `t1`.`uploaded_at` = `t2`.`last_upload` AND `t1`.`problem` = $problem AND `t1`.`user` = $this->id ORDER BY `t1`.`type`;"); $docs = []; @@ -235,17 +235,4 @@ class User return $docs; } - - public function getOrganizedTournaments() - { - global $DB; - $req = $DB->query("SELECT `tournament` FROM `organizers` JOIN `tournaments` ON `tournaments`.`id` = `tournament` WHERE `organizer` = $this->id ORDER BY `date_start`, `name`;"); - - $tournaments = []; - - while (($data = $req->fetch()) !== false) - $tournaments[] = Tournament::fromId($data["tournament"]); - - return $tournaments; - } } \ No newline at end of file diff --git a/server_files/controllers/ajouter_equipe.php b/server_files/controllers/ajouter_equipe.php index 0d0ebcc..2d03fb4 100644 --- a/server_files/controllers/ajouter_equipe.php +++ b/server_files/controllers/ajouter_equipe.php @@ -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"]); } } diff --git a/server_files/controllers/ajouter_organisateur.php b/server_files/controllers/ajouter_organisateur.php deleted file mode 100644 index dbb81b7..0000000 --- a/server_files/controllers/ajouter_organisateur.php +++ /dev/null @@ -1,57 +0,0 @@ -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"; \ No newline at end of file diff --git a/server_files/controllers/ajouter_tournoi.php b/server_files/controllers/ajouter_tournoi.php deleted file mode 100644 index 9356813..0000000 --- a/server_files/controllers/ajouter_tournoi.php +++ /dev/null @@ -1,99 +0,0 @@ -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"; diff --git a/server_files/controllers/equipe.php b/server_files/controllers/equipe.php index f86e107..080fe10 100644 --- a/server_files/controllers/equipe.php +++ b/server_files/controllers/equipe.php @@ -1,6 +1,6 @@ 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"; diff --git a/server_files/controllers/informations.php b/server_files/controllers/informations.php index 5076403..1fbce25 100644 --- a/server_files/controllers/informations.php +++ b/server_files/controllers/informations.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"; diff --git a/server_files/controllers/mon_equipe.php b/server_files/controllers/mon_equipe.php index 4f4d2e9..a354d64 100644 --- a/server_files/controllers/mon_equipe.php +++ b/server_files/controllers/mon_equipe.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"); } diff --git a/server_files/controllers/rejoindre_equipe.php b/server_files/controllers/rejoindre_equipe.php index dadcf35..88ac93f 100644 --- a/server_files/controllers/rejoindre_equipe.php +++ b/server_files/controllers/rejoindre_equipe.php @@ -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); } } diff --git a/server_files/controllers/solutions.php b/server_files/controllers/solutions.php deleted file mode 100644 index cab37a5..0000000 --- a/server_files/controllers/solutions.php +++ /dev/null @@ -1,72 +0,0 @@ -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"; diff --git a/server_files/controllers/solutions_orga.php b/server_files/controllers/solutions_orga.php deleted file mode 100644 index 945c9f8..0000000 --- a/server_files/controllers/solutions_orga.php +++ /dev/null @@ -1,24 +0,0 @@ -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"; diff --git a/server_files/controllers/syntheses.php b/server_files/controllers/syntheses.php deleted file mode 100644 index e2e2ec7..0000000 --- a/server_files/controllers/syntheses.php +++ /dev/null @@ -1,68 +0,0 @@ -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"; diff --git a/server_files/controllers/syntheses_orga.php b/server_files/controllers/syntheses_orga.php deleted file mode 100644 index c4415e2..0000000 --- a/server_files/controllers/syntheses_orga.php +++ /dev/null @@ -1,22 +0,0 @@ -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"; \ No newline at end of file diff --git a/server_files/controllers/tournoi.php b/server_files/controllers/tournoi.php deleted file mode 100644 index e7e0c3a..0000000 --- a/server_files/controllers/tournoi.php +++ /dev/null @@ -1,120 +0,0 @@ -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"; diff --git a/server_files/controllers/tournois.php b/server_files/controllers/tournois.php deleted file mode 100644 index db4c402..0000000 --- a/server_files/controllers/tournois.php +++ /dev/null @@ -1,5 +0,0 @@ -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"); diff --git a/server_files/model.php b/server_files/model.php index c8240c4..41d4be3 100644 --- a/server_files/model.php +++ b/server_files/model.php @@ -2,11 +2,10 @@ function loadUserValues() { - $_SESSION["user"] = $_SESSION["team"] = $_SESSION["tournament"] = null; + $_SESSION["user"] = $_SESSION["team"] = null; unset($_SESSION["user"]); unset($_SESSION["role"]); unset($_SESSION["team"]); - unset($_SESSION["tournament"]); if (isset($_SESSION["user_id"])) { $user = $_SESSION["user"] = User::fromId($_SESSION["user_id"]); @@ -21,12 +20,6 @@ function loadUserValues() exit(); } - if (isset($_GET["be-organizer"])) { - quitTeam(); - $user->setRole(Role::ORGANIZER); - exit(); - } - if (isset($_GET["be-participant"])) { quitTeam(); $user->setRole(Role::PARTICIPANT); @@ -52,14 +45,16 @@ function quitTeam() $user_id = $user->getId(); $role = $user->getRole(); - if ($role == Role::ADMIN || $role == Role::ORGANIZER) + if ($role == Role::ADMIN) return; - for ($i = 1; $i <= ($role == Role::ENCADRANT ? 2 : 6); ++$i) - /** @noinspection SqlResolve */ - $DB->exec("UPDATE `teams` SET `" . strtolower(Role::getName($role)) . "_$i` = NULL WHERE `" . strtolower(Role::getName($role)) . "_$i` = $user_id;"); + if ($role == Role::PARTICIPANT) + for ($i = 1; $i <= 6; ++$i) + /** @noinspection SqlResolve */ + $DB->exec("UPDATE `teams` SET `participant_$i` = NULL WHERE `participant_$i` = $user_id;"); + else + $DB->exec("UPDATE `teams` SET `encadrant` = NULL WHERE `encadrant` = $user_id;"); $user->setTeamId(null); - $DB->exec("UPDATE `teams` SET `encadrant_1` = `encadrant_2`, `encadrant_2` = NULL WHERE `encadrant_1` IS NULL;"); for ($i = 1; $i <= 5; ++$i) { /** @noinspection SqlResolve */ $DB->exec("UPDATE `teams` SET `participant_$i` = `participant_" . strval($i + 1) . "`, `participant_" . strval($i + 1) . "` = NULL WHERE `participant_$i` IS NULL;"); @@ -70,19 +65,6 @@ function quitTeam() unlink("$URL_BASE/files/" . $data["file_id"]); $DB->exec("DELETE FROM `documents` WHERE `user` = $user_id;"); - if ($DB->exec("DELETE FROM `teams` WHERE `encadrant_1` IS NULL AND `participant_1` IS NULL;") > 0) { - $team_id = $user->getTeamId(); - $req = $DB->query("SELECT `file_id` FROM `solutions` WHERE `team` = $team_id;"); - while (($data = $req->fetch()) !== false) - unlink("$URL_BASE/files/" . $data["file_id"]); - $DB->exec("DELETE FROM `solutions` WHERE `team` = $team_id;"); - - $req = $DB->query("SELECT `file_id` FROM `syntheses` WHERE `team` = $team_id;"); - while (($data = $req->fetch()) !== false) - unlink("$URL_BASE/files/" . $data["file_id"]); - $DB->exec("DELETE FROM `syntheses` WHERE `team` = $team_id;"); - } - $_SESSION["team"] = null; unset($_SESSION["team"]); } @@ -114,57 +96,29 @@ function trigramExists($trigram) return $req->fetch(); } -function tournamentExists($name) +function canValidate(Team $team) { - global $DB, $YEAR; - - $req = $DB->prepare("SELECT `id` FROM `tournaments` WHERE `name` = ? AND `year` = '$YEAR';"); - $req->execute([$name]); - return $req->fetch(); -} - -function canValidate(Team $team, Tournament $tournament) -{ - global $DB, $YEAR; + global $DB; $can_validate = $team->getValidationStatus() == ValidationStatus::NOT_READY; - $can_validate &= $team->getEncadrants()[0] != NULL; - $can_validate &= $team->getParticipants()[3] != NULL; - for ($i = 1; $i <= 2; ++$i) { - if ($team->getEncadrants()[$i - 1] === NULL) - continue; + $can_validate &= $team->getEncadrantId() != null; + $can_validate &= $team->getParticipants()[3] != null; - $req = $DB->prepare("SELECT COUNT(*) AS `version` FROM `documents` WHERE `user` = ? AND `tournament` = ? AND `type` = ?;"); - $req->execute([$team->getEncadrants()[$i - 1], $tournament->getId(), "PHOTO_CONSENT"]); - $d = $req->fetch(); - $can_validate &= $d["version"] > 0; - - $req = $DB->prepare("SELECT COUNT(*) AS `version` FROM `documents` WHERE `user` = ? AND `tournament` = ? AND `type` = ?;"); - $req->execute([$team->getEncadrants()[$i - 1], $tournament->getId(), "SANITARY_PLUG"]); + if ($team->getEncadrantId() != null) { + $req = $DB->prepare("SELECT COUNT(*) AS `version` FROM `documents` WHERE `user` = ? AND `problem` = ? AND `type` = ?;"); + $req->execute([$team->getEncadrantId(), $team->getProblem(), "PHOTO_CONSENT"]); $d = $req->fetch(); $can_validate &= $d["version"] > 0; } + for ($i = 1; $i <= 6; ++$i) { if ($team->getParticipants()[$i] === NULL) continue; - $req = $DB->prepare("SELECT COUNT(*) AS `version` FROM `documents` WHERE `user` = ? AND `tournament` = ? AND `type` = ?;"); - $req->execute([$team->getParticipants()[$i], $tournament->getId(), "PHOTO_CONSENT"]); + $req = $DB->prepare("SELECT COUNT(*) AS `version` FROM `documents` WHERE `user` = ? AND `problem` = ? AND `type` = ?;"); + $req->execute([$team->getParticipants()[$i], $team->getProblem(), "PHOTO_CONSENT"]); $d = $req->fetch(); $can_validate &= $d["version"] > 0; - - $req = $DB->prepare("SELECT COUNT(*) AS `version` FROM `documents` WHERE `user` = ? AND `tournament` = ? AND `type` = ?;"); - $req->execute([$team->getParticipants()[$i], $tournament->getId(), "SANITARY_PLUG"]); - $d = $req->fetch(); - $can_validate &= $d["version"] > 0; - - $birth_date = $DB->query("SELECT `birth_date` FROM `users` WHERE `id` = " . $team->getParticipants()[$i] . ";")->fetch()["birth_date"]; - if ($birth_date > strval($YEAR - 18) . substr($tournament->getStartDate(), 4)) { - $req = $DB->prepare("SELECT COUNT(*) AS `version` FROM `documents` WHERE `user` = ? AND `tournament` = ? AND `type` = ?;"); - $req->execute([$team->getParticipants()[$i], $tournament->getId(), "PARENTAL_CONSENT"]); - $d = $req->fetch(); - $can_validate &= $d["version"] > 0; - } } return $can_validate; @@ -185,11 +139,9 @@ function printDocuments($documents) } } -function getZipFile($document_type, $tournament_id, $team_id = -1) +function getZipFile($problem, $team_id = -1) { - global $LOCAL_PATH; - - $tournament = Tournament::fromId($tournament_id); + global $LOCAL_PATH, $DB; $zip = new ZipArchive(); @@ -199,44 +151,16 @@ function getZipFile($document_type, $tournament_id, $team_id = -1) die("Impossible de créer le fichier zip."); } - switch ($document_type) { - case DocumentType::SOLUTION: - $data = $tournament->getAllSolutions($team_id); - break; - case DocumentType::SYNTHESIS: - $data = $tournament->getAllSyntheses($team_id); - break; - default: - $data = $tournament->getAllDocuments($team_id); - break; - } + // TODO Replace DB query + $resp = $DB->query("SELECT * FROM `documents` WHERE `problem` = $problem" . ($team_id >= 0 ? " AND `team` = $team_id" : "") . ";"); - /** @var Document | Solution | Synthesis $file */ - foreach ($data as $file) { + /** @var Document $file */ + //foreach ($data as $file) { + while (($data = $resp->fetch()) != false) { + $file = Document::fromData($data); $file_id = $file->getFileId(); - $team = Team::fromId($file->getTeamId()); - switch ($document_type) { - case DocumentType::SOLUTION: - $name = "Problème " . $file->getProblem() . " " . $team->getTrigram() . ".pdf"; - break; - case DocumentType::SYNTHESIS: - $name = "Note de synthèse " . $team->getTrigram() . " pour " . ($file->getDest() == DestType::OPPOSANT ? "l'opposant" : "le rapporteur") . ".pdf"; - break; - default: - $user = User::fromId($file->getUserId()); - switch ($file->getType()) { - case DocumentType::PARENTAL_CONSENT: - $name = "Autorisation parentale de " . $user->getFirstName() . " " . $user->getSurname() . ".pdf"; - break; - case DocumentType::PHOTO_CONSENT: - $name = "Autorisation de droit à l'image de " . $user->getFirstName() . " " . $user->getSurname() . ".pdf"; - break; - default: - $name = "Fiche sanitaire de " . $user->getFirstName() . " " . $user->getSurname() . ".pdf"; - break; - } - break; - } + $user = User::fromId($file->getUserId()); + $name = "Autorisation de droit à l'image de " . $user->getFirstName() . " " . $user->getSurname() . ".pdf"; $zip->addFile("$LOCAL_PATH/files/$file_id", $name); } diff --git a/server_files/services/mail.php b/server_files/services/mail.php index b11169a..d5df32c 100644 --- a/server_files/services/mail.php +++ b/server_files/services/mail.php @@ -75,7 +75,7 @@ class Mailer self::sendMail($user->getEmail(), "Mot de passe changé – Correspondances des Jeunes Mathématicien·ne·s", $content); } - public static function sendAddTeamMail(User $user, Team $team, $problem) + public static function sendAddTeamMail(User $user, Team $team) { global $YEAR; @@ -84,13 +84,13 @@ class Mailer $content = preg_replace("#{SURNAME}#", $user->getSurname(), $content); $content = preg_replace("#{TEAM_NAME}#", $team->getName(), $content); $content = preg_replace("#{TRIGRAM}#", $team->getTrigram(), $content); - $content = preg_replace("#{PROBLEM}#", $problem, $content); + $content = preg_replace("#{PROBLEM}#", $team->getProblem(), $content); $content = preg_replace("#{ACCESS_CODE}#", $team->getAccessCode(), $content); self::sendMail($user->getEmail(), "Ajout d'une équipe Correspondances des Jeunes Mathématicien·ne·s $YEAR", $content); } - public static function sendJoinTeamMail(User $user, Team $team, Tournament $tournament) + public static function sendJoinTeamMail(User $user, Team $team) { global $YEAR; @@ -99,32 +99,8 @@ class Mailer $content = preg_replace("#{SURNAME}#", $user->getSurname(), $content); $content = preg_replace("#{TEAM_NAME}#", $team->getName(), $content); $content = preg_replace("#{TRIGRAM}#", $team->getTrigram(), $content); - $content = preg_replace("#{TOURNAMENT_NAME}#", $tournament->getName(), $content); + $content = preg_replace("#{PROBLEM}#", $team->getProblem(), $content); self::sendMail($user->getEmail(), "Équipe rejointe Correspondances des Jeunes Mathématicien·ne·s $YEAR", $content); } - - public static function sendAddOrganizerMail(NewOrganizer $new_orga) - { - global $YEAR; - - $content = self::getTemplate("add_organizer"); - $content = preg_replace("#{FIRST_NAME}#", $new_orga->first_name, $content); - $content = preg_replace("#{SURNAME}#", $new_orga->surname, $content); - $content = preg_replace("#{PASSWORD}#", $new_orga->password, $content); - - self::sendMail($new_orga->email, "Ajout d'un organisateur – Correspondances des Jeunes Mathématicien·ne·s $YEAR", $content); - } - - public static function sendAddOrganizerForTournamentMail(User $organizer, Tournament $tournament) - { - global $YEAR; - - $content = self::getTemplate("add_organizer_for_tournament"); - $content = preg_replace("#{FIRST_NAME}#", $organizer->getFirstName(), $content); - $content = preg_replace("#{SURNAME}#", $organizer->getSurname(), $content); - $content = preg_replace("#{TOURNAMENT_NAME}#", $tournament->getName(), $content); - - self::sendMail($organizer->getEmail(), "Ajout d'un organisateur pour le tournoi " . $tournament->getName() . " – Correspondances des Jeunes Mathématicien·ne·s $YEAR", $content); - } } diff --git a/server_files/services/mail_templates/add_organizer.html b/server_files/services/mail_templates/add_organizer.html deleted file mode 100644 index 7847fe9..0000000 --- a/server_files/services/mail_templates/add_organizer.html +++ /dev/null @@ -1,21 +0,0 @@ - - -
- -