See Release Notes
Long Term Support Release
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 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. 8 // 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. 13 // 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/>. 16 17 /** 18 * User enrolment edit script. 19 * 20 * This page allows the current user to edit a user enrolment. 21 * It is not compatible with the frontpage. 22 * 23 * NOTE: plugins are free to implement own edit scripts with extra logic. 24 * 25 * @package core_enrol 26 * @copyright 2011 Sam Hemelryk 27 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 28 */ 29 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. 34 35 $ueid = required_param('ue', PARAM_INT); 36 $filter = optional_param('ifilter', 0, PARAM_INT); // Table filter for return url. 37 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); 42 43 // The URL of the enrolled users page for the course. 44 $usersurl = new moodle_url('/user/index.php', array('id' => $course->id)); 45 46 // Do not allow any changes if plugin disabled, not available or not suitable. 47 if (!$plugin = enrol_get_plugin($instance->enrol)) { 48 redirect($usersurl); 49 } 50 if (!$plugin->allow_manage($instance)) { 51 redirect($usersurl); 52 } 53 54 // Obviously. 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)); 58 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); 65 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()); 70 71 $PAGE->set_url($url); 72 $PAGE->set_pagelayout('admin'); 73 navigation_node::override_active_url($usersurl); 74 75 // Get the enrolment edit form. 76 $mform = new enrol_user_enrolment_form($url, 77 [ 78 'user' => $user, 79 'course' => $course, 80 'ue' => $ue, 81 'enrolinstancename' => $plugin->get_instance_name($instance) 82 ] 83 ); 84 $mform->set_data($PAGE->url->params()); 85 86 if ($mform->is_cancelled()) { 87 redirect($returnurl); 88 89 } else if ($data = $mform->get_data()) { 90 if (!empty($data->duration) && $data->timeend == 0) { 91 $data->timeend = $data->timestart + $data->duration; 92 } 93 if ($manager->edit_enrolment($ue, $data)) { 94 redirect($returnurl); 95 } 96 } 97 98 $fullname = fullname($user); 99 $title = get_string('editenrolment', 'core_enrol'); 100 101 $PAGE->set_title($title); 102 $PAGE->set_heading($title); 103 $PAGE->navbar->add($title); 104 $PAGE->navbar->add($fullname); 105 106 echo $OUTPUT->header(); 107 echo $OUTPUT->heading($fullname); 108 $mform->display(); 109 echo $OUTPUT->footer();
title
Description
Body
title
Description
Body
title
Description
Body
title
Body