MDL-14177, remove the useless h1 tags
[moodle-linuxchix.git] / group / index.php
blobd70ebf2e1286a42bc55e7e3bd4b03c319eec4f9e
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/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 = get_record('course', 'id',$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 $roles = array();
50 if ($groupmemberroles = groups_get_members_by_role($groupid,$courseid,'u.id,u.firstname,u.lastname')) {
51 foreach($groupmemberroles as $roleid=>$roledata) {
52 $shortroledata=new StdClass;
53 $shortroledata->name=$roledata->name;
54 $shortroledata->users=array();
55 foreach($roledata->users as $member) {
56 $shortmember=new StdClass;
57 $shortmember->id=$member->id;
58 $shortmember->name=fullname($member, true);
59 $shortroledata->users[]=$shortmember;
61 $roles[]=$shortroledata;
64 $json = new Services_JSON();
65 echo $json->encode($roles);
66 die; // Client side JavaScript takes it from here.
68 case 'deletegroup':
69 redirect('group.php?delete=1&amp;courseid='.$courseid.'&amp;id='.$groupid);
70 break;
72 case 'showcreateorphangroupform':
73 redirect('group.php?courseid='.$courseid);
74 break;
76 case 'showautocreategroupsform':
77 redirect('autogroup.php?courseid='.$courseid);
78 break;
80 case 'showgroupsettingsform':
81 redirect('group.php?courseid='.$courseid.'&amp;id='.$groupid);
82 break;
84 case 'updategroups': //Currently reloading.
85 break;
87 case 'removemembers':
88 break;
90 case 'showaddmembersform':
91 redirect('members.php?group='.$groupid);
92 break;
94 case 'updatemembers': //Currently reloading.
95 break;
97 default: //ERROR.
98 if (debugging()) {
99 error('Error, unknown button/action. Probably a user-interface bug!', $returnurl);
100 break;
104 // Print the page and form
105 $strgroups = get_string('groups');
106 $strparticipants = get_string('participants');
108 $navlinks = array(array('name'=>$strparticipants, 'link'=>$CFG->wwwroot.'/user/index.php?id='.$courseid, 'type'=>'misc'),
109 array('name'=>$strgroups, 'link'=>'', 'type'=>'misc'));
110 $navigation = build_navigation($navlinks);
112 /// Print header
113 print_header_simple($strgroups, ': '.$strgroups, $navigation, '', '', true, '', navmenu($course));
114 // Add tabs
115 $currenttab = 'groups';
116 require('tabs.php');
118 $disabled = 'disabled="disabled"';
120 $showeditgroupsettingsform_disabled = $disabled;
121 $deletegroup_disabled = $disabled;
122 $showcreategroupform_disabled = $disabled;
124 if (!empty($groupid)) {
125 $showaddmembersform_disabled = '';
126 $showeditgroupsettingsform_disabled = '';
127 $deletegroup_disabled = '';
128 } else {
129 $deletegroup_disabled = $disabled;
130 $showeditgroupsettingsform_disabled = $disabled;
131 $showaddmembersform_disabled = $disabled;
134 print_heading(format_string($course->shortname) .' '.$strgroups, 'center', 3);
135 echo '<form id="groupeditform" action="index.php" method="post">'."\n";
136 echo '<div>'."\n";
137 echo '<input type="hidden" name="id" value="' . $courseid . '" />'."\n";
139 echo '<table cellpadding="6" class="generaltable generalbox groupmanagementtable boxaligncenter" summary="">'."\n";
140 echo '<tr>'."\n";
143 echo "<td>\n";
144 // NO GROUPINGS YET!
145 echo '<p><label for="groups"><span id="groupslabel">'.get_string('groups').':</span><span id="thegrouping">&nbsp;</span></label></p>'."\n";
147 if (ajaxenabled()) {
148 $onchange = 'membersCombo.refreshMembers(this.options[this.selectedIndex].value);';
149 } else {
150 $onchange = '';
154 echo '<select name="group" id="groups" size="15" class="select" onchange="'.$onchange.'"'."\n";
155 echo ' onclick="window.status=this.options[this.selectedIndex].title;" onmouseout="window.status=\'\';">'."\n";
157 $groups = groups_get_all_groups($courseid);
159 $sel_groupid = 0;
161 if ($groups) {
162 // Print out the HTML
163 foreach ($groups as $group) {
164 $select = '';
165 if ($groupid == $group->id) {
166 $select = ' selected="selected"';
167 $sel_groupid = $group->id;
169 $usercount = (int)count_records('groups_members', 'groupid', $group->id);
170 $groupname = format_string($group->name).' ('.$usercount.')';
172 echo "<option value=\"{$group->id}\"$select title=\"$groupname\">$groupname</option>\n";
174 } else {
175 // Print an empty option to avoid the XHTML error of having an empty select element
176 echo '<option>&nbsp;</option>';
179 echo '</select>'."\n";
180 echo '<p><input type="submit" name="act_updatemembers" id="updatemembers" value="'
181 . get_string('showmembersforgroup', 'group') . '" /></p>'."\n";
182 echo '<p><input type="submit" '. $showeditgroupsettingsform_disabled . ' name="act_showgroupsettingsform" id="showeditgroupsettingsform" value="'
183 . get_string('editgroupsettings', 'group') . '" /></p>'."\n";
184 echo '<p><input type="submit" '. $deletegroup_disabled . ' name="act_deletegroup" onclick="onDeleteGroup()" id="deletegroup" value="'
185 . get_string('deleteselectedgroup', 'group') . '" /></p>'."\n";
187 echo '<p><input type="submit" name="act_showcreateorphangroupform" id="showcreateorphangroupform" value="'
188 . get_string('creategroup', 'group') . '" /></p>'."\n";
190 echo '<p><input type="submit" name="act_showautocreategroupsform" id="showautocreategroupsform" value="'
191 . get_string('autocreategroups', 'group') . '" /></p>'."\n";
193 echo '</td>'."\n";
194 echo '<td>'."\n";
195 echo '<p><label for="members"><span id="memberslabel">'.get_string('membersofselectedgroup', 'group').' </span><span id="thegroup">&nbsp;</span></label></p>'."\n";
196 //NOTE: the SELECT was, multiple="multiple" name="user[]" - not used and breaks onclick.
197 echo '<select name="user" id="members" size="15" class="select"'."\n";
198 echo ' onclick="window.status=this.options[this.selectedIndex].title;" onmouseout="window.status=\'\';">'."\n";
200 $member_names = array();
202 $atleastonemember = false;
203 if ($sel_groupid) {
205 if ($groupmemberroles = groups_get_members_by_role($groupid,$courseid,'u.id,u.firstname,u.lastname')) {
206 foreach($groupmemberroles as $roleid=>$roledata) {
207 echo '<optgroup label="'.htmlspecialchars($roledata->name).'">';
208 foreach($roledata->users as $member) {
209 echo '<option value="'.$member->id.'">'.fullname($member, true).'</option>';
210 $atleastonemember = true;
212 echo '</optgroup>';
217 if (!$atleastonemember) {
218 // Print an empty option to avoid the XHTML error of having an empty select element
219 echo '<option>&nbsp;</option>';
222 echo '</select>'."\n";
224 echo '<p><input type="submit" ' . $showaddmembersform_disabled . ' name="act_showaddmembersform" '
225 . 'id="showaddmembersform" value="' . get_string('adduserstogroup', 'group'). '" /></p>'."\n";
226 echo '</td>'."\n";
227 echo '</tr>'."\n";
228 echo '</table>'."\n";
230 //<input type="hidden" name="rand" value="om" />
231 echo '</div>'."\n";
232 echo '</form>'."\n";
234 if (ajaxenabled()) {
235 echo '<script type="text/javascript">'."\n";
236 echo '//<![CDATA['."\n";
237 echo 'var groupsCombo = new UpdatableGroupsCombo("'.$CFG->wwwroot.'", '.$course->id.');'."\n";
238 echo 'var membersCombo = new UpdatableMembersCombo("'.$CFG->wwwroot.'", '.$course->id.');'."\n";
239 echo '//]]>'."\n";
240 echo '</script>'."\n";
243 print_footer($course);
246 * Returns the first button action with the given prefix, taken from
247 * POST or GET, otherwise returns false.
248 * See /lib/moodlelib.php function optional_param.
249 * @param $prefix 'act_' as in 'action'.
250 * @return string The action without the prefix, or false if no action found.
252 function groups_param_action($prefix = 'act_') {
253 $action = false;
254 //($_SERVER['QUERY_STRING'] && preg_match("/$prefix(.+?)=(.+)/", $_SERVER['QUERY_STRING'], $matches)) { //b_(.*?)[&;]{0,1}/
256 if ($_POST) {
257 $form_vars = $_POST;
259 elseif ($_GET) {
260 $form_vars = $_GET;
262 if ($form_vars) {
263 foreach ($form_vars as $key => $value) {
264 if (preg_match("/$prefix(.+)/", $key, $matches)) {
265 $action = $matches[1];
266 break;
270 if ($action && !preg_match('/^\w+$/', $action)) {
271 $action = false;
272 error('Action had wrong type.');
274 ///if (debugging()) echo 'Debug: '.$action;
275 return $action;