mark_free_answer.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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 = mysql_real_escape_string($_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. $nameTools=get_lang('Exercice');
  90. $interbreadcrumb[]=array("url" => "exercice.php","name" => get_lang('Exercices'));
  91. $my_msg = 'No change.';
  92. if($action == 'mark'){
  93. if (!empty($_POST['score']) AND $_POST['score'] < $obj_question->selectWeighting() AND $_POST['score'] >= 0){
  94. //mark the user mark into the database using something similar to the following function:
  95. global $_configuration;
  96. if($_configuration['tracking_enabled'])
  97. {
  98. $exercise_table = Database::get_statistic_table('track_e_exercices');
  99. #$tbl_learnpath_user = Database::get_course_table('learnpath_user');
  100. #global $origin, $tbl_learnpath_user, $learnpath_id, $learnpath_item_id;
  101. $sql = "SELECT * FROM $exercise_table
  102. WHERE exe_user_id = '$my_usr' AND exe_cours_id = '$my_cid' AND exe_exo_id = '$my_exe'
  103. ORDER BY exe_date DESC";
  104. #echo $sql;
  105. $res = api_sql_query($sql,__FILE__,__LINE__);
  106. if(mysql_num_rows($res)>0){
  107. $row = mysql_fetch_array($res);
  108. //@todo Check that just summing past score and the new free answer mark doesn't come up
  109. // with a score higher than the possible score for that exercise
  110. $my_score = $row['exe_result'] + $_POST['score'];
  111. $sql = "UPDATE $exercise_table SET exe_result = '$my_score'
  112. WHERE exe_id = '".$row['exe_id']."'";
  113. #echo $sql;
  114. $res = api_sql_query($sql,__FILE__,__LINE__);
  115. $my_msg = get_lang('MarkIsUpdated');
  116. }else{
  117. $my_score = $_POST['score'];
  118. $reallyNow = time();
  119. $sql = "INSERT INTO $exercise_table
  120. (
  121. `exe_user_id`,
  122. `exe_cours_id`,
  123. `exe_exo_id`,
  124. `exe_result`,
  125. `exe_weighting`,
  126. `exe_date`
  127. )
  128. VALUES
  129. (
  130. ".$my_usr.",
  131. '".$my_cid."',
  132. '".$my_exe."',
  133. '".$my_score."',
  134. '".$obj_question->selectWeighting()."',
  135. FROM_UNIXTIME(".$reallyNow.")
  136. )";
  137. #if ($origin == 'learnpath')
  138. #{
  139. # if ($user_id == "NULL")
  140. # {
  141. # $user_id = '0';
  142. # }
  143. # $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')";
  144. # $res2 = api_sql_query($sql2,__FILE__,__LINE__);
  145. #}
  146. $res = api_sql_query($sql,__FILE__,__LINE__);
  147. $my_msg = get_lang('MarkInserted');
  148. }
  149. //$mysql_query($sql);
  150. //return 0;
  151. }
  152. }else{
  153. $my_msg .= " There might have been a problem with the total score being too big...<br />\n";
  154. }
  155. }
  156. Display::display_header($nameTools,"Exercise");
  157. // Display simple marking interface
  158. // 1a - result of previous marking then exit suggestion
  159. // 1b - user answer and marking box + submit button
  160. $objAnswerTmp = new Answer();
  161. $objAnswerTmp->selectAnswer($answerId);
  162. if($action == 'mark'){
  163. echo $my_msg.'<br />
  164. <a href="exercice.php?cidReq='.$cidReq.'">'.get_lang('Back').'</a>';
  165. }else{
  166. echo '<h2>'.$obj_question->question .':</h2>
  167. '.$obj_question->selectTitle().'<br /><br />
  168. '.get_lang('PleaseGiveAMark').
  169. "<form action='' method='POST'>\n"
  170. ."<input type='hidden' name='exe' value='$my_exe'>\n"
  171. ."<input type='hidden' name='usr' value='$my_usr'>\n"
  172. ."<input type='hidden' name='cidReq' value='$my_cid'>\n"
  173. ."<input type='hidden' name='action' value='mark'>\n"
  174. ."<select name='score'>\n";
  175. for($i=0 ; $i<$obj_question->selectWeighting() ; $i++){
  176. echo '<option>'.$i.'</option>';
  177. }
  178. echo "</select>".
  179. "<input type='submit' name='submit' value='".get_lang('Ok')."'>\n"
  180. ."</form>";
  181. }
  182. Display::display_footer();
  183. ?>