lp_ajax_switch_item_toc.php 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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 'back_compat.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. //$objResponse->addAlert(api_get_path(REL_CODE_PATH).'newscorm/learnpathItem.class.php');
  89. if (is_object($mylp->items[$new_item_id])) {
  90. $mylpi = & $mylp->items[$new_item_id];
  91. } else {
  92. if ($debug > 1) { error_log('In switch_item_details - generating new item object', 0); }
  93. $mylpi = new learnpathItem($new_item_id, $user_id);
  94. $mylpi->set_lp_view($view_id);
  95. }
  96. /*
  97. * now get what's needed by the SCORM API:
  98. * -score
  99. * -max
  100. * -min
  101. * -lesson_status
  102. * -session_time
  103. * -suspend_data
  104. */
  105. $myscore = $mylpi->get_score();
  106. $mymax = $mylpi->get_max();
  107. if ($mymax === '') { $mymax = "''"; }
  108. $mymin = $mylpi->get_min();
  109. $mylesson_status = $mylpi->get_status();
  110. $mylesson_location = $mylpi->get_lesson_location();
  111. $mytotal_time = $mylpi->get_scorm_time('js');
  112. $mymastery_score = $mylpi->get_mastery_score();
  113. $mymax_time_allowed = $mylpi->get_max_time_allowed();
  114. $mylaunch_data = $mylpi->get_launch_data();
  115. /*
  116. if ($mylpi->get_type() == 'asset') {
  117. // 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)
  118. $mylesson_status = 'completed';
  119. $mylpi->set_status('completed');
  120. $mylpi->save();
  121. }
  122. */
  123. $mysession_time = $mylpi->get_total_time();
  124. $mysuspend_data = $mylpi->get_suspend_data();
  125. $mylesson_location = $mylpi->get_lesson_location();
  126. $myic = $mylpi->get_interactions_count();
  127. $myistring = '';
  128. for ($i = 0; $i < $myic; $i++) {
  129. $myistring .= ",[".$i.",'','','','','','','']";
  130. }
  131. if (!empty($myistring)) {
  132. $myistring = substr($myistring, 1);
  133. }
  134. $mytotal = $mylp->get_total_items_count_without_chapters();
  135. $mycomplete = $mylp->get_complete_items_count();
  136. $myprogress_mode = $mylp->get_progress_bar_mode();
  137. $myprogress_mode = ($myprogress_mode == '' ? '%' : $myprogress_mode);
  138. $mynext = $mylp->get_next_item_id();
  139. $myprevious = $mylp->get_previous_item_id();
  140. $myitemtype = $mylpi->get_type();
  141. $mylesson_mode = $mylpi->get_lesson_mode();
  142. $mycredit = $mylpi->get_credit();
  143. $mylaunch_data = $mylpi->get_launch_data();
  144. $myinteractions_count = $mylpi->get_interactions_count();
  145. $myobjectives_count = $mylpi->get_objectives_count();
  146. $mycore_exit = $mylpi->get_core_exit();
  147. $return .=
  148. //"saved_lesson_status='not attempted';" .
  149. "olms.lms_lp_id=".$lp_id.";" .
  150. "olms.lms_item_id=".$new_item_id.";" .
  151. "olms.lms_old_item_id=0;" .
  152. //"lms_been_synchronized=0;" .
  153. "olms.lms_initialized=0;" .
  154. //"lms_total_lessons=".$mytotal.";" .
  155. //"lms_complete_lessons=".$mycomplete.";" .
  156. //"lms_progress_bar_mode='".$myprogress_mode."';" .
  157. "olms.lms_view_id=".$view_id.";" .
  158. "olms.lms_user_id=".$user_id.";" .
  159. "olms.next_item=".$new_item_id.";" . // This one is very important to replace possible literal strings.
  160. "olms.lms_next_item=".$mynext.";" .
  161. "olms.lms_previous_item=".$myprevious.";" .
  162. "olms.lms_item_type = '".$myitemtype."';" .
  163. "olms.lms_item_credit = '".$mycredit."';" .
  164. "olms.lms_item_lesson_mode = '".$mylesson_mode."';" .
  165. "olms.lms_item_launch_data = '".$mylaunch_data."';" .
  166. "olms.lms_item_interactions_count = '".$myinteractions_count."';" .
  167. "olms.lms_item_objectives_count = '".$myinteractions_count."';" .
  168. "olms.lms_item_core_exit = '".$mycore_exit."';" .
  169. "olms.asset_timer = 0;";
  170. $return .= "update_toc('unhighlight','".$current_item."');".
  171. "update_toc('highlight','".$new_item_id."');".
  172. "update_toc('$mylesson_status','".$new_item_id."');".
  173. "update_progress_bar('$mycomplete','$mytotal','$myprogress_mode');";
  174. $mylp->set_error_msg('');
  175. $mylp->prerequisites_match(); // Check the prerequisites are all complete.
  176. if ($debug > 1) { error_log('Prereq_match() returned '.htmlentities($mylp->error), 0); }
  177. $_SESSION['scorm_item_id'] = $new_item_id; // Save the new item ID for the exercise tool to use.
  178. $_SESSION['lpobject'] = serialize($mylp);
  179. return $return;
  180. //return $objResponse;
  181. }
  182. echo switch_item_toc($_POST['lid'], $_POST['uid'], $_POST['vid'], $_POST['iid'], $_POST['next']);