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;
}
`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';
# --------------------------------------------------------
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';
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;
}
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'
);
# --------------------------------------------------------
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);
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,
// 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'
global $QUIZ_QUESTION_TYPE;
- echo "<A HREF=\"question.php?id=$question->id\" TITLE=\"".$QUIZ_QUESTION_TYPE[$question->type]."\">";
- switch ($question->type) {
+ echo "<A HREF=\"question.php?id=$question->id\" TITLE=\"".$QUIZ_QUESTION_TYPE[$question->qtype]."\">";
+ switch ($question->qtype) {
case SHORTANSWER:
echo "<IMG BORDER=0 HEIGHT=16 WIDTH=16 SRC=\"pix/sa.gif\">";
break;
notify("Error: Question not found!");
}
+ if (empty($actualgrade)) {
+ $actualgrade = 0;
+ }
+
$stranswer = get_string("answer", "quiz");
$strmarks = get_string("marks", "quiz");
print_spacer(1,100);
echo "</TD><TD VALIGN=TOP>";
- switch ($question->type) {
+ switch ($question->qtype) {
case SHORTANSWER:
if (!$options = get_record("quiz_shortanswer", "question", $question->id)) {
notify("Error: Missing question options!");
}
if ($response) {
$value = "VALUE=\"$response[0]\"";
+ } else {
+ $value = "";
}
echo "<P ALIGN=RIGHT>$stranswer: <INPUT TYPE=TEXT NAME=q$question->id SIZE=20 $value></P>";
if ($feedback) {
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) {
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";
}
}
echo "<FORM METHOD=GET ACTION=question.php>";
echo "<B>$strquestion:</B> ";
- choose_from_menu($QUIZ_QUESTION_TYPE, "type", "", "");
+ choose_from_menu($QUIZ_QUESTION_TYPE, "qtype", "", "");
echo "<INPUT TYPE=hidden NAME=category VALUE=\"$category->id\">";
echo "<INPUT TYPE=submit NAME=new VALUE=\"$strcreatenewquestion\">";
helpbutton("questiontypes", $strcreatenewquestion, "quiz");
$feedback = array();
$response = array();
- switch ($question->type) {
+ switch ($question->qtype) {
case SHORTANSWER:
if ($question->answer) {
$question->answer = trim($question->answer[0]);
$question->answer = "";
}
$response[0] = $question->answer;
+ $bestshortanswer = 0;
foreach($answers as $answer) { // There might be multiple right answers
if ($answer->fraction > $bestshortanswer) {
$correct[$answer->id] = $answer->answer;
+ $bestshortanswer = $answer->fraction;
}
if (!$answer->usecase) { // Don't compare case
$answer->answer = strtolower($answer->answer);
</TABLE>\r
\r
<INPUT type="hidden" name=id value="<? p($question->id) ?>">\r
-<INPUT type="hidden" name=type value="<? p($question->type) ?>">\r
+<INPUT type="hidden" name=qtype value="<? p($question->qtype) ?>">\r
<INPUT type="submit" value="<? print_string("savechanges") ?>">\r
\r
</CENTER>\r
optional_variable($id);
- optional_variable($type);
+ optional_variable($qtype);
optional_variable($category);
if ($id) {
error("This question category doesn't belong to a valid course!");
}
- $type = $question->type;
+ $qtype = $question->qtype;
} else if ($category) {
}
$question->category = $category->id;
- $question->type = $type;
+ $question->qtype = $qtype;
} else {
error("Must specify question id or category");
// Now to save all the answers and type-specific options
- switch ($question->type) {
+ switch ($question->qtype) {
case SHORTANSWER:
// Delete all the old answers
delete_records("quiz_answers", "question", $question->id);
}
unset($options);
- $options->question = $question->id;
- $options->true = $true->id;
- $options->false = $false->id;
+ $options->question = $question->id;
+ $options->trueanswer = $true->id;
+ $options->falseanswer = $false->id;
if (!insert_record("quiz_truefalse", $options)) {
error("Could not insert quiz truefalse options!");
}
}
- switch ($type) {
+ switch ($qtype) {
case SHORTANSWER:
if (!empty($question->id)) {
$options = get_record("quiz_shortanswer", "question", $question->id);
if (!empty($question->id)) {
$options = get_record("quiz_truefalse", "question", "$question->id");
}
- if (!empty($options->true)) {
- $true = get_record("quiz_answers", "id", "$options->true");
+ if (!empty($options->trueanswer)) {
+ $true = get_record("quiz_answers", "id", $options->trueanswer);
} else {
$true->fraction = 1;
$true->feedback = "";
}
- if (!empty($options->false)) {
- $false = get_record("quiz_answers", "id", "$options->false");
+ if (!empty($options->falseanswer)) {
+ $false = get_record("quiz_answers", "id", "$options->falseanswer");
} else {
$false->fraction = 0;
$false->feedback = "";
</TABLE>\r
\r
<INPUT type="hidden" name=id value="<? p($question->id) ?>">\r
-<INPUT type="hidden" name=type value="<? p($question->type) ?>">\r
+<INPUT type="hidden" name=qtype value="<? p($question->qtype) ?>">\r
<INPUT type="submit" value="<? print_string("savechanges") ?>">\r
\r
</CENTER>\r
</TABLE>\r
\r
<INPUT type="hidden" name=id value="<? p($question->id) ?>">\r
-<INPUT type="hidden" name=type value="<? p($question->type) ?>">\r
+<INPUT type="hidden" name=qtype value="<? p($question->qtype) ?>">\r
<INPUT type="submit" value="<? print_string("savechanges") ?>">\r
\r
</CENTER>\r
// This fragment is called by moodle_needs_upgrading() and /admin/index.php
////////////////////////////////////////////////////////////////////////////////
-$module->version = 2003010100; // The (date) version of this module
+$module->version = 2003010301; // The (date) version of this module
$module->cron = 0; // How often should cron check this module (seconds)?
?>