1
0
mirror of https://gitlab.com/animath/si/plateforme.git synced 2025-06-26 09:27:45 +02: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

@ -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
<form method="POST">
<input type="hidden" name="submitted" value="true" />
<table>
<table style="width: 100%;">
<tbody>
<tr>
<td>
<td style="width: 30%;">
<label for="name">Nom :</label>
</td>
<td>
<input type="text" id="name" name="name" />
<td style="width: 70%;">
<input style="width: 100%;" type="text" id="name" name="name" />
</td>
</tr>
<tr>
@ -96,7 +96,7 @@ if (!isset($_SESSION["role"]) or ($_SESSION["role"] != "PARTICIPANT" && $_SESSIO
<label for="trigram">Trigramme :</label>
</td>
<td>
<input type="text" id="trigram" name="trigram" />
<input style="width: 100%;" type="text" id="trigram" name="trigram" />
</td>
</tr>
<tr>
@ -104,7 +104,7 @@ if (!isset($_SESSION["role"]) or ($_SESSION["role"] != "PARTICIPANT" && $_SESSIO
<label for="tournament">Tournoi :</label>
</td>
<td>
<select id="tournament" name="tournament">
<select style="width: 100%;" id="tournament" name="tournament">
<?php
while (($data = $tournaments_response->fetch()) !== FALSE) {
echo "<option value=\"" . $data["id"] . "\">" . $data["name"] . "</option>\n";
@ -114,8 +114,8 @@ if (!isset($_SESSION["role"]) or ($_SESSION["role"] != "PARTICIPANT" && $_SESSIO
</td>
</tr>
<tr>
<td>
<input type="submit" />
<td colspan="2">
<input style="width: 100%;" type="submit" value="Ajouter une équipe" />
</td>
</tr>
</tbody>