savescores.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2004 Dokeos S.A.
  6. Copyright (c) 2003 Ghent University (UGent)
  7. Copyright (c) 2001 Universite catholique de Louvain (UCL)
  8. Copyright (c) Istvan Mandak
  9. For a full list of contributors, see "credits.txt".
  10. The full license can be read in "license.txt".
  11. This program is free software; you can redistribute it and/or
  12. modify it under the terms of the GNU General Public License
  13. as published by the Free Software Foundation; either version 2
  14. of the License, or (at your option) any later version.
  15. See the GNU General Public License for more details.
  16. Contact: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com
  17. ==============================================================================
  18. */
  19. /**
  20. ==============================================================================
  21. * Code library for HotPotatoes integration.
  22. *
  23. * @author Istvan Mandak
  24. * @package dokeos.exercise
  25. ==============================================================================
  26. */
  27. $langFile = 'learnpath';
  28. include ('../inc/global.inc.php');
  29. $this_section=SECTION_COURSES;
  30. include_once (api_get_path(LIBRARY_PATH).'fileManage.lib.php');
  31. $documentPath = api_get_path(SYS_COURSE_PATH).$_course['path']."/document";
  32. $full_file_path = $documentPath.$test;
  33. my_delete($full_file_path.$_uid.".t.html");
  34. $TABLETRACK_HOTPOTATOES = $statsDbName."`.`track_e_hotpotatoes";
  35. $tbl_learnpath_user = Database::get_course_table(LEARNPATH_USER_TABLE);
  36. //$_course['dbNameGlu']."learnpath_user";
  37. $_uid = $uid;
  38. $_cid = $cid;
  39. $test = mysql_real_escape_string($_REQUEST['test']);
  40. $score = mysql_real_escape_string($_REQUEST['score']);
  41. $origin = $_REQUEST['origin'];
  42. function save_scores($file, $score)
  43. {
  44. global $is_trackingEnabled, $origin, $tbl_learnpath_user,
  45. $learnpath_id, $learnpath_item_id, $_uid, $_cid,
  46. $TABLETRACK_HOTPOTATOES;
  47. // if tracking is disabled record nothing
  48. $weighting = 100; // 100%
  49. $reallyNow = time();
  50. $date = date("Y-m-d H:i:s", $reallyNow);
  51. if (!$is_trackingEnabled){return 0;}
  52. if ($_uid)
  53. {
  54. $user_id = "'".$_uid."'";
  55. }
  56. else // anonymous
  57. {
  58. $user_id = "NULL";
  59. }
  60. $sql = "INSERT INTO `".$TABLETRACK_HOTPOTATOES."`
  61. (`exe_name`,
  62. `exe_user_id`,
  63. `exe_date`,
  64. `exe_cours_id`,
  65. `exe_result`,
  66. `exe_weighting`
  67. )
  68. VALUES
  69. (
  70. '".$file."',
  71. ".$user_id.",
  72. '".$date."',
  73. '".$_cid."',
  74. '".$score."',
  75. '".$weighting."'
  76. )";
  77. error_log($sql,0);
  78. if ($origin == 'learnpath')
  79. {
  80. if ($user_id == "NULL")
  81. {
  82. $user_id = '0';
  83. }
  84. $sql2 = "update $tbl_learnpath_user
  85. set score='$score'
  86. where (user_id=$user_id and learnpath_id='$learnpath_id' and learnpath_item_id='$learnpath_item_id')";
  87. error_log($sql,0);
  88. $res2 = api_sql_query($sql2,__FILE__,__LINE__);
  89. }
  90. $res = api_sql_query($sql,__FILE__,__LINE__);
  91. }
  92. // Save the Scores
  93. save_scores($test, $score);
  94. // Back
  95. if ($origin != 'learnpath')
  96. {
  97. // $url = "Hpdownload.php?doc_url=".$test."&cid=".$cid; // back to the test
  98. $url = "exercice.php"; // back to exercices
  99. echo "<SCRIPT LANGUAGE='JavaScript' type='text/javascript'>";
  100. echo "window.open('$url', '_top', '')"; // back to exercices
  101. echo "</SCRIPT> ";
  102. }
  103. else
  104. {
  105. ?>
  106. <html>
  107. <head>
  108. <link rel='stylesheet' type='text/css' href='../css/scorm.css' />
  109. </head>
  110. <body>
  111. <br /><div class='message'>
  112. <?php echo get_lang('HotPotatoesFinished'); ?>
  113. </div>
  114. </body>
  115. </html>
  116. <?php
  117. }
  118. ?>