| 123456789101112131415161718192021222324252627282930313233343536373839 |
- <?php
- $test = Test::get($id);
- if(!$test) throw new Exception(__("Test not found."));
- $is_pdf = $name == "pdf";
- if($is_pdf) {
- $project = $test->getProject();
- $customers = Core::$user->getCustomers();
- $customer_ids = array_column($customers, "id");
- if(!in_array($project->customer_id, $customer_ids)) throw new Exception(__("You do not have permission to access this resource."));
- }
- if(!$is_pdf) {
- if(Core::$user->level < User::LEVEL_ADMIN) {
- if(Core::$user->id != $test->tester_id) throw new Exception(__("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");
- }
|