Automatic installer.php lang files by installer_builder (20070726)
[moodle-linuxchix.git] / group / index.php
blob84b8fe2e3ad285586e469308ee71c699098a8045
1 <?php
2 /**
3 * The main group management user interface.
5 * @copyright &copy; 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
11 require_once('../config.php');
12 require_once('lib.php');
13 require_once($CFG->libdir.'/moodlelib.php');
14 require_once($CFG->libdir.'/json/JSON.php');
16 require_js('yui_yahoo');
17 require_js('yui_dom');
18 require_js('yui_connection');
19 require_js($CFG->wwwroot.'/group/lib/clientlib.js');
22 $success = true;
24 $courseid = required_param('id', PARAM_INT);
25 $groupingid = optional_param('grouping', GROUP_NOT_IN_GROUPING, PARAM_INT);
26 $groupid = optional_param('group', false, PARAM_INT);
27 $userid = optional_param('user', false, PARAM_INT);
28 $action = groups_param_action();
30 if (empty($CFG->enablegroupings)) {
31 // NO GROUPINGS YET!
32 $groupingid = GROUP_NOT_IN_GROUPING;
35 if ($groupid) {
36 $groupingsforgroup = groups_get_groupings_for_group($groupid);
37 if ($groupingsforgroup) {
38 // NOTE
39 // We currently assume that a group can only belong to one grouping.
40 // FIXME
41 // The UI will have to be fixed if we want to support more than one
42 // groupings per group in the future.
44 // vy-shane AT moodle DOT com
45 $groupingid = array_shift($groupingsforgroup);
50 // Get the course information so we can print the header and
51 // check the course id is valid
52 $course = groups_get_course_info($courseid);
53 if (! $course) {
54 $success = false;
55 print_error('invalidcourse'); //'The course ID is invalid'
58 if ($success) {
59 // Make sure that the user has permissions to manage groups.
60 require_login($courseid);
62 $context = get_context_instance(CONTEXT_COURSE, $courseid);
63 if (! has_capability('moodle/course:managegroups', $context)) {
64 redirect(); //"group.php?id=$course->id"); // Not allowed to see all groups
67 // Set the session key so we can check this later
68 $sesskey = !empty($USER->id) ? $USER->sesskey : '';
71 switch ($action) {
72 case false: //OK, display form.
73 break;
75 case 'ajax_getgroupsingrouping':
76 if (GROUP_NOT_IN_GROUPING == $groupingid) {
77 $groupids = groups_get_groups_not_in_any_grouping($courseid);
78 } else {
79 $groupids = groups_get_groups_in_grouping($groupingid);
81 $group_names = groups_groupids_to_group_names($groupids);
82 $json = new Services_JSON();
83 echo $json->encode($group_names);
84 die; // Client side JavaScript takes it from here.
86 case 'ajax_getmembersingroup':
87 $members = array();
89 if ($memberids = groups_get_members($groupid)) {
90 $member_names = groups_userids_to_user_names($memberids, $courseid);
91 $json = new Services_JSON();
92 echo $json->encode($member_names);
94 die; // Client side JavaScript takes it from here.
96 case 'showgroupingsettingsform':
97 redirect(groups_grouping_edit_url($courseid, $groupingid, false));
98 break;
99 case 'showgroupingpermsform':
100 break;
101 case 'deletegrouping':
102 redirect(groups_grouping_edit_url($courseid, $groupingid, $html=false, $param='delete=1'));
103 break;
104 case 'showcreategroupingform':
105 redirect(groups_grouping_edit_url($courseid, null, false));
106 break;
107 case 'printerfriendly':
108 redirect('printgrouping.php?courseid='. $courseid .'&groupingid='. $groupingid);
109 break;
111 case 'showgroupsettingsform':
112 redirect(groups_group_edit_url($courseid, $groupid, $groupingid, false));
113 break;
114 case 'deletegroup':
115 redirect(groups_group_edit_url($courseid, $groupid, $groupingid, $html=false, $param='delete=1'));
116 break;
117 case 'removegroup':
118 break;
119 case 'showcreategroupform':
120 // Allow groups to be created outside of groupings
122 if (GROUP_NOT_IN_GROUPING == $groupingid) {
123 print_error('errornotingrouping', 'group', groups_home_url($courseid), get_string('notingrouping', 'group'));
126 redirect(groups_group_edit_url($courseid, null, $groupingid, false));
127 break;
128 case 'showcreateorphangroupform':
129 redirect(groups_group_edit_url($courseid, null, null, false));
130 break;
131 case 'addgroupstogroupingform':
132 break;
133 case 'updategroups': //Currently reloading.
134 break;
136 case 'removemembers':
137 break;
138 case 'showaddmembersform':
139 redirect(groups_members_add_url($courseid, $groupid, $groupingid, false));
140 break;
141 case 'updatemembers': //Currently reloading.
142 break;
144 default: //ERROR.
145 if (debugging()) {
146 error('Error, unknown button/action. Probably a user-interface bug!', groups_home_url($courseid));
147 break;
151 // Print the page and form
152 $strgroups = get_string('groups');
153 $strparticipants = get_string('participants');
155 print_header("$course->shortname: $strgroups home", //TODO: home
156 $course->fullname,
157 "<a href=\"$CFG->wwwroot/course/view.php?id=$courseid\">$course->shortname</a> ".
158 "-> <a href=\"$CFG->wwwroot/user/index.php?id=$courseid\">$strparticipants</a> ".
159 "-> $strgroups", '', '', true, '', user_login_string($course, $USER));
161 $usehtmleditor = false;
162 //TODO: eventually we'll implement all buttons, meantime hide the ones we haven't finished.
163 $shownotdone = false;
164 $disabled = 'disabled="disabled"';
166 // Pre-disable buttons based on URL variables
167 if (!empty($groupingid) && $groupingid > -1) {
168 $showeditgroupsettingsform_disabled = '';
169 $showeditgroupingsettingsform_disabled = '';
170 $deletegroup_disabled = '';
171 $deletegrouping_disabled = '';
172 $printerfriendly_disabled = '';
173 $showcreategroupform_disabled = '';
174 } else {
175 $showeditgroupsettingsform_disabled = $disabled;
176 $showeditgroupingsettingsform_disabled = $disabled;
177 $deletegroup_disabled = $disabled;
178 $deletegrouping_disabled = $disabled;
179 $printerfriendly_disabled = $disabled;
180 $showcreategroupform_disabled = $disabled;
183 if ($groupingid == -1 && groups_count_groups_in_grouping(GROUP_NOT_IN_GROUPING, $courseid) > 0) {
184 $printerfriendly_disabled = '';
187 if (!empty($groupid)) {
188 $showaddmembersform_disabled = '';
189 $showeditgroupsettingsform_disabled = '';
190 $deletegroup_disabled = '';
191 } else {
192 $deletegroup_disabled = $disabled;
193 $showeditgroupsettingsform_disabled = $disabled;
194 $showaddmembersform_disabled = $disabled;
197 print_heading(format_string($course->shortname) .' '.$strgroups, 'center', 3);
198 echo '<form id="groupeditform" action="index.php" method="post">'."\n";
199 echo '<div>'."\n";
200 echo '<input type="hidden" name="id" value="' . $courseid . '" />'."\n";
203 <input type="hidden" name="groupid" value="<?php p($selectedgroup) ?>" />
204 <input type="hidden" name="sesskey" value="<?php p($sesskey) ?>" />
205 <input type="hidden" name="roleid" value="<?php p($roleid) ?>" />
207 echo '<table cellpadding="6" class="generaltable generalbox groupmanagementtable boxaligncenter" summary="">'."\n";
208 echo '<tr>'."\n";
210 if (empty($CFG->enablegroupings)) {
211 // NO GROUPIGS YET!
212 $sel_groupingid = -1;
213 } else {
214 echo '<td class="generalboxcontent">'."\n";
215 echo '<p><label for="groupings">' . get_string('groupings', 'group') . '<span id="dummygrouping">&nbsp;</span></label></p>'."\n";
216 echo '<select name="grouping" id="groupings" size="15" class="select"';
217 echo ' onchange="groupsCombo.refreshGroups(this.options[this.selectedIndex].value);"';
218 //NOTE: onclick/onmouseout is for long names in IE6 (Firefox/IE7 display OPTION title).
219 echo ' onclick="window.status=this.options[this.selectedIndex].title;" onmouseout="window.status=\'\';">'."\n";
221 $groupingids = groups_get_groupings($courseid);
222 if (groups_count_groups_in_grouping(GROUP_NOT_IN_GROUPING, $courseid) > 0) {
223 //NOTE, only show the pseudo-grouping if it has groups.
224 $groupingids[] = GROUP_NOT_IN_GROUPING;
227 $sel_groupingid = -1;
229 if ($groupingids) {
230 // Put the groupings into a hash and sort them
231 foreach($groupingids as $id) {
232 $listgroupings[$id] = groups_get_grouping_displayname($id, $courseid);
234 natcasesort($listgroupings);
236 // Print out the HTML
237 $count = 1;
238 foreach($listgroupings as $id => $name) {
239 $select = '';
240 if ($groupingid == $id) { //|| $count <= 1) ??
241 $select = ' selected="selected"';
242 $sel_groupingid = $id;
244 echo "<option value=\"$id\"$select title=\"$name\">$name</option>\n";
245 $count++;
247 } else {
248 echo '<option>&nbsp;</option>';
251 echo '</select>'."\n";
254 echo '<p><input type="submit" name="act_updategroups" id="updategroups" value="'
255 . get_string('showgroupsingrouping', 'group') . '" /></p>'."\n";
256 echo '<p><input type="submit" ' . $showeditgroupingsettingsform_disabled . ' name="act_showgroupingsettingsform" id="showeditgroupingsettingsform" value="'
257 . get_string('editgroupingsettings', 'group') . '" /></p>'."\n";
259 if ($shownotdone) {
260 echo '<p><input type="submit" '.$disabled.' name="act_showgroupingpermsform" '
261 . 'id="showeditgroupingpermissionsform" value="'
262 . get_string('editgroupingpermissions', 'group') . '" /></p>'."\n";
265 echo '<p><input type="submit" ' . $deletegrouping_disabled . ' name="act_deletegrouping" id="deletegrouping" value="'
266 . get_string('deletegrouping', 'group') . '" /></p>'."\n";
267 echo '<p><input type="submit" name="act_showcreategroupingform" id="showcreategroupingform" value="'
268 . get_string('creategrouping', 'group') . '" /></p>'."\n";
270 if ($shownotdone) {
271 echo '<p><input type="submit" '.$disabled.' name="act_createautomaticgroupingform" '
272 . 'id="showcreateautomaticgroupingform" value="'
273 . get_string('createautomaticgrouping', 'group') . '" /></p>'."\n";
276 echo '<p><input type="submit" ' . $printerfriendly_disabled . ' name="act_printerfriendly" id="printerfriendly" value="'
277 . get_string('printerfriendly', 'group') . '" /></p>'."\n";
278 echo "</td>\n";
280 echo "<td>\n";
281 if (empty($CFG->enablegroupings)) {
282 // NO GROUPINGS YET!
283 echo '<p><label for="groups"><span id="groupslabel">'.get_string('groups').':</span><span id="thegrouping">&nbsp;</span></label></p>'."\n";
284 } else {
285 echo '<p><label for="groups"><span id="groupslabel">'.get_string('groupsinselectedgrouping', 'group').' </span><span id="thegrouping">'.get_string('grouping', 'group').'</span></label></p>'."\n";
287 echo '<select name="group" id="groups" size="15" class="select" onchange="membersCombo.refreshMembers(this.options[this.selectedIndex].value);"'."\n";
288 echo ' onclick="window.status=this.options[this.selectedIndex].title;" onmouseout="window.status=\'\';">'."\n";
290 if (GROUP_NOT_IN_GROUPING == $sel_groupingid) {
291 $groupids = groups_get_groups_not_in_any_grouping($courseid); //$sel_groupingid
292 } else {
293 $groupids = groups_get_groups_in_grouping($sel_groupingid);
295 if ($groupids) {
296 // Put the groups into a hash and sort them
297 $group_names = groups_groupids_to_group_names($groupids);
299 // Print out the HTML
300 $count = 1;
301 foreach ($group_names as $group) {
302 $select = '';
303 if ($groupid == $group->id) { //|| $count <= 1) ??
304 $select = ' selected="selected"';
305 $sel_groupid = $group->id;
307 echo "<option value=\"{$group->id}\"$select title=\"{$group->name}\">{$group->name}</option>\n";
308 $count++;
310 } else {
311 // Print an empty option to avoid the XHTML error of having an empty select element
312 echo '<option>&nbsp;</option>';
315 echo '</select>'."\n";
316 echo '<p><input type="submit" name="act_updatemembers" id="updatemembers" value="'
317 . get_string('showmembersforgroup', 'group') . '" /></p>'."\n";
318 echo '<p><input type="submit" '. $showeditgroupsettingsform_disabled . ' name="act_showgroupsettingsform" id="showeditgroupsettingsform" value="'
319 . get_string('editgroupsettings', 'group') . '" /></p>'."\n";
320 echo '<p><input type="submit" '. $deletegroup_disabled . ' name="act_deletegroup" onclick="onDeleteGroup()" id="deletegroup" value="'
321 . get_string('deleteselectedgroup', 'group') . '" /></p>'."\n";
323 if ($shownotdone) {
324 echo '<p><input type="submit" '.$disabled.' name="act_removegroup" '
325 . 'id="removegroup" value="' . get_string('removegroupfromselectedgrouping', 'group') . '" /></p>'."\n";
328 if (empty($CFG->enablegroupings)) {
329 // NO GROUPIGS YET!
330 echo '<p><input type="submit" name="act_showcreateorphangroupform" id="showcreateorphangroupform" value="'
331 . get_string('creategroup', 'group') . '" /></p>'."\n";
332 echo '<p><input type="submit" name="act_printerfriendly" id="printerfriendly" value="'
333 . get_string('printerfriendly', 'group') . '" /></p>'."\n";
334 } else {
335 echo '<p><input type="submit" ' . $showcreategroupform_disabled . ' name="act_showcreategroupform" id="showcreategroupform" value="'
336 . get_string('creategroupinselectedgrouping', 'group') . '" /></p>'."\n";
338 echo '<p><input type="submit" name="act_showcreateorphangroupform" id="showcreateorphangroupform" value="'
339 . get_string('createorphangroup', 'group') . '" /></p>'."\n";
341 if ($shownotdone) {
342 echo '<p><input type="submit" '.$disabled.' name="act_addgroupstogroupingform" '
343 . 'id="showaddgroupstogroupingform" value="' . get_string('addgroupstogrouping', 'group') . '" /></p>'."\n";
347 echo '</td>'."\n";
348 echo '<td>'."\n";
349 echo '<p><label for="members"><span id="memberslabel">'.get_string('membersofselectedgroup', 'group').' </span><span id="thegroup">&nbsp;</span></label></p>'."\n";
350 //NOTE: the SELECT was, multiple="multiple" name="user[]" - not used and breaks onclick.
351 echo '<select name="user" id="members" size="15" class="select"'."\n";
352 echo ' onclick="window.status=this.options[this.selectedIndex].title;" onmouseout="window.status=\'\';">'."\n";
354 if (isset($sel_groupid)) {
355 $userids = groups_get_members($sel_groupid);
357 if (isset($userids)) { //&& is_array($userids)
358 // Put the groupings into a hash and sort them
359 $user_names = groups_userids_to_user_names($userids, $courseid);
360 if(empty($user_names)) {
361 echo '<option>&nbsp;</option>';
362 } else {
363 foreach ($user_names as $user) {
364 echo "<option value=\"{$user->id}\" title=\"{$user->name}\">{$user->name}</option>\n";
367 } else {
368 // Print an empty option to avoid the XHTML error of having an empty select element
369 echo '<option>&nbsp;</option>';
372 echo '</select>'."\n";
374 if ($shownotdone) {
375 echo '<p><input type="submit" '.$disabled.' name="act_removemembers" '
376 . 'id="removemembers" value="' . get_string('removeselectedusers', 'group') . '"/></p>'."\n";
379 echo '<p><input type="submit" ' . $showaddmembersform_disabled . ' name="act_showaddmembersform" '
380 . 'id="showaddmembersform" value="' . get_string('adduserstogroup', 'group'). '" /></p>'."\n";
381 echo '</td>'."\n";
382 echo '</tr>'."\n";
383 echo '</table>'."\n";
385 //<input type="hidden" name="rand" value="om" />
386 echo '</div>'."\n";
387 echo '</form>'."\n";
389 echo '<script type="text/javascript">'."\n";
390 echo '//<![CDATA['."\n";
391 echo 'var groupsCombo = new UpdatableGroupsCombo("'.$CFG->wwwroot.'", '.$course->id.');'."\n";
392 echo 'var membersCombo = new UpdatableMembersCombo("'.$CFG->wwwroot.'", '.$course->id.');'."\n";
393 echo '//]]>'."\n";
394 echo '</script>'."\n";
396 print_footer($course);