1
0
mirror of https://gitlab.com/animath/si/plateforme.git synced 2024-12-24 17:42:23 +00:00

Possibilité de modifier nom et trigramme d'une équipe avant validation

This commit is contained in:
galaxyoyo 2019-08-26 12:16:39 +02:00
parent 4604ddd758
commit 1f186b43f7
3 changed files with 118 additions and 23 deletions

View File

@ -17,7 +17,7 @@ RewriteRule ^deconnexion$ server_files/deconnexion.php [L]
RewriteRule ^equipe/(.*?)$ server_files/equipe.php?trigram=$1 [L] RewriteRule ^equipe/(.*?)$ server_files/equipe.php?trigram=$1 [L]
RewriteRule ^file/(.*?)$ server_files/view_file.php?file_id=$1 [L] RewriteRule ^file/(.*?)$ server_files/view_file.php?file_id=$1 [L]
RewriteRule ^inscription$ server_files/inscription.php [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 ^mon_equipe$ server_files/mon_equipe.php [L]
RewriteRule ^rejoindre_equipe$ server_files/rejoindre_equipe.php [L] RewriteRule ^rejoindre_equipe$ server_files/rejoindre_equipe.php [L]
RewriteRule ^solutions$ server_files/solutions.php [L] RewriteRule ^solutions$ server_files/solutions.php [L]

View File

@ -5,27 +5,27 @@ include 'config.php';
$tournaments_response = $DB->query("SELECT `id`, `name` FROM `tournaments` WHERE `year` = '$YEAR';"); $tournaments_response = $DB->query("SELECT `id`, `name` FROM `tournaments` WHERE `year` = '$YEAR';");
if (isset($_POST["submitted"])) { if (isset($_POST["submitted"])) {
$error_message = registerTournament(); $error_message = registerTeam();
} }
function registerTournament() { function registerTeam() {
global $DB, $YEAR, $MAIL_ADDRESS, $access_code; global $DB, $YEAR, $MAIL_ADDRESS, $access_code;
if ($_SESSION["team_id"] != NULL) if ($_SESSION["team_id"] != NULL)
return "Vous êtes déjà dans une équipe."; return "Vous êtes déjà dans une équipe.";
$name = htmlspecialchars($_POST["name"]); $name = htmlspecialchars($_POST["name"]);
if (!isset($name) || $name == "") if (!isset($name) || $name == "")
return "Vous devez spécifier un nom d'équipe."; return "Vous devez spécifier un nom d'équipe.";
$result = $DB->query("SELECT `id` FROM `teams` WHERE `name` = '" . $name . "' AND `year` = '$YEAR';"); $result = $DB->query("SELECT `id` FROM `teams` WHERE `name` = '" . $name . "' AND `year` = '$YEAR';");
if ($result->fetch()) if ($result->fetch())
return "Une équipe existe déjà avec ce nom."; return "Une équipe existe déjà avec ce nom.";
$trigram = htmlspecialchars($_POST["trigram"]); $trigram = strtoupper(htmlspecialchars($_POST["trigram"]));
if (!preg_match("#[A-Z][A-Z][A-Z]#", $trigram)) if (!preg_match("#^[A-Z][A-Z][A-Z]$#", $trigram))
return "Le trigramme entré n'est pas valide."; return "Le trigramme entré n'est pas valide.";
$result = $DB->query("SELECT `id` FROM `teams` WHERE `trigram` = '" . $trigram . "' AND `year` = '$YEAR';"); $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) for ($i = 0; $i < 6; ++$i)
$access_code .= $alphabet[rand(0, strlen($alphabet) - 1)]; $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`) $req = $DB->prepare("INSERT INTO `teams` (`name`, `trigram`, `tournament`, `encadrant_1`, `participant_1`, `validation_status`, `access_code`, `year`)
VALUES (?, ?, ?, ?, ?, ?, ?);"); VALUES (?, ?, ?, ?, ?, ?, ?, ?);");
$result = $req->execute([$name, $trigram, $_SESSION["role"] == "ENCADRANT" ? $_SESSION["user_id"] : NULL, $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]); $_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';"); $result = $DB->query("SELECT `id` FROM `teams` WHERE `name` = '" . $name . "' AND `year` = '$YEAR';");
$data_team = $result->fetch(); $data_team = $result->fetch();
$DB->prepare("UPDATE `users` SET `team_id` = ? WHERE `id` = " . $_SESSION["user_id"] . ";")->execute([$data_team["id"]]); $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 = "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 .= "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"; $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
<form method="POST"> <form method="POST">
<input type="hidden" name="submitted" value="true" /> <input type="hidden" name="submitted" value="true" />
<table> <table style="width: 100%;">
<tbody> <tbody>
<tr> <tr>
<td> <td style="width: 30%;">
<label for="name">Nom :</label> <label for="name">Nom :</label>
</td> </td>
<td> <td style="width: 70%;">
<input type="text" id="name" name="name" /> <input style="width: 100%;" type="text" id="name" name="name" />
</td> </td>
</tr> </tr>
<tr> <tr>
@ -96,7 +96,7 @@ if (!isset($_SESSION["role"]) or ($_SESSION["role"] != "PARTICIPANT" && $_SESSIO
<label for="trigram">Trigramme :</label> <label for="trigram">Trigramme :</label>
</td> </td>
<td> <td>
<input type="text" id="trigram" name="trigram" /> <input style="width: 100%;" type="text" id="trigram" name="trigram" />
</td> </td>
</tr> </tr>
<tr> <tr>
@ -104,7 +104,7 @@ if (!isset($_SESSION["role"]) or ($_SESSION["role"] != "PARTICIPANT" && $_SESSIO
<label for="tournament">Tournoi :</label> <label for="tournament">Tournoi :</label>
</td> </td>
<td> <td>
<select id="tournament" name="tournament"> <select style="width: 100%;" id="tournament" name="tournament">
<?php <?php
while (($data = $tournaments_response->fetch()) !== FALSE) { while (($data = $tournaments_response->fetch()) !== FALSE) {
echo "<option value=\"" . $data["id"] . "\">" . $data["name"] . "</option>\n"; echo "<option value=\"" . $data["id"] . "\">" . $data["name"] . "</option>\n";
@ -114,8 +114,8 @@ if (!isset($_SESSION["role"]) or ($_SESSION["role"] != "PARTICIPANT" && $_SESSIO
</td> </td>
</tr> </tr>
<tr> <tr>
<td> <td colspan="2">
<input type="submit" /> <input style="width: 100%;" type="submit" value="Ajouter une équipe" />
</td> </td>
</tr> </tr>
</tbody> </tbody>

View File

@ -35,6 +35,8 @@ if (isset($_POST["leave_team"])) {
exit(); exit();
} }
$tournaments_response = $DB->query("SELECT `id`, `name` FROM `tournaments` WHERE `year` = '$YEAR';");
if (isset($_POST["send_document"])) { if (isset($_POST["send_document"])) {
sendDocument(); sendDocument();
} }
@ -54,6 +56,10 @@ if (isset($_SESSION["user_id"]) && isset($_SESSION["team_id"])) {
$documents_req->execute([$_SESSION["user_id"]]); $documents_req->execute([$_SESSION["user_id"]]);
} }
if (isset($_POST["team_edit"])) {
$error_message = updateTeam();
}
function sendDocument() { function sendDocument() {
global $LOCAL_PATH, $DB; global $LOCAL_PATH, $DB;
@ -92,6 +98,46 @@ function sendDocument() {
return false; 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;
}
?> ?>
<?php include "header.php" ?> <?php include "header.php" ?>
@ -130,9 +176,57 @@ for ($i = 1; $i <= 6; ++$i) {
echo "Participant $i : " . $user_data["first_name"] . " " . $user_data["surname"] . "<br />"; echo "Participant $i : " . $user_data["first_name"] . " " . $user_data["surname"] . "<br />";
} }
?> ?>
Code d'accès : <strong><?php echo $team_data["access_code"] ?></strong> Code d'accès : <strong><?php echo $team_data["access_code"] ?></strong><br />
<?php if (isset($_GET["modifier"])) { ?>
<form method="POST">
<input type="hidden" name="team_edit" value="true" />
<table style="width: 100%;">
<tbody>
<tr>
<td style="width: 30%;">
<label for="name">Nom :</label>
</td>
<td style="width: 70%;">
<input style="width: 100%;" type="text" id="name" name="name" value="<?= $team_data["name"] ?>" />
</td>
</tr>
<tr>
<td>
<label for="trigram">Trigramme :</label>
</td>
<td>
<input style="width: 100%;" type="text" id="trigram" name="trigram" value="<?= $team_data["trigram"] ?>" />
</td>
</tr>
<tr>
<td>
<label for="tournament">Tournoi :</label>
</td>
<td>
<select style="width: 100%;" id="tournament" name="tournament">
<?php
while (($data = $tournaments_response->fetch()) !== FALSE) {
echo "<option value=\"" . $data["id"] . "\">" . $data["name"] . "</option>\n";
}
?>
</select>
</td>
</tr>
<tr>
<td colspan="2">
<input style="width: 100%;" type="submit" value="Modifier l'équipe" />
</td>
</tr>
</tbody>
</table>
</form>
<?php } else { ?>
<?php if ($_SESSION["team_validation_status"] == "NOT_READY") { ?> <?php if ($_SESSION["team_validation_status"] == "NOT_READY") { ?>
<a href="<?= $URL_BASE ?>/mon_equipe/modifier">Modifier mon équipe</a>
<hr /> <hr />
<h2>Mes autorisations</h2> <h2>Mes autorisations</h2>
<?php <?php
@ -196,5 +290,6 @@ Code d'accès : <strong><?php echo $team_data["access_code"] ?></strong>
<input type="submit" name="request_validation" value="Demander la validation" /> <input type="submit" name="request_validation" value="Demander la validation" />
</form> </form>
<?php } ?> <?php } ?>
<?php } ?>
<?php include "footer.php" ?> <?php include "footer.php" ?>