From fe4457ae29542b30965682bb7c71450da7aafd31 Mon Sep 17 00:00:00 2001 From: Daren Chandisingh Date: Thu, 20 Jan 2011 11:07:14 +0000 Subject: [PATCH] [MDL-25874] Handle 'Cancel' action when editing lessons --- mod/lesson/editpage.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/mod/lesson/editpage.php b/mod/lesson/editpage.php index c7839b77591..e9bffb8a2cc 100644 --- a/mod/lesson/editpage.php +++ b/mod/lesson/editpage.php @@ -56,8 +56,30 @@ if ($edit) { $jumpto = lesson_page::get_jumptooptions($pageid, $lesson); $manager = lesson_page_type_manager::get($lesson); $editoroptions = array('noclean'=>true, 'maxfiles'=>EDITOR_UNLIMITED_FILES, 'maxbytes'=>$CFG->maxbytes); + +// If the previous page was the Question type selection form, this form +// will have a different name (e.g. _qf__lesson_add_page_form_selection +// versus _qf__lesson_add_page_form_multichoice). This causes confusion +// in moodleform::_process_submission because the array key check doesn't +// tie up with the current form name, which in turn means the "submitted" +// check ends up evaluating as false, thus it's not possible to check whether +// the Question type selection was cancelled. For this reason, a dummy form +// is created here solely to check whether the selection was cancelled. +if ($qtype) { + $mformdummy = $manager->get_page_form(0, array('editoroptions'=>$editoroptions, 'jumpto'=>$jumpto, 'lesson'=>$lesson, 'edit'=>$edit, 'maxbytes'=>$PAGE->course->maxbytes)); + if ($mformdummy->is_cancelled()) { + redirect("$CFG->wwwroot/mod/lesson/edit.php?id=$id"); + exit; + } +} + $mform = $manager->get_page_form($qtype, array('editoroptions'=>$editoroptions, 'jumpto'=>$jumpto, 'lesson'=>$lesson, 'edit'=>$edit, 'maxbytes'=>$PAGE->course->maxbytes)); +if ($mform->is_cancelled()) { + redirect("$CFG->wwwroot/mod/lesson/edit.php?id=$id"); + exit; +} + if ($edit) { $data = $editpage->properties(); $data->pageid = $editpage->id;