show_content.php 3.1 KB

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