courseid)) { print_error('invalidcourse'); } $courseid = $course->id; require_login($course); $context = get_context_instance(CONTEXT_COURSE, $courseid); require_capability('moodle/course:managegroups', $context); $strsearch = get_string('search'); $strshowall = get_string('showall'); $returnurl = $CFG->wwwroot.'/group/index.php?id='.$courseid.'&group='.$group->id; if ($frm = data_submitted() and confirm_sesskey()) { if (isset($frm->cancel)) { redirect($returnurl); } else if (isset($frm->add) and !empty($frm->addselect)) { foreach ($frm->addselect as $userid) { if (! $userid = clean_param($userid, PARAM_INT)) { continue; } if (!groups_add_member($groupid, $userid)) { print_error('erroraddremoveuser', 'group', $returnurl); } } } else if (isset($frm->remove) and !empty($frm->removeselect)) { foreach ($frm->removeselect as $userid) { if (! $userid = clean_param($userid, PARAM_INT)) { continue; } if (!groups_remove_member($groupid, $userid)) { print_error('erroraddremoveuser', 'group', $returnurl); } } } } $groupmembersoptions = ''; $groupmemberscount = 0; // Get members, organised by role, and display if ($groupmemberroles = groups_get_members_by_role($groupid,$courseid,'u.id,u.firstname,u.lastname')) { foreach($groupmemberroles as $roleid=>$roledata) { $groupmembersoptions .= ''; } } else { $groupmembersoptions .= ''; } $potentialmembers = array(); $potentialmembersoptions = ''; $potentialmemberscount = 0; // Get potential members, organised by role, and count them $potentialmembersbyrole = groups_get_users_not_in_group_by_role($courseid, $groupid, $searchtext); $potentialmemberscount=0; $potentialmembersids=array(); if (!empty($potentialmembersbyrole)) { foreach($potentialmembersbyrole as $roledata) { $potentialmemberscount+=count($roledata->users); $potentialmembersids=array_merge($potentialmembersids,array_keys($roledata->users)); } } $usergroups = array(); if ($potentialmemberscount <= MAX_USERS_PER_PAGE) { if ($potentialmemberscount != 0) { // Get other groups user already belongs to $sql = "SELECT u.id AS userid, g.* FROM {$CFG->prefix}user u " . "INNER JOIN {$CFG->prefix}groups_members gm ON u.id = gm.userid " . "INNER JOIN {$CFG->prefix}groups g ON gm.groupid = g.id " . "WHERE u.id IN (".implode(',',$potentialmembersids).") AND g.courseid = {$course->id} "; $rs = get_recordset_sql($sql); while ($usergroup = rs_fetch_next_record($rs)) { $usergroups[$usergroup->userid][$usergroup->id] = $usergroup; } rs_close($rs); foreach($potentialmembersbyrole as $roleid=>$roledata) { $potentialmembersoptions .= ''; } } else { $potentialmembersoptions .= ''; } } // Print the page and form $strgroups = get_string('groups'); $strparticipants = get_string('participants'); $stradduserstogroup = get_string('adduserstogroup', 'group'); $strusergroupmembership = get_string('usergroupmembership', 'group'); $groupname = format_string($group->name); $navlinks = array(); $navlinks[] = array('name' => $strparticipants, 'link' => "$CFG->wwwroot/user/index.php?id=$courseid", 'type' => 'misc'); $navlinks[] = array('name' => $strgroups, 'link' => "$CFG->wwwroot/group/index.php?id=$courseid", 'type' => 'misc'); $navlinks[] = array('name' => $stradduserstogroup, 'link' => null, 'type' => 'misc'); $navigation = build_navigation($navlinks); print_header("$course->shortname: $strgroups", $course->fullname, $navigation, '', '', true, '', user_login_string($course, $USER)); // Print Javascript for showing the selected users group membership ?>