lp_view.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540
  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 = !empty($_GET['lp_id']) ? intval($_GET['lp_id']) : 0;
  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, false, false) &&
  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. $lpType = $_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 type="text/javascript">
  65. <!--
  66. var jQueryFrameReadyConfigPath = \''.api_get_jquery_web_path().'\';
  67. -->
  68. </script>';
  69. $htmlHeadXtra[] = '<script type="text/javascript" src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.frameready.js"></script>';
  70. $htmlHeadXtra[] = '<script>
  71. $(document).ready(function() {
  72. $("div#log_content_cleaner").bind("click", function() {
  73. $("div#log_content").empty();
  74. });
  75. });
  76. var chamilo_xajax_handler = window.oxajax;
  77. </script>';
  78. if ($_SESSION['oLP']->mode == 'embedframe' || $_SESSION['oLP']->get_hide_toc_frame() == 1) {
  79. $htmlHeadXtra[] = '';
  80. }
  81. //Impress js
  82. if ($_SESSION['oLP']->mode == 'impress') {
  83. $lp_id = $_SESSION['oLP']->get_id();
  84. $url = api_get_path(WEB_CODE_PATH) . "newscorm/lp_impress.php?lp_id=$lp_id&" . api_get_cidreq();
  85. header("Location: $url");
  86. exit;
  87. }
  88. // Prepare variables for the test tool (just in case) - honestly, this should disappear later on.
  89. $_SESSION['scorm_view_id'] = $_SESSION['oLP']->get_view_id();
  90. $_SESSION['scorm_item_id'] = $lp_item_id;
  91. // Reinit exercises variables to avoid spacename clashes (see exercise tool)
  92. if (isset($exerciseResult) || isset($_SESSION['exerciseResult'])) {
  93. Session::erase('exerciseResult');
  94. Session::erase('objExercise');
  95. Session::erase('questionList');
  96. }
  97. // additional APIs
  98. $htmlHeadXtra[] = '<script>
  99. chamilo_courseCode = "' . $course_code . '";
  100. </script>';
  101. // Document API
  102. $htmlHeadXtra[] = '<script src="js/documentapi.js" type="text/javascript" language="javascript"></script>';
  103. // Storage API
  104. $htmlHeadXtra[] = '<script>
  105. var sv_user = \'' . api_get_user_id() . '\';
  106. var sv_course = chamilo_courseCode;
  107. var sv_sco = \'' . $lp_id . '\';
  108. </script>'; // FIXME fetch sco and userid from a more reliable source directly in sotrageapi.js
  109. $htmlHeadXtra[] = '<script type="text/javascript" src="js/storageapi.js"></script>';
  110. /**
  111. * Get a link to the corresponding document.
  112. */
  113. if ($debug) {
  114. error_log(" src: $src ");
  115. error_log(" lp_type: $lpType ");
  116. }
  117. $get_toc_list = $_SESSION['oLP']->get_toc();
  118. $get_teacher_buttons = $_SESSION['oLP']->get_teacher_toc_buttons();
  119. $type_quiz = false;
  120. foreach ($get_toc_list as $toc) {
  121. if ($toc['id'] == $lp_item_id && $toc['type'] == 'quiz') {
  122. $type_quiz = true;
  123. }
  124. }
  125. if (!isset($src)) {
  126. $src = null;
  127. switch ($lpType) {
  128. case 1:
  129. $_SESSION['oLP']->stop_previous_item();
  130. $htmlHeadXtra[] = '<script src="scorm_api.php" type="text/javascript" language="javascript"></script>';
  131. $preReqCheck = $_SESSION['oLP']->prerequisites_match($lp_item_id);
  132. if ($preReqCheck === true) {
  133. $src = $_SESSION['oLP']->get_link(
  134. 'http',
  135. $lp_item_id,
  136. $get_toc_list
  137. );
  138. // Prevents FF 3.6 + Adobe Reader 9 bug see BT#794 when calling a pdf file in a LP.
  139. $file_info = parse_url($src);
  140. if (isset($file_info['path'])) {
  141. $file_info = pathinfo($file_info['path']);
  142. }
  143. if (
  144. isset($file_info['extension']) &&
  145. api_strtolower(substr($file_info['extension'], 0, 3) == 'pdf')
  146. ) {
  147. $src = api_get_path(WEB_CODE_PATH).'newscorm/lp_view_item.php?lp_item_id='.$lp_item_id.'&'.api_get_cidreq();
  148. }
  149. $src = $_SESSION['oLP']->fixBlockedLinks($src);
  150. $_SESSION['oLP']->start_current_item(); // starts time counter manually if asset
  151. } else {
  152. $src = 'blank.php?error=prerequisites';
  153. }
  154. break;
  155. case 2:
  156. // save old if asset
  157. $_SESSION['oLP']->stop_previous_item(); // save status manually if asset
  158. $htmlHeadXtra[] = '<script src="scorm_api.php" type="text/javascript" language="javascript"></script>';
  159. $preReqCheck = $_SESSION['oLP']->prerequisites_match($lp_item_id);
  160. if ($preReqCheck === true) {
  161. $src = $_SESSION['oLP']->get_link('http', $lp_item_id, $get_toc_list);
  162. $_SESSION['oLP']->start_current_item(); // starts time counter manually if asset
  163. } else {
  164. $src = 'blank.php?error=prerequisites';
  165. }
  166. break;
  167. case 3:
  168. // aicc
  169. $_SESSION['oLP']->stop_previous_item(); // save status manually if asset
  170. $htmlHeadXtra[] = '<script src="' . $_SESSION['oLP']->get_js_lib().'" type="text/javascript" language="javascript"></script>';
  171. $preReqCheck = $_SESSION['oLP']->prerequisites_match($lp_item_id);
  172. if ($preReqCheck === true) {
  173. $src = $_SESSION['oLP']->get_link(
  174. 'http',
  175. $lp_item_id,
  176. $get_toc_list
  177. );
  178. $_SESSION['oLP']->start_current_item(); // starts time counter manually if asset
  179. } else {
  180. $src = 'blank.php';
  181. }
  182. break;
  183. case 4:
  184. break;
  185. }
  186. }
  187. $autostart = 'true';
  188. // Update status, total_time from lp_item_view table when you finish the exercises in learning path.
  189. if ($debug) {
  190. error_log('$type_quiz: ' . $type_quiz);
  191. error_log('$_REQUEST[exeId]: ' . intval($_REQUEST['exeId']));
  192. error_log('$lp_id: ' . $lp_id);
  193. error_log('$_GET[lp_item_id]: ' . intval($_GET['lp_item_id']));
  194. }
  195. if (
  196. !empty($_REQUEST['exeId']) &&
  197. isset($lp_id) &&
  198. isset($_GET['lp_item_id'])
  199. ) {
  200. global $src;
  201. $_SESSION['oLP']->items[$_SESSION['oLP']->current]->write_to_db();
  202. $TBL_TRACK_EXERCICES = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES);
  203. $TBL_LP_ITEM_VIEW = Database::get_course_table(TABLE_LP_ITEM_VIEW);
  204. $TBL_LP_ITEM = Database::get_course_table(TABLE_LP_ITEM);
  205. $safe_item_id = intval($_GET['lp_item_id']);
  206. $safe_id = $lp_id;
  207. $safe_exe_id = intval($_REQUEST['exeId']);
  208. if (
  209. $safe_id == strval(intval($safe_id)) &&
  210. $safe_item_id == strval(intval($safe_item_id))
  211. ) {
  212. $sql = 'SELECT start_date, exe_date, exe_result, exe_weighting, exe_exo_id
  213. FROM ' . $TBL_TRACK_EXERCICES . '
  214. WHERE exe_id = ' . $safe_exe_id;
  215. $res = Database::query($sql);
  216. $row_dates = Database::fetch_array($res);
  217. $time_start_date = api_strtotime($row_dates['start_date'], 'UTC');
  218. $time_exe_date = api_strtotime($row_dates['exe_date'], 'UTC');
  219. $mytime = (int) $time_exe_date - (int) $time_start_date;
  220. $score = (float) $row_dates['exe_result'];
  221. $max_score = (float) $row_dates['exe_weighting'];
  222. $sql = "UPDATE $TBL_LP_ITEM SET
  223. max_score = '$max_score'
  224. WHERE c_id = $course_id AND id = '" . $safe_item_id . "'";
  225. Database::query($sql);
  226. $sql = "SELECT id FROM $TBL_LP_ITEM_VIEW
  227. WHERE
  228. c_id = $course_id AND
  229. lp_item_id = '$safe_item_id' AND
  230. lp_view_id = '" . $_SESSION['oLP']->lp_view_id . "'
  231. ORDER BY id DESC
  232. LIMIT 1";
  233. $res_last_attempt = Database::query($sql);
  234. if (Database::num_rows($res_last_attempt) && !api_is_invitee()) {
  235. $row_last_attempt = Database::fetch_row($res_last_attempt);
  236. $lp_item_view_id = $row_last_attempt[0];
  237. $exercise = new Exercise(api_get_course_int_id());
  238. $exercise->read($row_dates['exe_exo_id']);
  239. $status = 'completed';
  240. if (!empty($exercise->pass_percentage)) {
  241. $status = 'failed';
  242. $success = ExerciseLib::is_success_exercise_result(
  243. $score,
  244. $max_score,
  245. $exercise->pass_percentage
  246. );
  247. if ($success) {
  248. $status = 'passed';
  249. }
  250. }
  251. $sql = "UPDATE $TBL_LP_ITEM_VIEW SET
  252. status = '$status',
  253. score = $score,
  254. total_time = $mytime
  255. WHERE id='" . $lp_item_view_id . "' AND c_id = $course_id ";
  256. if ($debug) {
  257. error_log($sql);
  258. }
  259. Database::query($sql);
  260. $sql = "UPDATE $TBL_TRACK_EXERCICES SET
  261. orig_lp_item_view_id = $lp_item_view_id
  262. WHERE exe_id = " . $safe_exe_id;
  263. Database::query($sql);
  264. }
  265. }
  266. if (intval($_GET['fb_type']) > 0) {
  267. $src = 'blank.php?msg=exerciseFinished';
  268. } else {
  269. $src = api_get_path(WEB_CODE_PATH) . 'exercice/result.php?origin=learnpath&id=' . $safe_exe_id.'&'.api_get_cidreq();
  270. if ($debug) {
  271. error_log('Calling URL: ' . $src);
  272. }
  273. }
  274. $autostart = 'false';
  275. }
  276. $_SESSION['oLP']->set_previous_item($lp_item_id);
  277. $nameTools = Security::remove_XSS($_SESSION['oLP']->get_name());
  278. $save_setting = api_get_setting('show_navigation_menu');
  279. global $_setting;
  280. $_setting['show_navigation_menu'] = 'false';
  281. $scorm_css_header = true;
  282. $lp_theme_css = $_SESSION['oLP']->get_theme();
  283. // Sets the css theme of the LP this call is also use at the frames (toc, nav, message).
  284. if ($_SESSION['oLP']->mode == 'fullscreen') {
  285. $htmlHeadXtra[] = "<script>window.open('$src','content_id','toolbar=0,location=0,status=0,scrollbars=1,resizable=1');</script>";
  286. }
  287. // Not in fullscreen mode.
  288. // Check if audio recorder needs to be in studentview.
  289. if (isset($_SESSION['status']) && $_SESSION['status'][$course_code] == 5) {
  290. $audio_recorder_studentview = true;
  291. } else {
  292. $audio_recorder_studentview = false;
  293. }
  294. // Set flag to ensure lp_header.php is loaded by this script (flag is unset in lp_header.php).
  295. $_SESSION['loaded_lp_view'] = true;
  296. $display_none = '';
  297. $margin_left = '340px';
  298. //Media player code
  299. $display_mode = $_SESSION['oLP']->mode;
  300. $scorm_css_header = true;
  301. $lp_theme_css = $_SESSION['oLP']->get_theme();
  302. // Setting up the CSS theme if exists.
  303. if (!empty($lp_theme_css) && !empty($mycourselptheme) && $mycourselptheme != -1 && $mycourselptheme == 1) {
  304. global $lp_theme_css;
  305. } else {
  306. $lp_theme_css = $my_style;
  307. }
  308. $progress_bar = "";
  309. if (!api_is_invitee()) {
  310. $progress_bar = $_SESSION['oLP']->getProgressBar();
  311. }
  312. $navigation_bar = $_SESSION['oLP']->get_navigation_bar();
  313. $navigation_bar_bottom = $_SESSION['oLP']->get_navigation_bar("control-bottom", "display:none");
  314. $mediaplayer = $_SESSION['oLP']->get_mediaplayer($autostart);
  315. $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
  316. $show_audioplayer = false;
  317. // Getting all the information about the item.
  318. $sql = "SELECT audio FROM " . $tbl_lp_item . "
  319. WHERE c_id = $course_id AND lp_id = '" . $_SESSION['oLP']->lp_id . "'";
  320. $res_media = Database::query($sql);
  321. if (Database::num_rows($res_media) > 0) {
  322. while ($row_media = Database::fetch_array($res_media)) {
  323. if (!empty($row_media['audio'])) {
  324. $show_audioplayer = true;
  325. break;
  326. }
  327. }
  328. }
  329. $is_allowed_to_edit = api_is_allowed_to_edit(false, true, true, false);
  330. $breadcrumb = null;
  331. if ($is_allowed_to_edit) {
  332. global $interbreadcrumb;
  333. $interbreadcrumb[] = array(
  334. 'url' => 'lp_controller.php?action=list&isStudentView=false',
  335. 'name' => get_lang('LearningPaths')
  336. );
  337. $interbreadcrumb[] = array(
  338. 'url' => api_get_self() . "?action=add_item&type=step&lp_id={$_SESSION['oLP']->lp_id}&isStudentView=false",
  339. 'name' => $_SESSION['oLP']->get_name()
  340. );
  341. $interbreadcrumb[] = array(
  342. 'url' => '#',
  343. 'name' => get_lang('Preview')
  344. );
  345. $breadcrumb = return_breadcrumb($interbreadcrumb, null, null);
  346. }
  347. // Return to course home.
  348. if ($is_allowed_to_edit) {
  349. $buttonHomeUrl = 'lp_controller.php?' . api_get_cidreq() . '&' . http_build_query([
  350. 'isStudentView' => 'false',
  351. 'action' => 'return_to_course_homepage'
  352. ]);
  353. } else {
  354. $buttonHomeUrl = 'lp_controller.php?' . api_get_cidreq() . '&' . http_build_query([
  355. 'action' => 'return_to_course_homepage'
  356. ]);
  357. }
  358. $buttonHomeText = get_lang('CourseHomepageLink');
  359. // Return to lp list
  360. if (api_get_course_setting('lp_return_link') == 1) {
  361. $buttonHomeUrl .= '&redirectTo=lp_list';
  362. $buttonHomeText = get_lang('LearningPathList');
  363. }
  364. $lpPreviewImagePath = Display::returnIconPath('unknown.png', ICON_SIZE_BIG);
  365. if ($_SESSION['oLP']->get_preview_image()) {
  366. $lpPreviewImagePath = $_SESSION['oLP']->get_preview_image_path();
  367. }
  368. if ($_SESSION['oLP']->current == $_SESSION['oLP']->get_last()) {
  369. $categories = Category::load(null, null, $course_code, null, null, $sessionId);
  370. if (!empty($categories)) {
  371. $gradebookEvaluations = $categories[0]->get_evaluations();
  372. $gradebookLinks = $categories[0]->get_links();
  373. if (
  374. count($gradebookEvaluations) === 0 &&
  375. count($gradebookLinks) === 1 &&
  376. $gradebookLinks[0]->get_type() == LINK_LEARNPATH &&
  377. $gradebookLinks[0]->get_ref_id() == $_SESSION['oLP']->lp_id
  378. ) {
  379. $gradebookMinScore = $categories[0]->get_certificate_min_score();
  380. $userScore = $gradebookLinks[0]->calc_score($user_id, 'best');
  381. if ($userScore[0] >= $gradebookMinScore) {
  382. Category::register_user_certificate($categories[0]->get_id(), $user_id);
  383. }
  384. }
  385. }
  386. }
  387. $template = new Template('title', false, false, true, true, false);
  388. $template->assign('glossary_extra_tools', api_get_setting('show_glossary_in_extra_tools'));
  389. $fixLinkSetting = api_get_configuration_value('lp_fix_embed_content');
  390. $fixLink = '';
  391. if ($fixLinkSetting) {
  392. $fixLink = '{type:"script", id:"_fr10", src:"'.api_get_path(WEB_LIBRARY_PATH).'javascript/fixlinks.js"}';
  393. }
  394. $template->assign('fix_link', $fixLink);
  395. $template->assign(
  396. 'glossary_tool_availables',
  397. ['true', 'lp', 'exercise_and_lp']
  398. );
  399. // If the global gamification mode is enabled...
  400. $gamificationMode = api_get_setting('gamification_mode');
  401. // ...AND this learning path is set in gamification mode, then change the display
  402. $gamificationMode = $gamificationMode && $_SESSION['oLP']->seriousgame_mode;
  403. $template->assign('show_glossary_in_documents', api_get_setting('show_glossary_in_documents'));
  404. $template->assign('jquery_web_path', api_get_jquery_web_path());
  405. $template->assign('jquery_ui_js_web_path', api_get_jquery_ui_js_web_path());
  406. $template->assign('jquery_ui_css_web_path', api_get_jquery_ui_css_web_path());
  407. $template->assign('is_allowed_to_edit', $is_allowed_to_edit);
  408. $template->assign('gamification_mode', $gamificationMode);
  409. $template->assign('breadcrumb', $breadcrumb);
  410. $template->assign('button_home_url', $buttonHomeUrl);
  411. $template->assign('button_home_text', $buttonHomeText);
  412. $template->assign('navigation_bar', $navigation_bar);
  413. $template->assign('progress_bar', $progress_bar);
  414. $template->assign('show_audio_player', $show_audioplayer);
  415. $template->assign('media_player', $mediaplayer);
  416. $template->assign('toc_list', $get_toc_list);
  417. $template->assign('teacher_toc_buttons', $get_teacher_buttons);
  418. $template->assign('iframe_src', $src);
  419. $template->assign('navigation_bar_bottom', $navigation_bar_bottom);
  420. if ($gamificationMode == 1) {
  421. $template->assign(
  422. 'gamification_stars',
  423. $_SESSION['oLP']->getCalculateStars($sessionId)
  424. );
  425. $template->assign(
  426. 'gamification_points',
  427. $_SESSION['oLP']->getCalculateScore($sessionId)
  428. );
  429. }
  430. $template->assign(
  431. 'lp_preview_image',
  432. Display::img(
  433. $lpPreviewImagePath,
  434. $_SESSION['oLP']->name,
  435. [],
  436. ICON_SIZE_BIG
  437. )
  438. );
  439. $template->assign('lp_author', $_SESSION['oLP']->get_author());
  440. $template->assign('lp_mode', $_SESSION['oLP']->mode);
  441. $template->assign('lp_title_scorm',$_SESSION['oLP']->name);
  442. $template->assign(
  443. 'lp_html_toc',
  444. $_SESSION['oLP']->get_html_toc($get_toc_list)
  445. );
  446. $template->assign('lp_id', $_SESSION['oLP']->lp_id);
  447. $template->assign('lp_current_item_id', $_SESSION['oLP']->get_current_item_id());
  448. $content = $template->fetch('default/learnpath/view.tpl');
  449. $template->assign('content', $content);
  450. $template->display_no_layout_template();
  451. // Restore a global setting.
  452. $_setting['show_navigation_menu'] = $save_setting;
  453. if ($debug) {
  454. error_log(' ------- end lp_view.php ------');
  455. }