mirror of
https://gitlab.com/animath/si/plateforme.git
synced 2024-12-24 03:02:23 +00:00
Possibilité de modifier nom et trigramme d'une équipe avant validation
This commit is contained in:
parent
4604ddd758
commit
1f186b43f7
@ -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]
|
||||
|
@ -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>
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<?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 />";
|
||||
}
|
||||
?>
|
||||
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") { ?>
|
||||
<a href="<?= $URL_BASE ?>/mon_equipe/modifier">Modifier mon équipe</a>
|
||||
<hr />
|
||||
<h2>Mes autorisations</h2>
|
||||
<?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" />
|
||||
</form>
|
||||
<?php } ?>
|
||||
<?php } ?>
|
||||
|
||||
<?php include "footer.php" ?>
|
||||
|
Loading…
Reference in New Issue
Block a user