showinframes.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430
  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. api_protect_course_script();
  30. $noPHP_SELF = true;
  31. $header_file = isset($_GET['file']) ? Security::remove_XSS($_GET['file']) : null;
  32. $document_id = intval($_GET['id']);
  33. $course_info = api_get_course_info();
  34. $course_code = api_get_course_id();
  35. $session_id = api_get_session_id();
  36. if (empty($course_info)) {
  37. api_not_allowed(true);
  38. }
  39. $show_web_odf = false;
  40. //Generate path
  41. if (!$document_id) {
  42. $document_id = DocumentManager::get_document_id($course_info, $header_file);
  43. }
  44. $document_data = DocumentManager::get_document_data_by_id($document_id, $course_code, true, $session_id);
  45. if ($session_id != 0 and !$document_data) {
  46. $document_data = DocumentManager::get_document_data_by_id($document_id, $course_code, true, 0);
  47. }
  48. if (empty($document_data)) {
  49. api_not_allowed(true);
  50. }
  51. $header_file = $document_data['path'];
  52. $name_to_show = $document_data['title'];
  53. $path_array = explode('/', str_replace('\\', '/', $header_file));
  54. $path_array = array_map('urldecode', $path_array);
  55. $header_file = implode('/', $path_array);
  56. $file = Security::remove_XSS(urldecode($document_data['path']));
  57. $file_root = $course_info['path'].'/document'.str_replace('%2F', '/', $file);
  58. $file_url_sys = api_get_path(SYS_COURSE_PATH).$file_root;
  59. $file_url_web = api_get_path(WEB_COURSE_PATH).$file_root;
  60. if (!file_exists($file_url_sys)) {
  61. api_not_allowed(true);
  62. }
  63. if (is_dir($file_url_sys)) {
  64. api_not_allowed(true);
  65. }
  66. // Check user visibility.
  67. $is_visible = DocumentManager::check_visibility_tree($document_id, api_get_course_id(), api_get_session_id(), api_get_user_id());
  68. if (!api_is_allowed_to_edit() && !$is_visible) {
  69. api_not_allowed(true);
  70. }
  71. $pathinfo = pathinfo($header_file);
  72. $jplayer_supported_files = array('mp4', 'ogv','flv');
  73. $jplayer_supported = false;
  74. if (in_array(strtolower($pathinfo['extension']), $jplayer_supported_files)) {
  75. $jplayer_supported = true;
  76. }
  77. $group_id = api_get_group_id();
  78. $current_group = GroupManager::get_group_properties($group_id);
  79. $current_group_name=$current_group['name'];
  80. $req_gid = null;
  81. if (isset($group_id) && $group_id != '') {
  82. $req_gid = '&amp;gidReq='.$group_id;
  83. $interbreadcrumb[] = array ('url' => '../group/group.php?', 'name' => get_lang('Groups'));
  84. $interbreadcrumb[] = array('url' => '../group/group_space.php?gidReq='.$group_id, 'name' => get_lang('GroupSpace').' '.$current_group_name);
  85. $name_to_show = explode('/', $name_to_show);
  86. unset ($name_to_show[1]);
  87. $name_to_show = implode('/', $name_to_show);
  88. }
  89. $interbreadcrumb[] = array('url' => './document.php?curdirpath='.dirname($header_file).$req_gid, 'name' => get_lang('Documents'));
  90. if (empty($document_data['parents'])) {
  91. if (isset($_GET['createdir'])) {
  92. $interbreadcrumb[] = array('url' => $document_data['document_url'], 'name' => $document_data['title']);
  93. } else {
  94. $interbreadcrumb[] = array('url' => '#', 'name' => $document_data['title']);
  95. }
  96. } else {
  97. foreach($document_data['parents'] as $document_sub_data) {
  98. if (!isset($_GET['createdir']) && $document_sub_data['id'] == $document_data['id']) {
  99. $document_sub_data['document_url'] = '#';
  100. }
  101. $interbreadcrumb[] = array('url' => $document_sub_data['document_url'], 'name' => $document_sub_data['title']);
  102. }
  103. }
  104. $this_section = SECTION_COURSES;
  105. $_SESSION['whereami'] = 'document/view';
  106. $nameTools = get_lang('Documents');
  107. /**
  108. * Main code section
  109. */
  110. header('Expires: Wed, 01 Jan 1990 00:00:00 GMT');
  111. //header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
  112. header('Last-Modified: Wed, 01 Jan 2100 00:00:00 GMT');
  113. header('Cache-Control: no-cache, must-revalidate');
  114. header('Pragma: no-cache');
  115. $browser_display_title = 'Documents - '.Security::remove_XSS($_GET['cidReq']).' - '.$file;
  116. // Only admins get to see the "no frames" link in pageheader.php, so students get a header that's not so high
  117. $frameheight = 135;
  118. if (api_is_course_admin()) {
  119. $frameheight = 165;
  120. }
  121. $mathJaxUrl = api_get_path(WEB_LIBRARY_JS_PATH).'math_jax/MathJax.js?config=default';
  122. $js_glossary_in_documents = '';
  123. if (api_get_setting('show_glossary_in_documents') == 'ismanual') {
  124. $js_glossary_in_documents = '
  125. $.frameReady(function() {
  126. // $("<div>I am a div courses</div>").prependTo("body");
  127. }, "top.mainFrame",
  128. { load: [
  129. {type:"script", id:"_fr1", src:"'.api_get_path(WEB_LIBRARY_JS_PATH).'jquery.js"},
  130. {type:"script", id:"_fr2", src:"'.api_get_path(WEB_LIBRARY_JS_PATH).'jquery.highlight.js"},
  131. {type:"script", id:"_fr3", src:"'.api_get_path(WEB_LIBRARY_PATH).'fckeditor/editor/plugins/glossary/fck_glossary_manual.js"},
  132. {type:"script", id:"_fr4", src:"'.$mathJaxUrl.'"}
  133. ]
  134. }
  135. );';
  136. } elseif (api_get_setting('show_glossary_in_documents') == 'isautomatic') {
  137. $js_glossary_in_documents = '
  138. $.frameReady(function(){
  139. // $("<div>I am a div courses</div>").prependTo("body");
  140. }, "top.mainFrame",
  141. { load: [
  142. {type:"script", id:"_fr1", src:"'.api_get_path(WEB_LIBRARY_JS_PATH).'jquery.js"},
  143. {type:"script", id:"_fr4", src:"'.api_get_path(WEB_LIBRARY_JS_PATH).'jquery-ui/smoothness/jquery-ui-1.8.21.custom.min.js"},
  144. {type:"stylesheet", id:"_fr5", src:"'.api_get_path(WEB_LIBRARY_JS_PATH).'jquery-ui/smoothness/jquery-ui-1.8.21.custom.css"},
  145. {type:"script", id:"_fr2", src:"'.api_get_path(WEB_LIBRARY_JS_PATH).'jquery.highlight.js"},
  146. {type:"script", id:"_fr3", src:"'.api_get_path(WEB_LIBRARY_PATH).'fckeditor/editor/plugins/glossary/fck_glossary_automatic.js"},
  147. {type:"script", id:"_fr6", src:"'.$mathJaxUrl.'"}
  148. ]
  149. }
  150. );';
  151. }
  152. if (empty($js_glossary_in_documents)) {
  153. $js_glossary_in_documents = '
  154. $.frameReady(function() {
  155. }, "top.mainFrame",
  156. {
  157. load: [
  158. {type:"script", id:"_fr1", src:"'.api_get_path(WEB_LIBRARY_JS_PATH).'jquery.js"},
  159. {type:"script", id:"_fr2", src:"'.$mathJaxUrl.'"}
  160. ]
  161. }
  162. );';
  163. }
  164. $web_odf_supported_files = DocumentManager::get_web_odf_extension_list();
  165. $htmlHeadXtra[] = api_get_js('math_jax/MathJax.js?config=TeX-AMS-MML_HTMLorMML');
  166. if (in_array(strtolower($pathinfo['extension']), $web_odf_supported_files)) {
  167. $show_web_odf = true;
  168. $htmlHeadXtra[] = api_get_js('webodf/webodf.js');
  169. $htmlHeadXtra[] = api_get_css(api_get_path(WEB_LIBRARY_JS_PATH).'webodf/webodf.css');
  170. $htmlHeadXtra[] = '
  171. <script charset="utf-8">
  172. function init() {
  173. var odfelement = document.getElementById("odf"),
  174. odfcanvas = new odf.OdfCanvas(odfelement);
  175. odfcanvas.load("'.$file_url_web.'");
  176. }
  177. $(document).ready(function() {
  178. window.setTimeout(init, 0);
  179. });
  180. </script>';
  181. }
  182. $execute_iframe = true;
  183. if ($jplayer_supported) {
  184. $extension = api_strtolower($pathinfo['extension']);
  185. $js_path = api_get_path(WEB_LIBRARY_JS_PATH);
  186. $htmlHeadXtra[] = '<link rel="stylesheet" href="'.$js_path.'jquery-jplayer/skins/blue/jplayer.blue.monday.css" type="text/css">';
  187. $htmlHeadXtra[] = '<script type="text/javascript" src="'.$js_path.'jquery-jplayer/jquery.jplayer.min.js"></script>';
  188. $jquery = ' $("#jquery_jplayer_1").jPlayer({
  189. ready: function() {
  190. $(this).jPlayer("setMedia", {
  191. '.$extension.' : "'.$document_data['direct_url'].'"
  192. });
  193. },
  194. errorAlerts: false,
  195. warningAlerts: false,
  196. //swfPath: "../inc/lib/javascript/jquery-jplayer",
  197. swfPath: "'.$js_path.'jquery-jplayer",
  198. //supplied: "m4a, oga, mp3, ogg, wav",
  199. supplied: "'.$extension.'",
  200. //wmode: "window",
  201. solution: "flash, html", // Do not change this setting
  202. cssSelectorAncestor: "#jp_container_1",
  203. });';
  204. $htmlHeadXtra[] = '<script>
  205. $(document).ready( function() {
  206. //Experimental changes to preview mp3, ogg files
  207. '.$jquery.'
  208. });
  209. </script>';
  210. $execute_iframe = false;
  211. }
  212. if ($show_web_odf) {
  213. $execute_iframe = false;
  214. }
  215. $is_freemind_available = $pathinfo['extension']=='mm' && api_get_setting('enable_freemind') == 'true';
  216. if ($is_freemind_available){
  217. $execute_iframe = false;
  218. }
  219. $is_nanogong_available = $pathinfo['extension']=='wav' && preg_match('/_chnano_.wav/i', $file_url_web) && api_get_setting('enable_nanogong') == 'true';
  220. if ($is_nanogong_available){
  221. $execute_iframe = false;
  222. }
  223. if (!$jplayer_supported && $execute_iframe) {
  224. $htmlHeadXtra[] = '<script type="text/javascript">
  225. <!--
  226. var jQueryFrameReadyConfigPath = \''.api_get_path(WEB_LIBRARY_JS_PATH).'jquery.js\';
  227. -->
  228. </script>';
  229. $htmlHeadXtra[] = '<script type="text/javascript" src="'.api_get_path(WEB_LIBRARY_JS_PATH).'jquery.frameready.js"></script>';
  230. $htmlHeadXtra[] = '<script>
  231. <!--
  232. var updateContentHeight = function() {
  233. my_iframe = document.getElementById("mainFrame");
  234. //this doesnt seem to work in IE 7,8,9
  235. new_height = my_iframe.contentWindow.document.body.scrollHeight;
  236. my_iframe.height = my_iframe.contentWindow.document.body.scrollHeight + "px";
  237. };
  238. // Fixes the content height of the frame
  239. window.onload = function() {
  240. updateContentHeight();
  241. '.$js_glossary_in_documents.'
  242. }
  243. -->
  244. </script>';
  245. }
  246. Display::display_header('');
  247. echo '<div align="center">';
  248. $file_url_web = api_get_path(WEB_COURSE_PATH).$_course['path'].'/document'.$header_file.'?'.api_get_cidreq();
  249. if (!$is_nanogong_available) {
  250. if (in_array(strtolower($pathinfo['extension']) , array('html', "htm"))) {
  251. echo '<a class="btn" href="'.$file_url_web.'" target="_blank">'.get_lang('CutPasteLink').'</a>';
  252. } else {
  253. echo '<a class="btn" href="'.$file_url_web.'" target="_blank">'.get_lang('Download').'</a>';
  254. }
  255. }
  256. if ($show_web_odf) {
  257. //echo Display::url(get_lang('Show'), api_get_path(WEB_CODE_PATH).'document/edit_odf.php?id='.$document_data['id'], array('class' => 'btn'));
  258. echo '<div id="odf"></div>';
  259. }
  260. echo '</div>';
  261. if ($jplayer_supported) {
  262. echo '<br /><div class="span12" style="margin:0 auto; width:100%; text-align:center;">';
  263. echo DocumentManager::generate_video_preview($document_data);
  264. echo '</div>';
  265. }
  266. if ($is_freemind_available) {
  267. ?>
  268. <script type="text/javascript" src="<?php echo api_get_path(WEB_LIBRARY_PATH) ?>swfobject/swfobject.js"></script>
  269. <style type="text/css">
  270. #flashcontent {
  271. height: 500px;
  272. padding-top:10px;
  273. }
  274. </style>
  275. <div id="flashcontent" onmouseover="giveFocus();">
  276. Flash plugin or Javascript are turned off.
  277. Activate both and reload to view the mindmap
  278. </div>
  279. <script>
  280. function giveFocus() {
  281. document.visorFreeMind.focus();
  282. }
  283. document.onload=giveFocus;
  284. // <![CDATA[
  285. // for allowing using http://.....?mindmap.mm mode
  286. function getMap(map){
  287. var result=map;
  288. var loc=document.location+'';
  289. if(loc.indexOf(".mm")>0 && loc.indexOf("?")>0){
  290. result=loc.substring(loc.indexOf("?")+1);
  291. }
  292. return result;
  293. }
  294. var fo = new FlashObject("<?php echo api_get_path(WEB_LIBRARY_PATH); ?>freeMindFlashBrowser/visorFreemind.swf", "visorFreeMind", "100%", "100%", 6, "#ffffff");
  295. fo.addParam("quality", "high");
  296. //fo.addParam("bgcolor", "#a0a0f0");
  297. fo.addVariable("openUrl", "_blank");//Default value "_self"
  298. fo.addVariable("startCollapsedToLevel","3");//Default value = "-1", meaning do nothing, the mindmap will open as it was saved. The root node, or central node, of your mindmap is level zero. You could force the browser to open (unfold) your mind map to an expanded level using this variable.
  299. fo.addVariable("maxNodeWidth","200");
  300. //
  301. fo.addVariable("mainNodeShape","elipse");//"rectangle", "elipse", "none". None hide the main node. Default is "elipse"
  302. fo.addVariable("justMap","false");
  303. fo.addVariable("initLoadFile",getMap("<?php echo $file_url_web; ?>"));
  304. fo.addVariable("defaultToolTipWordWrap",200);//max width for tooltips. Default "600" pixels
  305. fo.addVariable("offsetX","left");//for the center of the mindmap. Admit also "left" and "right"
  306. fo.addVariable("offsetY","top");//for the center of the mindmap. Admit also "top" and "bottom"
  307. fo.addVariable("buttonsPos","top");//"top" or "bottom"
  308. fo.addVariable("min_alpha_buttons",20);//for dynamic view of buttons
  309. fo.addVariable("max_alpha_buttons",100);//for dynamic view of buttons
  310. fo.addVariable("scaleTooltips","false");
  311. //
  312. //extra
  313. //fo.addVariable("CSSFile","<?php // echo api_get_path(WEB_LIBRARY_PATH); ?>freeMindFlashBrowser/flashfreemind.css");//
  314. //fo.addVariable("baseImagePath","<?php // echo api_get_path(WEB_LIBRARY_PATH); ?>freeMindFlashBrowser/");//
  315. //fo.addVariable("justMap","false");//Hides all the upper control options. Default value "false"
  316. //fo.addVariable("noElipseMode","anyvalue");//for changing to old elipseNode edges. Default = not set
  317. //fo.addVariable("ShotsWidth","200");//The width of snapshots, in pixels.
  318. //fo.addVariable("genAllShots","true");//Preview shots (like the samples on the Shots Width page) will be generated for all linked maps when your main map loads. If you have a lot of linked maps, this could take some time to complete
  319. //fo.addVariable("unfoldAll","true"); //For each mindmap loaded start the display with all nodes unfolded. Another variable to be wary of!
  320. //fo.addVariable("toolTipsBgColor","0xaaeeaa");: bgcolor for tooltips ej;"0xaaeeaa"
  321. //fo.addVariable("defaultWordWrap","300"); //default 600
  322. //
  323. fo.write("flashcontent");
  324. // ]]>
  325. </script>
  326. <?php
  327. }
  328. if ($is_nanogong_available) {
  329. //make temp audio
  330. $temp_folder=api_get_path(SYS_ARCHIVE_PATH).'temp/audio';
  331. if (!file_exists($temp_folder)) {
  332. @mkdir($temp_folder, api_get_permissions_for_new_directories(), true);
  333. }
  334. //make htaccess with allow from all, and file index.html into temp/audio
  335. $htaccess = api_get_path(SYS_ARCHIVE_PATH).'temp/audio/.htaccess';
  336. if (!file_exists($htaccess)) {
  337. $htaccess_content="order deny,allow\r\nallow from all\r\nOptions -Indexes";
  338. $fp = @ fopen(api_get_path(SYS_ARCHIVE_PATH).'temp/audio/.htaccess', 'w');
  339. if ($fp) {
  340. fwrite($fp, $htaccess_content);
  341. fclose($fp);
  342. }
  343. }
  344. //encript temp name file
  345. $name_crip = sha1(uniqid());//encript
  346. $findext= explode(".", $file);
  347. $extension= $findext[count($findext)-1];
  348. $file_crip=$name_crip.'.'.$extension;
  349. //copy file to temp/audio directory
  350. $from_sys=$file_url_sys;
  351. $to_sys=api_get_path(SYS_ARCHIVE_PATH).'temp/audio/'.$file_crip;
  352. if (file_exists($from_sys)) {
  353. copy($from_sys, $to_sys);
  354. }
  355. //get file from tmp directory
  356. $to_url = api_get_path(WEB_ARCHIVE_PATH).'temp/audio/'.$file_crip;
  357. echo '<div align="center">';
  358. echo '<a class="btn" href="'.$file_url_web.'" target="_blank">'.get_lang('Download').'</a>';
  359. echo '<br/>';
  360. echo '<br/>';
  361. echo DocumentManager::readNanogongFile($to_url);
  362. //erase temp file in tmp directory when return to documents
  363. $_SESSION['temp_audio_nanogong']=$to_sys;
  364. echo '</div>';
  365. }
  366. if ($execute_iframe) {
  367. echo '<iframe id="mainFrame" name="mainFrame" border="0" frameborder="0" scrolling="no" style="width:100%;" height="600" src="'.$file_url_web.'&amp;rand='.mt_rand(1, 10000).'" height="500"></iframe>';
  368. }
  369. if (api_get_setting('show_glossary_in_documents') == 'isautomatic') {
  370. echo '<div id="glossary_popup"></div>';
  371. }
  372. Display::display_footer();