diff --git a/server_files/classes/Document.php b/server_files/classes/Document.php index cfac1b9..575daa6 100644 --- a/server_files/classes/Document.php +++ b/server_files/classes/Document.php @@ -8,6 +8,7 @@ class Document private $tournament_id; private $type; private $uploaded_at; + private $version; private function __construct() {} @@ -21,9 +22,14 @@ class Document if ($data === false) return null; - $user = new Document(); - $user->fill($data); - return $user; + return self::fromData($data); + } + + public static function fromData($data) + { + $doc = new Document(); + $doc->fill($data); + return $doc; } private function fill($data) @@ -34,6 +40,7 @@ class Document $this->tournament_id = $data["tournament"]; $this->type = DocumentType::fromName($data["type"]); $this->uploaded_at = $data["uploaded_at"]; + $this->version = isset($data["version"]) ? $data["version"] : 1; } public function getFileId() @@ -65,6 +72,11 @@ class Document { return $this->uploaded_at; } + + public function getVersion() + { + return $this->version; + } } class Solution @@ -74,6 +86,7 @@ class Solution private $tournament_id; private $problem; private $uploaded_at; + private $version; private function __construct() {} @@ -87,9 +100,14 @@ class Solution if ($data === false) return null; - $user = new Solution(); - $user->fill($data); - return $user; + return self::fromData($data); + } + + public static function fromData($data) + { + $sol = new Solution(); + $sol->fill($data); + return $sol; } private function fill($data) @@ -99,6 +117,7 @@ class Solution $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() @@ -125,15 +144,21 @@ class Solution { return $this->uploaded_at; } + + public function getVersion() + { + return $this->version; + } } -class Synthese +class Synthesis { private $file_id; private $team_id; private $tournament_id; private $dest; private $uploaded_at; + private $version; private function __construct() {} @@ -147,9 +172,14 @@ class Synthese if ($data === false) return null; - $user = new Synthese(); - $user->fill($data); - return $user; + return self::fromData($data); + } + + public static function fromData($data) + { + $synthese = new Synthesis(); + $synthese->fill($data); + return $synthese; } private function fill($data) @@ -159,6 +189,7 @@ class Synthese $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() @@ -185,6 +216,11 @@ class Synthese { return $this->uploaded_at; } + + public function getVersion() + { + return $this->version; + } } class DestType @@ -233,7 +269,7 @@ class DocumentType const PHOTO_CONSENT = 1; const SANITARY_PLUG = 2; const SOLUTION = 3; - const SYNTHESE = 4; + const SYNTHESIS = 4; public static function getTranslatedName($type) { switch ($type) { @@ -261,7 +297,7 @@ class DocumentType case self::SOLUTION: return "SOLUTION"; default: - return "SYNTHESE"; + return "SYNTHESIS"; } } @@ -276,7 +312,7 @@ class DocumentType case "SOLUTION": return self::SOLUTION; default: - return self::SYNTHESE; + return self::SYNTHESIS; } } } \ No newline at end of file diff --git a/server_files/classes/Tournament.php b/server_files/classes/Tournament.php index 2461b3f..8b2cff0 100644 --- a/server_files/classes/Tournament.php +++ b/server_files/classes/Tournament.php @@ -1,22 +1,25 @@ 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"]; @@ -223,6 +248,22 @@ class Tournament $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; @@ -242,4 +283,55 @@ class Tournament { 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`) `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 a694170..1852ea7 100644 --- a/server_files/classes/User.php +++ b/server_files/classes/User.php @@ -359,4 +359,33 @@ class User { return $this->inscription_date; } + + public function getAllDocuments($tournament_id) + { + 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`) `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`;"); + + $docs = []; + + while (($data = $req->fetch()) !== false) + $docs[] = Document::fromData($data); + + 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/equipe.php b/server_files/controllers/equipe.php index 02d2462..1f52f94 100644 --- a/server_files/controllers/equipe.php +++ b/server_files/controllers/equipe.php @@ -6,6 +6,7 @@ if (!isset($_SESSION["user_id"]) || $_SESSION["role"] != Role::ORGANIZER && $_SE $trigram = htmlspecialchars($_GET["trigram"]); $team = Team::fromTrigram($trigram); +$tournament = Tournament::fromId($team->getTournamentId()); if ($team === null) require_once "server_files/404.php"; @@ -35,20 +36,17 @@ if (isset($_POST["select"])) { copy("$LOCAL_PATH/files/$old_id", "$LOCAL_PATH/files/$id"); - $req = $DB->prepare("INSERT INTO `solutions`(`file_id`, `team`, `tournament`, `problem`) - VALUES (?, ?, ?, ?);"); + $req = $DB->prepare("INSERT INTO `solutions`(`file_id`, `team`, `tournament`, `problem`) VALUES (?, ?, ?, ?);"); $req->execute([$id, $team->getId(), $_SESSION["final_id"], $sol_data["problem"]]); } } -$documents_req = $DB->prepare("SELECT `file_id`, `user`, `type`, COUNT(`type`) AS `version` FROM `documents` WHERE `team` = ? AND `tournament` = ? GROUP BY `user`, `type` ORDER BY `user`, `type` ASC, MAX(`uploaded_at`) DESC;"); -$documents_req->execute([$team->getId(), $team->getId()]); +// TODO Télécharger en zip les documents personnels -if ($team->isSelectedForFinal()) { - $documents_final_req = $DB->prepare("SELECT `file_id`, `user`, `type`, COUNT(`type`) AS `version` FROM `documents` WHERE `team` = ? AND `tournament` != ? GROUP BY `user`, `type` ORDER BY `user`, `type` ASC, MAX(`uploaded_at`) DESC;"); - $documents_final_req->execute([$team->getId(), $FINAL->getId()]); -} +$documents = $tournament->getAllDocuments($team->getId()); +$documents_final = null; -$tournament = Tournament::fromId($team->getTournamentId()); +if ($team->isSelectedForFinal()) + $documents_final = $FINAL->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 ff34005..9b076e2 100644 --- a/server_files/controllers/informations.php +++ b/server_files/controllers/informations.php @@ -11,13 +11,16 @@ if ($_SESSION["role"] != Role::ORGANIZER && $_SESSION["role"] != Role::ADMIN) { require_once "server_files/403.php"; } -if ($user === null) { +if ($user === null) require_once "server_files/404.php"; -} $team = Team::fromId($user->getTeamId()); +$tournaments = $user->getOrganizedTournaments(); -$documents_req = $DB->query("SELECT * FROM `documents` WHERE `user` = $id;"); -$tournaments_req = $DB->query("SELECT `tournament`, `name` FROM `organizers` JOIN `tournaments` ON `tournaments`.`id` = `tournament` WHERE `organizer` = $id ORDER BY `date_start`, `name`;"); +if ($team != null) { + $documents = $user->getAllDocuments($team->getTournamentId()); + if ($team->isSelectedForFinal()) + $documents_final = $user->getAllDocuments($FINAL->getId()); +} require_once "server_files/views/informations.php"; diff --git a/server_files/controllers/mon_equipe.php b/server_files/controllers/mon_equipe.php index 5af190f..8dd4d8c 100644 --- a/server_files/controllers/mon_equipe.php +++ b/server_files/controllers/mon_equipe.php @@ -5,7 +5,7 @@ if (isset($_POST["leave_team"])) { exit(); } -$tournaments_response = $DB->query("SELECT `id`, `name` FROM `tournaments` WHERE `year` = '$YEAR';"); +$tournaments = Tournament::getAllTournaments(false, true); if (isset($_POST["send_document"])) { $error_message = sendDocument(); @@ -19,13 +19,17 @@ if (isset($_POST["request_validation"])) { } if (isset($_SESSION["user_id"]) && isset($_SESSION["team"]) && $_SESSION["team"] !== null) { - /** @var Team $team */ + /** + * @var User $user + * @var Team $team + */ + $user = $_SESSION["user"]; $team = $_SESSION["team"]; $tournament = Tournament::fromId($team->getTournamentId()); - - $documents_req = $DB->prepare("SELECT `file_id`, `type`, COUNT(`type`) AS `version` FROM `documents` WHERE `user` = ? AND `tournament` = ? GROUP BY `type`, `uploaded_at` ORDER BY `type`, `uploaded_at` DESC;"); - $documents_req->execute([$_SESSION["user_id"], $_SESSION[$team->isSelectedForFinal() ? $FINAL->getId() : $tournament->getId()]]); + $documents = $user->getAllDocuments($team->getTournamentId()); + if ($team->isSelectedForFinal()) + $documents_final = $user->getAllDocuments($FINAL->getId()); } else require_once "server_files/403.php"; @@ -36,7 +40,7 @@ if (isset($_POST["team_edit"])) { function sendDocument() { - global $LOCAL_PATH, $DB; + global $LOCAL_PATH, $DB, $FINAL; $type = strtoupper(htmlspecialchars($_POST["type"])); if (!isset($type) || ($type != "PARENTAL_CONSENT" && $type != "PHOTO_CONSENT" && $type != "SANITARY_PLUG")) @@ -67,7 +71,7 @@ function sendDocument() $req = $DB->prepare("INSERT INTO `documents`(`file_id`, `user`, `team`, `tournament`, `type`) VALUES (?, ?, ?, ?, ?);"); - $req->execute([$id, $_SESSION["user_id"], $_SESSION["team_id"], $_SESSION[isset($_SESSION["final_id"]) ? "final_id" : "tournament_id"], $type]); + $req->execute([$id, $_SESSION["user_id"], $_SESSION["team"]->getId(), $_SESSION["team"]->isSelectedForFinal() ? $FINAL->getId() : $_SESSION["team"]->getTournamentId(), $type]); return false; } diff --git a/server_files/controllers/solutions.php b/server_files/controllers/solutions.php index 45bbb7d..34f471d 100644 --- a/server_files/controllers/solutions.php +++ b/server_files/controllers/solutions.php @@ -8,18 +8,19 @@ if (!isset($_SESSION["team"])) * @var Tournament $tournament */ $team = $_SESSION["team"]; -$tournament = Tournament::fromId($team->isSelectedForFinal() ? $FINAL->getId() : $team->getTournamentId()); +$tournament = Tournament::fromId($team->getTournamentId()); if (isset($_POST["send_solution"])) { $error_message = saveSolution(); } -/** @noinspection SqlAggregates */ -$solutions_req = $DB->prepare("SELECT `file_id`, `problem`, COUNT(`problem`) AS `version` FROM `solutions` WHERE `team` = ? AND `tournament` = ? GROUP BY `problem` ORDER BY `problem`, `uploaded_at` DESC;"); -$solutions_req->execute([$team->getId(), $tournament->getId()]); +$solutions = $tournament->getAllSolutions($team->getId()); +$solutions_final = null; +if ($team->isSelectedForFinal()) + $solutions_final = $FINAL->getAllSolutions($team->getId()); function saveSolution() { - global $LOCAL_PATH, $DB, $team, $tournament; + global $LOCAL_PATH, $DB, $team, $tournament, $FINAL; try { $problem = $_POST["problem"]; @@ -55,7 +56,7 @@ function saveSolution() { return "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(), $tournament->getId(), $problem]); + $req->execute([$id, $team->getId(), $team->isSelectedForFinal() ? $FINAL->getId() : $tournament->getId(), $problem]); return false; } diff --git a/server_files/controllers/solutions_orga.php b/server_files/controllers/solutions_orga.php index c049dba..69c9445 100644 --- a/server_files/controllers/solutions_orga.php +++ b/server_files/controllers/solutions_orga.php @@ -3,16 +3,10 @@ if (!isset($_SESSION["role"]) || $_SESSION["role"] != Role::ADMIN && $_SESSION["role"] != Role::ORGANIZER) require_once "server_files/403.php"; -/** @noinspection SqlAggregates */ -$req = $DB->query("SELECT `tournaments`.`id`, `name` FROM `tournaments` JOIN `organizers` ON `tournament` = `tournaments`.`id` WHERE " - . ($_SESSION["role"] == Role::ADMIN ? "" : "`organizer` = '" . $_SESSION["user_id"] . "' AND ") - . "`year` = $YEAR GROUP BY `tournament` ORDER BY `name`;"); - if (isset($_POST["download_zip"])) { $id = $_POST["tournament"]; - $tournament_name = $_POST["tournament_name"]; - /** @noinspection SqlAggregates */ - $files_req = $DB->query("SELECT *, COUNT(`problem`) AS `version` FROM `solutions` WHERE `tournament` = '$id' GROUP BY `team`, `problem` ORDER BY `team`, `problem`, `uploaded_at` DESC;"); + $tournament = Tournament::fromId($id); + $sols = $tournament->getAllSolutions(); $zip = new ZipArchive(); @@ -22,12 +16,12 @@ if (isset($_POST["download_zip"])) { die("Impossible de créer le fichier zip."); } - while (($data_file = $files_req->fetch()) !== false) { - $file_id = $data_file["file_id"]; - $problem = $data_file["problem"]; - $version = $data_file["version"]; - $team_id = $data_file["team"]; - $team = Team::fromId($team_id); + /** @var Solution $sol */ + foreach ($sols as $sol) { + $file_id = $sol->getFileId(); + $problem = $sol->getProblem(); + $version = $sol->getVersion(); + $team = Team::fromId($sol->getTeamId()); $team_name = $team->getName(); $team_trigram = $team->getTrigram(); @@ -37,7 +31,7 @@ if (isset($_POST["download_zip"])) { $zip->close(); header("Content-Type: application/zip"); - header("Content-Disposition: attachment; filename=\"Solutions du tournoi de $tournament_name.zip\""); + header("Content-Disposition: attachment; filename=\"Solutions du tournoi de " . $tournament->getName() . ".zip\""); header("Content-Length: " . strval(filesize($temp))); readfile($temp); @@ -45,29 +39,7 @@ if (isset($_POST["download_zip"])) { exit(); } -require_once "server_files/views/header.php"; +$user = $_SESSION["user"]; +$tournaments = $_SESSION["role"] == Role::ADMIN ? Tournament::getAllTournaments() : $user->getOrganizedTournaments(); -while (($data_tournament = $req->fetch()) !== false) { - echo "

