download.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. /* FUNCTIONS */
  9. /* file_html_dynamic_parsing removed */
  10. /* Other functions updated and moved to lib/document.lib.php */
  11. /* MAIN CODE */
  12. session_cache_limiter('none');
  13. require_once '../inc/global.inc.php';
  14. $this_section = SECTION_COURSES;
  15. require_once api_get_path(LIBRARY_PATH).'document.lib.php';
  16. $doc_url = $_GET['doc_url'];
  17. // Change the '&' that got rewritten to '///' by mod_rewrite back to '&'
  18. $doc_url = str_replace('///', '&', $doc_url);
  19. // Still a space present? it must be a '+' (that got replaced by mod_rewrite)
  20. $doc_url = str_replace(' ', '+', $doc_url);
  21. $doc_url = str_replace(array('../', '\\..', '\\0', '..\\'), array('', '', '', ''), $doc_url); //echo $doc_url;
  22. // Dealing with image included into survey: when users receive a link towards a
  23. // survey while not being authenticated on the plateform.
  24. // The administrator should probably be able to disable this code through admin
  25. // inteface.
  26. $refer_script = strrchr($_SERVER["HTTP_REFERER"], '/');
  27. if (substr($refer_script, 0, 15) == '/fillsurvey.php') {
  28. $invitation = substr(strstr($refer_script, 'invitationcode='), 15);
  29. $course = strstr($refer_script, 'course=');
  30. $course = substr($course, 7, strpos($course, '&') - 7);
  31. include '../survey/survey.download.inc.php';
  32. $_course = check_download_survey($course, $invitation, $doc_url);
  33. $_course['path'] = $_course['directory'];
  34. } else {
  35. // Protection
  36. api_protect_course_script();
  37. if (!isset($_course)) {
  38. api_not_allowed(true);
  39. }
  40. // If the rewrite rule asks for a directory, we redirect to the document explorer
  41. if (is_dir(api_get_path(SYS_COURSE_PATH).$_course['path'].'/document'.$doc_url)) {
  42. // Remove last slash if present
  43. // mod_rewrite can change /some/path/ to /some/path// in some cases, so clean them all off (René)
  44. while ($doc_url{$dul = strlen($doc_url) - 1} == '/') {
  45. $doc_url = substr($doc_url, 0, $dul);
  46. }
  47. // Group folder?
  48. $gid_req = ($_GET['gidReq']) ? '&gidReq='.Security::remove_XSS($_GET['gidReq']) : '';
  49. // Create the path
  50. $document_explorer = api_get_path(WEB_CODE_PATH).'document/document.php?curdirpath='.urlencode($doc_url).'&cidReq='.Security::remove_XSS($_GET['cidReq']).$gid_req;
  51. // Redirect
  52. header('Location: '.$document_explorer);
  53. }
  54. // Launch event
  55. event_download($doc_url);
  56. }
  57. $sys_course_path = api_get_path(SYS_COURSE_PATH);
  58. $full_file_name = $sys_course_path.$_course['path'].'/document'.str_replace('+', ' ', $doc_url);
  59. // Check visibility of document and paths
  60. $is_allowed_to_edit = api_is_allowed_to_edit();
  61. if (!$is_allowed_to_edit && !DocumentManager::is_visible($doc_url, $_course)) {
  62. echo 'document not visible'; //api_not_allowed backbutton won't work.
  63. exit; // You shouldn't be here anyway.
  64. }
  65. DocumentManager::file_send_for_download($full_file_name);
  66. exit;