savescores.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 ($_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. require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php';
  25. $documentPath = api_get_path(SYS_COURSE_PATH).$_course['path']."/document";
  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. $tbl_learnpath_user = Database::get_course_table(TABLE_LEARNPATH_USER);
  30. $TABLE_LP_ITEM_VIEW = Database::get_course_table(TABLE_LP_ITEM_VIEW);
  31. $_cid = api_get_course_id();
  32. $test = $_REQUEST['test'];
  33. $score = $_REQUEST['score'];
  34. $origin = $_REQUEST['origin'];
  35. $jscript2run = '';
  36. /**
  37. * Save the score for a HP quiz. Can be used by the learnpath tool as well
  38. * for HotPotatoes quizzes. When coming from the learning path, we
  39. * use the session variables telling us which item of the learning path has to
  40. * be updated (score-wise)
  41. * @param string File is the exercise name (the file name for a HP)
  42. * @param integer Score to save inside the tracking tables (HP and learnpath)
  43. * @return void
  44. */
  45. function save_scores($file, $score) {
  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 ".
  58. "(exe_name, exe_user_id, exe_date,exe_cours_id,exe_result,exe_weighting)" .
  59. "VALUES" .
  60. "(
  61. '".Database::escape_string($file)."',
  62. '".Database::escape_string($user_id)."',
  63. '".Database::escape_string($date)."',
  64. '".Database::escape_string($_cid)."',
  65. '".Database::escape_string($score)."',
  66. '".Database::escape_string($weighting)."')";
  67. Database::query($sql);
  68. if ($origin == 'learnpath') {
  69. //if we are in a learning path, save the score in the corresponding
  70. //table to get tracking in there as well
  71. global $jscript2run;
  72. //record the results in the learning path, using the SCORM interface (API)
  73. $jscript2run .= '<script>window.parent.API.void_save_asset('.$score.','.$weighting.');</script>';
  74. }
  75. }
  76. // Save the Scores
  77. save_scores($test, $score);
  78. // Back
  79. if ($origin != 'learnpath') {
  80. $url = "exercice.php"; // back to exercices
  81. $jscript2run .= '<script>'."window.open('$url', '_top', '')".'</script>';
  82. echo $jscript2run;
  83. } else {
  84. $htmlHeadXtra[] = $jscript2run;
  85. Display::display_header();
  86. echo get_lang('HotPotatoesFinished');
  87. Display::display_footer();
  88. }