mirror of
				https://gitlab.com/animath/si/plateforme.git
				synced 2025-11-04 05:42:12 +01:00 
			
		
		
		
	Organizers can change name & trigram
This commit is contained in:
		@@ -37,6 +37,7 @@ $ROUTES["^connexion/(reinitialiser_mdp)/(.*)/?$"] = ["server_files/controllers/c
 | 
			
		||||
$ROUTES["^connexion/?$"] = ["server_files/controllers/connexion.php"];
 | 
			
		||||
$ROUTES["^deconnexion/?$"] = ["server_files/controllers/deconnexion.php"];
 | 
			
		||||
$ROUTES["^equipe/([A-Z]{3})/?$"] = ["server_files/controllers/equipe.php", "trigram"];
 | 
			
		||||
$ROUTES["^equipe/([A-Z]{3})/(modifier)?$"] = ["server_files/controllers/equipe.php", "trigram", "modifier"];
 | 
			
		||||
$ROUTES["^file/([a-z0-9]{64})/?$"] = ["server_files/controllers/view_file.php", "file_id"];
 | 
			
		||||
$ROUTES["^informations/([0-9]*)/.*?$"] = ["server_files/controllers/informations.php", "id"];
 | 
			
		||||
$ROUTES["^inscription/?$"] = ["server_files/controllers/inscription.php"];
 | 
			
		||||
 
 | 
			
		||||
@@ -14,6 +14,18 @@ if ($_SESSION["role"] == Role::ORGANIZER && !$tournament->organize($_SESSION["us
 | 
			
		||||
if ($team === null)
 | 
			
		||||
	require_once "server_files/404.php";
 | 
			
		||||
 | 
			
		||||
if (isset($_POST["team_edit"])) {
 | 
			
		||||
	$edit_team = new EditTeam($_POST);
 | 
			
		||||
	try {
 | 
			
		||||
		$edit_team->makeVerifications();
 | 
			
		||||
		$edit_team->updateTeam();
 | 
			
		||||
	}
 | 
			
		||||
	catch (AssertionError $e) {
 | 
			
		||||
		$has_error = true;
 | 
			
		||||
		$error_message = $e->getMessage();
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
if (isset($_POST["validate"])) {
 | 
			
		||||
	$team->setValidationStatus(ValidationStatus::VALIDATED);
 | 
			
		||||
	Mailer::sendValidateTeam($team, $_POST["message"]);
 | 
			
		||||
@@ -23,7 +35,6 @@ elseif (isset($_POST["unvalidate"])) {
 | 
			
		||||
	Mailer::sendUnvalidateTeam($team, $_POST["message"]);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
if (isset($_POST["select"])) {
 | 
			
		||||
	$team->selectForFinal(true);
 | 
			
		||||
	$team->setValidationStatus(ValidationStatus::NOT_READY);
 | 
			
		||||
@@ -57,6 +68,50 @@ if (isset($_POST["download_zip"])) {
 | 
			
		||||
	exit();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class EditTeam
 | 
			
		||||
{
 | 
			
		||||
	public $name;
 | 
			
		||||
	public $trigram;
 | 
			
		||||
	public $tournament_id;
 | 
			
		||||
	private $team;
 | 
			
		||||
	private $tournament;
 | 
			
		||||
 | 
			
		||||
	public function __construct($data)
 | 
			
		||||
	{
 | 
			
		||||
		global $team;
 | 
			
		||||
 | 
			
		||||
		foreach ($data as $key => $value)
 | 
			
		||||
			$this->$key = htmlspecialchars($value);
 | 
			
		||||
 | 
			
		||||
		$this->trigram = strtoupper($this->trigram);
 | 
			
		||||
		$this->team = $team;
 | 
			
		||||
		$this->tournament = Tournament::fromId($this->tournament_id);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public function makeVerifications()
 | 
			
		||||
	{
 | 
			
		||||
		ensure($this->name != "" && $this->name != null, "Veuillez spécifier un nom d'équipe.");
 | 
			
		||||
		ensure($this->name == $this->team->getName() || !teamExists($this->name), "Une équipe existe déjà avec ce nom.");
 | 
			
		||||
		ensure(preg_match("#^[A-Z]{3}$#", $this->trigram), "Le trigramme n'est pas valide.");
 | 
			
		||||
		ensure($this->trigram == $this->team->getTrigram() || !trigramExists($this->trigram), "Une équipe a déjà choisi ce trigramme.");
 | 
			
		||||
		ensure($this->tournament != null, "Le tournoi indiqué n'existe pas.");
 | 
			
		||||
		ensure($this->tournament_id == $this->team->getTournamentId() || $_SESSION["role"] == Role::ADMIN, "Vous n'avez pas la permission pour changer cette équipe de tournoi.");
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public function updateTeam()
 | 
			
		||||
	{
 | 
			
		||||
		global $URL_BASE;
 | 
			
		||||
 | 
			
		||||
		$this->team->setName($this->name);
 | 
			
		||||
		$this->team->setTrigram($this->trigram);
 | 
			
		||||
		$this->team->setTournamentId($this->tournament_id);
 | 
			
		||||
 | 
			
		||||
		$_SESSION["tournament"] = $this->tournament;
 | 
			
		||||
 | 
			
		||||
		header("Location: $URL_BASE/equipe/$this->trigram");
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
$documents = $tournament->getAllDocuments($team->getId());
 | 
			
		||||
$documents_final = null;
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -59,6 +59,49 @@
 | 
			
		||||
        ?>
 | 
			
		||||
    </div>
 | 
			
		||||
 | 
			
		||||
<?php if (isset($_GET["modifier"])) { ?>
 | 
			
		||||
 | 
			
		||||
    <form method="POST">
 | 
			
		||||
        <div class="form-row">
 | 
			
		||||
            <div class="form-group col-md-6">
 | 
			
		||||
                <label for="name">Nom :</label>
 | 
			
		||||
                <input class="form-control" type="text" id="name" name="name" pattern="[A-Za-zÀ-ÿ ]+"
 | 
			
		||||
                       value="<?= $team->getName() ?>" required/>
 | 
			
		||||
            </div>
 | 
			
		||||
 | 
			
		||||
            <div class="form-group col-md-6">
 | 
			
		||||
                <label for="trigram">Trigramme :</label>
 | 
			
		||||
                <input class="form-control" type="text" id="trigram" name="trigram"
 | 
			
		||||
                       value="<?= $team->getTrigram() ?>" pattern="[A-Z]{3}" maxlength="3" required/>
 | 
			
		||||
            </div>
 | 
			
		||||
        </div>
 | 
			
		||||
 | 
			
		||||
        <div class="form-group row">
 | 
			
		||||
            <label for="tournament">Tournoi :</label>
 | 
			
		||||
            <select id="tournament" name="tournament_id" class="custom-select">
 | 
			
		||||
                <option value="0">Choisir un tournoi ...</option>
 | 
			
		||||
                <?php
 | 
			
		||||
                foreach (Tournament::getAllTournaments(false, true) as $tournament)
 | 
			
		||||
                    echo "<option value=\"" . $tournament->getId() . "\" "
 | 
			
		||||
                        . ($tournament->getId() == $team->getTournamentId() ? "selected" : "") . ">"
 | 
			
		||||
                        . $tournament->getName() . "</option>\n";
 | 
			
		||||
                ?>
 | 
			
		||||
            </select>
 | 
			
		||||
        </div>
 | 
			
		||||
 | 
			
		||||
        <div class="form-group row">
 | 
			
		||||
            <input class="btn btn-primary btn-lg btn-block" name="team_edit" type="submit"
 | 
			
		||||
                   value="Modifier l'équipe"/>
 | 
			
		||||
        </div>
 | 
			
		||||
    </form>
 | 
			
		||||
 | 
			
		||||
<?php }
 | 
			
		||||
 | 
			
		||||
if ($team->getValidationStatus() != ValidationStatus::VALIDATED) { ?>
 | 
			
		||||
    <hr/>
 | 
			
		||||
    <a href="/equipe/<?= $team->getTrigram() ?>/modifier"><button class="btn btn-secondary btn-lg btn-block">Modifier l'équipe</button></a>
 | 
			
		||||
<?php } ?>
 | 
			
		||||
 | 
			
		||||
    <hr/>
 | 
			
		||||
 | 
			
		||||
    <h2>Documents</h2>
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user