savescores.php 3.6 KB

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