2019-09-09 23:48:52 +00:00
< ? php
if ( ! isset ( $_GET [ " file_id " ])) {
header ( " Location: $URL_BASE " );
exit ();
}
if ( ! isset ( $_SESSION [ " user_id " ]))
require_once " server_files/403.php " ;
$id = htmlspecialchars ( $_GET [ " file_id " ]);
2019-09-11 16:41:45 +00:00
$file = Document :: fromId ( $id );
2019-09-09 23:48:52 +00:00
if ( $file !== null ) {
2019-09-11 16:41:45 +00:00
$team = Team :: fromId ( $file -> getTeamId ());;
2019-09-09 23:48:52 +00:00
$trigram = $team -> getTrigram ();
2019-09-11 16:41:45 +00:00
$user = User :: fromId ( $file -> getUserId ());
2019-09-09 23:48:52 +00:00
2019-09-11 16:41:45 +00:00
if (( $_SESSION [ " role " ] == Role :: PARTICIPANT || $_SESSION [ " role " ] == Role :: ENCADRANT ) && $user -> getId () != $_SESSION [ " user_id " ])
require_once " server_files/403.php " ;
2019-09-09 23:48:52 +00:00
2019-09-11 16:41:45 +00:00
$surname = $user -> getSurname ();
$first_name = $user -> getFirstName ();
2019-11-16 20:41:59 +00:00
$mime_type = finfo_file ( finfo_open ( FILEINFO_MIME_TYPE ), " $LOCAL_PATH /files/ $id " );
$ext = $mime_type == " application/pdf " ? " pdf " : ( $mime_type == " image/png " ? " png " : " jpg " );
$name = " Autorisation de droit à l'image de $first_name $surname . $ext " ;
2019-09-09 23:48:52 +00:00
2019-11-16 20:41:59 +00:00
header ( " Content-Type: " . $mime_type );
2019-09-21 11:37:48 +00:00
}
else {
$question = Question :: fromAttachedFile ( $id );
if ( $question != null )
{
$from = Team :: fromId ( $question -> getFrom ());
$to = Team :: fromId ( $question -> getTo ());
$mime_type = finfo_file ( finfo_open ( FILEINFO_MIME_TYPE ), " $LOCAL_PATH /files/ $id " );
2019-09-21 12:31:31 +00:00
$name = " Pièce jointe n° " . $question -> getNumber () . " de l'équipe " . $from -> getTrigram () . " pour l'équipe " . $from -> getTrigram () . " (problème " . $question -> getProblem () . " ) " ;
2019-09-21 18:39:40 +00:00
$name .= getExtFromMimeType ( $mime_type );
2019-09-21 11:37:48 +00:00
header ( " Content-Type: " . $mime_type );
}
else
require_once " server_files/404.php " ;
}
2019-09-09 23:48:52 +00:00
header ( " Content-Disposition: inline; filename= \" $name\ " " );
readfile ( " $LOCAL_PATH /files/ $id " );
exit ();