download.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use ChamiloSession as Session;
  4. /**
  5. * This file is responsible for passing requested documents to the browser.
  6. *
  7. * @package chamilo.document
  8. */
  9. session_cache_limiter('none');
  10. require_once __DIR__.'/../inc/global.inc.php';
  11. $this_section = SECTION_COURSES;
  12. // Protection
  13. api_protect_course_script();
  14. $_course = api_get_course_info();
  15. if (!isset($_course)) {
  16. api_not_allowed(true);
  17. }
  18. $doc_url = $_GET['doc_url'];
  19. // Change the '&' that got rewritten to '///' by mod_rewrite back to '&'
  20. $doc_url = str_replace('///', '&', $doc_url);
  21. // Still a space present? it must be a '+' (that got replaced by mod_rewrite)
  22. $doc_url = str_replace(' ', '+', $doc_url);
  23. $doc_url = str_replace(['../', '\\..', '\\0', '..\\'], ['', '', '', ''], $doc_url); //echo $doc_url;
  24. if (strpos($doc_url, '../') || strpos($doc_url, '/..')) {
  25. $doc_url = '';
  26. }
  27. $sys_course_path = api_get_path(SYS_COURSE_PATH).$_course['path'].'/scorm';
  28. $user_id = api_get_user_id();
  29. /** @var learnpath $lp */
  30. $lp = Session::read('oLP');
  31. if ($lp) {
  32. $lp_id = $lp->get_id();
  33. $lp_item_id = $lp->current;
  34. $lp_item_info = new learnpathItem($lp_item_id);
  35. if (!empty($lp_item_info)) {
  36. $visible = learnpath::is_lp_visible_for_student($lp_id, $user_id);
  37. if ($visible) {
  38. Event::event_download($doc_url);
  39. if (Security::check_abs_path($sys_course_path.$doc_url, $sys_course_path.'/')) {
  40. $full_file_name = $sys_course_path.$doc_url;
  41. DocumentManager::file_send_for_download($full_file_name);
  42. exit;
  43. }
  44. }
  45. //}
  46. }
  47. }
  48. echo Display::return_message(get_lang('Protected Document'), 'error');
  49. //api_not_allowed backbutton won't work.
  50. exit;