savescores.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. $_cid = api_get_course_id();
  25. $test = $_REQUEST['test'];
  26. $score = $_REQUEST['score'];
  27. $origin = $_REQUEST['origin'];
  28. $documentPath = api_get_path(SYS_COURSE_PATH).$_course['path']."/document";
  29. $full_file_path = $documentPath.$test;
  30. FileManager::my_delete($full_file_path.$_user['user_id'].".t.html");
  31. $TABLETRACK_HOTPOTATOES = Database::get_main_table(TABLE_STATISTIC_TRACK_E_HOTPOTATOES);
  32. $tbl_learnpath_user = Database::get_course_table(TABLE_LEARNPATH_USER);
  33. $TABLE_LP_ITEM_VIEW = Database::get_course_table(TABLE_LP_ITEM_VIEW);
  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, $TABLETRACK_HOTPOTATOES;
  47. $weighting = 100; // 100%
  48. $date = api_get_utc_datetime();
  49. if ($_user['user_id']) {
  50. $user_id = $_user['user_id'];
  51. } else {
  52. // anonymous
  53. $user_id = "NULL";
  54. }
  55. $sql = "INSERT INTO $TABLETRACK_HOTPOTATOES (exe_name, exe_user_id, exe_date, c_id, exe_result, exe_weighting) VALUES (
  56. '".Database::escape_string($file)."',
  57. '".Database::escape_string($user_id)."',
  58. '".Database::escape_string($date)."',
  59. '".api_get_course_int_id()."',
  60. '".Database::escape_string($score)."',
  61. '".Database::escape_string($weighting)."')";
  62. Database::query($sql);
  63. if ($origin == 'learnpath') {
  64. //if we are in a learning path, save the score in the corresponding
  65. //table to get tracking in there as well
  66. global $jscript2run;
  67. //record the results in the learning path, using the SCORM interface (API)
  68. $jscript2run .= "<script>
  69. $(document).ready(function() {
  70. //API_obj = window.frames.window.content.API;
  71. //API_obj = $('content_id').context.defaultView.content.API; //works only in FF
  72. //API_obj = window.parent.frames.window.top.API;
  73. API_obj = window.top.API;
  74. API_obj.void_save_asset('$score', '$weighting', 0, 'completed');
  75. });
  76. </script>";
  77. }
  78. }
  79. // Save the Scores
  80. save_scores($test, $score);
  81. // Back
  82. if ($origin != 'learnpath') {
  83. $url = "exercice.php"; // back to exercices
  84. $jscript2run .= '<script>'."window.open('$url', '_top', '')".'</script>';
  85. echo $jscript2run;
  86. } else {
  87. $htmlHeadXtra[] = $jscript2run;
  88. Display::display_reduced_header();
  89. Display::display_confirmation_message(get_lang('HotPotatoesFinished'));
  90. Display::display_footer();
  91. }