mirror of
https://github.com/moodle/moodle.git
synced 2025-01-17 21:49:15 +01:00
Many little fixes and cleanups for robustness
This commit is contained in:
parent
b9b8ab696f
commit
c04c41c7d2
@ -61,6 +61,8 @@ $string['guestsno'] = "Sorry, guests can not see or attempt quizzes";
|
||||
$string['imagedisplay'] = "Image to display";
|
||||
$string['introduction'] = "Introduction";
|
||||
$string['marks'] = "Marks";
|
||||
$string['missingname'] = "Missing question name";
|
||||
$string['missingquestiontext'] = "Missing question text";
|
||||
$string['multichoice'] = "Multiple Choice";
|
||||
$string['noanswers'] = "No answers were selected!";
|
||||
$string['noattempts'] = "No attempts have been made on this quiz";
|
||||
|
@ -69,14 +69,8 @@
|
||||
}
|
||||
}
|
||||
|
||||
if ($course->format == "weeks" and $quiz->days) {
|
||||
$timenow = time();
|
||||
$timestart = $course->startdate + (($cw->section - 1) * 608400);
|
||||
$timefinish = $timestart + (3600 * 24 * $quiz->days);
|
||||
$available = ($timestart < $timenow and $timenow < $timefinish);
|
||||
} else {
|
||||
$available = true;
|
||||
}
|
||||
$timenow = time();
|
||||
$available = ($quiz->timeopen < $timenow and $timenow < $quiz->timeclose);
|
||||
|
||||
/// Check to see if they are submitting answers
|
||||
if (match_referer() && isset($HTTP_POST_VARS)) {
|
||||
|
@ -83,7 +83,7 @@
|
||||
|
||||
echo "<P ALIGN=CENTER><FONT SIZE=3>";
|
||||
echo $streditcategories;
|
||||
helpbutton("categories", $strcategories, "quiz");
|
||||
helpbutton("categories", $streditcategories, "quiz");
|
||||
echo "</FONT></P>";
|
||||
|
||||
/// If data submitted, then process and store.
|
||||
|
@ -5,10 +5,14 @@
|
||||
|
||||
require_login();
|
||||
|
||||
if (empty($destination)) {
|
||||
$destination = "";
|
||||
}
|
||||
|
||||
if (match_referer($destination) && isset($course) && isset($HTTP_POST_VARS)) { // form submitted from mod.html
|
||||
$modform = (object)$HTTP_POST_VARS;
|
||||
|
||||
if (!$modform->name or !$modform->intro) {
|
||||
if (empty($modform->name) or empty($modform->intro)) {
|
||||
error(get_string("filloutallfields"), $HTTP_REFERER);
|
||||
}
|
||||
|
||||
@ -34,14 +38,14 @@
|
||||
error("You can't modify this course!");
|
||||
}
|
||||
|
||||
if (! $modform->grades) { // Construct an array to hold all the grades.
|
||||
if (empty($modform->grades)) { // Construct an array to hold all the grades.
|
||||
$modform->grades = quiz_get_all_question_grades($modform->questions, $modform->instance);
|
||||
}
|
||||
|
||||
|
||||
// Now, check for commands on this page and modify variables as necessary
|
||||
|
||||
if ($up) { /// Move the given question up a slot
|
||||
if (!empty($up)) { /// Move the given question up a slot
|
||||
$questions = explode(",", $modform->questions);
|
||||
if ($questions[0] <> $up) {
|
||||
foreach ($questions as $key => $question) {
|
||||
@ -56,7 +60,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
if ($down) { /// Move the given question down a slot
|
||||
if (!empty($down)) { /// Move the given question down a slot
|
||||
$questions = explode(",", $modform->questions);
|
||||
if ($questions[count($questions)-1] <> $down) {
|
||||
foreach ($questions as $key => $question) {
|
||||
@ -71,9 +75,9 @@
|
||||
}
|
||||
}
|
||||
|
||||
if ($add) { /// Add a question to the current quiz
|
||||
if (!empty($add)) { /// Add a question to the current quiz
|
||||
$rawquestions = $HTTP_POST_VARS;
|
||||
if ($modform->questions) {
|
||||
if (!empty($modform->questions)) {
|
||||
$questions = explode(",", $modform->questions);
|
||||
}
|
||||
foreach ($rawquestions as $key => $value) { // Parse input for question ids
|
||||
@ -90,14 +94,14 @@
|
||||
$modform->grades[$key] = 1; // default score
|
||||
}
|
||||
}
|
||||
if ($questions) {
|
||||
if (!empty($questions)) {
|
||||
$modform->questions = implode(",", $questions);
|
||||
} else {
|
||||
$modform->questions = "";
|
||||
}
|
||||
}
|
||||
|
||||
if ($delete) { /// Delete a question from the list
|
||||
if (!empty($delete)) { /// Delete a question from the list
|
||||
$questions = explode(",", $modform->questions);
|
||||
foreach ($questions as $key => $question) {
|
||||
if ($question == $delete) {
|
||||
@ -108,7 +112,7 @@
|
||||
$modform->questions = implode(",", $questions);
|
||||
}
|
||||
|
||||
if ($setgrades) { /// The grades have been updated, so update our internal list
|
||||
if (!empty($setgrades)) { /// The grades have been updated, so update our internal list
|
||||
$rawgrades = $HTTP_POST_VARS;
|
||||
unset($modform->grades);
|
||||
foreach ($rawgrades as $key => $value) { // Parse input for question -> grades
|
||||
@ -119,12 +123,16 @@
|
||||
}
|
||||
}
|
||||
|
||||
if ($cat) { //-----------------------------------------------------------
|
||||
if (!empty($cat)) { //-----------------------------------------------------------
|
||||
$modform->category = $cat;
|
||||
}
|
||||
|
||||
if (empty($modform->category)) {
|
||||
$modform->category = "";
|
||||
}
|
||||
|
||||
$modform->sumgrades = 0;
|
||||
if ($modform->grades) {
|
||||
if (!empty($modform->grades)) {
|
||||
foreach ($modform->grades as $grade) {
|
||||
$modform->sumgrades += $grade;
|
||||
}
|
||||
|
@ -34,9 +34,9 @@ function quiz_add_instance($quiz) {
|
||||
$quiz->created = time();
|
||||
$quiz->timemodified = time();
|
||||
$quiz->timeopen = make_timestamp($quiz->openyear, $quiz->openmonth, $quiz->openday,
|
||||
$quiz->openhour, $quiz->openminute, $quiz->opensecond);
|
||||
$quiz->openhour, $quiz->openminute, 0);
|
||||
$quiz->timeclose = make_timestamp($quiz->closeyear, $quiz->closemonth, $quiz->closeday,
|
||||
$quiz->closehour, $quiz->closeminute, $quiz->closesecond);
|
||||
$quiz->closehour, $quiz->closeminute, 0);
|
||||
|
||||
if (!$quiz->id = insert_record("quiz", $quiz)) {
|
||||
return false; // some error occurred
|
||||
@ -68,9 +68,9 @@ function quiz_update_instance($quiz) {
|
||||
|
||||
$quiz->timemodified = time();
|
||||
$quiz->timeopen = make_timestamp($quiz->openyear, $quiz->openmonth, $quiz->openday,
|
||||
$quiz->openhour, $quiz->openminute, $quiz->opensecond);
|
||||
$quiz->openhour, $quiz->openminute, 0);
|
||||
$quiz->timeclose = make_timestamp($quiz->closeyear, $quiz->closemonth, $quiz->closeday,
|
||||
$quiz->closehour, $quiz->closeminute, $quiz->closesecond);
|
||||
$quiz->closehour, $quiz->closeminute, 0);
|
||||
$quiz->id = $quiz->instance;
|
||||
|
||||
if (!update_record("quiz", $quiz)) {
|
||||
|
@ -11,11 +11,17 @@
|
||||
<TD align=right><P><B><? print_string("questionname", "quiz") ?>:</B></P></TD>
|
||||
<TD>
|
||||
<INPUT type="text" name="name" size=40 value="<? p($question->name) ?>">
|
||||
<? if (isset($err["name"])) formerr($err["name"]); ?>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR valign=top>
|
||||
<TD align=right><P><B><? print_string("question", "quiz") ?>:</B></P></TD>
|
||||
<TD>
|
||||
<? if (isset($err["questiontext"])) {
|
||||
formerr($err["questiontext"]);
|
||||
echo "<BR \>";
|
||||
}
|
||||
?>
|
||||
<textarea name="questiontext" rows=5 cols=50 wrap="virtual"><? p($question->questiontext)?></textarea>
|
||||
<? helpbutton("text", get_string("helptext")); ?>
|
||||
</TD>
|
||||
@ -35,10 +41,10 @@
|
||||
<TD align=right><P><B><? print_string("answerhowmany", "quiz") ?>:</B></P></TD>
|
||||
<TD>
|
||||
<?
|
||||
unset($menu);
|
||||
$menu[0] = get_string("answersingleno", "quiz");
|
||||
$menu[1] = get_string("answersingleyes", "quiz");
|
||||
choose_from_menu($menu, "single", "$options->single", "");
|
||||
unset($menu);
|
||||
?>
|
||||
</TD>
|
||||
</TR>
|
||||
|
@ -51,7 +51,7 @@
|
||||
|
||||
print_header("$course->shortname: $streditingquestion", "$course->shortname: $streditingquestion",
|
||||
"<A HREF=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</A>
|
||||
-> <A HREF=\"$HTTP_REFERER\">$streditingquiz</A> -> $streditingquestion");
|
||||
-> <A HREF=\"edit.php\">$streditingquiz</A> -> $streditingquestion");
|
||||
|
||||
if (isset($delete)) {
|
||||
if (isset($confirm)) {
|
||||
@ -104,156 +104,158 @@
|
||||
$question->image = $form->image;
|
||||
$question->category = $form->category;
|
||||
|
||||
if ($question->id) { // Question already exists
|
||||
if (!update_record("quiz_questions", $question)) {
|
||||
error("Could not update question!");
|
||||
if (!$err = formcheck($question)) {
|
||||
|
||||
if (!empty($question->id)) { // Question already exists
|
||||
if (!update_record("quiz_questions", $question)) {
|
||||
error("Could not update question!");
|
||||
}
|
||||
} else { // Question is a new one
|
||||
if (!$question->id = insert_record("quiz_questions", $question)) {
|
||||
error("Could not insert new question!");
|
||||
}
|
||||
}
|
||||
} else { // Question is a new one
|
||||
if (!$question->id = insert_record("quiz_questions", $question)) {
|
||||
error("Could not insert new question!");
|
||||
}
|
||||
}
|
||||
|
||||
// Now to save all the answers and type-specific options
|
||||
|
||||
switch ($question->type) {
|
||||
case SHORTANSWER:
|
||||
// Delete all the old answers
|
||||
delete_records("quiz_answers", "question", $question->id);
|
||||
delete_records("quiz_shortanswer", "question", $question->id);
|
||||
|
||||
$answers = array();
|
||||
$maxfraction = -1;
|
||||
|
||||
// Insert all the new answers
|
||||
foreach ($form->answer as $key => $formanswer) {
|
||||
if ($formanswer) {
|
||||
unset($answer);
|
||||
$answer->answer = $formanswer;
|
||||
$answer->question = $question->id;
|
||||
$answer->fraction = $fraction[$key];
|
||||
$answer->feedback = $feedback[$key];
|
||||
if (!$answer->id = insert_record("quiz_answers", $answer)) {
|
||||
error("Could not insert quiz answer!");
|
||||
}
|
||||
$answers[] = $answer->id;
|
||||
if ($fraction[$key] > $maxfraction) {
|
||||
$maxfraction = $fraction[$key];
|
||||
|
||||
// Now to save all the answers and type-specific options
|
||||
|
||||
switch ($question->type) {
|
||||
case SHORTANSWER:
|
||||
// Delete all the old answers
|
||||
delete_records("quiz_answers", "question", $question->id);
|
||||
delete_records("quiz_shortanswer", "question", $question->id);
|
||||
|
||||
$answers = array();
|
||||
$maxfraction = -1;
|
||||
|
||||
// Insert all the new answers
|
||||
foreach ($form->answer as $key => $formanswer) {
|
||||
if ($formanswer) {
|
||||
unset($answer);
|
||||
$answer->answer = $formanswer;
|
||||
$answer->question = $question->id;
|
||||
$answer->fraction = $fraction[$key];
|
||||
$answer->feedback = $feedback[$key];
|
||||
if (!$answer->id = insert_record("quiz_answers", $answer)) {
|
||||
error("Could not insert quiz answer!");
|
||||
}
|
||||
$answers[] = $answer->id;
|
||||
if ($fraction[$key] > $maxfraction) {
|
||||
$maxfraction = $fraction[$key];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unset($options);
|
||||
$options->question = $question->id;
|
||||
$options->answers = implode(",",$answers);
|
||||
$options->usecase = $form->usecase;
|
||||
if (!insert_record("quiz_shortanswer", $options)) {
|
||||
error("Could not insert quiz shortanswer options!");
|
||||
}
|
||||
|
||||
/// Perform sanity checks on fractional grades
|
||||
if ($maxfraction != 1) {
|
||||
$maxfraction = $maxfraction * 100;
|
||||
notice_yesno(get_string("fractionsnomax", "quiz", $maxfraction), "question.php?id=$question->id", "edit.php");
|
||||
print_footer($course);
|
||||
exit;
|
||||
}
|
||||
break;
|
||||
case TRUEFALSE:
|
||||
delete_records("quiz_answers", "question", $question->id);
|
||||
delete_records("quiz_truefalse", "question", $question->id);
|
||||
|
||||
$true->answer = get_string("true", "quiz");
|
||||
$true->question = $question->id;
|
||||
$true->fraction = $form->answer;
|
||||
$true->feedback = $form->feedbacktrue;
|
||||
if (!$true->id = insert_record("quiz_answers", $true)) {
|
||||
error("Could not insert quiz answer \"true\")!");
|
||||
}
|
||||
|
||||
$false->answer = get_string("false", "quiz");
|
||||
$false->question = $question->id;
|
||||
$false->fraction = 1 - (int)$form->answer;
|
||||
$false->feedback = $form->feedbackfalse;
|
||||
if (!$false->id = insert_record("quiz_answers", $false)) {
|
||||
error("Could not insert quiz answer \"false\")!");
|
||||
}
|
||||
|
||||
unset($options);
|
||||
$options->question = $question->id;
|
||||
$options->true = $true->id;
|
||||
$options->false = $false->id;
|
||||
if (!insert_record("quiz_truefalse", $options)) {
|
||||
error("Could not insert quiz truefalse options!");
|
||||
}
|
||||
break;
|
||||
case MULTICHOICE:
|
||||
delete_records("quiz_answers", "question", $question->id);
|
||||
delete_records("quiz_multichoice", "question", $question->id);
|
||||
|
||||
$totalfraction = 0;
|
||||
$maxfraction = -1;
|
||||
|
||||
$answers = array();
|
||||
|
||||
// Insert all the new answers
|
||||
foreach ($form->answer as $key => $formanswer) {
|
||||
if ($formanswer) {
|
||||
unset($answer);
|
||||
$answer->answer = $formanswer;
|
||||
$answer->question = $question->id;
|
||||
$answer->fraction = $fraction[$key];
|
||||
$answer->feedback = $feedback[$key];
|
||||
if (!$answer->id = insert_record("quiz_answers", $answer)) {
|
||||
error("Could not insert quiz answer!");
|
||||
}
|
||||
$answers[] = $answer->id;
|
||||
|
||||
if ($fraction[$key] > 0) { // Sanity checks
|
||||
$totalfraction += $fraction[$key];
|
||||
}
|
||||
if ($fraction[$key] > $maxfraction) {
|
||||
$maxfraction = $fraction[$key];
|
||||
}
|
||||
|
||||
unset($options);
|
||||
$options->question = $question->id;
|
||||
$options->answers = implode(",",$answers);
|
||||
$options->usecase = $form->usecase;
|
||||
if (!insert_record("quiz_shortanswer", $options)) {
|
||||
error("Could not insert quiz shortanswer options!");
|
||||
}
|
||||
}
|
||||
|
||||
unset($options);
|
||||
$options->question = $question->id;
|
||||
$options->answers = implode(",",$answers);
|
||||
$options->single = $form->single;
|
||||
if (!insert_record("quiz_multichoice", $options)) {
|
||||
error("Could not insert quiz multichoice options!");
|
||||
}
|
||||
|
||||
/// Perform sanity checks on fractional grades
|
||||
if ($options->single) {
|
||||
|
||||
/// Perform sanity checks on fractional grades
|
||||
if ($maxfraction != 1) {
|
||||
$maxfraction = $maxfraction * 100;
|
||||
notice_yesno(get_string("fractionsnomax", "quiz", $maxfraction), "question.php?id=$question->id", "edit.php");
|
||||
print_footer($course);
|
||||
exit;
|
||||
}
|
||||
} else {
|
||||
$totalfraction = round($totalfraction,2);
|
||||
if ($totalfraction != 1) {
|
||||
$totalfraction = $totalfraction * 100;
|
||||
notice_yesno(get_string("fractionsaddwrong", "quiz", $totalfraction), "question.php?id=$question->id", "edit.php");
|
||||
print_footer($course);
|
||||
exit;
|
||||
break;
|
||||
case TRUEFALSE:
|
||||
delete_records("quiz_answers", "question", $question->id);
|
||||
delete_records("quiz_truefalse", "question", $question->id);
|
||||
|
||||
$true->answer = get_string("true", "quiz");
|
||||
$true->question = $question->id;
|
||||
$true->fraction = $form->answer;
|
||||
$true->feedback = $form->feedbacktrue;
|
||||
if (!$true->id = insert_record("quiz_answers", $true)) {
|
||||
error("Could not insert quiz answer \"true\")!");
|
||||
}
|
||||
}
|
||||
break;
|
||||
case RANDOM:
|
||||
echo "<P>Not supported yet</P>";
|
||||
break;
|
||||
default:
|
||||
error("Non-existent question type!");
|
||||
break;
|
||||
|
||||
$false->answer = get_string("false", "quiz");
|
||||
$false->question = $question->id;
|
||||
$false->fraction = 1 - (int)$form->answer;
|
||||
$false->feedback = $form->feedbackfalse;
|
||||
if (!$false->id = insert_record("quiz_answers", $false)) {
|
||||
error("Could not insert quiz answer \"false\")!");
|
||||
}
|
||||
|
||||
unset($options);
|
||||
$options->question = $question->id;
|
||||
$options->true = $true->id;
|
||||
$options->false = $false->id;
|
||||
if (!insert_record("quiz_truefalse", $options)) {
|
||||
error("Could not insert quiz truefalse options!");
|
||||
}
|
||||
break;
|
||||
case MULTICHOICE:
|
||||
delete_records("quiz_answers", "question", $question->id);
|
||||
delete_records("quiz_multichoice", "question", $question->id);
|
||||
|
||||
$totalfraction = 0;
|
||||
$maxfraction = -1;
|
||||
|
||||
$answers = array();
|
||||
|
||||
// Insert all the new answers
|
||||
foreach ($form->answer as $key => $formanswer) {
|
||||
if ($formanswer) {
|
||||
unset($answer);
|
||||
$answer->answer = $formanswer;
|
||||
$answer->question = $question->id;
|
||||
$answer->fraction = $fraction[$key];
|
||||
$answer->feedback = $feedback[$key];
|
||||
if (!$answer->id = insert_record("quiz_answers", $answer)) {
|
||||
error("Could not insert quiz answer!");
|
||||
}
|
||||
$answers[] = $answer->id;
|
||||
|
||||
if ($fraction[$key] > 0) { // Sanity checks
|
||||
$totalfraction += $fraction[$key];
|
||||
}
|
||||
if ($fraction[$key] > $maxfraction) {
|
||||
$maxfraction = $fraction[$key];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unset($options);
|
||||
$options->question = $question->id;
|
||||
$options->answers = implode(",",$answers);
|
||||
$options->single = $form->single;
|
||||
if (!insert_record("quiz_multichoice", $options)) {
|
||||
error("Could not insert quiz multichoice options!");
|
||||
}
|
||||
|
||||
/// Perform sanity checks on fractional grades
|
||||
if ($options->single) {
|
||||
if ($maxfraction != 1) {
|
||||
$maxfraction = $maxfraction * 100;
|
||||
notice_yesno(get_string("fractionsnomax", "quiz", $maxfraction), "question.php?id=$question->id", "edit.php");
|
||||
print_footer($course);
|
||||
exit;
|
||||
}
|
||||
} else {
|
||||
$totalfraction = round($totalfraction,2);
|
||||
if ($totalfraction != 1) {
|
||||
$totalfraction = $totalfraction * 100;
|
||||
notice_yesno(get_string("fractionsaddwrong", "quiz", $totalfraction), "question.php?id=$question->id", "edit.php");
|
||||
print_footer($course);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case RANDOM:
|
||||
echo "<P>Not supported yet</P>";
|
||||
break;
|
||||
default:
|
||||
error("Non-existent question type!");
|
||||
break;
|
||||
}
|
||||
|
||||
redirect("edit.php");
|
||||
}
|
||||
|
||||
redirect("edit.php");
|
||||
|
||||
}
|
||||
|
||||
$grades = array(1,0.9,0.8,0.75,0.70,0.66666,0.60,0.50,0.40,0.33333,0.30,0.25,0.20,0.10,0.05,0);
|
||||
@ -284,38 +286,88 @@
|
||||
|
||||
// Print the question editing form
|
||||
|
||||
if (empty($question->id)) {
|
||||
$question->id = "";
|
||||
}
|
||||
if (empty($question->name)) {
|
||||
$question->name = "";
|
||||
}
|
||||
if (empty($question->questiontext)) {
|
||||
$question->questiontext = "";
|
||||
}
|
||||
if (empty($question->image)) {
|
||||
$question->image = "";
|
||||
}
|
||||
|
||||
|
||||
switch ($type) {
|
||||
case SHORTANSWER:
|
||||
$options = get_record("quiz_shortanswer", "question", "$question->id");// OK to fail
|
||||
$answersraw = get_records_list("quiz_answers", "id", "$options->answers");// OK to fail
|
||||
print_heading_with_help(get_string("editingshortanswer", "quiz"), "shortanswer", "quiz");
|
||||
if ($answersraw) {
|
||||
if (!empty($question->id)) {
|
||||
$options = get_record("quiz_shortanswer", "question", $question->id);
|
||||
} else {
|
||||
$options->usecase = 0;
|
||||
}
|
||||
if (!empty($options->answers)) {
|
||||
$answersraw = get_records_list("quiz_answers", "id", $options->answers);
|
||||
}
|
||||
for ($i=0; $i<6; $i++) {
|
||||
$answers[] = ""; // Make answer slots, default as blank
|
||||
}
|
||||
if (!empty($answersraw)) {
|
||||
$i=0;
|
||||
foreach ($answersraw as $answer) {
|
||||
$answers[] = $answer; // to renumber index 0,1,2...
|
||||
$answers[$i] = $answer; // insert answers into slots
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
print_heading_with_help(get_string("editingshortanswer", "quiz"), "shortanswer", "quiz");
|
||||
require("shortanswer.html");
|
||||
break;
|
||||
|
||||
case TRUEFALSE:
|
||||
$options = get_record("quiz_truefalse", "question", "$question->id"); // OK to fail
|
||||
$true = get_record("quiz_answers", "id", "$options->true"); // OK to fail
|
||||
$false = get_record("quiz_answers", "id", "$options->false"); // OK to fail
|
||||
if (!empty($question->id)) {
|
||||
$options = get_record("quiz_truefalse", "question", "$question->id");
|
||||
}
|
||||
if (!empty($options->true)) {
|
||||
$true = get_record("quiz_answers", "id", "$options->true");
|
||||
} else {
|
||||
$true->fraction = 1;
|
||||
$true->feedback = "";
|
||||
}
|
||||
if (!empty($options->false)) {
|
||||
$false = get_record("quiz_answers", "id", "$options->false");
|
||||
} else {
|
||||
$false->fraction = 0;
|
||||
$false->feedback = "";
|
||||
}
|
||||
|
||||
if ($true->fraction > $false->fraction) {
|
||||
$question->answer = 1;
|
||||
} else {
|
||||
$question->answer = 0;
|
||||
}
|
||||
|
||||
print_heading_with_help(get_string("editingtruefalse", "quiz"), "truefalse", "quiz");
|
||||
require("truefalse.html");
|
||||
break;
|
||||
|
||||
case MULTICHOICE:
|
||||
$options = get_record("quiz_multichoice", "question", "$question->id");// OK to fail
|
||||
$answersraw = get_records_list("quiz_answers", "id", "$options->answers");// OK to fail
|
||||
if ($answersraw) {
|
||||
if (!empty($question->id)) {
|
||||
$options = get_record("quiz_multichoice", "question", $question->id);
|
||||
} else {
|
||||
$options->single = "";
|
||||
}
|
||||
if (!empty($options->answers)) {
|
||||
$answersraw = get_records_list("quiz_answers", "id", $options->answers);
|
||||
}
|
||||
for ($i=0; $i<6; $i++) {
|
||||
$answers[] = ""; // Make answer slots, default as blank
|
||||
}
|
||||
if (!empty($answersraw)) {
|
||||
$i=0;
|
||||
foreach ($answersraw as $answer) {
|
||||
$answers[] = $answer; // to renumber index 0,1,2...
|
||||
$answers[$i] = $answer; // insert answers into slots
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
print_heading_with_help(get_string("editingmultichoice", "quiz"), "multichoice", "quiz");
|
||||
@ -333,4 +385,18 @@
|
||||
}
|
||||
|
||||
print_footer($course);
|
||||
|
||||
|
||||
function formcheck($question) {
|
||||
$err = array();
|
||||
|
||||
if (empty($question->name)) {
|
||||
$err["name"] = get_string("missingname", "quiz");
|
||||
}
|
||||
if (empty($question->questiontext)) {
|
||||
$err["questiontext"] = get_string("missingquestiontext", "quiz");
|
||||
}
|
||||
return $err;
|
||||
}
|
||||
|
||||
?>
|
||||
|
@ -11,11 +11,17 @@
|
||||
<TD align=right><P><B><? print_string("questionname", "quiz") ?>:</B></P></TD>
|
||||
<TD>
|
||||
<INPUT type="text" name="name" size=50 value="<? p($question->name) ?>">
|
||||
<? if (isset($err["name"])) formerr($err["name"]); ?>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR valign=top>
|
||||
<TD align=right><P><B><? print_string("question", "quiz") ?>:</B></P></TD>
|
||||
<TD>
|
||||
<? if (isset($err["questiontext"])) {
|
||||
formerr($err["questiontext"]);
|
||||
echo "<BR \>";
|
||||
}
|
||||
?>
|
||||
<textarea name="questiontext" rows=6 cols=50 wrap="virtual"><? p($question->questiontext)?></textarea>
|
||||
<? helpbutton("text", get_string("helptext")); ?>
|
||||
</TD>
|
||||
|
@ -11,11 +11,17 @@
|
||||
<TD align=right><P><B><? print_string("questionname", "quiz") ?>:</B></P></TD>
|
||||
<TD>
|
||||
<INPUT type="text" name="name" size=50 value="<? p($question->name) ?>">
|
||||
<? if (isset($err["name"])) formerr($err["name"]); ?>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR valign=top>
|
||||
<TD align=right><P><B><? print_string("question", "quiz") ?>:</B></P></TD>
|
||||
<TD>
|
||||
<? if (isset($err["questiontext"])) {
|
||||
formerr($err["questiontext"]);
|
||||
echo "<BR \>";
|
||||
}
|
||||
?>
|
||||
<textarea name="questiontext" rows=6 cols=50 wrap="virtual"><? p($question->questiontext)?></textarea>
|
||||
<? helpbutton("text", get_string("helptext")); ?>
|
||||
</TD>
|
||||
|
Loading…
x
Reference in New Issue
Block a user