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