savescores.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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 ($_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. $this_section=SECTION_COURSES;
  21. require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php';
  22. $documentPath = api_get_path(SYS_COURSE_PATH).$_course['path']."/document";
  23. $full_file_path = $documentPath.$test;
  24. my_delete($full_file_path.$_user['user_id'].".t.html");
  25. $TABLETRACK_HOTPOTATOES = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_HOTPOTATOES);
  26. $tbl_learnpath_user = Database::get_course_table(TABLE_LEARNPATH_USER);
  27. $TABLE_LP_ITEM_VIEW = Database::get_course_table(TABLE_LP_ITEM_VIEW);
  28. $_cid = api_get_course_id();
  29. $test = $_REQUEST['test'];
  30. $score = $_REQUEST['score'];
  31. $origin = $_REQUEST['origin'];
  32. $jscript2run = '';
  33. /**
  34. * Save the score for a HP quiz. Can be used by the learnpath tool as well
  35. * for HotPotatoes quizzes. When coming from the learning path, we
  36. * use the session variables telling us which item of the learning path has to
  37. * be updated (score-wise)
  38. * @param string File is the exercise name (the file name for a HP)
  39. * @param integer Score to save inside the tracking tables (HP and learnpath)
  40. * @return void
  41. */
  42. function save_scores($file, $score) {
  43. global $origin, $_user, $_cid,
  44. $TABLETRACK_HOTPOTATOES;
  45. // if tracking is disabled record nothing
  46. $weighting = 100; // 100%
  47. $reallyNow = time();
  48. $date = date("Y-m-d H:i:s", $reallyNow);
  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 ".
  56. "(exe_name, exe_user_id, exe_date,exe_cours_id,exe_result,exe_weighting)" .
  57. "VALUES" .
  58. "(
  59. '".Database::escape_string($file)."',
  60. '".Database::escape_string($user_id)."',
  61. '".Database::escape_string($date)."',
  62. '".Database::escape_string($_cid)."',
  63. '".Database::escape_string($score)."',
  64. '".Database::escape_string($weighting)."')";
  65. $res = 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 language="javascript" type="text/javascript">window.parent.API.void_save_asset('.$score.','.$weighting.');</script>';
  72. }
  73. }
  74. // Save the Scores
  75. save_scores($test, $score);
  76. // Back
  77. if ($origin != 'learnpath') {
  78. // $url = "Hpdownload.php?doc_url=".$test."&cid=".$cid; // back to the test
  79. $url = "exercice.php"; // back to exercices
  80. $jscript2run .= '<script language="javascript" type="text/javascript">'."window.open('$url', '_top', '')".'</script>';
  81. echo $jscript2run;
  82. } else {
  83. ?>
  84. <!DOCTYPE html
  85. PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  86. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  87. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo api_get_language_isocode(); ?>" lang="<?php echo api_get_language_isocode(); ?>">
  88. <head>
  89. <meta http-equiv="Content-Type" content="text/html; charset=<?php echo api_get_system_encoding(); ?>" />
  90. <link rel='stylesheet' type='text/css' href='../css/<?php echo api_get_setting('stylesheets');?>/scorm.css' />
  91. <?php echo $jscript2run; ?>
  92. </head>
  93. <body dir="<?php echo api_get_text_direction(); ?>">
  94. <br />
  95. <div class='message'>
  96. <?php echo get_lang('HotPotatoesFinished'); ?>
  97. </div>
  98. </body>
  99. </html>
  100. <?php
  101. }
  102. ?>