mark_free_answer.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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. * Free answer marking script
  18. * This script allows a course tutor to mark a student's free answer.
  19. * @package dokeos.exercise
  20. * @author Yannick Warnier <yannick.warnier@dokeos.com>
  21. * @version $Id: admin.php 10680 2007-01-11 21:26:23Z pcool $
  22. *
  23. * @todo respect coding guidelines
  24. */
  25. /*
  26. ==============================================================================
  27. INIT SECTION
  28. ==============================================================================
  29. */
  30. // name of the language file that needs to be included
  31. $language_file='exercice';
  32. // name of the language file that needs to be included
  33. include('../inc/global.inc.php');
  34. // including additional libraries
  35. include('exercise.class.php');
  36. include('question.class.php');
  37. include('answer.class.php');
  38. include_once(api_get_library_path().'/text.lib.php');
  39. // answer types
  40. define('UNIQUE_ANSWER', 1);
  41. define('MULTIPLE_ANSWER', 2);
  42. define('FILL_IN_BLANKS', 3);
  43. define('MATCHING', 4);
  44. define('FREE_ANSWER', 5);
  45. /** @todo use the Database:: functions */
  46. $TBL_EXERCICE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
  47. $TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST);
  48. $TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION);
  49. $TBL_REPONSES = Database::get_course_table(TABLE_QUIZ_ANSWER);
  50. //debug param. 0: no display - 1: debug display
  51. $debug=0;
  52. if($debug>0){echo str_repeat('&nbsp;',0).'Entered exercise_result.php'."<br />\n";var_dump($_POST);}
  53. // general parameters passed via POST/GET
  54. $my_course_code = $_GET['cid'];
  55. if(!empty($_REQUEST['exe'])){
  56. $my_exe = $_REQUEST['exe'];
  57. }else{
  58. $my_exe = null;
  59. }
  60. if(!empty($_REQUEST['qst'])){
  61. $my_qst = $_REQUEST['qst'];
  62. }else{
  63. $my_qst = null;
  64. }
  65. if(!empty($_REQUEST['usr'])){
  66. $my_usr = $_REQUEST['usr'];
  67. }else{
  68. $my_usr = null;
  69. }
  70. if(!empty($_REQUEST['cidReq'])){
  71. $my_cid = $_REQUEST['cidReq'];
  72. }else{
  73. $my_cid = null;
  74. }
  75. if(!empty($_POST['action'])){
  76. $action = $_POST['action'];
  77. }else{
  78. $action = '';
  79. }
  80. if (empty($my_qst) or empty($my_usr) or empty($my_cid) or empty($my_exe)){
  81. header('Location: exercice.php');
  82. exit();
  83. }
  84. if(!$is_courseTutor)
  85. {
  86. api_not_allowed();
  87. }
  88. $obj_question = Question :: read($my_qst);
  89. if (isset($_SESSION['gradebook'])){
  90. $gradebook= $_SESSION['gradebook'];
  91. }
  92. if (!empty($gradebook) && $gradebook=='view') {
  93. $interbreadcrumb[]= array (
  94. 'url' => '../gradebook/'.$_SESSION['gradebook_dest'],
  95. 'name' => get_lang('Gradebook')
  96. );
  97. }
  98. $nameTools=get_lang('Exercice');
  99. $interbreadcrumb[]=array("url" => "exercice.php","name" => get_lang('Exercices'));
  100. $my_msg = 'No change.';
  101. if($action == 'mark'){
  102. if (!empty($_POST['score']) AND $_POST['score'] < $obj_question->selectWeighting() AND $_POST['score'] >= 0){
  103. //mark the user mark into the database using something similar to the following function:
  104. global $_configuration;
  105. if($_configuration['tracking_enabled'])
  106. {
  107. $exercise_table = Database::get_statistic_table('track_e_exercices');
  108. #$tbl_learnpath_user = Database::get_course_table('learnpath_user');
  109. #global $origin, $tbl_learnpath_user, $learnpath_id, $learnpath_item_id;
  110. $sql = "SELECT * FROM $exercise_table
  111. WHERE exe_user_id = '".Database::escape_string($my_usr)."' AND exe_cours_id = '".Database::escape_string($my_cid)."' AND exe_exo_id = '".Database::escape_string($my_exe)."'
  112. ORDER BY exe_date DESC";
  113. #echo $sql;
  114. $res = Database::query($sql,__FILE__,__LINE__);
  115. if(mysql_num_rows($res)>0){
  116. $row = mysql_fetch_array($res);
  117. //@todo Check that just summing past score and the new free answer mark doesn't come up
  118. // with a score higher than the possible score for that exercise
  119. $my_score = $row['exe_result'] + $_POST['score'];
  120. $sql = "UPDATE $exercise_table SET exe_result = '$my_score'
  121. WHERE exe_id = '".$row['exe_id']."'";
  122. #echo $sql;
  123. $res = Database::query($sql,__FILE__,__LINE__);
  124. $my_msg = get_lang('MarkIsUpdated');
  125. }else{
  126. $my_score = $_POST['score'];
  127. $reallyNow = time();
  128. $sql = "INSERT INTO $exercise_table
  129. (
  130. exe_user_id,
  131. exe_cours_id,
  132. exe_exo_id,
  133. exe_result,
  134. exe_weighting,
  135. exe_date
  136. )
  137. VALUES
  138. (
  139. '".Database::escape_string($my_usr)."',
  140. '".Database::escape_string($my_cid)."',
  141. '".Database::escape_string($my_exe)."',
  142. '".Database::escape_string($my_score)."',
  143. '".Database::escape_string($obj_question->selectWeighting())."',
  144. FROM_UNIXTIME(".$reallyNow.")
  145. )";
  146. #if ($origin == 'learnpath')
  147. #{
  148. # if ($user_id == "NULL")
  149. # {
  150. # $user_id = '0';
  151. # }
  152. # $sql2 = "update `$tbl_learnpath_user` set score='$score' where (user_id=$user_id and learnpath_id='$learnpath_id' and learnpath_item_id='$learnpath_item_id')";
  153. # $res2 = Database::query($sql2,__FILE__,__LINE__);
  154. #}
  155. $res = Database::query($sql,__FILE__,__LINE__);
  156. $my_msg = get_lang('MarkInserted');
  157. }
  158. //$mysql_query($sql);
  159. //return 0;
  160. }
  161. }else{
  162. $my_msg .= get_lang('TotalScoreTooBig');
  163. }
  164. }
  165. Display::display_header($nameTools,"Exercise");
  166. // Display simple marking interface
  167. // 1a - result of previous marking then exit suggestion
  168. // 1b - user answer and marking box + submit button
  169. $objAnswerTmp = new Answer();
  170. $objAnswerTmp->selectAnswer($answerId);
  171. if($action == 'mark'){
  172. echo $my_msg.'<br />
  173. <a href="exercice.php?cidReq='.$cidReq.'">'.get_lang('Back').'</a>';
  174. }else{
  175. echo '<h2>'.$obj_question->question .':</h2>
  176. '.$obj_question->selectTitle().'<br /><br />
  177. '.get_lang('PleaseGiveAMark').
  178. "<form action='' method='POST'>\n"
  179. ."<input type='hidden' name='exe' value='$my_exe'>\n"
  180. ."<input type='hidden' name='usr' value='$my_usr'>\n"
  181. ."<input type='hidden' name='cidReq' value='$my_cid'>\n"
  182. ."<input type='hidden' name='action' value='mark'>\n"
  183. ."<select name='score'>\n";
  184. for($i=0 ; $i<$obj_question->selectWeighting() ; $i++){
  185. echo '<option>'.$i.'</option>';
  186. }
  187. echo "</select>".
  188. "<input type='submit' name='submit' value='".get_lang('Ok')."'>\n"
  189. ."</form>";
  190. }
  191. Display::display_footer();
  192. ?>