lp_ajax_last_update_status.php 4.9 KB

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