lp_ajax_last_update_status.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. $app['template.show_footer'] = false;
  31. $app['template.show_header'] = false;
  32. $app['default_layout'] = 'default/layout/blank.tpl';
  33. /**
  34. * Writes an item's new values into the database and returns the operation result
  35. * @param integer Learnpath ID
  36. * @param integer User ID
  37. * @param integer View ID
  38. * @param integer Item ID
  39. * @return string JavaScript operations to execute as soon as returned
  40. */
  41. function last_update_status($lp_id, $user_id, $view_id, $item_id) {
  42. error_log(__LINE__);
  43. global $_configuration;
  44. $debug = 0;
  45. $return = '';
  46. if ($debug > 0) { error_log('In last_update_status('.$lp_id.','.$user_id.','.$view_id.','.$item_id.')', 0); }
  47. require_once 'learnpath.class.php';
  48. require_once 'scorm.class.php';
  49. require_once 'learnpathItem.class.php';
  50. require_once 'scormItem.class.php';
  51. $mylp = '';
  52. if (isset($_SESSION['lpobject'])) {
  53. if ($debug > 1) { error_log('$_SESSION[lpobject] is set', 0); }
  54. $oLP = unserialize($_SESSION['lpobject']);
  55. if (!is_object($oLP)) {
  56. if ($debug > 2) { error_log(print_r($oLP, true), 0); }
  57. if ($debug > 2) { error_log('Building new lp', 0); }
  58. unset($oLP);
  59. $code = api_get_course_id();
  60. $mylp = new learnpath($code,$lp_id,$user_id);
  61. } else {
  62. if ($debug > 2) { error_log('Reusing session lp', 0); }
  63. $mylp = $oLP;
  64. }
  65. }
  66. error_log(__LINE__);
  67. // This function should only be used for SCORM paths.
  68. if ($mylp->get_type() != 2) {
  69. return;
  70. }
  71. $prereq_check = $mylp->prerequisites_match($item_id);
  72. $mystatus = '';
  73. if ($prereq_check === true) {
  74. error_log(__LINE__);
  75. // Launch the prerequisites check and set error if needed.
  76. $mylpi =& $mylp->items[$item_id];
  77. $mystatus_in_db = $mylpi->get_status(true);
  78. error_log($mystatus_in_db);
  79. if ($mystatus_in_db == 'not attempted' or $mystatus_in_db == '') {
  80. error_log(__LINE__);
  81. $mystatus = 'completed';
  82. $mastery_score = $mylpi->get_mastery_score();
  83. if ($mastery_score != -1) {
  84. error_log(__LINE__);
  85. $score = $mylpi->get_score();
  86. if ($score != 0 && $score >= $mastery_score) {
  87. error_log(__LINE__);
  88. $mystatus = 'passed';
  89. } else {
  90. error_log(__LINE__);
  91. $mystatus = 'failed';
  92. }
  93. }
  94. error_log(__LINE__);
  95. $mylpi->set_status($mystatus);
  96. $mylp->save_item($item_id, false);
  97. } else {
  98. error_log(__LINE__);
  99. return $return;
  100. }
  101. } else {
  102. error_log(__LINE__);
  103. return $return;
  104. }
  105. error_log(__LINE__);
  106. $mytotal = $mylp->get_total_items_count_without_chapters();
  107. $mycomplete = $mylp->get_complete_items_count();
  108. $myprogress_mode = $mylp->get_progress_bar_mode();
  109. $myprogress_mode = ($myprogress_mode==''?'%':$myprogress_mode);
  110. $return .= "update_toc('".$mystatus."','".$item_id."','no');";
  111. error_log('Return is now '.$return);
  112. $update_list = $mylp->get_update_queue();
  113. foreach ($update_list as $my_upd_id => $my_upd_status) {
  114. 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.
  115. $return .= "update_toc('".$my_upd_status."','".$my_upd_id."','no');";
  116. }
  117. }
  118. $return .= "update_progress_bar('$mycomplete','$mytotal','$myprogress_mode');";
  119. $return .="update_stats();";
  120. return $return;
  121. //return $objResponse;
  122. }
  123. error_log(__LINE__);
  124. echo last_update_status(
  125. $_REQUEST['lid'],
  126. $_REQUEST['uid'],
  127. $_REQUEST['vid'],
  128. $_REQUEST['iid']
  129. );