lp_view.php 22 KB

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