Skip to content

Commit

Permalink
MDL-52035 core_enrol: allow redirection to another page
Browse files Browse the repository at this point in the history
  • Loading branch information
mdjnelson committed Apr 26, 2016
1 parent 581ea50 commit 30498d9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
9 changes: 6 additions & 3 deletions enrol/editinstance.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
$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);

Expand All @@ -43,7 +43,10 @@
$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);
}
Expand All @@ -62,7 +65,7 @@
$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);
Expand Down
6 changes: 5 additions & 1 deletion enrol/editinstance_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function definition() {

$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));

Expand All @@ -60,6 +60,10 @@ public function definition() {
$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);
Expand Down

0 comments on commit 30498d9

Please sign in to comment.