1
0
mirror of https://gitlab.com/animath/si/plateforme.git synced 2025-06-24 19:00:32 +02:00

Organisateurs multiples, modification des tournois

This commit is contained in:
galaxyoyo
2019-08-26 20:14:29 +02:00
parent 7a81d09b88
commit 8b90877088
5 changed files with 310 additions and 70 deletions

View File

@ -17,20 +17,21 @@ function registerTournament() {
if ($result->fetch())
return "Un tournoi existe déjà avec ce nom.";
try {
$organizer_id = intval(htmlspecialchars($_POST["organizer"]));
}
catch (Exception $ex) {
return "Un problème a eu lieu concernant le choix de l'organisateur. Merci de ne pas formuler vous-même vos requêtes.";
}
if (!isset($_POST["organizer"]) || sizeof($_POST["organizer"]) == 0)
return "Aucun organisateur n'a été choisi.";
$result = $DB->query("SELECT `role`, `email` FROM `users` WHERE `id` = '" . $organizer_id . "' AND `year` = '$YEAR';");
$data = $result->fetch();
if ($data === FALSE)
return "L'organisateur spécifié n'existe pas.";
if ($data["role"] != "ORGANIZER" && $data["role"] != "ADMIN")
return "L'organisateur indiqué ne peut pas organiser de tournoi.";
$organize_mail = $data["email"];
$organizers = $_POST["organizer"];
$orga_mails = [];
foreach ($organizers as $orga) {
$result = $DB->query("SELECT `role`, `email` FROM `users` WHERE `id` = '" . $orga . "' AND `year` = '$YEAR';");
$data = $result->fetch();
if ($data === FALSE)
return "L'organisateur spécifié n'existe pas.";
if ($data["role"] != "ORGANIZER" && $data["role"] != "ADMIN")
return "L'organisateur indiqué ne peut pas organiser de tournoi.";
$orga_mails[] = $data["email"];
}
try {
$size = intval(htmlspecialchars($_POST["size"]));
@ -80,13 +81,22 @@ function registerTournament() {
$description = htmlspecialchars($_POST["description"]);
$req = $DB->prepare("INSERT INTO `tournaments` (`name`, `organizer`, `size`, `place`, `description`,
$req = $DB->prepare("INSERT INTO `tournaments` (`name`, `size`, `place`, `price`, `description`,
`date_start`, `date_end`, `date_inscription`, `date_solutions`, `date_syntheses`, `year`)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);");
$result = $req->execute([$name, $organizer_id, $size, $place, $description, $date_start, $date_end,
$req->execute([$name, $size, $place, $price, $description, $date_start, $date_end,
"$date_inscription $time_inscription", "$date_solutions $time_solutions", "$date_syntheses $time_syntheses", $YEAR]);
mail($organize_mail, "Organisateur TFJM² " . $name, "Vous venez d'être promu organisateur du tournoi " . $name . " pour le TFJM² $YEAR !", "From: $MAIL_ADDRESS");
$req = $DB->query("SELECT `id` FROM `tournaments` WHERE `name` = '$name' AND `year` = $YEAR;");
$tournament_id = $req->fetch()["id"];
foreach ($organizers as $orga) {
$req = $DB->prepare("INSERT INTO `organizers`(`organizer`, `tournament`) VALUES(?, ?);");
$req->execute([$orga, $tournament_id]);
}
foreach ($orga_mails as $orga_mail)
mail($orga_mail, "Organisateur TFJM² " . $name, "Vous venez d'être promu organisateur du tournoi " . $name . " pour le TFJM² $YEAR !", "From: $MAIL_ADDRESS");
return false;
}
@ -112,14 +122,14 @@ if (!isset($_SESSION["role"]) or $_SESSION["role"] != "ADMIN") {
<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" required />
</td>
</tr>
<tr>
@ -127,7 +137,7 @@ if (!isset($_SESSION["role"]) or $_SESSION["role"] != "ADMIN") {
<label for="organizer">Organisateur :</label>
</td>
<td>
<select id="organizer" name="organizer">
<select style="width: 100%;" id="organizer" name="organizer[]" multiple size="4" required>
<?php
while (($data = $orgas_response->fetch()) !== FALSE) {
echo "<option value=\"" . $data["id"] . "\">" . $data["first_name"] . " " . $data["surname"] . "</option>\n";
@ -141,7 +151,7 @@ if (!isset($_SESSION["role"]) or $_SESSION["role"] != "ADMIN") {
<label for="size">Nombre d'équipes :</label>
</td>
<td>
<input type="number" id="size" name="size" min="3" max="12" value="6" />
<input style="width: 100%;" type="number" id="size" name="size" min="3" max="12" value="6" required />
</td>
</tr>
<tr>
@ -149,7 +159,7 @@ if (!isset($_SESSION["role"]) or $_SESSION["role"] != "ADMIN") {
<label for="place">Lieu :</label>
</td>
<td>
<input type="text" id="place" name="place" />
<input style="width: 100%;" type="text" id="place" name="place" required />
</td>
</tr>
<tr>
@ -157,7 +167,7 @@ if (!isset($_SESSION["role"]) or $_SESSION["role"] != "ADMIN") {
<label for="price">Prix par participant</label>
</td>
<td>
<input type="number" id="price" name="price" min="0" max="21" value="21" />
<input style="width: 100%;" type="number" id="price" name="price" min="0" max="21" value="21" required />
</td>
</tr>
<tr>
@ -165,7 +175,7 @@ if (!isset($_SESSION["role"]) or $_SESSION["role"] != "ADMIN") {
<label for="date_start">Dates :</label>
</td>
<td>
Du <input type="date" id="date_start" name="date_start" /> au <input type="date" id="date_end" name="date_end" />
Du <input style="width: 45%;" type="date" id="date_start" name="date_start" required /> au <input style="width: 45%;" type="date" id="date_end" name="date_end" required />
</td>
</tr>
<tr>
@ -173,8 +183,8 @@ if (!isset($_SESSION["role"]) or $_SESSION["role"] != "ADMIN") {
<label for="date_inscription">Date limite d'inscription :</label>
</td>
<td>
<input type="date" id="date_inscription" name="date_inscription" />
<input type="time" id="time_inscription" name="time_inscription" />
<input style="width: 49%;" type="date" id="date_inscription" name="date_inscription" required />
<input style="width: 49%;" type="time" id="time_inscription" name="time_inscription" required />
</td>
</tr>
<tr>
@ -182,8 +192,8 @@ if (!isset($_SESSION["role"]) or $_SESSION["role"] != "ADMIN") {
<label for="date_solutions">Date limite pour rendre les solutions :</label>
</td>
<td>
<input type="date" id="date_solutions" name="date_solutions" />
<input type="time" id="time_solutions" name="time_solutions" />
<input style="width: 49%;" type="date" id="date_solutions" name="date_solutions" required />
<input style="width: 49%;" type="time" id="time_solutions" name="time_solutions" required />
</td>
</tr>
<tr>
@ -191,8 +201,8 @@ if (!isset($_SESSION["role"]) or $_SESSION["role"] != "ADMIN") {
<label for="date_syntheses">Date limite pour rendre les notes de synthèse :</label>
</td>
<td>
<input type="date" id="date_syntheses" name="date_syntheses" />
<input type="time" id="time_syntheses" name="time_syntheses" />
<input style="width: 49%;" type="date" id="date_syntheses" name="date_syntheses" required />
<input style="width: 49%;" type="time" id="time_syntheses" name="time_syntheses" required />
</td>
</tr>
<tr>
@ -200,12 +210,12 @@ if (!isset($_SESSION["role"]) or $_SESSION["role"] != "ADMIN") {
<label for="description">Description :</label>
</td>
<td>
<textarea name="description" id="description"></textarea>
<textarea style="width: 100%;" name="description" id="description" required></textarea>
</td>
</tr>
<tr>
<td>
<input type="submit" />
<td colspan="2">
<input style="width: 100%;" type="submit" value="Ajouter un tournoi" />
</td>
</tr>
</tbody>