download_scorm.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This file is responsible for passing requested documents to the browser.
  5. *
  6. * @package chamilo.document
  7. */
  8. session_cache_limiter('none');
  9. require_once __DIR__.'/../inc/global.inc.php';
  10. $this_section = SECTION_COURSES;
  11. // Protection
  12. api_protect_course_script();
  13. $_course = api_get_course_info();
  14. if (!isset($_course)) {
  15. api_not_allowed(true);
  16. }
  17. // If LP obj exists
  18. if (isset($_SESSION['oLP'])) {
  19. $obj = $_SESSION['oLP'];
  20. } else {
  21. api_not_allowed();
  22. }
  23. // If is visible for the current user
  24. if (!learnpath::is_lp_visible_for_student($obj->get_id(), api_get_user_id())) {
  25. api_not_allowed();
  26. }
  27. $doc_url = isset($_GET['doc_url']) ? $_GET['doc_url'] : null;
  28. // Change the '&' that got rewritten to '///' by mod_rewrite back to '&'
  29. $doc_url = str_replace('///', '&', $doc_url);
  30. // Still a space present? it must be a '+' (that got replaced by mod_rewrite)
  31. $doc_url = str_replace(' ', '+', $doc_url);
  32. $doc_url = str_replace(array('../', '\\..', '\\0', '..\\'), array('', '', '', ''), $doc_url); //echo $doc_url;
  33. if (strpos($doc_url, '../') || strpos($doc_url, '/..')) {
  34. $doc_url = '';
  35. }
  36. $sys_course_path = api_get_path(SYS_COURSE_PATH).$_course['path'].'/scorm';
  37. if (is_dir($sys_course_path.$doc_url)) {
  38. api_not_allowed();
  39. }
  40. if (Security::check_abs_path($sys_course_path.$doc_url, $sys_course_path.'/')) {
  41. $full_file_name = $sys_course_path.$doc_url;
  42. // Launch event
  43. Event::event_download($doc_url);
  44. $fixLinks = api_get_configuration_value('lp_replace_http_to_https');
  45. $result = DocumentManager::file_send_for_download($full_file_name, false, '', $fixLinks);
  46. if ($result === false) {
  47. api_not_allowed(true);
  48. }
  49. }
  50. exit;