lp_ajax_switch_item_toc.php 7.6 KB

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