diff --git a/server_files/classes/User.php b/server_files/classes/User.php index 1cc6986..8e51187 100644 --- a/server_files/classes/User.php +++ b/server_files/classes/User.php @@ -258,13 +258,13 @@ class User $DB->prepare("UPDATE `users` SET `receive_animath_mails` = ? WHERE `id` = ?;")->execute([$receive_animath_mails ? 1 : 0, $this->getId()]); } - public function getAllDocuments($problem) + public function getAllDocuments() { global $DB; $req = $DB->query("SELECT * FROM `documents` AS `t1` " - . "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;"); + . "INNER JOIN (SELECT `user`, MAX(`uploaded_at`) AS `last_upload`, COUNT(`team`) AS `version` FROM `documents` GROUP BY `problem`, `user`) `t2` " + . "ON `t1`.`user` = `t2`.`user` " + . "WHERE `t1`.`uploaded_at` = `t2`.`last_upload` AND `t1`.`user` = $this->id;"); $docs = []; diff --git a/server_files/controllers/mon_compte.php b/server_files/controllers/mon_compte.php index 988600e..13c5326 100644 --- a/server_files/controllers/mon_compte.php +++ b/server_files/controllers/mon_compte.php @@ -5,6 +5,7 @@ if (!isset($_SESSION["user_id"])) /** @var User $user */ $user = $_SESSION["user"]; +$documents = $user->getAllDocuments(); $has_error = false; $error_message = null; @@ -33,6 +34,18 @@ if (isset($_POST["update_password"])) { } } +if (isset($_POST["send_document"])) { + $send_document = new SendDocument(); + try { + $send_document->makeVerifications(); + $send_document->sendDocument(); + } + catch (AssertionError $e) { + $has_error = true; + $error_message = $e->getMessage(); + } +} + class MyAccount { public $email; @@ -119,4 +132,40 @@ class NewPassword } } +class SendDocument +{ + private $file; + + public function __construct() + { + $this->file = $_FILES["document"]; + } + + public function makeVerifications() + { + global $LOCAL_PATH; + + ensure($this->file["size"] <= 2e6, "Le fichier doit peser moins que 2 Mo."); + ensure(!$this->file["error"], "Une erreur est survenue."); + ensure(finfo_file(finfo_open(FILEINFO_MIME_TYPE), $this->file["tmp_name"]) == "application/pdf", "Le fichier doit être au format PDF."); + ensure(is_dir("$LOCAL_PATH/files") || mkdir("$LOCAL_PATH/files"), "Un problème est survenue dans l'envoi du fichier. Veuillez contacter l'administrateur du serveur."); + } + + public function sendDocument() + { + global $LOCAL_PATH, $DB; + + do + $id = genRandomPhrase(64); + while (file_exists("$LOCAL_PATH/files/$id")); + + 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`) + VALUES (?, ?, ?, ?);"); + $req->execute([$id, $_SESSION["user_id"], $_SESSION["team"]->getId(), $_SESSION["team"]->getProblem()]); + } +} + require_once "server_files/views/mon_compte.php"; diff --git a/server_files/controllers/mon_equipe.php b/server_files/controllers/mon_equipe.php index 8469ab4..bdfe99e 100644 --- a/server_files/controllers/mon_equipe.php +++ b/server_files/controllers/mon_equipe.php @@ -8,18 +8,6 @@ if (isset($_POST["leave_team"])) { $has_error = false; $error_message = null; -if (isset($_POST["send_document"])) { - $send_document = new SendDocument(); - try { - $send_document->makeVerifications(); - $send_document->sendDocument(); - } - catch (AssertionError $e) { - $has_error = true; - $error_message = $e->getMessage(); - } -} - if (isset($_POST["team_edit"])) { $my_team = new MyTeam($_POST); try { @@ -45,7 +33,6 @@ if (isset($_POST["request_validation"])) { $_SESSION["team"]->setValidationStatus(ValidationStatus::WAITING); } -$documents = []; /** @var Question[][] $questions_received */ $questions_received = []; @@ -57,7 +44,7 @@ if (isset($_SESSION["user_id"]) && isset($_SESSION["team"]) && $_SESSION["team"] $user = $_SESSION["user"]; $team = $_SESSION["team"]; - $documents = $user->getAllDocuments($team->getProblem()); + $documents = $user->getAllDocuments(); } else require_once "server_files/403.php"; @@ -68,42 +55,6 @@ if (isset($_GET["publish_videos"])) { exit(); } -class SendDocument -{ - private $file; - - public function __construct() - { - $this->file = $_FILES["document"]; - } - - public function makeVerifications() - { - global $LOCAL_PATH; - - ensure($this->file["size"] <= 2e6, "Le fichier doit peser moins que 2 Mo."); - ensure(!$this->file["error"], "Une erreur est survenue."); - ensure(finfo_file(finfo_open(FILEINFO_MIME_TYPE), $this->file["tmp_name"]) == "application/pdf", "Le fichier doit être au format PDF."); - ensure(is_dir("$LOCAL_PATH/files") || mkdir("$LOCAL_PATH/files"), "Un problème est survenue dans l'envoi du fichier. Veuillez contacter l'administrateur du serveur."); - } - - public function sendDocument() - { - global $LOCAL_PATH, $DB; - - do - $id = genRandomPhrase(64); - while (file_exists("$LOCAL_PATH/files/$id")); - - 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`) - VALUES (?, ?, ?, ?);"); - $req->execute([$id, $_SESSION["user_id"], $_SESSION["team"]->getId(), $_SESSION["team"]->getProblem()]); - } -} - class MyTeam { public $name; diff --git a/server_files/views/mon_compte.php b/server_files/views/mon_compte.php index 5a8528c..fb9eb28 100644 --- a/server_files/views/mon_compte.php +++ b/server_files/views/mon_compte.php @@ -8,17 +8,17 @@ require_once "header.php"; + ?>
Votre compte a bien été mis à jour !
- getEmail() != $my_account->email) { ?> + getEmail() != $my_account->email) { ?>
Votre adresse mail a bien été changée. Veuillez vérifier votre boîte mail pour valider votre nouvelle adresse, vous en aurez besoin pour vous reconnecter.
- +
@@ -47,9 +47,9 @@ if (!$has_error && (isset($my_account) || isset($new_password))) { doReceiveAnimathMails() ? "checked" : "" ?> /> + doReceiveAnimathMails() ? "checked" : "" ?> /> - getRole() == Role::PARTICIPANT) { ?> + getRole() == Role::PARTICIPANT) { ?>
@@ -70,7 +70,7 @@ if (!$has_error && (isset($my_account) || isset($new_password))) {
- +
@@ -78,7 +78,7 @@ if (!$has_error && (isset($my_account) || isset($new_password))) { name="description">getDescription() ?>
- +
-
+
@@ -108,8 +108,35 @@ if (!$has_error && (isset($my_account) || isset($new_password))) {
- +
+
+
+

Autorisation de droit à l'image

+
+getValidationStatus() == ValidationStatus::NOT_READY) { ?> +
+ +
+
+ + +
+
+ +
+ +
+
+ + \ No newline at end of file diff --git a/server_files/views/mon_equipe.php b/server_files/views/mon_equipe.php index 1d54e6b..c380f90 100644 --- a/server_files/views/mon_equipe.php +++ b/server_files/views/mon_equipe.php @@ -101,28 +101,7 @@ require_once "header.php"; -
-

Autorisation de droit à l'image

-
- getValidationStatus() == ValidationStatus::NOT_READY) { ?> -
- -
-
- - -
-
- -
- -
-
- + getValidationStatus() == ValidationStatus::NOT_READY) { ?>