savescores.php 3.7 KB

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