mark_free_answer.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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. // name of the language file that needs to be included
  41. $language_file='exercice';
  42. include('../inc/global.inc.php');
  43. include(api_get_library_path().'/text.lib.php');
  44. $TBL_EXERCICE_QUESTION = $_course['dbNameGlu'].'quiz_rel_question';
  45. $TBL_EXERCICES = $_course['dbNameGlu'].'quiz';
  46. $TBL_QUESTIONS = $_course['dbNameGlu'].'quiz_question';
  47. $TBL_REPONSES = $_course['dbNameGlu'].'quiz_answer';
  48. //debug param. 0: no display - 1: debug display
  49. $debug=0;
  50. if($debug>0){echo str_repeat('&nbsp;',0).'Entered exercise_result.php'."<br />\n";var_dump($_POST);}
  51. // general parameters passed via POST/GET
  52. $my_course_code = mysql_real_escape_string($_GET['cid']);
  53. if(!empty($_REQUEST['exe'])){
  54. $my_exe = $_REQUEST['exe'];
  55. }else{
  56. $my_exe = null;
  57. }
  58. if(!empty($_REQUEST['qst'])){
  59. $my_qst = $_REQUEST['qst'];
  60. }else{
  61. $my_qst = null;
  62. }
  63. if(!empty($_REQUEST['usr'])){
  64. $my_usr = $_REQUEST['usr'];
  65. }else{
  66. $my_usr = null;
  67. }
  68. if(!empty($_REQUEST['cidReq'])){
  69. $my_cid = $_REQUEST['cidReq'];
  70. }else{
  71. $my_cid = null;
  72. }
  73. if(!empty($_POST['action'])){
  74. $action = $_POST['action'];
  75. }else{
  76. $action = '';
  77. }
  78. if (empty($my_qst) or empty($my_usr) or empty($my_cid) or empty($my_exe)){
  79. header('Location: exercice.php');
  80. exit();
  81. }
  82. if(!$is_courseTutor)
  83. {
  84. api_not_allowed();
  85. }
  86. $obj_question=new Question();
  87. $obj_question->read($my_qst);
  88. $nameTools=get_lang('Exercice');
  89. $interbreadcrump[]=array("url" => "exercice.php","name" => get_lang('Exercices'));
  90. $my_msg = 'No change.';
  91. if($action == 'mark'){
  92. if (!empty($_POST['score']) AND $_POST['score'] < $obj_question->selectWeighting() AND $_POST['score'] >= 0){
  93. //mark the user mark into the database using something similar to the following function:
  94. global $_configuration;
  95. if($_configuration['tracking_enabled'])
  96. {
  97. $exercise_table = Database::get_statistic_table('track_e_exercices');
  98. #$tbl_learnpath_user = Database::get_course_table('learnpath_user');
  99. #global $origin, $tbl_learnpath_user, $learnpath_id, $learnpath_item_id;
  100. $sql = "SELECT * FROM $exercise_table
  101. WHERE exe_user_id = '$my_usr' AND exe_cours_id = '$my_cid' AND exe_exo_id = '$my_exe'
  102. ORDER BY exe_date DESC";
  103. #echo $sql;
  104. $res = api_sql_query($sql,__FILE__,__LINE__);
  105. if(mysql_num_rows($res)>0){
  106. $row = mysql_fetch_array($res);
  107. //@todo Check that just summing past score and the new free answer mark doesn't come up
  108. // with a score higher than the possible score for that exercise
  109. $my_score = $row['exe_result'] + $_POST['score'];
  110. $sql = "UPDATE $exercise_table SET exe_result = '$my_score'
  111. WHERE exe_id = '".$row['exe_id']."'";
  112. #echo $sql;
  113. $res = api_sql_query($sql,__FILE__,__LINE__);
  114. $my_msg = get_lang('MarkIsUpdated');
  115. }else{
  116. $my_score = $_POST['score'];
  117. $reallyNow = time();
  118. $sql = "INSERT INTO $exercise_table
  119. (
  120. `exe_user_id`,
  121. `exe_cours_id`,
  122. `exe_exo_id`,
  123. `exe_result`,
  124. `exe_weighting`,
  125. `exe_date`
  126. )
  127. VALUES
  128. (
  129. ".$my_usr.",
  130. '".$my_cid."',
  131. '".$my_exe."',
  132. '".$my_score."',
  133. '".$obj_question->selectWeighting()."',
  134. FROM_UNIXTIME(".$reallyNow.")
  135. )";
  136. #if ($origin == 'learnpath')
  137. #{
  138. # if ($user_id == "NULL")
  139. # {
  140. # $user_id = '0';
  141. # }
  142. # $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')";
  143. # $res2 = api_sql_query($sql2,__FILE__,__LINE__);
  144. #}
  145. $res = api_sql_query($sql,__FILE__,__LINE__);
  146. $my_msg = get_lang('MarkInserted');
  147. }
  148. //$mysql_query($sql);
  149. //return 0;
  150. }
  151. }else{
  152. $my_msg .= " There might have been a problem with the total score being too big...<br />\n";
  153. }
  154. }
  155. Display::display_header($nameTools,"Exercise");
  156. // Display simple marking interface
  157. // 1a - result of previous marking then exit suggestion
  158. // 1b - user answer and marking box + submit button
  159. $objAnswerTmp = new Answer();
  160. $objAnswerTmp->selectAnswer($answerId);
  161. if($action == 'mark'){
  162. echo $my_msg.'<br />
  163. <a href="exercice.php?cidReq='.$cidReq.'">'.get_lang('Back').'</a>';
  164. }else{
  165. echo '<h2>'.$obj_question->question .':</h2>
  166. '.$obj_question->selectTitle().'<br /><br />
  167. '.get_lang('PleaseGiveAMark').
  168. "<form action='' method='POST'>\n"
  169. ."<input type='hidden' name='exe' value='$my_exe'>\n"
  170. ."<input type='hidden' name='usr' value='$my_usr'>\n"
  171. ."<input type='hidden' name='cidReq' value='$my_cid'>\n"
  172. ."<input type='hidden' name='action' value='mark'>\n"
  173. ."<select name='score'>\n";
  174. for($i=0 ; $i<$obj_question->selectWeighting() ; $i++){
  175. echo '<option>'.$i.'</option>';
  176. }
  177. echo "</select>".
  178. "<input type='submit' name='submit' value='".get_lang('Ok')."'>\n"
  179. ."</form>";
  180. }
  181. Display::display_footer();
  182. ?>