lp_view.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  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. * @license GNU/GPL - See Dokeos license directory for details
  14. */
  15. /**
  16. * Script
  17. */
  18. /* INIT SECTION */
  19. $_SESSION['whereami'] = 'lp/view';
  20. $this_section=SECTION_COURSES;
  21. if ($lp_controller_touched != 1){
  22. header('location: lp_controller.php?action=view&item_id='.$_REQUEST['item_id']);
  23. exit;
  24. }
  25. /*
  26. Libraries
  27. */
  28. require_once 'back_compat.inc.php';
  29. //require_once '../learnpath/learnpath_functions.inc.php';
  30. require_once 'scorm.lib.php';
  31. require_once 'learnpath.class.php';
  32. require_once 'learnpathItem.class.php';
  33. //require_once 'lp_comm.common.php'; //xajax functions
  34. if (!$is_allowed_in_course) api_not_allowed();
  35. // we set the encoding of the lp
  36. if (!empty($_SESSION['oLP']->encoding)) {
  37. $charset = $_SESSION['oLP']->encoding;
  38. } else {
  39. $charset = api_get_system_encoding();
  40. }
  41. $oLearnpath = false;
  42. $course_code = api_get_course_id();
  43. $user_id = api_get_user_id();
  44. $platform_theme = api_get_setting('stylesheets'); // plataform's css
  45. $my_style = $platform_theme;
  46. //escape external variables
  47. /* Header */
  48. $htmlHeadXtra[] = '<script src="../inc/lib/javascript/jquery.js" type="text/javascript" language="javascript"></script>'; //jQuery
  49. if (api_get_setting('show_glossary_in_documents') == 'ismanual' || api_get_setting('show_glossary_in_documents') == 'isautomatic' ) {
  50. $htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.frameready.js" type="text/javascript" language="javascript"></script>';
  51. $htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.highlight.js" type="text/javascript" language="javascript"></script>';
  52. }
  53. $htmlHeadXtra[] = '<script language="javascript" type="text/javascript">
  54. $(document).ready(function (){
  55. $("div#log_content_cleaner").bind("click", function(){
  56. $("div#log_content").empty();
  57. });
  58. });
  59. </script>';
  60. $htmlHeadXtra[] = '<script language="JavaScript" type="text/javascript">
  61. var dokeos_xajax_handler = window.oxajax;
  62. </script>';
  63. $_SESSION['oLP']->error = '';
  64. $lp_type = $_SESSION['oLP']->get_type();
  65. $lp_item_id = $_SESSION['oLP']->get_current_item_id();
  66. //$lp_item_id = learnpath::escape_string($_GET['item_id']);
  67. //$_SESSION['oLP']->set_current_item($lp_item_id); // already done by lp_controller.php
  68. //Prepare variables for the test tool (just in case) - honestly, this should disappear later on
  69. $_SESSION['scorm_view_id'] = $_SESSION['oLP']->get_view_id();
  70. $_SESSION['scorm_item_id'] = $lp_item_id;
  71. $_SESSION['lp_mode'] = $_SESSION['oLP']->mode;
  72. //reinit exercises variables to avoid spacename clashes (see exercise tool)
  73. if(isset($exerciseResult) or isset($_SESSION['exerciseResult'])) {
  74. api_session_unregister($exerciseResult);
  75. }
  76. unset($_SESSION['objExercise']);
  77. unset($_SESSION['questionList']);
  78. /**
  79. * Get a link to the corresponding document
  80. */
  81. if (!isset($src)) {
  82. $src = '';
  83. switch($lp_type) {
  84. case 1:
  85. $_SESSION['oLP']->stop_previous_item();
  86. $htmlHeadXtra[] = '<script src="scorm_api.php" type="text/javascript" language="javascript"></script>';
  87. $prereq_check = $_SESSION['oLP']->prerequisites_match($lp_item_id);
  88. if($prereq_check === true){
  89. $src = $_SESSION['oLP']->get_link('http',$lp_item_id);
  90. //Prevents FF 3.6 + Adobe Reader 9 bug see BT#794 when calling a pdf file in a LP
  91. $file_info = pathinfo($src);
  92. if (api_strtolower(substr($file_info['extension'], 0, 3) == 'pdf')) {
  93. $src = 'lp_view_item.php?src='.$src;
  94. }
  95. $_SESSION['oLP']->start_current_item(); //starts time counter manually if asset
  96. } else {
  97. $src = 'blank.php?error=prerequisites';
  98. }
  99. break;
  100. case 2:
  101. //save old if asset
  102. $_SESSION['oLP']->stop_previous_item(); //save status manually if asset
  103. $htmlHeadXtra[] = '<script src="scorm_api.php" type="text/javascript" language="javascript"></script>';
  104. $prereq_check = $_SESSION['oLP']->prerequisites_match($lp_item_id);
  105. if($prereq_check === true){
  106. $src = $_SESSION['oLP']->get_link('http',$lp_item_id);
  107. $_SESSION['oLP']->start_current_item(); //starts time counter manually if asset
  108. }else{
  109. $src = 'blank.php?error=prerequisites';
  110. }
  111. break;
  112. case 3:
  113. //aicc
  114. $_SESSION['oLP']->stop_previous_item(); //save status manually if asset
  115. $htmlHeadXtra[] = '<script src="'.$_SESSION['oLP']->get_js_lib().'" type="text/javascript" language="javascript"></script>';
  116. $prereq_check = $_SESSION['oLP']->prerequisites_match($lp_item_id);
  117. if($prereq_check === true){
  118. $src = $_SESSION['oLP']->get_link('http',$lp_item_id);
  119. $_SESSION['oLP']->start_current_item(); //starts time counter manually if asset
  120. }else{
  121. $src = 'blank.php';
  122. }
  123. break;
  124. case 4:
  125. break;
  126. }
  127. }
  128. $list = $_SESSION['oLP']->get_toc();
  129. $type_quiz = false;
  130. foreach($list as $toc) {
  131. if ($toc['id'] == $lp_item_id && ($toc['type']=='quiz') ) {
  132. $type_quiz = true;
  133. }
  134. }
  135. $autostart = 'true';
  136. // update status,total_time from lp_item_view table when you finish the exercises in learning path
  137. if ($type_quiz && !empty($_REQUEST['exeId']) && isset($_GET['lp_id']) && isset($_GET['lp_item_id'])) {
  138. global $src;
  139. $_SESSION['oLP']->items[$_SESSION['oLP']->current]->write_to_db();
  140. $TBL_TRACK_EXERCICES = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  141. $TBL_LP_ITEM_VIEW = Database::get_course_table(TABLE_LP_ITEM_VIEW);
  142. $TBL_LP_VIEW = Database::get_course_table(TABLE_LP_VIEW);
  143. $TBL_LP_ITEM = Database::get_course_table(TABLE_LP_ITEM);
  144. $safe_item_id = Database::escape_string($_GET['lp_item_id']);
  145. $safe_id = Database::escape_string($_GET['lp_id']);
  146. $safe_exe_id = Database::escape_string($_REQUEST['exeId']);
  147. if ($safe_id == strval(intval($safe_id)) && $safe_item_id == strval(intval($safe_item_id))) {
  148. $sql = 'SELECT start_date,exe_date,exe_result,exe_weighting FROM ' . $TBL_TRACK_EXERCICES . ' WHERE exe_id = '.(int)$safe_exe_id;
  149. $res = Database::query($sql);
  150. $row_dates = Database::fetch_array($res);
  151. $time_start_date = convert_mysql_date($row_dates['start_date']);
  152. $time_exe_date = convert_mysql_date($row_dates['exe_date']);
  153. $mytime = ((int)$time_exe_date-(int)$time_start_date);
  154. $score = (float)$row_dates['exe_result'];
  155. $max_score = (float)$row_dates['exe_weighting'];
  156. $sql_upd_status = "UPDATE $TBL_LP_ITEM_VIEW SET status = 'completed' WHERE lp_item_id = '".(int)$safe_item_id."'
  157. AND lp_view_id = (SELECT lp_view.id FROM $TBL_LP_VIEW lp_view WHERE user_id = '".(int)$_SESSION['oLP']->user_id."' AND lp_id='".(int)$safe_id."')";
  158. Database::query($sql_upd_status);
  159. $sql_upd_max_score = "UPDATE $TBL_LP_ITEM SET max_score = '$max_score' WHERE id = '".(int)$safe_item_id."'";
  160. Database::query($sql_upd_max_score);
  161. $sql_last_attempt = "SELECT id FROM $TBL_LP_ITEM_VIEW WHERE lp_item_id = '$safe_item_id' AND lp_view_id = '".$_SESSION['oLP']->lp_view_id."' order by id desc limit 1";
  162. $res_last_attempt = Database::query($sql_last_attempt);
  163. $row_last_attempt = Database::fetch_row($res_last_attempt);
  164. if (Database::num_rows($res_last_attempt)>0) {
  165. $sql_upd_score = "UPDATE $TBL_LP_ITEM_VIEW SET score = $score,total_time = $mytime WHERE id='".$row_last_attempt[0]."'";
  166. Database::query($sql_upd_score);
  167. }
  168. }
  169. if(intval($_GET['fb_type']) > 0) {
  170. $src = 'blank.php?msg=exerciseFinished';
  171. } else {
  172. $src = api_get_path(WEB_CODE_PATH).'exercice/exercise_show.php?id='.Security::remove_XSS($_REQUEST['exeId']).'&origin=learnpath&learnpath_id='.Security::remove_XSS($_GET['lp_id']).'&learnpath_item_id='.Security::remove_XSS($_GET['lp_id']).'&fb_type='.Security::remove_XSS($_GET['fb_type']);
  173. }
  174. $autostart = 'false';
  175. }
  176. $_SESSION['oLP']->set_previous_item($lp_item_id);
  177. $nameTools = Security :: remove_XSS(api_convert_encoding($_SESSION['oLP']->get_name(), $charset, api_get_system_encoding()));
  178. $save_setting = api_get_setting("show_navigation_menu");
  179. global $_setting;
  180. $_setting['show_navigation_menu'] = 'false';
  181. $scorm_css_header=true;
  182. $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)
  183. if($_SESSION['oLP']->mode == 'fullscreen') {
  184. $htmlHeadXtra[] = "<script>window.open('$src','content_id','toolbar=0,location=0,status=0,scrollbars=1,resizable=1');</script>";
  185. }
  186. //not fullscreen mode
  187. require_once '../inc/reduced_header.inc.php';
  188. //$displayAudioRecorder = (api_get_setting('service_visio','active')=='true') ? true : false;
  189. //check if audio recorder needs to be in studentview
  190. $course_id=$_SESSION["_course"]["id"];
  191. if ($_SESSION["status"][$course_id]==5) {
  192. $audio_recorder_studentview = true;
  193. } else {
  194. $audio_recorder_studentview = false;
  195. }
  196. //set flag to ensure lp_header.php is loaded by this script (flag is unset in lp_header.php)
  197. $_SESSION['loaded_lp_view'] = true;
  198. ?>
  199. <body>
  200. <div id="learning_path_main" style="width:100%;height:100%;" >
  201. <div id="learning_path_left_zone" style="float:left;width:280px;height:100%">
  202. <!-- header -->
  203. <div id="header">
  204. <div id="learning_path_header" style="font-size:14px;">
  205. <table>
  206. <tr>
  207. <td>
  208. <a href="lp_controller.php?action=return_to_course_homepage&<?php echo api_get_cidreq(); ?>" target="_self" onclick="window.parent.API.save_asset();"><img src="../img/lp_arrow.gif" /></a>
  209. </td>
  210. <td>
  211. <a class="link" href="lp_controller.php?action=return_to_course_homepage&<?php echo api_get_cidreq(); ?>" target="_self" onclick="window.parent.API.save_asset();">
  212. <?php echo api_convert_encoding(get_lang('CourseHomepageLink'), $charset, api_get_system_encoding()); ?></a>
  213. </td>
  214. </tr>
  215. </table>
  216. </div>
  217. </div>
  218. <!-- end header -->
  219. <!-- Image preview Layout -->
  220. <!-- hub 26-50-2010 for lp toc height
  221. <div id="author_image" name="author_image" class="lp_author_image" style="height:23%; width:100%;margin-left:5px;">
  222. -->
  223. <div id="author_image" name="author_image" class="lp_author_image" style="width:100%;margin-left:5px;">
  224. <?php $image = '../img/lp_author_background.gif'; ?>
  225. <div id="preview_image" style="padding:5px;background-image: url('../img/lp_author_background.gif');background-repeat:no-repeat;height:110px">
  226. <div style="width:100; float:left;height:105;margin:5px">
  227. <span style="width:104px; height:96px; float:left; vertical-align:bottom;">
  228. <center>
  229. <?php
  230. if ($_SESSION['oLP']->get_preview_image()!='') {
  231. $picture = getimagesize(api_get_path(SYS_COURSE_PATH).api_get_course_path().'/upload/learning_path/images/'.$_SESSION['oLP']->get_preview_image());
  232. if($picture['1'] < 96) { $style = ' style="padding-top:'.((94 -$picture['1'])/2).'px;" '; }
  233. $size = ($picture['0'] > 104 && $picture['1'] > 96 )? ' width="104" height="96" ': $style;
  234. $my_path = api_get_path(WEB_COURSE_PATH).api_get_course_path().'/upload/learning_path/images/'.$_SESSION['oLP']->get_preview_image();
  235. echo '<img '.$size.' src="'.$my_path.'">';
  236. } else {
  237. echo Display :: display_icon('unknown_250_100.jpg', ' ');
  238. }
  239. ?>
  240. </center>
  241. </span>
  242. </div>
  243. <div id="nav_id" name="nav_name" class="lp_nav" style="margin-left:105;height:90">
  244. <?php
  245. $display_mode = $_SESSION['oLP']->mode;
  246. $scorm_css_header = true;
  247. $lp_theme_css = $_SESSION['oLP']->get_theme();
  248. //Setting up the CSS theme if exists
  249. if (!empty ($lp_theme_css) && !empty ($mycourselptheme) && $mycourselptheme != -1 && $mycourselptheme == 1) {
  250. global $lp_theme_css;
  251. } else {
  252. $lp_theme_css = $my_style;
  253. }
  254. $progress_bar = $_SESSION['oLP']->get_progress_bar('', -1, '', true);
  255. $navigation_bar = $_SESSION['oLP']->get_navigation_bar();
  256. $mediaplayer = $_SESSION['oLP']->get_mediaplayer($autostart);
  257. $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
  258. $show_audioplayer = false;
  259. // getting all the information about the item
  260. $sql = "SELECT audio FROM " . $tbl_lp_item . " WHERE lp_id = '" . $_SESSION['oLP']->lp_id."'";
  261. $res_media= Database::query($sql);
  262. if (Database::num_rows($res_media) > 0) {
  263. while ($row_media= Database::fetch_array($res_media)) {
  264. if (!empty($row_media['audio'])) {$show_audioplayer = true; break;}
  265. }
  266. }
  267. ?>
  268. <div id="lp_navigation_elem" class="lp_navigation_elem" style="padding-left:130px;margin-top:9px;">
  269. <div style="padding-top:15px;padding-bottom:50px;" ><?php echo $navigation_bar; ?></div>
  270. <div style="height:20px"><?php echo $progress_bar; ?></div>
  271. </div>
  272. </div>
  273. </div>
  274. </div>
  275. <!-- end image preview Layout -->
  276. <div id="author_name" style="position:relative;top:2px;left:0px;margin:0;padding:0;text-align:center;width:100%">
  277. <?php echo $_SESSION['oLP']->get_author(); ?>
  278. </div>
  279. <!-- media player layaout -->
  280. <?php $style_media = (($show_audioplayer)?' style= "position:relative;top:10px;left:10px;margin:8px;font-size:32pt;height:20px;"':'style="height:15px"'); ?>
  281. <div id="media" <?php echo $style_media ?>>
  282. <?php echo (!empty($mediaplayer))?$mediaplayer:'&nbsp;' ?>
  283. </div>
  284. <!-- end media player layaout -->
  285. <!-- toc layout -->
  286. <!-- hub 26-05-2010 remove height for lp toc height resizable
  287. <div id="toc_id" name="toc_name" style="overflow: auto; padding:0;margin-top:20px;height:60%;width:100%">
  288. -->
  289. <div id="toc_id" name="toc_name" style="overflow: auto; padding:0;margin-top:20px;width:100%">
  290. <div id="learning_path_toc" style="font-size:9pt;margin:0;"><?php echo $_SESSION['oLP']->get_html_toc(); ?>
  291. <?php if (!empty($_SESSION['oLP']->scorm_debug)) { //only show log
  292. ?>
  293. <!-- log message layout -->
  294. <div id="lp_log_name" name="lp_log_name" class="lp_log" style="height:150px;overflow:auto;margin:4px">
  295. <div id="log_content"></div>
  296. <div id="log_content_cleaner" style="color: white;">.</div>
  297. </div>
  298. <!-- end log message layout -->
  299. <?php } ?>
  300. </div>
  301. </div>
  302. <!-- end toc layout -->
  303. </div>
  304. <!-- end left Zone -->
  305. <!-- right Zone -->
  306. <div id="learning_path_right_zone" style="margin-left:282px;height:100%">
  307. <?php
  308. // hub 26-05-2010 Fullscreen or not fullscreen
  309. if($_SESSION['oLP']->mode == 'fullscreen') {
  310. echo '<iframe id="content_id_blank" name="content_name_blank" src="blank.php" border="0" frameborder="0" style="width:100%;height:600px" ></iframe>';
  311. } else {
  312. echo '<iframe id="content_id" name="content_name" src="'.$src.'" border="0" frameborder="0" style="width:100%;height:600px" ></iframe>';
  313. }
  314. ?>
  315. </div>
  316. <!-- end right Zone -->
  317. </div>
  318. <script language="JavaScript" type="text/javascript">
  319. // Need to be called after the <head> to be sure window.oxajax is defined
  320. //var dokeos_xajax_handler = window.oxajax;
  321. </script>
  322. <script language="JavaScript" type="text/javascript">
  323. // resize right and left pane to full height (HUB 20-05-2010)
  324. function updateContentHeight() {
  325. document.body.style.overflow = 'hidden';
  326. var IE = window.navigator.appName.match(/microsoft/i);
  327. var hauteurHeader = document.getElementById('header').offsetHeight;
  328. var hauteurAuthorImg = document.getElementById('author_image').offsetHeight;
  329. var hauteurAuthorName = document.getElementById('author_name').offsetHeight;
  330. var hauteurMedia = document.getElementById('media').offsetHeight;
  331. var hauteurTitre = document.getElementById('scorm_title').offsetHeight;
  332. var hauteurAction = 0;
  333. if (document.getElementById('actions_lp')) hauteurAction = document.getElementById('actions_lp').offsetHeight;
  334. var hauteurHaut = hauteurHeader+hauteurAuthorImg+hauteurAuthorName+hauteurMedia+hauteurTitre+hauteurAction;
  335. var innerHauteur = (IE) ? document.body.clientHeight : window.innerHeight ;
  336. var debugsize = 0;
  337. // -40 is a static adjustement for margin, spaces on the page
  338. <?php if (!empty($_SESSION['oLP']->scorm_debug)) echo 'debugsize = 150;' ?>
  339. document.getElementById('inner_lp_toc').style.height = innerHauteur - hauteurHaut - 40 - debugsize + "px";
  340. if (document.getElementById('content_id')) {
  341. document.getElementById('content_id').style.height = innerHauteur + 'px';
  342. }
  343. //loads the glossary library
  344. <?php
  345. if (api_get_setting('show_glossary_in_extra_tools') == 'true') {
  346. if (api_get_setting('show_glossary_in_documents') == 'ismanual') {
  347. ?>
  348. $.frameReady(function(){
  349. // $("<div>I am a div courses</div>").prependTo("body");
  350. }, "top.content_name",
  351. { load: [
  352. {type:"script", id:"_fr1", src:"<?php echo api_get_path(WEB_LIBRARY_PATH); ?>javascript/jquery.js"},
  353. {type:"script", id:"_fr2", src:"<?php echo api_get_path(WEB_LIBRARY_PATH); ?>javascript/jquery.highlight.js"},
  354. {type:"script", id:"_fr3", src:"<?php echo api_get_path(WEB_LIBRARY_PATH); ?>fckeditor/editor/plugins/glossary/fck_glossary_manual.js"}
  355. ] }
  356. );
  357. <?php
  358. } elseif (api_get_setting('show_glossary_in_documents') == 'isautomatic') {
  359. ?>
  360. $.frameReady(function(){
  361. // $("<div>I am a div courses</div>").prependTo("body");
  362. }, "top.content_name",
  363. { load: [
  364. {type:"script", id:"_fr1", src:"<?php echo api_get_path(WEB_LIBRARY_PATH); ?>javascript/jquery.js"},
  365. {type:"script", id:"_fr2", src:"<?php echo api_get_path(WEB_LIBRARY_PATH); ?>javascript/jquery.highlight.js"},
  366. {type:"script", id:"_fr3", src:"<?php echo api_get_path(WEB_LIBRARY_PATH); ?>fckeditor/editor/plugins/glossary/fck_glossary_automatic.js"}
  367. ] }
  368. );
  369. <?php
  370. }
  371. }
  372. ?>
  373. }
  374. window.onload = updateContentHeight;
  375. window.onresize = updateContentHeight;
  376. -->
  377. </script>
  378. </body>
  379. <?php
  380. //restore global setting
  381. $_setting['show_navigation_menu'] = $save_setting;