mark_free_answer.php 4.8 KB

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