mirror of
https://gitlab.com/animath/si/plateforme-corres2math.git
synced 2024-12-25 17:42:22 +00:00
155 lines
4.4 KiB
PHP
155 lines
4.4 KiB
PHP
<?php
|
|
|
|
if (isset($_POST["leave_team"])) {
|
|
quitTeam();
|
|
exit();
|
|
}
|
|
|
|
$has_error = false;
|
|
$error_message = null;
|
|
|
|
if (isset($_POST["send_document"])) {
|
|
$send_document = new SendDocument();
|
|
try {
|
|
$send_document->makeVerifications();
|
|
$send_document->sendDocument();
|
|
}
|
|
catch (AssertionError $e) {
|
|
$has_error = true;
|
|
$error_message = $e->getMessage();
|
|
}
|
|
}
|
|
|
|
if (isset($_POST["team_edit"])) {
|
|
$my_team = new MyTeam($_POST);
|
|
try {
|
|
$my_team->makeVerifications();
|
|
$my_team->updateTeam();
|
|
}
|
|
catch (AssertionError $e) {
|
|
$has_error = true;
|
|
$error_message = $e->getMessage();
|
|
}
|
|
}
|
|
|
|
if (isset($_POST["request_validation"])) {
|
|
if (!canValidate($team)) {
|
|
$has_error = true;
|
|
$error_message = "Votre équipe ne peut pas demander la validation : il manque soit des participants, soit des documents.";
|
|
}
|
|
else if (!isset($_POST["engage"])) {
|
|
$has_error = true;
|
|
$error_message = "Vous devez cocher la case qui vous engage à participer à l'intégralité des Correspondances.";
|
|
}
|
|
else
|
|
$_SESSION["team"]->setValidationStatus(ValidationStatus::WAITING);
|
|
}
|
|
|
|
$documents = [];
|
|
/** @var Question[][] $questions_received */
|
|
$questions_received = [];
|
|
|
|
if (isset($_SESSION["user_id"]) && isset($_SESSION["team"]) && $_SESSION["team"] !== null) {
|
|
/**
|
|
* @var User $user
|
|
* @var Team $team
|
|
*/
|
|
$user = $_SESSION["user"];
|
|
$team = $_SESSION["team"];
|
|
|
|
$documents = $user->getAllDocuments($team->getProblem());
|
|
$video = Video::getVideo(Reason::SOLUTION, $team);
|
|
$questions_received = Question::getQuestionsTo($team);
|
|
}
|
|
else
|
|
require_once "server_files/403.php";
|
|
|
|
if (isset($_GET["publish_videos"])) {
|
|
$team->setAllowPublish(!$team->allowPublish());
|
|
header("Location: /mon-equipe");
|
|
exit();
|
|
}
|
|
|
|
class SendDocument
|
|
{
|
|
private $file;
|
|
private $type;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->file = $_FILES["document"];
|
|
$this->type = strtoupper(htmlspecialchars($_POST["type"]));
|
|
}
|
|
|
|
public function makeVerifications()
|
|
{
|
|
global $LOCAL_PATH;
|
|
|
|
ensure($this->file["size"] <= 2e6, "Le fichier doit peser moins que 2 Mo.");
|
|
ensure(!$this->file["error"], "Une erreur est survenue.");
|
|
ensure(finfo_file(finfo_open(FILEINFO_MIME_TYPE), $this->file["tmp_name"]) == "application/pdf", "Le fichier doit être au format PDF.");
|
|
ensure(is_dir("$LOCAL_PATH/files") || mkdir("$LOCAL_PATH/files"), "Un problème est survenue dans l'envoi du fichier. Veuillez contacter l'administrateur du serveur.");
|
|
}
|
|
|
|
public function sendDocument()
|
|
{
|
|
global $LOCAL_PATH, $DB;
|
|
|
|
do
|
|
$id = genRandomPhrase(64);
|
|
while (file_exists("$LOCAL_PATH/files/$id"));
|
|
|
|
if (!rename($this->file["tmp_name"], "$LOCAL_PATH/files/$id"))
|
|
throw new AssertionError("Une erreur est survenue lors de l'envoi du fichier.");
|
|
|
|
$req = $DB->prepare("INSERT INTO `documents`(`file_id`, `user`, `team`, `problem`, `type`)
|
|
VALUES (?, ?, ?, ?, ?);");
|
|
$req->execute([$id, $_SESSION["user_id"], $_SESSION["team"]->getId(), $_SESSION["team"]->getProblem(), $this->type]);
|
|
}
|
|
}
|
|
|
|
class MyTeam
|
|
{
|
|
public $name;
|
|
public $trigram;
|
|
public $problem;
|
|
/** @var Team */
|
|
private $team;
|
|
|
|
public function __construct($data)
|
|
{
|
|
foreach ($data as $key => $value)
|
|
$this->$key = htmlspecialchars($value);
|
|
|
|
$this->trigram = strtoupper($this->trigram);
|
|
$this->team = $_SESSION["team"];
|
|
}
|
|
|
|
public function makeVerifications()
|
|
{
|
|
global $CONFIG;
|
|
|
|
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.");
|
|
ensure(date("Y-m-d H:i:s") <= $CONFIG->getInscriptionDate(), "Les inscriptions sont terminées.");
|
|
ensure($this->team->getValidationStatus() == ValidationStatus::NOT_READY, "Votre équipe est déjà validée ou en cours de validation.");
|
|
}
|
|
|
|
public function updateTeam()
|
|
{
|
|
global $URL_BASE;
|
|
|
|
$this->team->setName($this->name);
|
|
$this->team->setTrigram($this->trigram);
|
|
$this->team->setProblem($this->problem);
|
|
|
|
header("Location: $URL_BASE/mon-equipe");
|
|
}
|
|
}
|
|
|
|
require_once "server_files/views/mon_equipe.php";
|