lp_view.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  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. */
  14. use \ChamiloSession as Session;
  15. $use_anonymous = true;
  16. $_SESSION['whereami'] = 'lp/view';
  17. $this_section = SECTION_COURSES;
  18. if ($lp_controller_touched != 1) {
  19. header('location: lp_controller.php?action=view&item_id=' . intval($_REQUEST['item_id']));
  20. exit;
  21. }
  22. require_once '../inc/global.inc.php';
  23. //To prevent the template class
  24. $show_learnpath = true;
  25. api_protect_course_script();
  26. $lp_id = intval($_GET['lp_id']);
  27. $sessionId = api_get_session_id();
  28. // Check if the learning path is visible for student - (LP requisites)
  29. if (!api_is_platform_admin()) {
  30. if (
  31. !api_is_allowed_to_edit(null, true) &&
  32. !learnpath::is_lp_visible_for_student($lp_id, api_get_user_id())
  33. ) {
  34. api_not_allowed(true);
  35. }
  36. }
  37. // Checking visibility (eye icon)
  38. $visibility = api_get_item_visibility(
  39. api_get_course_info(),
  40. TOOL_LEARNPATH,
  41. $lp_id,
  42. $action,
  43. api_get_user_id(),
  44. $sessionId
  45. );
  46. if (!api_is_allowed_to_edit(false, true, false, false) && intval($visibility) == 0) {
  47. api_not_allowed(true);
  48. }
  49. if (empty($_SESSION['oLP'])) {
  50. api_not_allowed(true);
  51. }
  52. $debug = 0;
  53. if ($debug) {
  54. error_log('------ Entering lp_view.php -------');
  55. }
  56. $_SESSION['oLP']->error = '';
  57. $lp_item_id = $_SESSION['oLP']->get_current_item_id();
  58. $lp_type = $_SESSION['oLP']->get_type();
  59. $course_code = api_get_course_id();
  60. $course_id = api_get_course_int_id();
  61. $user_id = api_get_user_id();
  62. $platform_theme = api_get_setting('stylesheets'); // Platform's css.
  63. $my_style = $platform_theme;
  64. $htmlHeadXtra[] = '<script src="' . api_get_path(WEB_LIBRARY_PATH) .
  65. 'javascript/jquery.lp_minipanel.js" type="text/javascript" language="javascript"></script>';
  66. $htmlHeadXtra[] = '<script>
  67. $(document).ready(function() {
  68. $("div#log_content_cleaner").bind("click", function() {
  69. $("div#log_content").empty();
  70. });
  71. });
  72. var chamilo_xajax_handler = window.oxajax;
  73. </script>';
  74. if ($_SESSION['oLP']->mode == 'embedframe' || $_SESSION['oLP']->get_hide_toc_frame() == 1) {
  75. $htmlHeadXtra[] = 'hello';
  76. }
  77. //Impress js
  78. if ($_SESSION['oLP']->mode == 'impress') {
  79. $lp_id = $_SESSION['oLP']->get_id();
  80. $url = api_get_path(WEB_CODE_PATH) . "newscorm/lp_impress.php?lp_id=$lp_id&" . api_get_cidreq();
  81. header("Location: $url");
  82. exit;
  83. }
  84. // Prepare variables for the test tool (just in case) - honestly, this should disappear later on.
  85. $_SESSION['scorm_view_id'] = $_SESSION['oLP']->get_view_id();
  86. $_SESSION['scorm_item_id'] = $lp_item_id;
  87. // Reinit exercises variables to avoid spacename clashes (see exercise tool)
  88. if (isset($exerciseResult) || isset($_SESSION['exerciseResult'])) {
  89. Session::erase('exerciseResult');
  90. Session::erase('objExercise');
  91. Session::erase('questionList');
  92. }
  93. // additional APIs
  94. $htmlHeadXtra[] = '<script>
  95. chamilo_courseCode = "' . $course_code . '";
  96. </script>';
  97. // Document API
  98. $htmlHeadXtra[] = '<script src="js/documentapi.js" type="text/javascript" language="javascript"></script>';
  99. // Storage API
  100. $htmlHeadXtra[] = '<script>
  101. var sv_user = \'' . api_get_user_id() . '\';
  102. var sv_course = chamilo_courseCode;
  103. var sv_sco = \'' . intval($_REQUEST['lp_id']) . '\';
  104. </script>'; // FIXME fetch sco and userid from a more reliable source directly in sotrageapi.js
  105. $htmlHeadXtra[] = '<script type="text/javascript" src="js/storageapi.js"></script>';
  106. /**
  107. * Get a link to the corresponding document.
  108. */
  109. if ($debug) {
  110. error_log(" src: $src ");
  111. error_log(" lp_type: $lp_type ");
  112. }
  113. $get_toc_list = $_SESSION['oLP']->get_toc();
  114. $type_quiz = false;
  115. foreach ($get_toc_list as $toc) {
  116. if ($toc['id'] == $lp_item_id && $toc['type'] == 'quiz') {
  117. $type_quiz = true;
  118. }
  119. }
  120. if (!isset($src)) {
  121. $src = null;
  122. switch ($lp_type) {
  123. case 1:
  124. $_SESSION['oLP']->stop_previous_item();
  125. $htmlHeadXtra[] = '<script src="scorm_api.php" type="text/javascript" language="javascript"></script>';
  126. $prereq_check = $_SESSION['oLP']->prerequisites_match($lp_item_id);
  127. if ($prereq_check === true) {
  128. $src = $_SESSION['oLP']->get_link('http', $lp_item_id, $get_toc_list);
  129. // Prevents FF 3.6 + Adobe Reader 9 bug see BT#794 when calling a pdf file in a LP.
  130. $file_info = parse_url($src);
  131. $file_info = pathinfo($file_info['path']);
  132. if (
  133. isset($file_info['extension']) &&
  134. api_strtolower(substr($file_info['extension'], 0, 3) == 'pdf')
  135. ) {
  136. $src = api_get_path(WEB_CODE_PATH)
  137. . 'newscorm/lp_view_item.php?lp_item_id=' . $lp_item_id
  138. . '&' . api_get_cidreq();
  139. }
  140. $_SESSION['oLP']->start_current_item(); // starts time counter manually if asset
  141. } else {
  142. $src = 'blank.php?error=prerequisites';
  143. }
  144. break;
  145. case 2:
  146. // save old if asset
  147. $_SESSION['oLP']->stop_previous_item(); // save status manually if asset
  148. $htmlHeadXtra[] = '<script src="scorm_api.php" type="text/javascript" language="javascript"></script>';
  149. $prereq_check = $_SESSION['oLP']->prerequisites_match($lp_item_id);
  150. if ($prereq_check === true) {
  151. $src = $_SESSION['oLP']->get_link('http', $lp_item_id, $get_toc_list);
  152. $_SESSION['oLP']->start_current_item(); // starts time counter manually if asset
  153. } else {
  154. $src = 'blank.php?error=prerequisites';
  155. }
  156. break;
  157. case 3:
  158. // aicc
  159. $_SESSION['oLP']->stop_previous_item(); // save status manually if asset
  160. $htmlHeadXtra[] = '<script src="' . $_SESSION['oLP']->get_js_lib()
  161. . '" type="text/javascript" language="javascript"></script>';
  162. $prereq_check = $_SESSION['oLP']->prerequisites_match($lp_item_id);
  163. if ($prereq_check === true) {
  164. $src = $_SESSION['oLP']->get_link('http', $lp_item_id, $get_toc_list);
  165. $_SESSION['oLP']->start_current_item(); // starts time counter manually if asset
  166. } else {
  167. $src = 'blank.php';
  168. }
  169. break;
  170. case 4:
  171. break;
  172. }
  173. }
  174. $autostart = 'true';
  175. // Update status, total_time from lp_item_view table when you finish the exercises in learning path.
  176. if ($debug) {
  177. error_log('$type_quiz: ' . $type_quiz);
  178. error_log('$_REQUEST[exeId]: ' . intval($_REQUEST['exeId']));
  179. error_log('$lp_id: ' . $lp_id);
  180. error_log('$_GET[lp_item_id]: ' . intval($_GET['lp_item_id']));
  181. }
  182. if (
  183. !empty($_REQUEST['exeId']) &&
  184. isset($lp_id) &&
  185. isset($_GET['lp_item_id'])
  186. ) {
  187. global $src;
  188. $_SESSION['oLP']->items[$_SESSION['oLP']->current]->write_to_db();
  189. $TBL_TRACK_EXERCICES = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES);
  190. $TBL_LP_ITEM_VIEW = Database::get_course_table(TABLE_LP_ITEM_VIEW);
  191. $TBL_LP_ITEM = Database::get_course_table(TABLE_LP_ITEM);
  192. $safe_item_id = intval($_GET['lp_item_id']);
  193. $safe_id = $lp_id;
  194. $safe_exe_id = intval($_REQUEST['exeId']);
  195. if (
  196. $safe_id == strval(intval($safe_id)) &&
  197. $safe_item_id == strval(intval($safe_item_id))
  198. ) {
  199. $sql = 'SELECT start_date, exe_date, exe_result, exe_weighting
  200. FROM ' . $TBL_TRACK_EXERCICES . '
  201. WHERE exe_id = ' . $safe_exe_id;
  202. $res = Database::query($sql);
  203. $row_dates = Database::fetch_array($res);
  204. $time_start_date = api_strtotime($row_dates['start_date'], 'UTC');
  205. $time_exe_date = api_strtotime($row_dates['exe_date'], 'UTC');
  206. $mytime = ((int) $time_exe_date - (int) $time_start_date);
  207. $score = (float) $row_dates['exe_result'];
  208. $max_score = (float) $row_dates['exe_weighting'];
  209. $sql = "UPDATE $TBL_LP_ITEM SET
  210. max_score = '$max_score'
  211. WHERE c_id = $course_id AND id = '" . $safe_item_id . "'";
  212. Database::query($sql);
  213. $sql = "SELECT id FROM $TBL_LP_ITEM_VIEW
  214. WHERE
  215. c_id = $course_id AND
  216. lp_item_id = '$safe_item_id' AND
  217. lp_view_id = '" . $_SESSION['oLP']->lp_view_id . "'
  218. ORDER BY id DESC
  219. LIMIT 1";
  220. $res_last_attempt = Database::query($sql);
  221. if (Database::num_rows($res_last_attempt) && !api_is_invitee()) {
  222. $row_last_attempt = Database::fetch_row($res_last_attempt);
  223. $lp_item_view_id = $row_last_attempt[0];
  224. $sql = "UPDATE $TBL_LP_ITEM_VIEW SET
  225. status = 'completed' ,
  226. score = $score,
  227. total_time = $mytime
  228. WHERE id='" . $lp_item_view_id . "' AND c_id = $course_id ";
  229. if ($debug) {
  230. error_log($sql);
  231. }
  232. Database::query($sql);
  233. $sql = "UPDATE $TBL_TRACK_EXERCICES SET
  234. orig_lp_item_view_id = $lp_item_view_id
  235. WHERE exe_id = " . $safe_exe_id;
  236. Database::query($sql);
  237. }
  238. }
  239. if (intval($_GET['fb_type']) > 0) {
  240. $src = 'blank.php?msg=exerciseFinished';
  241. } else {
  242. $src = api_get_path(WEB_CODE_PATH) . 'exercice/result.php?origin=learnpath&id=' . $safe_exe_id;
  243. if ($debug) {
  244. error_log('Calling URL: ' . $src);
  245. }
  246. }
  247. $autostart = 'false';
  248. }
  249. $_SESSION['oLP']->set_previous_item($lp_item_id);
  250. $nameTools = Security::remove_XSS($_SESSION['oLP']->get_name());
  251. $save_setting = api_get_setting('show_navigation_menu');
  252. global $_setting;
  253. $_setting['show_navigation_menu'] = 'false';
  254. $scorm_css_header = true;
  255. $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).
  256. if ($_SESSION['oLP']->mode == 'fullscreen') {
  257. $htmlHeadXtra[] = "<script>window.open('$src','content_id','toolbar=0,location=0,status=0,scrollbars=1,resizable=1');</script>";
  258. }
  259. // Not in fullscreen mode.
  260. // Check if audio recorder needs to be in studentview.
  261. if (isset($_SESSION['status']) && $_SESSION['status'][$course_code] == 5) {
  262. $audio_recorder_studentview = true;
  263. } else {
  264. $audio_recorder_studentview = false;
  265. }
  266. // Set flag to ensure lp_header.php is loaded by this script (flag is unset in lp_header.php).
  267. $_SESSION['loaded_lp_view'] = true;
  268. $display_none = '';
  269. $margin_left = '340px';
  270. //Media player code
  271. $display_mode = $_SESSION['oLP']->mode;
  272. $scorm_css_header = true;
  273. $lp_theme_css = $_SESSION['oLP']->get_theme();
  274. // Setting up the CSS theme if exists.
  275. if (!empty($lp_theme_css) && !empty($mycourselptheme) && $mycourselptheme != -1 && $mycourselptheme == 1) {
  276. global $lp_theme_css;
  277. } else {
  278. $lp_theme_css = $my_style;
  279. }
  280. $progress_bar = "";
  281. if (!api_is_invitee()) {
  282. $progress_bar = $_SESSION['oLP']->getProgressBar();
  283. }
  284. $navigation_bar = $_SESSION['oLP']->get_navigation_bar();
  285. $navigation_bar_bottom = $_SESSION['oLP']->get_navigation_bar("control-bottom", "display:none");
  286. $mediaplayer = $_SESSION['oLP']->get_mediaplayer($autostart);
  287. $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
  288. $show_audioplayer = false;
  289. // Getting all the information about the item.
  290. $sql = "SELECT audio FROM " . $tbl_lp_item . "
  291. WHERE c_id = $course_id AND lp_id = '" . $_SESSION['oLP']->lp_id . "'";
  292. $res_media = Database::query($sql);
  293. if (Database::num_rows($res_media) > 0) {
  294. while ($row_media = Database::fetch_array($res_media)) {
  295. if (!empty($row_media['audio'])) {
  296. $show_audioplayer = true;
  297. break;
  298. }
  299. }
  300. }
  301. $is_allowed_to_edit = api_is_allowed_to_edit(false, true, true, false);
  302. $breadcrumb = null;
  303. if ($is_allowed_to_edit) {
  304. global $interbreadcrumb;
  305. $interbreadcrumb[] = array(
  306. 'url' => 'lp_controller.php?action=list&isStudentView=false',
  307. 'name' => get_lang('LearningPaths')
  308. );
  309. $interbreadcrumb[] = array(
  310. 'url' => api_get_self() . "?action=add_item&type=step&lp_id={$_SESSION['oLP']->lp_id}&isStudentView=false",
  311. 'name' => $_SESSION['oLP']->get_name()
  312. );
  313. $interbreadcrumb[] = array(
  314. 'url' => '#',
  315. 'name' => get_lang('Preview')
  316. );
  317. $breadcrumb = return_breadcrumb($interbreadcrumb, null, null);
  318. }
  319. // Return to course home.
  320. if ($is_allowed_to_edit) {
  321. $buttonHomeUrl = 'lp_controller.php?' . api_get_cidreq() . '&' . http_build_query([
  322. 'isStudentView' => 'false',
  323. 'action' => 'return_to_course_homepage'
  324. ]);
  325. } else {
  326. $buttonHomeUrl = 'lp_controller.php?' . api_get_cidreq() . '&' . http_build_query([
  327. 'action' => 'return_to_course_homepage'
  328. ]);
  329. }
  330. $buttonHomeText = get_lang('CourseHomepageLink');
  331. // Return to lp list
  332. if (api_get_course_setting('lp_return_link') == 1) {
  333. $buttonHomeUrl .= '&redirectTo=lp_list';
  334. $buttonHomeText = get_lang('LearningPathList');
  335. }
  336. $lpPreviewImagePath = 'unknown.png';
  337. if ($_SESSION['oLP']->get_preview_image()) {
  338. $lpPreviewImagePath = $_SESSION['oLP']->get_preview_image_path();
  339. }
  340. $gamificationMode = api_get_setting('gamification_mode');
  341. $template = new Template('title', false, false, true, true, false);
  342. $template->assign('glossary_extra_tools', api_get_setting('show_glossary_in_extra_tools'));
  343. $template->assign(
  344. 'glossary_tool_availables',
  345. ['true', 'lp', 'exercise_and_lp']
  346. );
  347. $template->assign('show_glossary_in_documents', api_get_setting('show_glossary_in_documents'));
  348. $template->assign('jquery_web_path', api_get_jquery_web_path());
  349. $template->assign('jquery_ui_js_web_path', api_get_jquery_ui_js_web_path());
  350. $template->assign('jquery_ui_css_web_path', api_get_jquery_ui_css_web_path());
  351. $template->assign('is_allowed_to_edit', $is_allowed_to_edit);
  352. $template->assign('gamification_mode', $gamificationMode);
  353. $template->assign('breadcrumb', $breadcrumb);
  354. $template->assign('button_home_url', $buttonHomeUrl);
  355. $template->assign('button_home_text', $buttonHomeText);
  356. $template->assign('navigation_bar', $navigation_bar);
  357. $template->assign('progress_bar', $progress_bar);
  358. $template->assign('show_audio_player', $show_audioplayer);
  359. $template->assign('media_player', $mediaplayer);
  360. $template->assign('toc_list', $get_toc_list);
  361. $template->assign('iframe_src', $src);
  362. $template->assign('navigation_bar_bottom', $navigation_bar_bottom);
  363. if ($gamificationMode == 1) {
  364. $template->assign(
  365. 'gamification_stars',
  366. $_SESSION['oLP']->getCalculateStars($sessionId)
  367. );
  368. $template->assign(
  369. 'gamification_points',
  370. $_SESSION['oLP']->getCalculateScore($sessionId)
  371. );
  372. }
  373. $template->assign(
  374. 'lp_preview_image',
  375. Display::img(
  376. $lpPreviewImagePath,
  377. $_SESSION['oLP']->name,
  378. array('class' => 'img-circle'),
  379. ICON_SIZE_BIG
  380. )
  381. );
  382. $template->assign('lp_author', $_SESSION['oLP']->get_author());
  383. $template->assign('lp_mode', $_SESSION['oLP']->mode);
  384. $template->assign('lp_title_scorm',$_SESSION['oLP']->name);
  385. $template->assign(
  386. 'lp_html_toc',
  387. $_SESSION['oLP']->get_html_toc($get_toc_list)
  388. );
  389. $template->assign('lp_id', $_SESSION['oLP']->lp_id);
  390. $template->assign('lp_current_item_id', $_SESSION['oLP']->get_current_item_id());
  391. $content = $template->fetch('default/learnpath/view.tpl');
  392. $template->assign('content', $content);
  393. $template->display_no_layout_template();
  394. // Restore a global setting.
  395. $_setting['show_navigation_menu'] = $save_setting;
  396. if ($debug) {
  397. error_log(' ------- end lp_view.php ------');
  398. }