1
0
mirror of https://gitlab.com/animath/si/plateforme-corres2math.git synced 2024-12-05 02:06:52 +00:00

Étape 0 : inscription des équipes (en cours)

This commit is contained in:
galaxyoyo 2019-09-12 12:18:15 +02:00
parent 340be7faf5
commit 7ef88be38c
14 changed files with 541 additions and 32 deletions

20
.idea/dataSources.xml Normal file
View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DataSourceManagerImpl" format="xml" multifile-model="true">
<data-source source="LOCAL" name="corres2math@galaxyoyo.com" uuid="ffa0ffc8-d602-402c-b199-f2cc9c5789c8">
<driver-ref>mysql.8</driver-ref>
<synchronize>true</synchronize>
<jdbc-driver>com.mysql.cj.jdbc.Driver</jdbc-driver>
<jdbc-url>jdbc:mysql://galaxyoyo.com:3306/corres2math</jdbc-url>
<driver-properties>
<property name="autoReconnect" value="true" />
<property name="zeroDateTimeBehavior" value="CONVERT_TO_NULL" />
<property name="tinyInt1isBit" value="false" />
<property name="characterEncoding" value="utf8" />
<property name="characterSetResults" value="utf8" />
<property name="yearIsDateType" value="false" />
<property name="serverTimezone" value="Europe/Paris" />
</driver-properties>
</data-source>
</component>
</project>

View File

@ -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

View File

@ -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");

View File

@ -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.");

View File

@ -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";

View File

@ -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.");

View File

