mirror of
https://gitlab.com/animath/si/plateforme.git
synced 2024-11-30 04:53:02 +00:00
65 lines
2.0 KiB
PHP
65 lines
2.0 KiB
PHP
<?php
|
|
|
|
if (!isset($_SESSION["team"]))
|
|
require_once "server_files/403.php";
|
|
|
|
/**
|
|
* @var Team $team
|
|
* @var Tournament $tournament
|
|
*/
|
|
$team = $_SESSION["team"];
|
|
$tournament = Tournament::fromId($team->getTournamentId());
|
|
|
|
if (isset($_POST["send_solution"])) {
|
|
$error_message = saveSolution();
|
|
}
|
|
|
|
$solutions = $tournament->getAllSolutions($team->getId());
|
|
$solutions_final = null;
|
|
if ($team->isSelectedForFinal())
|
|
$solutions_final = $FINAL->getAllSolutions($team->getId());
|
|
|
|
function saveSolution() {
|
|
global $LOCAL_PATH, $DB, $team, $tournament, $FINAL;
|
|
|
|
try {
|
|
$problem = $_POST["problem"];
|
|
if ($problem < 1 || $problem > 9)
|
|
return "Le numéro de problème est invalide.";
|
|
}
|
|
catch (Throwable $t) {
|
|
return "Le numéro de problème n'est pas valide. Merci de ne pas créer vos propres requêtes.";
|
|
}
|
|
|
|
$file = $_FILES["solution"];
|
|
|
|
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 format 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 `solutions`(`file_id`, `team`, `tournament`, `problem`) VALUES (?, ?, ?, ?);");
|
|
$req->execute([$id, $team->getId(), $team->isSelectedForFinal() ? $FINAL->getId() : $tournament->getId(), $problem]);
|
|
|
|
return false;
|
|
}
|
|
|
|
require_once "server_files/views/solutions.php";
|