Annotation of loncom/interface/grouproster.pm, revision 1.7
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: #
1.5 bisitz 3: # $Id
4: #
1.1 raeburn 5: # Copyright Michigan State University Board of Trustees
6: #
7: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
8: #
9: # LON-CAPA is free software; you can redistribute it and/or modify
10: # it under the terms of the GNU General Public License as published by
11: # the Free Software Foundation; either version 2 of the License, or
12: # (at your option) any later version.
13: #
14: # LON-CAPA is distributed in the hope that it will be useful,
15: # but WITHOUT ANY WARRANTY; without even the implied warranty of
16: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17: # GNU General Public License for more details.
18: #
19: # You should have received a copy of the GNU General Public License
20: # along with LON-CAPA; if not, write to the Free Software
21: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22: #
23: # /home/httpd/html/adm/gpl.txt
24: #
25: # http://www.lon-capa.org/
26: #
27:
28: package Apache::grouproster;
29:
30: use strict;
31: use Apache::lonnet;
32: use Apache::loncommon;
33: use Apache::lonhtmlcommon;
34: use Apache::lonlocal;
35: use Apache::longroup;
1.2 raeburn 36: use LONCAPA;
1.1 raeburn 37: use Apache::Constants qw(:common :http);
38: use lib '/home/httpd/lib/perl/';
39:
40: sub handler {
41: my ($r) = @_;
42: &Apache::loncommon::content_type($r,'text/html');
43: $r->send_http_header;
44:
45: if ($r->header_only) {
46: return OK;
47: }
48:
49: # Needs to be in a course
50: if (! ($env{'request.course.fn'})) {
51: # Not in a course
52: $env{'user.error.msg'}=
53: "/adm/coursegroups:mdg:0:0:Cannot edit or view course groups";
54: return HTTP_NOT_ACCEPTABLE;
55: }
56:
1.4 raeburn 57: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
58: ['group','ref','status']);
1.1 raeburn 59:
60: my $gpterm = &Apache::loncommon::group_term();
61: my $ucgpterm = $gpterm;
62: $ucgpterm =~ s/^(\w)/uc($1)/e;
63: my $crstype = &Apache::loncommon::course_type();
64: my $group;
1.4 raeburn 65: my %curr_groups;
1.1 raeburn 66:
1.4 raeburn 67: # Validating group input.
68: my $badinput;
1.1 raeburn 69: if ((!defined($env{'form.group'})) || ($env{'form.group'} eq '')) {
1.5 bisitz 70: $r->print(&mt('No group name provided.').'<br />');
1.4 raeburn 71: $badinput = 1;
1.1 raeburn 72: } else {
73: $group = $env{'form.group'};
74: $group =~ s/\W//g;
75: }
1.4 raeburn 76: if (!$badinput && $group eq '') {
1.5 bisitz 77: $r->print(&mt('Invalid group name provided.').'<br />');
1.4 raeburn 78: $badinput = 1;
1.1 raeburn 79: }
80:
81: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
82: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
83:
84: if ($cdom eq '' || $cnum eq '') {
1.5 bisitz 85: $r->print(&mt('Invalid [_1]',$crstype).'<br />');
1.4 raeburn 86: $badinput = 1;
1.1 raeburn 87: }
88:
1.4 raeburn 89: if (!$badinput) {
90: %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
91: if (!defined($curr_groups{$group})) {
92: $r->print(&mt('"[_1]" is not the name of a valid group in this [_2].',
93: $group,lc($crstype)));
94: $badinput = 1;
95: }
96: }
97: if ($badinput) {
1.2 raeburn 98: return OK;
1.4 raeburn 99: }
1.1 raeburn 100:
101: &Apache::lonhtmlcommon::clear_breadcrumbs();
102:
103: my $can_view = &Apache::lonnet::allowed('vgm',$env{'request.course.id'}.
104: '/'.$group);
105: my $view_details = &Apache::lonnet::allowed('vmd',$env{'request.course.id'}.'/'.$group);
106:
1.3 raeburn 107: my $viewgrps = &Apache::lonnet::allowed('vcg',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''));
1.1 raeburn 108: my $editgrps = &Apache::lonnet::allowed('mdg',$env{'request.course.id'});
109:
110: if ((!$can_view) && (!$view_details) && (!$viewgrps) && (!$editgrps)) {
1.5 bisitz 111: $r->print(&mt('You do not have privileges to view the membership roster in this '.$gpterm.'.'));
1.1 raeburn 112: return OK;
113: }
1.2 raeburn 114: my %content = &Apache::longroup::get_group_settings($curr_groups{$group});
1.1 raeburn 115: my $description = &unescape($content{'description'});
116: $r->print(&roster_header($cdom,$cnum,$group,$description,$gpterm,$ucgpterm));
117:
118: my $available;
119: foreach my $tool (sort(keys(%{$content{'functions'}}))) {
120: if ($content{functions}{$tool} eq 'on') {
121: push(@{$available},$tool);
122: }
123: }
124:
125: &roster_table($r,$cdom,$cnum,$group,$can_view,$view_details,$viewgrps,
126: $editgrps,$available,$gpterm,$ucgpterm);
127:
128: $r->print(&Apache::loncommon::end_page());
129: return OK;
130: }
131:
132: sub roster_header {
133: my ($cdom,$cnum,$group,$description,$gpterm,$ucgpterm) = @_;
1.3 raeburn 134: my $refarg;
1.4 raeburn 135: if (exists($env{'form.ref'}) && $env{'form.ref'} ne 'popup') {
1.3 raeburn 136: $refarg = 'ref='.$env{'form.ref'};
137: &Apache::lonhtmlcommon::add_breadcrumb
138: ({href=>"/adm/coursegroups",
139: text=>"Groups",
140: title=>"View course groups"});
141: }
1.4 raeburn 142: my $args;
143: if ($env{'form.ref'} eq 'popup') {
144: $args = {
145: 'no_nav_bar' => 1,
146: 'no_inline_link' => 1,
147: };
148: }
1.1 raeburn 149: my $jscript = qq|
150: function changeSort(caller) {
151: document.grouproster.sortby.value = caller;
152: document.grouproster.submit();
153: }\n|;
1.4 raeburn 154: my $itemtitle = &mt('Group membership status - [_1]',$description);
1.1 raeburn 155: my $output =
1.4 raeburn 156: &Apache::loncommon::start_page('Group Membership',
1.1 raeburn 157: '<script type="text/javascript">'.
1.4 raeburn 158: $jscript.'</script>',$args);
159: if ($env{'form.ref'} eq 'popup') {
160: $output .= '<h3>'.&mt('Group membership status - [_1]',$description).
161: '</h3>';
162: } else {
163: &Apache::lonhtmlcommon::add_breadcrumb
164: ({href=>"/adm/$cdom/$cnum/$group/smppg?$refarg",
165: text=>"$ucgpterm: $description",
166: title=>"Go to group's home page"},
167: {href=>'/adm/grouproster?group='.$group.'&'.$refarg,
1.6 schafran 168: text=>"Membership Roster",
1.4 raeburn 169: title=>"Display group membership"},);
1.5 bisitz 170: $output .= &Apache::lonhtmlcommon::breadcrumbs(&mt($gpterm.' membership status - [_1]',$description));
1.4 raeburn 171: }
1.1 raeburn 172: return $output;
173: }
174:
175: sub roster_table {
176: my ($r,$cdom,$cnum,$group,$can_view,$view_details,$viewgrps,$editgrps,
177: $available,$gpterm,$ucgpterm) = @_;
178:
179: my $fixedprivs = &Apache::longroup::get_fixed_privs();
180:
1.3 raeburn 181: my ($memberinfo,$numitems,$hastools,$addtools) =
1.1 raeburn 182: &Apache::longroup::group_memberlist($cdom,$cnum,$group,$fixedprivs,
183: $available);
184: my (%tooltype,$toolprivs);
185:
186: if ($hastools) {
187: $toolprivs = &Apache::longroup::get_tool_privs($gpterm);
188: foreach my $tool (sort(keys(%{$toolprivs}))) {
189: foreach my $priv (sort(keys(%{$$toolprivs{$tool}}))) {
190: $tooltype{$priv} = $tool;
191: }
192: }
193: }
194:
195: my %lt = &Apache::lonlocal::texthash(
196: 'name' => 'Name',
197: 'usnm' => 'Username',
198: 'doma' => 'Domain',
199: 'stid' => 'ID',
200: 'stda' => 'Start Date',
201: 'enda' => 'End Date',
202: 'func' => 'Functionality',
203: 'priv' => 'Privileges',
204: 'all' => 'Any Membership status',
205: 'active' => 'Active Member',
206: 'previous' => 'Former Member',
207: 'future' => 'Future Member',
208: 'updi' => 'Update Display',
209: );
210: my $status = $env{'form.status'};
211: if (!defined($status)) {
212: $status = 'active';
213: }
214: if (($viewgrps) || ($editgrps) ||
215: (&Apache::lonnet::allowed('vmd',$env{'request.course.id'}.'/'.$group))) {
216: if (keys(%{$memberinfo}) == 0) {
1.5 bisitz 217: $r->print(&mt('There are no membership data to display for this '.$gpterm.'.'));
1.1 raeburn 218: return;
219: }
220: $r->print('<br /><form name="rosterstatus" method="post" action="/adm/grouproster">'.&mt('Membership status: ').'<select name="status">');
221: foreach my $type ('active','previous','future','all') {
222: $r->print('<option value="'.$type.'" ');
223: if ($status eq $type) {
224: $r->print('selected="selected"');
225: }
226: $r->print('>'.$lt{$type}.'</option>');
227: }
228: $r->print('</select>'."\n".
229: '<input type="submit" name="statusbutton" value="'.
230: $lt{'updi'}.'"><input type="hidden" name="sortby" value="'.
231: $env{'form.sortby'}.'"/>'.
1.3 raeburn 232: '<input type="hidden" name="group" value="'.$group.'"/>');
233: if (exists($env{'form.ref'})) {
234: $r->print('<input type="hidden" name="ref" value="'.$env{'form.ref'}.
235: '" />');
236: }
1.4 raeburn 237: $r->print('</form><br />');
1.1 raeburn 238:
239: }
1.4 raeburn 240: $r->print('<br />');
1.1 raeburn 241: if (ref($numitems) eq 'HASH') {
242: foreach my $key (keys(%{$numitems})) {
243: if ($status eq $key && !$$numitems{$key}) {
1.5 bisitz 244: $r->print(&mt('There are no '.$gpterm.'s to display in this [_1].',
245: lc($lt{$key})));
1.1 raeburn 246: return;
247: }
248: }
249: }
250: $r->print('
251: <form name="grouproster" action="/adm/grouproster" method="post">
252: <input type="hidden" name="group" value="'.$group.'" />
253: <input type="hidden" name="sortby" value="'.$env{'form.sortby'}.'" />
1.4 raeburn 254: <input type="hidden" name="status" value="'.$status.'" />
1.1 raeburn 255: ');
1.3 raeburn 256: if (exists($env{'form.ref'})) {
257: $r->print('<input type="hidden" name="ref" value="'.$env{'form.ref'}.
258: '" />');
259: }
1.1 raeburn 260: my %Sortby = ();
261: my $usercount = 0;
262: foreach my $user (sort(keys(%{$memberinfo}))) {
263: if ($env{'form.sortby'} eq 'fullname') {
264: push(@{$Sortby{$$memberinfo{$user}{fullname}}},$user);
265: } elsif ($env{'form.sortby'} eq 'username') {
266: push(@{$Sortby{$$memberinfo{$user}{uname}}},$user);
267: } elsif ($env{'form.sortby'} eq 'domain') {
268: push(@{$Sortby{$$memberinfo{$user}{udom}}},$user);
269: } elsif ($env{'form.sortby'} eq 'id') {
270: push(@{$Sortby{$$memberinfo{$user}{id}}},$user);
271: } else {
272: push(@{$Sortby{$$memberinfo{$user}{fullname}}},$user);
273: }
274: }
275: $r->print(&Apache::loncommon::start_data_table());
276: $r->print(&members_table_header_row(\%lt,$viewgrps,$editgrps,$view_details,
277: $hastools));
278: foreach my $key (sort(keys(%Sortby))) {
279: foreach my $user (@{$Sortby{$key}}) {
280: if (($status eq 'all') ||
281: ($status eq $$memberinfo{$user}{status})) {
282: $r->print(&members_table_row($viewgrps,$editgrps,$view_details,
283: $hastools,\%tooltype,$toolprivs,$$memberinfo{$user}));
284: }
285: }
286: }
287: $r->print(&Apache::loncommon::end_data_table());
288: $r->print('</form>');
289: return;
290: }
291:
292: sub members_table_header_row {
293: my ($lt,$viewgrps,$editgrps,$view_details,$hastools) = @_;
294: my $output = &Apache::loncommon::start_data_table_header_row();
295: $output .= "<th><a href=\"javascript:changeSort('fullname')\">".
296: "$$lt{'name'}</a></th>";
297: if ($viewgrps || $editgrps || $view_details ) {
298: $output .= "<th><a href=\"javascript:changeSort('username')\">$$lt{'usnm'}</a></th>";
299: $output .= "<th><a href=\"javascript:changeSort('domain')\">$$lt{'doma'}</a></th>";
300: }
301: if ($viewgrps || $editgrps) {
302: $output .= "<th><a href=\"javascript:changeSort('id')\">$$lt{'stid'}</a></th>";
303: }
304: if ($viewgrps || $editgrps || $view_details ) {
305: $output .= "<th><a href=\"javascript:changeSort('start')\">$$lt{'stda'}</a></th>";
306: $output .= "<th><a href=\"javascript:changeSort('end')\">$$lt{'enda'}</a></th>";
307: if ($hastools) {
308: if ($viewgrps || $editgrps) {
309: $output .= '<th><b>'.$$lt{'priv'}.'</b></th>';
310: } elsif ($view_details) {
311: $output .= '<th><b>'.$$lt{'func'}.'</b></th>';
312: }
313: }
314: }
315: $output .= &Apache::loncommon::end_data_table_header_row();
316: return $output;
317: }
318:
319: sub members_table_row {
320: my ($viewgrps,$editgrps,$view_details,$hastools,$tooltype,$toolprivs,
321: $userinfo) = @_;
322: my $output = &Apache::loncommon::start_data_table_row();
323: $output .= '<td>'.&Apache::loncommon::aboutmewrapper($$userinfo{'fullname'},
324: $$userinfo{'uname'},$$userinfo{'udom'} ).
325: '</td>';
326: if ($viewgrps || $editgrps || $view_details ) {
327: $output .= '<td>'.$$userinfo{'uname'}.'</td>';
328: $output .= '<td>'.$$userinfo{'udom'}.'</td>';
329: }
330: if ($viewgrps || $editgrps) {
331: $output .= '<td>'.$$userinfo{'id'}.'</td>';
332: }
333: if ($viewgrps || $editgrps || $view_details) {
334: $output .= '<td>'.$$userinfo{'start'}.'</td>';
335: $output .= '<td>'.$$userinfo{'end'}.'</td>';
336: }
337: if ($hastools) {
338: if ($viewgrps || $editgrps) {
339: my $curr_tool;
340: my $privlist;
341: foreach my $priv (@{$$userinfo{'privs'}}) {
1.4 raeburn 342: if (defined($$tooltype{$priv})) {
343: if ($curr_tool ne $$tooltype{$priv}) {
344: $curr_tool = $$tooltype{$priv};
345: $privlist .= '<b>'.$curr_tool.'</b>: ';
346: }
347: $privlist .= $$toolprivs{$curr_tool}{$priv}.', ';
1.1 raeburn 348: }
349: }
350: $privlist =~ s/, $//;
351: $output .= '<td>'.$privlist.'</td>';
352: } elsif ($view_details) {
1.7 ! bisitz 353: $output .= '<td><span class="LC_nobreak">'.join(' ',
! 354: @{$$userinfo{'currtools'}}).'</span></td>';
1.1 raeburn 355: }
356: }
357: $output .= &Apache::loncommon::end_data_table_row();
358: return $output;
359: }
360:
361: 1;
362:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>