mirror of
https://gitlab.com/animath/si/plateforme.git
synced 2025-06-26 05:17:39 +02:00
Améliorations du code
This commit is contained in:
@ -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";
|
||||
|
@ -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";
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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 "<h1>Tournoi de " . $data_tournament["name"] . "</h1>\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 : <a href=\"$URL_BASE/file/$file_id\">Télécharger</a><br />";
|
||||
}
|
||||
|
||||
echo "<form method=\"POST\">\n";
|
||||
echo "<input type=\"hidden\" name=\"tournament\" value=\"$id\" />\n";
|
||||
echo "<input type=\"hidden\" name=\"tournament_name\" value=\"" . $data_tournament["name"] . "\" />\n";
|
||||
echo "<input style=\"width: 100%\" type=\"submit\" name=\"download_zip\" value=\"Télécharger l'archive\" />\n";
|
||||
echo "</form><hr />\n";
|
||||
}
|
||||
|
||||
require_once "server_files/views/footer.php";
|
||||
require_once "server_files/views/solutions_orga.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;
|
||||
}
|
||||
|
@ -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 "<h1>Tournoi de " . $data_tournament["name"] . "</h1>\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 : <a href=\"$URL_BASE/file/$file_id\">Télécharger</a><br />";
|
||||
}
|
||||
|
||||
echo "<form method=\"POST\">\n";
|
||||
echo "<input type=\"hidden\" name=\"tournament\" value=\"$id\" />\n";
|
||||
echo "<input type=\"hidden\" name=\"tournament_name\" value=\"" . $data_tournament["name"] . "\" />\n";
|
||||
echo "<input style=\"width: 100%\" type=\"submit\" name=\"download_zip\" value=\"Télécharger l'archive\" />\n";
|
||||
echo "</form><hr />\n";
|
||||
}
|
||||
|
||||
require_once "server_files/views/footer.php";
|
||||
require_once "server_files/views/syntheses_orga.php";
|
@ -1,9 +1,7 @@
|
||||
<?php
|
||||
|
||||
$tournament_name = htmlspecialchars($_GET["name"]);
|
||||
|
||||
$tournament = Tournament::fromName($tournament_name);
|
||||
$orgas = $tournament->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;
|
||||
|
@ -1,7 +1,5 @@
|
||||
<?php
|
||||
|
||||
$response = $DB->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";
|
||||
|
@ -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";
|
||||
|
||||
|
Reference in New Issue
Block a user