dokeos-exercise
[ class tree: dokeos-exercise ] [ index: dokeos-exercise ] [ all elements ]

Source for file mark_free_answer.php

Documentation is available at mark_free_answer.php

  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 mysql_real_escape_string($_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_qstor empty($my_usror empty($my_cidor 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. $nameTools=get_lang('Exercice');
  109.  
  110. $interbreadcrumb[]=array("url" => "exercice.php","name" => get_lang('Exercices'));
  111.  
  112. $my_msg 'No change.';
  113.  
  114. if($action == 'mark'){
  115.     if (!empty($_POST['score']AND $_POST['score'$obj_question->selectWeighting(AND $_POST['score'>= 0){
  116.  
  117.         //mark the user mark into the database using something similar to the following function:
  118.         global $_configuration;
  119.  
  120.         if($_configuration['tracking_enabled'])
  121.         {
  122.             $exercise_table Database::get_statistic_table('track_e_exercices');
  123.             #$tbl_learnpath_user = Database::get_course_table('learnpath_user');
  124.             #global $origin, $tbl_learnpath_user, $learnpath_id, $learnpath_item_id;
  125.             $sql "SELECT * FROM $exercise_table
  126.                 WHERE exe_user_id = '$my_usr' AND exe_cours_id = '$my_cid' AND exe_exo_id = '$my_exe'
  127.                 ORDER BY exe_date DESC";
  128.             #echo $sql;
  129.             $res api_sql_query($sql,__FILE__,__LINE__);
  130.             if(mysql_num_rows($res)>0){
  131.                 $row mysql_fetch_array($res);
  132.                 //@todo Check that just summing past score and the new free answer mark doesn't come up
  133.                 // with a score higher than the possible score for that exercise
  134.                 $my_score $row['exe_result'$_POST['score'];
  135.                 $sql "UPDATE $exercise_table SET exe_result = '$my_score'
  136.                     WHERE exe_id = '".$row['exe_id']."'";
  137.                 #echo $sql;
  138.                 $res api_sql_query($sql,__FILE__,__LINE__);
  139.                 $my_msg get_lang('MarkIsUpdated');
  140.             }else{
  141.                 $my_score $_POST['score'];
  142.                 $reallyNow time();
  143.                 $sql "INSERT INTO $exercise_table
  144.                           (
  145.                            `exe_user_id`,
  146.                            `exe_cours_id`,
  147.                            `exe_exo_id`,
  148.                            `exe_result`,
  149.                            `exe_weighting`,
  150.                            `exe_date`
  151.                           )
  152.  
  153.                           VALUES
  154.                           (
  155.                           ".$my_usr.",
  156.                            '".$my_cid."',
  157.                            '".$my_exe."',
  158.                            '".$my_score."',
  159.                            '".$obj_question->selectWeighting()."',
  160.                            FROM_UNIXTIME(".$reallyNow.")
  161.                           )";
  162.                 #if ($origin == 'learnpath')
  163.                 #{
  164.                 #    if ($user_id == "NULL")
  165.                 #    {
  166.                 #        $user_id = '0';
  167.                 #    }
  168.                 #    $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')";
  169.                 #    $res2 = api_sql_query($sql2,__FILE__,__LINE__);
  170.                 #}
  171.                 $res api_sql_query($sql,__FILE__,__LINE__);
  172.                 $my_msg get_lang('MarkInserted');
  173.             }
  174.             //$mysql_query($sql);
  175.             //return 0;
  176.         }
  177.     }else{
  178.         $my_msg .= " There might have been a problem with the total score being too big...<br />\n";
  179.     }
  180. }
  181.  
  182. Display::display_header($nameTools,"Exercise");
  183.  
  184. // Display simple marking interface
  185.  
  186. // 1a - result of previous marking then exit suggestion
  187. // 1b - user answer and marking box + submit button
  188. $objAnswerTmp new Answer();
  189. $objAnswerTmp->selectAnswer($answerId);
  190.  
  191. if($action == 'mark'){
  192.     echo $my_msg.'<br />
  193.         <a href="exercice.php?cidReq='.$cidReq.'">'.get_lang('Back').'</a>';
  194. }else{
  195.  
  196.  
  197.     echo '<h2>'.$obj_question->question .':</h2>
  198.         '.$obj_question->selectTitle().'<br /><br />
  199.         '.get_lang('PleaseGiveAMark').
  200.         "<form action='' method='POST'>\n"
  201.         ."<input type='hidden' name='exe' value='$my_exe'>\n"
  202.         ."<input type='hidden' name='usr' value='$my_usr'>\n"
  203.         ."<input type='hidden' name='cidReq' value='$my_cid'>\n"
  204.         ."<input type='hidden' name='action' value='mark'>\n"
  205.         ."<select name='score'>\n";
  206.         for($i=$i<$obj_question->selectWeighting($i++){
  207.             echo '<option>'.$i.'</option>';
  208.         }
  209.         echo "</select>".
  210.         "<input type='submit' name='submit' value='".get_lang('Ok')."'>\n"
  211.         ."</form>";
  212. }
  213.  
  214.  
  215. ?>

Documentation generated on Thu, 12 Jun 2008 14:04:54 -0500 by phpDocumentor 1.4.1