savescores.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. $reallyNow = time();
  51. $date = date("Y-m-d H:i:s", $reallyNow);
  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 ".
  59. "(exe_name, exe_user_id, exe_date,exe_cours_id,exe_result,exe_weighting)" .
  60. "VALUES" .
  61. "(
  62. '".Database::escape_string($file)."',
  63. '".Database::escape_string($user_id)."',
  64. '".Database::escape_string($date)."',
  65. '".Database::escape_string($_cid)."',
  66. '".Database::escape_string($score)."',
  67. '".Database::escape_string($weighting)."')";
  68. $res = Database::query($sql);
  69. if ($origin == 'learnpath') {
  70. //if we are in a learning path, save the score in the corresponding
  71. //table to get tracking in there as well
  72. global $jscript2run;
  73. //record the results in the learning path, using the SCORM interface (API)
  74. $jscript2run .= '<script language="javascript" type="text/javascript">window.parent.API.void_save_asset('.$score.','.$weighting.');</script>';
  75. }
  76. }
  77. // Save the Scores
  78. save_scores($test, $score);
  79. // Back
  80. if ($origin != 'learnpath') {
  81. // $url = "Hpdownload.php?doc_url=".$test."&cid=".$cid; // back to the test
  82. $url = "exercice.php"; // back to exercices
  83. $jscript2run .= '<script language="javascript" type="text/javascript">'."window.open('$url', '_top', '')".'</script>';
  84. echo $jscript2run;
  85. } else {
  86. ?>
  87. <!DOCTYPE html
  88. PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  89. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  90. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo api_get_language_isocode(); ?>" lang="<?php echo api_get_language_isocode(); ?>">
  91. <head>
  92. <meta http-equiv="Content-Type" content="text/html; charset=<?php echo api_get_system_encoding(); ?>" />
  93. <link rel='stylesheet' type='text/css' href='../css/<?php echo api_get_setting('stylesheets');?>/scorm.css' />
  94. <?php echo $jscript2run; ?>
  95. </head>
  96. <body dir="<?php echo api_get_text_direction(); ?>">
  97. <br />
  98. <div class='message'>
  99. <?php echo get_lang('HotPotatoesFinished'); ?>
  100. </div>
  101. </body>
  102. </html>
  103. <?php
  104. }
  105. ?>