savescores.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Saving the scores.
  5. * @package chamilo.exercise
  6. * @author
  7. * @version $Id: savescores.php 15602 2008-06-18 08:52:24Z pcool $
  8. */
  9. require_once '../inc/global.inc.php';
  10. $courseInfo = api_get_course_info();
  11. $_user = api_get_user_info();
  12. $this_section = SECTION_COURSES;
  13. $documentPath = api_get_path(SYS_COURSE_PATH).$courseInfo['path']."/document";
  14. $test = $_REQUEST['test'];
  15. $full_file_path = $documentPath.$test;
  16. my_delete($full_file_path.$_user['user_id'].".t.html");
  17. $TABLETRACK_HOTPOTATOES = Database::get_main_table(TABLE_STATISTIC_TRACK_E_HOTPOTATOES);
  18. $TABLE_LP_ITEM_VIEW = Database::get_course_table(TABLE_LP_ITEM_VIEW);
  19. $score = $_REQUEST['score'];
  20. $origin = $_REQUEST['origin'];
  21. $learnpath_item_id = intval($_REQUEST['learnpath_item_id']);
  22. $lpViewId = isset($_REQUEST['lp_view_id']) ? intval($_REQUEST['lp_view_id']) : null;
  23. $course_id = $courseInfo['real_id'];
  24. $jscript2run = '';
  25. /**
  26. * Save the score for a HP quiz. Can be used by the learnpath tool as well
  27. * for HotPotatoes quizzes. When coming from the learning path, we
  28. * use the session variables telling us which item of the learning path has to
  29. * be updated (score-wise)
  30. * @param string File is the exercise name (the file name for a HP)
  31. * @param integer Score to save inside the tracking tables (HP and learnpath)
  32. * @return void
  33. */
  34. function save_scores($file, $score)
  35. {
  36. global $origin, $_user, $TABLETRACK_HOTPOTATOES;
  37. // if tracking is disabled record nothing
  38. $weighting = 100; // 100%
  39. $date = api_get_utc_datetime();
  40. $c_id = api_get_course_int_id();
  41. if ($_user['user_id']) {
  42. $user_id = $_user['user_id'];
  43. } else {
  44. // anonymous
  45. $user_id = "NULL";
  46. }
  47. $params = [
  48. 'exe_name' => $file,
  49. 'exe_user_id' => $user_id,
  50. 'exe_date' => $date,
  51. 'c_id' => $c_id,
  52. 'exe_result' => $score,
  53. 'exe_weighting' => $weighting,
  54. ];
  55. Database::insert($TABLETRACK_HOTPOTATOES, $params);
  56. if ($origin == 'learnpath') {
  57. //if we are in a learning path, save the score in the corresponding
  58. //table to get tracking in there as well
  59. global $jscript2run;
  60. //record the results in the learning path, using the SCORM interface (API)
  61. $jscript2run .= "<script>
  62. $(document).ready(function() {
  63. //API_obj = window.frames.window.content.API;
  64. //API_obj = $('content_id').context.defaultView.content.API; //works only in FF
  65. //API_obj = window.parent.frames.window.top.API;
  66. API_obj = window.top.API;
  67. API_obj.void_save_asset('$score', '$weighting', 0, 'completed');
  68. });
  69. </script>";
  70. }
  71. }
  72. // Save the Scores
  73. save_scores($test, $score);
  74. // Back
  75. if ($origin != 'learnpath') {
  76. $url = "exercise.php"; // back to exercises
  77. $jscript2run .= '<script>'."window.open('$url', '_top', '')".'</script>';
  78. echo $jscript2run;
  79. } else {
  80. $htmlHeadXtra[] = $jscript2run;
  81. Display::display_reduced_header();
  82. if (!empty($course_id) && !empty($learnpath_item_id) && !empty($lpViewId)) {
  83. $sql = "UPDATE $TABLE_LP_ITEM_VIEW SET
  84. status = 'completed'
  85. WHERE
  86. c_id = $course_id AND
  87. lp_item_id= $learnpath_item_id AND
  88. lp_view_id = $lpViewId
  89. ";
  90. Database::query($sql);
  91. Display::display_confirmation_message(get_lang('HotPotatoesFinished'));
  92. } else {
  93. Display::display_error_message(get_lang('Error'));
  94. }
  95. Display::display_footer();
  96. }