diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml
new file mode 100644
index 0000000..0be229c
--- /dev/null
+++ b/.idea/dataSources.xml
@@ -0,0 +1,20 @@
+
+
+
+
+ mysql.8
+ true
+ com.mysql.cj.jdbc.Driver
+ jdbc:mysql://galaxyoyo.com:3306/corres2math
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/dispatcher.php b/dispatcher.php
index 3dbcbd3..6f347a9 100644
--- a/dispatcher.php
+++ b/dispatcher.php
@@ -38,6 +38,8 @@ $ROUTES["^inscription/?$"] = ["server_files/controllers/inscription.php"];
$ROUTES["^mon_compte/?$"] = ["server_files/controllers/mon_compte.php"];
$ROUTES["^mon_equipe/(modifier)/?$"] = ["server_files/controllers/mon_equipe.php", "modifier"];
$ROUTES["^mon_equipe/?$"] = ["server_files/controllers/mon_equipe.php"];
+$ROUTES["^probleme/([1-4])/?$"] = ["server_files/controllers/probleme.php", "probleme"];
+$ROUTES["^problemes/?$"] = ["server_files/controllers/problemes.php"];
$ROUTES["^rejoindre_equipe/?$"] = ["server_files/controllers/rejoindre_equipe.php"];
# Assets files
diff --git a/server_files/config.php b/server_files/config.php
index e2ad09d..056262b 100644
--- a/server_files/config.php
+++ b/server_files/config.php
@@ -7,7 +7,6 @@ $YEAR = $_ENV["CORRES2MATH_YEAR"];
$URL_BASE = $_ENV["CORRES2MATH_URL_BASE"];
$LOCAL_PATH = $_ENV["CORRES2MATH_LOCAL_PATH"];
$MAIL_DOMAIN = $_ENV["CORRES2MATH_MAIL_DOMAIN"];
-$MAIL_DOMAIN = "correspondances-maths.fr";
/**
* DB infos
@@ -25,5 +24,163 @@ catch (Exception $ex) {
die("Erreur lors de la connexion à la base de données : " . $ex->getMessage());
}
+$CONFIG = new Config();
+$CONFIG->initDB();
+$CONFIG->loadConfigValues();
+
+class Config
+{
+ private $inscription_date;
+ private $start_phase1_date;
+ private $end_phase1_date;
+ private $start_phase2_date;
+ private $end_phase2_date;
+ private $start_phase3_date;
+ private $end_phase3_date;
+ private $start_phase4_date;
+ private $end_phase4_date;
+
+ public function initDB()
+ {
+ global $DB;
+
+ $DB->exec("SET GLOBAL time_zone = 'Europe/Paris';");
+ $DB->exec("INSERT IGNORE INTO `config` VALUES ('inscription_date', CURRENT_TIMESTAMP), ('start_phase1_date', CURRENT_TIMESTAMP), ('end_phase1_date', CURRENT_TIMESTAMP),
+ ('start_phase2_date', CURRENT_TIMESTAMP), ('end_phase2_date', CURRENT_TIMESTAMP),
+ ('start_phase3_date', CURRENT_TIMESTAMP), ('end_phase3_date', CURRENT_TIMESTAMP),
+ ('start_phase4_date', CURRENT_TIMESTAMP), ('end_phase4_date', CURRENT_TIMESTAMP);");
+ }
+
+ public function loadConfigValues()
+ {
+ global $DB;
+
+ $req = $DB->query("SELECT * FROM `config`;");
+
+ while (($data = $req->fetch()) !== false) {
+ $key = $data["key"];
+ $this->$key = $data["value"];
+ }
+ }
+
+ public function getInscriptionDate()
+ {
+ return $this->inscription_date;
+ }
+
+ public function setInscriptionDate($inscription_date)
+ {
+ global $DB;
+ $DB->exec("UPDATE `config` SET `value` = '$inscription_date' WHERE `key` = 'inscription_date';");
+
+ $this->inscription_date = $inscription_date;
+ }
+
+ public function getStartPhase1Date()
+ {
+ return $this->start_phase1_date;
+ }
+
+ public function setStartPhase1Date($start_phase1_date)
+ {
+ global $DB;
+ $DB->exec("UPDATE `config` SET `value` = '$start_phase1_date' WHERE `key` = 'start_phase1_date';");
+
+ $this->start_phase1_date = $start_phase1_date;
+ }
+
+ public function getEndPhase1Date()
+ {
+ return $this->end_phase1_date;
+ }
+
+ public function setEndPhase1Date($end_phase1_date)
+ {
+ global $DB;
+ $DB->exec("UPDATE `config` SET `value` = '$end_phase1_date' WHERE `key` = 'end_phase1_date';");
+
+ $this->end_phase1_date = $end_phase1_date;
+ }
+
+ public function getStartPhase2Date()
+ {
+ return $this->start_phase2_date;
+ }
+
+ public function setStartPhase2Date($start_phase2_date)
+ {
+ global $DB;
+ $DB->exec("UPDATE `config` SET `value` = '$start_phase2_date' WHERE `key` = 'start_phase2_date';");
+
+ $this->start_phase2_date = $start_phase2_date;
+ }
+
+ public function getEndPhase2Date()
+ {
+ return $this->end_phase2_date;
+ }
+
+ public function setEndPhase2Date($end_phase2_date)
+ {
+ global $DB;
+ $DB->exec("UPDATE `config` SET `value` = '$end_phase2_date' WHERE `key` = 'end_phase2_date';");
+
+ $this->end_phase2_date = $end_phase2_date;
+ }
+
+ public function getStartPhase3Date()
+ {
+ return $this->start_phase3_date;
+ }
+
+ public function setStartPhase3Date($start_phase3_date)
+ {
+ global $DB;
+ $DB->exec("UPDATE `config` SET `value` = '$start_phase3_date' WHERE `key` = 'start_phase3_date';");
+
+ $this->start_phase3_date = $start_phase3_date;
+ }
+
+ public function getEndPhase3Date()
+ {
+ return $this->end_phase3_date;
+ }
+
+ public function setEndPhase3Date($end_phase3_date)
+ {
+ global $DB;
+ $DB->exec("UPDATE `config` SET `value` = '$end_phase3_date' WHERE `key` = 'end_phase3_date';");
+
+ $this->end_phase3_date = $end_phase3_date;
+ }
+
+ public function getStartPhase4Date()
+ {
+ return $this->start_phase4_date;
+ }
+
+ public function setStartPhase4Date($start_phase4_date)
+ {
+ global $DB;
+ $DB->exec("UPDATE `config` SET `value` = '$start_phase4_date' WHERE `key` = 'start_phase4_date';");
+
+ $this->start_phase4_date = $start_phase4_date;
+ }
+
+ public function getEndPhase4Date()
+ {
+ return $this->end_phase4_date;
+ }
+
+ public function setEndPhase4Date($end_phase4_date)
+ {
+ global $DB;
+ $DB->exec("UPDATE `config` SET `value` = '$end_phase4_date' WHERE `key` = 'end_phase4_date';");
+
+ $this->end_phase4_date = $end_phase4_date;
+ }
+}
+
session_start();
setlocale(LC_ALL, "fr_FR.utf8");
+date_default_timezone_set("Europe/Paris");
diff --git a/server_files/controllers/ajouter_equipe.php b/server_files/controllers/ajouter_equipe.php
index 2d03fb4..81c6c12 100644
--- a/server_files/controllers/ajouter_equipe.php
+++ b/server_files/controllers/ajouter_equipe.php
@@ -28,11 +28,14 @@ class NewTeam {
{
foreach ($data as $key => $value)
$this->$key = htmlspecialchars($value);
+
+ $this->trigram = strtoupper($this->trigram);
}
public function makeVerifications() {
ensure($_SESSION["team"] == null, "Vous êtes déjà dans une équipe.");
ensure($this->name != null && $this->name != "", "Vous devez spécifier un nom d'équipe.");
+ ensure(preg_match("#^[\p{L} ]+$#ui", $this->name), "Le nom de l'équite ne doit pas comporter de caractères spéciaux.");
ensure(preg_match("#^[A-Z]{3}$#", $this->trigram), "Le trigramme entré n'est pas valide.");
ensure(!teamExists($this->name), "Une équipe existe déjà avec ce nom.");
ensure(!trigramExists($this->trigram), "Une équipe a déjà choisi ce trigramme.");
diff --git a/server_files/controllers/informations.php b/server_files/controllers/informations.php
index 1fbce25..d18589d 100644
--- a/server_files/controllers/informations.php
+++ b/server_files/controllers/informations.php
@@ -16,8 +16,7 @@ if ($user === null)
$team = Team::fromId($user->getTeamId());
-if ($team != null) {
+if ($team != null)
$documents = $user->getAllDocuments($team->getProblem());
-}
require_once "server_files/views/informations.php";
diff --git a/server_files/controllers/mon_equipe.php b/server_files/controllers/mon_equipe.php
index a354d64..d7ff562 100644
--- a/server_files/controllers/mon_equipe.php
+++ b/server_files/controllers/mon_equipe.php
@@ -111,6 +111,7 @@ class MyTeam
{
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("#^[\p{L} ]+$#ui", $this->name), "Le nom de l'équipe ne doit pas comporter de caractères spéciaux.");
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(preg_match("#^[1-4]$#", $this->problem), "Le problème indiqué n'existe pas.");
diff --git a/server_files/controllers/probleme.php b/server_files/controllers/probleme.php
new file mode 100644
index 0000000..c06aa02
--- /dev/null
+++ b/server_files/controllers/probleme.php
@@ -0,0 +1,122 @@
+makeVerifications();
+ $update_tournament->updateTournament();
+ } catch (AssertionError $e) {
+ $has_error = true;
+ $error_message = $e->getMessage();
+ }
+}
+
+$teams = []; //$tournament->getAllTeams();
+
+class UpdateTournament
+{
+ public $name;
+ public $organizers;
+ public $size;
+ public $place;
+ public $price;
+ public $date_start;
+ public $date_end;
+ public $date_inscription;
+ public $time_inscription;
+ public $date_solutions;
+ public $time_solutions;
+ public $date_syntheses;
+ public $time_syntheses;
+ public $description;
+ public $final;
+
+ public function __construct($data)
+ {
+ global $tournament;
+
+ foreach ($data as $key => $value)
+ $this->$key = ($key == "organizers" ? $value : htmlspecialchars($value));
+
+ if ($_SESSION["role"] != Role::ADMIN) {
+ $this->organizers = [];
+ /** @var User $organizer */
+ foreach ($tournament->getOrganizers() as $organizer)
+ $this->organizers[] = $organizer->getId();
+ }
+ }
+
+ public function makeVerifications()
+ {
+ global $tournament;
+
+ ensure($this->name != null && $this->name != "", "Le nom est invalide.");
+ ensure($this->name == $tournament->getName() || !tournamentExists($this->name), "Un tournoi existe déjà avec ce nom.");
+ ensure(sizeof($this->organizers) > 0, "Aucun organisateur n'a été choisi.");
+
+ $orgas = [];
+ foreach ($this->organizers as $orga_id) {
+ $orga = User::fromId($orga_id);
+ ensure($orga != null, "Un organisateur spécifié n'existe pas.");
+ ensure($orga->getRole() == Role::ORGANIZER || $orga->getRole() == Role::ADMIN, "Une personne indiquée ne peut pas organiser de tournoi.");
+ $orgas[] = $orga;
+ }
+ $this->organizers = $orgas;
+
+ ensure(preg_match("#[0-9]*#", $this->size), "Le nombre d'équipes indiqué n'est pas un nombre valide.");
+ $this->size = intval($this->size);
+ ensure($this->size >= 3 && $this->size <= 15, "Un tournoi doit avoir au moins 3 et au plus 15 équipes.");
+
+ ensure(preg_match("#[0-9]*#", $this->price), "Le tarif pour les participants n'est pas un entier valide.");
+ $this->price = intval($this->price);
+ ensure($this->price >= 0, "Le TFJM² ne va pas payer les élèves pour venir.");
+ ensure($this->price <= 50, "Soyons raisonnable sur le prix.");
+
+ ensure(dateWellFormed($this->date_start), "La date de début n'est pas valide.");
+ ensure(dateWellFormed($this->date_end), "La date de fin n'est pas valide.");
+ ensure(dateWellFormed($this->date_inscription . " " . $this->time_inscription), "La date de clôture des inscriptions n'est pas valide.");
+ ensure(dateWellFormed($this->date_solutions . " " . $this->time_solutions), "La date limite de remise des solutions n'est pas valide.");
+ ensure(dateWellFormed($this->date_syntheses . " " . $this->time_syntheses), "La date limite de remise des notes de synthèse n'est pas valide.");
+ }
+
+ public function updateTournament()
+ {
+ global $URL_BASE, $tournament;
+
+ $tournament->setName($this->name);
+ $tournament->setSize($this->size);
+ $tournament->setPlace($this->place);
+ $tournament->setPrice($this->price);
+ $tournament->setStartDate($this->date_start);
+ $tournament->setEndDate($this->date_end);
+ $tournament->setInscriptionDate("$this->date_inscription $this->time_inscription");
+ $tournament->setSolutionsDate("$this->date_solutions $this->time_solutions");
+ $tournament->setSynthesesDate("$this->date_syntheses $this->time_syntheses");
+
+ foreach ($this->organizers as $organizer) {
+ if (!$tournament->organize($organizer->getId()))
+ Mailer::sendAddOrganizerForTournamentMail($organizer, $tournament);
+ }
+
+ $tournament->clearOrganizers();
+ /** @var User $organizer */
+ foreach ($this->organizers as $organizer)
+ $tournament->addOrganizer($organizer);
+
+ header("Location: $URL_BASE/tournoi/" . $this->name);
+ exit();
+ }
+}
+
+require_once "server_files/views/probleme.php";
diff --git a/server_files/controllers/problemes.php b/server_files/controllers/problemes.php
new file mode 100644
index 0000000..faa6c0d
--- /dev/null
+++ b/server_files/controllers/problemes.php
@@ -0,0 +1,3 @@
+
-isSelectedForFinal()) { ?>
-
- Autorisations pour la finale
-
-
-
-
getValidationStatus() == ValidationStatus::WAITING && $_SESSION["role"] == Role::ADMIN) { ?>
-
-
-
\ No newline at end of file
+require_once "footer.php" ?>
\ No newline at end of file
diff --git a/server_files/views/header.php b/server_files/views/header.php
index 9b9e821..b85ca6f 100644
--- a/server_files/views/header.php
+++ b/server_files/views/header.php
@@ -24,7 +24,8 @@