MDL-10838 Applied standard table classes and scopes to tr, th and tds of the grader...
[moodle-pu.git] / group / index.php
blob72f71aacd3df355258da6f8e5a8011fea374994b
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.'/json/JSON.php');
15 require_js('yui_yahoo');
16 require_js('yui_dom');
17 require_js('yui_utilities');
18 require_js('yui_connection');
19 require_js($CFG->wwwroot.'/group/lib/clientlib.js');
21 $courseid = required_param('id', PARAM_INT);
22 $groupid = optional_param('group', false, PARAM_INT);
23 $userid = optional_param('user', false, PARAM_INT);
24 $action = groups_param_action();
26 $returnurl = $CFG->wwwroot.'/group/index.php?id='.$courseid;
28 // Get the course information so we can print the header and
29 // check the course id is valid
31 if (!$course = groups_get_course_info($courseid)) {
32 $success = false;
33 print_error('invalidcourse'); //'The course ID is invalid'
36 // Make sure that the user has permissions to manage groups.
37 require_login($course);
39 $context = get_context_instance(CONTEXT_COURSE, $courseid);
40 if (! has_capability('moodle/course:managegroups', $context)) {
41 redirect(); //"group.php?id=$course->id"); // Not allowed to see all groups
44 switch ($action) {
45 case false: //OK, display form.
46 break;
48 case 'ajax_getmembersingroup':
49 $members = array();
51 if ($memberids = groups_get_members($groupid)) {
52 $member_names = groups_userids_to_user_names($memberids, $courseid);
53 $json = new Services_JSON();
54 echo $json->encode($member_names);
56 die; // Client side JavaScript takes it from here.
58 case 'deletegroup':
59 redirect('edit.php?delete=1&amp;courseid='.$courseid.'&amp;id='.$groupid);
60 break;
62 case 'showcreateorphangroupform':
63 redirect('edit.php?courseid='.$courseid);
64 break;
66 case 'showgroupsettingsform':
67 redirect('edit.php?courseid='.$courseid.'&amp;id='.$groupid);
68 break;
70 case 'updategroups': //Currently reloading.
71 break;
73 case 'removemembers':
74 break;
76 case 'showaddmembersform':
77 redirect('assign.php?group='.$groupid);
78 break;
80 case 'updatemembers': //Currently reloading.
81 break;
83 default: //ERROR.
84 if (debugging()) {
85 error('Error, unknown button/action. Probably a user-interface bug!', $returnurl);
86 break;
90 // Print the page and form
91 $strgroups = get_string('groups');
92 $strparticipants = get_string('participants');
94 print_header("$course->shortname: $strgroups",
95 $course->fullname,
96 "<a href=\"$CFG->wwwroot/course/view.php?id=$courseid\">$course->shortname</a> ".
97 "-> <a href=\"$CFG->wwwroot/user/index.php?id=$courseid\">$strparticipants</a> ".
98 "-> $strgroups", '', '', true, '', user_login_string($course, $USER));
100 $disabled = 'disabled="disabled"';
102 $showeditgroupsettingsform_disabled = $disabled;
103 $deletegroup_disabled = $disabled;
104 $showcreategroupform_disabled = $disabled;
106 if (!empty($groupid)) {
107 $showaddmembersform_disabled = '';
108 $showeditgroupsettingsform_disabled = '';
109 $deletegroup_disabled = '';
110 } else {
111 $deletegroup_disabled = $disabled;
112 $showeditgroupsettingsform_disabled = $disabled;
113 $showaddmembersform_disabled = $disabled;
116 print_heading(format_string($course->shortname) .' '.$strgroups, 'center', 3);
117 echo '<form id="groupeditform" action="index.php" method="post">'."\n";
118 echo '<div>'."\n";
119 echo '<input type="hidden" name="id" value="' . $courseid . '" />'."\n";
121 echo '<table cellpadding="6" class="generaltable generalbox groupmanagementtable boxaligncenter" summary="">'."\n";
122 echo '<tr>'."\n";
125 echo "<td>\n";
126 // NO GROUPINGS YET!
127 echo '<p><label for="groups"><span id="groupslabel">'.get_string('groups').':</span><span id="thegrouping">&nbsp;</span></label></p>'."\n";
129 echo '<select name="group" id="groups" size="15" class="select" onchange="membersCombo.refreshMembers(this.options[this.selectedIndex].value);"'."\n";
130 echo ' onclick="window.status=this.options[this.selectedIndex].title;" onmouseout="window.status=\'\';">'."\n";
132 if ($groups_records = get_groups($courseid)) {
133 $groupids = groups_groups_to_groupids($groups_records, $courseid);
134 } else {
135 $groupids = false;
138 $sel_groupid = 0;
140 if ($groupids) {
141 // Put the groups into a hash and sort them
142 $group_names = groups_groupids_to_group_names($groupids);
144 // Print out the HTML
145 $count = 1;
146 foreach ($group_names as $group) {
147 $select = '';
148 if ($groupid == $group->id) { //|| $count <= 1) ??
149 $select = ' selected="selected"';
150 $sel_groupid = $group->id;
152 echo "<option value=\"{$group->id}\"$select title=\"{$group->name}\">{$group->name}</option>\n";
153 $count++;
155 } else {
156 // Print an empty option to avoid the XHTML error of having an empty select element
157 echo '<option>&nbsp;</option>';
160 echo '</select>'."\n";
161 echo '<p><input type="submit" name="act_updatemembers" id="updatemembers" value="'
162 . get_string('showmembersforgroup', 'group') . '" /></p>'."\n";
163 echo '<p><input type="submit" '. $showeditgroupsettingsform_disabled . ' name="act_showgroupsettingsform" id="showeditgroupsettingsform" value="'
164 . get_string('editgroupsettings', 'group') . '" /></p>'."\n";
165 echo '<p><input type="submit" '. $deletegroup_disabled . ' name="act_deletegroup" onclick="onDeleteGroup()" id="deletegroup" value="'
166 . get_string('deleteselectedgroup', 'group') . '" /></p>'."\n";
168 echo '<p><input type="submit" name="act_showcreateorphangroupform" id="showcreateorphangroupform" value="'
169 . get_string('creategroup', 'group') . '" /></p>'."\n";
171 echo '</td>'."\n";
172 echo '<td>'."\n";
173 echo '<p><label for="members"><span id="memberslabel">'.get_string('membersofselectedgroup', 'group').' </span><span id="thegroup">&nbsp;</span></label></p>'."\n";
174 //NOTE: the SELECT was, multiple="multiple" name="user[]" - not used and breaks onclick.
175 echo '<select name="user" id="members" size="15" class="select"'."\n";
176 echo ' onclick="window.status=this.options[this.selectedIndex].title;" onmouseout="window.status=\'\';">'."\n";
178 $userids = false;
179 if ($sel_groupid) {
180 $userids = groups_get_members($sel_groupid);
183 if ($userids) {
184 // Put the groupings into a hash and sort them
185 $user_names = groups_userids_to_user_names($userids, $courseid);
186 if(empty($user_names)) {
187 echo '<option>&nbsp;</option>';
188 } else {
189 foreach ($user_names as $user) {
190 echo "<option value=\"{$user->id}\" title=\"{$user->name}\">{$user->name}</option>\n";
193 } else {
194 // Print an empty option to avoid the XHTML error of having an empty select element
195 echo '<option>&nbsp;</option>';
198 echo '</select>'."\n";
200 echo '<p><input type="submit" ' . $showaddmembersform_disabled . ' name="act_showaddmembersform" '
201 . 'id="showaddmembersform" value="' . get_string('adduserstogroup', 'group'). '" /></p>'."\n";
202 echo '</td>'."\n";
203 echo '</tr>'."\n";
204 echo '</table>'."\n";
206 //<input type="hidden" name="rand" value="om" />
207 echo '</div>'."\n";
208 echo '</form>'."\n";
210 echo '<script type="text/javascript">'."\n";
211 echo '//<![CDATA['."\n";
212 echo 'var groupsCombo = new UpdatableGroupsCombo("'.$CFG->wwwroot.'", '.$course->id.');'."\n";
213 echo 'var membersCombo = new UpdatableMembersCombo("'.$CFG->wwwroot.'", '.$course->id.');'."\n";
214 echo '//]]>'."\n";
215 echo '</script>'."\n";
217 print_footer($course);