"MDL-15251, see tracker"
[moodle-linuxchix.git] / group / overview.php
blob737f1a405c46b8e3c29b20356cd1a75980cbf236
1 <?php // $Id$
2 /**
3 * Print an overview of groupings & group membership
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 */
11 require_once('../config.php');
13 $courseid = required_param('id', PARAM_INT);
14 $groupid = optional_param('group', 0, PARAM_INT);
15 $groupingid = optional_param('grouping', 0, PARAM_INT);
17 $returnurl = $CFG->wwwroot.'/group/index.php?id='.$courseid;
18 $rooturl = $CFG->wwwroot.'/group/overview.php?id='.$courseid;
20 if (!$course = get_record('course', 'id',$courseid)) {
21 error('invalidcourse');
24 // Make sure that the user has permissions to manage groups.
25 require_login($course);
27 $context = get_context_instance(CONTEXT_COURSE, $courseid);
28 require_capability('moodle/course:managegroups', $context);
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');
40 // Get all groupings
41 if (empty($CFG->enablegroupings)) {
42 $groupings = array();
43 $members = array(-1 => array()); //groups not in a grouping
44 $groupingid = 0;
45 } else {
46 if (!$groupings = get_records('groupings', 'courseid', $courseid, 'name')) {
47 $groupings = array();
49 $members = array();
50 foreach ($groupings as $grouping) {
51 $members[$grouping->id] = array();
53 $members[-1] = array(); //groups not in a grouping
56 // Get all groups
57 if (!$groups = get_records('groups', 'courseid', $courseid, 'name')) {
58 $groups = array();
61 if (empty($CFG->enablegroupings)) {
62 $groupwhere = $groupid ? "AND g.id = $groupid" : "";
63 $sql = "SELECT g.id AS groupid, NULL AS groupingid, u.id AS userid, u.firstname, u.lastname, u.idnumber, u.username
64 FROM {$CFG->prefix}groups g
65 LEFT JOIN {$CFG->prefix}groups_members gm ON g.id = gm.groupid
66 LEFT JOIN {$CFG->prefix}user u ON gm.userid = u.id
67 WHERE g.courseid = {$course->id} $groupwhere
68 ORDER BY g.name, u.lastname, u.firstname";
69 } else {
70 $groupingwhere = $groupingid ? "AND gg.groupingid = $groupingid" : "";
71 $groupwhere = $groupid ? "AND g.id = $groupid" : "";
72 $sql = "SELECT g.id AS groupid, gg.groupingid, u.id AS userid, u.firstname, u.lastname, u.idnumber, u.username
73 FROM {$CFG->prefix}groups g
74 LEFT JOIN {$CFG->prefix}groupings_groups gg ON g.id = gg.groupid
75 LEFT JOIN {$CFG->prefix}groups_members gm ON g.id = gm.groupid
76 LEFT JOIN {$CFG->prefix}user u ON gm.userid = u.id
77 WHERE g.courseid = {$course->id} $groupingwhere $groupwhere
78 ORDER BY g.name, u.lastname, u.firstname";
81 if ($rs = get_recordset_sql($sql)) {
82 while ($row = rs_fetch_next_record($rs)) {
83 $user = new object();
84 $user->id = $row->userid;
85 $user->firstname = $row->firstname;
86 $user->lastname = $row->lastname;
87 $user->username = $row->username;
88 $user->idnumber = $row->idnumber;
89 if (!$row->groupingid) {
90 $row->groupingid = -1;
92 if (!array_key_exists($row->groupid, $members[$row->groupingid])) {
93 $members[$row->groupingid][$row->groupid] = array();
95 $members[$row->groupingid][$row->groupid][] = $user;
97 rs_close($rs);
101 // Print the page and form
102 $navlinks = array(array('name'=>$strparticipants, 'link'=>$CFG->wwwroot.'/user/index.php?id='.$courseid, 'type'=>'misc'),
103 array('name'=>$strgroups, 'link'=>'', 'type'=>'misc'));
104 $navigation = build_navigation($navlinks);
106 /// Print header
107 print_header_simple($strgroups, ': '.$strgroups, $navigation, '', '', true, '', navmenu($course));
108 // Add tabs
109 $currenttab = 'overview';
110 require('tabs.php');
112 /// Print overview
113 print_heading(format_string($course->shortname) .' '.$stroverview, 'center', 3);
115 echo $strfiltergroups;
117 if (!empty($CFG->enablegroupings)) {
118 $options = array();
119 $options[0] = get_string('all');
120 foreach ($groupings as $grouping) {
121 $options[$grouping->id] = strip_tags(format_string($grouping->name));
123 popup_form($rooturl.'&amp;group='.$groupid.'&amp;grouping=', $options, 'selectgrouping', $groupingid, '', '', '', false, 'self', $strgrouping);
126 $options = array();
127 $options[0] = get_string('all');
128 foreach ($groups as $group) {
129 $options[$group->id] = strip_tags(format_string($group->name));
131 popup_form($rooturl.'&amp;grouping='.$groupingid.'&amp;group=', $options, 'selectgroup', $groupid, '', '', '', false, 'self', $strgroup);
134 /// Print table
135 $printed = false;
136 foreach ($members as $gpgid=>$groupdata) {
137 if ($groupingid and $groupingid != $gpgid) {
138 continue; // do not show
140 $table = new object();
141 $table->head = array(get_string('groupscount', 'group', count($groupdata)), get_string('groupmembers', 'group'), get_string('usercount', 'group'));
142 $table->size = array('20%', '70%', '10%');
143 $table->align = array('left', 'left', 'center');
144 $table->width = '90%';
145 $table->data = array();
146 foreach ($groupdata as $gpid=>$users) {
147 if ($groupid and $groupid != $gpid) {
148 continue;
150 $line = array();
151 $name = format_string($groups[$gpid]->name);
152 $jsdescription = addslashes_js(trim(format_text($groups[$gpid]->description)));
153 if (empty($jsdescription)) {
154 $line[] = $name;
155 } else {
156 $jsstrdescription = addslashes_js($strdescription);
157 $overlib = "return overlib('$jsdescription', BORDER, 0, FGCLASS, 'description', "
158 ."CAPTIONFONTCLASS, 'caption', CAPTION, '$jsstrdescription');";
159 $line[] = '<span onmouseover="'.s($overlib).'" onmouseout="return nd();">'.$name.'</span>';
161 $fullnames = array();
162 foreach ($users as $user) {
163 $fullnames[] = '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$user->id.'&amp;course='.$course->id.'">'.fullname($user, true).'</a>';
165 $line[] = implode(', ', $fullnames);
166 $line[] = count($users);
167 $table->data[] = $line;
169 if ($groupid and empty($table->data)) {
170 continue;
172 if (!empty($CFG->enablegroupings)) {
173 if ($gpgid < 0) {
174 print_heading($strnotingrouping, '', 3);
175 } else {
176 print_heading(format_string($groupings[$gpgid]->name), '', 3);
177 print_box(format_text($groupings[$gpgid]->description), 'generalbox boxwidthnarrow boxaligncenter');
180 print_table($table, false);
181 $printed = true;
184 print_footer($course);