showinframes.php 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This file will show documents in a separate frame.
  5. * We don't like frames, but it was the best of two bad things.
  6. *
  7. * display html files within Chamilo - html files have the Chamilo header.
  8. *
  9. * --- advantages ---
  10. * users "feel" like they are in Chamilo,
  11. * and they can use the navigation context provided by the header.
  12. *
  13. * --- design ---
  14. * a file gets a parameter (an html file)
  15. * and shows
  16. * - chamilo header
  17. * - html file from parameter
  18. * - (removed) chamilo footer
  19. *
  20. * @version 0.6
  21. * @author Roan Embrechts (roan.embrechts@vub.ac.be)
  22. * @package chamilo.document
  23. */
  24. /**
  25. * INITIALIZATION
  26. */
  27. $language_file[] = 'document';
  28. require_once '../inc/global.inc.php';
  29. require_once api_get_path(LIBRARY_PATH).'document.lib.php';
  30. require_once api_get_path(LIBRARY_PATH).'glossary.lib.php';
  31. require_once api_get_path(LIBRARY_PATH).'groupmanager.lib.php';
  32. // Protection
  33. api_protect_course_script();
  34. $noPHP_SELF = true;
  35. $header_file = Security::remove_XSS($_GET['file']);
  36. $document_id = intval($_GET['id']);
  37. $course_info = api_get_course_info();
  38. $course_code = api_get_course_id();
  39. if (empty($course_info)) {
  40. api_not_allowed(true);
  41. }
  42. //Generate path
  43. if (!$document_id) {
  44. $document_id = DocumentManager::get_document_id($course_info, $header_file);
  45. }
  46. $document_data = DocumentManager::get_document_data_by_id($document_id, $course_code, true);
  47. if (empty($document_data)) {
  48. api_not_allowed(true);
  49. }
  50. $header_file = $document_data['path'];
  51. $name_to_show = $document_data['title'];
  52. $path_array = explode('/', str_replace('\\', '/', $header_file));
  53. $path_array = array_map('urldecode', $path_array);
  54. $header_file = implode('/', $path_array);
  55. $file = Security::remove_XSS(urldecode($document_data['path']));
  56. $file_root = $course_info['path'].'/document'.str_replace('%2F', '/', $file);
  57. $file_url_sys = api_get_path(SYS_COURSE_PATH).$file_root;
  58. $file_url_web = api_get_path(WEB_COURSE_PATH).$file_root;
  59. if (!file_exists($file_url_sys)) {
  60. api_not_allowed(true);
  61. }
  62. if (is_dir($file_url_sys)) {
  63. api_not_allowed(true);
  64. }
  65. //fix the screen when you try to access a protected course through the url
  66. $is_allowed_in_course = $_SESSION ['is_allowed_in_course'];
  67. if ($is_allowed_in_course == false) {
  68. api_not_allowed(true);
  69. }
  70. //Check user visibility
  71. //$is_visible = DocumentManager::is_visible_by_id($document_id, $course_info, api_get_session_id(), api_get_user_id());
  72. $is_visible = DocumentManager::check_visibility_tree($document_id, api_get_course_id(), api_get_session_id(), api_get_user_id());
  73. if (!api_is_allowed_to_edit() && !$is_visible) {
  74. api_not_allowed(true);
  75. }
  76. $group_id = api_get_group_id();
  77. $current_group = GroupManager::get_group_properties($group_id);
  78. $current_group_name=$current_group['name'];
  79. if (isset($group_id) && $group_id != '') {
  80. $req_gid = '&amp;gidReq='.$group_id;
  81. $interbreadcrumb[] = array ('url' => '../group/group.php?', 'name' => get_lang('Groups'));
  82. $interbreadcrumb[] = array('url' => '../group/group_space.php?gidReq='.$group_id, 'name' => get_lang('GroupSpace').' '.$current_group_name);
  83. $name_to_show = explode('/', $name_to_show);
  84. unset ($name_to_show[1]);
  85. $name_to_show = implode('/', $name_to_show);
  86. }
  87. $interbreadcrumb[] = array('url' => './document.php?curdirpath='.dirname($header_file).$req_gid, 'name' => get_lang('Documents'));
  88. if (empty($document_data['parents'])) {
  89. if (isset($_GET['createdir'])) {
  90. $interbreadcrumb[] = array('url' => $document_data['document_url'], 'name' => $document_data['title']);
  91. } else {
  92. $interbreadcrumb[] = array('url' => '#', 'name' => $document_data['title']);
  93. }
  94. } else {
  95. foreach($document_data['parents'] as $document_sub_data) {
  96. if (!isset($_GET['createdir']) && $document_sub_data['id'] == $document_data['id']) {
  97. $document_sub_data['document_url'] = '#';
  98. }
  99. $interbreadcrumb[] = array('url' => $document_sub_data['document_url'], 'name' => $document_sub_data['title']);
  100. }
  101. }
  102. $this_section = SECTION_COURSES;
  103. $_SESSION['whereami'] = 'document/view';
  104. $nameTools = get_lang('Documents');
  105. /**
  106. * Main code section
  107. */
  108. header('Expires: Wed, 01 Jan 1990 00:00:00 GMT');
  109. //header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
  110. header('Last-Modified: Wed, 01 Jan 2100 00:00:00 GMT');
  111. header('Cache-Control: no-cache, must-revalidate');
  112. header('Pragma: no-cache');
  113. $browser_display_title = 'Documents - '.Security::remove_XSS($_GET['cidReq']).' - '.$file;
  114. // Only admins get to see the "no frames" link in pageheader.php, so students get a header that's not so high
  115. $frameheight = 135;
  116. if ($is_courseAdmin) {
  117. $frameheight = 165;
  118. }
  119. $js_glossary_in_documents = '';
  120. if (api_get_setting('show_glossary_in_documents') == 'ismanual') {
  121. $js_glossary_in_documents = ' // $(document).ready(function() {
  122. $.frameReady(function() {
  123. // $("<div>I am a div courses</div>").prependTo("body");
  124. }, "top.mainFrame",
  125. { load: [
  126. {type:"script", id:"_fr1", src:"'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.min.js"},
  127. {type:"script", id:"_fr2", src:"'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.highlight.js"},
  128. {type:"script", id:"_fr3", src:"'.api_get_path(WEB_LIBRARY_PATH).'fckeditor/editor/plugins/glossary/fck_glossary_manual.js"}
  129. ]
  130. }
  131. );
  132. //});';
  133. } elseif (api_get_setting('show_glossary_in_documents') == 'isautomatic') {
  134. $js_glossary_in_documents = '// $(document).ready(function() {
  135. $.frameReady(function(){
  136. // $("<div>I am a div courses</div>").prependTo("body");
  137. }, "top.mainFrame",
  138. { load: [
  139. {type:"script", id:"_fr1", src:"'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.min.js"},
  140. {type:"script", id:"_fr2", src:"'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.highlight.js"},
  141. {type:"script", id:"_fr3", src:"'.api_get_path(WEB_LIBRARY_PATH).'fckeditor/editor/plugins/glossary/fck_glossary_automatic.js"}
  142. ]
  143. }
  144. );
  145. // });';
  146. }
  147. $htmlHeadXtra[] = '<script type="text/javascript">
  148. <!--
  149. var jQueryFrameReadyConfigPath = \''.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.min.js\';
  150. -->
  151. </script>';
  152. $htmlHeadXtra[] = '<script type="text/javascript" src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.frameready.js"></script>';
  153. $htmlHeadXtra[] = '
  154. <script type="text/javascript">
  155. <!--
  156. var updateContentHeight = function() {
  157. //HeaderHeight = document.getElementById("header").offsetHeight;
  158. //FooterHeight = document.getElementById("footer").offsetHeight;
  159. //document.getElementById("mainFrame").style.height = ((docHeight-(parseInt(HeaderHeight)+parseInt(FooterHeight)))+60)+"px";
  160. my_iframe = document.getElementById("mainFrame");
  161. //this doesnt seem to work in IE 7,8,9
  162. new_height = my_iframe.contentWindow.document.body.scrollHeight;
  163. my_iframe.height = my_iframe.contentWindow.document.body.scrollHeight + "px";
  164. };
  165. // Fixes the content height of the frame
  166. window.onload = function() {
  167. updateContentHeight();
  168. '.$js_glossary_in_documents.'
  169. }
  170. -->
  171. </script>';
  172. //Display::display_header($tool_name, 'User');
  173. Display::display_header('');
  174. echo "<div align=\"center\">";
  175. $file_url_web = api_get_path(WEB_COURSE_PATH).$_course['path'].'/document'.$header_file.'?'.api_get_cidreq();
  176. echo '<a href="'.$file_url_web.'" target="_blank">'.get_lang('_cut_paste_link').'</a></div>';
  177. $pathinfo =pathinfo($header_file);
  178. if ($pathinfo['extension']=='wav' && api_get_setting('enable_nanogong') == 'true'){
  179. echo '<div align="center">';
  180. echo '<br/>';
  181. echo '<applet id="applet" archive="../inc/lib/nanogong/nanogong.jar" code="gong.NanoGong" width="160" height="40">';
  182. echo '<param name="SoundFileURL" value="'.$file_url_web.'" />';
  183. echo '<param name="ShowSaveButton" value="false" />';
  184. echo '<param name="ShowTime" value="true" />';
  185. echo '<param name="ShowRecordButton" value="false" />';
  186. echo '</applet>';
  187. echo '</div>';
  188. }
  189. else{
  190. echo '<iframe border="0" frameborder="0" scrolling="no" style="width:100%;" height="600" id="mainFrame" name="mainFrame" src="'.$file_url_web.'&amp;rand='.mt_rand(1, 10000).'" height="500"></iframe>';
  191. }
  192. Display::display_footer();