showinframes.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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. /* INITIALIZATION */
  25. $language_file[] = 'document';
  26. require_once '../inc/global.inc.php';
  27. require_once api_get_path(LIBRARY_PATH).'glossary.lib.php';
  28. require_once api_get_path(LIBRARY_PATH).'groupmanager.lib.php';
  29. $noPHP_SELF = true;
  30. $header_file = Security::remove_XSS($_GET['file']);
  31. $path_array = explode('/', str_replace('\\', '/', $header_file));
  32. $path_array = array_map('urldecode', $path_array);
  33. $header_file = implode('/', $path_array);
  34. $nameTools = $header_file;
  35. $name_to_show = cut($header_file, 80);
  36. $current_group = GroupManager :: get_group_properties($_SESSION['_gid']);
  37. $current_group_name=$current_group['name'];
  38. if (isset($_SESSION['_gid']) && $_SESSION['_gid'] != '') {
  39. $req_gid = '&amp;gidReq='.$_SESSION['_gid'];
  40. $interbreadcrumb[] = array ('url' => '../group/group.php?', 'name' => get_lang('Groups'));
  41. $interbreadcrumb[] = array('url' => '../group/group_space.php?gidReq='.$_SESSION['_gid'], 'name' => get_lang('GroupSpace').' '.$current_group_name);
  42. $name_to_show = explode('/', $name_to_show);
  43. unset ($name_to_show[1]);
  44. $name_to_show = implode('/', $name_to_show);
  45. }
  46. $interbreadcrumb[] = array('url' => './document.php?curdirpath='.dirname($header_file).$req_gid, 'name' => get_lang('Documents'));
  47. $interbreadcrumb[] = array('url' => 'showinframes.php?gid='.$req_gid.'&file='.$header_file, 'name' => $name_to_show);
  48. $file_url_sys = api_get_path(SYS_COURSE_PATH).'document'.$header_file;
  49. $path_info = pathinfo($file_url_sys);
  50. $this_section = SECTION_COURSES;
  51. /*
  52. if (!empty($_GET['nopages'])) {
  53. $nopages = Security::remove_XSS($_GET['nopages']);
  54. if ($nopages == 1) {
  55. require_once api_get_path(INCLUDE_PATH).'reduced_header.inc.php';
  56. Display::display_error_message(get_lang('FileNotFound'));
  57. }
  58. exit;
  59. }
  60. */
  61. $_SESSION['whereami'] = 'document/view';
  62. $nameTools = get_lang('Documents');
  63. $file = Security::remove_XSS(urldecode($_GET['file']));
  64. /* Main section */
  65. header('Expires: Wed, 01 Jan 1990 00:00:00 GMT');
  66. //header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
  67. header('Last-Modified: Wed, 01 Jan 2100 00:00:00 GMT');
  68. header('Cache-Control: no-cache, must-revalidate');
  69. header('Pragma: no-cache');
  70. $browser_display_title = 'Documents - '.Security::remove_XSS($_GET['cidReq']).' - '.$file;
  71. // Only admins get to see the "no frames" link in pageheader.php, so students get a header that's not so high
  72. $frameheight = 135;
  73. if ($is_courseAdmin) {
  74. $frameheight = 165;
  75. }
  76. $file_root = $_course['path'].'/document'.str_replace('%2F', '/', $file);
  77. $file_url_sys = api_get_path(SYS_COURSE_PATH).$file_root;
  78. $file_url_web = api_get_path(WEB_COURSE_PATH).$file_root;
  79. $path_info = pathinfo($file_url_sys);
  80. $js_glossary_in_documents = '';
  81. if (api_get_setting('show_glossary_in_documents') == 'ismanual') {
  82. $js_glossary_in_documents = ' // $(document).ready(function() {
  83. $.frameReady(function() {
  84. // $("<div>I am a div courses</div>").prependTo("body");
  85. }, "top.mainFrame",
  86. { load: [
  87. {type:"script", id:"_fr1", src:"'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.js"},
  88. {type:"script", id:"_fr2", src:"'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.highlight.js"},
  89. {type:"script", id:"_fr3", src:"'.api_get_path(WEB_LIBRARY_PATH).'fckeditor/editor/plugins/glossary/fck_glossary_manual.js"}
  90. ]
  91. }
  92. );
  93. //});';
  94. } elseif (api_get_setting('show_glossary_in_documents') == 'isautomatic') {
  95. $js_glossary_in_documents = '// $(document).ready(function() {
  96. $.frameReady(function(){
  97. // $("<div>I am a div courses</div>").prependTo("body");
  98. }, "top.mainFrame",
  99. { load: [
  100. {type:"script", id:"_fr1", src:"'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.js"},
  101. {type:"script", id:"_fr2", src:"'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.highlight.js"},
  102. {type:"script", id:"_fr3", src:"'.api_get_path(WEB_LIBRARY_PATH).'fckeditor/editor/plugins/glossary/fck_glossary_automatic.js"}
  103. ]
  104. }
  105. );
  106. // });';
  107. }
  108. $htmlHeadXtra[] = '<script language="javascript" src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.js"></script>';
  109. $htmlHeadXtra[] = '<script language="javascript" src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.frameready.js"></script>';
  110. $htmlHeadXtra[] = '<script type="text/javascript">
  111. <!--
  112. var updateContentHeight = function() {
  113. HeaderHeight = document.getElementById("header").offsetHeight;
  114. FooterHeight = document.getElementById("footer").offsetHeight;
  115. docHeight = document.body.clientHeight;
  116. document.getElementById("mainFrame").style.height = ((docHeight-(parseInt(HeaderHeight)+parseInt(FooterHeight)))+60)+"px";
  117. };
  118. // Fixes the content height of the frame
  119. window.onload = function() {
  120. updateContentHeight();
  121. '.$js_glossary_in_documents.'
  122. }
  123. -->
  124. </script>';
  125. //fix the screen when you try to access a protected course through the url
  126. $is_allowed_in_course = $_SESSION ['is_allowed_in_course'];
  127. if($is_allowed_in_course==false){
  128. Display::display_header();
  129. echo '<div align="center">';
  130. Display::display_error_message(get_lang('NotAllowedClickBack').'<br /><br /><a href="javascript:history.back(1)">'.get_lang('BackToPreviousPage').'</a><br />', false);
  131. echo '</div>';
  132. Display::display_footer();
  133. die();
  134. }
  135. //Display::display_header($tool_name, 'User');
  136. Display::display_header('');
  137. echo "<div align=\"center\">";
  138. $file_url_web = api_get_path(WEB_COURSE_PATH).$_course['path'].'/document'.$header_file.'?'.api_get_cidreq();
  139. echo '<a href="'.$file_url_web.'" target="_blank">'.get_lang('_cut_paste_link').'</a></div>';
  140. //echo '<div>';
  141. if (file_exists($file_url_sys)) {
  142. echo '<iframe border="0" frameborder="0" scrolling="auto" style="width:100%;" id="mainFrame" name="mainFrame" src="'.$file_url_web.'?'.api_get_cidreq().'&rand='.mt_rand(1, 10000).'"></iframe>';
  143. } else {
  144. echo '<frame name="mainFrame" id="mainFrame" src=showinframes.php?nopages=1 />';
  145. }
  146. //echo '</div>';
  147. Display::display_footer();