Annotation of loncom/interface/grouproster.pm, revision 1.1
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;
! 34: use Apache::Constants qw(:common :http);
! 35: use lib '/home/httpd/lib/perl/';
! 36:
! 37: sub handler {
! 38: my ($r) = @_;
! 39: &Apache::loncommon::content_type($r,'text/html');
! 40: $r->send_http_header;
! 41:
! 42: if ($r->header_only) {
! 43: return OK;
! 44: }
! 45:
! 46: # Needs to be in a course
! 47: if (! ($env{'request.course.fn'})) {
! 48: # Not in a course
! 49: $env{'user.error.msg'}=
! 50: "/adm/coursegroups:mdg:0:0:Cannot edit or view course groups";
! 51: return HTTP_NOT_ACCEPTABLE;
! 52: }
! 53:
! 54: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['group']);
! 55:
! 56: my $gpterm = &Apache::loncommon::group_term();
! 57: my $ucgpterm = $gpterm;
! 58: $ucgpterm =~ s/^(\w)/uc($1)/e;
! 59: my $crstype = &Apache::loncommon::course_type();
! 60: my $group;
! 61:
! 62: if ((!defined($env{'form.group'})) || ($env{'form.group'} eq '')) {
! 63: $r->print(&mt('No [_1] name provided',$gpterm));
! 64:
! 65: } else {
! 66: $group = $env{'form.group'};
! 67: $group =~ s/\W//g;
! 68: }
! 69: if ($group eq '') {
! 70: $r->print(&mt('Invalid [_1] name provided',$gpterm));
! 71: }
! 72:
! 73: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
! 74: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
! 75:
! 76: if ($cdom eq '' || $cnum eq '') {
! 77: $r->print(&mt('Invalid [_1]',$crstype));
! 78: }
! 79:
! 80: my @coursegroups = split(/:/,$env{'request.course.groups'});
! 81: if ((@coursegroups == 0) || ((@coursegroups > 0) &&
! 82: (!(grep/^\Q$group\E$/,@coursegroups)))) {
! 83: $r->print(&mt('[_1] is not the name of a valid [_2] in this [_3].',
! 84: $group,$gpterm,lc($crstype)));
! 85: }
! 86:
! 87: &Apache::lonhtmlcommon::clear_breadcrumbs();
! 88:
! 89: my $can_view = &Apache::lonnet::allowed('vgm',$env{'request.course.id'}.
! 90: '/'.$group);
! 91: my $view_details = &Apache::lonnet::allowed('vmd',$env{'request.course.id'}.'/'.$group);
! 92:
! 93: my $viewgrps = &Apache::lonnet::allowed('vcg',$env{'request.course.id'});
! 94: my $editgrps = &Apache::lonnet::allowed('mdg',$env{'request.course.id'});
! 95:
! 96: if ((!$can_view) && (!$view_details) && (!$viewgrps) && (!$editgrps)) {
! 97: $r->print(&mt('You do not have privileges to view the membership roster in this [_1]',$gpterm));
! 98: return OK;
! 99: }
! 100: my %coursegroups = &Apache::longroup::coursegroups($cdom,$cnum,$group);
! 101: my %content = &Apache::longroup::get_group_settings($coursegroups{$group});
! 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) = @_;
! 121: my $jscript = qq|
! 122: function changeSort(caller) {
! 123: document.grouproster.sortby.value = caller;
! 124: document.grouproster.submit();
! 125: }\n|;
! 126: my $output =
! 127: &Apache::loncommon::start_page(&mt('[_1] Membership ',$ucgpterm),
! 128: '<script type="text/javascript">'.
! 129: $jscript.'</script>');
! 130: &Apache::lonhtmlcommon::add_breadcrumb
! 131: ({href=>"/adm/$cdom/$cnum/$group/grppg",
! 132: text=>"$ucgpterm: $description",
! 133: title=>"Go to group's home page"},
! 134: {href=>"/adm/grouproster?group=$group",
! 135: text=>"Membership roster",
! 136: title=>"Display group membership"},);
! 137: $output .= &Apache::lonhtmlcommon::breadcrumbs(&mt('[_1] membership status - [_2]',$gpterm,$description));
! 138: return $output;
! 139: }
! 140:
! 141: sub roster_table {
! 142: my ($r,$cdom,$cnum,$group,$can_view,$view_details,$viewgrps,$editgrps,
! 143: $available,$gpterm,$ucgpterm) = @_;
! 144:
! 145: my $fixedprivs = &Apache::longroup::get_fixed_privs();
! 146:
! 147: my ($memberinfo,$hastools,$addtools,$numitems) =
! 148: &Apache::longroup::group_memberlist($cdom,$cnum,$group,$fixedprivs,
! 149: $available);
! 150: my (%tooltype,$toolprivs);
! 151:
! 152: if ($hastools) {
! 153: $toolprivs = &Apache::longroup::get_tool_privs($gpterm);
! 154: foreach my $tool (sort(keys(%{$toolprivs}))) {
! 155: foreach my $priv (sort(keys(%{$$toolprivs{$tool}}))) {
! 156: $tooltype{$priv} = $tool;
! 157: }
! 158: }
! 159: }
! 160:
! 161: my %lt = &Apache::lonlocal::texthash(
! 162: 'name' => 'Name',
! 163: 'usnm' => 'Username',
! 164: 'doma' => 'Domain',
! 165: 'stid' => 'ID',
! 166: 'stda' => 'Start Date',
! 167: 'enda' => 'End Date',
! 168: 'func' => 'Functionality',
! 169: 'priv' => 'Privileges',
! 170: 'all' => 'Any Membership status',
! 171: 'active' => 'Active Member',
! 172: 'previous' => 'Former Member',
! 173: 'future' => 'Future Member',
! 174: 'updi' => 'Update Display',
! 175: );
! 176: my $status = $env{'form.status'};
! 177: if (!defined($status)) {
! 178: $status = 'active';
! 179: }
! 180: if (($viewgrps) || ($editgrps) ||
! 181: (&Apache::lonnet::allowed('vmd',$env{'request.course.id'}.'/'.$group))) {
! 182: if (keys(%{$memberinfo}) == 0) {
! 183: $r->print(&mt('There are no membership data to display for this [_1]',
! 184: $gpterm));
! 185: return;
! 186: }
! 187: $r->print('<br /><form name="rosterstatus" method="post" action="/adm/grouproster">'.&mt('Membership status: ').'<select name="status">');
! 188: foreach my $type ('active','previous','future','all') {
! 189: $r->print('<option value="'.$type.'" ');
! 190: if ($status eq $type) {
! 191: $r->print('selected="selected"');
! 192: }
! 193: $r->print('>'.$lt{$type}.'</option>');
! 194: }
! 195: $r->print('</select>'."\n".
! 196: '<input type="submit" name="statusbutton" value="'.
! 197: $lt{'updi'}.'"><input type="hidden" name="sortby" value="'.
! 198: $env{'form.sortby'}.'"/>'.
! 199: '<input type="hidden" name="group" value="'.$group.
! 200: '"/></form><br /><br />');
! 201:
! 202: }
! 203: if (ref($numitems) eq 'HASH') {
! 204: foreach my $key (keys(%{$numitems})) {
! 205: if ($status eq $key && !$$numitems{$key}) {
! 206: $r->print(&mt('There are no [_1] members to display in this [_2]',
! 207: $key,$gpterm));
! 208: return;
! 209: }
! 210: }
! 211: }
! 212: $r->print('
! 213: <form name="grouproster" action="/adm/grouproster" method="post">
! 214: <input type="hidden" name="group" value="'.$group.'" />
! 215: <input type="hidden" name="sortby" value="'.$env{'form.sortby'}.'" />
! 216: ');
! 217: my %Sortby = ();
! 218: my $usercount = 0;
! 219: foreach my $user (sort(keys(%{$memberinfo}))) {
! 220: if ($env{'form.sortby'} eq 'fullname') {
! 221: push(@{$Sortby{$$memberinfo{$user}{fullname}}},$user);
! 222: } elsif ($env{'form.sortby'} eq 'username') {
! 223: push(@{$Sortby{$$memberinfo{$user}{uname}}},$user);
! 224: } elsif ($env{'form.sortby'} eq 'domain') {
! 225: push(@{$Sortby{$$memberinfo{$user}{udom}}},$user);
! 226: } elsif ($env{'form.sortby'} eq 'id') {
! 227: push(@{$Sortby{$$memberinfo{$user}{id}}},$user);
! 228: } else {
! 229: push(@{$Sortby{$$memberinfo{$user}{fullname}}},$user);
! 230: }
! 231: }
! 232: $r->print(&Apache::loncommon::start_data_table());
! 233: $r->print(&members_table_header_row(\%lt,$viewgrps,$editgrps,$view_details,
! 234: $hastools));
! 235: foreach my $key (sort(keys(%Sortby))) {
! 236: foreach my $user (@{$Sortby{$key}}) {
! 237: if (($status eq 'all') ||
! 238: ($status eq $$memberinfo{$user}{status})) {
! 239: $r->print(&members_table_row($viewgrps,$editgrps,$view_details,
! 240: $hastools,\%tooltype,$toolprivs,$$memberinfo{$user}));
! 241: }
! 242: }
! 243: }
! 244: $r->print(&Apache::loncommon::end_data_table());
! 245: $r->print('</form>');
! 246: return;
! 247: }
! 248:
! 249: sub members_table_header_row {
! 250: my ($lt,$viewgrps,$editgrps,$view_details,$hastools) = @_;
! 251: my $output = &Apache::loncommon::start_data_table_header_row();
! 252: $output .= "<th><a href=\"javascript:changeSort('fullname')\">".
! 253: "$$lt{'name'}</a></th>";
! 254: if ($viewgrps || $editgrps || $view_details ) {
! 255: $output .= "<th><a href=\"javascript:changeSort('username')\">$$lt{'usnm'}</a></th>";
! 256: $output .= "<th><a href=\"javascript:changeSort('domain')\">$$lt{'doma'}</a></th>";
! 257: }
! 258: if ($viewgrps || $editgrps) {
! 259: $output .= "<th><a href=\"javascript:changeSort('id')\">$$lt{'stid'}</a></th>";
! 260: }
! 261: if ($viewgrps || $editgrps || $view_details ) {
! 262: $output .= "<th><a href=\"javascript:changeSort('start')\">$$lt{'stda'}</a></th>";
! 263: $output .= "<th><a href=\"javascript:changeSort('end')\">$$lt{'enda'}</a></th>";
! 264: if ($hastools) {
! 265: if ($viewgrps || $editgrps) {
! 266: $output .= '<th><b>'.$$lt{'priv'}.'</b></th>';
! 267: } elsif ($view_details) {
! 268: $output .= '<th><b>'.$$lt{'func'}.'</b></th>';
! 269: }
! 270: }
! 271: }
! 272: $output .= &Apache::loncommon::end_data_table_header_row();
! 273: return $output;
! 274: }
! 275:
! 276: sub members_table_row {
! 277: my ($viewgrps,$editgrps,$view_details,$hastools,$tooltype,$toolprivs,
! 278: $userinfo) = @_;
! 279: my $output = &Apache::loncommon::start_data_table_row();
! 280: $output .= '<td>'.&Apache::loncommon::aboutmewrapper($$userinfo{'fullname'},
! 281: $$userinfo{'uname'},$$userinfo{'udom'} ).
! 282: '</td>';
! 283: if ($viewgrps || $editgrps || $view_details ) {
! 284: $output .= '<td>'.$$userinfo{'uname'}.'</td>';
! 285: $output .= '<td>'.$$userinfo{'udom'}.'</td>';
! 286: }
! 287: if ($viewgrps || $editgrps) {
! 288: $output .= '<td>'.$$userinfo{'id'}.'</td>';
! 289: }
! 290: if ($viewgrps || $editgrps || $view_details) {
! 291: $output .= '<td>'.$$userinfo{'start'}.'</td>';
! 292: $output .= '<td>'.$$userinfo{'end'}.'</td>';
! 293: }
! 294: if ($hastools) {
! 295: if ($viewgrps || $editgrps) {
! 296: my $curr_tool;
! 297: my $privlist;
! 298: foreach my $priv (@{$$userinfo{'privs'}}) {
! 299: unless ($curr_tool eq $$tooltype{$priv}) {
! 300: $curr_tool = $$tooltype{$priv};
! 301: $privlist .= '<b>'.$curr_tool.'</b>: ';
! 302: }
! 303: $privlist .= $$toolprivs{$curr_tool}{$priv}.', ';
! 304: }
! 305: $privlist =~ s/, $//;
! 306: $output .= '<td>'.$privlist.'</td>';
! 307: } elsif ($view_details) {
! 308: $output .= '<td><nobr>'.join(' ',
! 309: @{$$userinfo{'currtools'}}).'</nobr></td>';
! 310: }
! 311: }
! 312: $output .= &Apache::loncommon::end_data_table_row();
! 313: return $output;
! 314: }
! 315:
! 316: 1;
! 317:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>