diff --git a/assets/Autorisation de droit à l'image - majeur.pdf b/assets/Autorisation de droit à l'image - majeur.pdf new file mode 100644 index 0000000..b6d8d98 Binary files /dev/null and b/assets/Autorisation de droit à l'image - majeur.pdf differ diff --git a/assets/Autorisation de droit à l'image - mineur.pdf b/assets/Autorisation de droit à l'image - mineur.pdf new file mode 100644 index 0000000..ea380cb Binary files /dev/null and b/assets/Autorisation de droit à l'image - mineur.pdf differ diff --git a/dispatcher.php b/dispatcher.php index 09487ac..4a235cc 100644 --- a/dispatcher.php +++ b/dispatcher.php @@ -58,6 +58,8 @@ $ROUTES["^suivi-tournoi/?$"] = ["server_files/controllers/suivi_tournoi.php"]; # Assets files +$ROUTES["^Autorisation de droit à l'image - majeur.pdf$"] = ["assets/Autorisation de droit à l'image - majeur.pdf", "application/pdf"]; +$ROUTES["^Autorisation de droit à l'image - mineur.pdf$"] = ["assets/Autorisation de droit à l'image - mineur.pdf", "application/pdf"]; $ROUTES["^favicon\.ico$"] = ["assets/favicon.ico", "image/x-icon"]; $ROUTES["^logo\.png"] = ["assets/logo.png", "image/png"]; $ROUTES["^style\.css$"] = ["assets/style.css", "text/css"]; diff --git a/server_files/classes/Document.php b/server_files/classes/Document.php index 05e3977..bcfeca0 100644 --- a/server_files/classes/Document.php +++ b/server_files/classes/Document.php @@ -79,7 +79,7 @@ class Document $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 " . ($team_id >= 0 ? "AND `team` = $team_id" : "") . ";"); + . "WHERE `t1`.`uploaded_at` = `t2`.`last_upload` AND `t1`.`problem` = $problem " . ($team_id >= 0 ? "AND `team` = $team_id" : "") . " ORDER BY `t1`.`user`;"); $docs = []; diff --git a/server_files/controllers/equipe.php b/server_files/controllers/equipe.php index 51f7c68..6cefd75 100644 --- a/server_files/controllers/equipe.php +++ b/server_files/controllers/equipe.php @@ -18,6 +18,40 @@ elseif (isset($_POST["unvalidate"])) { $team->setValidationStatus(ValidationStatus::NOT_READY); Mailer::sendUnvalidateTeam($team); } +elseif (isset($_POST["select_problem"])) { + if ($team->getValidationStatus() == ValidationStatus::NOT_READY) { + $problem = $_POST["select_problem"]; + if (preg_match("#[0-4]#", $problem)) { + $team->setProblem($problem); + $DB->prepare("UPDATE `documents` SET `problem` = ? WHERE `team` = ?;")->execute([$problem, $team->getId()]); + } + else { + $has_error = true; + $error_message = "Le problème indiqué n'existe pas."; + } + } + else { + $has_error = true; + $error_message = "Cette équipe est déjà validée ou en cours de validation."; + } +} +elseif (isset($_POST["delete_team"])) { + if ($team->getValidationStatus() == ValidationStatus::NOT_READY) { + $documents = Document::getAllDocuments($team->getProblem(), $team->getId()); + /** @var Document $doc */ + foreach ($documents as $doc) + unlink($LOCAL_PATH . "/files/" . $doc->getFileId()); + $DB->prepare("DELETE FROM `documents` WHERE `team` = ?;")->execute([$team->getId()]); + $DB->prepare("DELETE FROM `teams` WHERE `id` = ?;")->execute([$team->getId()]); + $DB->prepare("UPDATE `users` SET `team_id` = NULL WHERE `team_id` = ?;")->execute([$team->getId()]); + header("Location: /"); + exit(0); + } + else { + $has_error = true; + $error_message = "Cette équipe est déjà validée ou en cours de validation."; + } +} if (isset($_POST["download_zip"])) { $file_name = getZipFile($team->getProblem(), $team->getId()); diff --git a/server_files/controllers/informations.php b/server_files/controllers/informations.php index 684de17..9e463f1 100644 --- a/server_files/controllers/informations.php +++ b/server_files/controllers/informations.php @@ -92,6 +92,6 @@ class AttributeTeam } if ($team != null) - $documents = $user->getAllDocuments($team->getProblem()); + $documents = $user->getAllDocuments(); require_once "server_files/views/informations.php"; diff --git a/server_files/controllers/mon_equipe.php b/server_files/controllers/mon_equipe.php index 75b510d..dd12ef0 100644 --- a/server_files/controllers/mon_equipe.php +++ b/server_files/controllers/mon_equipe.php @@ -29,8 +29,10 @@ if (isset($_POST["request_validation"])) { $has_error = true; $error_message = "Vous devez cocher la case qui vous engage à participer à l'intégralité des Correspondances."; } - else + else { $_SESSION["team"]->setValidationStatus(ValidationStatus::WAITING); + Mailer::sendRequestValidationMail($team); + } } /** @var Question[][] $questions_received */ @@ -95,6 +97,7 @@ class MyTeam $this->team->setProblem($this->problem); $DB->exec("UPDATE `teams` SET `problem` = " . $this->problem . " WHERE `id` = " . $this->team->getId() . ";"); + $DB->exec("UPDATE `documents` SET `problem` = " . $this->problem . " WHERE `team` = " . $this->team->getId() . ";"); header("Location: $URL_BASE/mon-equipe"); } diff --git a/server_files/model.php b/server_files/model.php index 27350bd..4316626 100644 --- a/server_files/model.php +++ b/server_files/model.php @@ -95,13 +95,6 @@ function canValidate(Team $team) $can_validate &= $team->getParticipants()[2] != null; $can_validate &= preg_match("#[1-4]#", $team->getProblem()); - if ($team->getEncadrantId() != null) { - $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; - } - for ($i = 1; $i <= 5; ++$i) { if ($team->getParticipants()[$i] === NULL) continue; diff --git a/server_files/services/mail.php b/server_files/services/mail.php index 07c854f..e2d2488 100644 --- a/server_files/services/mail.php +++ b/server_files/services/mail.php @@ -150,6 +150,19 @@ class Mailer self::sendMail($user->getEmail(), "Équipe rejointe – Correspondances des Jeunes Mathématicien·ne·s $YEAR", $content); } + public static function sendRequestValidationMail(Team $team) + { + global $YEAR; + + $content = self::getTemplate("request_validation"); + $content = preg_replace("#{TEAM_NAME}#", $team->getName(), $content); + $content = preg_replace("#{TRIGRAM}#", $team->getTrigram(), $content); + $content = preg_replace("#{PROBLEM}#", $team->getProblem(), $content); + $content = preg_replace("#{ACCESS_CODE}#", $team->getAccessCode(), $content); + + self::broadcastToAdmins("Ajout d'une équipe – Correspondances des Jeunes Mathématicien·ne·s $YEAR", $content); + } + public static function sendValidateTeam($team) { global $YEAR; diff --git a/server_files/services/mail_templates/request_validation.html b/server_files/services/mail_templates/request_validation.html new file mode 100644 index 0000000..137166e --- /dev/null +++ b/server_files/services/mail_templates/request_validation.html @@ -0,0 +1,19 @@ + + + +
+ +