| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- <?php /** @noinspection PhpUnhandledExceptionInspection */
- /**
- * @var int $id
- * @var string $name
- */
- $test = Test::get($id);
- if(!$test) {
- throw new RuntimeException(__("Test not found."));
- }
- $user = Core::$user;
- $is_pdf = ($name === "pdf");
- if($is_pdf) {
- $project = $test->getProject();
- $customers = $user->getCustomers();
- $customer_ids = array_column($customers, "id");
- if(!in_array($project->customer_id, $customer_ids)) {
- throw new RuntimeException(__("You do not have permission to access this resource."));
- }
- }
- if(!$is_pdf && !$user->canVerifyTests() && $user->is($test->tester_id)) {
- throw new RuntimeException(__("You do not have permission to access this resource."));
- }
- $directory = $test->getDirectory();
- $path_jpg = $directory . "/" . $name . ".jpg";
- $path_pdf = $directory . "/" . $name . ".pdf";
- if(file_exists($path_jpg)) {
- header("Content-Type: image/jpeg");
- readfile($path_jpg);
- }
- else if(file_exists($path_pdf)) {
- header("Content-Type: application/pdf");
- readfile($path_pdf);
- }
- else {
- header("Content-Type: image/png");
- readfile("public/img/blank.png");
- }
|