From 5a93a0a754fa28ee85380f3607493fedcadeac09 Mon Sep 17 00:00:00 2001 From: galaxyoyo Date: Sat, 7 Sep 2019 19:01:23 +0200 Subject: [PATCH] =?UTF-8?q?Correction=20de=20probl=C3=A8mes=20vis-=C3=A0-v?= =?UTF-8?q?is=20de=20l'envoi=20et=20le=20t=C3=A9l=C3=A9chargement=20de=20f?= =?UTF-8?q?ichiers?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dispatcher.php | 2 +- server_files/classes/Document.php | 8 +++---- server_files/controllers/solutions.php | 25 ++++++++++++--------- server_files/controllers/syntheses.php | 25 ++++++++++++--------- server_files/controllers/syntheses_orga.php | 2 +- server_files/controllers/view_file.php | 9 +++----- 6 files changed, 37 insertions(+), 34 deletions(-) diff --git a/dispatcher.php b/dispatcher.php index c14079f..3a9dfb4 100644 --- a/dispatcher.php +++ b/dispatcher.php @@ -32,7 +32,7 @@ $ROUTES["^confirmer_mail/([a-z0-9]*)/?$"] = ["server_files/controllers/confirmer $ROUTES["^connexion/?$"] = ["server_files/controllers/connexion.php"]; $ROUTES["^deconnexion/?$"] = ["server_files/controllers/deconnexion.php"]; $ROUTES["^equipe/([A-Z]{3})/?$"] = ["server_files/controllers/equipe.php", "trigram"]; -$ROUTES["^file/[a-z0-9]{64}/?$"] = ["server_files/controllers/view_file.php", "file_id"]; +$ROUTES["^file/([a-z0-9]{64})/?$"] = ["server_files/controllers/view_file.php", "file_id"]; $ROUTES["^informations/([0-9]*)/.*?$"] = ["server_files/controllers/informations.php", "id"]; $ROUTES["^inscription/?$"] = ["server_files/controllers/inscription.php"]; $ROUTES["^mon_compte/?$"] = ["server_files/controllers/mon_compte.php"]; diff --git a/server_files/classes/Document.php b/server_files/classes/Document.php index 32710e6..cfac1b9 100644 --- a/server_files/classes/Document.php +++ b/server_files/classes/Document.php @@ -80,7 +80,7 @@ class Solution public static function fromId($id) { global $DB; - $req = $DB->prepare("SELECT * FROM `documents` WHERE `file_id` = ?;"); + $req = $DB->prepare("SELECT * FROM `solutions` WHERE `file_id` = ?;"); $req->execute([htmlspecialchars($id)]); $data = $req->fetch(); @@ -95,8 +95,8 @@ class Solution private function fill($data) { $this->file_id = $data["file_id"]; - $this->team_id = $data["team_id"]; - $this->tournament_id = $data["tournament_id"]; + $this->team_id = $data["team"]; + $this->tournament_id = $data["tournament"]; $this->problem = $data["problem"]; $this->uploaded_at = $data["uploaded_at"]; } @@ -140,7 +140,7 @@ class Synthese public static function fromId($id) { global $DB; - $req = $DB->prepare("SELECT * FROM `documents` WHERE `file_id` = ?;"); + $req = $DB->prepare("SELECT * FROM `syntheses` WHERE `file_id` = ?;"); $req->execute([htmlspecialchars($id)]); $data = $req->fetch(); diff --git a/server_files/controllers/solutions.php b/server_files/controllers/solutions.php index 0357130..45bbb7d 100644 --- a/server_files/controllers/solutions.php +++ b/server_files/controllers/solutions.php @@ -3,20 +3,23 @@ if (!isset($_SESSION["team"])) require_once "server_files/403.php"; -if (isset($_POST["send_solution"])) { - $error_message = saveSolution(); -} - -/** @var Team $team */ +/** + * @var Team $team + * @var Tournament $tournament + */ $team = $_SESSION["team"]; - -$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([$team->getId(), $_SESSION[$team->isSelectedForFinal() ? $FINAL->getId() : $team->getTournamentId()]]); - $tournament = Tournament::fromId($team->isSelectedForFinal() ? $FINAL->getId() : $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()]); + function saveSolution() { - global $LOCAL_PATH, $DB; + global $LOCAL_PATH, $DB, $team, $tournament; try { $problem = $_POST["problem"]; @@ -52,7 +55,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, $_SESSION["team_id"], $_SESSION["tournament_id"], $problem]); + $req->execute([$id, $team->getId(), $tournament->getId(), $problem]); return false; } diff --git a/server_files/controllers/syntheses.php b/server_files/controllers/syntheses.php index 05886ee..1e3520f 100644 --- a/server_files/controllers/syntheses.php +++ b/server_files/controllers/syntheses.php @@ -3,20 +3,23 @@ if (!isset($_SESSION["team"])) require_once "server_files/403.php"; -if (isset($_POST["send_synthese"])) { - $error_message = saveSynthese(); -} - -/** @var Team $team */ +/** + * @var Team $team + * @var Tournament $tournament + */ $team = $_SESSION["team"]; - -$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->getId(), $_SESSION[$team->isSelectedForFinal() ? $FINAL->getId() : $team->getTournamentId()]]); - $tournament = Tournament::fromId($team->isSelectedForFinal() ? $FINAL->getId() : $team->getTournamentId()); +if (isset($_POST["send_synthese"])) { + $error_message = saveSynthese(); +} + +/** @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()]); + function saveSynthese() { - global $LOCAL_PATH, $DB; + global $LOCAL_PATH, $DB, $team, $tournament; $dest = strtoupper(htmlspecialchars($_POST["dest"])); @@ -48,7 +51,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, $_SESSION["team_id"], $_SESSION["tournament_id"], $dest]); + $req->execute([$id, $team->getId(), $tournament->getId(), $dest]); return false; } diff --git a/server_files/controllers/syntheses_orga.php b/server_files/controllers/syntheses_orga.php index f8f852b..16b1b77 100644 --- a/server_files/controllers/syntheses_orga.php +++ b/server_files/controllers/syntheses_orga.php @@ -31,7 +31,7 @@ if (isset($_POST["download_zip"])) { header("Content-Type: application/zip"); header("Content-Disposition: attachment; filename=\"Notes de syntèses du tournoi de $tournament_name.zip\""); - header("Content-Length: " . strval(filesize($temp) + 1)); + header("Content-Length: " . filesize($temp)); readfile($temp); diff --git a/server_files/controllers/view_file.php b/server_files/controllers/view_file.php index a20f6af..ed480a0 100644 --- a/server_files/controllers/view_file.php +++ b/server_files/controllers/view_file.php @@ -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 == "SYNTHESE") { + else if ($type == DocumentType::SYNTHESE) { $dest = $file->getDest(); $name = "Note de synthèse $trigram pour " . ($dest == DestType::OPPOSANT ? "l'opposant" : "le rapporteur") . ".pdf"; @@ -67,15 +67,12 @@ if ($file !== null) { $name .= " de $first_name $surname.pdf"; } } -else { +else require_once "server_files/404.php"; - http_response_code(404); - exit(); -} header("Content-Type: application/pdf"); header("Content-Disposition: inline; filename=\"$name\""); -readfile("$URL_BASE/files/$id"); +readfile("$LOCAL_PATH/files/$id"); exit(); \ No newline at end of file