lp_ajax_switch_item_toc.php 7.8 KB

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