diff --git a/lang/en/quiz.php b/lang/en/quiz.php
index bf02cfbe253..5566ea07ab5 100644
--- a/lang/en/quiz.php
+++ b/lang/en/quiz.php
@@ -41,9 +41,11 @@ $string['category'] = 'Category';
$string['categoryinfo'] = 'Category info';
$string['categorymove'] = 'The category \'$a->name\' contains $a->count questions. Please choose another category to move them to.';
$string['categorymoveto'] = 'Move them to this category';
+$string['checkanswer'] = 'Check';
$string['choice'] = 'Choice';
$string['choices'] = 'Available choices';
$string['choosedatasetproperties'] = 'Choose dataset properties';
+$string['close'] = 'Close preview';
$string['confirmstartattempt'] = 'The Quiz has a time limit. Are you sure that you wish to start?';
$string['correctanswer'] = 'Correct answer';
$string['correctanswerformula'] = 'Correct Answer Formula';
@@ -175,6 +177,8 @@ $string['overdue'] = 'Overdue';
$string['paragraphquestion'] = 'Paragraph Question not supported at line $a. The question will be ignored';
$string['passworderror'] = 'The password entered was incorrect';
$string['percentcorrect'] = 'Percent Correct';
+$string['preview'] = 'Preview';
+$string['previewquestion'] = 'Preview question';
$string['publish'] = 'Publish';
$string['publishedit'] = 'You must have permission in the publishing course to add or edit questions in this category';
$string['qti'] = 'IMS QTI format';
diff --git a/mod/quiz/lib.php b/mod/quiz/lib.php
index 8a276c4a10f..ec43af7fe9a 100644
--- a/mod/quiz/lib.php
+++ b/mod/quiz/lib.php
@@ -1209,6 +1209,7 @@ function quiz_print_question_list($questionlist, $grades) {
$strmovedown = get_string("movedown");
$strsavegrades = get_string("savegrades", "quiz");
$strtype = get_string("type", "quiz");
+ $strpreview = get_string("preview", "quiz");
$count = 0;
$sumgrade = 0;
@@ -1251,6 +1252,9 @@ function quiz_print_question_list($questionlist, $grades) {
echo "
";
echo " ";
+ echo " ";
+
if ($canedit) {
echo "\n";
@@ -1292,6 +1296,7 @@ function quiz_print_cat_question_list($categoryid, $quizselected=true) {
$straddselectedtoquiz = get_string("addselectedtoquiz", "quiz");
$strtype = get_string("type", "quiz");
$strcreatemultiple = get_string("createmultiple", "quiz");
+ $strpreview = get_string("preview","quiz");
if (!$categoryid) {
echo " ";
@@ -1395,6 +1400,8 @@ function quiz_print_cat_question_list($categoryid, $quizselected=true) {
echo " | \n";
echo "id&delete=$question->id\">\n ";
+ echo "id','$strpreview','scrollbars=yes,resizable=yes,width=700,height=480', false)\"> ";
echo "id\">";
echo " | \n";// deleted jm
diff --git a/mod/quiz/preview.php b/mod/quiz/preview.php
new file mode 100644
index 00000000000..63cb916e32b
--- /dev/null
+++ b/mod/quiz/preview.php
@@ -0,0 +1,149 @@
+category = $category;
+ }
+ if (! $category = get_record("quiz_categories", "id", $question->category)) {
+ error("This question doesn't belong to a valid category!");
+ }
+ if (! $course = get_record("course", "id", $category->course)) {
+ error("This question category doesn't belong to a valid course!");
+ }
+
+ $qtype = $question->qtype;
+
+
+ } 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->qtype = $qtype;
+
+ } else {
+ error("Must specify question id or category");
+ }
+
+ if (empty($qtype)) {
+ error("No question type was specified!");
+ } else if (!isset($QUIZ_QTYPES[$qtype])) {
+ error("Could not find question type: '$qtype'");
+ }
+
+ require_login($course->id);
+
+
+ if (!isteacheredit($course->id)) {
+ error("You can't modify these questions!");
+ }
+
+
+ $strquizzes = get_string('modulenameplural', 'quiz');
+ $streditingquiz = get_string(isset($SESSION->modform->instance) ? "editingquiz" : "editquestions", "quiz");
+ $streditingquestion = get_string("editingquestion", "quiz");
+
+ print_header();
+ print_heading(get_string("previewquestion","quiz"));
+
+ echo "";
+
+ if (empty($question->id)) {
+ $question->id = "";
+ }
+ if (empty($question->name)) {
+ $question->name = "";
+ }
+ if (empty($question->questiontext)) {
+ $question->questiontext = "";
+ }
+ if (empty($question->image)) {
+ $question->image = "";
+ }
+
+ if ($results && isset($results->details[$question->id])) {
+ $details = $results->details[$question->id];
+ } else {
+ $details = false;
+ }
+
+ if($rawanswers = data_submitted()) {
+ $rawanswers = (array)$rawanswers;
+
+ $answers = array();
+ $feedbacks = array();
+ $qids = array();
+
+ foreach ($rawanswers as $key => $value) { // Parse input for question->response
+ $postedId = quiz_extract_posted_id($key);
+ if ($id == $postedId) {
+ $question->response[$key] = trim($value);
+ $questionType = $QUIZ_QTYPES[$question->qtype]->name();
+ $rezult = get_exp_answers($id); //answers from the database
+
+ if($rezult) {
+ foreach ($rezult as $qid => $answer) {
+ if($qid == $value || $answer->answer == $value) {
+ $feedbacks[$qid] = " - ".format_text($answer->feedback, true, false)."";
+ if($answer->fraction > 0)
+ $answers[$qid] = "" . $answer->answer . "";
+ else
+ $answers[$qid] = $answer->answer;
+ } else {
+ if(!isset($answers[$qid])) {
+ if($answer->fraction > 0)
+ $answers[$qid] = "" . $answer->answer . "";
+ else
+ $answers[$qid] = $answer->answer;
+ $feedbacks[$qid] = '';
+ }
+ }
+ $qids[] = $qid;
+ }
+ }//end if rezult
+ }//end if pId==id
+ }//end for each rowanswers
+
+ print_simple_box_start("center", "90%");
+ $QUIZ_QTYPES[$question->qtype]->print_question
+ (1, 0, $question, true, $resultdetails);
+
+ $qids = array_unique($qids); //erease duplicates
+ for($i = 0; $i < count($qids); $i++) {
+ global $THEME;
+ echo "" . $answers[$qids[$i]] . format_text($feedbacks[$qids[$i]], true, false)."
";
+ }
+ print_simple_box_end();
+
+ } else {//show question list
+ echo "";
+ }
+
+?>