Dokeos PHP Cross Reference Learning Management Systems

Source: /main/exercice/mark_free_answer.php - 227 lines - 6887 bytes - Summary - Text - Print

Description: Free answer marking script This script allows a course tutor to mark a student's free answer.

   1  <?php
   2  /*

   3      DOKEOS - elearning and course management software

   4  

   5      For a full list of contributors, see documentation/credits.html

   6  

   7      This program is free software; you can redistribute it and/or

   8      modify it under the terms of the GNU General Public License

   9      as published by the Free Software Foundation; either version 2

  10      of the License, or (at your option) any later version.

  11      See "documentation/licence.html" more details.

  12  

  13      Contact:

  14          Dokeos

  15          Rue des Palais 44 Paleizenstraat

  16          B-1030 Brussels - Belgium

  17          Tel. +32 (2) 211 34 56

  18  */
  19  
  20  
  21  /**

  22  *    Free answer marking script

  23  *     This script allows a course tutor to mark a student's free answer.

  24  *    @package dokeos.exercise

  25  *     @author Yannick Warnier <yannick.warnier@dokeos.com>

  26  *     @version $Id: admin.php 10680 2007-01-11 21:26:23Z pcool $

  27  *

  28  *     @todo respect coding guidelines

  29  */
  30  
  31  /*

  32  ==============================================================================

  33          INIT SECTION

  34  ==============================================================================

  35  */
  36  // name of the language file that needs to be included

  37  $language_file='exercice';
  38  
  39  // name of the language file that needs to be included

  40  include ('../inc/global.inc.php');
  41  
  42  // including additional libraries

  43  include ('exercise.class.php');
  44  include ('question.class.php');
  45  include ('answer.class.php');
  46  include_once(api_get_library_path().'/text.lib.php');
  47  
  48  // answer types

  49  define('UNIQUE_ANSWER',    1);
  50  define('MULTIPLE_ANSWER',    2);
  51  define('FILL_IN_BLANKS',    3);
  52  define('MATCHING',        4);
  53  define('FREE_ANSWER', 5);
  54  
  55  
  56  
  57  
  58  /** @todo use the Database:: functions */

  59  $TBL_EXERCICE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
  60  $TBL_EXERCICES         = Database::get_course_table(TABLE_QUIZ_TEST);
  61  $TBL_QUESTIONS         = Database::get_course_table(TABLE_QUIZ_QUESTION);
  62  $TBL_REPONSES          = Database::get_course_table(TABLE_QUIZ_ANSWER);
  63  
  64  //debug param. 0: no display - 1: debug display

  65  $debug=0;
  66  if($debug>0){echo str_repeat('&nbsp;',0).'Entered exercise_result.php'."<br />\n";var_dump($_POST);}
  67  
  68  // general parameters passed via POST/GET

  69  $my_course_code = $_GET['cid'];
  70  if(!empty($_REQUEST['exe'])){
  71      $my_exe = $_REQUEST['exe'];
  72  }else{
  73      $my_exe = null;
  74  }
  75  if(!empty($_REQUEST['qst'])){
  76      $my_qst = $_REQUEST['qst'];
  77  }else{
  78      $my_qst = null;
  79  }
  80  if(!empty($_REQUEST['usr'])){
  81      $my_usr = $_REQUEST['usr'];
  82  }else{
  83      $my_usr = null;
  84  }
  85  if(!empty($_REQUEST['cidReq'])){
  86      $my_cid = $_REQUEST['cidReq'];
  87  }else{
  88      $my_cid = null;
  89  }
  90  if(!empty($_POST['action'])){
  91      $action = $_POST['action'];
  92  }else{
  93      $action = '';
  94  }
  95  
  96  if (empty($my_qst) or empty($my_usr) or empty($my_cid) or empty($my_exe)){
  97      header('Location: exercice.php');
  98      exit();
  99  }
 100  
 101  if(!$is_courseTutor)
 102  {
 103      api_not_allowed();
 104  }
 105  
 106  $obj_question = Question :: read($my_qst);
 107  
 108  if (isset($_SESSION['gradebook'])){
 109      $gradebook=    $_SESSION['gradebook'];
 110  }
 111  
 112  if (!empty($gradebook) && $gradebook=='view') {    
 113      $interbreadcrumb[]= array (
 114              'url' => '../gradebook/'.$_SESSION['gradebook_dest'],
 115              'name' => get_lang('Gradebook')
 116          );
 117  }
 118  
 119  $nameTools=get_lang('Exercice');
 120  
 121  $interbreadcrumb[]=array("url" => "exercice.php","name" => get_lang('Exercices'));
 122  
 123  $my_msg = 'No change.';
 124  
 125  if($action == 'mark'){
 126      if (!empty($_POST['score']) AND $_POST['score'] < $obj_question->selectWeighting() AND $_POST['score'] >= 0){
 127  
 128          //mark the user mark into the database using something similar to the following function:

 129          global $_configuration;
 130  
 131          if($_configuration['tracking_enabled'])
 132          {
 133              $exercise_table = Database::get_statistic_table('track_e_exercices');
 134              #$tbl_learnpath_user = Database::get_course_table('learnpath_user');

 135              #global $origin, $tbl_learnpath_user, $learnpath_id, $learnpath_item_id;

 136              $sql = "SELECT * FROM $exercise_table
 137                  WHERE exe_user_id = '".Database::escape_string($my_usr)."' AND exe_cours_id = '".Database::escape_string($my_cid)."' AND exe_exo_id = '".Database::escape_string($my_exe)."'
 138                  ORDER BY exe_date DESC";
 139              #echo $sql;

 140              $res = api_sql_query($sql,__FILE__,__LINE__);
 141              if(mysql_num_rows($res)>0){
 142                  $row = mysql_fetch_array($res);
 143                  //@todo Check that just summing past score and the new free answer mark doesn't come up

 144                  // with a score higher than the possible score for that exercise

 145                  $my_score = $row['exe_result'] + $_POST['score'];
 146                  $sql = "UPDATE $exercise_table SET exe_result = '$my_score'
 147                      WHERE exe_id = '".$row['exe_id']."'";
 148                  #echo $sql;

 149                  $res = api_sql_query($sql,__FILE__,__LINE__);
 150                  $my_msg = get_lang('MarkIsUpdated');
 151              }else{
 152                  $my_score = $_POST['score'];
 153                  $reallyNow = time();
 154                  $sql = "INSERT INTO $exercise_table
 155                            (
 156                             exe_user_id,
 157                             exe_cours_id,
 158                             exe_exo_id,
 159                             exe_result,
 160                             exe_weighting,
 161                             exe_date
 162                            )
 163  
 164                            VALUES
 165                            (
 166                             '".Database::escape_string($my_usr)."',
 167                             '".Database::escape_string($my_cid)."',
 168                             '".Database::escape_string($my_exe)."',
 169                             '".Database::escape_string($my_score)."',
 170                             '".Database::escape_string($obj_question->selectWeighting())."',
 171                             FROM_UNIXTIME(".$reallyNow.")
 172                            )";
 173                  #if ($origin == 'learnpath')

 174                  #{

 175                  #    if ($user_id == "NULL")

 176                  #    {

 177                  #        $user_id = '0';

 178                  #    }

 179                  #    $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')";

 180                  #    $res2 = api_sql_query($sql2,__FILE__,__LINE__);

 181                  #}

 182                  $res = api_sql_query($sql,__FILE__,__LINE__);
 183                  $my_msg = get_lang('MarkInserted');
 184              }
 185              //$mysql_query($sql);

 186              //return 0;

 187          }
 188      }else{
 189          $my_msg .= get_lang('TotalScoreTooBig');
 190      }
 191  }
 192  
 193  Display::display_tool_header($nameTools,"Exercise");
 194  
 195  // Display simple marking interface

 196  
 197  // 1a - result of previous marking then exit suggestion

 198  // 1b - user answer and marking box + submit button

 199  $objAnswerTmp = new Answer();
 200  $objAnswerTmp->selectAnswer($answerId);
 201  
 202  if($action == 'mark'){
 203      echo $my_msg.'<br />
 204          <a href="exercice.php?cidReq='.$cidReq.'">'.get_lang('Back').'</a>';
 205  }else{
 206  
 207  
 208      echo '<h2>'.$obj_question->question .':</h2>
 209          '.$obj_question->selectTitle().'<br /><br />
 210          '.get_lang('PleaseGiveAMark').
 211          "<form action='' method='POST'>\n"
 212          ."<input type='hidden' name='exe' value='$my_exe'>\n"
 213          ."<input type='hidden' name='usr' value='$my_usr'>\n"
 214          ."<input type='hidden' name='cidReq' value='$my_cid'>\n"
 215          ."<input type='hidden' name='action' value='mark'>\n"
 216          ."<select name='score'>\n";
 217          for($i=0 ; $i<$obj_question->selectWeighting() ; $i++){
 218              echo '<option>'.$i.'</option>';
 219          }
 220          echo "</select>".
 221          "<input type='submit' name='submit' value='".get_lang('Ok')."'>\n"
 222          ."</form>";
 223  }
 224  
 225  Display::display_footer();
 226  
 227  ?>

title

Description

title

Description

title

Description

title

title

Body