diff --git a/mod/quiz/attempt.php b/mod/quiz/attempt.php index 9b6c2a5d4f4..fc0953329ce 100644 --- a/mod/quiz/attempt.php +++ b/mod/quiz/attempt.php @@ -115,7 +115,9 @@ } if (! $attempt = quiz_save_attempt($quiz, $questions, $result, $numattempts)) { - error("Sorry! Could not save your attempt!"); + notice(get_string("alreadysubmitted", "quiz"), "view.php?id=$cm->id"); + print_footer($course); + exit; } if (! quiz_save_best_grade($quiz, $USER)) { diff --git a/mod/quiz/lib.php b/mod/quiz/lib.php index b6f65b058ff..aec475b2cee 100644 --- a/mod/quiz/lib.php +++ b/mod/quiz/lib.php @@ -16,9 +16,11 @@ $QUIZ_GRADE_METHOD = array ( GRADEHIGHEST => get_string("gradehighest", "quiz"), define("SHORTANSWER", "1"); define("TRUEFALSE", "2"); define("MULTICHOICE", "3"); +define("RANDOM", "4"); $QUIZ_QUESTION_TYPE = array ( MULTICHOICE => get_string("multichoice", "quiz"), TRUEFALSE => get_string("truefalse", "quiz"), - SHORTANSWER => get_string("shortanswer", "quiz") ); + SHORTANSWER => get_string("shortanswer", "quiz"), + RANDOM => get_string("random", "quiz") ); @@ -213,12 +215,19 @@ function quiz_print_comment($text) { echo "cellheading2\">".text_to_html($text, true, false).""; } +function quiz_print_correctanswer($text) { + global $THEME; + + echo "
$text
"; +} + function quiz_print_question($number, $questionid, $grade, $courseid, - $feedback=NULL, $response=NULL, $actualgrade=NULL) { + $feedback=NULL, $response=NULL, $actualgrade=NULL, $correct=NULL) { /// Prints a quiz question, any format global $THEME; $comment = $THEME->cellheading2; + $green = "#AAFFAA"; if (!$question = get_record("quiz_questions", "id", $questionid)) { notify("Error: Question not found!"); @@ -253,6 +262,10 @@ function quiz_print_question($number, $questionid, $grade, $courseid, if ($feedback) { quiz_print_comment("$feedback[0]
"); } + if ($correct) { + $correctanswers = implode(",", $correct); + quiz_print_correctanswer($correctanswers); + } break; case TRUEFALSE: @@ -283,10 +296,20 @@ function quiz_print_question($number, $questionid, $grade, $courseid, $falsechecked = "CHECKED"; $feedbackid = $false->id; } - echo "$stranswer: "; + if ($correct) { + if ($correct[$true->id]) { + $truecorrect = "CLASS=highlight"; + } + if ($correct[$false->id]) { + $falsecorrect = "CLASS=highlight"; + } + } + echo "
| $stranswer: "; + echo " | "; echo "id\" VALUE=\"$true->id\">$true->answer"; - echo " "; + echo " | "; echo "id\" VALUE=\"$false->id\">$false->answer"; + echo " |
$feedback[$feedbackid]
"); } @@ -325,7 +348,11 @@ function quiz_print_question($number, $questionid, $grade, $courseid, echo "id"."a$answer->id VALUE=\"$answer->id\">"; } echo ""; - echo "Random questions not supported yet
"; + break; + + default: notify("Error: Unknown question type!"); } @@ -365,14 +397,22 @@ function quiz_print_quiz_questions($quiz, $results=NULL) { echo "id\">"; foreach ($questions as $key => $questionid) { + $feedback = NULL; + $response = NULL; + $actualgrades = NULL; + $correct = NULL; if ($results) { - $feedback = $results->feedback[$questionid]; - } else { - $feedback = NULL; + $feedback = $results->feedback[$questionid]; + $response = $results->response[$questionid]; + $actualgrades = $results->grades[$questionid]; + if ($quiz->correctanswers) { + $correct = $results->correct[$questionid]; + } } + print_simple_box_start("CENTER", "90%"); quiz_print_question($key+1, $questionid, $grades[$questionid]->grade, $quiz->course, - $results->feedback[$questionid], $results->response[$questionid], $results->grades[$questionid]); + $feedback, $response, $actualgrades, $correct); print_simple_box_end(); echo "Not supported yet
"; + break; default: error("Non-existent question type!"); break; @@ -237,6 +240,10 @@ print_heading(get_string("editingmultichoice", "quiz")); require("multichoice.html"); break; + case RANDOM: + print_heading("Not supported yet"); + print_continue("edit.php"); + break; default: error("Invalid question type");