]> git.mjollnir.org Git - moodle.git/commitdiff
Fix for MDL-10823 Access to question edit page denied from quiz preview screen.
authorjamiesensei <jamiesensei>
Tue, 14 Aug 2007 04:22:05 +0000 (04:22 +0000)
committerjamiesensei <jamiesensei>
Tue, 14 Aug 2007 04:22:05 +0000 (04:22 +0000)
mod/quiz/locallib.php
question/editlib.php
question/preview.php
question/type/description/questiontype.php
question/type/questiontype.php

index eab2d7441dddffbf8e5edd608b4148968f879e60..daed4ac411b5ec7775baf55e9151b893da376a78 100644 (file)
@@ -661,12 +661,13 @@ function quiz_upgrade_states($attempt) {
  * @return the HTML for a preview question icon.
  */
 function quiz_question_preview_button($quiz, $question) {
-    global $CFG;
+    global $CFG, $COURSE;
     if (!question_has_capability_on($question, 'use', $question->category)){
         return '';
     }
     $strpreview = get_string('previewquestion', 'quiz');
-    return link_to_popup_window('/question/preview.php?id=' . $question->id . '&amp;quizid=' . $quiz->id, 'questionpreview',
+    $quizorcourseid = $quiz->id?('&amp;quizid=' . $quiz->id):('&amp;courseid=' .$COURSE->id);
+    return link_to_popup_window('/question/preview.php?id=' . $question->id . $quizorcourseid, 'questionpreview',
             "<img src=\"$CFG->pixpath/t/preview.gif\" class=\"iconsmall\" alt=\"$strpreview\" />",
             0, 0, $strpreview, QUESTION_PREVIEW_POPUP_OPTIONS, true);
 }
index 947e1e8cd92ca812de03aa496ae3cfd7a822b83b..945a8a6f58e4848740d1b0e8376f9898d12c6ac4 100644 (file)
@@ -336,7 +336,8 @@ function question_list($contexts, $pageurl, $categoryandcontext, $cm = null,
 
         // preview
         if ($canuseq) {
-            link_to_popup_window('/question/preview.php?id=' . $question->id . '&amp;quizid=' . $quizid, 'questionpreview',
+            $quizorcourseid = $quizid?('&amp;quizid=' . $quizid):('&amp;courseid=' .$COURSE->id);
+            link_to_popup_window('/question/preview.php?id=' . $question->id . $quizorcourseid, 'questionpreview',
                     "<img src=\"$CFG->pixpath/t/preview.gif\" class=\"iconsmall\" alt=\"$strpreview\" />",
                     0, 0, $strpreview, QUESTION_PREVIEW_POPUP_OPTIONS);
         }
index 8922ac69d6a7e0d16872f6585a62bb698beadd82..e992c204ecb0a115a060a7562277fa2fc770ea00 100644 (file)
     $id = required_param('id', PARAM_INT);        // question id
     // if no quiz id is specified then a dummy quiz with default options is used
     $quizid = optional_param('quizid', 0, PARAM_INT);
+    // if no quiz id is specified then tell us the course
+    if (empty($quizid)) {
+        $courseid = required_param('courseid', PARAM_INT);
+    }
+
     // Test if we are continuing an attempt at a question
     $continue = optional_param('continue', 0, PARAM_BOOL);
     // Check for any of the submit buttons
@@ -48,6 +53,8 @@
         $url = $CFG->wwwroot . '/question/preview.php?id=' . $id;
         if ($quizid) {
             $url .= '&amp;quizid=' . $quizid;
+        } else {
+            $url .= '&amp;courseid=' . $courseid;
         }
         $url .= '&amp;continue=1';
         redirect($url);
@@ -60,7 +67,8 @@
         $quiz = new cmoptions;
         $quiz->id = 0;
         $quiz->review = $CFG->quiz_review;
-        require_login_in_context($questions[$id]->contextid);
+        require_login($courseid, false);
+        $quiz->course = $courseid;
     } else if (!$quiz = get_record('quiz', 'id', $quizid)) {
         error("Quiz id $quizid does not exist");
     } else {
     echo '<div class="controls">';
     echo "<input type=\"hidden\" name=\"id\" value=\"$id\" />\n";
     echo "<input type=\"hidden\" name=\"quizid\" value=\"$quizid\" />\n";
+    echo "<input type=\"hidden\" name=\"courseid\" value=\"$courseid\" />\n";
     echo "<input type=\"hidden\" name=\"continue\" value=\"1\" />\n";
 
     // Print the mark and finish attempt buttons
index 1ba123698f684c60af9dc700f8384b85256ce811..f8042ecba324a63c27d69fce448c17999ddbc267 100644 (file)
@@ -44,12 +44,21 @@ class description_qtype extends default_questiontype {
     function print_question(&$question, &$state, $number, $cmoptions, $options) {
         global $CFG;
 
+        if (!empty($cmoptions->id)) {
+            $cm = get_coursemodule_from_instance('quiz', $cmoptions->id);
+            $cmorcourseid = '&amp;cmid='.$cm->id;
+        } else if (!empty($cmoptions->course)) {
+            $cmorcourseid = '&amp;courseid='.$cmoptions->course;
+        } else {
+            error('Need to provide courseid or cmid to print_question.');
+        }
+
         // For editing teachers print a link to an editing popup window
-        $editlink = '';
         if (question_has_capability_on($question, 'edit')) {
             $stredit = get_string('edit');
             $linktext = '<img src="'.$CFG->pixpath.'/t/edit.gif" alt="'.$stredit.'" />';
-            $editlink = link_to_popup_window('/question/question.php?id='.$question->id, $stredit, $linktext, 450, 550, $stredit, '', true);
+            $editlink = link_to_popup_window('/question/question.php?id='.$question->id.$cmorcourseid,
+                                             $stredit, $linktext, 450, 550, $stredit, '', true);
         }
 
         $questiontext = $this->format_text($question->questiontext, $question->questiontextformat, $cmoptions);
index 354fffddd1da9b35f511e4bf4bfffef52bf65126..51824748b94b8efc75a5b8747919f80b462d1da2 100644 (file)
@@ -804,16 +804,17 @@ class default_questiontype {
         global $CFG;
         $isgraded = question_state_is_graded($state->last_graded);
 
-        // If this question is being shown in the context of a quiz
         // get the context so we can determine whether some extra links
-        // should be shown. (Don't show these links during question preview.)
-        $cm = get_coursemodule_from_instance('quiz', $cmoptions->id);
-        if (!empty($cm->id)) {
+        // should be shown.
+        if (!empty($cmoptions->id)) {
+            $cm = get_coursemodule_from_instance('quiz', $cmoptions->id);
             $context = get_context_instance(CONTEXT_MODULE, $cm->id);
-        } else if (!empty($cm->course)) {
-            $context = get_context_instance(CONTEXT_COURSE, $cm->course);
+            $cmorcourseid = '&amp;cmid='.$cm->id;
+        } else if (!empty($cmoptions->course)) {
+            $context = get_context_instance(CONTEXT_COURSE, $cmoptions->course);
+            $cmorcourseid = '&amp;courseid='.$cmoptions->course;
         } else {
-            $context = get_context_instance(CONTEXT_SYSTEM, SITEID);
+            error('Need to provide courseid or cmid to print_question.');
         }
 
         // For editing teachers print a link to an editing popup window
@@ -821,7 +822,8 @@ class default_questiontype {
         if (question_has_capability_on($question, 'edit')) {
             $stredit = get_string('edit');
             $linktext = '<img src="'.$CFG->pixpath.'/t/edit.gif" alt="'.$stredit.'" />';
-            $editlink = link_to_popup_window('/question/question.php?inpopup=1&amp;id='.$question->id, 'editquestion', $linktext, 450, 550, $stredit, '', true);
+            $editlink = link_to_popup_window('/question/question.php?inpopup=1&amp;id='.$question->id.$cmorcourseid,
+                                             'editquestion', $linktext, 450, 550, $stredit, '', true);
         }
 
         $generalfeedback = '';
@@ -1157,7 +1159,7 @@ class default_questiontype {
         // Question types may wish to override this (eg. to ignore trailing
         // white space or to make "7.0" and "7" compare equal).
 
-        // In php neither == nor === compare arrays the way you want. The following 
+        // In php neither == nor === compare arrays the way you want. The following
         // ensures that the arrays have the same keys, with the same values.
         $result = false;
         $diff1 = array_diff_assoc($state->responses, $teststate->responses);