mark_free_answer.php 5.0 KB

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