lp_view.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  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. /**
  15. * Code
  16. */
  17. use \ChamiloSession as Session;
  18. $_SESSION['whereami'] = 'lp/view';
  19. $this_section = SECTION_COURSES;
  20. if ($lp_controller_touched != 1) {
  21. header('location: lp_controller.php?action=view&item_id='.intval($_REQUEST['item_id']));
  22. exit;
  23. }
  24. /* Libraries */
  25. //require_once '../inc/global.inc.php';
  26. require_once 'learnpath.class.php';
  27. require_once 'learnpathItem.class.php';
  28. //To prevent the template class
  29. $show_learnpath = true;
  30. api_protect_course_script();
  31. $lp_id = intval($_GET['lp_id']);
  32. // Check if the learning path is visible for student - (LP requisites)
  33. if (!api_is_allowed_to_edit(null, true, true, false) && !learnpath::is_lp_visible_for_student($lp_id, api_get_user_id())) {
  34. api_not_allowed(true);
  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. /** @var learnpath $learnPath */
  53. $learnPath = $_SESSION['oLP'];
  54. $learnPath->setError(null);
  55. $lp_item_id = $learnPath->get_current_item_id();
  56. $lp_type = $learnPath->get_type();
  57. $course_code = api_get_course_id();
  58. $course_id = api_get_course_int_id();
  59. $user_id = api_get_user_id();
  60. $platform_theme = api_get_setting('stylesheets');
  61. $my_style = $platform_theme;
  62. //$htmlHeadXtra[] = $app['template']->fetch('default/javascript/newscorm/minipanel.tpl');
  63. /*
  64. if ($_SESSION['oLP']->mode == 'embedframe' || $_SESSION['oLP']->get_hide_toc_frame() == 1) {
  65. $htmlHeadXtra[] = '<script>
  66. $(document).ready(function(){
  67. toogle_minipanel();
  68. });
  69. </script>';
  70. }*/
  71. // Impress js
  72. $lpId = $learnPath->get_id();
  73. if ($learnPath->mode == 'impress') {
  74. $url = api_get_path(WEB_CODE_PATH)."newscorm/lp_impress.php?lp_id=$lpId&".api_get_cidreq();
  75. header("Location: $url");
  76. exit;
  77. }
  78. // Prepare variables for the test tool (just in case) - honestly, this should disappear later on.
  79. $_SESSION['scorm_view_id'] = $learnPath->get_view_id();
  80. $_SESSION['scorm_item_id'] = $lp_item_id;
  81. // Reinit exercises variables to avoid spacename clashes (see exercise tool)
  82. if (isset($exerciseResult) || isset($_SESSION['exerciseResult'])) {
  83. Session::erase($exerciseResult);
  84. }
  85. unset($_SESSION['objExercise']);
  86. unset($_SESSION['questionList']);
  87. /** @var Template $template */
  88. $template = $app['template'];
  89. $template->assign('course_code', $course_code);
  90. $template->assign('lp_id', $lpId);
  91. $get_toc_list = $learnPath->get_toc();
  92. $type_quiz = false;
  93. foreach ($get_toc_list as $toc) {
  94. if ($toc['id'] == $lp_item_id && ($toc['type'] == 'quiz')) {
  95. $type_quiz = true;
  96. }
  97. }
  98. if (!isset($src)) {
  99. $src = null;
  100. switch ($lp_type) {
  101. case 1:
  102. $learnPath->stop_previous_item();
  103. $htmlHeadXtra[] = '<script src="'.api_get_path(WEB_CODE_PATH).'newscorm/scorm_api.php" type="text/javascript"></script>';
  104. $prereq_check = $learnPath->prerequisites_match($lp_item_id);
  105. if ($prereq_check === true) {
  106. $src = $learnPath->get_link('http', $lp_item_id, $get_toc_list);
  107. // Prevents FF 3.6 + Adobe Reader 9 bug see BT#794 when calling a pdf file in a LP.
  108. $file_info = parse_url($src);
  109. $file_info = pathinfo($file_info['path']);
  110. if (isset($file_info['extension']) && api_strtolower(substr($file_info['extension'], 0, 3) == 'pdf')) {
  111. $src = api_get_path(WEB_CODE_PATH).'newscorm/lp_view_item.php?lp_item_id='.$lp_item_id;
  112. }
  113. $learnPath->start_current_item(); // starts time counter manually if asset
  114. } else {
  115. $src = 'blank.php?error=prerequisites';
  116. }
  117. break;
  118. case 2:
  119. // save old if asset
  120. $learnPath->stop_previous_item(); // save status manually if asset
  121. $htmlHeadXtra[] = '<script src="'.api_get_path(WEB_CODE_PATH).'newscorm/scorm_api.php" type="text/javascript" language="javascript"></script>';
  122. $prereq_check = $learnPath->prerequisites_match($lp_item_id);
  123. if ($prereq_check === true) {
  124. $src = $learnPath->get_link('http', $lp_item_id, $get_toc_list);
  125. $learnPath->start_current_item(); // starts time counter manually if asset
  126. } else {
  127. $src = 'blank.php?error=prerequisites';
  128. }
  129. break;
  130. case 3:
  131. // aicc
  132. $learnPath->stop_previous_item(); // save status manually if asset
  133. $htmlHeadXtra[] = '<script src="'.$learnPath->get_js_lib().'" type="text/javascript" language="javascript"></script>';
  134. $prereq_check = $learnPath->prerequisites_match($lp_item_id);
  135. if ($prereq_check === true) {
  136. $src = $learnPath->get_link('http', $lp_item_id, $get_toc_list);
  137. $learnPath->start_current_item(); // starts time counter manually if asset
  138. } else {
  139. $src = 'blank.php';
  140. }
  141. break;
  142. case 4:
  143. break;
  144. }
  145. }
  146. $autostart = 'true';
  147. if (!$learnPath->check_attempts()) {
  148. api_not_allowed(true);
  149. }
  150. if ($type_quiz && !empty($_REQUEST['exeId']) && isset($lp_id) && isset($_GET['lp_item_id'])) {
  151. global $src;
  152. $learnPath->items[$learnPath->current]->write_to_db();
  153. $TBL_TRACK_EXERCICES = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  154. $TBL_LP_ITEM_VIEW = Database::get_course_table(TABLE_LP_ITEM_VIEW);
  155. $TBL_LP_ITEM = Database::get_course_table(TABLE_LP_ITEM);
  156. $safe_item_id = intval($_GET['lp_item_id']);
  157. $safe_id = $lp_id;
  158. $safe_exe_id = intval($_REQUEST['exeId']);
  159. if ($safe_id == strval(intval($safe_id)) && $safe_item_id == strval(intval($safe_item_id))) {
  160. $sql = 'SELECT start_date, exe_date, exe_result, exe_weighting FROM '.$TBL_TRACK_EXERCICES.' WHERE exe_id = '.$safe_exe_id;
  161. if ($debug) {
  162. error_log($sql);
  163. }
  164. $res = Database::query($sql);
  165. $row_dates = Database::fetch_array($res);
  166. $time_start_date = api_strtotime($row_dates['start_date'], 'UTC');
  167. $time_exe_date = api_strtotime($row_dates['exe_date'], 'UTC');
  168. $mytime = ((int)$time_exe_date - (int)$time_start_date);
  169. $score = (float)$row_dates['exe_result'];
  170. $max_score = (float)$row_dates['exe_weighting'];
  171. $sql_upd_max_score = "UPDATE $TBL_LP_ITEM SET max_score = '$max_score' WHERE c_id = $course_id AND id = '".$safe_item_id."'";
  172. if ($debug) {
  173. error_log($sql_upd_max_score);
  174. }
  175. Database::query($sql_upd_max_score);
  176. $sql_last_attempt = "SELECT id FROM $TBL_LP_ITEM_VIEW WHERE c_id = $course_id AND lp_item_id = '$safe_item_id' AND lp_view_id = '".$learnPath->lp_view_id."' order by id desc limit 1";
  177. $res_last_attempt = Database::query($sql_last_attempt);
  178. if ($debug) {
  179. error_log($sql_last_attempt);
  180. }
  181. if (Database::num_rows($res_last_attempt)) {
  182. $row_last_attempt = Database::fetch_row($res_last_attempt);
  183. $lp_item_view_id = $row_last_attempt[0];
  184. $sql_upd_score = "UPDATE $TBL_LP_ITEM_VIEW SET status = 'completed' , score = $score, total_time = $mytime
  185. WHERE id='".$lp_item_view_id."' AND c_id = $course_id ";
  186. if ($debug) {
  187. error_log($sql_upd_score);
  188. }
  189. Database::query($sql_upd_score);
  190. $update_query = "UPDATE $TBL_TRACK_EXERCICES SET orig_lp_item_view_id = $lp_item_view_id WHERE exe_id = ".$safe_exe_id;
  191. Database::query($update_query);
  192. }
  193. }
  194. if (intval($_GET['fb_type']) > 0) {
  195. $src = 'blank.php?msg=exerciseFinished';
  196. } else {
  197. $src = api_get_path(WEB_CODE_PATH).'exercice/result.php?origin=learnpath&id='.$safe_exe_id;
  198. if ($debug) {
  199. error_log('Calling URL: '.$src);
  200. }
  201. }
  202. $autostart = 'false';
  203. }
  204. $learnPath->set_previous_item($lp_item_id);
  205. $lpName = Security::remove_XSS($learnPath->get_name());
  206. $save_setting = api_get_setting('show_navigation_menu');
  207. global $_setting;
  208. $_setting['show_navigation_menu'] = 'false';
  209. $scorm_css_header = true;
  210. // Sets the css theme of the LP this call is also use at the frames (toc, nav, message).
  211. $lp_theme_css = $learnPath->get_theme();
  212. // Check if audio recorder needs to be in studentview.
  213. if (isset($_SESSION['status']) && $_SESSION['status'][$course_code] == 5) {
  214. $audio_recorder_studentview = true;
  215. } else {
  216. $audio_recorder_studentview = false;
  217. }
  218. // Set flag to ensure lp_header.php is loaded by this script (flag is unset in lp_header.php).
  219. $_SESSION['loaded_lp_view'] = true;
  220. $display_none = '';
  221. $margin_left = '305px';
  222. // Media player code
  223. $display_mode = $learnPath->mode;
  224. $scorm_css_header = true;
  225. $lp_theme_css = $learnPath->get_theme();
  226. // Setting up the CSS theme if exists.
  227. if (!empty ($lp_theme_css) && !empty ($mycourselptheme) && $mycourselptheme != -1 && $mycourselptheme == 1) {
  228. global $lp_theme_css;
  229. } else {
  230. $lp_theme_css = $my_style;
  231. }
  232. $progress_bar = $learnPath->get_progress_bar('', -1, '', true);
  233. $navigation_bar = $learnPath->get_navigation_bar();
  234. $mediaplayer = $learnPath->get_mediaplayer($autostart);
  235. $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
  236. $show_audioplayer = false;
  237. // Getting all the information about the item.
  238. $sql = "SELECT audio FROM ".$tbl_lp_item." WHERE c_id = $course_id AND lp_id = '".$learnPath->lp_id."'";
  239. $res_media = Database::query($sql);
  240. if (Database::num_rows($res_media) > 0) {
  241. while ($row_media = Database::fetch_array($res_media)) {
  242. if (!empty($row_media['audio'])) {
  243. $show_audioplayer = true;
  244. break;
  245. }
  246. }
  247. }
  248. $template->assign('api_is_allowed_to_edit', api_is_allowed_to_edit(null, true, false, false));
  249. if ($is_allowed_to_edit) {
  250. global $interbreadcrumb;
  251. $interbreadcrumb[] = array(
  252. 'url' => 'lp_controller.php?action=list&isStudentView=false',
  253. 'name' => get_lang('LearningPaths')
  254. );
  255. $interbreadcrumb[] = array(
  256. 'url' => api_get_self()."?action=add_item&type=step&lp_id=".$learnPath->lp_id."&isStudentView=false",
  257. 'name' => $learnPath->get_name()
  258. );
  259. $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('Preview'));
  260. $template->assign('breadcrumb', $app['template']->returnBreadcrumb($interbreadcrumb, null, null));
  261. }
  262. if ($learnPath->get_preview_image() != '') {
  263. $picture = getimagesize(api_get_path(SYS_COURSE_PATH).api_get_course_path().'/upload/learning_path/images/'.$learnPath->get_preview_image());
  264. $style = null;
  265. if ($picture['1'] < 96) {
  266. $style = ' style="padding-top:'.((94 - $picture['1']) / 2).'px;" ';
  267. }
  268. $size = ($picture['0'] > 104 && $picture['1'] > 96) ? ' width="104" height="96" ' : $style;
  269. $my_path = $learnPath->get_preview_image_path();
  270. $picture = $my_path;
  271. } else {
  272. $picture = Display::return_icon('unknown_250_100.jpg', null, array(), ICON_SIZE_SMALL, false, true);
  273. }
  274. $app['template']->assign('course_url', api_get_cidreq());
  275. $app['template']->assign('picture', $picture);
  276. $app['template']->assign('navigation_bar', $navigation_bar);
  277. $app['template']->assign('progress_bar', $progress_bar);
  278. $app['template']->assign('author', $learnPath->get_author());
  279. $app['template']->assign('mediaplayer', $mediaplayer);
  280. $app['template']->assign('table_of_contents', $learnPath->get_html_toc($get_toc_list));
  281. $app['template']->assign('lp_name', $lpName);
  282. // hub 26-05-2010 Fullscreen or not fullscreen
  283. $height = '100%';
  284. if ($learnPath->mode == 'fullscreen') {
  285. $iframe = '<iframe id="content_id_blank" name="content_name_blank" src="blank.php" border="0" frameborder="0" style="width:100%;height:'.$height.'" allowFullScreen></iframe>';
  286. } else {
  287. $iframe = '<iframe id="content_id" name="content_name" src="'.$src.'" border="0" frameborder="0" style="display: block; width:100%; height:'.$height.'" allowFullScreen></iframe>';
  288. }
  289. $app['template']->assign('iframe', $iframe);
  290. $app['template']->assign('show_glossary', api_get_setting('show_glossary_in_extra_tools'));
  291. $app['template']->assign('glossary_type', api_get_setting('show_glossary_in_documents'));
  292. // Restore a global setting.
  293. $_setting['show_navigation_menu'] = $save_setting;
  294. //$content = $app['template']->fetch('default/javascript/newscorm/lp.tpl');
  295. $app['template.show_footer'] = false;
  296. $app['template.show_header'] = false;
  297. $app['default_layout'] = 'default/learnpath/lp.tpl';