plateforme-tfjm2/server_files/controllers/syntheses.php

61 lines
1.9 KiB
PHP
Raw Normal View History

2019-09-06 11:48:50 +00:00
<?php
if (!isset($_SESSION["team"]))
require_once "server_files/403.php";
2019-09-06 11:48:50 +00:00
/**
* @var Team $team
* @var Tournament $tournament
*/
$team = $_SESSION["team"];
2019-09-07 23:35:05 +00:00
$tournament = Tournament::fromId($team->getTournamentId());
2019-09-07 23:35:05 +00:00
if (isset($_POST["send_synthesis"])) {
$error_message = saveSynthesis();
}
2019-09-06 11:48:50 +00:00
2019-09-07 23:35:05 +00:00
$syntheses = $tournament->getAllSyntheses($team->getId());
$syntheses_final = null;
if ($team->isSelectedForFinal())
$syntheses_final = $FINAL->getAllSyntheses($team->getId());
2019-09-06 11:48:50 +00:00
2019-09-07 23:35:05 +00:00
function saveSynthesis() {
global $LOCAL_PATH, $DB, $team, $tournament, $FINAL;
2019-09-06 11:48:50 +00:00
$dest = strtoupper(htmlspecialchars($_POST["dest"]));
if (!isset($dest) || ($dest != "OPPOSANT" && $dest != "RAPPORTEUR"))
return "Le destinataire est invalide.";
$file = $_FILES["synthese"];
if ($file["size"] > 5000000 || $file["error"])
return "Une erreur est survenue. Merci de vérifier que le fichier pèse moins que 5 Mo.";
if (finfo_file(finfo_open(FILEINFO_MIME_TYPE), $file["tmp_name"]) != 'application/pdf')
return "Le fichier doit être au destmat PDF.";
if (!is_dir("$LOCAL_PATH/files") && !mkdir("$LOCAL_PATH/files"))
return "Les droits sont insuffisants. Veuillez contacter l'administrateur du serveur.";
$alphabet = "abcdefghijklmnopqrstuvwxyz0123456789";
do {
$id = "";
for ($i = 0; $i < 64; ++$i) {
$id .= $alphabet[rand(0, strlen($alphabet) - 1)];
}
}
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 (?, ?, ?, ?);");
2019-09-07 23:35:05 +00:00
$req->execute([$id, $team->getId(), $team->isSelectedForFinal() ? $FINAL->getId() : $tournament->getId(), $dest]);
2019-09-06 11:48:50 +00:00
return false;
}
require_once "server_files/views/syntheses.php";