@ -0,0 +1,122 @@
<?php
$problem = htmlspecialchars($_GET["probleme"]);
if (!preg_match("#[1-4]#", $problem))
require_once "server_files/404.php";
if (isset($_GET["modifier"]) && $_SESSION["role"] != Role::ADMIN)
require_once "server_files/403.php";
$has_error = false;
$error_message = null;
if (isset($_POST["edit_tournament"])) {
$update_tournament = new UpdateTournament($_POST);
try {
$update_tournament->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";

View File

@ -0,0 +1,3 @@
<?php
require_once "server_files/views/problemes.php";

View File

@ -30,16 +30,6 @@ for ($i = 1; $i <= 6; ++$i) {
<input style="width: 100%;" type="submit" name="download_zip" value="Télécharger l'archive"/>
</form>
<?php if ($team->isSelectedForFinal()) { ?>
<hr/>
<h2>Autorisations pour la finale</h2>
<?php printDocuments($documents_final) ?>
<form method="POST">
<input type="hidden" name="final" value="true" />
<input style="width: 100%;" type="submit" name="download_zip" value="Télécharger l'archive"/>
</form>
<?php } ?>
<?php if ($team->getValidationStatus() == ValidationStatus::WAITING && $_SESSION["role"] == Role::ADMIN) { ?>
<form method="POST">
<input style="width: 100%;" type="submit" name="validate" value="Valider l'équipe"/>
@ -47,11 +37,4 @@ for ($i = 1; $i <= 6; ++$i) {
<?php
}
if (!$team->isSelectedForFinal() && $_SESSION["role"] == Role::ADMIN) { ?>
<hr/>
<form method="POST">
<input style="width: 100%;" type="submit" name="select" value="Sélectionner pour la finale nationale"/>
</form>
<?php } ?>
<?php require_once "footer.php" ?>
require_once "footer.php" ?>

View File

@ -24,7 +24,8 @@
<body>
<ul id="menu">
<li id="menu-logo"><img src="<?= $URL_BASE ?>/logo.png" alt="Logo Corres2Math"></li>
<li><a href="<?= $URL_BASE ?>/">Accueil</a></li>
<li><a href="<?= $URL_BASE ?>/">Accueil</a></li>
<li><a href="<?= $URL_BASE ?>/problemes">Liste des problèmes</a></li>
<?php if (!isset($_SESSION["user_id"])) { ?>
<li><a href="<?= $URL_BASE ?>/connexion">Connexion</a></li>
<li><a href="<?= $URL_BASE ?>/inscription">Inscription</a></li>

View File

@ -18,8 +18,7 @@ echo "<hr />";
if ($user->getRole() == Role::PARTICIPANT || $user->getRole() == Role::ENCADRANT) { ?>
<h2>Autorisations</h2>
<?php
// TODO Add documents
# printDocuments($documents);
printDocuments($documents);
}
require_once "footer.php";

View File

@ -59,7 +59,7 @@ for ($i = 1; $i <= 6; ++$i) {
<select style="width: 100%;" id="problem" name="problem">
<?php
for ($i = 1; $i <= 4; ++$i)
echo "<option value=\"$i\"" . ($team->getProblem() == $i ? "selected" : "") . ">$i</option>\n";
echo "<option value=\"$i\" " . ($team->getProblem() == $i ? "selected" : "") . ">$i</option>\n";
?>
</select>
</td>
@ -82,13 +82,11 @@ for ($i = 1; $i <= 6; ++$i) {
<hr/>
<h2>Mes autorisations</h2>
<?php
// TODO Add documents
//printDocuments($documents);
printDocuments($documents);
if ($team->getValidationStatus() == ValidationStatus::NOT_READY) { ?>
<hr />
<form method="post" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="5000000"/>
<table style="width: 100%;">
<tbody>
<tr>
@ -128,13 +126,11 @@ for ($i = 1; $i <= 6; ++$i) {
</form>
</td>
<?php
// TODO check end of inscription
$can_validate = canValidate($team);
if (true) { ?>
if ($can_validate) { ?>
<td style="width: 50%;">
<form method="post">
<input style="width: 100%;" type="submit" name="request_validation"
value="Demander la validation"/>
<input style="width: 100%;" type="submit" name="request_validation" value="Demander la validation"/>
</form>
</td>
<?php } ?>

View File

@ -0,0 +1,191 @@
<?php require_once "header.php" ?>
<?php
if ($has_error)
echo "<h2>Erreur : $error_message</h2>";
?>
<h2>Problème <?= $problem ?></h2>
<?php if (!isset($_GET["modifier"]) && $_SESSION["role"] == Role::ADMIN) { ?>
<a href="<?= $URL_BASE ?>/probleme/<?= $problem ?>/modifier">Éditer le tournoi</a>
<?php } ?>
<?php if (!isset($_GET["modifier"])) { ?>
<hr/>
<h2>Équipes inscrites pour ce problème :</h2>
<table style="border: 1px solid black; width: 100%;">
<thead>
<tr>
<th style="border: 1px solid black; text-align: center">
Équipe
</th>
<th style="border: 1px solid black; text-align: center">
Trigramme
</th>
<th style="border: 1px solid black; text-align: center">
Date d'inscription
</th>
<th style="border: 1px solid black; text-align: center">
État de validation de l'inscription
</th>
</tr>
</thead>
<tbody>
<?php
/** @var Team $team */
foreach ($teams as $team) {
?>
<tr>
<td style="border: 1px solid black; text-align: center">
<?php
if (isset($_SESSION["role"]) && $_SESSION["role"] == Role::ADMIN)
echo "<a href=\"$URL_BASE/equipe/" . $team->getTrigram() . "\">" . $team->getName(). "</a>";
else
echo $team->getName();
?>
</td>
<td style="border: 1px solid black; text-align: center"><?= $team->getTrigram() ?></td>
<td style="border: 1px solid black; text-align: center"><?= formatDate($team->getInscriptionDate()) ?></td>
<td style="border: 1px solid black; text-align: center"><?= ValidationStatus::getTranslatedName($team->getValidationStatus()) ?></td>
</tr>
<?php
}
?>
</tbody>
<tfoot>
<tr>
<th style="border: 1px solid black; text-align: center">
Équipe
</th>
<th style="border: 1px solid black; text-align: center">
Trigramme
</th>
<th style="border: 1px solid black; text-align: center">
Date d'inscription
</th>
<th style="border: 1px solid black; text-align: center">
État de validation de l'inscription
</th>
</tr>
</tfoot>
</table>
<?php
}
else {
?>
<form method="POST">
<input type="hidden" name="submitted" 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="<?= $tournament->getName() ?>" required />
</td>
</tr>
<?php if ($_SESSION["role"] == Role::ADMIN) { ?>
<tr>
<td>
<label for="organizers">Organisateur :</label>
</td>
<td>
<select style="width: 100%;" id="organizers" name="organizers[]" multiple size="4" required>
<?php
while (($orga_data = $orgas_response->fetch()) !== FALSE) {
echo "<option value=\"" . $orga_data["id"] . "\" " . ($tournament->organize($orga_data["id"]) ? "selected" : "")
. ">" . $orga_data["first_name"] . " " . $orga_data["surname"] . "</option>\n";
}
?>
</select>
</td>
</tr>
<?php } ?>
<tr>
<td>
<label for="size">Nombre d'équipes :</label>
</td>
<td>
<input style="width: 100%;" type="number" id="size" name="size" min="3" max="12" value="<?= $tournament->getSize() ?>" required />
</td>
</tr>
<tr>
<td>
<label for="place">Lieu :</label>
</td>
<td>
<input style="width: 100%;" type="text" id="place" name="place" value="<?= $tournament->getPlace() ?>" required />
</td>
</tr>
<tr>
<td>
<label for="price">Prix par participant</label>
</td>
<td>
<input style="width: 100%;" type="number" id="price" name="price" min="0" max="50" value="<?= $tournament->getPrice() ?>" required />
</td>
</tr>
<tr>
<td>
<label for="date_start">Dates :</label>
</td>
<td>
Du <input style="width: 45%;" type="date" id="date_start" name="date_start" value="<?= $tournament->getStartDate() ?>" required />
au <input style="width: 45%;" type="date" id="date_end" name="date_end" value="<?= $tournament->getEndDate() ?>" required />
</td>
</tr>
<tr>
<td>
<label for="date_inscription">Date limite d'inscription :</label>
</td>
<td>
<input style="width: 49%;" type="date" id="date_inscription" name="date_inscription" value="<?= substr($tournament->getInscriptionDate(), 0, 10) ?>" required />
<input style="width: 49%;" type="time" id="time_inscription" name="time_inscription" value="<?= substr($tournament->getInscriptionDate(), 11) ?>" required />
</td>
</tr>
<tr>
<td>
<label for="date_solutions">Date limite pour rendre les solutions :</label>
</td>
<td>
<input style="width: 49%;" type="date" id="date_solutions" name="date_solutions" value="<?= substr($tournament->getSolutionsDate(), 0, 10) ?>" required />
<input style="width: 49%;" type="time" id="time_solutions" name="time_solutions" value="<?= substr($tournament->getSolutionsDate(),11) ?>" required />
</td>
</tr>
<tr>
<td>
<label for="date_syntheses">Date limite pour rendre les notes de synthèse :</label>
</td>
<td>
<input style="width: 49%;" type="date" id="date_syntheses" name="date_syntheses"
value="<?= substr($tournament->getSynthesesDate(), 0, 10) ?>" required/>
<input style="width: 49%;" type="time" id="time_syntheses" name="time_syntheses"
value="<?= substr($tournament->getSynthesesDate(), 11) ?>" required/>
</td>
</tr>
<tr>
<td>
<label for="description">Description :</label>
</td>
<td>
<textarea style="width: 100%;" name="description" id="description" required><?= $tournament->getDescription() ?></textarea>
</td>
</tr>
<tr>
<td colspan="2">
<input style="width: 100%;" type="submit" name="edit_tournament" value="Modifier le tournoi" />
</td>
</tr>
</tbody>
</table>
</form>
<?php } ?>
<?php require_once "footer.php" ?>

View File

@ -0,0 +1,32 @@
<?php require_once "header.php" ?>
<h2>Liste des problèmes</h2>
<table style="border: 1px solid black; width: 100%">
<thead style="border: 1px solid black">
<tr>
<th style="border: 1px solid black; text-align: center">Problème</th>
<th style="border: 1px solid black; text-align: center">Inscription avant le</th>
</tr>
</thead>
<tbody style="border: 1px solid black">
<?php
for ($i = 1; $i <= 4; ++$i) {
?>
<tr style="border: 1px solid black">
<td style="border: 1px solid black; text-align: center"><a href="<?= $URL_BASE ?>/probleme/<?= $i ?>"><?= $i ?></a></td>
<td style="border: 1px solid black; text-align: center"><?= formatDate($CONFIG->getInscriptionDate(), true) ?></td>
</tr>
<?php
}
?>
</tbody>
<tfoot style="border: 1px solid black">
<tr>
<th style="border: 1px solid black; text-align: center">Problème</th>
<th style="border: 1px solid black; text-align: center">Inscription avant le</th>
</tr>
</tfoot>
</table>
<?php require_once "footer.php" ?>