lp_ajax_last_update_status.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php //$id$
  2. /**
  3. * This script contains the server part of the xajax interaction process. The
  4. * client part is located in lp_api.php or other api's.
  5. * This script exists exclusively to comply with the SCORM 1.2 rules notes that
  6. * say that if the SCO doesn't give a status throughout its execution, then the
  7. * status should be automatically set to 'completed', then the score should be
  8. * evaluated against mastery_score and, if a raw score and mastery_score value
  9. * are set, assign the final status based on that.
  10. * As such, this script will:
  11. * 1 - check the current status for the given element is still 'not attempted'
  12. * 2 - check if there is a mastery score
  13. * 3 - check if there is a raw score
  14. * 4 - if 2 or 3 are false, change the status to 'completed', else compare
  15. * whether the raw score is higher than the mastery score. If not, the status
  16. * will be set to 'failed', if yes, the status will be set to 'passed'
  17. * 5 - update the status in the table of contents
  18. * @package dokeos.learnpath
  19. * @author Yannick Warnier <yannick.warnier@dokeos.com>
  20. */
  21. //flag to allow for anonymous user - needs to be set before global.inc.php
  22. $use_anonymous = true;
  23. // name of the language file that needs to be included
  24. $language_file[] = 'learnpath';
  25. require_once('back_compat.inc.php');
  26. /**
  27. * Writes an item's new values into the database and returns the operation result
  28. * @param integer Learnpath ID
  29. * @param integer User ID
  30. * @param integer View ID
  31. * @param integer Item ID
  32. * @return string JavaScript operations to execute as soon as returned
  33. */
  34. function last_update_status($lp_id,$user_id,$view_id,$item_id)
  35. {
  36. error_log(__LINE__);
  37. global $_configuration;
  38. $debug=0;
  39. $return = '';
  40. if($debug>0){error_log('In last_update_status('.$lp_id.','.$user_id.','.$view_id.','.$item_id.')',0);}
  41. require_once('learnpath.class.php');
  42. require_once('scorm.class.php');
  43. require_once('learnpathItem.class.php');
  44. require_once('scormItem.class.php');
  45. $mylp = '';
  46. if(isset($_SESSION['lpobject']))
  47. {
  48. if($debug>1){error_log('////$_SESSION[lpobject] is set',0);}
  49. $oLP =& unserialize($_SESSION['lpobject']);
  50. if(!is_object($oLP)){
  51. if($debug>2){error_log(print_r($oLP,true),0);}
  52. if($debug>2){error_log('////Building new lp',0);}
  53. unset($oLP);
  54. $code = api_get_course_id();
  55. $mylp = & new learnpath($code,$lp_id,$user_id);
  56. }else{
  57. if($debug>2){error_log('////Reusing session lp',0);}
  58. $mylp = & $oLP;
  59. }
  60. }
  61. error_log(__LINE__);
  62. // this function should only be used for SCORM paths
  63. if ($mylp->get_type()!=2) {
  64. return;
  65. }
  66. $prereq_check = $mylp->prerequisites_match($item_id);
  67. $mystatus = '';
  68. if ($prereq_check === true) {
  69. error_log(__LINE__);
  70. //launch the prerequisites check and set error if needed
  71. $mylpi =& $mylp->items[$item_id];
  72. $mystatus_in_db = $mylpi->get_status(true);
  73. error_log($mystatus_in_db);
  74. if ($mystatus_in_db == 'not attempted' or $mystatus_in_db == '') {
  75. error_log(__LINE__);
  76. $mystatus = 'completed';
  77. $mastery_score = $mylpi->get_mastery_score();
  78. if ($mastery_score != -1) {
  79. error_log(__LINE__);
  80. $score = $mylpi->get_score();
  81. if ($score != 0 && $score >= $mastery_score) {
  82. error_log(__LINE__);
  83. $mystatus = 'passed';
  84. } else {
  85. error_log(__LINE__);
  86. $mystatus = 'failed';
  87. }
  88. }
  89. error_log(__LINE__);
  90. $mylpi->set_status($mystatus);
  91. $mylp->save_item($item_id,false);
  92. } else {
  93. error_log(__LINE__);
  94. return $return;
  95. }
  96. } else {
  97. error_log(__LINE__);
  98. return $return;
  99. }
  100. error_log(__LINE__);
  101. $mytotal = $mylp->get_total_items_count_without_chapters();
  102. $mycomplete = $mylp->get_complete_items_count();
  103. $myprogress_mode = $mylp->get_progress_bar_mode();
  104. $myprogress_mode = ($myprogress_mode==''?'%':$myprogress_mode);
  105. $return .= "update_toc('".$mystatus."','".$item_id."','no');";
  106. error_log('Return is now '.$return);
  107. $update_list = $mylp->get_update_queue();
  108. foreach ($update_list as $my_upd_id => $my_upd_status) {
  109. if ($my_upd_id != $item_id) { //only update the status from other items (i.e. parents and brothers), do not update current as we just did it already
  110. $return .= "update_toc('".$my_upd_status."','".$my_upd_id."','no');";
  111. }
  112. }
  113. $return .= "update_progress_bar('$mycomplete','$mytotal','$myprogress_mode');";
  114. $return .="update_stats();";
  115. return $return;
  116. //return $objResponse;
  117. }
  118. error_log(__LINE__);
  119. echo last_update_status(
  120. $_GET['lid'],
  121. $_GET['uid'],
  122. $_GET['vid'],
  123. $_GET['iid']);