mirror of
https://github.com/moodle/moodle.git
synced 2025-04-24 18:04:43 +02:00
Fix for MDL-10823 Access to question edit page denied from quiz preview screen.
This commit is contained in:
parent
b6aeb9ba31
commit
e7e62d45be
@ -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',
|
||||
"<img src=\"$CFG->pixpath/t/preview.gif\" class=\"iconsmall\" alt=\"$strpreview\" />",
|
||||
0, 0, $strpreview, QUESTION_PREVIEW_POPUP_OPTIONS, true);
|
||||
}
|
||||
|
@ -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',
|
||||
"<img src=\"$CFG->pixpath/t/preview.gif\" class=\"iconsmall\" alt=\"$strpreview\" />",
|
||||
0, 0, $strpreview, QUESTION_PREVIEW_POPUP_OPTIONS);
|
||||
}
|
||||
|
@ -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 '<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
|
||||
|
@ -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 = '<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);
|
||||
|
@ -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 = '<img src="'.$CFG->pixpath.'/t/edit.gif" alt="'.$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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user