lp_ajax_last_update_status.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. // Flag to allow for anonymous user - needs to be set before global.inc.php'
  23. $use_anonymous = true;
  24. // Name of the language file that needs to be included.
  25. $language_file[] = 'learnpath';
  26. require_once 'back_compat.inc.php';
  27. /**
  28. * Writes an item's new values into the database and returns the operation result
  29. * @param integer Learnpath ID
  30. * @param integer User ID
  31. * @param integer View ID
  32. * @param integer Item ID
  33. * @return string JavaScript operations to execute as soon as returned
  34. */
  35. function last_update_status($lp_id, $user_id, $view_id, $item_id) {
  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. if ($debug > 1) { error_log('////$_SESSION[lpobject] is set', 0); }
  48. $oLP =& unserialize($_SESSION['lpobject']);
  49. if (!is_object($oLP)) {
  50. if ($debug > 2) { 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 > 2) { error_log('////Reusing session lp', 0); }
  57. $mylp = & $oLP;
  58. }
  59. }
  60. error_log(__LINE__);
  61. // This function should only be used for SCORM paths.
  62. if ($mylp->get_type() != 2) {
  63. return;
  64. }
  65. $prereq_check = $mylp->prerequisites_match($item_id);
  66. $mystatus = '';
  67. if ($prereq_check === true) {
  68. error_log(__LINE__);
  69. // Launch the prerequisites check and set error if needed.
  70. $mylpi =& $mylp->items[$item_id];
  71. $mystatus_in_db = $mylpi->get_status(true);
  72. error_log($mystatus_in_db);
  73. if ($mystatus_in_db == 'not attempted' or $mystatus_in_db == '') {
  74. error_log(__LINE__);
  75. $mystatus = 'completed';
  76. $mastery_score = $mylpi->get_mastery_score();
  77. if ($mastery_score != -1) {
  78. error_log(__LINE__);
  79. $score = $mylpi->get_score();
  80. if ($score != 0 && $score >= $mastery_score) {
  81. error_log(__LINE__);
  82. $mystatus = 'passed';
  83. } else {
  84. error_log(__LINE__);
  85. $mystatus = 'failed';
  86. }
  87. }
  88. error_log(__LINE__);
  89. $mylpi->set_status($mystatus);
  90. $mylp->save_item($item_id, false);
  91. } else {
  92. error_log(__LINE__);
  93. return $return;
  94. }
  95. } else {
  96. error_log(__LINE__);
  97. return $return;
  98. }
  99. error_log(__LINE__);
  100. $mytotal = $mylp->get_total_items_count_without_chapters();
  101. $mycomplete = $mylp->get_complete_items_count();
  102. $myprogress_mode = $mylp->get_progress_bar_mode();
  103. $myprogress_mode = ($myprogress_mode==''?'%':$myprogress_mode);
  104. $return .= "update_toc('".$mystatus."','".$item_id."','no');";
  105. error_log('Return is now '.$return);
  106. $update_list = $mylp->get_update_queue();
  107. foreach ($update_list as $my_upd_id => $my_upd_status) {
  108. 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.
  109. $return .= "update_toc('".$my_upd_status."','".$my_upd_id."','no');";
  110. }
  111. }
  112. $return .= "update_progress_bar('$mycomplete','$mytotal','$myprogress_mode');";
  113. $return .="update_stats();";
  114. return $return;
  115. //return $objResponse;
  116. }
  117. error_log(__LINE__);
  118. echo last_update_status(
  119. $_REQUEST['lid'],
  120. $_REQUEST['uid'],
  121. $_REQUEST['vid'],
  122. $_REQUEST['iid']);