From 2b1bb79efb0d02f76d0b9d43157c5cfa73a33b42 Mon Sep 17 00:00:00 2001 From: galaxyoyo Date: Wed, 25 Sep 2019 01:08:38 +0200 Subject: [PATCH] Corrections mineurs --- server_files/classes/Document.php | 4 ++-- server_files/classes/User.php | 6 +++--- server_files/controllers/mon_equipe.php | 10 ++++------ server_files/model.php | 8 ++++---- server_files/views/mon_equipe.php | 12 +++++++++--- setup/create_database.sql | 1 - 6 files changed, 22 insertions(+), 19 deletions(-) diff --git a/server_files/classes/Document.php b/server_files/classes/Document.php index 2c14f08..6b8cbaf 100644 --- a/server_files/classes/Document.php +++ b/server_files/classes/Document.php @@ -84,8 +84,8 @@ class Document { global $DB; $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` " + . "INNER JOIN (SELECT `user`, `problem`, MAX(`uploaded_at`) AS `last_upload`, COUNT(`team`) AS `version` FROM `documents` GROUP BY `problem`, `user`) `t2` " + . "ON `t1`.`user` = `t2`.`user` AND `t1`.`problem` = `t2`.`problem` " . "WHERE `t1`.`uploaded_at` = `t2`.`last_upload` AND `t1`.`problem` = $problem " . ($team_id >= 0 ? "AND `team` = $team_id" : "") . " ORDER BY `t1`.`type`;"); $docs = []; diff --git a/server_files/classes/User.php b/server_files/classes/User.php index 6af19d2..91fac07 100644 --- a/server_files/classes/User.php +++ b/server_files/classes/User.php @@ -247,9 +247,9 @@ class User { global $DB; $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 AND `t1`.`user` = $this->id ORDER BY `t1`.`type`;"); + . "INNER JOIN (SELECT `user`, `problem`, MAX(`uploaded_at`) AS `last_upload`, COUNT(`team`) AS `version` FROM `documents` GROUP BY `problem`, `user`) `t2` " + . "ON `t1`.`user` = `t2`.`user` AND `t1`.`problem` = `t2`.`problem` " + . "WHERE `t1`.`uploaded_at` = `t2`.`last_upload` AND `t1`.`problem` = $problem AND `t1`.`user` = $this->id;"); $docs = []; diff --git a/server_files/controllers/mon_equipe.php b/server_files/controllers/mon_equipe.php index 47c8d21..a4cc332 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)) { + if (!canValidate($_SESSION["team"])) { $has_error = true; $error_message = "Votre équipe ne peut pas demander la validation : il manque soit des participants, soit des documents."; } @@ -73,12 +73,10 @@ if (isset($_GET["publish_videos"])) { class SendDocument { private $file; - private $type; public function __construct() { $this->file = $_FILES["document"]; - $this->type = strtoupper(htmlspecialchars($_POST["type"])); } public function makeVerifications() @@ -102,9 +100,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`, `problem`, `type`) - VALUES (?, ?, ?, ?, ?);"); - $req->execute([$id, $_SESSION["user_id"], $_SESSION["team"]->getId(), $_SESSION["team"]->getProblem(), $this->type]); + $req = $DB->prepare("INSERT INTO `documents`(`file_id`, `user`, `team`, `problem`) + VALUES (?, ?, ?, ?);"); + $req->execute([$id, $_SESSION["user_id"], $_SESSION["team"]->getId(), $_SESSION["team"]->getProblem()]); } } diff --git a/server_files/model.php b/server_files/model.php index 444e85f..27a814a 100644 --- a/server_files/model.php +++ b/server_files/model.php @@ -94,8 +94,8 @@ function canValidate(Team $team) $can_validate &= $team->getParticipants()[2] != null; 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"]); + $req = $DB->prepare("SELECT COUNT(*) AS `version` FROM `documents` WHERE `user` = ? AND `problem` = ?;"); + $req->execute([$team->getEncadrantId(), $team->getProblem()]); $d = $req->fetch(); $can_validate &= $d["version"] > 0; } @@ -104,8 +104,8 @@ function canValidate(Team $team) if ($team->getParticipants()[$i] === NULL) continue; - $req = $DB->prepare("SELECT COUNT(*) AS `version` FROM `documents` WHERE `user` = ? AND `problem` = ? AND `type` = ?;"); - $req->execute([$team->getParticipants()[$i], $team->getProblem(), "PHOTO_CONSENT"]); + $req = $DB->prepare("SELECT COUNT(*) AS `version` FROM `documents` WHERE `user` = ? AND `problem` = ?;"); + $req->execute([$team->getParticipants()[$i], $team->getProblem()]); $d = $req->fetch(); $can_validate &= $d["version"] > 0; } diff --git a/server_files/views/mon_equipe.php b/server_files/views/mon_equipe.php index ab625e9..56ca4d7 100644 --- a/server_files/views/mon_equipe.php +++ b/server_files/views/mon_equipe.php @@ -133,14 +133,20 @@ require_once "header.php"; +
-
+ +
- = Phase::PHASE1) { ?> + getValidationStatus() == ValidationStatus::WAITING) { ?> +
+ Votre équipe est en attente de validation. +
+ = Phase::PHASE1) { ?>

Déroulement du tournoi

diff --git a/setup/create_database.sql b/setup/create_database.sql index 2701fca..0283c8a 100644 --- a/setup/create_database.sql +++ b/setup/create_database.sql @@ -47,7 +47,6 @@ CREATE TABLE IF NOT EXISTS `documents` ( `user` int(11) NOT NULL, `team` int(11) NOT NULL, `problem` int(11) NOT NULL, - `type` varchar(64) NOT NULL, `uploaded_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`file_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;