show_content.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @author jmontoya
  5. *
  6. * @package chamilo.document
  7. */
  8. /**
  9. * Code
  10. */
  11. /* INITIALIZATION */
  12. $language_file[] = 'document';
  13. // Protection
  14. api_protect_course_script();
  15. $noPHP_SELF = true;
  16. $header_file = isset($_GET['file']) ? Security::remove_XSS($_GET['file']) : null;
  17. $document_id = intval($_GET['id']);
  18. $course_info = api_get_course_info();
  19. $course_code = api_get_course_id();
  20. if (empty($course_info)) {
  21. api_not_allowed(true);
  22. }
  23. //Generate path
  24. if (!$document_id) {
  25. $document_id = DocumentManager::get_document_id($course_info, $header_file);
  26. }
  27. $document_data = DocumentManager::get_document_data_by_id($document_id, $course_code);
  28. if (empty($document_data)) {
  29. api_not_allowed(true);
  30. }
  31. $header_file = $document_data['path'];
  32. $name_to_show = Text::cut($header_file, 80);
  33. $path_array = explode('/', str_replace('\\', '/', $header_file));
  34. $path_array = array_map('urldecode', $path_array);
  35. $header_file = implode('/', $path_array);
  36. $file = Security::remove_XSS(urldecode($document_data['path']));
  37. $file_root = $course_info['path'].'/document'.str_replace('%2F', '/', $file);
  38. $file_url_sys = api_get_path(SYS_COURSE_PATH).$file_root;
  39. $file_url_web = api_get_path(WEB_COURSE_PATH).$file_root;
  40. if (!file_exists($file_url_sys)) {
  41. api_not_allowed(true);
  42. }
  43. if (is_dir($file_url_sys)) {
  44. api_not_allowed(true);
  45. }
  46. // Check user visibility.
  47. //$is_visible = DocumentManager::is_visible_by_id($document_id, $course_info, api_get_session_id(), api_get_user_id());
  48. $is_visible = DocumentManager::check_visibility_tree($document_id, api_get_course_id(), api_get_session_id(), api_get_user_id());
  49. if (!api_is_allowed_to_edit() && !$is_visible) {
  50. api_not_allowed(true);
  51. }
  52. //TODO:clean all code
  53. /* Main section */
  54. header('Expires: Wed, 01 Jan 1990 00:00:00 GMT');
  55. //header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
  56. header('Last-Modified: Wed, 01 Jan 2100 00:00:00 GMT');
  57. header('Cache-Control: no-cache, must-revalidate');
  58. header('Pragma: no-cache');
  59. $browser_display_title = 'Documents - '.Security::remove_XSS($_GET['cidReq']).' - '.$file;
  60. $file_url_web = api_get_path(WEB_COURSE_PATH).$_course['path'].'/document'.$header_file.'?'.api_get_cidreq();
  61. $pathinfo = pathinfo($header_file);
  62. if ($pathinfo['extension']=='wav' && preg_match('/_chnano_.wav/i', $file_url_web) && api_get_setting('enable_nanogong') == 'true') {
  63. echo '<div align="center">';
  64. echo '<br/>';
  65. echo '<applet id="applet" archive="../inc/lib/nanogong/nanogong.jar" code="gong.NanoGong" width="160" height="40" >';
  66. echo '<param name="SoundFileURL" value="'.$file_url_web.'" />';
  67. echo '<param name="ShowSaveButton" value="false" />';
  68. echo '<param name="ShowTime" value="true" />';
  69. echo '<param name="ShowRecordButton" value="false" />';
  70. echo '</applet>';
  71. echo '</div>';
  72. } else {
  73. if ($pathinfo['extension']=='swf') {
  74. $width='83%';
  75. $height='83%';
  76. } else {
  77. $width='100%'; $height='100%';
  78. }
  79. echo '<iframe border="0" frameborder="0" scrolling="no"
  80. style="width:'.$width.';
  81. height:'.$height.';
  82. background-color:#ffffff;"
  83. id="mainFrame"
  84. name="mainFrame"
  85. src="'.$file_url_web.'?'.api_get_cidreq().'&amp;rand='.mt_rand(1, 1000).'">
  86. </iframe>';
  87. }
  88. $app['template.show_footer'] = false;
  89. $app['template.show_header'] = false;