lp_view.php 15 KB

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