showinframes.php 17 KB

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