showinframes.php 17 KB

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