download.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. /**
  9. * Code
  10. * Many functions updated and moved to lib/document.lib.php
  11. */
  12. session_cache_limiter('none');
  13. require_once '../inc/global.inc.php';
  14. $this_section = SECTION_COURSES;
  15. // Protection
  16. api_protect_course_script();
  17. if (!isset($_course)) {
  18. api_not_allowed(true);
  19. }
  20. $doc_url = $_GET['doc_url'];
  21. // Change the '&' that got rewritten to '///' by mod_rewrite back to '&'
  22. $doc_url = str_replace('///', '&', $doc_url);
  23. // Still a space present? it must be a '+' (that got replaced by mod_rewrite)
  24. $doc_url = str_replace(' ', '+', $doc_url);
  25. $doc_url = str_replace(array('../', '\\..', '\\0', '..\\'), array('', '', '', ''), $doc_url); //echo $doc_url;
  26. if (strpos($doc_url,'../') OR strpos($doc_url,'/..')) {
  27. $doc_url = '';
  28. }
  29. $sys_course_path = api_get_path(SYS_COURSE_PATH).$_course['path'].'/scorm';
  30. $user_id = api_get_user_id();
  31. if ($_SESSION['oLP']) {
  32. $lp_id = $_SESSION['oLP']->get_id();
  33. $lp_item_id = $_SESSION['oLP']->current;
  34. $lp_item_info = new learnpathItem($lp_item_id);
  35. if (!empty($lp_item_info)) {
  36. //if (basename($lp_item_info->path) == basename($doc_url)) {
  37. $visible = learnpath::is_lp_visible_for_student($lp_id, $user_id);
  38. if ($visible) {
  39. event_download($doc_url);
  40. if (Security::check_abs_path($sys_course_path.$doc_url, $sys_course_path.'/')) {
  41. $full_file_name = $sys_course_path.$doc_url;
  42. DocumentManager::file_send_for_download($full_file_name);
  43. exit;
  44. }
  45. }
  46. //}
  47. }
  48. }
  49. Display::display_error_message(get_lang('ProtectedDocument'));//api_not_allowed backbutton won't work.
  50. exit;