mark_free_answer.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. <?php // $Id: mark_free_answer.php,v 1.1.2.1 2005/08/30 01:47:37 yannoo Exp $
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2004 Dokeos S.A.
  6. Copyright (c) 2005 Yannick Warnier <yannick.warnier@dokeos.com>
  7. For a full list of contributors, see "credits.txt".
  8. The full license can be read in "license.txt".
  9. This program is free software; you can redistribute it and/or
  10. modify it under the terms of the GNU General Public License
  11. as published by the Free Software Foundation; either version 2
  12. of the License, or (at your option) any later version.
  13. See the GNU General Public License for more details.
  14. Contact: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com
  15. ==============================================================================
  16. */
  17. /**
  18. ==============================================================================
  19. * FREE ANSWER MARKING SCRIPT
  20. *
  21. * This script allows a course tutor to mark a student's free answer.
  22. *@author Yannick Warnier <yannick.warnier@dokeos.com>
  23. * @package dokeos.exercise
  24. ==============================================================================
  25. */
  26. /*
  27. ==============================================================================
  28. INIT SECTION
  29. ==============================================================================
  30. */
  31. include('exercise.class.php');
  32. include('question.class.php');
  33. include('answer.class.php');
  34. // answer types
  35. define('UNIQUE_ANSWER', 1);
  36. define('MULTIPLE_ANSWER', 2);
  37. define('FILL_IN_BLANKS', 3);
  38. define('MATCHING', 4);
  39. define('FREE_ANSWER', 5);
  40. $langFile='exercice';
  41. include('../inc/global.inc.php');
  42. include(api_get_library_path().'/text.lib.php');
  43. $TBL_EXERCICE_QUESTION = $_course['dbNameGlu'].'quiz_rel_question';
  44. $TBL_EXERCICES = $_course['dbNameGlu'].'quiz';
  45. $TBL_QUESTIONS = $_course['dbNameGlu'].'quiz_question';
  46. $TBL_REPONSES = $_course['dbNameGlu'].'quiz_answer';
  47. //debug param. 0: no display - 1: debug display
  48. $debug=0;
  49. if($debug>0){echo str_repeat('&nbsp;',0).'Entered exercise_result.php'."<br />\n";var_dump($_POST);}
  50. // general parameters passed via POST/GET
  51. $my_course_code = mysql_real_escape_string($_GET['cid']);
  52. if(!empty($_REQUEST['exe'])){
  53. $my_exe = $_REQUEST['exe'];
  54. }else{
  55. $my_exe = null;
  56. }
  57. if(!empty($_REQUEST['qst'])){
  58. $my_qst = $_REQUEST['qst'];
  59. }else{
  60. $my_qst = null;
  61. }
  62. if(!empty($_REQUEST['usr'])){
  63. $my_usr = $_REQUEST['usr'];
  64. }else{
  65. $my_usr = null;
  66. }
  67. if(!empty($_REQUEST['cidReq'])){
  68. $my_cid = $_REQUEST['cidReq'];
  69. }else{
  70. $my_cid = null;
  71. }
  72. if(!empty($_POST['action'])){
  73. $action = $_POST['action'];
  74. }else{
  75. $action = '';
  76. }
  77. if (empty($my_qst) or empty($my_usr) or empty($my_cid) or empty($my_exe)){
  78. header('Location: exercice.php');
  79. exit();
  80. }
  81. if(!$is_courseTutor)
  82. {
  83. api_not_allowed();
  84. }
  85. $obj_question=new Question();
  86. $obj_question->read($my_qst);
  87. $nameTools=get_lang('Exercice');
  88. $interbreadcrump[]=array("url" => "exercice.php","name" => get_lang('Exercices'));
  89. $my_msg = 'No change.';
  90. if($action == 'mark'){
  91. if (!empty($_POST['score']) AND $_POST['score'] < $obj_question->selectWeighting() AND $_POST['score'] >= 0){
  92. //mark the user mark into the database using something similar to the following function:
  93. global $is_trackingEnabled, $statsDbName;
  94. if($is_trackingEnabled){
  95. $exercise_table = Database::get_statistic_table('track_e_exercices');
  96. #$tbl_learnpath_user = Database::get_course_table('learnpath_user');
  97. #global $origin, $tbl_learnpath_user, $learnpath_id, $learnpath_item_id;
  98. $sql = "SELECT * FROM $exercise_table
  99. WHERE exe_user_id = '$my_usr' AND exe_cours_id = '$my_cid' AND exe_exo_id = '$my_exe'
  100. ORDER BY exe_date DESC";
  101. #echo $sql;
  102. $res = api_sql_query($sql,__FILE__,__LINE__);
  103. if(mysql_num_rows($res)>0){
  104. $row = mysql_fetch_array($res);
  105. //@todo Check that just summing past score and the new free answer mark doesn't come up
  106. // with a score higher than the possible score for that exercise
  107. $my_score = $row['exe_result'] + $_POST['score'];
  108. $sql = "UPDATE $exercise_table SET exe_result = '$my_score'
  109. WHERE exe_id = '".$row['exe_id']."'";
  110. #echo $sql;
  111. $res = api_sql_query($sql,__FILE__,__LINE__);
  112. $my_msg = get_lang('MarkIsUpdated');
  113. }else{
  114. $my_score = $_POST['score'];
  115. $reallyNow = time();
  116. $sql = "INSERT INTO $exercise_table
  117. (
  118. `exe_user_id`,
  119. `exe_cours_id`,
  120. `exe_exo_id`,
  121. `exe_result`,
  122. `exe_weighting`,
  123. `exe_date`
  124. )
  125. VALUES
  126. (
  127. ".$my_usr.",
  128. '".$my_cid."',
  129. '".$my_exe."',
  130. '".$my_score."',
  131. '".$obj_question->selectWeighting()."',
  132. FROM_UNIXTIME(".$reallyNow.")
  133. )";
  134. #if ($origin == 'learnpath')
  135. #{
  136. # if ($user_id == "NULL")
  137. # {
  138. # $user_id = '0';
  139. # }
  140. # $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')";
  141. # $res2 = api_sql_query($sql2,__FILE__,__LINE__);
  142. #}
  143. $res = api_sql_query($sql,__FILE__,__LINE__);
  144. $my_msg = get_lang('MarkInserted');
  145. }
  146. //$mysql_query($sql);
  147. //return 0;
  148. }
  149. }else{
  150. $my_msg .= " There might have been a problem with the total score being too big...<br />\n";
  151. }
  152. }
  153. Display::display_header($nameTools,"Exercise");
  154. // Display simple marking interface
  155. // 1a - result of previous marking then exit suggestion
  156. // 1b - user answer and marking box + submit button
  157. $objAnswerTmp = new Answer();
  158. $objAnswerTmp->selectAnswer($answerId);
  159. if($action == 'mark'){
  160. echo $my_msg.'<br />
  161. <a href="exercice.php?cidReq='.$cidReq.'">'.get_lang('Back').'</a>';
  162. }else{
  163. echo '<h2>'.$obj_question->question .':</h2>
  164. '.$obj_question->selectTitle().'<br /><br />
  165. '.get_lang('PleaseGiveAMark').
  166. "<form action='' method='POST'>\n"
  167. ."<input type='hidden' name='exe' value='$my_exe'>\n"
  168. ."<input type='hidden' name='usr' value='$my_usr'>\n"
  169. ."<input type='hidden' name='cidReq' value='$my_cid'>\n"
  170. ."<input type='hidden' name='action' value='mark'>\n"
  171. ."<select name='score'>\n";
  172. for($i=0 ; $i<$obj_question->selectWeighting() ; $i++){
  173. echo '<option>'.$i.'</option>';
  174. }
  175. echo "</select>".
  176. "<input type='submit' name='submit' value='".get_lang('Ok')."'>\n"
  177. ."</form>";
  178. }
  179. Display::display_footer();
  180. ?>