savescores.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php
  2. /*
  3. DOKEOS - elearning and course management software
  4. For a full list of contributors, see documentation/credits.html
  5. This program is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU General Public License
  7. as published by the Free Software Foundation; either version 2
  8. of the License, or (at your option) any later version.
  9. See "documentation/licence.html" more details.
  10. Contact:
  11. Dokeos
  12. Rue des Palais 44 Paleizenstraat
  13. B-1030 Brussels - Belgium
  14. Tel. +32 (2) 211 34 56
  15. */
  16. /**
  17. * Saving the scores.
  18. * @package dokeos.exercise
  19. * @author
  20. * @version $Id: savescores.php 15602 2008-06-18 08:52:24Z pcool $
  21. */
  22. // name of the language file that needs to be included
  23. $language_file = 'learnpath';
  24. if($_GET['origin']=='learnpath')
  25. {
  26. require_once ('../newscorm/learnpath.class.php');
  27. require_once ('../newscorm/learnpathItem.class.php');
  28. require_once ('../newscorm/scorm.class.php');
  29. require_once ('../newscorm/scormItem.class.php');
  30. require_once ('../newscorm/aicc.class.php');
  31. require_once ('../newscorm/aiccItem.class.php');
  32. }
  33. include ('../inc/global.inc.php');
  34. $this_section=SECTION_COURSES;
  35. include_once (api_get_path(LIBRARY_PATH).'fileManage.lib.php');
  36. $documentPath = api_get_path(SYS_COURSE_PATH).$_course['path']."/document";
  37. $full_file_path = $documentPath.$test;
  38. my_delete($full_file_path.$_user['user_id'].".t.html");
  39. $TABLETRACK_HOTPOTATOES = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_HOTPOTATOES);
  40. $tbl_learnpath_user = Database::get_course_table(TABLE_LEARNPATH_USER);
  41. $TABLE_LP_ITEM_VIEW = Database::get_course_table(TABLE_LP_ITEM_VIEW);
  42. $_cid = api_get_course_id();
  43. $test = $_REQUEST['test'];
  44. $score = $_REQUEST['score'];
  45. $origin = $_REQUEST['origin'];
  46. $jscript2run = '';
  47. /**
  48. * Save the score for a HP quiz. Can be used by the learnpath tool as well
  49. * for HotPotatoes quizzes. When coming from the learning path, we
  50. * use the session variables telling us which item of the learning path has to
  51. * be updated (score-wise)
  52. * @param string File is the exercise name (the file name for a HP)
  53. * @param integer Score to save inside the tracking tables (HP and learnpath)
  54. * @return void
  55. */
  56. function save_scores($file, $score)
  57. {
  58. global $_configuration, $origin,
  59. $_user, $_cid,
  60. $TABLETRACK_HOTPOTATOES;
  61. // if tracking is disabled record nothing
  62. $weighting = 100; // 100%
  63. $reallyNow = time();
  64. $date = date("Y-m-d H:i:s", $reallyNow);
  65. if (!$_configuration['tracking_enabled'])
  66. {
  67. return 0;
  68. }
  69. if ($_user['user_id'])
  70. {
  71. $user_id = "'".$_user['user_id']."'";
  72. }
  73. else // anonymous
  74. {
  75. $user_id = "NULL";
  76. }
  77. $sql = "INSERT INTO $TABLETRACK_HOTPOTATOES ".
  78. "(exe_name, exe_user_id, exe_date,exe_cours_id,exe_result,exe_weighting)" .
  79. "VALUES" .
  80. "(
  81. '".Database::escape_string($file)."',
  82. '".Database::escape_string($user_id)."',
  83. '".Database::escape_string($date)."',
  84. '".Database::escape_string($_cid)."',
  85. '".Database::escape_string($score)."',
  86. '".Database::escape_string($weighting)."')";
  87. $res = api_sql_query($sql,__FILE__,__LINE__);
  88. if ($origin == 'learnpath')
  89. {
  90. //if we are in a learning path, save the score in the corresponding
  91. //table to get tracking in there as well
  92. global $jscript2run;
  93. //record the results in the learning path, using the SCORM interface (API)
  94. $jscript2run .= '<script language="javascript" type="text/javascript">window.parent.API.void_save_asset('.$score.','.$weighting.');</script>';
  95. }
  96. }
  97. // Save the Scores
  98. save_scores($test, $score);
  99. // Back
  100. if ($origin != 'learnpath')
  101. {
  102. // $url = "Hpdownload.php?doc_url=".$test."&cid=".$cid; // back to the test
  103. $url = "exercice.php"; // back to exercices
  104. $jscript2run .= '<script language="javascript" type="text/javascript">'."window.open('$url', '_top', '')".'</script>';
  105. echo $jscript2run;
  106. }
  107. else
  108. {
  109. ?>
  110. <html>
  111. <head>
  112. <link rel='stylesheet' type='text/css' href='../css/<?php echo api_get_setting('stylesheets');?>/scorm.css' />
  113. <?php echo $jscript2run; ?>
  114. </head>
  115. <body>
  116. <br />
  117. <div class='message'>
  118. <?php echo get_lang('HotPotatoesFinished'); ?>
  119. </div>
  120. </body>
  121. </html>
  122. <?php
  123. }
  124. ?>