$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);
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()));
/** * Returns an array of URL params for both the table and the manager. * * @return array */ public function get_combined_url_params() { return $this->get_url_params() + $this->manager->get_url_params(); }
$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':
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':
$id = required_param('id', PARAM_INT); // course id $action = optional_param('action', '', PARAM_ACTION); $filter = optional_param('ifilter', 0, PARAM_INT); $course = $DB->get_record('course', array('id' => $id), '*', MUST_EXIST); $context = get_context_instance(CONTEXT_COURSE, $course->id, MUST_EXIST); require_login($course); require_capability('moodle/role:assign', $context); if ($course->id == SITEID) { redirect("{$CFG->wwwroot}/"); } $PAGE->set_url('/enrol/otherusers.php', array('id' => $course->id)); $PAGE->set_pagelayout('admin'); $manager = new course_enrolment_manager($course, $filter); $table = new course_enrolment_other_users_table($manager, $PAGE->url); $pageurl = new moodle_url($PAGE->url, $manager->get_url_params() + $table->get_url_params()); /*** * Actions will go here */ /*$fields = array( 'userdetails' => array ( 'picture' => false, 'firstname' => get_string('firstname'), 'lastname' => get_string('lastname'), 'email' => get_string('email') ), 'lastseen' => get_string('lastaccess'), 'role' => array( 'roles' => get_string('roles', 'role'), 'context' => get_string('context') )
/** * Sets the fields for this table. These get added to the tables head as well. * * You can also use a multi dimensional array for this to have multiple fields * in a single column * * @param array $fields An array of fields to set * @param string $output */ public function set_fields($fields, $output) { $this->fields = $fields; $this->head = array(); $this->colclasses = array(); $this->align = array(); $url = new moodle_url($this->pageurl, $this->get_url_params() + $this->manager->get_url_params()); foreach ($fields as $name => $label) { $newlabel = ''; if (is_array($label)) { $bits = array(); foreach ($label as $n => $l) { if ($l === false) { continue; } if (!in_array($n, self::$sortablefields)) { $bits[] = $l; } else { $link = html_writer::link(new moodle_url($url, array(self::SORTVAR => $n)), $fields[$name][$n]); if ($this->sort == $n) { $link .= ' ' . html_writer::link(new moodle_url($url, array(self::SORTVAR => $n, self::SORTDIRECTIONVAR => $this->get_field_sort_direction($n))), $this->get_direction_icon($output, $n)); } $bits[] = html_writer::tag('span', $link, array('class' => 'subheading_' . $n)); } } $newlabel = join(' / ', $bits); } else { if (!in_array($name, self::$sortablefields)) { $newlabel = $label; } else { $newlabel = html_writer::link(new moodle_url($url, array(self::SORTVAR => $name)), $fields[$name]); if ($this->sort == $name) { $newlabel .= ' ' . html_writer::link(new moodle_url($url, array(self::SORTVAR => $name, self::SORTDIRECTIONVAR => $this->get_field_sort_direction($name))), $this->get_direction_icon($output, $name)); } } } $this->head[] = $newlabel; $this->colclasses[] = 'field col_' . $name; } }