From 95d7f305360f31af34a8e619d00cc85e92c76aef Mon Sep 17 00:00:00 2001 From: Yohann Date: Wed, 4 Dec 2019 11:45:14 +0100 Subject: [PATCH] =?UTF-8?q?Possibilit=C3=A9=20d'encadrer=20plusieurs=20?= =?UTF-8?q?=C3=A9quipes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/codeStyles/Project.xml | 9 ++++ .idea/codeStyles/codeStyleConfig.xml | 5 +++ dispatcher.php | 6 +++ server_files/classes/Team.php | 16 +++++++ server_files/classes/User.php | 14 ++++++ server_files/config.php | 2 +- server_files/controllers/ajouter_equipe.php | 12 +++-- .../controllers/commenter_echange.php | 16 +++++-- server_files/controllers/envoyer_video.php | 16 +++++-- server_files/controllers/informations.php | 6 +-- server_files/controllers/ma_participation.php | 12 +++-- server_files/controllers/mon_equipe.php | 12 +++-- server_files/controllers/poser_questions.php | 11 ++++- server_files/controllers/rejoindre_equipe.php | 3 +- .../controllers/repondre_questions.php | 14 +++++- server_files/model.php | 9 +++- server_files/views/ajouter_equipe.php | 8 +++- server_files/views/header.php | 45 +++++++++++++------ server_files/views/mon_equipe.php | 5 +++ server_files/views/rejoindre_equipe.php | 6 +++ 20 files changed, 185 insertions(+), 42 deletions(-) create mode 100644 .idea/codeStyles/Project.xml create mode 100644 .idea/codeStyles/codeStyleConfig.xml diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..8f9a506 --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,9 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 0000000..79ee123 --- /dev/null +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/dispatcher.php b/dispatcher.php index b682605..3422fb8 100644 --- a/dispatcher.php +++ b/dispatcher.php @@ -35,6 +35,7 @@ $ROUTES["^ajouter-admin$"] = ["server_files/controllers/ajouter_admin.php"]; $ROUTES["^calendrier/(modifier)$"] = ["server_files/controllers/calendrier.php", "edit"]; $ROUTES["^calendrier/?$"] = ["server_files/controllers/calendrier.php"]; $ROUTES["^commenter-echange-4$"] = ["server_files/controllers/commenter_echange.php"]; +$ROUTES["^commenter-echange-4/([A-Z]{3})$"] = ["server_files/controllers/commenter_echange.php", "trigram"]; $ROUTES["^confirmer-mail/([a-z0-9]*)/?$"] = ["server_files/controllers/confirmer_mail.php", "token"]; $ROUTES["^connexion/(confirmation-mail)/?$"] = ["server_files/controllers/connexion.php", "confirmation-mail"]; $ROUTES["^connexion/(mdp-oublie)/?$"] = ["server_files/controllers/connexion.php", "mdp_oublie"]; @@ -42,6 +43,7 @@ $ROUTES["^connexion/(reinitialiser_mdp)/(.*)/?$"] = ["server_files/controllers/c $ROUTES["^connexion/?$"] = ["server_files/controllers/connexion.php"]; $ROUTES["^deconnexion/?$"] = ["server_files/controllers/deconnexion.php"]; $ROUTES["^envoyer-video-1$"] = ["server_files/controllers/envoyer_video.php"]; +$ROUTES["^envoyer-video-1/([A-Z]{3})$"] = ["server_files/controllers/envoyer_video.php", "trigram"]; $ROUTES["^equipe/([A-Z]{3})/?$"] = ["server_files/controllers/equipe.php", "trigram"]; $ROUTES["^exporter-donnees/?$"] = ["server_files/controllers/exporter_donnees.php"]; $ROUTES["^file/([a-z0-9]{64})/?$"] = ["server_files/controllers/view_file.php", "file_id"]; @@ -51,12 +53,16 @@ $ROUTES["^mon-compte/?$"] = ["server_files/controllers/mon_compte.php"]; $ROUTES["^mon-equipe/(diffusion-videos)/?$"] = ["server_files/controllers/mon_equipe.php", "publish_videos"]; $ROUTES["^mon-equipe/(modifier)/?$"] = ["server_files/controllers/mon_equipe.php", "modifier"]; $ROUTES["^mon-equipe/?$"] = ["server_files/controllers/mon_equipe.php"]; +$ROUTES["^mon-equipe/([A-Z]{3})/?$"] = ["server_files/controllers/mon_equipe.php", "trigram"]; $ROUTES["^ma-participation/?$"] = ["server_files/controllers/ma_participation.php"]; +$ROUTES["^ma-participation/([A-Z]{3})/?$"] = ["server_files/controllers/ma_participation.php", "trigram"]; $ROUTES["^poser-questions-2$"] = ["server_files/controllers/poser_questions.php"]; +$ROUTES["^poser-questions-2/([A-Z]{3})$"] = ["server_files/controllers/poser_questions.php", "trigram"]; $ROUTES["^probleme/([0-4])/?$"] = ["server_files/controllers/probleme.php", "probleme"]; $ROUTES["^profils-orphelins/?$"] = ["server_files/controllers/profils_orphelins.php"]; $ROUTES["^rejoindre-equipe/?$"] = ["server_files/controllers/rejoindre_equipe.php"]; $ROUTES["^repondre-questions-3$"] = ["server_files/controllers/repondre_questions.php"]; +$ROUTES["^repondre-questions-3/([A-Z]{3})$"] = ["server_files/controllers/repondre_questions.php"]; $ROUTES["^suivi-correspondances/?$"] = ["server_files/controllers/suivi_correspondances.php"]; # Assets files diff --git a/server_files/classes/Team.php b/server_files/classes/Team.php index a5e75f2..bf610d8 100644 --- a/server_files/classes/Team.php +++ b/server_files/classes/Team.php @@ -221,4 +221,20 @@ class Team { return $this->year; } + + public function getAllDocuments() + { + global $DB; + $req = $DB->query("SELECT * FROM `documents` AS `t1` " + . "INNER JOIN (SELECT `team`, MAX(`uploaded_at`) AS `last_upload`, COUNT(`user`) AS `version` FROM `documents` GROUP BY `problem`, `user`, `team`) `t2` " + . "ON `t1`.`team` = `t2`.`team` " + . "WHERE `t1`.`uploaded_at` = `t2`.`last_upload` AND `t1`.`team` = $this->id;"); + + $docs = []; + + while (($data = $req->fetch()) !== false) + $docs[] = Document::fromData($data); + + return $docs; + } } diff --git a/server_files/classes/User.php b/server_files/classes/User.php index 3cf143c..36b37e8 100644 --- a/server_files/classes/User.php +++ b/server_files/classes/User.php @@ -301,4 +301,18 @@ class User return $docs; } + + // Seulement pour les encadrants + public function getTeams() + { + global $DB; + $req = $DB->query("SELECT `id` FROM `teams` WHERE `encadrant` = $this->id;"); + + $teams = []; + + while (($data =$req->fetch()) !== false) + $teams[] = Team::fromId($data["id"]); + + return $teams; + } } \ No newline at end of file diff --git a/server_files/config.php b/server_files/config.php index 51ee8e8..155f878 100644 --- a/server_files/config.php +++ b/server_files/config.php @@ -214,7 +214,7 @@ class Config { global $DB, $YEAR; - if (isset($_SESSION["user_id"]) && $_SESSION["role"] == Role::ADMIN) + if (isset($_SESSION["user_id"]) && $_SESSION["role"] == Role::ADMIN || isset($_SESSION["admin"])) return; $DB->exec("UPDATE `config` SET `value` = " . ($this->views + 1) . " WHERE `key` = 'views_$YEAR';"); diff --git a/server_files/controllers/ajouter_equipe.php b/server_files/controllers/ajouter_equipe.php index 5995607..234d341 100644 --- a/server_files/controllers/ajouter_equipe.php +++ b/server_files/controllers/ajouter_equipe.php @@ -41,7 +41,7 @@ class NewTeam { global $CONFIG; ensure(date("Y-m-d H:i:s") < $CONFIG->getInscriptionDate(), "La date limite d'inscription est dépassée."); - ensure($_SESSION["team"] == null, "Vous êtes déjà dans une équipe."); + ensure($_SESSION["team"] == null || $_SESSION["role"] == Role::ENCADRANT, "Vous êtes déjà dans une équipe."); ensure($this->name != null && $this->name != "", "Vous devez spécifier un nom d'équipe."); ensure(preg_match("#^[\p{L} ]+$#ui", $this->name), "Le nom de l'équipe ne doit pas comporter de caractères spéciaux."); ensure(preg_match("#^[A-Z]{3}$#", $this->trigram), "Le trigramme entré n'est pas valide."); @@ -61,10 +61,14 @@ class NewTeam { $req->execute([$this->name, $this->trigram, $this->problem, $_SESSION["role"] == Role::ENCADRANT ? $_SESSION["user_id"] : NULL, $_SESSION["role"] == Role::PARTICIPANT ? $_SESSION["user_id"] : NULL, $this->allow_publish, ValidationStatus::getName(ValidationStatus::NOT_READY), $this->access_code, $YEAR]); - $_SESSION["team"] = Team::fromTrigram($this->trigram); - $_SESSION["user"]->setTeamId($_SESSION["team"]->getId()); + $_SESSION["teams"] = $_SESSION["user"]->getTeams(); + $team = Team::fromTrigram($this->trigram); + if ($_SESSION["role"] == Role::PARTICIPANT) { + $_SESSION["team"] = $team; + $_SESSION["user"]->setTeamId($_SESSION["team"]->getId()); + } - Mailer::sendAddTeamMail($_SESSION["user"], $_SESSION["team"]); + Mailer::sendAddTeamMail($_SESSION["user"], $team); } } diff --git a/server_files/controllers/commenter_echange.php b/server_files/controllers/commenter_echange.php index 5e5a32d..bfa4c6a 100644 --- a/server_files/controllers/commenter_echange.php +++ b/server_files/controllers/commenter_echange.php @@ -1,9 +1,19 @@ getRole() == Role::PARTICIPANT ? $_SESSION["team"] : Team::fromTrigram($_GET["trigram"]); + +if ($team == null) + require_once "server_files/404.php"; + +if ($team->getEncadrantId() != $user->getId() || $team->getValidationStatus() != ValidationStatus::VALIDATED) require_once "server_files/403.php"; if (isset($_POST["upload_answer"])) { diff --git a/server_files/controllers/envoyer_video.php b/server_files/controllers/envoyer_video.php index 72a119f..1de3c6b 100644 --- a/server_files/controllers/envoyer_video.php +++ b/server_files/controllers/envoyer_video.php @@ -1,9 +1,19 @@ getValidationStatus() != ValidationStatus::VALIDATED) +/** + * @var User $user + * @var Team $team + */ +$user = $_SESSION["user"]; +;$team = $user->getRole() == Role::PARTICIPANT ? $_SESSION["team"] : Team::fromTrigram($_GET["trigram"]); + +if ($team == null) + require_once "server_files/404.php"; + +if ($team->getEncadrantId() != $user->getId() || $team->getValidationStatus() != ValidationStatus::VALIDATED) require_once "server_files/403.php"; $has_error = false; diff --git a/server_files/controllers/informations.php b/server_files/controllers/informations.php index 46e0625..149cb59 100644 --- a/server_files/controllers/informations.php +++ b/server_files/controllers/informations.php @@ -14,13 +14,13 @@ if ($_SESSION["role"] != Role::ADMIN) { if ($user === null) require_once "server_files/404.php"; -$team = Team::fromId($user->getTeamId()); +$teams = $user->getTeams(); $has_error = false; $error_message = null; if (isset($_POST["kick"])) { - if ($team == null) { + if (sizeof($teams) == null) { $has_error = true; $error_message = "La personne à expulser n'est dans aucune équipe."; } @@ -109,7 +109,7 @@ class AttributeTeam } } -if ($team != null) +if ($teams != null) $documents = $user->getAllDocuments(); require_once "server_files/views/informations.php"; diff --git a/server_files/controllers/ma_participation.php b/server_files/controllers/ma_participation.php index 850b3d0..a83ed0a 100644 --- a/server_files/controllers/ma_participation.php +++ b/server_files/controllers/ma_participation.php @@ -1,12 +1,18 @@ 0) { /** * @var User $user - * @var Team $team + * @var Team team */ $user = $_SESSION["user"]; - $team = $_SESSION["team"]; + $team = $user->getRole() == Role::PARTICIPANT ? $_SESSION["team"] : Team::fromTrigram($_GET["trigram"]); + + if ($team == null) + require_once "server_files/404.php"; + + if ($team->getEncadrantId() != $user->getId()) + require_once "server_files/403.php"; $video = Video::getVideo(Reason::SOLUTION, $team); $questions_received = Question::getQuestionsTo($team); diff --git a/server_files/controllers/mon_equipe.php b/server_files/controllers/mon_equipe.php index b2b32c3..34182dd 100644 --- a/server_files/controllers/mon_equipe.php +++ b/server_files/controllers/mon_equipe.php @@ -38,15 +38,21 @@ if (isset($_POST["request_validation"])) { /** @var Question[][] $questions_received */ $questions_received = []; -if (isset($_SESSION["user_id"]) && isset($_SESSION["team"]) && $_SESSION["team"] !== null) { +if (isset($_SESSION["user_id"]) && isset($_SESSION["teams"]) && sizeof($_SESSION["teams"]) > 0) { /** * @var User $user * @var Team $team */ $user = $_SESSION["user"]; - $team = $_SESSION["team"]; + $team = $user->getRole() == Role::PARTICIPANT ? $_SESSION["team"] : Team::fromTrigram($_GET["trigram"]); - $documents = $user->getAllDocuments(); + if ($team == null) + require_once "server_files/404.php"; + + if ($team->getEncadrantId() != $user->getId()) + require_once "server_files/403.php"; + + $documents = $team->getAllDocuments(); } else require_once "server_files/403.php"; diff --git a/server_files/controllers/poser_questions.php b/server_files/controllers/poser_questions.php index de5b3f4..913aefa 100644 --- a/server_files/controllers/poser_questions.php +++ b/server_files/controllers/poser_questions.php @@ -3,10 +3,17 @@ if (!isset($_SESSION["user_id"]) || $_SESSION["role"] != Role::PARTICIPANT && $_SESSION["role"] != Role::ENCADRANT || Phase::getCurrentPhase() != Phase::PHASE2) require_once "server_files/403.php"; -/** @var Team $team */ -$team = $_SESSION["team"]; +/** + * @var User $user + * @var Team $team + */ +$user = $_SESSION["user"]; +$team = $user->getRole() == Role::PARTICIPANT ? $_SESSION["team"] : Team::fromTrigram($_GET["trigram"]); if ($team == null) + require_once "server_files/404.php"; + +if ($team->getEncadrantId() != $user->getId()) require_once "server_files/403.php"; $has_error = false; diff --git a/server_files/controllers/rejoindre_equipe.php b/server_files/controllers/rejoindre_equipe.php index 1f70f55..dd12c44 100644 --- a/server_files/controllers/rejoindre_equipe.php +++ b/server_files/controllers/rejoindre_equipe.php @@ -1,6 +1,6 @@ getInscriptionDate(), "La date limite d'inscription est dépassée."); + ensure($_SESSION["team"] == null || $_SESSION["role"] == Role::ENCADRANT, "Vous êtes déjà dans une équipe."); ensure(preg_match("#[a-z0-9]{6}#", $this->access_code), "Le code d'accès doit comporter 6 caractères alphanumériques."); ensure($this->team != null, "Ce code d'accès est invalide."); ensure($this->team->getValidationStatus() == ValidationStatus::NOT_READY, "Cette équipe est déjà validée ou en cours de validation, vous ne pouvez pas la rejoindre."); diff --git a/server_files/controllers/repondre_questions.php b/server_files/controllers/repondre_questions.php index 318a48d..dbfbc04 100644 --- a/server_files/controllers/repondre_questions.php +++ b/server_files/controllers/repondre_questions.php @@ -2,8 +2,18 @@ if (!isset($_SESSION["user_id"]) || $_SESSION["role"] != Role::PARTICIPANT && $_SESSION["role"] != Role::ENCADRANT || Phase::getCurrentPhase() != Phase::PHASE3) require_once "server_files/403.php"; -/** @var Team $team */ -$team = $_SESSION["team"]; +/** + * @var User $user + * @var Team $team + */ +$user = $_SESSION["user"]; +$team = $user->getRole() == Role::PARTICIPANT ? $_SESSION["team"] : Team::fromTrigram($_GET["trigram"]); + +if ($team == null) + require_once "server_files/404.php"; + +if ($team->getEncadrantId() != $user->getId() || $team->getValidationStatus() != ValidationStatus::VALIDATED) + require_once "server_files/403.php"; $has_error = false; $error_message = null; diff --git a/server_files/model.php b/server_files/model.php index bb8f2ff..8bc7789 100644 --- a/server_files/model.php +++ b/server_files/model.php @@ -6,6 +6,7 @@ function loadUserValues() unset($_SESSION["user"]); unset($_SESSION["role"]); unset($_SESSION["team"]); + unset($_SESSION["teams"]); if (isset($_SESSION["user_id"])) { $user = $_SESSION["user"] = User::fromId($_SESSION["user_id"]); @@ -16,8 +17,10 @@ function loadUserValues() $_SESSION["role"] = $user->getRole(); - if ($user->getTeamId() !== null) - $_SESSION["team"] = Team::fromId($user->getTeamId()); + $_SESSION["teams"] = $user->getTeams(); + + if ($user->getRole() == Role::PARTICIPANT) + $_SESSION["team"] = sizeof($_SESSION["teams"]) > 0 ? $_SESSION["teams"][0] : null; } if (isset($_GET["view-as-admin"])) { @@ -65,6 +68,8 @@ function quitTeam($user_id = -1) $_SESSION["team"] = null; unset($_SESSION["team"]); + + $_SESSION["teams"] = $user->getTeams(); } function userExists($email) diff --git a/server_files/views/ajouter_equipe.php b/server_files/views/ajouter_equipe.php index 0e7aacf..df1618a 100644 --- a/server_files/views/ajouter_equipe.php +++ b/server_files/views/ajouter_equipe.php @@ -11,7 +11,7 @@ require_once "header.php"; Votre équipe a bien été créée ! Voici le code d'accès à transmettre aux autres membres de votre équipe : access_code ?> - +
Vous êtes déjà dans une équipe.
@@ -21,6 +21,12 @@ require_once "header.php"; + 0) { ?> +
+ Vous êtes déjà inscrit dans une équipe. Vous pouvez toutefois encadrer plusieurs équipes. +
+ +
Chacune des informations pourra être modifiée avant que l'équipe tant que l'équipe n'est pas validée.
diff --git a/server_files/views/header.php b/server_files/views/header.php index d014785..9221c98 100644 --- a/server_files/views/header.php +++ b/server_files/views/header.php @@ -37,7 +37,7 @@ Mon compte - getInscriptionDate()) { ?> - - getValidationStatus() == ValidationStatus::VALIDATED) { ?> - + } + { + /** + * @var Team $_team + */ + foreach ($_SESSION["teams"] as $_team) { + $appendice = $_SESSION["role"] == Role::ENCADRANT ? "/" . $_team->getTrigram() : ""; + $info = sizeof($_SESSION["teams"]) > 1 ? " (" . $_team->getTrigram() . ")" : ""; + ?> + + getValidationStatus() == ValidationStatus::VALIDATED) { ?> + - - - - + +