$numattempts = 1;
}
- if ($numattempts > $quiz->attempts) {
- error("Sorry, you've had $quiz->attempts attempts already.", "view.php?id=$cm->id");
+ if ($quiz->attempts) {
+ if ($numattempts > $quiz->attempts) {
+ error("Sorry, you've had $quiz->attempts attempts already.", "view.php?id=$cm->id");
+ }
}
if ($course->format == "weeks" and $quiz->days) {
error("Sorry! Could not calculate your best grade!");
}
- print_heading(get_string("grade", "quiz").": $result->grade/$quiz->grade ($result->sumgrades / $quiz->sumgrades = $percent %)");
+ print_heading(get_string("grade", "quiz").": $result->grade/$quiz->grade ($result->sumgrades / $quiz->sumgrades = $result->percentage %)");
print_continue("view.php?id=$cm->id");
error("Sorry, this quiz is not available", "view.php?id=$cm->id");
}
- print_heading("Attempt $numattempts out of $quiz->attempts");
+ print_heading(get_string("attempt", "quiz", $numattempts));
print_simple_box($quiz->intro, "CENTER");
echo "<BR>";
- quiz_print_quiz_questions($quiz);
+ if (! quiz_print_quiz_questions($quiz)) {
+ print_continue("view.php?id=$cm->id");
+ }
/// Finish the page
error(get_string("filloutallfields"), $HTTP_REFERER);
}
-
$SESSION->modform = $modform; // Save the form in the current session
save_session("SESSION");
// Now, check for commands on this page and modify variables as necessary
- if ($up) { //------------------------------------------------------------
+ if ($up) { /// Move the given question up a slot
$questions = explode(",", $modform->questions);
if ($questions[0] <> $up) {
foreach ($questions as $key => $question) {
}
}
- if ($down) { //----------------------------------------------------------
+ if ($down) { /// Move the given question down a slot
$questions = explode(",", $modform->questions);
if ($questions[count($questions)-1] <> $down) {
foreach ($questions as $key => $question) {
}
}
- if ($add) { //-----------------------------------------------------------
+ if ($add) { /// Add a question to the current quiz
$rawquestions = $HTTP_POST_VARS;
- $questions = explode(",", $modform->questions);
+ if ($modform->questions) {
+ $questions = explode(",", $modform->questions);
+ }
foreach ($rawquestions as $key => $value) { // Parse input for question ids
if (substr($key, 0, 1) == "q") {
$key = substr($key,1);
- foreach ($questions as $question) {
- if ($question == $key) {
- continue 2;
+ if ($questions) {
+ foreach ($questions as $question) {
+ if ($question == $key) {
+ continue 2;
+ }
}
}
$questions[] = $key;
- $modform->grades[$key] = 1;
+ $modform->grades[$key] = 1; // default score
}
}
$modform->questions = implode(",", $questions);
}
- if ($delete) { //--------------------------------------------------------
+ if ($delete) { /// Delete a question from the list
$questions = explode(",", $modform->questions);
foreach ($questions as $key => $question) {
if ($question == $delete) {
$modform->questions = implode(",", $questions);
}
- if ($grade) { //---------------------------------------------------------
+ if ($grade) { /// The grades have been updated, so update our internal list
$rawgrades = $HTTP_POST_VARS;
foreach ($rawgrades as $key => $value) { // Parse input for question -> grades
if (substr($key, 0, 1) == "q") {
}
}
+ $modform->sumgrades = 0;
+ if ($modform->grades) {
+ foreach ($modform->grades as $grade) {
+ $modform->sumgrades += $grade;
+ }
+ }
+
$SESSION->modform = $modform;
save_session("SESSION");
// Print basic page layout.
echo "<TABLE BORDER=0 WIDTH=\"100%\" CELLPADDING=2 CELLSPACING=0>";
- echo "<TR><TD WIDTH=50%>";
+ echo "<TR><TD WIDTH=50% VALIGN=TOP>";
print_simple_box_start("CENTER", "100%", $THEME->body);
print_heading($modform->name);
quiz_print_question_list($modform->questions, $modform->grades);
return false; // some error occurred
}
- // The grades for each question in this quiz are stored in an array
+ // The grades for every question in this quiz are stored in an array
if ($quiz->grades) {
foreach ($quiz->grades as $question => $grade) {
$questiongrade->quiz = $quiz->id;
}
- // The grades for each question in this quiz are stored in an array
+ // The grades for every question in this quiz are stored in an array
// Insert or update records as appropriate
$existing = get_records("quiz_question_grades", "quiz", $quiz->id, "", "question,grade,id");
$result = true;
- # Delete any dependent records here #
+ if ($attempts = get_record("quiz_attempts", "quiz", "$quiz->id")) {
+ foreach ($attempts as $attempt) {
+ if (! delete_records("quiz_responses", "attempt", "$attempt->id")) {
+ $result = false;
+ }
+ }
+ }
+
+ if (! delete_records("quiz_attempts", "quiz", "$quiz->id")) {
+ $result = false;
+ }
+
+ if (! delete_records("quiz_grades", "quiz", "$quiz->id")) {
+ $result = false;
+ }
+
+ if (! delete_records("quiz_question_grades", "quiz", "$quiz->id")) {
+ $result = false;
+ }
if (! delete_records("quiz", "id", "$quiz->id")) {
$result = false;
// Prints a whole quiz on one page.
if (!$quiz->questions) {
- error("No questions have been defined!", "view.php?id=$cm->id");
+ notify("No questions have been defined!", "view.php?id=$cm->id");
+ return false;
}
$questions = explode(",", $quiz->questions);
if (!$grades = get_records_list("quiz_question_grades", "question", $quiz->questions, "", "question,grade")) {
- error("No grades were found for these questions!");
+ notify("No grades were found for these questions!");
+ return false;
}
echo "<FORM METHOD=POST ACTION=attempt.php>";
}
echo "<CENTER><INPUT TYPE=submit VALUE=\"".get_string("savemyanswers", "quiz")."\"></CENTER>";
echo "</FORM>";
+
+ return true;
}
function quiz_get_default_category($courseid) {
}
// Otherwise, we need to make one
- $category->name = get_string("miscellaneous", "quiz");
- $category->info = get_string("miscellaneous", "quiz");
+ $category->name = get_string("default", "quiz");
+ $category->info = get_string("defaultinfo", "quiz");
$category->course = $courseid;
$category->publish = 0;
}
$strcategory = get_string("category", "quiz");
$strshow = get_string("show", "quiz");
- $strrename = get_string("rename", "quiz");
+ $stredit = get_string("edit");
$strdelete = get_string("delete");
$strnew = get_string("new");
echo "<B>$strcategory:</B> ";
choose_from_menu($categories, "cat", "$current");
echo "<INPUT TYPE=submit NAME=catshow VALUE=\"$strshow\">";
- echo "<INPUT TYPE=submit NAME=catrename VALUE=\"$strrename\">";
- echo "<INPUT TYPE=submit NAME=catdelete VALUE=\"$strdelete\">";
+ echo "<INPUT TYPE=submit NAME=catedit VALUE=\"$stredit\">";
+ echo "<INPUT TYPE=submit NAME=catdelete VALUE=\"$strdelete\"> ";
echo "<INPUT TYPE=submit NAME=catnew VALUE=\"$strnew\">";
echo "</FORM>";
}
$strmovedown = get_string("movedown");
$strsavegrades = get_string("savegrades", "quiz");
- for ($i=100; $i>=0; $i--) {
+ for ($i=10; $i>=0; $i--) {
$gradesmenu[$i] = $i;
}
$count = 0;
$total = count($order);
echo "<FORM METHOD=post ACTION=edit.php>";
echo "<TABLE BORDER=0 CELLPADDING=5 CELLSPACING=2 WIDTH=\"100%\">";
- echo "<TR><TH COLSPAN=3>$strorder</TH><TH align=left>$strquestionname</TH><TH>$strgrade</TH><TH>$stredit</TH></TR>";
+ echo "<TR><TH WIDTH=10 COLSPAN=3>$strorder</TH><TH align=left WIDTH=\"100%\">$strquestionname</TH><TH WIDTH=10>$strgrade</TH><TH WIDTH=10>$stredit</TH></TR>";
foreach ($order as $qnum) {
$count++;
echo "<TR BGCOLOR=\"$THEME->cellcontent\">";
echo "</TD><TD></TD></TR>";
echo "</TABLE>";
echo "</FORM>";
+
+ return $sumgrade;
}
global $THEME, $QUIZ_QUESTION_TYPE;
+ $strcategory = get_string("category", "quiz");
$strquestion = get_string("question", "quiz");
$strnoquestions = get_string("noquestions", "quiz");
$strselect = get_string("select", "quiz");
notify("Category not found!");
return;
}
- echo "<P>$category->info</P>";
+ echo "<P><B>$strcategory:</B> $category->name</P>\n";
+ echo text_to_html($category->info);
- echo "<FORM METHOD=POST ACTION=question.php>";
+ echo "<FORM METHOD=GET ACTION=question.php>";
echo "<B>$strquestion:</B> ";
choose_from_menu($QUIZ_QUESTION_TYPE, "type", "", "");
echo "<INPUT TYPE=hidden NAME=category VALUE=\"$category->id\">";
return;
}
+ $canedit = isteacher($category->course);
+
echo "<FORM METHOD=post ACTION=edit.php>";
echo "<TABLE BORDER=0 CELLPADDING=5 CELLSPACING=2 WIDTH=\"100%\">";
- echo "<TR><TH width=10>$strselect</TH><TH width=* align=left>$strquestionname</TH><TH width=10>$stredit</TH></TR>";
+ echo "<TR><TH width=10>$strselect</TH><TH width=* align=left>$strquestionname</TH>";
+ if ($canedit) {
+ echo "<TH width=10>$stredit</TH>";
+ }
+ echo "</TR>";
foreach ($questions as $question) {
echo "<TR BGCOLOR=\"$THEME->cellcontent\">";
echo "<TD ALIGN=CENTER>";
echo "<INPUT TYPE=CHECKBOX NAME=q$question->id VALUE=\"1\">";
echo "</TD>";
echo "<TD>".$question->name."</TD>";
- echo "<TD>";
- echo "<A TITLE=\"$strdelete\" HREF=\"question.php?delete=$question->id\"><IMG
- SRC=\"../../pix/t/delete.gif\" BORDER=0></A> ";
- echo "<A TITLE=\"$stredit\" HREF=\"question.php?id=$question->id\"><IMG
- SRC=\"../../pix/t/edit.gif\" BORDER=0></A>";
- echo "</TD></TR>";
+ if ($canedit) {
+ echo "<TD>";
+ echo "<A TITLE=\"$strdelete\" HREF=\"question.php?delete=$question->id\"><IMG
+ SRC=\"../../pix/t/delete.gif\" BORDER=0></A> ";
+ echo "<A TITLE=\"$stredit\" HREF=\"question.php?id=$question->id\"><IMG
+ SRC=\"../../pix/t/edit.gif\" BORDER=0></A>";
+ echo "</TD></TR>";
+ }
+ echo "</TR>";
}
echo "<TR><TD COLSPAN=3>";
echo "<INPUT TYPE=hidden NAME=add VALUE=\"1\">";
if ($grade < 0.0) { // No negative grades
$grade = 0.0;
}
+
$result->grades[$question->id] = $grade;
$result->sumgrades += $grade;
$result->feedback[$question->id] = $feedback;
<? include_once("$CFG->dirroot/mod/quiz/lib.php") ?>
-<H1 ALIGN=CENTER><FONT COLOR=RED>This module is not ready for use</FONT></H1>
-
<FORM name="form" method="post" action="<?=$CFG->wwwroot?>/mod/quiz/edit.php">
<CENTER>
<TABLE cellpadding=5>
<TD align=right><P><B><? print_string("maximumgrade") ?>:</B></P></TD>
<TD>
<?
- for ($i=100; $i>=0; $i--) {
+ for ($i=100; $i>=1; $i--) {
$grades[$i] = $i;
}
choose_from_menu($grades, "grade", "$form->grade", "");
--- /dev/null
+<FORM name="theform" method="post" action="question.php">\r
+<CENTER>\r
+<TABLE cellpadding=5>\r
+<TR valign=top>\r
+ <TD align=right><P><B><? print_string("questionname", "quiz") ?>:</B></P></TD>\r
+ <TD>\r
+ <INPUT type="text" name="name" size=40 value="<? p($question->name) ?>">\r
+ </TD>\r
+</TR>\r
+<TR valign=top>\r
+ <TD align=right><P><B><? print_string("question", "quiz") ?>:</B></P></TD>\r
+ <TD>\r
+ <textarea name="intro" rows=5 cols=50 wrap="virtual"><? p($question->question) ?></textarea>\r
+ <? helpbutton("text", get_string("helptext")); ?>\r
+ </TD>\r
+</TR>\r
+<TR valign=top>\r
+ <TD align=right><P><B><? print_string("category", "quiz") ?>:</B></P></TD>\r
+ <TD>\r
+ <?\r
+ choose_from_menu($categories, "category", "$question->category", "");\r
+ ?>\r
+ </TD>\r
+</TR>\r
+<TR valign=top>\r
+ <TD align=right><P><B><? print_string("attemptsallowed", "quiz") ?>:</B></P></TD>\r
+ <TD>\r
+ <?\r
+ $options[0] = get_string("answersingleno", "quiz");\r
+ $options[1] = get_string("answersingleyes", "quiz");\r
+ choose_from_menu($options, "single", "$options->single", "");\r
+ ?>\r
+ </TD>\r
+</TR>\r
+</TABLE>\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=category value="<? p($question->category) ?>">\r
+<INPUT type="submit" value="<? print_string("savechanges") ?>">\r
+\r
+\r
+\r
+answers go here ...\r
+\r
+</CENTER>\r
+</FORM>\r
<?PHP // $Id$
+ /// For creating and editing quiz questions.
+ require("../../config.php");
+ require("lib.php");
+
+ optional_variable($id);
+
+ optional_variable($type);
+ optional_variable($category);
+
+ if ($id) {
+ if (! $question = get_record("quiz_questions", "id", $id)) {
+ error("This question doesn't exist");
+ }
+
+ if (! $category = get_record("quiz_categories", "id", $question->category)) {
+ error("This question doesn't belong to a vald category!");
+ }
+ if (! $course = get_record("course", "id", $category->course)) {
+ error("This question category doesn't belong to a valid course!");
+ }
+
+ $type = $question->type;
+
+ switch ($type) {
+ case SHORTANSWER:
+ print_heading(get_string("editingshortanswer", "quiz"));
+ require("shortanswer.html");
+ break;
+ case TRUEFALSE:
+ print_heading(get_string("editingtruefalse", "quiz"));
+ require("truefalse.html");
+ break;
+ case MULTICHOICE:
+ print_heading(get_string("editingmultichoice", "quiz"));
+ require("multichoice.html");
+ break;
+ }
+
+ } else if ($category) {
+ if (! $category = get_record("quiz_categories", "id", $category)) {
+ error("This wasn't a valid category!");
+ }
+ if (! $course = get_record("course", "id", $category->course)) {
+ error("This category doesn't belong to a valid course!");
+ }
+
+ $question->category = $category->id;
+ $question->type = $type;
+
+ } else {
+ error("Must specify question id or category");
+ }
+
+ require_login($course->id);
+
+ if (!isteacher($course->id)) {
+ error("You can't modify this course!");
+ }
+
+ $streditingquiz = get_string("editingquiz", "quiz");
+ $streditingquestion = get_string("editingquestion", "quiz");
+
+ 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");
+
+ if (match_referer() and isset($HTTP_POST_VARS)) { // question submitted
+
+ }
+
+ $grades = array(100,90,80,75,70,66.66,60,50,40,33.33,30,25,20,10,5);
+ foreach ($grades as $grade) {
+ $gradeoptions[$grade] = $grade;
+ $gradeoptions[-$grade] = -$grade;
+ }
+ arsort($gradeoptions, SORT_NUMERIC);
+
+ if (!$categories = get_records_sql_menu("SELECT id,name FROM quiz_categories
+ WHERE course='$course->id' OR publish = '1'
+ ORDER by name ASC")) {
+ error("No categories!");
+ }
+
+ // Print the question editing form
+
+ switch ($type) {
+ case SHORTANSWER:
+ $options = get_record("quiz_shortanswer", "question", "$question->id");// OK to fail
+ $answer = get_record("quiz_answers", "id", "$options->answer"); // OK to fail
+ print_heading(get_string("editingshortanswer", "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
+ print_heading(get_string("editingtruefalse", "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) {
+ foreach ($answersraw as $answer) {
+ $answers[] = $answer; // to renumber index 0,1,2...
+ }
+ }
+ print_heading(get_string("editingmultichoice", "quiz"));
+ require("multichoice.html");
+ break;
+
+ default:
+ error("Invalid question type");
+ break;
+ }
+
+ print_footer($course);
?>
$mygrade = quiz_get_best_grade($quiz->id, $USER->id);
- if ($numattempts < $quiz->attempts) {
+ if ($numattempts < $quiz->attempts or !$quiz->attempts) {
if ($available) {
- $options["id"] = $quiz->id;
+ $options["id"] = $cm->id;
if ($numattempts) {
print_heading("Your best grade so far is $mygrade / $quiz->grade.");
}
+ echo "<BR>";
echo "<DIV align=CENTER>";
print_single_button("attempt.php", $options, $label="Attempt quiz now");
echo "</P>";