diff --git a/mod/quiz/db/mysql.php b/mod/quiz/db/mysql.php
index 754eef177db..11c787380a1 100644
--- a/mod/quiz/db/mysql.php
+++ b/mod/quiz/db/mysql.php
@@ -29,12 +29,18 @@ function quiz_upgrade($oldversion) {
execute_sql("ALTER TABLE `quiz_attempts` CHANGE `user` `userid` INT(10) UNSIGNED DEFAULT '0' NOT NULL ");
}
- // prefixes required from here on
+ // prefixes required from here on, or use table_column()
if ($oldversion < 2003010100) {
execute_sql(" ALTER TABLE {$CFG->prefix}quiz ADD review TINYINT(4) UNSIGNED DEFAULT '0' NOT NULL AFTER `grademethod` ");
}
+ if ($oldversion < 2003010301) {
+ table_column("quiz_truefalse", "true", "trueanswer", "INTEGER", "UNSIGNED", "0", "NOT NULL", "");
+ table_column("quiz_truefalse", "false", "falseanswer", "INTEGER", "UNSIGNED", "0", "NOT NULL", "");
+ table_column("quiz_questions", "type", "qtype", "INTEGER", "UNSIGNED", "0", "NOT NULL", "");
+ }
+
return true;
}
diff --git a/mod/quiz/db/mysql.sql b/mod/quiz/db/mysql.sql
index 4c844a757a5..c601b5d9066 100644
--- a/mod/quiz/db/mysql.sql
+++ b/mod/quiz/db/mysql.sql
@@ -132,7 +132,7 @@ CREATE TABLE `prefix_quiz_questions` (
`name` varchar(255) NOT NULL default '',
`questiontext` text NOT NULL,
`image` varchar(255) NOT NULL default '',
- `type` smallint(6) NOT NULL default '0',
+ `qtype` smallint(6) NOT NULL default '0',
PRIMARY KEY (`id`)
) TYPE=MyISAM COMMENT='The quiz questions themselves';
# --------------------------------------------------------
@@ -172,8 +172,8 @@ CREATE TABLE `prefix_quiz_shortanswer` (
CREATE TABLE `prefix_quiz_truefalse` (
`id` int(10) unsigned NOT NULL auto_increment,
`question` int(10) unsigned NOT NULL default '0',
- `true` int(10) unsigned NOT NULL default '0',
- `false` int(10) unsigned NOT NULL default '0',
+ `trueanswer` int(10) unsigned NOT NULL default '0',
+ `falseanswer` int(10) unsigned NOT NULL default '0',
PRIMARY KEY (`id`),
KEY `question` (`question`)
) TYPE=MyISAM COMMENT='Options for True-False questions';
diff --git a/mod/quiz/db/postgres7.php b/mod/quiz/db/postgres7.php
index 87cd5dff450..bc7010d2c6f 100644
--- a/mod/quiz/db/postgres7.php
+++ b/mod/quiz/db/postgres7.php
@@ -10,6 +10,12 @@ function quiz_upgrade($oldversion) {
execute_sql(" ALTER TABLE {$CFG->prefix}quiz ADD review integer DEFAULT '0' NOT NULL AFTER `grademethod` ");
}
+ if ($oldversion < 2003010301) {
+ table_column("quiz_truefalse", "true", "trueanswer", "INTEGER", "UNSIGNED", "0", "NOT NULL", "");
+ table_column("quiz_truefalse", "false", "falseanswer", "INTEGER", "UNSIGNED", "0", "NOT NULL", "");
+ table_column("quiz_questions", "type", "qtype", "INTEGER", "UNSIGNED", "0", "NOT NULL", "");
+ }
+
return true;
}
diff --git a/mod/quiz/db/postgres7.sql b/mod/quiz/db/postgres7.sql
index c42b7b02b07..459e22a3454 100644
--- a/mod/quiz/db/postgres7.sql
+++ b/mod/quiz/db/postgres7.sql
@@ -124,7 +124,7 @@ CREATE TABLE prefix_quiz_questions (
name varchar(255) NOT NULL default '',
questiontext text NOT NULL default '',
image varchar(255) NOT NULL default '',
- type integer NOT NULL default '0'
+ qtype integer NOT NULL default '0'
);
# --------------------------------------------------------
@@ -161,8 +161,8 @@ CREATE INDEX question_prefix_quiz_shortanswer_idx ON prefix_quiz_shortanswer (qu
CREATE TABLE prefix_quiz_truefalse (
id SERIAL PRIMARY KEY,
question integer NOT NULL default '0',
- "true" integer NOT NULL default '0',
- "false" integer NOT NULL default '0'
+ trueanswer integer NOT NULL default '0',
+ falseanswer integer NOT NULL default '0'
);
CREATE INDEX question_prefix_quiz_truefalse_idx ON prefix_quiz_truefalse (question);
diff --git a/mod/quiz/lib.php b/mod/quiz/lib.php
index 58cc00a3982..bfb61ef192f 100644
--- a/mod/quiz/lib.php
+++ b/mod/quiz/lib.php
@@ -240,7 +240,7 @@ function quiz_get_grade_records($quiz) {
function quiz_get_answers($question) {
// Given a question, returns the correct answers and grades
global $CFG;
- switch ($question->type) {
+ switch ($question->qtype) {
case SHORTANSWER; // Could be multiple answers
return get_records_sql("SELECT a.*, sa.usecase, g.grade
FROM {$CFG->prefix}quiz_shortanswer sa,
@@ -285,7 +285,7 @@ function quiz_get_attempt_responses($attempt) {
// for regrading using quiz_grade_attempt_results()
global $CFG;
- if (!$responses = get_records_sql("SELECT q.id, q.type, r.answer
+ if (!$responses = get_records_sql("SELECT q.id, q.qtype, r.answer
FROM {$CFG->prefix}quiz_responses r,
{$CFG->prefix}quiz_questions q
WHERE r.attempt = '$attempt->id'
@@ -324,8 +324,8 @@ function quiz_print_question_icon($question) {
global $QUIZ_QUESTION_TYPE;
- echo "id\" TITLE=\"".$QUIZ_QUESTION_TYPE[$question->type]."\">";
- switch ($question->type) {
+ echo "id\" TITLE=\"".$QUIZ_QUESTION_TYPE[$question->qtype]."\">";
+ switch ($question->qtype) {
case SHORTANSWER:
echo "
";
break;
@@ -350,6 +350,10 @@ function quiz_print_question($number, $questionid, $grade, $courseid,
notify("Error: Question not found!");
}
+ if (empty($actualgrade)) {
+ $actualgrade = 0;
+ }
+
$stranswer = get_string("answer", "quiz");
$strmarks = get_string("marks", "quiz");
@@ -363,7 +367,7 @@ function quiz_print_question($number, $questionid, $grade, $courseid,
print_spacer(1,100);
echo "
$stranswer: id SIZE=20 $value>
"; if ($feedback) { @@ -389,10 +395,10 @@ function quiz_print_question($number, $questionid, $grade, $courseid, if (!$options = get_record("quiz_truefalse", "question", $question->id)) { notify("Error: Missing question options!"); } - if (!$true = get_record("quiz_answers", "id", $options->true)) { + if (!$true = get_record("quiz_answers", "id", $options->trueanswer)) { notify("Error: Missing question answers!"); } - if (!$false = get_record("quiz_answers", "id", $options->false)) { + if (!$false = get_record("quiz_answers", "id", $options->falseanswer)) { notify("Error: Missing question answers!"); } if (!$true->answer) { @@ -406,18 +412,24 @@ function quiz_print_question($number, $questionid, $grade, $courseid, print_file_picture($question->image, $courseid, 200); } - if ($response[$true->id]) { + $truechecked = ""; + $falsechecked = ""; + + if (!empty($response[$true->id])) { $truechecked = "CHECKED"; $feedbackid = $true->id; - } else if ($response[$false->id]) { + } else if (!empty($response[$false->id])) { $falsechecked = "CHECKED"; $feedbackid = $false->id; } + + $truecorrect = ""; + $falsecorrect = ""; if ($correct) { - if ($correct[$true->id]) { + if (!empty($correct[$true->id])) { $truecorrect = "CLASS=highlight"; } - if ($correct[$false->id]) { + if (!empty($correct[$false->id])) { $falsecorrect = "CLASS=highlight"; } } @@ -751,7 +763,7 @@ function quiz_print_cat_question_list($categoryid) { echo "