mark_free_answer.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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. include('../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. if($debug>0){echo str_repeat('&nbsp;',0).'Entered exercise_result.php'."<br />\n";var_dump($_POST);}
  26. // general parameters passed via POST/GET
  27. $my_course_code = $_GET['cid'];
  28. if(!empty($_REQUEST['exe'])){
  29. $my_exe = $_REQUEST['exe'];
  30. }else{
  31. $my_exe = null;
  32. }
  33. if(!empty($_REQUEST['qst'])){
  34. $my_qst = $_REQUEST['qst'];
  35. }else{
  36. $my_qst = null;
  37. }
  38. if(!empty($_REQUEST['usr'])){
  39. $my_usr = $_REQUEST['usr'];
  40. }else{
  41. $my_usr = null;
  42. }
  43. if(!empty($_REQUEST['cidReq'])){
  44. $my_cid = $_REQUEST['cidReq'];
  45. }else{
  46. $my_cid = null;
  47. }
  48. if(!empty($_POST['action'])){
  49. $action = $_POST['action'];
  50. }else{
  51. $action = '';
  52. }
  53. if (empty($my_qst) or empty($my_usr) or empty($my_cid) or empty($my_exe)){
  54. header('Location: exercice.php');
  55. exit();
  56. }
  57. if(!$is_courseTutor)
  58. {
  59. api_not_allowed();
  60. }
  61. $obj_question = Question :: read($my_qst);
  62. if (isset($_SESSION['gradebook'])){
  63. $gradebook= $_SESSION['gradebook'];
  64. }
  65. if (!empty($gradebook) && $gradebook=='view') {
  66. $interbreadcrumb[]= array (
  67. 'url' => '../gradebook/'.$_SESSION['gradebook_dest'],
  68. 'name' => get_lang('ToolGradebook')
  69. );
  70. }
  71. $nameTools=get_lang('Exercice');
  72. $interbreadcrumb[]=array("url" => "exercice.php","name" => get_lang('Exercices'));
  73. $my_msg = 'No change.';
  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_statistic_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 = ".intval($my_usr)." AND exe_cours_id = '".Database::escape_string($my_cid)."' AND exe_exo_id = ".intval($my_exe)."
  81. ORDER BY exe_date DESC";
  82. #echo $sql;
  83. $res = Database::query($sql);
  84. if (Database::num_rows($res)>0){
  85. $row = Database::fetch_array($res);
  86. //@todo Check that just summing past score and the new free answer mark doesn't come up
  87. // with a score higher than the possible score for that exercise
  88. $my_score = $row['exe_result'] + $_POST['score'];
  89. $sql = "UPDATE $exercise_table SET exe_result = '$my_score'
  90. WHERE exe_id = '".$row['exe_id']."'";
  91. #echo $sql;
  92. $res = Database::query($sql);
  93. $my_msg = get_lang('MarkIsUpdated');
  94. } else {
  95. $my_score = $_POST['score'];
  96. $reallyNow = time();
  97. $sql = "INSERT INTO $exercise_table (
  98. exe_user_id,
  99. exe_cours_id,
  100. exe_exo_id,
  101. exe_result,
  102. exe_weighting,
  103. exe_date
  104. ) VALUES (
  105. ".intval($my_usr).",
  106. '".Database::escape_string($my_cid)."',
  107. ".intval($my_exe).",
  108. '".Database::escape_string($my_score)."',
  109. '".Database::escape_string($obj_question->selectWeighting())."',
  110. FROM_UNIXTIME(".$reallyNow.")
  111. )";
  112. #if ($origin == 'learnpath')
  113. #{
  114. # if ($user_id == "NULL")
  115. # {
  116. # $user_id = '0';
  117. # }
  118. # $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')";
  119. # $res2 = Database::query($sql2);
  120. #}
  121. $res = Database::query($sql);
  122. $my_msg = get_lang('MarkInserted');
  123. }
  124. //Database::query($sql);
  125. //return 0;
  126. } else {
  127. $my_msg .= get_lang('TotalScoreTooBig');
  128. }
  129. }
  130. Display::display_header($nameTools,"Exercise");
  131. // Display simple marking interface
  132. // 1a - result of previous marking then exit suggestion
  133. // 1b - user answer and marking box + submit button
  134. $objAnswerTmp = new Answer($my_qst);
  135. $objAnswerTmp->selectAnswer($answerId);
  136. if($action == 'mark'){
  137. echo $my_msg.'<br />
  138. <a href="exercice.php?cidReq='.$cidReq.'">'.get_lang('Back').'</a>';
  139. } else {
  140. echo '<h2>'.$obj_question->question .':</h2>
  141. '.$obj_question->selectTitle().'<br /><br />
  142. '.get_lang('PleaseGiveAMark').
  143. "<form action='' method='POST'>\n"
  144. ."<input type='hidden' name='exe' value='$my_exe'>\n"
  145. ."<input type='hidden' name='usr' value='$my_usr'>\n"
  146. ."<input type='hidden' name='cidReq' value='$my_cid'>\n"
  147. ."<input type='hidden' name='action' value='mark'>\n"
  148. ."<select name='score'>\n";
  149. for($i=0 ; $i<$obj_question->selectWeighting() ; $i++){
  150. echo '<option>'.$i.'</option>';
  151. }
  152. echo "</select>".
  153. "<input type='submit' name='submit' value='".get_lang('Ok')."'>\n"
  154. ."</form>";
  155. }
  156. Display::display_footer();