Amélioration du code de la page "Notes de synthèse" (vue équipe)
This commit is contained in:
parent
44e3e3f639
commit
cca62a99d0
|
@ -231,34 +231,34 @@ class DestType
|
||||||
|
|
||||||
public static function getTranslatedName($status) {
|
public static function getTranslatedName($status) {
|
||||||
switch ($status) {
|
switch ($status) {
|
||||||
case self::DEFENSEUR:
|
|
||||||
return "Défenseur";
|
|
||||||
case self::OPPOSANT:
|
case self::OPPOSANT:
|
||||||
return "Opposant";
|
return "Opposant";
|
||||||
default:
|
case self::RAPPORTEUR:
|
||||||
return "Rapporteur";
|
return "Rapporteur";
|
||||||
|
default:
|
||||||
|
return "Défenseur";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getName($status) {
|
public static function getName($status) {
|
||||||
switch ($status) {
|
switch ($status) {
|
||||||
case self::DEFENSEUR:
|
|
||||||
return "DEFENSEUR";
|
|
||||||
case self::OPPOSANT:
|
case self::OPPOSANT:
|
||||||
return "OPPOSANT";
|
return "OPPOSANT";
|
||||||
default:
|
case self::RAPPORTEUR:
|
||||||
return "RAPPORTEUR";
|
return "RAPPORTEUR";
|
||||||
|
default:
|
||||||
|
return "DEFENSEUR";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function fromName($name) {
|
public static function fromName($name) {
|
||||||
switch ($name) {
|
switch ($name) {
|
||||||
case "DEFENSEUR":
|
|
||||||
return self::DEFENSEUR;
|
|
||||||
case "OPPOSANT":
|
case "OPPOSANT":
|
||||||
return self::OPPOSANT;
|
return self::OPPOSANT;
|
||||||
default:
|
case "RAPPORTEUR":
|
||||||
return self::RAPPORTEUR;
|
return self::RAPPORTEUR;
|
||||||
|
default:
|
||||||
|
return self::DEFENSEUR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,6 +54,7 @@ class SaveSolution
|
||||||
public function saveSolution()
|
public function saveSolution()
|
||||||
{
|
{
|
||||||
global $LOCAL_PATH, $DB, $team, $tournament, $FINAL;
|
global $LOCAL_PATH, $DB, $team, $tournament, $FINAL;
|
||||||
|
|
||||||
do
|
do
|
||||||
$id = genRandomPhrase(64);
|
$id = genRandomPhrase(64);
|
||||||
while (file_exists("$LOCAL_PATH/files/$id"));
|
while (file_exists("$LOCAL_PATH/files/$id"));
|
||||||
|
|
|
@ -11,7 +11,14 @@ $team = $_SESSION["team"];
|
||||||
$tournament = Tournament::fromId($team->getTournamentId());
|
$tournament = Tournament::fromId($team->getTournamentId());
|
||||||
|
|
||||||
if (isset($_POST["send_synthesis"])) {
|
if (isset($_POST["send_synthesis"])) {
|
||||||
$error_message = saveSynthesis();
|
$save_synthesis = new SaveSynthesis();
|
||||||
|
try {
|
||||||
|
$save_synthesis->makeVerifications();
|
||||||
|
$save_synthesis->saveSynthesis();
|
||||||
|
} catch (AssertionError $e) {
|
||||||
|
$has_error = true;
|
||||||
|
$error_message = $e->getMessage();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$syntheses = $tournament->getAllSyntheses($team->getId());
|
$syntheses = $tournament->getAllSyntheses($team->getId());
|
||||||
|
@ -19,36 +26,43 @@ $syntheses_final = null;
|
||||||
if ($team->isSelectedForFinal())
|
if ($team->isSelectedForFinal())
|
||||||
$syntheses_final = $FINAL->getAllSyntheses($team->getId());
|
$syntheses_final = $FINAL->getAllSyntheses($team->getId());
|
||||||
|
|
||||||
function saveSynthesis() {
|
class SaveSynthesis
|
||||||
global $LOCAL_PATH, $DB, $team, $tournament, $FINAL;
|
{
|
||||||
|
private $dest;
|
||||||
|
private $file;
|
||||||
|
|
||||||
$dest = strtoupper(htmlspecialchars($_POST["dest"]));
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->file = $_FILES["document"];
|
||||||
|
$this->dest = DestType::fromName(strtoupper(htmlspecialchars($_POST["problem"])));
|
||||||
|
}
|
||||||
|
|
||||||
if (!isset($dest) || ($dest != "OPPOSANT" && $dest != "RAPPORTEUR"))
|
public function makeVerifications()
|
||||||
return "Le destinataire est invalide.";
|
{
|
||||||
|
global $LOCAL_PATH;
|
||||||
|
|
||||||
$file = $_FILES["synthese"];
|
ensure($this->dest != DestType::DEFENSEUR, "Le destinataire est invalide.");
|
||||||
|
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.");
|
||||||
|
}
|
||||||
|
|
||||||
if ($file["size"] > 5000000 || $file["error"])
|
public function saveSynthesis()
|
||||||
return "Une erreur est survenue. Merci de vérifier que le fichier pèse moins que 5 Mo.";
|
{
|
||||||
|
global $LOCAL_PATH, $DB, $team, $tournament, $FINAL;
|
||||||
|
do
|
||||||
|
$id = genRandomPhrase(64);
|
||||||
|
while (file_exists("$LOCAL_PATH/files/$id"));
|
||||||
|
|
||||||
if (finfo_file(finfo_open(FILEINFO_MIME_TYPE), $file["tmp_name"]) != 'application/pdf')
|
if (!rename($this->file["tmp_name"], "$LOCAL_PATH/files/$id"))
|
||||||
return "Le fichier doit être au destmat PDF.";
|
throw new AssertionError("Une erreur est survenue lors de l'envoi du fichier.");
|
||||||
|
|
||||||
if (!is_dir("$LOCAL_PATH/files") && !mkdir("$LOCAL_PATH/files"))
|
$req = $DB->prepare("INSERT INTO `syntheses`(`file_id`, `team`, `tournament`, `dest`) VALUES (?, ?, ?, ?);");
|
||||||
return "Les droits sont insuffisants. Veuillez contacter l'administrateur du serveur.";
|
$req->execute([$id, $team->getId(), $team->isSelectedForFinal() ? $FINAL->getId() : $tournament->getId(), $this->dest]);
|
||||||
|
|
||||||
do
|
return false;
|
||||||
$id = genRandomPhrase(64);
|
}
|
||||||
while (file_exists("$LOCAL_PATH/files/$id"));
|
|
||||||
|
|
||||||
if (!rename($file["tmp_name"], "$LOCAL_PATH/files/$id"))
|
|
||||||
return "Une erreur est survenue lors de l'envoi du fichier.";
|
|
||||||
|
|
||||||
$req = $DB->prepare("INSERT INTO `syntheses`(`file_id`, `team`, `tournament`, `dest`) VALUES (?, ?, ?, ?);");
|
|
||||||
$req->execute([$id, $team->getId(), $team->isSelectedForFinal() ? $FINAL->getId() : $tournament->getId(), $dest]);
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
require_once "server_files/views/syntheses.php";
|
require_once "server_files/views/syntheses.php";
|
||||||
|
|
Loading…
Reference in New Issue