show_content.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @author jmontoya
  5. *
  6. * @package chamilo.document
  7. */
  8. require_once __DIR__.'/../inc/global.inc.php';
  9. // Protection
  10. api_protect_course_script(true);
  11. $header_file = isset($_GET['file']) ? Security::remove_XSS($_GET['file']) : null;
  12. $document_id = intval($_GET['id']);
  13. $courseId = api_get_course_int_id();
  14. $course_info = api_get_course_info_by_id($courseId);
  15. $course_code = $course_info['code'];
  16. $session_id = api_get_session_id();
  17. if (empty($course_info)) {
  18. api_not_allowed(true);
  19. }
  20. // Generate path
  21. if (!$document_id) {
  22. $document_id = DocumentManager::get_document_id($course_info, $header_file);
  23. }
  24. $document_data = DocumentManager::get_document_data_by_id(
  25. $document_id,
  26. $course_code,
  27. true,
  28. $session_id
  29. );
  30. if ($session_id != 0 && !$document_data) {
  31. $document_data = DocumentManager::get_document_data_by_id(
  32. $document_id,
  33. $course_code,
  34. true,
  35. 0
  36. );
  37. }
  38. if (empty($document_data)) {
  39. api_not_allowed(true);
  40. }
  41. $header_file = $document_data['path'];
  42. $name_to_show = cut($header_file, 80);
  43. $path_array = explode('/', str_replace('\\', '/', $header_file));
  44. $path_array = array_map('urldecode', $path_array);
  45. $header_file = implode('/', $path_array);
  46. $file = Security::remove_XSS(urldecode($document_data['path']));
  47. $file_root = $course_info['path'].'/document'.str_replace('%2F', '/', $file);
  48. $file_url_sys = api_get_path(SYS_COURSE_PATH).$file_root;
  49. $file_url_web = api_get_path(WEB_COURSE_PATH).$file_root;
  50. if (!file_exists($file_url_sys)) {
  51. api_not_allowed(true);
  52. }
  53. if (is_dir($file_url_sys)) {
  54. api_not_allowed(true);
  55. }
  56. //fix the screen when you try to access a protected course through the url
  57. $is_allowed_in_course = api_is_allowed_in_course();
  58. if ($is_allowed_in_course == false) {
  59. api_not_allowed(true);
  60. }
  61. // Check user visibility
  62. $is_visible = DocumentManager::check_visibility_tree(
  63. $document_id,
  64. api_get_course_info(),
  65. api_get_session_id(),
  66. api_get_user_id(),
  67. api_get_group_id()
  68. );
  69. if (!api_is_allowed_to_edit() && !$is_visible) {
  70. api_not_allowed(true);
  71. }
  72. //TODO:clean all code
  73. /* Main section */
  74. header('Expires: Wed, 01 Jan 1990 00:00:00 GMT');
  75. //header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
  76. header('Last-Modified: Wed, 01 Jan 2100 00:00:00 GMT');
  77. header('Cache-Control: no-cache, must-revalidate');
  78. header('Pragma: no-cache');
  79. $browser_display_title = 'Documents - '.Security::remove_XSS($_GET['cidReq']).' - '.$file;
  80. $file_url_web = api_get_path(WEB_COURSE_PATH).$course_info['path'].'/document'.$header_file.'?'.api_get_cidreq();
  81. $pathinfo = pathinfo($header_file);
  82. if ($pathinfo['extension'] == 'swf') {
  83. $width = '83%';
  84. $height = '83%';
  85. } else {
  86. $width = '100%';
  87. $height = '100%';
  88. }
  89. echo '<iframe border="0" frameborder="0" scrolling="no" style="width:'.$width.'; height:'.$height.';background-color:#ffffff;" id="mainFrame" name="mainFrame" src="'.$file_url_web.'?'.api_get_cidreq().'&amp;rand='.mt_rand(1, 1000).'"></iframe>';