lp_view.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This file was originally the copy of document.php, but many modifications happened since then ;
  5. * the direct file view is not needed anymore, if the user uploads a scorm zip file, a directory
  6. * will be automatically created for it, and the files will be uncompressed there for example ;
  7. *
  8. * @package chamilo.learnpath
  9. * @author Yannick Warnier <ywarnier@beeznest.org> - redesign
  10. * @author Denes Nagy, principal author
  11. * @author Isthvan Mandak, several new features
  12. * @author Roan Embrechts, code improvements and refactoring
  13. * @license GNU/GPL - See Chamilo license directory for details
  14. */
  15. /**
  16. * Code
  17. */
  18. $_SESSION['whereami'] = 'lp/view';
  19. $this_section = SECTION_COURSES;
  20. if ($lp_controller_touched != 1) {
  21. header('location: lp_controller.php?action=view&item_id='.$_REQUEST['item_id']);
  22. exit;
  23. }
  24. /* Libraries */
  25. require_once 'back_compat.inc.php';
  26. require_once 'scorm.lib.php';
  27. require_once 'learnpath.class.php';
  28. require_once 'learnpathItem.class.php';
  29. //To prevent the template class
  30. $show_learnpath = true;
  31. api_protect_course_script();
  32. $course_code = api_get_course_id();
  33. $course_id = api_get_course_int_id();
  34. $user_id = api_get_user_id();
  35. $platform_theme = api_get_setting('stylesheets'); // Plataform's css.
  36. $my_style = $platform_theme;
  37. $htmlHeadXtra[] = api_get_jquery_ui_js();
  38. $htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.lp_minipanel.js" type="text/javascript" language="javascript"></script>';
  39. if (api_get_setting('show_glossary_in_documents') == 'ismanual' || api_get_setting('show_glossary_in_documents') == 'isautomatic' ) {
  40. $htmlHeadXtra[] = '<script type="text/javascript">
  41. <!--
  42. var jQueryFrameReadyConfigPath = \''.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.min.js\';
  43. -->
  44. </script>';
  45. $htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.frameready.js" type="text/javascript" language="javascript"></script>';
  46. $htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.highlight.js" type="text/javascript" language="javascript"></script>';
  47. }
  48. $htmlHeadXtra[] = '<script language="javascript" type="text/javascript">
  49. $(document).ready(function (){
  50. $("div#log_content_cleaner").bind("click", function() {
  51. $("div#log_content").empty();
  52. });
  53. });
  54. </script>';
  55. $htmlHeadXtra[] = '<script language="JavaScript" type="text/javascript">
  56. var dokeos_xajax_handler = window.oxajax;
  57. </script>';
  58. $_SESSION['oLP']->error = '';
  59. $lp_item_id = $_SESSION['oLP']->get_current_item_id();
  60. $lp_type = $_SESSION['oLP']->get_type();
  61. $lp_id = intval($_GET['lp_id']);
  62. // Check if the learning path is visible for student - (LP requisites)
  63. if (!api_is_allowed_to_edit(null, true) && !learnpath::is_lp_visible_for_student($lp_id, api_get_user_id())) {
  64. api_not_allowed();
  65. }
  66. //Checking visibility (eye icon)
  67. $visibility = api_get_item_visibility(api_get_course_info(), TOOL_LEARNPATH, $lp_id, $action, api_get_user_id(), api_get_session_id());
  68. if (!api_is_allowed_to_edit(null, true) && intval($visibility) == 0 ) {
  69. api_not_allowed();
  70. }
  71. // Prepare variables for the test tool (just in case) - honestly, this should disappear later on.
  72. $_SESSION['scorm_view_id'] = $_SESSION['oLP']->get_view_id();
  73. $_SESSION['scorm_item_id'] = $lp_item_id;
  74. $_SESSION['lp_mode'] = $_SESSION['oLP']->mode;
  75. // Reinit exercises variables to avoid spacename clashes (see exercise tool)
  76. if (isset($exerciseResult) || isset($_SESSION['exerciseResult'])) {
  77. api_session_unregister($exerciseResult);
  78. }
  79. unset($_SESSION['objExercise']);
  80. unset($_SESSION['questionList']);
  81. // additional APIs
  82. $htmlHeadXtra[] = '<script type="text/javascript" language="javascript">
  83. chamilo_courseCode = "'.$course_code.'";
  84. </script>';
  85. // Document API
  86. $htmlHeadXtra[] = '<script src="js/documentapi.js" type="text/javascript" language="javascript"></script>';
  87. // Storage API
  88. $htmlHeadXtra[] = '<script type="text/javascript">
  89. var sv_user = \''.api_get_user_id().'\';
  90. var sv_course = chamilo_courseCode;
  91. var sv_sco = \''.$_REQUEST['lp_id'].'\';
  92. </script>'; // FIXME fetch sco and userid from a more reliable source directly in sotrageapi.js
  93. $htmlHeadXtra[] = '<script type="text/javascript" src="js/storageapi.js"></script>';
  94. /**
  95. * Get a link to the corresponding document.
  96. */
  97. if (!isset($src)) {
  98. $src = '';
  99. switch($lp_type) {
  100. case 1:
  101. $_SESSION['oLP']->stop_previous_item();
  102. $htmlHeadXtra[] = '<script src="scorm_api.php" type="text/javascript" language="javascript"></script>';
  103. $prereq_check = $_SESSION['oLP']->prerequisites_match($lp_item_id);
  104. if ($prereq_check === true) {
  105. $src = $_SESSION['oLP']->get_link('http', $lp_item_id);
  106. //Prevents FF 3.6 + Adobe Reader 9 bug see BT#794 when calling a pdf file in a LP.
  107. $file_info = parse_url($src);
  108. $file_info = pathinfo($file_info['path']);
  109. if (api_strtolower(substr($file_info['extension'], 0, 3) == 'pdf')) {
  110. //$src = api_get_path(WEB_CODE_PATH).'newscorm/lp_view_item.php?src='.$src;
  111. $src = api_get_path(WEB_CODE_PATH).'newscorm/lp_view_item.php?lp_item_id='.$lp_item_id;
  112. }
  113. $_SESSION['oLP']->start_current_item(); // starts time counter manually if asset
  114. } else {
  115. $src = 'blank.php?error=prerequisites';
  116. }
  117. break;
  118. case 2:
  119. // save old if asset
  120. $_SESSION['oLP']->stop_previous_item(); // save status manually if asset
  121. $htmlHeadXtra[] = '<script src="scorm_api.php" type="text/javascript" language="javascript"></script>';
  122. $prereq_check = $_SESSION['oLP']->prerequisites_match($lp_item_id);
  123. if ($prereq_check === true) {
  124. $src = $_SESSION['oLP']->get_link('http',$lp_item_id);
  125. $_SESSION['oLP']->start_current_item(); // starts time counter manually if asset
  126. } else {
  127. $src = 'blank.php?error=prerequisites';
  128. }
  129. break;
  130. case 3:
  131. // aicc
  132. $_SESSION['oLP']->stop_previous_item(); // save status manually if asset
  133. $htmlHeadXtra[] = '<script src="'.$_SESSION['oLP']->get_js_lib().'" type="text/javascript" language="javascript"></script>';
  134. $prereq_check = $_SESSION['oLP']->prerequisites_match($lp_item_id);
  135. if ($prereq_check === true) {
  136. $src = $_SESSION['oLP']->get_link('http',$lp_item_id);
  137. $_SESSION['oLP']->start_current_item(); // starts time counter manually if asset
  138. } else {
  139. $src = 'blank.php';
  140. }
  141. break;
  142. case 4:
  143. break;
  144. }
  145. }
  146. $list = $_SESSION['oLP']->get_toc();
  147. $type_quiz = false;
  148. foreach($list as $toc) {
  149. if ($toc['id'] == $lp_item_id && ($toc['type']=='quiz')) {
  150. $type_quiz = true;
  151. }
  152. }
  153. $debug = 0;
  154. $autostart = 'true';
  155. // Update status, total_time from lp_item_view table when you finish the exercises in learning path.
  156. if ($type_quiz && !empty($_REQUEST['exeId']) && isset($lp_id) && isset($_GET['lp_item_id'])) {
  157. global $src;
  158. $_SESSION['oLP']->items[$_SESSION['oLP']->current]->write_to_db();
  159. $TBL_TRACK_EXERCICES = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  160. $TBL_LP_ITEM_VIEW = Database::get_course_table(TABLE_LP_ITEM_VIEW);
  161. //$TBL_LP_VIEW = Database::get_course_table(TABLE_LP_VIEW);
  162. $TBL_LP_ITEM = Database::get_course_table(TABLE_LP_ITEM);
  163. $safe_item_id = Database::escape_string($_GET['lp_item_id']);
  164. $safe_id = $lp_id;
  165. $safe_exe_id = intval($_REQUEST['exeId']);
  166. if ($safe_id == strval(intval($safe_id)) && $safe_item_id == strval(intval($safe_item_id))) {
  167. $sql = 'SELECT start_date, exe_date, exe_result, exe_weighting FROM ' . $TBL_TRACK_EXERCICES . ' WHERE exe_id = '.$safe_exe_id;
  168. $res = Database::query($sql);
  169. $row_dates = Database::fetch_array($res);
  170. $time_start_date = api_strtotime($row_dates['start_date'],'UTC');
  171. $time_exe_date = api_strtotime($row_dates['exe_date'],'UTC');
  172. $mytime = ((int)$time_exe_date-(int)$time_start_date);
  173. $score = (float)$row_dates['exe_result'];
  174. $max_score = (float)$row_dates['exe_weighting'];
  175. $sql_upd_max_score = "UPDATE $TBL_LP_ITEM SET max_score = '$max_score' WHERE c_id = $course_id AND id = '".(int)$safe_item_id."'";
  176. if ($debug) error_log($sql_upd_max_score);
  177. Database::query($sql_upd_max_score);
  178. $sql_last_attempt = "SELECT id FROM $TBL_LP_ITEM_VIEW WHERE c_id = $course_id AND lp_item_id = '$safe_item_id' AND lp_view_id = '".$_SESSION['oLP']->lp_view_id."' order by id desc limit 1";
  179. $res_last_attempt = Database::query($sql_last_attempt);
  180. if (Database::num_rows($res_last_attempt)) {
  181. $row_last_attempt = Database::fetch_row($res_last_attempt);
  182. $lp_item_view_id = $row_last_attempt[0];
  183. $sql_upd_score = "UPDATE $TBL_LP_ITEM_VIEW SET status = 'completed' , score = $score, total_time = $mytime
  184. WHERE id='".$lp_item_view_id."' AND c_id = $course_id ";
  185. if ($debug) error_log($sql_upd_score);
  186. Database::query($sql_upd_score);
  187. $update_query = "UPDATE $TBL_TRACK_EXERCICES SET orig_lp_item_view_id = $lp_item_view_id WHERE exe_id = ".$safe_exe_id;
  188. Database::query($update_query);
  189. }
  190. }
  191. if (intval($_GET['fb_type']) > 0) {
  192. $src = 'blank.php?msg=exerciseFinished';
  193. } else {
  194. $src = api_get_path(WEB_CODE_PATH).'exercice/exercise_show.php?id='.$safe_exe_id.'&origin=learnpath&learnpath_id='.$lp_id.'&learnpath_item_id='.$lp_id.'&fb_type='.Security::remove_XSS($_GET['fb_type']);
  195. if ($debug) error_log('Calling URL'.$src);
  196. }
  197. $autostart = 'false';
  198. }
  199. $_SESSION['oLP']->set_previous_item($lp_item_id);
  200. $nameTools = Security :: remove_XSS($_SESSION['oLP']->get_name());
  201. $save_setting = api_get_setting('show_navigation_menu');
  202. global $_setting;
  203. $_setting['show_navigation_menu'] = 'false';
  204. $scorm_css_header = true;
  205. $lp_theme_css = $_SESSION['oLP']->get_theme(); // Sets the css theme of the LP this call is also use at the frames (toc, nav, message).
  206. if ($_SESSION['oLP']->mode == 'fullscreen') {
  207. $htmlHeadXtra[] = "<script>window.open('$src','content_id','toolbar=0,location=0,status=0,scrollbars=1,resizable=1');</script>";
  208. }
  209. // Not in fullscreen mode.
  210. //require_once '../inc/reduced_header.inc.php';
  211. Display::display_reduced_header($nameTools);
  212. //$displayAudioRecorder = (api_get_setting('service_visio', 'active') == 'true') ? true : false;
  213. // Check if audio recorder needs to be in studentview.
  214. //$course_id = $_SESSION['_course']['id'];
  215. if ($_SESSION['status'][$course_code] == 5) {
  216. $audio_recorder_studentview = true;
  217. } else {
  218. $audio_recorder_studentview = false;
  219. }
  220. // Set flag to ensure lp_header.php is loaded by this script (flag is unset in lp_header.php).
  221. $_SESSION['loaded_lp_view'] = true;
  222. $display_none = '';
  223. $margin_left = '290px';
  224. if ($_SESSION['oLP']->mode == 'embedframe' ||$_SESSION['oLP']->get_hide_toc_frame()==1 ) {
  225. $display_none = ';display:none;';
  226. $margin_left = '12px';
  227. }
  228. //Media player code
  229. $display_mode = $_SESSION['oLP']->mode;
  230. $scorm_css_header = true;
  231. $lp_theme_css = $_SESSION['oLP']->get_theme();
  232. // Setting up the CSS theme if exists.
  233. if (!empty ($lp_theme_css) && !empty ($mycourselptheme) && $mycourselptheme != -1 && $mycourselptheme == 1) {
  234. global $lp_theme_css;
  235. } else {
  236. $lp_theme_css = $my_style;
  237. }
  238. $progress_bar = $_SESSION['oLP']->get_progress_bar('', -1, '', true);
  239. $navigation_bar = $_SESSION['oLP']->get_navigation_bar();
  240. $mediaplayer = $_SESSION['oLP']->get_mediaplayer($autostart);
  241. $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
  242. $show_audioplayer = false;
  243. // Getting all the information about the item.
  244. $sql = "SELECT audio FROM " . $tbl_lp_item . " WHERE c_id = $course_id AND lp_id = '" . $_SESSION['oLP']->lp_id."'";
  245. $res_media= Database::query($sql);
  246. if (Database::num_rows($res_media) > 0) {
  247. while ($row_media= Database::fetch_array($res_media)) {
  248. if (!empty($row_media['audio'])) {$show_audioplayer = true; break;}
  249. }
  250. }
  251. ?>
  252. <div id="learning_path_left_zone" style="float:left;width:280px;height:100%<?php echo $display_none;?>">
  253. <!-- header -->
  254. <div id="header">
  255. <div id="learning_path_header" style="font-size:14px;">
  256. <table>
  257. <tr>
  258. <td>
  259. <a href="lp_controller.php?action=return_to_course_homepage&<?php echo api_get_cidreq(); ?>" target="_self" onclick="javascript: window.parent.API.save_asset();">
  260. <img src="../img/lp_arrow.gif" />
  261. </a>
  262. </td>
  263. <td>
  264. <a class="link" href="lp_controller.php?action=return_to_course_homepage&<?php echo api_get_cidreq(); ?>" target="_self" onclick="javascript: window.parent.API.save_asset();">
  265. <?php echo get_lang('CourseHomepageLink'); ?></a>
  266. </td>
  267. </tr>
  268. </table>
  269. </div>
  270. </div>
  271. <!-- end header -->
  272. <!-- Image preview Layout -->
  273. <!-- hub 26-50-2010 for lp toc height
  274. <div id="author_image" name="author_image" class="lp_author_image" style="height:23%; width:100%;margin-left:5px;">
  275. -->
  276. <div id="author_image" name="author_image" class="row-fluid">
  277. <div class="span12">
  278. <div class="row-fluid well2">
  279. <div class="span4">
  280. <?php
  281. if ($_SESSION['oLP']->get_preview_image()!='') {
  282. $picture = getimagesize(api_get_path(SYS_COURSE_PATH).api_get_course_path().'/upload/learning_path/images/'.$_SESSION['oLP']->get_preview_image());
  283. if($picture['1'] < 96) { $style = ' style="padding-top:'.((94 -$picture['1'])/2).'px;" '; }
  284. $size = ($picture['0'] > 104 && $picture['1'] > 96 )? ' width="104" height="96" ': $style;
  285. $my_path = api_get_path(WEB_COURSE_PATH).api_get_course_path().'/upload/learning_path/images/'.$_SESSION['oLP']->get_preview_image();
  286. echo '<img src="'.$my_path.'">';
  287. } else {
  288. echo Display :: display_icon('unknown_250_100.jpg');
  289. }
  290. ?>
  291. </div>
  292. <div id="lp_navigation_elem" class="span8">
  293. <div class="row">
  294. <div class="span8">
  295. <?php echo $navigation_bar; ?>
  296. <div id="progress_bar">
  297. <?php echo $progress_bar; ?>
  298. </div>
  299. </div>
  300. </div>
  301. </div>
  302. </div>
  303. </div>
  304. </div>
  305. <!-- end image preview Layout -->
  306. <div id="author_name" style="position:relative;top:2px;left:0px;margin:0;padding:0;text-align:center;width:100%">
  307. <?php echo $_SESSION['oLP']->get_author(); ?>
  308. </div>
  309. <!-- media player layaout -->
  310. <?php $style_media = (($show_audioplayer) ? ' style= "position:relative;top:10px;left:10px;margin:8px;font-size:32pt;height:20px;"' : 'style="height:15px"'); ?>
  311. <div id="media" <?php echo $style_media; ?>>
  312. <?php echo (!empty($mediaplayer)) ? $mediaplayer : '&nbsp;' ?>
  313. </div>
  314. <!-- end media player layout -->
  315. <!-- TOC layout -->
  316. <!-- hub 26-05-2010 remove height for lp toc height resizable
  317. <div id="toc_id" name="toc_name" style="overflow: auto; padding:0;margin-top:20px;height:60%;width:100%">
  318. -->
  319. <div id="toc_id" name="toc_name" style="overflow: auto; padding:0;margin-top:20px;width:100%">
  320. <div id="learning_path_toc" style="font-size:9pt;margin:0;">
  321. <?php echo $_SESSION['oLP']->get_html_toc(); ?>
  322. <?php if (!empty($_SESSION['oLP']->scorm_debug)) { //only show log ?>
  323. <!-- log message layout -->
  324. <div id="lp_log_name" name="lp_log_name" class="lp_log" style="height:150px;overflow:auto;margin:4px">
  325. <div id="log_content"></div>
  326. <div id="log_content_cleaner" style="color: white;">.</div>
  327. </div>
  328. <!-- end log message layout -->
  329. <?php } ?>
  330. </div>
  331. </div>
  332. <!-- end TOC layout -->
  333. </div>
  334. <!-- end left Zone -->
  335. <!-- right Zone -->
  336. <div id="learning_path_right_zone" style="margin-left:<?php echo $margin_left;?>;height:100%">
  337. <?php
  338. // hub 26-05-2010 Fullscreen or not fullscreen
  339. if ($_SESSION['oLP']->mode == 'fullscreen') {
  340. echo '<iframe id="content_id_blank" name="content_name_blank" src="blank.php" border="0" frameborder="0" style="width:100%;height:600px" ></iframe>';
  341. } else {
  342. echo '<iframe id="content_id" name="content_name" src="'.$src.'" border="0" frameborder="0" style="width:100%;height:600px"></iframe>';
  343. }
  344. ?>
  345. </div>
  346. <!-- end right Zone -->
  347. </div>
  348. <script language="javascript" type="text/javascript">
  349. // Resize right and left pane to full height (HUB 20-05-2010).
  350. function updateContentHeight() {
  351. document.body.style.overflow = 'hidden';
  352. var IE = window.navigator.appName.match(/microsoft/i);
  353. var hauteurHeader = document.getElementById('header').offsetHeight;
  354. var hauteurAuthorImg = document.getElementById('author_image').offsetHeight;
  355. var hauteurAuthorName = document.getElementById('author_name').offsetHeight;
  356. var hauteurMedia = document.getElementById('media').offsetHeight;
  357. var hauteurTitre = document.getElementById('scorm_title').offsetHeight;
  358. var hauteurAction = 0;
  359. if (document.getElementById('actions_lp')) hauteurAction = document.getElementById('actions_lp').offsetHeight;
  360. var hauteurHaut = hauteurHeader+hauteurAuthorImg+hauteurAuthorName+hauteurMedia+hauteurTitre+hauteurAction;
  361. var innerHauteur = (IE) ? document.body.clientHeight : window.innerHeight ;
  362. var debugsize = 0;
  363. // -40 is a static adjustement for margin, spaces on the page
  364. <?php if (!empty($_SESSION['oLP']->scorm_debug)) echo 'debugsize = 150;' ?>
  365. document.getElementById('inner_lp_toc').style.height = innerHauteur - hauteurHaut - 40 - debugsize + "px";
  366. if (document.getElementById('content_id')) {
  367. document.getElementById('content_id').style.height = innerHauteur + 'px';
  368. }
  369. // Loads the glossary library.
  370. <?php
  371. if (api_get_setting('show_glossary_in_extra_tools') == 'true') {
  372. if (api_get_setting('show_glossary_in_documents') == 'ismanual') {
  373. ?>
  374. $.frameReady(function(){
  375. // $("<div>I am a div courses</div>").prependTo("body");
  376. }, "top.content_name",
  377. { load: [
  378. {type:"script", id:"_fr1", src:"<?php echo api_get_path(WEB_LIBRARY_PATH); ?>javascript/jquery.min.js"},
  379. {type:"script", id:"_fr2", src:"<?php echo api_get_path(WEB_LIBRARY_PATH); ?>javascript/jquery.highlight.js"},
  380. {type:"script", id:"_fr3", src:"<?php echo api_get_path(WEB_LIBRARY_PATH); ?>fckeditor/editor/plugins/glossary/fck_glossary_manual.js"}
  381. ] }
  382. );
  383. <?php
  384. } elseif (api_get_setting('show_glossary_in_documents') == 'isautomatic') {
  385. ?>
  386. $.frameReady(function(){
  387. // $("<div>I am a div courses</div>").prependTo("body");
  388. }, "top.content_name",
  389. { load: [
  390. {type:"script", id:"_fr1", src:"<?php echo api_get_path(WEB_LIBRARY_PATH); ?>javascript/jquery.min.js"},
  391. {type:"script", id:"_fr2", src:"<?php echo api_get_path(WEB_LIBRARY_PATH); ?>javascript/jquery.highlight.js"},
  392. {type:"script", id:"_fr3", src:"<?php echo api_get_path(WEB_LIBRARY_PATH); ?>fckeditor/editor/plugins/glossary/fck_glossary_automatic.js"}
  393. ] }
  394. );
  395. <?php
  396. }
  397. }
  398. ?>
  399. }
  400. window.onload = updateContentHeight;
  401. window.onresize = updateContentHeight;
  402. -->
  403. </script>
  404. <?php
  405. // Restore a global setting.
  406. $_setting['show_navigation_menu'] = $save_setting;