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');
13 require_once($CFG->libdir
.'/moodlelib.php');
17 $courseid = required_param('courseid', PARAM_INT
);
18 $groupingid = required_param('grouping', PARAM_INT
);
19 $groupid = required_param('group', PARAM_INT
);
21 // Get the course information so we can print the header and
22 // check the course id is valid
23 $course = groups_get_course_info($courseid);
26 print_error('invalidcourse');
28 if (empty($groupid)) {
30 print_error('errorinvalidgroup', 'group', groups_home_url($courseid));
34 // Make sure that the user has permissions to manage groups.
35 require_login($courseid);
37 $context = get_context_instance(CONTEXT_COURSE
, $courseid);
38 if (! has_capability('moodle/course:managegroups', $context)) {
42 if ($frm = data_submitted() and confirm_sesskey()) {
44 if (isset($frm->cancel
)) {
45 redirect('index.php?id='. $courseid
46 .'&grouping='. $groupingid .'&group='. $groupid);
48 elseif (isset($frm->add
) and !empty($frm->addselect
)) {
50 foreach ($frm->addselect
as $userid) {
51 if (! $userid = clean_param($userid, PARAM_INT
)) {
54 $success = groups_add_member($groupid, $userid);
56 print_error('erroraddremoveuser', 'group', groups_home_url($courseid));
60 elseif (isset($frm->remove
) and !empty($frm->removeselect
)) {
62 foreach ($frm->removeselect
as $userid) {
63 if (! $userid = clean_param($userid, PARAM_INT
)) {
66 $success = groups_remove_member($groupid, $userid);
68 print_error('erroraddremoveuser', 'group', groups_home_url($courseid));
72 $eventdata = new object();
73 $eventdata -> groupid
= $groupid;
74 $eventdata -> userid
= $userid;
75 events_trigger('group_user_removed', $eventdata);
80 $groupmembers = groups_get_members($groupid);
81 $groupmembersoptions = '';
82 $groupmemberscount = 0;
83 if ($groupmembers != false) {
84 // Put the groupings into a hash and sorts them
85 foreach ($groupmembers as $userid) {
86 $listmembers[$userid] = groups_get_user_displayname($userid, $courseid);
87 $groupmemberscount ++
;
89 natcasesort($listmembers);
92 foreach($listmembers as $id => $name) {
93 $groupmembersoptions .= "<option value=\"$id\">$name</option>\n";
96 $groupmembersoptions .= '<option> </option>';
99 //TODO: If no 'showall' button, then set true.
102 $potentialmembers = array();
103 $potentialmembersoptions = '';
104 $potentialmemberscount = 0;
105 if (!$showall && $groupingid != GROUP_NOT_IN_GROUPING
) {
106 $potentialmembers = groups_get_users_not_in_any_group_in_grouping($courseid, $groupingid, $groupid);
108 $potentialmembers = groups_get_users_not_in_group($courseid, $groupid);
111 if ($potentialmembers != false) {
112 // Put the groupings into a hash and sorts them
113 foreach ($potentialmembers as $userid) {
114 $nonmembers[$userid] = groups_get_user_displayname($userid, $courseid);
115 $potentialmemberscount++
;
117 natcasesort($nonmembers);
119 // Print out the HTML
120 foreach($nonmembers as $id => $name) {
121 $potentialmembersoptions .= "<option value=\"$id\">$name</option>\n";
124 $potentialmembersoptions .= '<option> </option>';
127 // Print the page and form
128 $strgroups = get_string('groups');
129 $strparticipants = get_string('participants');
131 $groupname = groups_get_group_displayname($groupid);
133 print_header("$course->shortname: $strgroups",
135 "<a href=\"$CFG->wwwroot/course/view.php?id=$courseid\">$course->shortname</a> ".
136 "-> <a href=\"$CFG->wwwroot/user/index.php?id=$courseid\">$strparticipants</a> ".
137 '-> <a href="' .format_string(groups_home_url($courseid, $groupid, $groupingid, false)) . "\">$strgroups</a>".
138 '-> '. get_string('adduserstogroup', 'group'), '', '', true, '', user_login_string($course, $USER));
141 <div id
="addmembersform">
142 <h3
class="main"><?php
print_string('adduserstogroup', 'group'); echo " $groupname"; ?
></h3
>
144 <form id
="assignform" method
="post" action
="">
146 <input type
="hidden" name
="sesskey" value
="<?php p(sesskey()); ?>" />
147 <input type
="hidden" name
="courseid" value
="<?php p($courseid); ?>" />
148 <input type
="hidden" name
="grouping" value
="<?php echo $groupingid; ?>" />
149 <input type
="hidden" name
="group" value
="<?php echo $groupid; ?>" />
151 <table summary
="" cellpadding
="5" cellspacing
="0">
154 <label
for="removeselect"><?php
print_string('existingmembers', 'group', $groupmemberscount); //count($contextusers) ?></label>
156 <select name
="removeselect[]" size
="20" id
="removeselect" multiple
="multiple"
157 onfocus
="document.getElementById('assignform').add.disabled=true;
158 document.getElementById('assignform').remove.disabled=false;
159 document.getElementById('assignform').addselect.selectedIndex=-1;">
160 <?php
echo $groupmembersoptions ?
>
163 <?php
// Hidden assignment? ?>
165 <?php
check_theme_arrows(); ?
>
166 <p
class="arrow_button">
167 <input name
="add" id
="add" type
="submit" value
="<?php echo ' '.$THEME->larrow.' '.get_string('add'); ?>" title
="<?php print_string('add'); ?>" />
169 <input name
="remove" id
="remove" type
="submit" value
="<?php echo ' '.$THEME->rarrow.' '.get_string('remove'); ?>" title
="<?php print_string('remove'); ?>" />
173 <label
for="addselect"><?php
print_string('potentialmembers', 'group', $potentialmemberscount); //$usercount ?></label>
175 <select name
="addselect[]" size
="20" id
="addselect" multiple
="multiple"
176 onfocus
="document.getElementById('assignform').add.disabled=false;
177 document.getElementById('assignform').remove.disabled=true;
178 document.getElementById('assignform').removeselect.selectedIndex=-1;">
179 <?php
echo $potentialmembersoptions ?
>
182 <?php
//TODO: Search box?
184 /*if (!empty($searchtext)) {
185 echo '<input name="showall" type="submit" value="'.get_string('showall').'" />'."\n";
191 <input type
="submit" name
="cancel" value
="<?php print_string('backtogroups', 'group'); ?>" />
199 print_footer($course);