savescores.php 4.2 KB

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