mirror of
				https://gitlab.com/animath/si/plateforme.git
				synced 2025-11-04 01:32:05 +01:00 
			
		
		
		
	
		
			
				
	
	
		
			67 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			67 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?php
 | 
						|
 | 
						|
include "config.php";
 | 
						|
 | 
						|
if (!isset($_GET["file_id"])) {
 | 
						|
	header("Location: $URL_BASE");
 | 
						|
	exit();
 | 
						|
}
 | 
						|
 | 
						|
$id = htmlspecialchars($_GET["file_id"]);
 | 
						|
$type = "SOLUTION";
 | 
						|
 | 
						|
$req = $DB->query("SELECT * FROM `solutions` WHERE `file_id` = '$id';");
 | 
						|
if (($data = $req->fetch()) === false) {
 | 
						|
	$req = $DB->query("SELECT * FROM `syntheses` WHERE `file_id` = '$id';");
 | 
						|
	$type = "SYNTHESE";
 | 
						|
 | 
						|
	if (($data = $req->fetch()) === false) {
 | 
						|
		$req = $DB->query("SELECT * FROM `documents` WHERE `file_id` = '$id';");
 | 
						|
		$type = "DOCUMENT";
 | 
						|
		$data = $req->fetch();
 | 
						|
	}
 | 
						|
}
 | 
						|
 | 
						|
if ($data !== false) {
 | 
						|
	$team_data = $DB->query("SELECT `trigram` FROM `teams` WHERE `id` = " . $data["team"] . ";")->fetch();
 | 
						|
	$tournament_data = $DB->query("SELECT `name` FROM `tournaments` WHERE `id` = " . $data["tournament"] . ";")->fetch();
 | 
						|
	$trigram = $team_data["trigram"];
 | 
						|
	if ($type == "SOLUTION") {
 | 
						|
		$problem = $data["problem"];
 | 
						|
		$name = "Problème $problem $trigram.pdf";
 | 
						|
	}
 | 
						|
	else if ($type == "SYNTHESE") {
 | 
						|
		$dest = $data["dest"];
 | 
						|
		$name = "Note de synthèse $trigram pour " . ($dest == "OPPOSANT" ? "l'opposant" : "le rapporteur") . ".pdf";
 | 
						|
	}
 | 
						|
	else if ($type == "DOCUMENT") {
 | 
						|
		$user_id = $data["user"];
 | 
						|
		$user_data = $DB->query("SELECT `surname`, `first_name` FROM `users` WHERE `id` = 'user';")->fetch();
 | 
						|
		$surname = $user_data["surname"];
 | 
						|
		$first_name = $user_data["first_name"];
 | 
						|
		switch ($data["type"]) {
 | 
						|
			case "PARENTAL_CONSENT":
 | 
						|
				$name = "Autorisation parentale";
 | 
						|
				break;
 | 
						|
			case "PHOTO_CONSENT":
 | 
						|
				$name = "Autorisation de droit à l'image";
 | 
						|
				break;
 | 
						|
			case "SANITARY_PLUG":
 | 
						|
				$name = "Fiche sanitaire";
 | 
						|
				break;
 | 
						|
		}
 | 
						|
		$name .= " de $first_name $surname.pdf";
 | 
						|
	}
 | 
						|
}
 | 
						|
else {
 | 
						|
	include_once "404.php";
 | 
						|
	http_response_code(404);
 | 
						|
	exit();
 | 
						|
}
 | 
						|
 | 
						|
header("Content-Type: application/pdf");
 | 
						|
header("Content-Disposition: inline; filename=\"$name\"");
 | 
						|
 | 
						|
readfile("$URL_BASE/files/$id");
 | 
						|
 | 
						|
exit();
 |