download_scorm.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 '../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. $obj = learnpath::getCurrentLpFromSession();
  18. // If LP obj exists
  19. if (empty($obj)) {
  20. api_not_allowed();
  21. }
  22. //If is visible for the current user
  23. if (!learnpath::is_lp_visible_for_student($obj->get_id(), api_get_user_id())) {
  24. api_not_allowed();
  25. }
  26. $doc_url = isset($_GET['doc_url']) ? $_GET['doc_url'] : null;
  27. // Change the '&' that got rewritten to '///' by mod_rewrite back to '&'
  28. $doc_url = str_replace('///', '&', $doc_url);
  29. // Still a space present? it must be a '+' (that got replaced by mod_rewrite)
  30. $doc_url = str_replace(' ', '+', $doc_url);
  31. $doc_url = str_replace(array('../', '\\..', '\\0', '..\\'), array('', '', '', ''), $doc_url); //echo $doc_url;
  32. if (strpos($doc_url,'../') || strpos($doc_url,'/..')) {
  33. $doc_url = '';
  34. }
  35. $sys_course_path = api_get_path(SYS_COURSE_PATH).$_course['path'].'/scorm';
  36. if (is_dir($sys_course_path.$doc_url)) {
  37. api_not_allowed();
  38. }
  39. if (Security::check_abs_path($sys_course_path.$doc_url, $sys_course_path.'/')) {
  40. $full_file_name = $sys_course_path.$doc_url;
  41. // Launch event
  42. Event::event_download($doc_url);
  43. $fixLinks = api_get_configuration_value('lp_replace_http_to_https');
  44. $result = DocumentManager::file_send_for_download($full_file_name, false, '', $fixLinks);
  45. if ($result === false) {
  46. api_not_allowed(true);
  47. }
  48. }
  49. exit;