lp_ajax_initialize.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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, in particular, enables the process of SCO's initialization. It
  6. * resets the JavaScript values for each SCO to the current LMS status.
  7. * @package dokeos.learnpath
  8. * @author Yannick Warnier <ywarnier@beeznest.org>
  9. */
  10. /**
  11. * Script
  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 initialize_item($lp_id,$user_id,$view_id,$next_item)
  27. {
  28. $debug=0;
  29. $return = '';
  30. if($debug>0){error_log('In initialize_item('.$lp_id.','.$user_id.','.$view_id.','.$next_item.')',0);}
  31. //$objResponse = new xajaxResponse();
  32. /*$item_id may be one of:
  33. * -'next'
  34. * -'previous'
  35. * -'first'
  36. * -'last'
  37. * - a real item ID
  38. */
  39. require_once('learnpath.class.php');
  40. require_once('scorm.class.php');
  41. require_once('aicc.class.php');
  42. require_once('learnpathItem.class.php');
  43. require_once('scormItem.class.php');
  44. require_once('aiccItem.class.php');
  45. $mylp = '';
  46. if (isset($_SESSION['lpobject'])) {
  47. if ($debug>1) {error_log('////$_SESSION[lpobject] is set',0);}
  48. $oLP =& unserialize($_SESSION['lpobject']);
  49. if (!is_object($oLP)) {
  50. if($debug>1){error_log(print_r($oLP,true),0);}
  51. if($debug>2){error_log('////Building new lp',0);}
  52. unset($oLP);
  53. $code = api_get_course_id();
  54. $mylp = & new learnpath($code,$lp_id,$user_id);
  55. } else {
  56. if($debug>1){error_log('////Reusing session lp',0);}
  57. $mylp = & $oLP;
  58. }
  59. }
  60. $mylp->set_current_item($next_item);
  61. if ($debug>1) {error_log('In {default} - item is '.$new_item_id,0);}
  62. $mylp->start_current_item(true);
  63. /*
  64. if ($mylp->force_commit) {
  65. $mylp->save_current();
  66. }
  67. */
  68. //$objResponse->addAlert(api_get_path(REL_CODE_PATH).'newscorm/learnpathItem.class.php');
  69. if (is_object($mylp->items[$next_item])) {
  70. $mylpi = & $mylp->items[$next_item];
  71. } else {
  72. if($debug>1){error_log('In switch_item_details - generating new item object',0);}
  73. $mylpi =& new learnpathItem($next_item,$user_id);
  74. $mylpi->set_lp_view($view_id);
  75. }
  76. /*
  77. * now get what's needed by the SCORM API:
  78. * -score
  79. * -max
  80. * -min
  81. * -lesson_status
  82. * -session_time
  83. * -suspend_data
  84. */
  85. $myscore = $mylpi->get_score();
  86. $mymax = $mylpi->get_max();
  87. if($mymax===''){$mymax="''";}
  88. $mymin = $mylpi->get_min();
  89. $mylesson_status = $mylpi->get_status();
  90. $mylesson_location = $mylpi->get_lesson_location();
  91. $mytotal_time = $mylpi->get_scorm_time('js');
  92. $mymastery_score = $mylpi->get_mastery_score();
  93. $mymax_time_allowed = $mylpi->get_max_time_allowed();
  94. $mylaunch_data = $mylpi->get_launch_data();
  95. $mysession_time = $mylpi->get_total_time();
  96. $mysuspend_data = $mylpi->get_suspend_data();
  97. $mylesson_location = $mylpi->get_lesson_location();
  98. $myic = $mylpi->get_interactions_count();
  99. $myistring = '';
  100. for ($i=0;$i<$myic;$i++) {
  101. $myistring .= ",[".$i.",'','','','','','','']";
  102. }
  103. if (!empty($myistring)) {
  104. $myistring = substr($myistring,1);
  105. }
  106. $return .=
  107. "olms.score=".$myscore.";" .
  108. "olms.max=".$mymax.";" .
  109. "olms.min=".$mymin.";" .
  110. "olms.lesson_status='".$mylesson_status."';" .
  111. "olms.lesson_location='".$mylesson_location."';" .
  112. "olms.session_time='".$mysession_time."';" .
  113. "olms.suspend_data='".$mysuspend_data."';" .
  114. "olms.total_time = '".$mytotal_time."';" .
  115. "olms.mastery_score = '".$mymastery_score."';" .
  116. "olms.max_time_allowed = '".$mymax_time_allowed."';" .
  117. "olms.launch_data = '".$mylaunch_data."';" .
  118. "olms.interactions = new Array(".$myistring.");" .
  119. "olms.item_objectives = new Array();" .
  120. "olms.G_lastError = 0;" .
  121. "olms.G_LastErrorMessage = 'No error';" ;
  122. /*
  123. * and re-initialise the rest (proper to the LMS)
  124. * -lms_lp_id
  125. * -lms_item_id
  126. * -lms_old_item_id
  127. * -lms_new_item_id
  128. * -lms_initialized
  129. * -lms_progress_bar_mode
  130. * -lms_view_id
  131. * -lms_user_id
  132. */
  133. $mytotal = $mylp->get_total_items_count_without_chapters();
  134. $mycomplete = $mylp->get_complete_items_count();
  135. $myprogress_mode = $mylp->get_progress_bar_mode();
  136. $myprogress_mode = ($myprogress_mode==''?'%':$myprogress_mode);
  137. $mynext = $mylp->get_next_item_id();
  138. $myprevious = $mylp->get_previous_item_id();
  139. $myitemtype = $mylpi->get_type();
  140. $mylesson_mode = $mylpi->get_lesson_mode();
  141. $mycredit = $mylpi->get_credit();
  142. $mylaunch_data = $mylpi->get_launch_data();
  143. $myinteractions_count = $mylpi->get_interactions_count();
  144. $myobjectives_count = $mylpi->get_objectives_count();
  145. $mycore_exit = $mylpi->get_core_exit();
  146. $return .=
  147. "olms.lms_lp_id=".$lp_id.";" .
  148. "olms.lms_item_id=".$next_item.";" .
  149. "olms.lms_old_item_id=0;" .
  150. "olms.lms_initialized=0;" .
  151. "olms.lms_view_id=".$view_id.";" .
  152. "olms.lms_user_id=".$user_id.";" .
  153. "olms.next_item=".$next_item.";" . //this one is very important to replace possible literal strings
  154. "olms.lms_next_item=".$mynext.";" .
  155. "olms.lms_previous_item=".$myprevious.";" .
  156. "olms.lms_item_type = '".$myitemtype."';" .
  157. "olms.lms_item_credit = '".$mycredit."';" .
  158. "olms.lms_item_lesson_mode = '".$mylesson_mode."';" .
  159. "olms.lms_item_launch_data = '".$mylaunch_data."';" .
  160. "olms.lms_item_interactions_count = '".$myinteractions_count."';" .
  161. "olms.lms_item_objectives_count = '".$myinteractions_count."';" .
  162. "olms.lms_item_core_exit = '".$mycore_exit."';" .
  163. "olms.asset_timer = 0;";
  164. $mylp->set_error_msg('');
  165. $mylp->prerequisites_match(); //check the prerequisites are all complete
  166. if($debug>1){error_log('Prereq_match() returned '.htmlentities($mylp->error),0);}
  167. //$_SESSION['scorm_item_id'] = $new_item_id;//Save the new item ID for the exercise tool to use
  168. //$_SESSION['lpobject'] = serialize($mylp);
  169. return $return;
  170. }
  171. echo initialize_item($_POST['lid'],$_POST['uid'],$_POST['vid'],$_POST['iid']);