Commit | Line | Data |
---|---|---|
f3f7610c ML |
1 | <?php |
2 | /** | |
3 | * Add/remove members from group. | |
4 | * | |
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 | |
9 | * @package groups | |
10 | */ | |
11 | require_once('../config.php'); | |
12 | require_once('lib.php'); | |
13 | require_once($CFG->libdir.'/moodlelib.php'); | |
14 | ||
15 | $success = true; | |
16 | ||
17 | $courseid = required_param('courseid', PARAM_INT); | |
18 | $groupingid = required_param('grouping', PARAM_INT); | |
19 | $groupid = required_param('group', PARAM_INT); | |
20 | ||
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); | |
24 | if (! $course) { | |
25 | $success = false; | |
b39552af | 26 | print_error('invalidcourse'); |
27 | } | |
28 | if (empty($groupid)) { | |
29 | $success = false; | |
30 | print_error('errorinvalidgroup', 'group', groups_home_url($courseid)); | |
f3f7610c ML |
31 | } |
32 | ||
33 | if ($success) { | |
34 | // Make sure that the user has permissions to manage groups. | |
35 | require_login($courseid); | |
36 | ||
37 | $context = get_context_instance(CONTEXT_COURSE, $courseid); | |
38 | if (! has_capability('moodle/course:managegroups', $context)) { | |
39 | redirect(); | |
40 | } | |
41 | ||
42 | if ($frm = data_submitted() and confirm_sesskey()) { | |
43 | ||
44 | if (isset($frm->cancel)) { | |
45 | redirect('index.php?id='. $courseid | |
1ecd677e | 46 | .'&grouping='. $groupingid .'&group='. $groupid); |
f3f7610c ML |
47 | } |
48 | elseif (isset($frm->add) and !empty($frm->addselect)) { | |
49 | ||
50 | foreach ($frm->addselect as $userid) { | |
51 | if (! $userid = clean_param($userid, PARAM_INT)) { | |
52 | continue; | |
53 | } | |
f3f7610c ML |
54 | $success = groups_add_member($groupid, $userid); |
55 | if (! $success) { | |
b39552af | 56 | print_error('erroraddremoveuser', 'group', groups_home_url($courseid)); |
f3f7610c ML |
57 | } |
58 | } | |
59 | } | |
60 | elseif (isset($frm->remove) and !empty($frm->removeselect)) { | |
61 | ||
62 | foreach ($frm->removeselect as $userid) { | |
63 | if (! $userid = clean_param($userid, PARAM_INT)) { | |
64 | continue; | |
65 | } | |
66 | $success = groups_remove_member($groupid, $userid); | |
67 | if (! $success) { | |
b39552af | 68 | print_error('erroraddremoveuser', 'group', groups_home_url($courseid)); |
f3f7610c ML |
69 | } |
70 | } | |
71 | } | |
72 | } | |
73 | ||
74 | // Print the page and form | |
75 | $strgroups = get_string('groups'); | |
76 | $strparticipants = get_string('participants'); | |
77 | ||
78 | $groupname = groups_get_group_displayname($groupid); | |
79 | ||
80 | print_header("$course->shortname: $strgroups", | |
6ba65fa0 | 81 | $course->fullname, |
f3f7610c ML |
82 | "<a href=\"$CFG->wwwroot/course/view.php?id=$courseid\">$course->shortname</a> ". |
83 | "-> <a href=\"$CFG->wwwroot/user/index.php?id=$courseid\">$strparticipants</a> ". | |
b4e80a8b | 84 | '-> <a href="' .format_string(groups_home_url($courseid, $groupid, $groupingid, false)) . "\">$strgroups</a>". |
85 | '-> '. get_string('adduserstogroup', 'group'), '', '', true, '', user_login_string($course, $USER)); | |
f3f7610c | 86 | |
f3f7610c ML |
87 | ?> |
88 | <div id="addmembersform"> | |
89 | <h3 class="main"><?php print_string('adduserstogroup', 'group'); echo " $groupname"; ?></h3> | |
90 | ||
b4e80a8b | 91 | <form id="assignform" method="post" action=""> |
92 | <div> | |
f3f7610c ML |
93 | <input type="hidden" name="sesskey" value="<?php p(sesskey()); ?>" /> |
94 | <input type="hidden" name="courseid" value="<?php p($courseid); ?>" /> | |
95 | <input type="hidden" name="grouping" value="<?php echo $groupingid; ?>" /> | |
96 | <input type="hidden" name="group" value="<?php echo $groupid; ?>" /> | |
97 | ||
b4e80a8b | 98 | <table summary="" cellpadding="5" cellspacing="0"> |
f3f7610c ML |
99 | <tr> |
100 | <td valign="top"> | |
101 | <label for="removeselect"><?php print_string('existingusers', 'role'); //count($contextusers) ?></label> | |
102 | <br /> | |
103 | <select name="removeselect[]" size="20" id="removeselect" multiple="multiple" | |
b4e80a8b | 104 | onfocus="document.getElementById('assignform').add.disabled=true; |
105 | document.getElementById('assignform').remove.disabled=false; | |
106 | document.getElementById('assignform').addselect.selectedIndex=-1;"> | |
f3f7610c ML |
107 | <?php |
108 | $userids = groups_get_members($groupid); | |
109 | ||
110 | if ($userids != false) { | |
111 | // Put the groupings into a hash and sorts them | |
112 | foreach ($userids as $userid) { | |
113 | $listmembers[$userid] = groups_get_user_displayname($userid, $courseid); | |
114 | } | |
115 | natcasesort($listmembers); | |
116 | ||
117 | // Print out the HTML | |
118 | foreach($listmembers as $id => $name) { | |
119 | echo "<option value=\"$id\">$name</option>\n"; | |
120 | } | |
b4e80a8b | 121 | } else { |
122 | echo '<option> </option>'; | |
f3f7610c ML |
123 | } |
124 | ?> | |
125 | </select></td> | |
126 | <td valign="top"> | |
127 | <?php // Hidden assignment? ?> | |
128 | ||
129 | <?php check_theme_arrows(); ?> | |
130 | <p class="arrow_button"> | |
131 | <input name="add" id="add" type="submit" value="<?php echo ' '.$THEME->larrow.' '.get_string('add'); ?>" title="<?php print_string('add'); ?>" /> | |
132 | <br /> | |
133 | <input name="remove" id="remove" type="submit" value="<?php echo ' '.$THEME->rarrow.' '.get_string('remove'); ?>" title="<?php print_string('remove'); ?>" /> | |
134 | </p> | |
135 | </td> | |
136 | <td valign="top"> | |
137 | <label for="addselect"><?php print_string('potentialusers', 'role'); //$usercount ?></label> | |
138 | <br /> | |
139 | <select name="addselect[]" size="20" id="addselect" multiple="multiple" | |
b4e80a8b | 140 | onfocus="document.getElementById('assignform').add.disabled=false; |
141 | document.getElementById('assignform').remove.disabled=true; | |
142 | document.getElementById('assignform').removeselect.selectedIndex=-1;"> | |
f3f7610c | 143 | <?php |
b39552af | 144 | //TODO: If no 'showall' button, then set true. |
145 | $showall = true; | |
f3f7610c | 146 | unset($userids); |
b39552af | 147 | if (!$showall && $groupingid != GROUP_NOT_IN_GROUPING) { |
f3f7610c ML |
148 | $userids = groups_get_users_not_in_any_group_in_grouping($courseid, $groupingid, $groupid); |
149 | } else { | |
150 | $userids = groups_get_users_not_in_group($courseid, $groupid); | |
151 | } | |
152 | ||
153 | if ($userids != false) { | |
154 | // Put the groupings into a hash and sorts them | |
155 | foreach ($userids as $userid) { | |
156 | $nonmembers[$userid] = groups_get_user_displayname($userid, $courseid); | |
157 | } | |
158 | natcasesort($nonmembers); | |
159 | ||
160 | // Print out the HTML | |
161 | foreach($nonmembers as $id => $name) { | |
162 | echo "<option value=\"$id\">$name</option>\n"; | |
163 | } | |
b4e80a8b | 164 | } else { |
165 | echo '<option> </option>'; | |
f3f7610c ML |
166 | } |
167 | ?> | |
168 | </select> | |
169 | <br /> | |
b39552af | 170 | <?php //TODO: Search box? |
f3f7610c | 171 | |
b39552af | 172 | /*if (!empty($searchtext)) { |
173 | echo '<input name="showall" type="submit" value="'.get_string('showall').'" />'."\n"; | |
174 | }*/ | |
f3f7610c ML |
175 | ?> |
176 | </td> | |
177 | </tr> | |
178 | <tr><td> | |
e91cc88c | 179 | <input type="submit" name="cancel" value="<?php print_string('backtogroups', 'group'); ?>" /> |
f3f7610c ML |
180 | </td></tr> |
181 | </table> | |
b4e80a8b | 182 | </div> |
f3f7610c ML |
183 | </form> |
184 | </div> | |
185 | ||
186 | <?php | |
187 | print_footer($course); | |
188 | } | |
189 | ||
190 | ?> |