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('The course ID is invalid');
30 // Make sure that the user has permissions to manage groups.
31 require_login($courseid);
33 $context = get_context_instance(CONTEXT_COURSE
, $courseid);
34 if (! has_capability('moodle/course:managegroups', $context)) {
38 if ($frm = data_submitted() and confirm_sesskey()) {
40 if (isset($frm->cancel
)) {
41 redirect('index.php?id='. $courseid
42 .'&groupingid='. $groupingid .'&groupid='. $groupid);
44 elseif (isset($frm->add
) and !empty($frm->addselect
)) {
46 foreach ($frm->addselect
as $userid) {
47 if (! $userid = clean_param($userid, PARAM_INT
)) {
50 //echo "Try user $userid, group $groupid<br/>\n";
51 $success = groups_add_member($groupid, $userid);
53 print_error('Failed to add user $userid to group.');
57 elseif (isset($frm->remove
) and !empty($frm->removeselect
)) {
59 foreach ($frm->removeselect
as $userid) {
60 if (! $userid = clean_param($userid, PARAM_INT
)) {
63 $success = groups_remove_member($groupid, $userid);
65 print_error('Failed to remove user $userid from group.');
71 // Print the page and form
72 $strgroups = get_string('groups');
73 $strparticipants = get_string('participants');
75 $groupname = groups_get_group_displayname($groupid);
77 print_header("$course->shortname: $strgroups",
79 "<a href=\"$CFG->wwwroot/course/view.php?id=$courseid\">$course->shortname</a> ".
80 "-> <a href=\"$CFG->wwwroot/user/index.php?id=$courseid\">$strparticipants</a> ".
81 "-> $strgroups", '', '', true, '', user_login_string($course, $USER));
83 //require_once('assign-form.html');
85 <div id
="addmembersform">
86 <h3
class="main"><?php
print_string('adduserstogroup', 'group'); echo " $groupname"; ?
></h3
>
88 <form name
="assignform" id
="assignform" method
="post" action
="">
90 <input type
="hidden" name
="sesskey" value
="<?php p(sesskey()); ?>" />
91 <input type
="hidden" name
="courseid" value
="<?php p($courseid); ?>" />
92 <input type
="hidden" name
="grouping" value
="<?php echo $groupingid; ?>" />
93 <input type
="hidden" name
="group" value
="<?php echo $groupid; ?>" />
95 <table summary
="" align
="center" cellpadding
="5" cellspacing
="0">
98 <label
for="removeselect"><?php
print_string('existingusers', 'role'); //count($contextusers) ?></label>
100 <select name
="removeselect[]" size
="20" id
="removeselect" multiple
="multiple"
101 onfocus
="document.assignform.add.disabled=true;
102 document.assignform.remove.disabled=false;
103 document.assignform.addselect.selectedIndex=-1;">
105 $userids = groups_get_members($groupid);
107 if ($userids != false) {
108 // Put the groupings into a hash and sorts them
109 foreach ($userids as $userid) {
110 $listmembers[$userid] = groups_get_user_displayname($userid, $courseid);
112 natcasesort($listmembers);
114 // Print out the HTML
115 foreach($listmembers as $id => $name) {
116 echo "<option value=\"$id\">$name</option>\n";
122 <?php
// Hidden assignment? ?>
124 <?php
check_theme_arrows(); ?
>
125 <p
class="arrow_button">
126 <input name
="add" id
="add" type
="submit" value
="<?php echo ' '.$THEME->larrow.' '.get_string('add'); ?>" title
="<?php print_string('add'); ?>" />
128 <input name
="remove" id
="remove" type
="submit" value
="<?php echo ' '.$THEME->rarrow.' '.get_string('remove'); ?>" title
="<?php print_string('remove'); ?>" />
132 <label
for="addselect"><?php
print_string('potentialusers', 'role'); //$usercount ?></label>
134 <select name
="addselect[]" size
="20" id
="addselect" multiple
="multiple"
135 onfocus
="document.assignform.add.disabled=false;
136 document.assignform.remove.disabled=true;
137 document.assignform.removeselect.selectedIndex=-1;">
141 if ($showall == 0 && $groupingid != GROUP_NOT_IN_GROUPING
) {
142 $userids = groups_get_users_not_in_any_group_in_grouping($courseid, $groupingid, $groupid);
144 $userids = groups_get_users_not_in_group($courseid, $groupid);
147 if ($userids != false) {
148 // Put the groupings into a hash and sorts them
149 foreach ($userids as $userid) {
150 $nonmembers[$userid] = groups_get_user_displayname($userid, $courseid);
152 natcasesort($nonmembers);
154 // Print out the HTML
155 foreach($nonmembers as $id => $name) {
156 echo "<option value=\"$id\">$name</option>\n";
162 <?php
//TODO: Search box
164 if (!empty($searchtext)) {
165 echo '<input name="showall" id="showall" type="submit" value="'.$strshowall.'" />'."\n";
171 <input type
="submit" name
="cancel" value
="<?php print_string('return', 'group'); ?>" />
179 print_footer($course);