Tournoi de " . $data_tournament["name"] . "

\n"; - $id = $data_tournament["id"]; - /** @noinspection SqlAggregates */ - $files_req = $DB->query("SELECT *, COUNT(`problem`) AS `version` FROM `solutions` WHERE `tournament` = '$id' GROUP BY `team` ORDER BY `team`, `problem`, `uploaded_at` DESC;"); - while (($data_file = $files_req->fetch()) !== false) { - $file_id = $data_file["file_id"]; - $problem = $data_file["problem"]; - $version = $data_file["version"]; - $team_id = $data_file["team"]; - $team = Team::fromId($team_id); - $team_name = $team->getName(); - $team_trigram = $team->getTrigram(); - echo "Problème n°$problem de l'équipe $team_name ($team_trigram), version $version : Télécharger
"; - } - - echo "
\n"; - echo "\n"; - echo "\n"; - echo "\n"; - echo "

\n"; -} - -require_once "server_files/views/footer.php"; +require_once "server_files/views/solutions_orga.php"; diff --git a/server_files/controllers/syntheses.php b/server_files/controllers/syntheses.php index 1e3520f..65a2327 100644 --- a/server_files/controllers/syntheses.php +++ b/server_files/controllers/syntheses.php @@ -8,18 +8,19 @@ if (!isset($_SESSION["team"])) * @var Tournament $tournament */ $team = $_SESSION["team"]; -$tournament = Tournament::fromId($team->isSelectedForFinal() ? $FINAL->getId() : $team->getTournamentId()); +$tournament = Tournament::fromId($team->getTournamentId()); -if (isset($_POST["send_synthese"])) { - $error_message = saveSynthese(); +if (isset($_POST["send_synthesis"])) { + $error_message = saveSynthesis(); } -/** @noinspection SqlAggregates */ -$syntheses_req = $DB->prepare("SELECT `file_id`, `dest`, COUNT(`dest`) AS `version` FROM `syntheses` WHERE `team` = ? AND `tournament` = ? GROUP BY `dest` ORDER BY `dest`, `uploaded_at` DESC;"); -$syntheses_req->execute([$team->getId(), $tournament->getId()]); +$syntheses = $tournament->getAllSyntheses($team->getId()); +$syntheses_final = null; +if ($team->isSelectedForFinal()) + $syntheses_final = $FINAL->getAllSyntheses($team->getId()); -function saveSynthese() { - global $LOCAL_PATH, $DB, $team, $tournament; +function saveSynthesis() { + global $LOCAL_PATH, $DB, $team, $tournament, $FINAL; $dest = strtoupper(htmlspecialchars($_POST["dest"])); @@ -51,7 +52,7 @@ function saveSynthese() { return "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(), $tournament->getId(), $dest]); + $req->execute([$id, $team->getId(), $team->isSelectedForFinal() ? $FINAL->getId() : $tournament->getId(), $dest]); return false; } diff --git a/server_files/controllers/syntheses_orga.php b/server_files/controllers/syntheses_orga.php index 16b1b77..6973c30 100644 --- a/server_files/controllers/syntheses_orga.php +++ b/server_files/controllers/syntheses_orga.php @@ -3,9 +3,8 @@ if (isset($_POST["download_zip"])) { $id = $_POST["tournament"]; - $tournament_name = $_POST["tournament_name"]; - /** @noinspection SqlAggregates */ - $files_req = $DB->query("SELECT *, COUNT(`dest`) AS `version` FROM `syntheses` WHERE `tournament` = '$id' GROUP BY `team`, `dest` ORDER BY `team`, `dest`, `uploaded_at` DESC;"); + $tournament = Tournament::fromId($id); + $syntheses = $tournament->getAllSyntheses(); $zip = new ZipArchive(); @@ -15,22 +14,22 @@ if (isset($_POST["download_zip"])) { die("Impossible de créer le fichier zip."); } - while (($data_file = $files_req->fetch()) !== false) { - $file_id = $data_file["file_id"]; - $dest = $data_file["dest"]; - $version = $data_file["version"]; - $team_id = $data_file["team"]; - $team = Team::fromId($team_id); + /** @var Synthesis $synthesis */ + foreach ($syntheses as $synthesis) { + $file_id = $synthesis->getFileId(); + $dest = $synthesis->getDest(); + $version = $synthesis->getVersion(); + $team = Team::fromId($synthesis->getTeamId()); $team_name = $team->getName(); $team_trigram = $team->getTrigram(); - $zip->addFile("$LOCAL_PATH/files/$file_id", "Note de synthèse $team_trigram pour " . ($dest == "OPPOSANT" ? "l'opposant" : "le rapporteur") . ".pdf"); + $zip->addFile("$LOCAL_PATH/files/$file_id", "Note de synthèse $team_trigram pour " . ($dest == DestType::OPPOSANT ? "l'opposant" : "le rapporteur") . ".pdf"); } $zip->close(); header("Content-Type: application/zip"); - header("Content-Disposition: attachment; filename=\"Notes de syntèses du tournoi de $tournament_name.zip\""); + header("Content-Disposition: attachment; filename=\"Notes de syntèses du tournoi de " . $tournament->getName() . ".zip\""); header("Content-Length: " . filesize($temp)); readfile($temp); @@ -38,33 +37,7 @@ if (isset($_POST["download_zip"])) { exit(); } -require_once "server_files/views/header.php"; +$user = $_SESSION["user"]; +$tournaments = $_SESSION["role"] == Role::ADMIN ? Tournament::getAllTournaments() : $user->getOrganizedTournaments(); -$req = $DB->query("SELECT `tournaments`.`id`, `name` FROM `tournaments` JOIN `organizers` ON `tournament` = `tournaments`.`id` WHERE " - . ($_SESSION["role"] == Role::ADMIN ? "" : "`organizer` = '" . $_SESSION["user_id"] . "' AND ") - . "`year` = $YEAR GROUP BY `tournament`, `name` ORDER BY `name`;"); - -while (($data_tournament = $req->fetch()) !== false) { - echo "

Tournoi de " . $data_tournament["name"] . "

\n"; - $id = $data_tournament["id"]; - $files_req = $DB->query("SELECT *, COUNT(`dest`) AS `version` FROM `syntheses` WHERE `tournament` = '$id' GROUP BY `team`, `dest`, `uploaded_at` ORDER BY `team`, `dest`, `uploaded_at` DESC;"); - while (($data_file = $files_req->fetch()) !== false) { - $file_id = $data_file["file_id"]; - $dest = $data_file["dest"]; - $version = $data_file["version"]; - $team_id = $data_file["team"]; - $team = Team::fromId($team_id); - $team_name = $team->getName(); - $team_trigram = $team->getTrigram(); - echo "Note de synthèse de l'équipe $team_name ($team_trigram) pour " . ($dest == "OPPOSANT" ? "l'opposant" : "le rapporteur") - . ", version $version : Télécharger
"; - } - - echo "
\n"; - echo "\n"; - echo "\n"; - echo "\n"; - echo "

\n"; -} - -require_once "server_files/views/footer.php"; +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 index e478229..36d9e46 100644 --- a/server_files/controllers/tournoi.php +++ b/server_files/controllers/tournoi.php @@ -1,9 +1,7 @@ getOrganizers(); if ($tournament === null) require_once "server_files/404.php"; @@ -14,13 +12,8 @@ if (isset($_GET["modifier"]) && $_SESSION["role"] != Role::ADMIN && !$tournament if (isset($_POST["edit_tournament"])) { $error_message = updateTournament(); } - -if ($tournament->isFinal()) - $teams_response = $DB->query("SELECT `id`, `name`, `trigram`, `inscription_date`, `validation_status` FROM `teams` WHERE `final_selection` AND `year` = $YEAR;"); -else - $teams_response = $DB->query("SELECT `id`, `name`, `trigram`, `inscription_date`, `validation_status` FROM `teams` WHERE `tournament` = " . $tournament->getId() . " AND `year` = $YEAR;"); - -$orgas_response = $DB->query("SELECT `id`, `surname`, `first_name` FROM `users` WHERE (`role` = 'ORGANIZER' OR `role` = 'ADMIN') AND `year` = '$YEAR';"); +$orgas = $tournament->getOrganizers(); +$teams = $tournament->getAllTeams(); function updateTournament() { global $DB, $URL_BASE, $YEAR, $tournament, $orgas; diff --git a/server_files/controllers/tournois.php b/server_files/controllers/tournois.php index ce23d82..db4c402 100644 --- a/server_files/controllers/tournois.php +++ b/server_files/controllers/tournois.php @@ -1,7 +1,5 @@ query("SELECT `name`, `date_start`, `date_end`, `date_inscription`, `date_solutions`, `size` FROM `tournaments` - WHERE `year` = '$YEAR' AND `final` = false ORDER BY `date_start`, `name`;"); -$final_data = $DB->query("SELECT `name`, `date_start`, `date_end`, `date_solutions`, `size` FROM `tournaments` WHERE `final` AND `year` = $YEAR;")->fetch(); +$tournaments = Tournament::getAllTournaments(); require_once "server_files/views/tournois.php"; diff --git a/server_files/controllers/view_file.php b/server_files/controllers/view_file.php index ed480a0..14aa853 100644 --- a/server_files/controllers/view_file.php +++ b/server_files/controllers/view_file.php @@ -13,8 +13,8 @@ $id = htmlspecialchars($_GET["file_id"]); $type = DocumentType::SOLUTION; $file = Solution::fromId($id); if ($file === null) { - $type = DocumentType::SYNTHESE; - $file = Synthese::fromId($id); + $type = DocumentType::SYNTHESIS; + $file = Synthesis::fromId($id); if ($file === null) { $file = Document::fromId($id); @@ -37,7 +37,7 @@ if ($file !== null) { 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::SYNTHESE) { + else if ($type == DocumentType::SYNTHESIS) { $dest = $file->getDest(); $name = "Note de synthèse $trigram pour " . ($dest == DestType::OPPOSANT ? "l'opposant" : "le rapporteur") . ".pdf"; diff --git a/server_files/model.php b/server_files/model.php index afe6503..ed0005d 100644 --- a/server_files/model.php +++ b/server_files/model.php @@ -119,4 +119,18 @@ function tournamentExists($name) { $req = $DB->prepare("SELECT `id` FROM `tournaments` WHERE `name` = ? AND `year` = '$YEAR';"); $req->execute([$name]); return $req->fetch(); +} + +function printDocuments($documents) { + global $URL_BASE; + + foreach ($documents as $document) { + $file_id = $document->getFileId(); + $user = User::fromId($document->getUserId()); + $surname = $user->getSurname(); + $first_name = $user->getFirstName(); + $name = DocumentType::getTranslatedName($document->getType()); + $version = $document->getVersion(); + echo "$name de $first_name $surname (version $version) : Télécharger
"; + } } \ No newline at end of file diff --git a/server_files/views/equipe.php b/server_files/views/equipe.php index e3b2f1e..a1ddb8f 100644 --- a/server_files/views/equipe.php +++ b/server_files/views/equipe.php @@ -1,10 +1,10 @@ -

Informations sur l'équipe

+

Informations sur l'équipe

-Nom de l'équipe : getName() ?>
-Trigramme : getTrigram() ?>
-Tournoi : getName() ?>">getName() ?>
+ Nom de l'équipe : getName() ?>
+ Trigramme : getTrigram() ?>
+ Tournoi : getName() ?>">getName() ?>
getEncadrants()[$i] == NULL) @@ -26,72 +26,37 @@ if ($team->isSelectedForFinal()) { } ?> -
+
-

Autorisations

+

Autorisations

-fetch()) !== false) { - $file_id = $data["file_id"]; - $type = $data["type"]; - $user_id = $data["user"]; - $user_data = $DB->query("SELECT `surname`, `first_name` FROM `users` WHERE `id` = '$user_id';")->fetch(); - $surname = $user_data["surname"]; - $first_name = $user_data["first_name"]; - $version = $data["version"]; - switch ($data["type"]) { - case "PARENTAL_CONSENT": - $name = "Autorisation parentale"; - break; - case "PHOTO_CONSENT": - $name = "Autorisation de droit à l'image"; - break; - case "SANITARY_PLUG": - $name = "Fiche sanitaire"; - break; - } - echo "$name de $first_name $surname : Télécharger
"; -} -?> + + +
+ +
isSelectedForFinal()) { ?> -
-

Autorisations pour la finale

- fetch()) !== false) { - $file_id = $data["file_id"]; - $type = $data["type"]; - $user_id = $data["user"]; - $user_data = $DB->query("SELECT `surname`, `first_name` FROM `users` WHERE `id` = '$user_id';")->fetch(); - $surname = $user_data["surname"]; - $first_name = $user_data["first_name"]; - $version = $data["version"]; - switch ($data["type"]) { - case "PARENTAL_CONSENT": - $name = "Autorisation parentale"; - break; - case "PHOTO_CONSENT": - $name = "Autorisation de droit à l'image"; - break; - case "SANITARY_PLUG": - $name = "Fiche sanitaire"; - break; - } - echo "$name de $first_name $surname : Télécharger
"; - } -} +
+

Autorisations pour la finale

+ +
+ +
+ -if ($team->getValidationStatus() == ValidationStatus::WAITING && $_SESSION["role"] == Role::ADMIN) { ?> -
- -
+getValidationStatus() == ValidationStatus::WAITING && $_SESSION["role"] == Role::ADMIN) { ?> +
+ +
isSelectedForFinal() && isset($_SESSION["user_id"]) && $_SESSION["role"] == Role::ADMIN) { ?> -
- -
+if (!$team->isSelectedForFinal() && $_SESSION["role"] == Role::ADMIN) { ?> +
+
+ +
\ No newline at end of file diff --git a/server_files/views/informations.php b/server_files/views/informations.php index 1a332f4..275f868 100644 --- a/server_files/views/informations.php +++ b/server_files/views/informations.php @@ -13,21 +13,7 @@ Numéro de téléphone : getPhoneNumber() ?>
getRole() == Role::PARTICIPANT) { ?> Lycée : getSchool() ?>
- Classe : getClass()) { - case "TERMINALE": - echo "Terminale"; - break; - case "PREMIERE": - echo "Première"; - break; - case "SECONDE": - echo "Seconde ou avant"; - break; - default: - echo "A hacké le site"; - break; - } - ?>
+ Classe : getClass()) ?>
Nom du responsable légal : getResponsibleName() ?>
Numéro de téléphone du responsable légal : getResponsiblePhone() ?>
Adresse e-mail du responsable légal : getResponsibleEmail() ?> @@ -38,34 +24,21 @@ Numéro de téléphone : getPhoneNumber() ?>
echo "
"; if ($user->getRole() == Role::ADMIN || $user->getRole() == Role::ORGANIZER) { - while (($tournament_data = $tournaments_req->fetch()) !== false) { - echo "Organise le tournoi " . $tournament_data["name"] . "
"; + foreach ($tournaments as $tournament) { + echo "Organise le tournoi getName(). "\">" . $tournament->getName() . "
"; } } elseif ($user->getRole() == Role::PARTICIPANT || $user->getRole() == Role::ENCADRANT) { ?>

Autorisations

- fetch()) !== false) { - $file_id = $data["file_id"]; - $type = $data["type"]; - $user_id = $data["user"]; - $user_data = $DB->query("SELECT `surname`, `first_name` FROM `users` WHERE `id` = '$user_id';")->fetch(); - $surname = $user_data["surname"]; - $first_name = $user_data["first_name"]; - $version = $data["version"]; - switch ($data["type"]) { - case "PARENTAL_CONSENT": - $name = "Autorisation parentale"; - break; - case "PHOTO_CONSENT": - $name = "Autorisation de droit à l'image"; - break; - case "SANITARY_PLUG": - $name = "Fiche sanitaire"; - break; - } - echo "$name de $first_name $surname : Télécharger
"; - } + isSelectedForFinal()) { ?> +
+

Autorisations pour la finale

+ -

Informations sur l'équipe

+

Informations sur l'équipe

-Nom de l'équipe : getName() ?>
-Trigramme : getTrigram() ?>
-Tournoi : getName() ?>
+ Nom de l'équipe : getName() ?>
+ Trigramme : getTrigram() ?>
+ Tournoi : getName() ?>
getEncadrants()[$i] == NULL) @@ -31,7 +31,7 @@ for ($i = 1; $i <= 6; ++$i) { echo "Participant $i : getFirstName() . " " . $participant->getSurname() . "\">" . $participant->getFirstName() . " " . $participant->getSurname() . "
"; } ?> -Code d'accès : getAccessCode() ?>
+ Code d'accès : getAccessCode() ?>
isSelectedForFinal()) { $final_name = $FINAL->getName(); echo "Équipe sélectionnée pour la finale nationale.
"; @@ -39,133 +39,125 @@ Code d'accès : getAccessCode() ?>
-
- - - - - - - - - - - - - - + + + + + +
- - - -
- - - -
- - - + + + + + + + + + + + + + - - - - - -
+ + + +
+ + + +
+ + + -
- -
- + +
+ +
+ - - Modifier mon équipe + + Modifier mon équipe -
-

Mes autorisations

+
+

Mes autorisations

fetch()) !== false) { - $file_id = $data["file_id"]; - $type = $data["type"]; - $version = $data["version"]; - switch ($data["type"]) { - case "PARENTAL_CONSENT": - $name = "Autorisation parentale"; - break; - case "PHOTO_CONSENT": - $name = "Autorisation de droit à l'image"; - break; - case "SANITARY_PLUG": - $name = "Fiche sanitaire"; - break; - } - echo "$name : Télécharger
"; + printDocuments($documents); + + if ($team->isSelectedForFinal()) { ?> +
+

Mes autorisations pour la finale

+ getValidationStatus() == ValidationStatus::NOT_READY) { ?> -
- - - - - - + + + + + + + + + +
- - - + + + + + - - - - - - - - - -
+ + + -
- - - -
- -
- + + + +
+ + + +
+ +
+ -
getValidationStatus() == ValidationStatus::NOT_READY) { ?> - - - +
+
-
- -
-
+ + - + - -
+
+ +
+
-
- -
-
+
+ +
+
+ + diff --git a/server_files/views/solutions.php b/server_files/views/solutions.php index a44fcc3..4312d55 100644 --- a/server_files/views/solutions.php +++ b/server_files/views/solutions.php @@ -7,56 +7,70 @@ if (isset($error_message)) { } else { echo "

Le fichier a été correctement envoyé !

"; } -}?> +} ?> getSolutionsDate()) { ?> -
- - - - - - + + + + + + + + + +
- - - + + + + + - - - - - - - - - -
+ + + -
- - - -
- -
- + +
+ + + +
+ +
+ -
+
-

Solutions soumises :

+

Solutions soumises :

fetch()) !== false) { - $file_id = $data["file_id"]; - $problem = $data["problem"]; - $version = $data["version"]; +/** @var Solution $sol */ +foreach ($solutions as $sol) { + $file_id = $sol->getFileId(); + $problem = $sol->getProblem(); + $version = $sol->getVersion(); echo "Problème $problem (Version $version) : Télécharger
"; } +if ($team->isSelectedForFinal()) { ?> +
+ +

Solutions soumises pour la finale :

+ getFileId(); + $problem = $sol->getProblem(); + $version = $sol->getVersion(); + echo "Problème $problem (Version $version) : Télécharger
"; + } +} require_once "footer.php"; diff --git a/server_files/views/solutions_orga.php b/server_files/views/solutions_orga.php new file mode 100644 index 0000000..989d719 --- /dev/null +++ b/server_files/views/solutions_orga.php @@ -0,0 +1,25 @@ +Tournoi de " . $tournament->getName() . "\n"; + $sols = $tournament->getAllSolutions(); + /** @var Solution $sol */ + foreach ($sols as $sol) { + $file_id = $sol->getFileId(); + $problem = $sol->getProblem(); + $version = $sol->getVersion(); + $team = Team::fromId($sol->getTeamId()); + $team_name = $team->getName(); + $team_trigram = $team->getTrigram(); + echo "Problème n°$problem de l'équipe $team_name ($team_trigram), version $version : Télécharger
"; + } + + echo "
\n"; + echo "getId() . "\" />\n"; + echo "\n"; + echo "

\n"; +} + +require_once "server_files/views/footer.php"; \ No newline at end of file diff --git a/server_files/views/syntheses.php b/server_files/views/syntheses.php index e1daaf9..fe9edf1 100644 --- a/server_files/views/syntheses.php +++ b/server_files/views/syntheses.php @@ -41,7 +41,7 @@ if (isset($error_message)) { - + @@ -54,11 +54,26 @@ if (isset($error_message)) {

Notes de synthèse soumises :

fetch()) !== false) { - $file_id = $data["file_id"]; - $dest = $data["dest"]; - $version = $data["version"]; - echo "Note de synthèse pour " . ($dest == "OPPOSANT" ? "l'opposant" : "le rapporteur") . " (Version $version) : Télécharger
"; +/** @var Synthesis $synthesis */ +foreach ($syntheses as $synthesis) { + $file_id = $synthesis->getFileId(); + $dest = $synthesis->getDest(); + $version = $synthesis->getVersion(); + echo "Note de synthèse pour " . ($dest == DestType::OPPOSANT ? "l'opposant" : "le rapporteur") . " (version $version) : Télécharger
"; +} + +if ($team->isSelectedForFinal()) { ?> +
+ +

Notes de synthèse soumises pour la finale :

+ getFileId(); + $dest = $synthesis->getDest(); + $version = $synthesis->getVersion(); + echo "Note de synthèse pour " . ($dest == DestType::OPPOSANT ? "l'opposant" : "le rapporteur") . " (version $version) : Télécharger
"; + } } require_once "footer.php"; \ No newline at end of file diff --git a/server_files/views/syntheses_orga.php b/server_files/views/syntheses_orga.php new file mode 100644 index 0000000..2912be6 --- /dev/null +++ b/server_files/views/syntheses_orga.php @@ -0,0 +1,27 @@ +Tournoi de " . $tournament->getName() . "\n"; + $syntheses = $tournament->getAllSyntheses(); + /** @var Synthesis $synthesis */ + foreach ($syntheses as $synthesis) { + $file_id = $synthesis->getFileId(); + $dest = $synthesis->getDest(); + $version = $synthesis->getVersion(); + $team = Team::fromId($synthesis->getTeamId()); + $team_name = $team->getName(); + $team_trigram = $team->getTrigram(); + echo "Note de synthèse de l'équipe $team_name ($team_trigram) pour " . ($dest == DestType::OPPOSANT ? "l'opposant" : "le rapporteur") + . ", version $version : Télécharger
"; + } + + echo "
\n"; + echo "getId() . "\" />\n"; + echo "\n"; + echo "

\n"; +} + +require_once "server_files/views/footer.php"; diff --git a/server_files/views/tournoi.php b/server_files/views/tournoi.php index 1e5ec28..904f671 100644 --- a/server_files/views/tournoi.php +++ b/server_files/views/tournoi.php @@ -31,7 +31,7 @@ if ($tournament->isFinal()) echo "Ce tournoi est la finale nationale du TFJM² 2020.
"; ?> - +organize($_SESSION["user_id"]))) { ?> Éditer le tournoi @@ -60,38 +60,21 @@ if ($tournament->isFinal()) fetch()) != false) { + /** @var Team $team */ + foreach ($teams as $team) { ?> " . $team_data["name"] . ""; + if (isset($_SESSION["role"]) && ($_SESSION["role"] == Role::ADMIN || ($_SESSION["role"] == Role::ORGANIZER && $tournament->organize($_SESSION["user_id"])))) + echo "getTrigram() . "\">" . $team->getName(). ""; else - echo $team_data["name"]; - ?> - - - - - getName(); ?> + getTrigram() ?> + getInscriptionDate()) ?> + getValidationStatus()) ?> fetch()) !== FALSE) { - echo "\n"; } ?> diff --git a/server_files/views/tournois.php b/server_files/views/tournois.php index 13fffae..e631025 100644 --- a/server_files/views/tournois.php +++ b/server_files/views/tournois.php @@ -5,7 +5,7 @@ - + @@ -14,29 +14,22 @@ fetch()) !== FALSE) { + foreach ($tournaments as $tournament) { ?> - - - - - + + + + + - - - - - - - - +
LieuNom Dates Inscription avant le Date de rendu des solutions
">Du au getName() ?>Du getStartDate()) ?> au getEndDate()) ?>getSolutionsDate()) ?>getSynthesesDate()) ?>getSize() ?>
">Du au
LieuNom Dates Inscription avant le Date de rendu des solutions