mirror of
				https://gitlab.com/animath/si/plateforme.git
				synced 2025-11-04 16:42:28 +01:00 
			
		
		
		
	Possibilité de modifier nom et trigramme d'une équipe avant validation
This commit is contained in:
		@@ -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" ?>
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user