mark_free_answer.php 5.6 KB

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