1
0

test_file.php 974 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. $test = Test::get($id);
  3. if(!$test) throw new Exception(__("Test not found."));
  4. $is_pdf = $name == "pdf";
  5. if($is_pdf) {
  6. $project = $test->getProject();
  7. $customers = Core::$user->getCustomers();
  8. $customer_ids = array_column($customers, "id");
  9. if(!in_array($project->customer_id, $customer_ids)) throw new Exception(__("You do not have permission to access this resource."));
  10. }
  11. if(!$is_pdf) {
  12. if(!Core::$user->canVerifyTests()) {
  13. if(Core::$user->id != $test->tester_id) throw new Exception(__("You do not have permission to access this resource."));
  14. }
  15. }
  16. $directory = $test->getDirectory();
  17. $path_jpg = $directory . "/" . $name . ".jpg";
  18. $path_pdf = $directory . "/" . $name . ".pdf";
  19. if(file_exists($path_jpg)) {
  20. header("Content-Type: image/jpeg");
  21. readfile($path_jpg);
  22. }
  23. else if(file_exists($path_pdf)) {
  24. header("Content-Type: application/pdf");
  25. readfile($path_pdf);
  26. }
  27. else {
  28. header("Content-Type: image/png");
  29. readfile("public/img/blank.png");
  30. }