list($ctxsql, $ctxjoin) = context_instance_preload_sql('c.id', CONTEXT_COURSE, 'ctx'); $sql = "SELECT c.* {$ctxsql}\n FROM {course} c\n LEFT JOIN {enrol} e ON e.courseid = c.id\n {$ctxjoin}\n WHERE e.id = :enrolid"; $params = array('enrolid' => $ue->enrolid); $course = $DB->get_record_sql($sql, $params, MUST_EXIST); context_instance_preload($course); if ($course->id == SITEID) { redirect(new moodle_url('/')); } require_login($course); require_capability("enrol/globalclassroom:unenrol", get_context_instance(CONTEXT_COURSE, $course->id, MUST_EXIST)); $manager = new course_enrolment_manager($PAGE, $course, $filter); $table = new course_enrolment_users_table($manager, $PAGE); // The URL of the enrolled users page for the course. $usersurl = new moodle_url('/enrol/users.php', array('id' => $course->id)); // The URl to return the user too after this screen. $returnurl = new moodle_url($usersurl, $manager->get_url_params() + $table->get_url_params()); // The URL of this page $url = new moodle_url('/enrol/globalclassroom/unenroluser.php', $returnurl->params()); $url->param('ue', $ueid); $PAGE->set_url($url); $PAGE->set_pagelayout('admin'); navigation_node::override_active_url($usersurl); list($instance, $plugin) = $manager->get_user_enrolment_components($ue); if (!$plugin->allow_unenrol($instance) || $instance->enrol != 'globalclassroom' || !$plugin instanceof enrol_globalclassroom_plugin) { print_error('erroreditenrolment', 'enrol'); } // If the unenrolment has been confirmed and the sesskey is valid unenrol the user. if ($confirm && confirm_sesskey() && $manager->unenrol_user($ue)) { redirect($returnurl); } $yesurl = new moodle_url($PAGE->url, array('confirm' => 1, 'sesskey' => sesskey()));
$instance = $DB->get_record('enrol', array('id' => $ue->enrolid), '*', MUST_EXIST); $course = $DB->get_record('course', array('id' => $instance->courseid), '*', MUST_EXIST); $context = context_course::instance($course->id); // set up PAGE url first! $PAGE->set_url('/enrol/unenroluser.php', array('ue' => $ueid, 'ifilter' => $filter)); require_login($course); if (!enrol_is_enabled($instance->enrol)) { print_error('erroreditenrolment', 'enrol'); } $plugin = enrol_get_plugin($instance->enrol); if (!$plugin->allow_unenrol_user($instance, $ue) or !has_capability("enrol/{$instance->enrol}:unenrol", $context)) { print_error('erroreditenrolment', 'enrol'); } $manager = new course_enrolment_manager($PAGE, $course, $filter); $table = new course_enrolment_users_table($manager, $PAGE); $returnurl = new moodle_url('/enrol/users.php', array('id' => $course->id) + $manager->get_url_params() + $table->get_url_params()); $usersurl = new moodle_url('/enrol/users.php', array('id' => $course->id)); $PAGE->set_pagelayout('admin'); navigation_node::override_active_url($usersurl); // If the unenrolment has been confirmed and the sesskey is valid unenrol the user. if ($confirm && confirm_sesskey()) { $plugin->unenrol_user($instance, $ue->userid); redirect($returnurl); } $yesurl = new moodle_url($PAGE->url, array('confirm' => 1, 'sesskey' => sesskey())); $message = get_string('unenrolconfirm', 'core_enrol', array('user' => fullname($user, true), 'course' => format_string($course->fullname))); $fullname = fullname($user); $title = get_string('unenrol', 'core_enrol'); $PAGE->set_title($title); $PAGE->set_heading($title); $PAGE->navbar->add($title);
require_once "{$CFG->dirroot}/group/lib.php"; $id = required_param('id', PARAM_INT); // course id $action = optional_param('action', '', PARAM_ALPHANUMEXT); $filter = optional_param('ifilter', 0, PARAM_INT); $course = $DB->get_record('course', array('id' => $id), '*', MUST_EXIST); $context = context_course::instance($course->id, MUST_EXIST); if ($course->id == SITEID) { redirect(new moodle_url('/')); } require_login($course); require_capability('moodle/course:enrolreview', $context); $PAGE->set_pagelayout('admin'); $manager = new course_enrolment_manager($PAGE, $course, $filter); $table = new course_enrolment_users_table($manager, $PAGE); $PAGE->set_url('/enrol/users.php', $manager->get_url_params() + $table->get_url_params()); navigation_node::override_active_url(new moodle_url('/enrol/users.php', array('id' => $id))); // Check if there is an action to take if ($action) { // Check if the page is confirmed (and sesskey is correct) $confirm = optional_param('confirm', false, PARAM_BOOL) && confirm_sesskey(); $actiontaken = false; $pagetitle = ''; $pageheading = ''; $mform = null; $pagecontent = null; switch ($action) { /** * Removes a role from the user with this course */ case 'unassign':
$newcourse = optional_param('newcourse', false, PARAM_BOOL); // When users reset the form, redirect back to first page without other params. if (optional_param('resetbutton', '', PARAM_RAW) !== '') { redirect('users.php?id=' . $id . '&newcourse=' . $newcourse); } $course = $DB->get_record('course', array('id' => $id), '*', MUST_EXIST); $context = context_course::instance($course->id, MUST_EXIST); if ($course->id == SITEID) { redirect(new moodle_url('/')); } require_login($course); require_capability('moodle/course:enrolreview', $context); $PAGE->set_pagelayout('admin'); $manager = new course_enrolment_manager($PAGE, $course, $filter, $role, $search, $fgroup, $status); $table = new course_enrolment_users_table($manager, $PAGE); $PAGE->set_url('/enrol/users.php', $manager->get_url_params() + $table->get_url_params() + array('newcourse' => $newcourse)); navigation_node::override_active_url(new moodle_url('/enrol/users.php', array('id' => $id))); // Check if there is an action to take if ($action) { // Check if the page is confirmed (and sesskey is correct) $confirm = optional_param('confirm', false, PARAM_BOOL) && confirm_sesskey(); $actiontaken = false; $pagetitle = ''; $pageheading = ''; $mform = null; $pagecontent = null; switch ($action) { /** * Removes a role from the user with this course */ case 'unassign':
$id = required_param('id', PARAM_INT); // course id $action = optional_param('action', '', PARAM_ACTION); $filter = optional_param('ifilter', 0, PARAM_INT); $PAGE->set_url(new moodle_url('/enrol/users.php', array('id' => $id))); $course = $DB->get_record('course', array('id' => $id), '*', MUST_EXIST); $context = get_context_instance(CONTEXT_COURSE, $course->id, MUST_EXIST); if ($course->id == SITEID) { redirect(new moodle_url('/')); } require_login($course); require_capability('moodle/course:enrolreview', $context); $PAGE->set_pagelayout('admin'); $manager = new course_enrolment_manager($course, $filter); $table = new course_enrolment_users_table($manager, $PAGE->url); $pageurl = new moodle_url($PAGE->url, $manager->get_url_params() + $table->get_url_params()); // Check if there is an action to take if ($action) { // Check if the page is confirmed (and sesskey is correct) $confirm = optional_param('confirm', false, PARAM_BOOL) && confirm_sesskey(); $actiontaken = false; $pagetitle = ''; $pageheading = ''; $mform = null; $pagecontent = null; switch ($action) { /** * Unenrols a user from this course */ case 'unenrol': $ue = $DB->get_record('user_enrolments', array('id' => required_param('ue', PARAM_INT)), '*', MUST_EXIST);