diff --git a/.htaccess b/.htaccess index 4f6016d..ac61a1f 100644 --- a/.htaccess +++ b/.htaccess @@ -25,5 +25,6 @@ RewriteRule ^solutions$ server_files/solutions.php [L] RewriteRule ^solutions_orga$ server_files/solutions_orga.php [L] RewriteRule ^syntheses$ server_files/syntheses.php [L] RewriteRule ^syntheses_orga$ server_files/syntheses_orga.php [L] +RewriteRule ^tournoi/(.*?)/(.*?)$ server_files/tournoi.php?nom=$1&$2 [L] RewriteRule ^tournoi/(.*?)$ server_files/tournoi.php?nom=$1 [L] RewriteRule ^tournois$ server_files/tournois.php [L] diff --git a/server_files/ajouter_tournoi.php b/server_files/ajouter_tournoi.php index 434897f..829edee 100644 --- a/server_files/ajouter_tournoi.php +++ b/server_files/ajouter_tournoi.php @@ -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") {