The very last save button is tabindexed, too. Forgot to include it in the last commit...
[moodle.git] / group / overview.php
CommitLineData
acf000b0 1<?php // $Id$
2/**
3 * Print an overview of groupings & group membership
4 *
5 * @author Matt Clarkson mattc@catalyst.net.nz
6 * @version 0.0.1
7 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
8 * @package groups
9 */
f16fa0a3 10
acf000b0 11require_once('../config.php');
12
f16fa0a3 13$courseid = required_param('id', PARAM_INT);
14$groupid = optional_param('group', 0, PARAM_INT);
15$groupingid = optional_param('grouping', 0, PARAM_INT);
acf000b0 16
17$returnurl = $CFG->wwwroot.'/group/index.php?id='.$courseid;
f16fa0a3 18$rooturl = $CFG->wwwroot.'/group/overview.php?id='.$courseid;
acf000b0 19
20if (!$course = get_record('course', 'id',$courseid)) {
5a2a5331 21 print_error('invalidcourse');
acf000b0 22}
23
24// Make sure that the user has permissions to manage groups.
25require_login($course);
26
27$context = get_context_instance(CONTEXT_COURSE, $courseid);
28require_capability('moodle/course:managegroups', $context);
29
f16fa0a3 30$strgroups = get_string('groups');
31$strparticipants = get_string('participants');
32$stroverview = get_string('overview', 'group');
33$strgrouping = get_string('grouping', 'group');
34$strgroup = get_string('group', 'group');
35$strnotingrouping = get_string('notingrouping', 'group');
36$strfiltergroups = get_string('filtergroups', 'group');
37$strnogroups = get_string('nogroups', 'group');
38$strdescription = get_string('description');
39
40// Get all groupings
41if (empty($CFG->enablegroupings)) {
42 $groupings = array();
43 $members = array(-1 => array()); //groups not in a grouping
44 $groupingid = 0;
45} else {
f33e1ed4 46 if (!$groupings = $DB->get_records('groupings', array('courseid'=>$courseid), 'name')) {
f16fa0a3 47 $groupings = array();
48 }
49 $members = array();
50 foreach ($groupings as $grouping) {
51 $members[$grouping->id] = array();
52 }
53 $members[-1] = array(); //groups not in a grouping
54}
55
56// Get all groups
f33e1ed4 57if (!$groups = $DB->get_records('groups', array('courseid'=>$courseid), 'name')) {
f16fa0a3 58 $groups = array();
59}
acf000b0 60
f33e1ed4 61$params = array($courseid);
62if ($groupid) {
63 $groupwhere = "AND g.id = ?";
64 $params[] = $groupid;
65} else {
66 $groupwhere = "";
67}
68
f16fa0a3 69if (empty($CFG->enablegroupings)) {
f16fa0a3 70 $sql = "SELECT g.id AS groupid, NULL AS groupingid, u.id AS userid, u.firstname, u.lastname, u.idnumber, u.username
f33e1ed4 71 FROM {groups} g
72 LEFT JOIN {groups_members} gm ON g.id = gm.groupid
73 LEFT JOIN {user} u ON gm.userid = u.id
74 WHERE g.courseid = ? $groupwhere
f16fa0a3 75 ORDER BY g.name, u.lastname, u.firstname";
76} else {
f33e1ed4 77 if ($groupingid) {
78 $groupingwhere = "AND gg.groupingid = ";
79 $params[] = $groupingid;
80 } else {
81 $groupingwhere = "";
82 }
f16fa0a3 83 $sql = "SELECT g.id AS groupid, gg.groupingid, u.id AS userid, u.firstname, u.lastname, u.idnumber, u.username
f33e1ed4 84 FROM {groups} g
85 LEFT JOIN {groupings_groups} gg ON g.id = gg.groupid
86 LEFT JOIN {groups_members} gm ON g.id = gm.groupid
87 LEFT JOIN {user} u ON gm.userid = u.id
88 WHERE g.courseid = ? $groupwhere $groupingwhere
f16fa0a3 89 ORDER BY g.name, u.lastname, u.firstname";
90}
91
f33e1ed4 92if ($rs = $DB->get_recordset_sql($sql, $params)) {
93 foreach ($rs as $row) {
f16fa0a3 94 $user = new object();
95 $user->id = $row->userid;
96 $user->firstname = $row->firstname;
97 $user->lastname = $row->lastname;
98 $user->username = $row->username;
99 $user->idnumber = $row->idnumber;
100 if (!$row->groupingid) {
101 $row->groupingid = -1;
102 }
103 if (!array_key_exists($row->groupid, $members[$row->groupingid])) {
104 $members[$row->groupingid][$row->groupid] = array();
105 }
106 $members[$row->groupingid][$row->groupid][] = $user;
107 }
108 rs_close($rs);
109}
acf000b0 110
acf000b0 111
112// Print the page and form
113$navlinks = array(array('name'=>$strparticipants, 'link'=>$CFG->wwwroot.'/user/index.php?id='.$courseid, 'type'=>'misc'),
114 array('name'=>$strgroups, 'link'=>'', 'type'=>'misc'));
115$navigation = build_navigation($navlinks);
116
117/// Print header
118print_header_simple($strgroups, ': '.$strgroups, $navigation, '', '', true, '', navmenu($course));
f16fa0a3 119// Add tabs
120$currenttab = 'overview';
121require('tabs.php');
acf000b0 122
f16fa0a3 123/// Print overview
124print_heading(format_string($course->shortname) .' '.$stroverview, 'center', 3);
acf000b0 125
f16fa0a3 126echo $strfiltergroups;
acf000b0 127
acf000b0 128if (!empty($CFG->enablegroupings)) {
f16fa0a3 129 $options = array();
130 $options[0] = get_string('all');
131 foreach ($groupings as $grouping) {
132 $options[$grouping->id] = strip_tags(format_string($grouping->name));
acf000b0 133 }
f16fa0a3 134 popup_form($rooturl.'&amp;group='.$groupid.'&amp;grouping=', $options, 'selectgrouping', $groupingid, '', '', '', false, 'self', $strgrouping);
acf000b0 135}
136
f16fa0a3 137$options = array();
138$options[0] = get_string('all');
139foreach ($groups as $group) {
140 $options[$group->id] = strip_tags(format_string($group->name));
acf000b0 141}
f16fa0a3 142popup_form($rooturl.'&amp;grouping='.$groupingid.'&amp;group=', $options, 'selectgroup', $groupid, '', '', '', false, 'self', $strgroup);
acf000b0 143
f16fa0a3 144
145/// Print table
146$printed = false;
147foreach ($members as $gpgid=>$groupdata) {
148 if ($groupingid and $groupingid != $gpgid) {
149 continue; // do not show
acf000b0 150 }
f16fa0a3 151 $table = new object();
152 $table->head = array(get_string('groupscount', 'group', count($groupdata)), get_string('groupmembers', 'group'), get_string('usercount', 'group'));
153 $table->size = array('20%', '70%', '10%');
154 $table->align = array('left', 'left', 'center');
155 $table->width = '90%';
156 $table->data = array();
157 foreach ($groupdata as $gpid=>$users) {
158 if ($groupid and $groupid != $gpid) {
159 continue;
acf000b0 160 }
f16fa0a3 161 $line = array();
162 $name = format_string($groups[$gpid]->name);
3980c306 163 $jsdescription = addslashes_js(trim(format_text($groups[$gpid]->description)));
f16fa0a3 164 if (empty($jsdescription)) {
165 $line[] = $name;
166 } else {
167 $jsstrdescription = addslashes_js($strdescription);
168 $overlib = "return overlib('$jsdescription', BORDER, 0, FGCLASS, 'description', "
169 ."CAPTIONFONTCLASS, 'caption', CAPTION, '$jsstrdescription');";
170 $line[] = '<span onmouseover="'.s($overlib).'" onmouseout="return nd();">'.$name.'</span>';
171 }
172 $fullnames = array();
173 foreach ($users as $user) {
174 $fullnames[] = '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$user->id.'&amp;course='.$course->id.'">'.fullname($user, true).'</a>';
175 }
176 $line[] = implode(', ', $fullnames);
177 $line[] = count($users);
178 $table->data[] = $line;
acf000b0 179 }
f16fa0a3 180 if ($groupid and empty($table->data)) {
181 continue;
acf000b0 182 }
f16fa0a3 183 if (!empty($CFG->enablegroupings)) {
184 if ($gpgid < 0) {
185 print_heading($strnotingrouping, '', 3);
186 } else {
187 print_heading(format_string($groupings[$gpgid]->name), '', 3);
3980c306 188 print_box(format_text($groupings[$gpgid]->description), 'generalbox boxwidthnarrow boxaligncenter');
acf000b0 189 }
190 }
f16fa0a3 191 print_table($table, false);
192 $printed = true;
acf000b0 193}
194
195print_footer($course);
196?>