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; | |
26 | print_error('The course ID is invalid'); | |
27 | } | |
28 | ||
29 | if ($success) { | |
30 | // Make sure that the user has permissions to manage groups. | |
31 | require_login($courseid); | |
32 | ||
33 | $context = get_context_instance(CONTEXT_COURSE, $courseid); | |
34 | if (! has_capability('moodle/course:managegroups', $context)) { | |
35 | redirect(); | |
36 | } | |
37 | ||
38 | if ($frm = data_submitted() and confirm_sesskey()) { | |
39 | ||
40 | if (isset($frm->cancel)) { | |
41 | redirect('index.php?id='. $courseid | |
42 | .'&groupingid='. $groupingid .'&groupid='. $groupid); | |
43 | } | |
44 | elseif (isset($frm->add) and !empty($frm->addselect)) { | |
45 | ||
46 | foreach ($frm->addselect as $userid) { | |
47 | if (! $userid = clean_param($userid, PARAM_INT)) { | |
48 | continue; | |
49 | } | |
50 | //echo "Try user $userid, group $groupid<br>\n"; | |
51 | $success = groups_add_member($groupid, $userid); | |
52 | if (! $success) { | |
53 | print_error('Failed to add user $userid to group.'); | |
54 | } | |
55 | } | |
56 | } | |
57 | elseif (isset($frm->remove) and !empty($frm->removeselect)) { | |
58 | ||
59 | foreach ($frm->removeselect as $userid) { | |
60 | if (! $userid = clean_param($userid, PARAM_INT)) { | |
61 | continue; | |
62 | } | |
63 | $success = groups_remove_member($groupid, $userid); | |
64 | if (! $success) { | |
65 | print_error('Failed to remove user $userid from group.'); | |
66 | } | |
67 | } | |
68 | } | |
69 | } | |
70 | ||
71 | // Print the page and form | |
72 | $strgroups = get_string('groups'); | |
73 | $strparticipants = get_string('participants'); | |
74 | ||
75 | $groupname = groups_get_group_displayname($groupid); | |
76 | ||
77 | print_header("$course->shortname: $strgroups", | |
78 | "$course->fullname", | |
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)); | |
82 | ||
83 | //require_once('assign-form.html'); | |
84 | ?> | |
85 | <div id="addmembersform"> | |
86 | <h3 class="main"><?php print_string('adduserstogroup', 'group'); echo " $groupname"; ?></h3> | |
87 | ||
88 | <form name="assignform" id="assignform" method="post" action=""> | |
89 | ||
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; ?>" /> | |
94 | ||
95 | <table summary="" align="center" cellpadding="5" cellspacing="0"> | |
96 | <tr> | |
97 | <td valign="top"> | |
98 | <label for="removeselect"><?php print_string('existingusers', 'role'); //count($contextusers) ?></label> | |
99 | <br /> | |
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;"> | |
104 | <?php | |
105 | $userids = groups_get_members($groupid); | |
106 | ||
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); | |
111 | } | |
112 | natcasesort($listmembers); | |
113 | ||
114 | // Print out the HTML | |
115 | foreach($listmembers as $id => $name) { | |
116 | echo "<option value=\"$id\">$name</option>\n"; | |
117 | } | |
118 | } | |
119 | ?> | |
120 | </select></td> | |
121 | <td valign="top"> | |
122 | <?php // Hidden assignment? ?> | |
123 | ||
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'); ?>" /> | |
127 | <br /> | |
128 | <input name="remove" id="remove" type="submit" value="<?php echo ' '.$THEME->rarrow.' '.get_string('remove'); ?>" title="<?php print_string('remove'); ?>" /> | |
129 | </p> | |
130 | </td> | |
131 | <td valign="top"> | |
132 | <label for="addselect"><?php print_string('potentialusers', 'role'); //$usercount ?></label> | |
133 | <br /> | |
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;"> | |
138 | <?php | |
139 | $showall = 0; | |
140 | unset($userids); | |
141 | if ($showall == 0 && $groupingid != GROUP_NOT_IN_GROUPING) { | |
142 | $userids = groups_get_users_not_in_any_group_in_grouping($courseid, $groupingid, $groupid); | |
143 | } else { | |
144 | $userids = groups_get_users_not_in_group($courseid, $groupid); | |
145 | } | |
146 | ||
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); | |
151 | } | |
152 | natcasesort($nonmembers); | |
153 | ||
154 | // Print out the HTML | |
155 | foreach($nonmembers as $id => $name) { | |
156 | echo "<option value=\"$id\">$name</option>\n"; | |
157 | } | |
158 | } | |
159 | ?> | |
160 | </select> | |
161 | <br /> | |
162 | <?php //TODO: Search box | |
163 | ||
164 | if (!empty($searchtext)) { | |
165 | echo '<input name="showall" id="showall" type="submit" value="'.$strshowall.'" />'."\n"; | |
166 | } | |
167 | ?> | |
168 | </td> | |
169 | </tr> | |
170 | <tr><td> | |
171 | <input type="submit" name="cancel" value="<?php print_string('return', 'group'); ?>" /> | |
172 | </td></tr> | |
173 | </table> | |
174 | ||
175 | </form> | |
176 | </div> | |
177 | ||
178 | <?php | |
179 | print_footer($course); | |
180 | } | |
181 | ||
182 | ?> |