showinframesmin.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @author Juan Carlos Raña Trabado (herodoto@telefonica.net)
  5. *
  6. * @package chamilo.document
  7. */
  8. /**
  9. * Code
  10. */
  11. /* INITIALIZATION */
  12. $language_file[] = 'document';
  13. require_once '../inc/global.inc.php';
  14. // Protection
  15. api_protect_course_script();
  16. $noPHP_SELF = true;
  17. $header_file = Security::remove_XSS($_GET['file']);
  18. $document_id = intval($_GET['id']);
  19. $course_info = api_get_course_info();
  20. $course_code = api_get_course_id();
  21. if (empty($course_info)) {
  22. api_not_allowed(true);
  23. }
  24. //Generate path
  25. if (!$document_id) {
  26. $document_id = DocumentManager::get_document_id($course_info, $header_file);
  27. }
  28. $document_data = DocumentManager::get_document_data_by_id($document_id, $course_code);
  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. $js_glossary_in_documents = '';
  73. if (api_get_setting('show_glossary_in_documents') == 'ismanual') {
  74. $js_glossary_in_documents = ' // $(document).ready(function() {
  75. $.frameReady(function() {
  76. // $("<div>I am a div courses</div>").prependTo("body");
  77. }, "mainFrame",
  78. { load: [
  79. {type:"script", id:"_fr1", src:"'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.min.js"},
  80. {type:"script", id:"_fr2", src:"'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.highlight.js"},
  81. {type:"script", id:"_fr3", src:"'.api_get_path(WEB_LIBRARY_PATH).'javascript/ckeditor/plugins/glossary/fck_glossary_manual.js"}
  82. ]
  83. }
  84. );
  85. //});';
  86. } elseif (api_get_setting('show_glossary_in_documents') == 'isautomatic') {
  87. $js_glossary_in_documents = '// $(document).ready(function() {
  88. $.frameReady(function(){
  89. // $("<div>I am a div courses</div>").prependTo("body");
  90. }, "mainFrame",
  91. { load: [
  92. {type:"script", id:"_fr1", src:"'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.min.js"},
  93. {type:"script", id:"_fr2", src:"'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.highlight.js"},
  94. {type:"script", id:"_fr3", src:"'.api_get_path(WEB_LIBRARY_PATH).'fckeditor/editor/plugins/glossary/fck_glossary_automatic.js"}
  95. ]
  96. }
  97. );
  98. // });';
  99. }
  100. $htmlHeadXtra[] = '<script type="text/javascript">
  101. <!--
  102. var jQueryFrameReadyConfigPath = \''.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.min.js\';
  103. -->
  104. </script>';
  105. $htmlHeadXtra[] = '<script type="text/javascript" src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.frameready.js"></script>';
  106. $htmlHeadXtra[] = '
  107. <script type="text/javascript">
  108. <!--
  109. var updateContentHeight = function() {
  110. //HeaderHeight = document.getElementById("header").offsetHeight;
  111. //FooterHeight = document.getElementById("footer").offsetHeight;
  112. //document.getElementById("mainFrame").style.height = ((docHeight-(parseInt(HeaderHeight)+parseInt(FooterHeight)))+60)+"px";
  113. my_iframe = document.getElementById("mainFrame");
  114. new_height = my_iframe.contentWindow.document.body.scrollHeight;
  115. my_iframe.height = my_iframe.contentWindow.document.body.scrollHeight + "px";
  116. };
  117. // Fixes the content height of the frame
  118. window.onload = function() {
  119. updateContentHeight();
  120. '.$js_glossary_in_documents.'
  121. }
  122. -->
  123. </script>';
  124. Display::display_reduced_header();
  125. echo '<div align="center">';
  126. $file_url_web = api_get_path(WEB_COURSE_PATH).$_course['path'].'/document'.$header_file.'?'.api_get_cidreq();
  127. $pathinfo = pathinfo($header_file);
  128. if ($pathinfo['extension']=='wav' && preg_match('/_chnano_.wav/i', $file_url_web) && api_get_setting('enable_nanogong') == 'true'){
  129. echo '<div align="center">';
  130. echo '<br/>';
  131. echo '<applet id="applet" archive="../inc/lib/nanogong/nanogong.jar" code="gong.NanoGong" width="160" height="95" >';
  132. echo '<param name="SoundFileURL" value="'.$file_url_web.'" />';
  133. echo '<param name="ShowSaveButton" value="false" />';
  134. echo '<param name="ShowTime" value="true" />';
  135. echo '<param name="ShowRecordButton" value="false" />';
  136. echo '</applet>';
  137. echo '</div>';
  138. } else {
  139. if ($pathinfo['extension']=='swf'){ $width='83%'; $height='83%';} else {$width='100%'; $height='';}
  140. echo '<iframe border="0" frameborder="0" scrolling="no" style="width:'.$width.'; height:'.$height.';background-color:#ffffff;" id="mainFrame" name="mainFrame" src="'.$file_url_web.'&amp;rand='.mt_rand(1, 10000).'"></iframe>';
  141. }