savescores.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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 13988 2007-12-14 05:05:51Z yannoo $
  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 = mysql_real_escape_string($_REQUEST['test']);
  44. $score = mysql_real_escape_string($_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. "('$file',$user_id,'$date','$_cid','$score','$weighting')";
  81. $res = api_sql_query($sql,__FILE__,__LINE__);
  82. if ($origin == 'learnpath')
  83. {
  84. //if we are in a learning path, save the score in the corresponding
  85. //table to get tracking in there as well
  86. global $jscript2run;
  87. $jscript2run .= '<script language="javascript" type="text/javascript">window.parent.API.void_save_asset('.$score.');</script>';
  88. }
  89. }
  90. // Save the Scores
  91. save_scores($test, $score);
  92. // Back
  93. if ($origin != 'learnpath')
  94. {
  95. // $url = "Hpdownload.php?doc_url=".$test."&cid=".$cid; // back to the test
  96. $url = "exercice.php"; // back to exercices
  97. $jscript2run .= '<script language="javascript" type="text/javascript">'."window.open('$url', '_top', '')".'</script>';
  98. echo $jscript2run;
  99. }
  100. else
  101. {
  102. ?>
  103. <html>
  104. <head>
  105. <link rel='stylesheet' type='text/css' href='../css/<?php echo api_get_setting('stylesheets');?>/scorm.css' />
  106. <?php echo $jscript2run; ?>
  107. </head>
  108. <body>
  109. <br />
  110. <div class='message'>
  111. <?php echo get_lang('HotPotatoesFinished'); ?>
  112. </div>
  113. </body>
  114. </html>
  115. <?php
  116. }
  117. ?>