plateforme-tfjm2/server_files/controllers/view_file.php

78 lines
2.3 KiB
PHP
Raw Normal View History

2019-08-21 20:56:46 +00:00
<?php
if (!isset($_GET["file_id"])) {
header("Location: $URL_BASE");
exit();
}
if (!isset($_SESSION["user_id"]))
require_once "server_files/403.php";
2019-08-21 20:56:46 +00:00
$id = htmlspecialchars($_GET["file_id"]);
$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
if ($file === null) {
$file = Document::fromId($id);
$type = DocumentType::PARENTAL_CONSENT;
2019-08-21 20:56:46 +00:00
}
}
if ($file !== null) {
$team = Team::fromId($file->getTeamId());
$tournament = Tournament::fromId($file->getTournamentId());
$trigram = $team->getTrigram();
if ($_SESSION["role"] == Role::ORGANIZER && !$tournament->organize($_SESSION["user_id"]))
require_once "server_files/403.php";
if ($type == DocumentType::SOLUTION) {
$problem = $file->getProblem();
2019-08-21 20:56:46 +00:00
$name = "Problème $problem $trigram.pdf";
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 23:35:05 +00:00
else if ($type == DocumentType::SYNTHESIS) {
$dest = $file->getDest();
$name = "Note de synthèse $trigram pour " . ($dest == DestType::OPPOSANT ? "l'opposant" : "le rapporteur") . ".pdf";
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
}
else {
$user = User::fromId($file->getUserId());
$type = $file->getType();
if (($_SESSION["role"] == Role::PARTICIPANT || $_SESSION["role"] == Role::ENCADRANT) && $user->getId() != $_SESSION["user_id"])
require_once "server_files/403.php";
$surname = $user->getSurname();
$first_name = $user->getFirstName();
switch ($type) {
case DocumentType::PARENTAL_CONSENT:
2019-08-21 20:56:46 +00:00
$name = "Autorisation parentale";
break;
case DocumentType::PHOTO_CONSENT:
2019-08-21 20:56:46 +00:00
$name = "Autorisation de droit à l'image";
break;
case DocumentType::SANITARY_PLUG:
2019-08-21 20:56:46 +00:00
$name = "Fiche sanitaire";
break;
}
$name .= " de $first_name $surname.pdf";
}
}
else
require_once "server_files/404.php";
2019-08-21 20:56:46 +00:00
header("Content-Type: application/pdf");
header("Content-Disposition: inline; filename=\"$name\"");
readfile("$LOCAL_PATH/files/$id");
2019-08-21 20:56:46 +00:00
exit();