print_error('invalidgroupid'); } if (!($course = $DB->get_record('course', array('id' => $group->courseid)))) { print_error('invalidcourse'); } $courseid = $course->id; require_login($course); $context = get_context_instance(CONTEXT_COURSE, $courseid); require_capability('moodle/course:managegroups', $context); $returnurl = $CFG->wwwroot . '/group/index.php?id=' . $courseid . '&group=' . $group->id; if (optional_param('cancel', false, PARAM_BOOL)) { redirect($returnurl); } $groupmembersselector = new group_members_selector('removeselect', array('groupid' => $groupid, 'courseid' => $course->id)); $groupmembersselector->set_extra_fields(array()); $potentialmembersselector = new group_non_members_selector('addselect', array('groupid' => $groupid, 'courseid' => $course->id)); $potentialmembersselector->set_extra_fields(array()); if (optional_param('add', false, PARAM_BOOL) && confirm_sesskey()) { $userstoadd = $potentialmembersselector->get_selected_users(); if (!empty($userstoadd)) { foreach ($userstoadd as $user) { if (!groups_add_member($groupid, $user->id)) { print_error('erroraddremoveuser', 'group', $returnurl); } $groupmembersselector->invalidate_selected_users(); $potentialmembersselector->invalidate_selected_users(); } } } if (optional_param('remove', false, PARAM_BOOL) && confirm_sesskey()) { $userstoremove = $groupmembersselector->get_selected_users();
require_once $CFG->libdir . '/filelib.php'; $groupid = required_param('group', PARAM_INT); $cancel = optional_param('cancel', false, PARAM_BOOL); $group = $DB->get_record('groups', array('id' => $groupid), '*', MUST_EXIST); $course = $DB->get_record('course', array('id' => $group->courseid), '*', MUST_EXIST); $PAGE->set_url('/group/members.php', array('group' => $groupid)); $PAGE->set_pagelayout('admin'); require_login($course); $context = context_course::instance($course->id); require_capability('moodle/course:managegroups', $context); $returnurl = $CFG->wwwroot . '/group/index.php?id=' . $course->id . '&group=' . $group->id; if ($cancel) { redirect($returnurl); } $groupmembersselector = new group_members_selector('removeselect', array('groupid' => $groupid, 'courseid' => $course->id)); $potentialmembersselector = new group_non_members_selector('addselect', array('groupid' => $groupid, 'courseid' => $course->id)); if (optional_param('add', false, PARAM_BOOL) && confirm_sesskey()) { $userstoadd = $potentialmembersselector->get_selected_users(); if (!empty($userstoadd)) { foreach ($userstoadd as $user) { if (!groups_add_member($groupid, $user->id)) { print_error('erroraddremoveuser', 'group', $returnurl); } $groupmembersselector->invalidate_selected_users(); $potentialmembersselector->invalidate_selected_users(); } } } if (optional_param('remove', false, PARAM_BOOL) && confirm_sesskey()) { $userstoremove = $groupmembersselector->get_selected_users(); if (!empty($userstoremove)) {