From 39abeec4e6e8ae8ab37920f16d23997a7693aebd Mon Sep 17 00:00:00 2001 From: Yohann Date: Tue, 3 Sep 2019 00:01:54 +0200 Subject: [PATCH] Support de la finale --- server_files/ajouter_tournoi.php | 25 ++++++-- server_files/config.php | 9 ++- server_files/equipe.php | 98 ++++++++++++++++++++++++++++-- server_files/mon_equipe.php | 101 ++++++++++++++++--------------- server_files/solutions.php | 13 ++-- server_files/solutions_orga.php | 5 +- server_files/syntheses.php | 13 ++-- server_files/syntheses_orga.php | 3 +- server_files/tournoi.php | 9 ++- server_files/tournois.php | 10 ++- 10 files changed, 210 insertions(+), 76 deletions(-) diff --git a/server_files/ajouter_tournoi.php b/server_files/ajouter_tournoi.php index 829edee..7c73a88 100644 --- a/server_files/ajouter_tournoi.php +++ b/server_files/ajouter_tournoi.php @@ -80,12 +80,17 @@ function registerTournament() { return "Une date est mal formée."; $description = htmlspecialchars($_POST["description"]); + + $final = isset($_POST["final"]) && $_POST["final"]; + + if ($final && $DB->query("SELECT `id` FROM `tournaments` WHERE `final` = true AND `year` = $YEAR;")->fetch() !== false) + return "Une finale est déjà enregistrée."; $req = $DB->prepare("INSERT INTO `tournaments` (`name`, `size`, `place`, `price`, `description`, - `date_start`, `date_end`, `date_inscription`, `date_solutions`, `date_syntheses`, `year`) - VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);"); + `date_start`, `date_end`, `date_inscription`, `date_solutions`, `date_syntheses`, `final`, `year`) + VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);"); $req->execute([$name, $size, $place, $price, $description, $date_start, $date_end, - "$date_inscription $time_inscription", "$date_solutions $time_solutions", "$date_syntheses $time_syntheses", $YEAR]); + "$date_inscription $time_inscription", "$date_solutions $time_solutions", "$date_syntheses $time_syntheses", $final, $YEAR]); $req = $DB->query("SELECT `id` FROM `tournaments` WHERE `name` = '$name' AND `year` = $YEAR;"); $tournament_id = $req->fetch()["id"]; @@ -175,7 +180,8 @@ if (!isset($_SESSION["role"]) or $_SESSION["role"] != "ADMIN") { - Du au + Du au + @@ -184,6 +190,7 @@ if (!isset($_SESSION["role"]) or $_SESSION["role"] != "ADMIN") { + @@ -193,6 +200,7 @@ if (!isset($_SESSION["role"]) or $_SESSION["role"] != "ADMIN") { + @@ -202,6 +210,7 @@ if (!isset($_SESSION["role"]) or $_SESSION["role"] != "ADMIN") { + @@ -213,6 +222,14 @@ if (!isset($_SESSION["role"]) or $_SESSION["role"] != "ADMIN") { + + + + + + + + diff --git a/server_files/config.php b/server_files/config.php index c90bb7a..2ee4d36 100644 --- a/server_files/config.php +++ b/server_files/config.php @@ -41,11 +41,18 @@ if (isset($_SESSION["user_id"])) { } if (isset($_SESSION["user_id"]) && isset($_SESSION["team_id"]) && $_SESSION["team_id"] != NULL) { - $response = $DB->query("SELECT `tournament`, `validation_status` FROM `teams` WHERE `id` ='" . $_SESSION["team_id"] . "' AND `year` = '$YEAR';"); + $response = $DB->query("SELECT `tournament`, `validation_status`, `final_selection` FROM `teams` WHERE `id` ='" . $_SESSION["team_id"] . "' AND `year` = '$YEAR';"); $data = $response->fetch(); $_SESSION["tournament_id"] = $data["tournament"]; $_SESSION["team_validation_status"] = $data["validation_status"]; } + + if ((isset($data["final_selection"]) && $data["final_selection"]) || $_SESSION["role"] == "ADMIN" || $_SESSION["role"] == "ORGANIZER") { + $response = $DB->query("SELECT `id`, `name` FROM `tournaments` WHERE `final` AND `year` = $YEAR;"); + $data = $response->fetch(); + $_SESSION["final_id"] = $data["id"]; + $_SESSION["final_name"] = $data["name"]; + } } setlocale(LC_ALL, "fr_FR.utf8"); diff --git a/server_files/equipe.php b/server_files/equipe.php index 5b945b2..60fe63f 100644 --- a/server_files/equipe.php +++ b/server_files/equipe.php @@ -10,13 +10,67 @@ if (isset($_POST["validate"])) { $team_data = $DB->query("SELECT * FROM `teams` WHERE `trigram` = '$trigram' AND `year` = $YEAR;")->fetch(); +if (isset($_POST["select"])) { + $DB->exec("UPDATE `teams` SET `final_selection` = true, `validation_status` = 'NOT_READY' WHERE `trigram` = '$trigram' AND `year` = $YEAR;"); + $team_data["validation_status"] = "NOT_READY"; + $team_data["final_selection"] = true; + $final_id = $_SESSION["final_id"]; + $team_id = $team_data["id"]; + + $sols_req = $DB->prepare("SELECT `file_id`, `problem`, COUNT(`problem`) AS `version` FROM `solutions` WHERE `team` = ? AND `tournament` = ? GROUP BY `problem`, `uploaded_at` ORDER BY `problem`, `uploaded_at` DESC;"); + $sols_req->execute([$team_data["id"], $team_data["tournament"]]); + while (($sol_data = $sols_req->fetch()) !== false) { + $old_id = $sol_data["file_id"]; + $alphabet = "abcdefghijklmnopqrstuvwxyz0123456789"; + + do { + $id = ""; + for ($i = 0; $i < 64; ++$i) { + $id .= $alphabet[rand(0, strlen($alphabet) - 1)]; + } + } + while (file_exists("$LOCAL_PATH/files/$id")); + + copy("$LOCAL_PATH/files/$old_id", "$LOCAL_PATH/files/$id"); + + $req = $DB->prepare("INSERT INTO `solutions`(`file_id`, `team`, `tournament`, `problem`) + VALUES (?, ?, ?, ?);"); + $req->execute([$id, $team_id, $_SESSION["final_id"], $sol_data["problem"]]); + } + + $syntheses_req = $DB->prepare("SELECT `file_id`, `dest`, COUNT(`dest`) AS `version` FROM `syntheses` WHERE `team` = ? AND `tournament` = ? GROUP BY `dest`, `uploaded_at` ORDER BY `dest`, `uploaded_at` DESC;"); + $syntheses_req->execute([$team_data["id"], $team_data["tournament"]]); + while (($synthese_data = $syntheses_req->fetch()) !== false) { + $old_id = $synthese_data["file_id"]; + $alphabet = "abcdefghijklmnopqrstuvwxyz0123456789"; + + do { + $id = ""; + for ($i = 0; $i < 64; ++$i) { + $id .= $alphabet[rand(0, strlen($alphabet) - 1)]; + } + } + while (file_exists("$LOCAL_PATH/files/$id")); + + copy("$LOCAL_PATH/files/$old_id", "$LOCAL_PATH/files/$id"); + + $req = $DB->prepare("INSERT INTO `syntheses`(`file_id`, `team`, `tournament`, `dest`) VALUES (?, ?, ?, ?);"); + $req->execute([$id, $team_id, $_SESSION["final_id"], $synthese_data["dest"]]); + } +} + if ($team_data === false) include "404.php"; $tournament_data = $DB->query("SELECT `name`, `date_start` FROM `tournaments` WHERE `id` = '" . $team_data["tournament"] . "' AND `year` = '$YEAR';")->fetch(); -$documents_req = $DB->prepare("SELECT `file_id`, `user`, `type`, COUNT(`type`) AS `version` FROM `documents` WHERE `team` = ? GROUP BY `user`, `type` ORDER BY `user`, `type` ASC, MAX(`uploaded_at`) DESC;"); -$documents_req->execute([$team_data["id"]]); +$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_data["id"], $team_data["tournament"]]); + +if ($team_data["final_selection"]) { + $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_data["id"], $_SESSION["final_id"]]); +} ?> @@ -42,6 +96,10 @@ for ($i = 1; $i <= 6; ++$i) { $id = $user_data["id"]; echo "Participant $i : " . $user_data["first_name"] . " " . $user_data["surname"] . "
"; } +if ($team_data["final_selection"]) { + $final_name = $_SESSION["final_name"]; + echo "Équipe sélectionnée pour la finale nationale."; +} ?>
@@ -72,11 +130,43 @@ while (($data = $documents_req->fetch()) !== false) { } ?> - +
+

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
"; + } +} if ($team_data["validation_status"] == "WAITING" && $_SESSION["role"] == "ADMIN") { ?>
- + +
+ +
+
diff --git a/server_files/mon_equipe.php b/server_files/mon_equipe.php index b853e37..4553d4e 100644 --- a/server_files/mon_equipe.php +++ b/server_files/mon_equipe.php @@ -42,9 +42,9 @@ if (isset($_POST["send_document"])) { } if (isset($_POST["request_validation"])) { - if (!checkCanValidate()) - $error_message = "Votre équipe ne peut pas demander la validation : il manque soit des participants, soit des documents."; - else { + if (!checkCanValidate()) + $error_message = "Votre équipe ne peut pas demander la validation : il manque soit des participants, soit des documents."; + else { $DB->exec("UPDATE `teams` SET `validation_status` = 'WAITING' WHERE `id` = " . $_SESSION["team_id"] . ";"); $_SESSION["team_validation_status"] = "WAITING"; } @@ -56,8 +56,8 @@ if (isset($_SESSION["user_id"]) && isset($_SESSION["team_id"])) { $tournament_data = $DB->query("SELECT `name`, `date_start` FROM `tournaments` WHERE `id` = '" . $team_data["tournament"] . "' AND `year` = '$YEAR';")->fetch(); - $documents_req = $DB->prepare("SELECT `file_id`, `type`, COUNT(`type`) AS `version` FROM `documents` WHERE `user` = ? GROUP BY `type`, `uploaded_at` ORDER BY `type`, `uploaded_at` DESC;"); - $documents_req->execute([$_SESSION["user_id"]]); + $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[isset($_SESSION["final_id"]) ? "final_id" : "tournament_id"]]); } if (isset($_POST["team_edit"])) { @@ -97,7 +97,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["tournament_id"], $type]); + $req->execute([$id, $_SESSION["user_id"], $_SESSION["team_id"], $_SESSION[isset($_SESSION["final_id"]) ? "final_id" : "tournament_id"], $type]); return false; } @@ -143,9 +143,10 @@ function updateTeam() return false; } -function checkCanValidate() { - global $DB, $team_data, $tournament_data, $YEAR; - $can_validate = $team_data["validation_status"] == "NOT_READY"; +function checkCanValidate() +{ + global $DB, $team_data, $tournament_data, $YEAR; + $can_validate = $team_data["validation_status"] == "NOT_READY"; $can_validate &= $team_data["encadrant_1"] != NULL; $can_validate &= $team_data["participant_4"] != NULL; for ($i = 1; $i <= 2; ++$i) { @@ -226,6 +227,10 @@ for ($i = 1; $i <= 6; ++$i) { } ?> Code d'accès :
+Équipe sélectionnée pour la finale nationale.
"; +} ?> @@ -278,28 +283,28 @@ Code d'accès :
Modifier mon équipe -
-

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
"; + +
+

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
"; + } + if ($team_data["validation_status"] == "NOT_READY") { ?>
@@ -334,28 +339,28 @@ Code d'accès :
-
- - - + +
+ +
+ + + - - - - -
+
+ +
+
- +
-
- -
-
- + + + diff --git a/server_files/solutions.php b/server_files/solutions.php index 4e4f85f..4699162 100644 --- a/server_files/solutions.php +++ b/server_files/solutions.php @@ -9,11 +9,11 @@ if (isset($_POST["send_solution"])) { $error_message = saveSolution(); } -$solutions_req = $DB->prepare("SELECT `file_id`, `problem`, COUNT(`problem`) AS `version` FROM `solutions` WHERE `team` = ? GROUP BY `problem`, `uploaded_at` ORDER BY `problem`, `uploaded_at` DESC;"); -$solutions_req->execute([$_SESSION["team_id"]]); +$solutions_req = $DB->prepare("SELECT `file_id`, `problem`, COUNT(`problem`) AS `version` FROM `solutions` WHERE `team` = ? AND `tournament` = ? GROUP BY `problem`, `uploaded_at` ORDER BY `problem`, `uploaded_at` DESC;"); +$solutions_req->execute([$_SESSION["team_id"], $_SESSION[isset($_SESSION["final_id"]) ? "final_id" : "tournament_id"]]); $tournament_req = $DB->prepare("SELECT `date_solutions` FROM `tournaments` WHERE `id` = ?;"); -$tournament_req->execute([$_SESSION["tournament_id"]]); +$tournament_req->execute([$_SESSION[isset($_SESSION["final_id"]) ? "final_id" : "tournament_id"]]); $tournament_data = $tournament_req->fetch(); function saveSolution() { @@ -52,8 +52,7 @@ function saveSolution() { if (!rename($file["tmp_name"], "$LOCAL_PATH/files/$id")) return "Une erreur est survenue lors de l'envoi du fichier."; - $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, $_SESSION["team_id"], $_SESSION["tournament_id"], $problem]); return false; @@ -74,14 +73,14 @@ function saveSolution() {
- +
- $i\n"; diff --git a/server_files/solutions_orga.php b/server_files/solutions_orga.php index 94a52fd..891e4be 100644 --- a/server_files/solutions_orga.php +++ b/server_files/solutions_orga.php @@ -54,7 +54,7 @@ $req = $DB->query("SELECT `tournaments`.`id`, `name` FROM `tournaments` JOIN `or while (($data_tournament = $req->fetch()) !== false) { echo "

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

\n"; $id = $data_tournament["id"]; - $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;"); + $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"]; @@ -70,8 +70,9 @@ while (($data_tournament = $req->fetch()) !== false) { " /> - + +
prepare("SELECT `file_id`, `dest`, COUNT(`dest`) AS `version` FROM `syntheses` WHERE `team` = ? GROUP BY `dest`, `uploaded_at` ORDER BY `dest`, `uploaded_at` DESC;"); -$syntheses_req->execute([$_SESSION["team_id"]]); +$syntheses_req = $DB->prepare("SELECT `file_id`, `dest`, COUNT(`dest`) AS `version` FROM `syntheses` WHERE `team` = ? AND `tournament` = ? GROUP BY `dest`, `uploaded_at` ORDER BY `dest`, `uploaded_at` DESC;"); +$syntheses_req->execute([$_SESSION["team_id"], $_SESSION[isset($_SESSION["final_id"]) ? "final_id" : "tournament_id"]]); $tournament_req = $DB->prepare("SELECT `date_solutions`, `date_syntheses` FROM `tournaments` WHERE `id` = ?;"); -$tournament_req->execute([$_SESSION["tournament_id"]]); +$tournament_req->execute([$_SESSION[isset($_SESSION["final_id"]) ? "final_id" : "tournament_id"]]); $tournament_data = $tournament_req->fetch(); function saveSynthese() { @@ -48,8 +48,7 @@ function saveSynthese() { if (!rename($file["tmp_name"], "$LOCAL_PATH/files/$id")) return "Une erreur est survenue lors de l'envoi du fichier."; - $req = $DB->prepare("INSERT INTO `syntheses`(`file_id`, `team`, `tournament`, `dest`) - VALUES (?, ?, ?, ?);"); + $req = $DB->prepare("INSERT INTO `syntheses`(`file_id`, `team`, `tournament`, `dest`) VALUES (?, ?, ?, ?);"); $req->execute([$id, $_SESSION["team_id"], $_SESSION["tournament_id"], $dest]); return false; @@ -77,14 +76,14 @@ if (isset($error_message)) {
- +
+ + + + + +
- diff --git a/server_files/syntheses_orga.php b/server_files/syntheses_orga.php index 322e07e..6e336b6 100644 --- a/server_files/syntheses_orga.php +++ b/server_files/syntheses_orga.php @@ -70,8 +70,9 @@ while (($data_tournament = $req->fetch()) !== false) { " /> - + +
diff --git a/server_files/tournoi.php b/server_files/tournoi.php index dac1568..4855e01 100644 --- a/server_files/tournoi.php +++ b/server_files/tournoi.php @@ -26,7 +26,10 @@ if (isset($_POST["edit_tournament"])) { $error_message = updateTournament(); } -$teams_response = $DB->query("SELECT `id`, `name`, `trigram`, `inscription_date`, `validation_status` FROM `teams` WHERE `tournament` = " . $data["id"] . " AND `year` = $YEAR;"); +if ($data["final"]) + $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` = " . $data["id"] . " AND `year` = $YEAR;"); $orgas_response = $DB->query("SELECT `id`, `surname`, `first_name` FROM `users` WHERE (`role` = 'ORGANIZER' OR `role` = 'ADMIN') AND `year` = '$YEAR';"); @@ -152,6 +155,10 @@ function updateTournament() { Date limite d'envoi des solutions :
Date limite d'envoi des notes de synthèse :
Description :
+ Ce tournoi est la finale nationale du TFJM² 2020.
"; + ?> /modifier">Éditer le tournoi diff --git a/server_files/tournois.php b/server_files/tournois.php index a5b04fb..5d33359 100644 --- a/server_files/tournois.php +++ b/server_files/tournois.php @@ -3,7 +3,8 @@ include 'config.php'; $response = $DB->query("SELECT `name`, `date_start`, `date_end`, `date_inscription`, `date_solutions`, `size` FROM `tournaments` - WHERE `year` = '$YEAR' ORDER BY `date_start`, `name`;"); + 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(); ?> @@ -35,6 +36,13 @@ $response = $DB->query("SELECT `name`, `date_start`, `date_end`, `date_inscripti +
">Du au