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));
74 $groupmembers = groups_get_members($groupid);
75 $groupmembersoptions = '';
76 $groupmemberscount = 0;
77 if ($groupmembers != false) {
78 // Put the groupings into a hash and sorts them
79 foreach ($groupmembers as $userid) {
80 $listmembers[$userid] = groups_get_user_displayname($userid, $courseid);
81 $groupmemberscount ++
;
83 natcasesort($listmembers);
86 foreach($listmembers as $id => $name) {
87 $groupmembersoptions .= "<option value=\"$id\">$name</option>\n";
90 $groupmembersoptions .= '<option> </option>';
93 //TODO: If no 'showall' button, then set true.
96 $potentialmembers = array();
97 $potentialmembersoptions = '';
98 $potentialmemberscount = 0;
99 if (!$showall && $groupingid != GROUP_NOT_IN_GROUPING
) {
100 $potentialmembers = groups_get_users_not_in_any_group_in_grouping($courseid, $groupingid, $groupid);
102 $potentialmembers = groups_get_users_not_in_group($courseid, $groupid);
105 if ($potentialmembers != false) {
106 // Put the groupings into a hash and sorts them
107 foreach ($potentialmembers as $userid) {
108 $nonmembers[$userid] = groups_get_user_displayname($userid, $courseid);
109 $potentialmemberscount++
;
111 natcasesort($nonmembers);
113 // Print out the HTML
114 foreach($nonmembers as $id => $name) {
115 $potentialmembersoptions .= "<option value=\"$id\">$name</option>\n";
118 $potentialmembersoptions .= '<option> </option>';
121 // Print the page and form
122 $strgroups = get_string('groups');
123 $strparticipants = get_string('participants');
125 $groupname = groups_get_group_displayname($groupid);
127 print_header("$course->shortname: $strgroups",
129 "<a href=\"$CFG->wwwroot/course/view.php?id=$courseid\">$course->shortname</a> ".
130 "-> <a href=\"$CFG->wwwroot/user/index.php?id=$courseid\">$strparticipants</a> ".
131 '-> <a href="' .format_string(groups_home_url($courseid, $groupid, $groupingid, false)) . "\">$strgroups</a>".
132 '-> '. get_string('adduserstogroup', 'group'), '', '', true, '', user_login_string($course, $USER));
135 <div id
="addmembersform">
136 <h3
class="main"><?php
print_string('adduserstogroup', 'group'); echo " $groupname"; ?
></h3
>
138 <form id
="assignform" method
="post" action
="">
140 <input type
="hidden" name
="sesskey" value
="<?php p(sesskey()); ?>" />
141 <input type
="hidden" name
="courseid" value
="<?php p($courseid); ?>" />
142 <input type
="hidden" name
="grouping" value
="<?php echo $groupingid; ?>" />
143 <input type
="hidden" name
="group" value
="<?php echo $groupid; ?>" />
145 <table summary
="" cellpadding
="5" cellspacing
="0">
148 <label
for="removeselect"><?php
print_string('existingmembers', 'group', $groupmemberscount); //count($contextusers) ?></label>
150 <select name
="removeselect[]" size
="20" id
="removeselect" multiple
="multiple"
151 onfocus
="document.getElementById('assignform').add.disabled=true;
152 document.getElementById('assignform').remove.disabled=false;
153 document.getElementById('assignform').addselect.selectedIndex=-1;">
154 <?php
echo $groupmembersoptions ?
>
157 <?php
// Hidden assignment? ?>
159 <?php
check_theme_arrows(); ?
>
160 <p
class="arrow_button">
161 <input name
="add" id
="add" type
="submit" value
="<?php echo ' '.$THEME->larrow.' '.get_string('add'); ?>" title
="<?php print_string('add'); ?>" />
163 <input name
="remove" id
="remove" type
="submit" value
="<?php echo ' '.$THEME->rarrow.' '.get_string('remove'); ?>" title
="<?php print_string('remove'); ?>" />
167 <label
for="addselect"><?php
print_string('potentialmembers', 'group', $potentialmemberscount); //$usercount ?></label>
169 <select name
="addselect[]" size
="20" id
="addselect" multiple
="multiple"
170 onfocus
="document.getElementById('assignform').add.disabled=false;
171 document.getElementById('assignform').remove.disabled=true;
172 document.getElementById('assignform').removeselect.selectedIndex=-1;">
173 <?php
echo $potentialmembersoptions ?
>
176 <?php
//TODO: Search box?
178 /*if (!empty($searchtext)) {
179 echo '<input name="showall" type="submit" value="'.get_string('showall').'" />'."\n";
185 <input type
="submit" name
="cancel" value
="<?php print_string('backtogroups', 'group'); ?>" />
193 print_footer($course);