lp_ajax_switch_item_toc.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This script contains the server part of the xajax interaction process. The client part is located
  5. * in lp_api.php or other api's.
  6. * This script updated the TOC of the SCORM without updating the SCO's attributes
  7. * @package chamilo.learnpath
  8. * @author Yannick Warnier <ywarnier@beeznest.org>
  9. */
  10. /**
  11. * Code
  12. */
  13. // Flag to allow for anonymous user - needs to be set before global.inc.php.
  14. $use_anonymous = true;
  15. // Name of the language file that needs to be included.
  16. $language_file[] = 'learnpath';
  17. require_once '../inc/global.inc.php';
  18. /**
  19. * Get one item's details
  20. * @param integer LP ID
  21. * @param integer user ID
  22. * @param integer View ID
  23. * @param integer Current item ID
  24. * @param integer New item ID
  25. */
  26. function switch_item_toc($lp_id, $user_id, $view_id, $current_item, $next_item) {
  27. $debug = 0;
  28. $return = '';
  29. if ($debug > 0) { error_log('In xajax_switch_item_toc('.$lp_id.','.$user_id.','.$view_id.','.$current_item.','.$next_item.')', 0); }
  30. require_once 'learnpath.class.php';
  31. require_once 'scorm.class.php';
  32. require_once 'aicc.class.php';
  33. require_once 'learnpathItem.class.php';
  34. require_once 'scormItem.class.php';
  35. require_once 'aiccItem.class.php';
  36. $mylp = '';
  37. if (isset($_SESSION['lpobject'])) {
  38. if ($debug > 1) { error_log('$_SESSION[lpobject] is set', 0); }
  39. $oLP = unserialize($_SESSION['lpobject']);
  40. if (!is_object($oLP)) {
  41. if ($debug > 1) { error_log(print_r($oLP, true), 0); }
  42. if ($debug > 2) { error_log('Building new lp', 0); }
  43. unset($oLP);
  44. $code = api_get_course_id();
  45. $mylp = new learnpath($code, $lp_id, $user_id);
  46. } else {
  47. if ($debug > 1) { error_log('Reusing session lp', 0); }
  48. $mylp = $oLP;
  49. }
  50. }
  51. $new_item_id = 0;
  52. switch ($next_item) {
  53. case 'next':
  54. $mylp->set_current_item($current_item);
  55. $mylp->next();
  56. $new_item_id = $mylp->get_current_item_id();
  57. if ($debug > 1) { error_log('In {next} - next item is '.$new_item_id.'(current: '.$current_item.')', 0); }
  58. break;
  59. case 'previous':
  60. $mylp->set_current_item($current_item);
  61. $mylp->previous();
  62. $new_item_id = $mylp->get_current_item_id();
  63. if ($debug > 1) { error_log('In {previous} - next item is '.$new_item_id.'(current: '.$current_item.')', 0); }
  64. break;
  65. case 'first':
  66. $mylp->set_current_item($current_item);
  67. $mylp->first();
  68. $new_item_id = $mylp->get_current_item_id();
  69. if ($debug > 1) { error_log('In {first} - next item is '.$new_item_id.'(current: '.$current_item.')', 0); }
  70. break;
  71. case 'last':
  72. break;
  73. default:
  74. // Should be filtered to check it's not hacked
  75. if($next_item == $current_item){
  76. // If we're opening the same item again.
  77. $mylp->items[$current_item]->restart();
  78. }
  79. $new_item_id = $next_item;
  80. $mylp->set_current_item($new_item_id);
  81. if ($debug > 1) { error_log('In {default} - next item is '.$new_item_id.'(current: '.$current_item.')', 0); }
  82. break;
  83. }
  84. $mylp->start_current_item(true);
  85. if ($mylp->force_commit) {
  86. $mylp->save_current();
  87. }
  88. if (is_object($mylp->items[$new_item_id])) {
  89. $mylpi = $mylp->items[$new_item_id];
  90. } else {
  91. if ($debug > 1) { error_log('In switch_item_details - generating new item object', 0); }
  92. $mylpi = new learnpathItem($new_item_id, $user_id);
  93. $mylpi->set_lp_view($view_id);
  94. }
  95. /*
  96. * now get what's needed by the SCORM API:
  97. * -score
  98. * -max
  99. * -min
  100. * -lesson_status
  101. * -session_time
  102. * -suspend_data
  103. */
  104. $myscore = $mylpi->get_score();
  105. $mymax = $mylpi->get_max();
  106. if ($mymax === '') { $mymax = "''"; }
  107. $mymin = $mylpi->get_min();
  108. $mylesson_status = $mylpi->get_status();
  109. $mylesson_location = $mylpi->get_lesson_location();
  110. $mytotal_time = $mylpi->get_scorm_time('js');
  111. $mymastery_score = $mylpi->get_mastery_score();
  112. $mymax_time_allowed = $mylpi->get_max_time_allowed();
  113. $mylaunch_data = $mylpi->get_launch_data();
  114. $mysession_time = $mylpi->get_total_time();
  115. $mysuspend_data = $mylpi->get_suspend_data();
  116. $mylesson_location = $mylpi->get_lesson_location();
  117. $myic = $mylpi->get_interactions_count();
  118. $myistring = '';
  119. for ($i = 0; $i < $myic; $i++) {
  120. $myistring .= ",[".$i.",'','','','','','','']";
  121. }
  122. if (!empty($myistring)) {
  123. $myistring = substr($myistring, 1);
  124. }
  125. $mytotal = $mylp->get_total_items_count_without_chapters();
  126. $mycomplete = $mylp->get_complete_items_count();
  127. $myprogress_mode = $mylp->get_progress_bar_mode();
  128. $myprogress_mode = ($myprogress_mode == '' ? '%' : $myprogress_mode);
  129. $mynext = $mylp->get_next_item_id();
  130. $myprevious = $mylp->get_previous_item_id();
  131. $myitemtype = $mylpi->get_type();
  132. $mylesson_mode = $mylpi->get_lesson_mode();
  133. $mycredit = $mylpi->get_credit();
  134. $mylaunch_data = $mylpi->get_launch_data();
  135. $myinteractions_count = $mylpi->get_interactions_count();
  136. $myobjectives_count = $mylpi->get_objectives_count();
  137. $mycore_exit = $mylpi->get_core_exit();
  138. $return .=
  139. //"saved_lesson_status='not attempted';" .
  140. "olms.lms_lp_id=".$lp_id.";" .
  141. "olms.lms_item_id=".$new_item_id.";" .
  142. "olms.lms_old_item_id=0;" .
  143. //"lms_been_synchronized=0;" .
  144. "olms.lms_initialized=0;" .
  145. //"lms_total_lessons=".$mytotal.";" .
  146. //"lms_complete_lessons=".$mycomplete.";" .
  147. //"lms_progress_bar_mode='".$myprogress_mode."';" .
  148. "olms.lms_view_id=".$view_id.";" .
  149. "olms.lms_user_id=".$user_id.";" .
  150. "olms.next_item=".$new_item_id.";" . // This one is very important to replace possible literal strings.
  151. "olms.lms_next_item=".$mynext.";" .
  152. "olms.lms_previous_item=".$myprevious.";" .
  153. "olms.lms_item_type = '".$myitemtype."';" .
  154. "olms.lms_item_credit = '".$mycredit."';" .
  155. "olms.lms_item_lesson_mode = '".$mylesson_mode."';" .
  156. "olms.lms_item_launch_data = '".$mylaunch_data."';" .
  157. "olms.lms_item_interactions_count = '".$myinteractions_count."';" .
  158. "olms.lms_item_objectives_count = '".$myinteractions_count."';" .
  159. "olms.lms_item_core_exit = '".$mycore_exit."';" .
  160. "olms.asset_timer = 0;";
  161. $return .= "update_toc('unhighlight','".$current_item."');".
  162. "update_toc('highlight','".$new_item_id."');".
  163. "update_toc('$mylesson_status','".$new_item_id."');".
  164. "update_progress_bar('$mycomplete','$mytotal','$myprogress_mode');";
  165. $mylp->set_error_msg('');
  166. $mylp->prerequisites_match(); // Check the prerequisites are all complete.
  167. if ($debug > 1) { error_log('Prereq_match() returned '.htmlentities($mylp->error), 0); }
  168. $_SESSION['scorm_item_id'] = $new_item_id; // Save the new item ID for the exercise tool to use.
  169. $_SESSION['lpobject'] = serialize($mylp);
  170. return $return;
  171. }
  172. echo switch_item_toc($_POST['lid'], $_POST['uid'], $_POST['vid'], $_POST['iid'], $_POST['next']);