3 * Add/remove members from group.
5 * @copyright © 2006 The Open University
6 * @author N.D.Freear AT open.ac.uk
7 * @author J.White AT open.ac.uk
8 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
11 require_once('../config.php');
12 require_once('lib.php');
14 define("MAX_USERS_PER_PAGE", 5000);
16 $groupid = required_param('group', PARAM_INT
);
17 $searchtext = optional_param('searchtext', '', PARAM_RAW
); // search string
18 $showall = optional_param('showall', 0, PARAM_BOOL
);
24 if (!$group = get_record('groups', 'id', $groupid)) {
25 error('Incorrect group id');
28 if (!$course = get_record('course', 'id', $group->courseid
)) {
29 print_error('invalidcourse');
31 $courseid = $course->id
;
33 require_login($course);
34 $context = get_context_instance(CONTEXT_COURSE
, $courseid);
35 require_capability('moodle/course:managegroups', $context);
37 $strsearch = get_string('search');
38 $strshowall = get_string('showall');
39 $returnurl = $CFG->wwwroot
.'/group/index.php?id='.$courseid.'&group='.$group->id
;
42 if ($frm = data_submitted() and confirm_sesskey()) {
44 if (isset($frm->cancel
)) {
47 } else if (isset($frm->add
) and !empty($frm->addselect
)) {
49 foreach ($frm->addselect
as $userid) {
50 if (! $userid = clean_param($userid, PARAM_INT
)) {
53 if (!groups_add_member($groupid, $userid)) {
54 print_error('erroraddremoveuser', 'group', $returnurl);
58 } else if (isset($frm->remove
) and !empty($frm->removeselect
)) {
60 foreach ($frm->removeselect
as $userid) {
61 if (! $userid = clean_param($userid, PARAM_INT
)) {
64 if (!groups_remove_member($groupid, $userid)) {
65 print_error('erroraddremoveuser', 'group', $returnurl);
69 $eventdata = new object();
70 $eventdata -> groupid
= $groupid;
71 $eventdata -> userid
= $userid;
72 events_trigger('group_user_removed', $eventdata);
77 $groupmembersoptions = '';
78 $groupmemberscount = 0;
80 if ($groupmembers = groups_get_members($groupid)) {
81 foreach($groupmembers as $member) {
82 $groupmembersoptions .= '<option value="'.$member->id
.'">'.fullname($member, true).'</option>';
83 $groupmemberscount ++
;
87 $groupmembersoptions .= '<option> </option>';
90 $potentialmembers = array();
91 $potentialmembersoptions = '';
92 $potentialmemberscount = 0;
94 $potentialmembers = groups_get_users_not_in_group($courseid, $groupid, $searchtext);
95 if (!empty($potentialmembers)) {
96 $potentialmemberscount = count($potentialmembers);
98 $potentialmemberscount = 0;
100 if ($potentialmemberscount <= MAX_USERS_PER_PAGE
) {
102 if ($potentialmembers != false) {
103 // Put the groupings into a hash and sorts them
104 foreach ($potentialmembers as $userid => $user) {
105 $nonmembers[$userid] = fullname($user);
107 natcasesort($nonmembers);
109 // Print out the HTML
110 foreach($nonmembers as $id => $name) {
111 $potentialmembersoptions .= "<option value=\"$id\">$name</option>\n";
114 $potentialmembersoptions .= '<option> </option>';
118 // Print the page and form
119 $strgroups = get_string('groups');
120 $strparticipants = get_string('participants');
121 $stradduserstogroup = get_string('adduserstogroup', 'group');
123 $groupname = format_string($group->name
);
126 $navlinks[] = array('name' => $strparticipants, 'link' => "$CFG->wwwroot/user/index.php?id=$courseid", 'type' => 'misc');
127 $navlinks[] = array('name' => $strgroups, 'link' => "$CFG->wwwroot/group/index.php?id=$courseid", 'type' => 'misc');
128 $navlinks[] = array('name' => $stradduserstogroup, 'link' => null, 'type' => 'misc');
129 $navigation = build_navigation($navlinks);
131 print_header("$course->shortname: $strgroups", $course->fullname
, $navigation, '', '', true, '', user_login_string($course, $USER));
134 <div id
="addmembersform">
135 <h3
class="main"><?php
print_string('adduserstogroup', 'group'); echo ": $groupname"; ?
></h3
>
137 <form id
="assignform" method
="post" action
="members.php">
139 <input type
="hidden" name
="sesskey" value
="<?php p(sesskey()); ?>" />
140 <input type
="hidden" name
="group" value
="<?php echo $groupid; ?>" />
142 <table summary
="" cellpadding
="5" cellspacing
="0">
145 <label
for="removeselect"><?php
print_string('existingmembers', 'group', $groupmemberscount); //count($contextusers) ?></label>
147 <select name
="removeselect[]" size
="20" id
="removeselect" multiple
="multiple"
148 onfocus
="document.getElementById('assignform').add.disabled=true;
149 document.getElementById('assignform').remove.disabled=false;
150 document.getElementById('assignform').addselect.selectedIndex=-1;">
151 <?php
echo $groupmembersoptions ?
>
154 <?php
// Hidden assignment? ?>
156 <?php
check_theme_arrows(); ?
>
157 <p
class="arrow_button">
158 <input name
="add" id
="add" type
="submit" value
="<?php echo ' '.$THEME->larrow.' '.get_string('add'); ?>" title
="<?php print_string('add'); ?>" />
160 <input name
="remove" id
="remove" type
="submit" value
="<?php echo ' '.$THEME->rarrow.' '.get_string('remove'); ?>" title
="<?php print_string('remove'); ?>" />
164 <label
for="addselect"><?php
print_string('potentialmembers', 'group', $potentialmemberscount); //$usercount ?></label>
166 <select name
="addselect[]" size
="20" id
="addselect" multiple
="multiple"
167 onfocus
="document.getElementById('assignform').add.disabled=false;
168 document.getElementById('assignform').remove.disabled=true;
169 document.getElementById('assignform').removeselect.selectedIndex=-1;">
171 if ($potentialmemberscount > MAX_USERS_PER_PAGE
) {
172 echo '<optgroup label="'.get_string('toomanytoshow').'"><option></option></optgroup>'."\n"
173 .'<optgroup label="'.get_string('trysearching').'"><option></option></optgroup>'."\n";
175 echo $potentialmembersoptions;
180 <label
for="searchtext" class="accesshide"><?php
p($strsearch) ?
></label
>
181 <input type
="text" name
="searchtext" id
="searchtext" size
="30" value
="<?php p($searchtext, true) ?>"
182 onfocus
="getElementById('assignform').add.disabled=true;
183 getElementById('assignform').remove.disabled=true;
184 getElementById('assignform').removeselect.selectedIndex=-1;
185 getElementById('assignform').addselect.selectedIndex=-1;"
186 onkeydown
= "var keyCode = event.which ? event.which : event.keyCode;
188 getElementById('assignform').previoussearch.value=1;
189 getElementById('assignform').submit();
191 <input name
="search" id
="search" type
="submit" value
="<?php p($strsearch) ?>" />
193 if (!empty($searchtext)) {
194 echo '<input name="showall" id="showall" type="submit" value="'.$strshowall.'" />'."\n";
200 <input type
="submit" name
="cancel" value
="<?php print_string('backtogroups', 'group'); ?>" />
208 print_footer($course);