MDL-52035 core_enrol: allow redirection to another page

This commit is contained in:
Mark Nelson 2016-04-12 14:57:43 +08:00
parent 581ea5013a
commit 30498d9a0e
2 changed files with 11 additions and 4 deletions

View File

@ -28,7 +28,7 @@ require_once('editinstance_form.php');
$courseid = required_param('courseid', PARAM_INT);
$type = required_param('type', PARAM_COMPONENT);
$instanceid = optional_param('id', 0, PARAM_INT);
$return = optional_param('returnurl', 0, PARAM_LOCALURL);
$course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
$context = context_course::instance($course->id, MUST_EXIST);
@ -43,7 +43,10 @@ require_capability('enrol/' . $type . ':config', $context);
$PAGE->set_url('/enrol/editinstance.php', array('courseid' => $course->id, 'id' => $instanceid, 'type' => $type));
$PAGE->set_pagelayout('admin');
$return = new moodle_url('/enrol/instances.php', array('id' => $course->id));
if (empty($return)) {
$return = new moodle_url('/enrol/instances.php', array('id' => $course->id));
}
if (!enrol_is_enabled($type)) {
redirect($return);
}
@ -62,7 +65,7 @@ if ($instanceid) {
$instance->status = ENROL_INSTANCE_ENABLED; // Do not use default for automatically created instances here.
}
$mform = new enrol_instance_edit_form(null, array($instance, $plugin, $context, $type));
$mform = new enrol_instance_edit_form(null, array($instance, $plugin, $context, $type, $return));
if ($mform->is_cancelled()) {
redirect($return);

View File

@ -45,7 +45,7 @@ class enrol_instance_edit_form extends moodleform {
$mform = $this->_form;
list($instance, $plugin, $context, $type) = $this->_customdata;
list($instance, $plugin, $context, $type, $returnurl) = $this->_customdata;
$mform->addElement('header', 'header', get_string('pluginname', 'enrol_' . $type));
@ -60,6 +60,10 @@ class enrol_instance_edit_form extends moodleform {
$mform->setType('type', PARAM_COMPONENT);
$instance->type = $type;
$mform->addElement('hidden', 'returnurl');
$mform->setType('returnurl', PARAM_LOCALURL);
$mform->setConstant('returnurl', $returnurl);
$this->add_action_buttons(true, ($instance->id ? null : get_string('addinstance', 'enrol')));
$this->set_data($instance);