showinframes.php 17 KB

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