show_content.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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();
  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($document_id, $course_code, true, $session_id);
  26. if ($session_id != 0 and !$document_data) {
  27. $document_data = DocumentManager::get_document_data_by_id($document_id, $course_code, true, 0);
  28. }
  29. if (empty($document_data)) {
  30. api_not_allowed(true);
  31. }
  32. $header_file = $document_data['path'];
  33. $name_to_show = cut($header_file, 80);
  34. $path_array = explode('/', str_replace('\\', '/', $header_file));
  35. $path_array = array_map('urldecode', $path_array);
  36. $header_file = implode('/', $path_array);
  37. $file = Security::remove_XSS(urldecode($document_data['path']));
  38. $file_root = $course_info['path'].'/document'.str_replace('%2F', '/', $file);
  39. $file_url_sys = api_get_path(SYS_COURSE_PATH).$file_root;
  40. $file_url_web = api_get_path(WEB_COURSE_PATH).$file_root;
  41. if (!file_exists($file_url_sys)) {
  42. api_not_allowed(true);
  43. }
  44. if (is_dir($file_url_sys)) {
  45. api_not_allowed(true);
  46. }
  47. //fix the screen when you try to access a protected course through the url
  48. $is_allowed_in_course = $_SESSION['is_allowed_in_course'];
  49. if ($is_allowed_in_course == false) {
  50. api_not_allowed(true);
  51. }
  52. //Check user visibility
  53. //$is_visible = DocumentManager::is_visible_by_id($document_id, $course_info, api_get_session_id(), api_get_user_id());
  54. $is_visible = DocumentManager::check_visibility_tree(
  55. $document_id,
  56. api_get_course_id(),
  57. api_get_session_id(),
  58. api_get_user_id(),
  59. api_get_group_id()
  60. );
  61. if (!api_is_allowed_to_edit() && !$is_visible) {
  62. api_not_allowed(true);
  63. }
  64. //TODO:clean all code
  65. /* Main section */
  66. header('Expires: Wed, 01 Jan 1990 00:00:00 GMT');
  67. //header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
  68. header('Last-Modified: Wed, 01 Jan 2100 00:00:00 GMT');
  69. header('Cache-Control: no-cache, must-revalidate');
  70. header('Pragma: no-cache');
  71. $browser_display_title = 'Documents - '.Security::remove_XSS($_GET['cidReq']).' - '.$file;
  72. $file_url_web = api_get_path(WEB_COURSE_PATH).$_course['path'].'/document'.$header_file.'?'.api_get_cidreq();
  73. $pathinfo = pathinfo($header_file);
  74. if ($pathinfo['extension']=='wav' && preg_match('/_chnano_.wav/i', $file_url_web) && api_get_setting('enable_nanogong') == 'true'){
  75. echo '<div align="center">';
  76. echo '<br/>';
  77. echo '<applet id="applet" archive="../inc/lib/nanogong/nanogong.jar" code="gong.NanoGong" width="160" height="95" >';
  78. echo '<param name="SoundFileURL" value="'.$file_url_web.'" />';
  79. echo '<param name="ShowSaveButton" value="false" />';
  80. echo '<param name="ShowTime" value="true" />';
  81. echo '<param name="ShowRecordButton" value="false" />';
  82. echo '</applet>';
  83. echo '</div>';
  84. } else {
  85. if ($pathinfo['extension']=='swf') { $width='83%'; $height='83%';} else {$width='100%'; $height='100%';}
  86. 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>';
  87. }