From 1f186b43f7eb3b86afc0fffd7a6dc7bd4ef5c9c1 Mon Sep 17 00:00:00 2001 From: galaxyoyo Date: Mon, 26 Aug 2019 12:16:39 +0200 Subject: [PATCH] =?UTF-8?q?Possibilit=C3=A9=20de=20modifier=20nom=20et=20t?= =?UTF-8?q?rigramme=20d'une=20=C3=A9quipe=20avant=20validation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .htaccess | 2 +- server_files/ajouter_equipe.php | 42 +++++++------- server_files/mon_equipe.php | 97 ++++++++++++++++++++++++++++++++- 3 files changed, 118 insertions(+), 23 deletions(-) diff --git a/.htaccess b/.htaccess index 7f2d8b2..bde2839 100644 --- a/.htaccess +++ b/.htaccess @@ -17,7 +17,7 @@ RewriteRule ^deconnexion$ server_files/deconnexion.php [L] RewriteRule ^equipe/(.*?)$ server_files/equipe.php?trigram=$1 [L] RewriteRule ^file/(.*?)$ server_files/view_file.php?file_id=$1 [L] RewriteRule ^inscription$ server_files/inscription.php [L] -RewriteRule ^mon_compte$ server_files/mon_compte.php [L] +RewriteRule ^mon_equipe/(.*?)$ server_files/mon_equipe.php?$1 [L] RewriteRule ^mon_equipe$ server_files/mon_equipe.php [L] RewriteRule ^rejoindre_equipe$ server_files/rejoindre_equipe.php [L] RewriteRule ^solutions$ server_files/solutions.php [L] diff --git a/server_files/ajouter_equipe.php b/server_files/ajouter_equipe.php index 9dd42ae..b0bc049 100644 --- a/server_files/ajouter_equipe.php +++ b/server_files/ajouter_equipe.php @@ -5,27 +5,27 @@ include 'config.php'; $tournaments_response = $DB->query("SELECT `id`, `name` FROM `tournaments` WHERE `year` = '$YEAR';"); if (isset($_POST["submitted"])) { - $error_message = registerTournament(); + $error_message = registerTeam(); } -function registerTournament() { +function registerTeam() { global $DB, $YEAR, $MAIL_ADDRESS, $access_code; - + if ($_SESSION["team_id"] != NULL) return "Vous êtes déjà dans une équipe."; $name = htmlspecialchars($_POST["name"]); - + if (!isset($name) || $name == "") return "Vous devez spécifier un nom d'équipe."; - + $result = $DB->query("SELECT `id` FROM `teams` WHERE `name` = '" . $name . "' AND `year` = '$YEAR';"); if ($result->fetch()) return "Une équipe existe déjà avec ce nom."; - $trigram = htmlspecialchars($_POST["trigram"]); - - if (!preg_match("#[A-Z][A-Z][A-Z]#", $trigram)) + $trigram = strtoupper(htmlspecialchars($_POST["trigram"])); + + if (!preg_match("#^[A-Z][A-Z][A-Z]$#", $trigram)) return "Le trigramme entré n'est pas valide."; $result = $DB->query("SELECT `id` FROM `teams` WHERE `trigram` = '" . $trigram . "' AND `year` = '$YEAR';"); @@ -44,15 +44,15 @@ function registerTournament() { for ($i = 0; $i < 6; ++$i) $access_code .= $alphabet[rand(0, strlen($alphabet) - 1)]; - $req = $DB->prepare("INSERT INTO `teams` (`name`, `trigram`, `encadrant_1`, `participant_1`, `validation_status`, `access_code`, `year`) - VALUES (?, ?, ?, ?, ?, ?, ?);"); - $result = $req->execute([$name, $trigram, $_SESSION["role"] == "ENCADRANT" ? $_SESSION["user_id"] : NULL, + $req = $DB->prepare("INSERT INTO `teams` (`name`, `trigram`, `tournament`, `encadrant_1`, `participant_1`, `validation_status`, `access_code`, `year`) + VALUES (?, ?, ?, ?, ?, ?, ?, ?);"); + $req->execute([$name, $trigram, $tournament_id, $_SESSION["role"] == "ENCADRANT" ? $_SESSION["user_id"] : NULL, $_SESSION["role"] == "PARTICIPANT" ? $_SESSION["user_id"] : NULL, "NOT_READY", $access_code, $YEAR]); - + $result = $DB->query("SELECT `id` FROM `teams` WHERE `name` = '" . $name . "' AND `year` = '$YEAR';"); $data_team = $result->fetch(); $DB->prepare("UPDATE `users` SET `team_id` = ? WHERE `id` = " . $_SESSION["user_id"] . ";")->execute([$data_team["id"]]); - + $msg = "Bonjour " . $_SESSION["first_name"] . " " . $_SESSION["surname"] . ",\r\n\r\n"; $msg .= "Vous venez de créer l'équipe « $name » ($trigram) pour le TFJM² de " . $data["name"] . " et nous vous en remercions. "; $msg .= "Afin de permettre aux autres membres de votre équipe de vous rejoindre, veuillez leur transmettre le code d'accès : " . $access_code . "\r\n\r\n"; @@ -81,14 +81,14 @@ if (!isset($_SESSION["role"]) or ($_SESSION["role"] != "PARTICIPANT" && $_SESSIO
- +
- - @@ -96,7 +96,7 @@ if (!isset($_SESSION["role"]) or ($_SESSION["role"] != "PARTICIPANT" && $_SESSIO @@ -104,7 +104,7 @@ if (!isset($_SESSION["role"]) or ($_SESSION["role"] != "PARTICIPANT" && $_SESSIO - diff --git a/server_files/mon_equipe.php b/server_files/mon_equipe.php index c29fd22..3e00703 100644 --- a/server_files/mon_equipe.php +++ b/server_files/mon_equipe.php @@ -35,6 +35,8 @@ if (isset($_POST["leave_team"])) { exit(); } +$tournaments_response = $DB->query("SELECT `id`, `name` FROM `tournaments` WHERE `year` = '$YEAR';"); + if (isset($_POST["send_document"])) { sendDocument(); } @@ -54,6 +56,10 @@ if (isset($_SESSION["user_id"]) && isset($_SESSION["team_id"])) { $documents_req->execute([$_SESSION["user_id"]]); } +if (isset($_POST["team_edit"])) { + $error_message = updateTeam(); +} + function sendDocument() { global $LOCAL_PATH, $DB; @@ -92,6 +98,46 @@ function sendDocument() { return false; } +function updateTeam() { + global $DB, $YEAR, $URL_BASE, $MAIL_ADDRESS, $team_data; + + if ($_SESSION["team_id"] == NULL) + return "Vous n'êtes pas dans une équipe."; + + $name = htmlspecialchars($_POST["name"]); + + if (!isset($name) || $name == "") + return "Vous devez spécifier un nom d'équipe."; + + echo $team_data["id"]; + $result = $DB->query("SELECT `id` FROM `teams` WHERE `name` = '" . $name . "' AND `id` != " . $team_data["id"] . " AND `year` = '$YEAR';"); + if ($result->fetch()) + return "Une équipe existe déjà avec ce nom." . $team_data["id"]; + + $trigram = strtoupper(htmlspecialchars($_POST["trigram"])); + + if (!preg_match("#^[A-Z][A-Z][A-Z]$#", $trigram)) + return "Le trigramme entré n'est pas valide."; + + $result = $DB->query("SELECT `id` FROM `teams` WHERE `trigram` = '" . $trigram . "' AND `id` != '" . $team_data["id"] . "' AND `year` = '$YEAR';"); + if ($result->fetch()) + return "Une équipe a déjà choisi ce trigramme."; + + $tournament_id = intval(htmlspecialchars($_POST["tournament"])); + + $result = $DB->query("SELECT `id`, `name` FROM `tournaments` WHERE `id` = '" . $tournament_id . "' AND `year` = '$YEAR';"); + $data = $result->fetch(); + if ($data === FALSE) + return "Le tournoi spécifié n'existe pas."; + + $req = $DB->prepare("UPDATE `teams` SET `name` = ?, `trigram` = ?, `tournament` = ? WHERE `id` = ?;"); + $req->execute([$name, $trigram, $tournament_id, $team_data["id"]]); + + header("Location: $URL_BASE/mon_equipe"); + + return false; +} + ?> @@ -130,9 +176,57 @@ for ($i = 1; $i <= 6; ++$i) { echo "Participant $i : " . $user_data["first_name"] . " " . $user_data["surname"] . "
"; } ?> -Code d'accès : +Code d'accès :
+ + + + + +
+ - + +
- +
- fetch()) !== FALSE) { echo "\n"; @@ -114,8 +114,8 @@ if (!isset($_SESSION["role"]) or ($_SESSION["role"] != "PARTICIPANT" && $_SESSIO
- + +
+ + + + + + + + + + + + + + + + + +
+ + + " /> +
+ + + " /> +
+ + + +
+ +
+
+ + + Modifier mon équipe

Mes autorisations

+