lp_view.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use Chamilo\CourseBundle\Entity\CLpCategory;
  4. use ChamiloSession as Session;
  5. /**
  6. * This file was originally the copy of document.php, but many modifications happened since then ;
  7. * the direct file view is not needed anymore, if the user uploads a scorm zip file, a directory
  8. * will be automatically created for it, and the files will be uncompressed there for example ;.
  9. *
  10. * @package chamilo.learnpath
  11. *
  12. * @author Yannick Warnier <ywarnier@beeznest.org> - redesign
  13. * @author Denes Nagy, principal author
  14. * @author Isthvan Mandak, several new features
  15. * @author Roan Embrechts, code improvements and refactoring
  16. */
  17. $use_anonymous = true;
  18. $this_section = SECTION_COURSES;
  19. if ($lp_controller_touched != 1) {
  20. header('Location: lp_controller.php?action=view&item_id='.intval($_REQUEST['item_id']));
  21. exit;
  22. }
  23. require_once __DIR__.'/../inc/global.inc.php';
  24. api_protect_course_script();
  25. if (isset($_REQUEST['origin']) && $_REQUEST['origin'] === 'learnpath') {
  26. $_REQUEST['origin'] = '';
  27. }
  28. // To prevent the template class
  29. $lp_id = !empty($_GET['lp_id']) ? (int) $_GET['lp_id'] : 0;
  30. $sessionId = api_get_session_id();
  31. $course_code = api_get_course_id();
  32. $course_id = api_get_course_int_id();
  33. $user_id = api_get_user_id();
  34. // Check if the learning path is visible for student - (LP requisites)
  35. if (!api_is_platform_admin()) {
  36. if (!api_is_allowed_to_edit(null, true, false, false) &&
  37. !learnpath::is_lp_visible_for_student($lp_id, api_get_user_id())
  38. ) {
  39. api_not_allowed(true);
  40. }
  41. }
  42. // Checking visibility (eye icon)
  43. $visibility = api_get_item_visibility(
  44. api_get_course_info(),
  45. TOOL_LEARNPATH,
  46. $lp_id,
  47. $action,
  48. api_get_user_id(),
  49. $sessionId
  50. );
  51. if ($visibility === 0 &&
  52. !api_is_allowed_to_edit(false, true, false, false)
  53. ) {
  54. api_not_allowed(true);
  55. }
  56. /** @var learnpath $lp */
  57. $lp = Session::read('oLP');
  58. if (empty($lp)) {
  59. api_not_allowed(true);
  60. }
  61. $debug = 0;
  62. if ($debug) {
  63. error_log('------ Entering lp_view.php -------');
  64. }
  65. $lp_item_id = $lp->get_current_item_id();
  66. $lpType = $lp->get_type();
  67. if (!$is_allowed_to_edit) {
  68. $categoryId = $lp->getCategoryId();
  69. $em = Database::getManager();
  70. if (!empty($categoryId)) {
  71. /** @var CLpCategory $category */
  72. $category = $em->getRepository('ChamiloCourseBundle:CLpCategory')->find($categoryId);
  73. $block = false;
  74. if ($category) {
  75. $user = UserManager::getRepository()->find($user_id);
  76. $users = $category->getUsers();
  77. if (!empty($users) && $users->count() > 0) {
  78. if ($user && !$category->hasUserAdded($user)) {
  79. $block = true;
  80. }
  81. }
  82. $isVisible = learnpath::categoryIsVisibleForStudent(
  83. $category,
  84. $user
  85. );
  86. if ($isVisible) {
  87. $block = false;
  88. }
  89. if ($block) {
  90. api_not_allowed(true);
  91. }
  92. }
  93. }
  94. }
  95. $platform_theme = api_get_setting('stylesheets');
  96. $my_style = $platform_theme;
  97. $ajaxUrl = api_get_path(WEB_AJAX_PATH).'lp.ajax.php?a=get_item_prerequisites&'.api_get_cidreq();
  98. $htmlHeadXtra[] = '<script>
  99. <!--
  100. var jQueryFrameReadyConfigPath = \''.api_get_jquery_web_path().'\';
  101. -->
  102. </script>';
  103. $htmlHeadXtra[] = api_get_css_asset('qtip2/jquery.qtip.min.css');
  104. $htmlHeadXtra[] = api_get_asset('qtip2/jquery.qtip.min.js');
  105. $htmlHeadXtra[] = '<script type="text/javascript" src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.frameready.js"></script>';
  106. $htmlHeadXtra[] = '<script>
  107. $(function() {
  108. $("div#log_content_cleaner").bind("click", function() {
  109. $("div#log_content").empty();
  110. });
  111. });
  112. var chamilo_xajax_handler = window.oxajax;
  113. </script>';
  114. $allowLpItemTip = api_get_configuration_value('hide_accessibility_label_on_lp_item') === false;
  115. if ($allowLpItemTip) {
  116. $htmlHeadXtra[] = '<script>
  117. $(function() {
  118. $(".scorm_item_normal").qtip({
  119. content: {
  120. text: function(event, api) {
  121. var item = $(this);
  122. var itemId = $(this).attr("id");
  123. itemId = itemId.replace("toc_", "");
  124. var textToShow = "";
  125. $.ajax({
  126. type: "GET",
  127. url: "'.$ajaxUrl.'&item_id="+ itemId,
  128. async: false
  129. })
  130. .then(function(content) {
  131. if (content == 1) {
  132. textToShow = "'.addslashes(get_lang('LPItemCanBeAccessed')).'";
  133. api.set("style.classes", "qtip-green qtip-shadow");
  134. } else {
  135. textToShow = content;
  136. api.set("style.classes", "qtip-red qtip-shadow");
  137. }
  138. return textToShow;
  139. });
  140. return textToShow;
  141. }
  142. }
  143. });
  144. });
  145. </script>';
  146. }
  147. // Impress js
  148. if ($lp->mode === 'impress') {
  149. $lp_id = $lp->get_id();
  150. $url = api_get_path(WEB_CODE_PATH)."lp/lp_impress.php?lp_id=$lp_id&".api_get_cidreq();
  151. header("Location: $url");
  152. exit;
  153. }
  154. // Prepare variables for the test tool (just in case) - honestly, this should disappear later on.
  155. Session::write('scorm_view_id', $lp->get_view_id());
  156. Session::write('scorm_item_id', $lp_item_id);
  157. // Reinit exercises variables to avoid spacename clashes (see exercise tool)
  158. if (isset($exerciseResult) || isset($_SESSION['exerciseResult'])) {
  159. Session::erase('exerciseResult');
  160. Session::erase('objExercise');
  161. Session::erase('questionList');
  162. Session::erase('duration_time_previous');
  163. Session::erase('duration_time');
  164. }
  165. // additional APIs
  166. $htmlHeadXtra[] = '<script>
  167. chamilo_courseCode = "'.$course_code.'";
  168. </script>';
  169. // Document API
  170. $htmlHeadXtra[] = '<script src="js/documentapi.js" type="text/javascript" language="javascript"></script>';
  171. // Storage API
  172. $htmlHeadXtra[] = '<script>
  173. var sv_user = \''.api_get_user_id().'\';
  174. var sv_course = chamilo_courseCode;
  175. var sv_sco = \''.$lp_id.'\';
  176. </script>'; // FIXME fetch sco and userid from a more reliable source directly in sotrageapi.js
  177. $htmlHeadXtra[] = '<script type="text/javascript" src="js/storageapi.js"></script>';
  178. /**
  179. * Get a link to the corresponding document.
  180. */
  181. if ($debug) {
  182. error_log(" src: $src ");
  183. error_log(" lp_type: $lpType ");
  184. }
  185. $get_toc_list = $lp->get_toc();
  186. $get_teacher_buttons = $lp->get_teacher_toc_buttons();
  187. $type_quiz = false;
  188. foreach ($get_toc_list as $toc) {
  189. if ($toc['id'] == $lp_item_id && $toc['type'] == 'quiz') {
  190. $type_quiz = true;
  191. }
  192. }
  193. if (!isset($src)) {
  194. $src = null;
  195. switch ($lpType) {
  196. case 1:
  197. $lp->stop_previous_item();
  198. $htmlHeadXtra[] = '<script src="scorm_api.php" type="text/javascript" language="javascript"></script>';
  199. $preReqCheck = $lp->prerequisites_match($lp_item_id);
  200. if ($preReqCheck === true) {
  201. $src = $lp->get_link(
  202. 'http',
  203. $lp_item_id,
  204. $get_toc_list
  205. );
  206. // Prevents FF 3.6 + Adobe Reader 9 bug see BT#794 when calling a pdf file in a LP.
  207. $file_info = parse_url($src);
  208. if (isset($file_info['path'])) {
  209. $file_info = pathinfo($file_info['path']);
  210. }
  211. if (isset($file_info['extension']) &&
  212. api_strtolower(substr($file_info['extension'], 0, 3)) == 'pdf'
  213. ) {
  214. $src = api_get_path(WEB_CODE_PATH).'lp/lp_view_item.php?lp_item_id='.$lp_item_id.'&'.api_get_cidreq();
  215. }
  216. $src = $lp->fixBlockedLinks($src);
  217. $lp->start_current_item(); // starts time counter manually if asset
  218. } else {
  219. $src = 'blank.php?error=prerequisites';
  220. }
  221. break;
  222. case 2:
  223. // save old if asset
  224. $lp->stop_previous_item(); // save status manually if asset
  225. $htmlHeadXtra[] = '<script src="scorm_api.php" type="text/javascript" language="javascript"></script>';
  226. $preReqCheck = $lp->prerequisites_match($lp_item_id);
  227. if ($preReqCheck === true) {
  228. $src = $lp->get_link('http', $lp_item_id, $get_toc_list);
  229. $lp->start_current_item(); // starts time counter manually if asset
  230. } else {
  231. $src = 'blank.php?error=prerequisites';
  232. }
  233. break;
  234. case 3:
  235. // aicc
  236. $lp->stop_previous_item(); // save status manually if asset
  237. $htmlHeadXtra[] = '<script src="'.$lp->get_js_lib().'" type="text/javascript" language="javascript"></script>';
  238. $preReqCheck = $lp->prerequisites_match($lp_item_id);
  239. if ($preReqCheck === true) {
  240. $src = $lp->get_link(
  241. 'http',
  242. $lp_item_id,
  243. $get_toc_list
  244. );
  245. $lp->start_current_item(); // starts time counter manually if asset
  246. } else {
  247. $src = 'blank.php';
  248. }
  249. break;
  250. case 4:
  251. break;
  252. }
  253. }
  254. $autostart = 'true';
  255. // Update status, total_time from lp_item_view table when you finish the exercises in learning path.
  256. if ($debug) {
  257. error_log('$type_quiz: '.$type_quiz);
  258. error_log('$_REQUEST[exeId]: '.intval($_REQUEST['exeId']));
  259. error_log('$lp_id: '.$lp_id);
  260. error_log('$_GET[lp_item_id]: '.intval($_GET['lp_item_id']));
  261. }
  262. if (!empty($_REQUEST['exeId']) &&
  263. isset($lp_id) &&
  264. isset($_GET['lp_item_id'])
  265. ) {
  266. global $src;
  267. $lp->items[$lp->current]->write_to_db();
  268. $TBL_TRACK_EXERCICES = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES);
  269. $TBL_LP_ITEM_VIEW = Database::get_course_table(TABLE_LP_ITEM_VIEW);
  270. $TBL_LP_ITEM = Database::get_course_table(TABLE_LP_ITEM);
  271. $safe_item_id = (int) $_GET['lp_item_id'];
  272. $safe_id = $lp_id;
  273. $safe_exe_id = (int) $_REQUEST['exeId'];
  274. if (!empty($safe_id) && !empty($safe_item_id)) {
  275. $sql = 'SELECT start_date, exe_date, exe_result, exe_weighting, exe_exo_id, exe_duration
  276. FROM '.$TBL_TRACK_EXERCICES.'
  277. WHERE exe_id = '.$safe_exe_id;
  278. $res = Database::query($sql);
  279. $row_dates = Database::fetch_array($res);
  280. $duration = (int) $row_dates['exe_duration'];
  281. $score = (float) $row_dates['exe_result'];
  282. $max_score = (float) $row_dates['exe_weighting'];
  283. $sql = "UPDATE $TBL_LP_ITEM SET
  284. max_score = '$max_score'
  285. WHERE iid = $safe_item_id";
  286. Database::query($sql);
  287. $sql = "SELECT id FROM $TBL_LP_ITEM_VIEW
  288. WHERE
  289. c_id = $course_id AND
  290. lp_item_id = $safe_item_id AND
  291. lp_view_id = ".$lp->get_view_id()."
  292. ORDER BY id DESC
  293. LIMIT 1";
  294. $res_last_attempt = Database::query($sql);
  295. if (Database::num_rows($res_last_attempt) && !api_is_invitee()) {
  296. $row_last_attempt = Database::fetch_row($res_last_attempt);
  297. $lp_item_view_id = $row_last_attempt[0];
  298. $exercise = new Exercise(api_get_course_int_id());
  299. $exercise->read($row_dates['exe_exo_id']);
  300. $status = 'completed';
  301. if (!empty($exercise->pass_percentage)) {
  302. $status = 'failed';
  303. $success = ExerciseLib::isSuccessExerciseResult(
  304. $score,
  305. $max_score,
  306. $exercise->pass_percentage
  307. );
  308. if ($success) {
  309. $status = 'passed';
  310. }
  311. }
  312. $sql = "UPDATE $TBL_LP_ITEM_VIEW SET
  313. status = '$status',
  314. score = $score,
  315. total_time = $duration
  316. WHERE iid = $lp_item_view_id";
  317. if ($debug) {
  318. error_log($sql);
  319. }
  320. Database::query($sql);
  321. $sql = "UPDATE $TBL_TRACK_EXERCICES SET
  322. orig_lp_item_view_id = $lp_item_view_id
  323. WHERE exe_id = ".$safe_exe_id;
  324. Database::query($sql);
  325. }
  326. }
  327. if (intval($_GET['fb_type']) != EXERCISE_FEEDBACK_TYPE_END) {
  328. $src = 'blank.php?msg=exerciseFinished';
  329. } else {
  330. $src = api_get_path(WEB_CODE_PATH).'exercise/result.php?id='.$safe_exe_id.'&'.api_get_cidreq(true, true, 'learnpath');
  331. if ($debug) {
  332. error_log('Calling URL: '.$src);
  333. }
  334. }
  335. $autostart = 'false';
  336. }
  337. $lp->set_previous_item($lp_item_id);
  338. $nameTools = Security::remove_XSS($lp->get_name());
  339. $save_setting = api_get_setting('show_navigation_menu');
  340. global $_setting;
  341. $_setting['show_navigation_menu'] = 'false';
  342. $scorm_css_header = true;
  343. $lp_theme_css = $lp->get_theme();
  344. // Sets the css theme of the LP this call is also use at the frames (toc, nav, message).
  345. if ($lp->mode == 'fullscreen') {
  346. $htmlHeadXtra[] = "<script>
  347. window.open('$src','content_id','toolbar=0,location=0,status=0,scrollbars=1,resizable=1');
  348. </script>";
  349. }
  350. // Set flag to ensure lp_header.php is loaded by this script (flag is unset in lp_header.php).
  351. Session::write('loaded_lp_view', true);
  352. $display_none = '';
  353. $margin_left = '340px';
  354. // Media player code
  355. $display_mode = $lp->mode;
  356. $scorm_css_header = true;
  357. $lp_theme_css = $lp->get_theme();
  358. // Setting up the CSS theme if exists.
  359. if (!empty($lp_theme_css) && !empty($mycourselptheme) && $mycourselptheme != -1 && $mycourselptheme == 1) {
  360. global $lp_theme_css;
  361. } else {
  362. $lp_theme_css = $my_style;
  363. }
  364. $progress_bar = '';
  365. if (!api_is_invitee()) {
  366. $progress_bar = $lp->getProgressBar();
  367. }
  368. $navigation_bar = $lp->get_navigation_bar();
  369. $navigation_bar_bottom = $lp->get_navigation_bar('control-bottom');
  370. $mediaplayer = $lp->get_mediaplayer($lp->current, $autostart);
  371. $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
  372. // Getting all the information about the item.
  373. $sql = "SELECT audio FROM $tbl_lp_item
  374. WHERE c_id = $course_id AND lp_id = ".$lp->lp_id;
  375. $res_media = Database::query($sql);
  376. $show_audioplayer = false;
  377. if (Database::num_rows($res_media) > 0) {
  378. while ($row_media = Database::fetch_array($res_media)) {
  379. if (!empty($row_media['audio'])) {
  380. $show_audioplayer = true;
  381. break;
  382. }
  383. }
  384. }
  385. $is_allowed_to_edit = api_is_allowed_to_edit(false, true, true, false);
  386. global $interbreadcrumb;
  387. if ($is_allowed_to_edit) {
  388. $interbreadcrumb[] = [
  389. 'url' => api_get_self().'?action=list&isStudentView=false&'.api_get_cidreq(true, true, 'course'),
  390. 'name' => get_lang('LearningPaths'),
  391. ];
  392. $interbreadcrumb[] = [
  393. 'url' => api_get_self()."?action=add_item&type=step&lp_id={$lp->lp_id}&isStudentView=false&".api_get_cidreq(true, true, 'course'),
  394. 'name' => $lp->getNameNoTags(),
  395. ];
  396. $interbreadcrumb[] = [
  397. 'url' => '#',
  398. 'name' => get_lang('Preview'),
  399. ];
  400. $buttonHomeUrl = 'lp_controller.php?'.api_get_cidreq(true, true, 'course').'&'.http_build_query([
  401. 'isStudentView' => 'false',
  402. 'action' => 'return_to_course_homepage',
  403. ]);
  404. } else {
  405. $buttonHomeUrl = 'lp_controller.php?'.api_get_cidreq(true, true, 'course').'&'.http_build_query([
  406. 'action' => 'return_to_course_homepage',
  407. ]);
  408. }
  409. $buttonHomeText = get_lang('CourseHomepageLink');
  410. $returnLink = api_get_course_setting('lp_return_link');
  411. switch ($returnLink) {
  412. case 1: // lp list
  413. $buttonHomeUrl .= '&redirectTo=lp_list';
  414. $buttonHomeText = get_lang('LearningPathList');
  415. break;
  416. case 2: // user portal
  417. $buttonHomeUrl .= '&redirectTo=my_courses';
  418. $buttonHomeText = get_lang('MyCourses');
  419. break;
  420. }
  421. $lpPreviewImagePath = Display::returnIconPath('unknown.png', ICON_SIZE_BIG);
  422. if ($lp->get_preview_image()) {
  423. $lpPreviewImagePath = $lp->get_preview_image_path();
  424. }
  425. if ($lp->current == $lp->get_last()) {
  426. $categories = Category::load(
  427. null,
  428. null,
  429. $course_code,
  430. null,
  431. null,
  432. $sessionId
  433. );
  434. if (!empty($categories)) {
  435. $gradebookEvaluations = $categories[0]->get_evaluations();
  436. $gradebookLinks = $categories[0]->get_links();
  437. if (count($gradebookEvaluations) === 0 &&
  438. count($gradebookLinks) === 1 &&
  439. $gradebookLinks[0]->get_type() == LINK_LEARNPATH &&
  440. $gradebookLinks[0]->get_ref_id() == $lp->lp_id
  441. ) {
  442. $gradebookMinScore = $categories[0]->getCertificateMinScore();
  443. $userScore = $gradebookLinks[0]->calc_score($user_id, 'best');
  444. if ($userScore[0] >= $gradebookMinScore) {
  445. Category::generateUserCertificate($categories[0]->get_id(), $user_id);
  446. }
  447. }
  448. }
  449. }
  450. $template = new Template('', false, false, true, true, false);
  451. $fixLinkSetting = api_get_configuration_value('lp_fix_embed_content');
  452. $fixLink = '';
  453. if ($fixLinkSetting) {
  454. $fixLink = '{type:"script", id:"_fr10", src:"'.api_get_path(WEB_LIBRARY_PATH).'fixlinks.js"}';
  455. }
  456. $template->assign('fix_link', $fixLink);
  457. $template->assign('glossary_tool_available_list', ['true', 'lp', 'exercise_and_lp']);
  458. // If the global gamification mode is enabled...
  459. $gamificationMode = api_get_setting('gamification_mode');
  460. // ...AND this learning path is set in gamification mode, then change the display
  461. $gamificationMode = $gamificationMode && $lp->seriousgame_mode;
  462. $template->assign('gamification_mode', $gamificationMode);
  463. $template->assign('glossary_extra_tools', api_get_setting('show_glossary_in_extra_tools'));
  464. $template->assign('show_glossary_in_documents', api_get_setting('show_glossary_in_documents'));
  465. $template->assign('jquery_web_path', api_get_jquery_web_path());
  466. $template->assign('jquery_ui_js_web_path', api_get_jquery_ui_js_web_path());
  467. $template->assign('jquery_ui_css_web_path', api_get_jquery_ui_css_web_path());
  468. $template->assign('is_allowed_to_edit', $is_allowed_to_edit);
  469. $template->assign('button_home_url', $buttonHomeUrl);
  470. $template->assign('button_home_text', $buttonHomeText);
  471. $template->assign('navigation_bar', $navigation_bar);
  472. $template->assign('progress_bar', $progress_bar);
  473. $template->assign('show_audio_player', $show_audioplayer);
  474. $template->assign('media_player', $mediaplayer);
  475. $template->assign('toc_list', $get_toc_list);
  476. $template->assign('teacher_toc_buttons', $get_teacher_buttons);
  477. $template->assign('iframe_src', $src);
  478. $template->assign('navigation_bar_bottom', $navigation_bar_bottom);
  479. $template->assign('show_left_column', $lp->getHideTableOfContents() == 0);
  480. $showMenu = 0;
  481. $settings = api_get_configuration_value('lp_view_settings');
  482. $display = isset($settings['display']) ? $settings['display'] : false;
  483. if (!empty($display)) {
  484. $showMenu = isset($display['show_toolbar_by_default']) && $display['show_toolbar_by_default'] ? 1 : 0;
  485. }
  486. $template->assign('show_toolbar_by_default', $showMenu);
  487. if ($gamificationMode == 1) {
  488. $template->assign('gamification_stars', $lp->getCalculateStars($sessionId));
  489. $template->assign('gamification_points', $lp->getCalculateScore($sessionId));
  490. }
  491. $template->assign('lp_author', $lp->get_author());
  492. $lpMinTime = '';
  493. if (Tracking::minimumTimeAvailable(api_get_session_id(), api_get_course_int_id())) {
  494. // Calulate minimum and accumulated time
  495. $timeLp = $_SESSION['oLP']->getAccumulateWorkTime();
  496. $timeTotalCourse = $_SESSION['oLP']->getAccumulateWorkTimeTotalCourse();
  497. // Minimum connection percentage
  498. $perc = 100;
  499. // Time from the course
  500. $tc = $timeTotalCourse;
  501. // Percentage of the learning paths
  502. $pl = 0;
  503. if (!empty($timeTotalCourse)) {
  504. $pl = $timeLp / $timeTotalCourse;
  505. }
  506. // Minimum time for each learning path
  507. $time_min = intval($pl * $tc * $perc / 100);
  508. if ($_SESSION['oLP']->getAccumulateWorkTime() > 0) {
  509. $lpMinTime = '('.$time_min.' min)';
  510. }
  511. $lpTimeList = Tracking::getCalculateTime($user_id, api_get_course_int_id(), api_get_session_id());
  512. $lpTime = isset($lpTimeList[TOOL_LEARNPATH][$lp_id]) ? (int) $lpTimeList[TOOL_LEARNPATH][$lp_id] : 0;
  513. if ($lpTime >= ($time_min * 60)) {
  514. $time_progress_perc = '100%';
  515. $time_progress_value = 100;
  516. } else {
  517. $time_progress_value = intval(($lpTime * 100) / ($time_min * 60));
  518. $time_progress_perc = $time_progress_value.'%';
  519. }
  520. $template->assign('time_progress_perc', $time_progress_perc);
  521. $template->assign('time_progress_value', $time_progress_value);
  522. // Cronometro
  523. $hour = (intval($lpTime / 3600)) < 10 ? '0'.intval($lpTime / 3600) : intval($lpTime / 3600);
  524. $template->assign('hour', $hour);
  525. $template->assign('minute', date('i', $lpTime));
  526. $template->assign('second', date('s', $lpTime));
  527. $template->assign('hour_min', api_time_to_hms($timeLp * 60, '</div><div class="divider">:</div><div>'));
  528. }
  529. $template->assign('lp_accumulate_work_time', $lpMinTime);
  530. $template->assign('lp_mode', $lp->mode);
  531. $template->assign('lp_title_scorm', $lp->get_name());
  532. if (api_get_configuration_value('lp_view_accordion') === true && $lpType == 1) {
  533. $template->assign('data_panel', $lp->getParentToc($get_toc_list));
  534. } else {
  535. $template->assign('data_list', $lp->getListArrayToc($get_toc_list));
  536. }
  537. $template->assign('lp_id', $lp->lp_id);
  538. $template->assign('lp_current_item_id', $lp->get_current_item_id());
  539. $template->assign('disable_js_in_lp_view', (int) api_get_configuration_value('disable_js_in_lp_view'));
  540. $template->assign(
  541. 'lp_preview_image',
  542. Display::img(
  543. $lpPreviewImagePath,
  544. $lp->getNameNoTags(),
  545. [],
  546. ICON_SIZE_BIG
  547. )
  548. );
  549. $frameReady = Display::getFrameReadyBlock('#content_id, #content_id_blank');
  550. $template->assign('frame_ready', $frameReady);
  551. $view = $template->get_template('learnpath/view.tpl');
  552. $content = $template->fetch($view);
  553. $template->assign('content', $content);
  554. $template->display_no_layout_template();
  555. // Restore a global setting.
  556. $_setting['show_navigation_menu'] = $save_setting;
  557. Session::write('oLP', $lp);
  558. if ($debug) {
  559. error_log(' ------- end lp_view.php ------');
  560. }