From: jamiesensei Date: Tue, 14 Aug 2007 04:22:05 +0000 (+0000) Subject: Fix for MDL-10823 Access to question edit page denied from quiz preview screen. X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=e7e62d45be8090f0c6e8279dd46e557243d6ac6e;p=moodle.git Fix for MDL-10823 Access to question edit page denied from quiz preview screen. --- diff --git a/mod/quiz/locallib.php b/mod/quiz/locallib.php index eab2d7441d..daed4ac411 100644 --- a/mod/quiz/locallib.php +++ b/mod/quiz/locallib.php @@ -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 . '&quizid=' . $quiz->id, 'questionpreview', + $quizorcourseid = $quiz->id?('&quizid=' . $quiz->id):('&courseid=' .$COURSE->id); + return link_to_popup_window('/question/preview.php?id=' . $question->id . $quizorcourseid, 'questionpreview', "pixpath/t/preview.gif\" class=\"iconsmall\" alt=\"$strpreview\" />", 0, 0, $strpreview, QUESTION_PREVIEW_POPUP_OPTIONS, true); } diff --git a/question/editlib.php b/question/editlib.php index 947e1e8cd9..945a8a6f58 100644 --- a/question/editlib.php +++ b/question/editlib.php @@ -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 . '&quizid=' . $quizid, 'questionpreview', + $quizorcourseid = $quizid?('&quizid=' . $quizid):('&courseid=' .$COURSE->id); + link_to_popup_window('/question/preview.php?id=' . $question->id . $quizorcourseid, 'questionpreview', "pixpath/t/preview.gif\" class=\"iconsmall\" alt=\"$strpreview\" />", 0, 0, $strpreview, QUESTION_PREVIEW_POPUP_OPTIONS); } diff --git a/question/preview.php b/question/preview.php index 8922ac69d6..e992c204ec 100644 --- a/question/preview.php +++ b/question/preview.php @@ -22,6 +22,11 @@ $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 .= '&quizid=' . $quizid; + } else { + $url .= '&courseid=' . $courseid; } $url .= '&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 { @@ -201,6 +209,7 @@ echo '
'; echo "\n"; echo "\n"; + echo "\n"; echo "\n"; // Print the mark and finish attempt buttons diff --git a/question/type/description/questiontype.php b/question/type/description/questiontype.php index 1ba123698f..f8042ecba3 100644 --- a/question/type/description/questiontype.php +++ b/question/type/description/questiontype.php @@ -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 = '&cmid='.$cm->id; + } else if (!empty($cmoptions->course)) { + $cmorcourseid = '&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 = ''.$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); diff --git a/question/type/questiontype.php b/question/type/questiontype.php index 354fffddd1..51824748b9 100644 --- a/question/type/questiontype.php +++ b/question/type/questiontype.php @@ -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 = '&cmid='.$cm->id; + } else if (!empty($cmoptions->course)) { + $context = get_context_instance(CONTEXT_COURSE, $cmoptions->course); + $cmorcourseid = '&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 = ''.$stredit.''; - $editlink = link_to_popup_window('/question/question.php?inpopup=1&id='.$question->id, 'editquestion', $linktext, 450, 550, $stredit, '', true); + $editlink = link_to_popup_window('/question/question.php?inpopup=1&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);