lp_view.php 19 KB

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