2 // This file is part of Moodle - http://moodle.org/
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 * User enrolment edit script.
20 * This page allows the current user to edit a user enrolment.
21 * It is not compatible with the frontpage.
23 * NOTE: plugins are free to implement own edit scripts with extra logic.
26 * @copyright 2011 Sam Hemelryk
27 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
30 require('../config.php');
31 require_once("$CFG->dirroot/enrol/locallib.php"); // Required for the course enrolment manager.
32 require_once("$CFG->dirroot/enrol/renderer.php"); // Required for the course enrolment users table.
33 require_once("$CFG->dirroot/enrol/editenrolment_form.php"); // Forms for this page.
35 $ueid = required_param('ue', PARAM_INT
);
36 $filter = optional_param('ifilter', 0, PARAM_INT
); // Table filter for return url.
38 $ue = $DB->get_record('user_enrolments', array('id' => $ueid), '*', MUST_EXIST
);
39 $user = $DB->get_record('user', array('id'=>$ue->userid
), '*', MUST_EXIST
);
40 $instance = $DB->get_record('enrol', array('id'=>$ue->enrolid
), '*', MUST_EXIST
);
41 $course = $DB->get_record('course', array('id'=>$instance->courseid
), '*', MUST_EXIST
);
43 // The URL of the enrolled users page for the course.
44 $usersurl = new moodle_url('/user/index.php', array('id' => $course->id
));
46 // Do not allow any changes if plugin disabled, not available or not suitable.
47 if (!$plugin = enrol_get_plugin($instance->enrol
)) {
50 if (!$plugin->allow_manage($instance)) {
55 require_login($course);
56 // The user must be able to manage enrolments within the course.
57 require_capability('enrol/'.$instance->enrol
.':manage', context_course
::instance($course->id
, MUST_EXIST
));
59 // Get the enrolment manager for this course.
60 $manager = new course_enrolment_manager($PAGE, $course, $filter);
61 // Get an enrolment users table object. Doing this will automatically retrieve the the URL params
62 // relating to table the user was viewing before coming here, and allows us to return the user to the
63 // exact page of the users screen they can from.
64 $table = new course_enrolment_users_table($manager, $PAGE);
66 // The URl to return the user too after this screen.
67 $returnurl = new moodle_url($usersurl, $manager->get_url_params()+
$table->get_url_params());
68 // The URL of this page.
69 $url = new moodle_url('/enrol/editenrolment.php', $returnurl->params());
72 $PAGE->set_pagelayout('admin');
73 navigation_node
::override_active_url($usersurl);
75 // Get the enrolment edit form.
76 $mform = new enrol_user_enrolment_form($url,
81 'enrolinstancename' => $plugin->get_instance_name($instance)
84 $mform->set_data($PAGE->url
->params());
86 if ($mform->is_cancelled()) {
89 } else if ($data = $mform->get_data()) {
90 if ($manager->edit_enrolment($ue, $data)) {
95 $fullname = fullname($user);
96 $title = get_string('editenrolment', 'core_enrol');
98 $PAGE->set_title($title);
99 $PAGE->set_heading($title);
100 $PAGE->navbar
->add($title);
101 $PAGE->navbar
->add($fullname);
103 echo $OUTPUT->header();
104 echo $OUTPUT->heading($fullname);
106 echo $OUTPUT->footer();