showinframesmin.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. require_once api_get_path(LIBRARY_PATH).'document.lib.php';
  15. require_once api_get_path(LIBRARY_PATH).'glossary.lib.php';
  16. require_once api_get_path(LIBRARY_PATH).'groupmanager.lib.php';
  17. // Protection
  18. api_protect_course_script();
  19. $noPHP_SELF = true;
  20. $header_file = Security::remove_XSS($_GET['file']);
  21. $document_id = intval($_GET['id']);
  22. $course_info = api_get_course_info();
  23. $course_code = api_get_course_id();
  24. if (empty($course_info)) {
  25. api_not_allowed(true);
  26. }
  27. //Generate path
  28. if (!$document_id) {
  29. $document_id = DocumentManager::get_document_id($course_info, $header_file);
  30. }
  31. $document_data = DocumentManager::get_document_data_by_id($document_id, $course_code);
  32. if (empty($document_data)) {
  33. api_not_allowed(true);
  34. }
  35. $header_file = $document_data['path'];
  36. $name_to_show = Text::cut($header_file, 80);
  37. $path_array = explode('/', str_replace('\\', '/', $header_file));
  38. $path_array = array_map('urldecode', $path_array);
  39. $header_file = implode('/', $path_array);
  40. $file = Security::remove_XSS(urldecode($document_data['path']));
  41. $file_root = $course_info['path'].'/document'.str_replace('%2F', '/', $file);
  42. $file_url_sys = api_get_path(SYS_COURSE_PATH).$file_root;
  43. $file_url_web = api_get_path(WEB_COURSE_PATH).$file_root;
  44. if (!file_exists($file_url_sys)) {
  45. api_not_allowed(true);
  46. }
  47. if (is_dir($file_url_sys)) {
  48. api_not_allowed(true);
  49. }
  50. //fix the screen when you try to access a protected course through the url
  51. $is_allowed_in_course = $_SESSION ['is_allowed_in_course'];
  52. if ($is_allowed_in_course == false) {
  53. api_not_allowed(true);
  54. }
  55. //Check user visibility
  56. //$is_visible = DocumentManager::is_visible_by_id($document_id, $course_info, api_get_session_id(), api_get_user_id());
  57. $is_visible = DocumentManager::check_visibility_tree($document_id, api_get_course_id(), api_get_session_id(), api_get_user_id());
  58. if (!api_is_allowed_to_edit() && !$is_visible) {
  59. api_not_allowed(true);
  60. }
  61. //TODO:clean all code
  62. /* Main section */
  63. header('Expires: Wed, 01 Jan 1990 00:00:00 GMT');
  64. //header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
  65. header('Last-Modified: Wed, 01 Jan 2100 00:00:00 GMT');
  66. header('Cache-Control: no-cache, must-revalidate');
  67. header('Pragma: no-cache');
  68. $browser_display_title = 'Documents - '.Security::remove_XSS($_GET['cidReq']).' - '.$file;
  69. $js_glossary_in_documents = '';
  70. if (api_get_setting('show_glossary_in_documents') == 'ismanual') {
  71. $js_glossary_in_documents = ' // $(document).ready(function() {
  72. $.frameReady(function() {
  73. // $("<div>I am a div courses</div>").prependTo("body");
  74. }, "mainFrame",
  75. { load: [
  76. {type:"script", id:"_fr1", src:"'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.min.js"},
  77. {type:"script", id:"_fr2", src:"'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.highlight.js"},
  78. {type:"script", id:"_fr3", src:"'.api_get_path(WEB_LIBRARY_PATH).'fckeditor/editor/plugins/glossary/fck_glossary_manual.js"}
  79. ]
  80. }
  81. );
  82. //});';
  83. } elseif (api_get_setting('show_glossary_in_documents') == 'isautomatic') {
  84. $js_glossary_in_documents = '// $(document).ready(function() {
  85. $.frameReady(function(){
  86. // $("<div>I am a div courses</div>").prependTo("body");
  87. }, "mainFrame",
  88. { load: [
  89. {type:"script", id:"_fr1", src:"'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.min.js"},
  90. {type:"script", id:"_fr2", src:"'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.highlight.js"},
  91. {type:"script", id:"_fr3", src:"'.api_get_path(WEB_LIBRARY_PATH).'fckeditor/editor/plugins/glossary/fck_glossary_automatic.js"}
  92. ]
  93. }
  94. );
  95. // });';
  96. }
  97. $htmlHeadXtra[] = '<script type="text/javascript">
  98. <!--
  99. var jQueryFrameReadyConfigPath = \''.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.min.js\';
  100. -->
  101. </script>';
  102. $htmlHeadXtra[] = '<script type="text/javascript" src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.frameready.js"></script>';
  103. $htmlHeadXtra[] = '
  104. <script type="text/javascript">
  105. <!--
  106. var updateContentHeight = function() {
  107. //HeaderHeight = document.getElementById("header").offsetHeight;
  108. //FooterHeight = document.getElementById("footer").offsetHeight;
  109. //document.getElementById("mainFrame").style.height = ((docHeight-(parseInt(HeaderHeight)+parseInt(FooterHeight)))+60)+"px";
  110. my_iframe = document.getElementById("mainFrame");
  111. new_height = my_iframe.contentWindow.document.body.scrollHeight;
  112. my_iframe.height = my_iframe.contentWindow.document.body.scrollHeight + "px";
  113. };
  114. // Fixes the content height of the frame
  115. window.onload = function() {
  116. updateContentHeight();
  117. '.$js_glossary_in_documents.'
  118. }
  119. -->
  120. </script>';
  121. Display::display_reduced_header();
  122. echo '<div align="center">';
  123. $file_url_web = api_get_path(WEB_COURSE_PATH).$_course['path'].'/document'.$header_file.'?'.api_get_cidreq();
  124. $pathinfo = pathinfo($header_file);
  125. if ($pathinfo['extension']=='wav' && preg_match('/_chnano_.wav/i', $file_url_web) && api_get_setting('enable_nanogong') == 'true'){
  126. echo '<div align="center">';
  127. echo '<br/>';
  128. echo '<applet id="applet" archive="../inc/lib/nanogong/nanogong.jar" code="gong.NanoGong" width="160" height="40" >';
  129. echo '<param name="SoundFileURL" value="'.$file_url_web.'" />';
  130. echo '<param name="ShowSaveButton" value="false" />';
  131. echo '<param name="ShowTime" value="true" />';
  132. echo '<param name="ShowRecordButton" value="false" />';
  133. echo '</applet>';
  134. echo '</div>';
  135. } else {
  136. if ($pathinfo['extension']=='swf'){ $width='83%'; $height='83%';} else {$width='100%'; $height='';}
  137. 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>';
  138. }