show_content.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. $publicPath = api_get_path(WEB_PUBLIC_PATH);
  42. // http://localhost/chamilo2/courses/ABC/document/aa.html
  43. $courseCode = api_get_course_id();
  44. $path = $document_data['path'];
  45. $type = 'show';
  46. $url = $publicPath."courses/$courseCode/document$path?type=$type";
  47. header("Location: $url");
  48. exit;
  49. $header_file = $document_data['path'];
  50. $name_to_show = cut($header_file, 80);
  51. $path_array = explode('/', str_replace('\\', '/', $header_file));
  52. $path_array = array_map('urldecode', $path_array);
  53. $header_file = implode('/', $path_array);
  54. $file = Security::remove_XSS(urldecode($document_data['path']));
  55. $file_root = $course_info['path'].'/document'.str_replace('%2F', '/', $file);
  56. $file_url_sys = api_get_path(SYS_COURSE_PATH).$file_root;
  57. $file_url_web = api_get_path(WEB_COURSE_PATH).$file_root;
  58. if (!file_exists($file_url_sys)) {
  59. api_not_allowed(true);
  60. }
  61. if (is_dir($file_url_sys)) {
  62. api_not_allowed(true);
  63. }
  64. //fix the screen when you try to access a protected course through the url
  65. $is_allowed_in_course = api_is_allowed_in_course();
  66. if ($is_allowed_in_course == false) {
  67. api_not_allowed(true);
  68. }
  69. // Check user visibility
  70. $is_visible = DocumentManager::check_visibility_tree(
  71. $document_id,
  72. api_get_course_info(),
  73. api_get_session_id(),
  74. api_get_user_id(),
  75. api_get_group_id()
  76. );
  77. if (!api_is_allowed_to_edit() && !$is_visible) {
  78. api_not_allowed(true);
  79. }
  80. //TODO:clean all code
  81. /* Main section */
  82. header('Expires: Wed, 01 Jan 1990 00:00:00 GMT');
  83. //header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
  84. header('Last-Modified: Wed, 01 Jan 2100 00:00:00 GMT');
  85. header('Cache-Control: no-cache, must-revalidate');
  86. header('Pragma: no-cache');
  87. $browser_display_title = 'Documents - '.Security::remove_XSS($_GET['cidReq']).' - '.$file;
  88. $file_url_web = api_get_path(WEB_COURSE_PATH).$course_info['path'].'/document'.$header_file.'?'.api_get_cidreq();
  89. $pathinfo = pathinfo($header_file);
  90. if ($pathinfo['extension'] == 'swf') {
  91. $width = '83%';
  92. $height = '83%';
  93. } else {
  94. $width = '100%';
  95. $height = '100%';
  96. }
  97. 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>';