2019-08-21 20:56:46 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
if (!isset($_GET["file_id"])) {
|
|
|
|
header("Location: $URL_BASE");
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
2019-09-06 23:55:10 +00:00
|
|
|
if (!isset($_SESSION["user_id"]))
|
2019-09-07 11:42:36 +00:00
|
|
|
require_once "server_files/403.php";
|
2019-09-06 23:55:10 +00:00
|
|
|
|
2019-08-21 20:56:46 +00:00
|
|
|
$id = htmlspecialchars($_GET["file_id"]);
|
|
|
|
|
2019-09-07 16:43:51 +00:00
|
|
|
$type = DocumentType::SOLUTION;
|
|
|
|
$file = Solution::fromId($id);
|
|
|
|
if ($file === null) {
|
2019-09-07 23:35:05 +00:00
|
|
|
$type = DocumentType::SYNTHESIS;
|
|
|
|
$file = Synthesis::fromId($id);
|
2019-08-21 20:56:46 +00:00
|
|
|
|
2019-09-07 16:43:51 +00:00
|
|
|
if ($file === null) {
|
|
|
|
$file = Document::fromId($id);
|
|
|
|
$type = DocumentType::PARENTAL_CONSENT;
|
2019-08-21 20:56:46 +00:00
|
|
|
}
|
|
|
|
}
|
2019-08-26 14:27:55 +00:00
|
|
|
|
2019-09-07 16:43:51 +00:00
|
|
|
if ($file !== null) {
|
|
|
|
$team = Team::fromId($file->getTeamId());
|
|
|
|
$tournament = Tournament::fromId($file->getTournamentId());
|
2019-09-06 23:33:05 +00:00
|
|
|
$trigram = $team->getTrigram();
|
2019-09-07 16:43:51 +00:00
|
|
|
|
|
|
|
if ($_SESSION["role"] == Role::ORGANIZER && !$tournament->organize($_SESSION["user_id"]))
|
|
|
|
require_once "server_files/403.php";
|
|
|
|
|
|
|
|
if ($type == DocumentType::SOLUTION) {
|
|
|
|
$problem = $file->getProblem();
|
2020-02-03 15:44:38 +00:00
|
|
|
$name = "Problème $problem $trigram";
|
2019-09-06 23:55:10 +00:00
|
|
|
|
2020-05-04 23:06:57 +00:00
|
|
|
if (($_SESSION["role"] == Role::PARTICIPANT || $_SESSION["role"] == Role::ENCADRANT) && (!isset($_SESSION["team"]) || $_SESSION["team"]->getId() != $team->getId())) {
|
|
|
|
$req = $DB->prepare("SELECT opposed_problem, rapported_problem, opposed_problem_2, rapported_problem_2 FROM teams WHERE id = ?;");
|
|
|
|
$req->execute([$_SESSION["team"]->getId()]);
|
|
|
|
$data = $req->fetch();
|
|
|
|
if ($id != $data["opposed_problem"] && $id != $data["rapported_problem"]) {
|
|
|
|
if (date("Y-m-d H:i") < $tournament->getSolutionsDate2() || ($id != $data["opposed_problem_2"] && $id != $data["rapported_problem_2"]))
|
|
|
|
require_once "server_files/403.php";
|
|
|
|
}
|
|
|
|
}
|
2019-08-21 20:56:46 +00:00
|
|
|
}
|
2019-09-07 23:35:05 +00:00
|
|
|
else if ($type == DocumentType::SYNTHESIS) {
|
2019-09-07 16:43:51 +00:00
|
|
|
$dest = $file->getDest();
|
2020-05-04 23:06:57 +00:00
|
|
|
$name = "Note de synthèse $trigram " . ($dest == DestType::OPPOSANT ? "de l'opposant" : "du rapporteur");
|
2019-09-06 23:55:10 +00:00
|
|
|
|
2019-09-07 16:43:51 +00:00
|
|
|
if (($_SESSION["role"] == Role::PARTICIPANT || $_SESSION["role"] == Role::ENCADRANT) && (!isset($_SESSION["team"]) || $_SESSION["team"]->getId() != $team->getId()))
|
|
|
|
require_once "server_files/403.php";
|
2019-08-21 20:56:46 +00:00
|
|
|
}
|
2019-09-07 16:43:51 +00:00
|
|
|
else {
|
|
|
|
$user = User::fromId($file->getUserId());
|
|
|
|
$type = $file->getType();
|
2019-09-06 23:55:10 +00:00
|
|
|
|
2020-01-18 13:43:42 +00:00
|
|
|
if (($_SESSION["role"] == Role::PARTICIPANT || $_SESSION["role"] == Role::ENCADRANT)) {
|
|
|
|
if ($type != DocumentType::MOTIVATION_LETTER && $user->getId() != $_SESSION["user_id"] || $file->getTeamId() != $team->getId())
|
|
|
|
require_once "server_files/403.php";
|
|
|
|
}
|
2019-09-06 23:55:10 +00:00
|
|
|
|
2019-09-07 16:43:51 +00:00
|
|
|
switch ($type) {
|
|
|
|
case DocumentType::PARENTAL_CONSENT:
|
2019-08-21 20:56:46 +00:00
|
|
|
$name = "Autorisation parentale";
|
|
|
|
break;
|
2019-09-07 16:43:51 +00:00
|
|
|
case DocumentType::PHOTO_CONSENT:
|
2019-08-21 20:56:46 +00:00
|
|
|
$name = "Autorisation de droit à l'image";
|
|
|
|
break;
|
2019-09-07 16:43:51 +00:00
|
|
|
case DocumentType::SANITARY_PLUG:
|
2019-08-21 20:56:46 +00:00
|
|
|
$name = "Fiche sanitaire";
|
|
|
|
break;
|
2020-01-01 23:09:02 +00:00
|
|
|
case DocumentType::SCHOLARSHIP:
|
|
|
|
$name = "Notification de bourse";
|
|
|
|
break;
|
2019-08-21 20:56:46 +00:00
|
|
|
}
|
2020-01-18 13:43:42 +00:00
|
|
|
if ($type == DocumentType::MOTIVATION_LETTER)
|
2020-02-03 15:44:38 +00:00
|
|
|
$name = "Lettre de motivation de l'équipe $trigram";
|
2020-01-18 13:43:42 +00:00
|
|
|
else {
|
|
|
|
$surname = $user->getSurname();
|
|
|
|
$first_name = $user->getFirstName();
|
2020-02-03 15:44:38 +00:00
|
|
|
$name .= " de $first_name $surname";
|
2020-01-18 13:43:42 +00:00
|
|
|
}
|
2019-08-21 20:56:46 +00:00
|
|
|
}
|
|
|
|
}
|
2019-09-07 17:01:23 +00:00
|
|
|
else
|
2019-09-07 11:42:36 +00:00
|
|
|
require_once "server_files/404.php";
|
2019-08-21 20:56:46 +00:00
|
|
|
|
2020-02-03 15:44:38 +00:00
|
|
|
$mime = finfo_file(finfo_open(FILEINFO_MIME_TYPE), "$LOCAL_PATH/files/$id");
|
|
|
|
if ($mime == "application/pdf")
|
|
|
|
$name .= ".pdf";
|
|
|
|
elseif ($mime == "image/png")
|
|
|
|
$name .= ".png";
|
|
|
|
else
|
|
|
|
$name = ".jpg";
|
|
|
|
|
|
|
|
header("Content-Type: $mime");
|
2019-08-21 20:56:46 +00:00
|
|
|
header("Content-Disposition: inline; filename=\"$name\"");
|
|
|
|
|
2019-09-07 17:01:23 +00:00
|
|
|
readfile("$LOCAL_PATH/files/$id");
|
2019-08-21 20:56:46 +00:00
|
|
|
|
|
|
|
exit();
|