[LON-CAPA-cvs] cvs: doc /loncapafiles loncapafiles.lpml loncom loncapa_apache.conf loncom/interface grouproster.pm

raeburn lon-capa-cvs@mail.lon-capa.org
Sun, 02 Jul 2006 18:01:59 -0000


This is a MIME encoded message

--raeburn1151863319
Content-Type: text/plain

raeburn		Sun Jul  2 14:01:59 2006 EDT

  Added files:                 
    /loncom/interface	grouproster.pm 

  Modified files:              
    /loncom	loncapa_apache.conf 
    /doc/loncapafiles	loncapafiles.lpml 
  Log:
  Bug 4859. Providing group roster display. 
  
  
--raeburn1151863319
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20060702140159.txt"

Index: loncom/loncapa_apache.conf
diff -u loncom/loncapa_apache.conf:1.143 loncom/loncapa_apache.conf:1.144
--- loncom/loncapa_apache.conf:1.143	Fri Jun 30 04:14:27 2006
+++ loncom/loncapa_apache.conf	Sun Jul  2 14:01:32 2006
@@ -1,7 +1,7 @@
 ##
 ## loncapa_apache.conf -- Apache HTTP LON-CAPA configuration file
 ##
-## $Id: loncapa_apache.conf,v 1.143 2006/06/30 08:14:27 raeburn Exp $
+## $Id: loncapa_apache.conf,v 1.144 2006/07/02 18:01:32 raeburn Exp $
 ##
 
 #
@@ -896,6 +896,17 @@
 ErrorDocument     500 /adm/errorhandler
 </Location>
 
+<Location /adm/grouproster>
+AuthType LONCAPA
+Require valid-user
+PerlAuthzHandler       Apache::lonacc
+SetHandler perl-script
+PerlHandler Apache::grouproster
+ErrorDocument     403 /adm/login
+ErrorDocument     406 /adm/roles
+ErrorDocument     500 /adm/errorhandler
+</Location>
+
 <Location /adm/whatsnew>
 AuthType LONCAPA
 Require valid-user
Index: doc/loncapafiles/loncapafiles.lpml
diff -u doc/loncapafiles/loncapafiles.lpml:1.488 doc/loncapafiles/loncapafiles.lpml:1.489
--- doc/loncapafiles/loncapafiles.lpml:1.488	Fri Jun 30 04:14:24 2006
+++ doc/loncapafiles/loncapafiles.lpml	Sun Jul  2 14:01:59 2006
@@ -2,7 +2,7 @@
  "http://lpml.sourceforge.net/DTD/lpml.dtd">
 <!-- loncapafiles.lpml -->
 
-<!-- $Id: loncapafiles.lpml,v 1.488 2006/06/30 08:14:24 raeburn Exp $ -->
+<!-- $Id: loncapafiles.lpml,v 1.489 2006/07/02 18:01:59 raeburn Exp $ -->
 
 <!--
 
@@ -3957,6 +3957,15 @@
 <status>works/unverified</status>
 </file>
 <file>
+<source>loncom/interface/grouproster.pm</source>
+<target dist='default'>home/httpd/lib/perl/Apache/grouproster.pm</target>
+<categoryname>handler</categoryname>
+<description>
+Display group membership information. Type of information available depends on group privileges of the user.  
+</description>
+<status>works/unverified</status>
+</file>
+<file>
 <source>loncom/interface/lonmsg.pm</source>
 <target dist='default'>home/httpd/lib/perl/Apache/lonmsg.pm</target>
 <categoryname>handler</categoryname>

Index: loncom/interface/grouproster.pm
+++ loncom/interface/grouproster.pm
# The LearningOnline Network with CAPA
#
# Copyright Michigan State University Board of Trustees
#
# This file is part of the LearningOnline Network with CAPA (LON-CAPA).
#
# LON-CAPA is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# LON-CAPA is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with LON-CAPA; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
# /home/httpd/html/adm/gpl.txt
#
# http://www.lon-capa.org/
#

package Apache::grouproster;
                                                                                 
use strict;
use Apache::lonnet;
use Apache::loncommon;
use Apache::lonhtmlcommon;
use Apache::lonlocal;
use Apache::longroup;
use Apache::Constants qw(:common :http);
use lib '/home/httpd/lib/perl/';

sub handler {
    my ($r) = @_;
    &Apache::loncommon::content_type($r,'text/html');
    $r->send_http_header;
                                                                                 
    if ($r->header_only) {
        return OK;
    }
                                                                                 
    #  Needs to be in a course
    if (! ($env{'request.course.fn'})) {
        # Not in a course
        $env{'user.error.msg'}=
     "/adm/coursegroups:mdg:0:0:Cannot edit or view course groups";
        return HTTP_NOT_ACCEPTABLE;
    }

    &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['group']); 

    my $gpterm  = &Apache::loncommon::group_term();
    my $ucgpterm = $gpterm;
    $ucgpterm =~ s/^(\w)/uc($1)/e;  
    my $crstype = &Apache::loncommon::course_type();
    my $group;

    if ((!defined($env{'form.group'})) || ($env{'form.group'} eq '')) {
        $r->print(&mt('No [_1] name provided',$gpterm));
                                                                                   
    } else {
        $group = $env{'form.group'};
        $group =~ s/\W//g;
    }
    if ($group eq '') {
        $r->print(&mt('Invalid [_1] name provided',$gpterm));
    }

    my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
    my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};

    if ($cdom eq '' || $cnum eq '') {
        $r->print(&mt('Invalid [_1]',$crstype));
    }

    my @coursegroups = split(/:/,$env{'request.course.groups'});
    if ((@coursegroups == 0) || ((@coursegroups > 0) && 
                                 (!(grep/^\Q$group\E$/,@coursegroups)))) {
        $r->print(&mt('[_1] is not the name of a valid [_2] in this [_3].',
                      $group,$gpterm,lc($crstype)));
    } 

    &Apache::lonhtmlcommon::clear_breadcrumbs();

    my $can_view = &Apache::lonnet::allowed('vgm',$env{'request.course.id'}.
                                            '/'.$group);
    my $view_details = &Apache::lonnet::allowed('vmd',$env{'request.course.id'}.'/'.$group);

    my $viewgrps = &Apache::lonnet::allowed('vcg',$env{'request.course.id'});
    my $editgrps = &Apache::lonnet::allowed('mdg',$env{'request.course.id'});

    if ((!$can_view) && (!$view_details) && (!$viewgrps) && (!$editgrps)) {
        $r->print(&mt('You do not have privileges to view the membership roster in this [_1]',$gpterm));
        return OK;
    }
    my %coursegroups = &Apache::longroup::coursegroups($cdom,$cnum,$group);
    my %content = &Apache::longroup::get_group_settings($coursegroups{$group});
    my $description = &unescape($content{'description'});
    $r->print(&roster_header($cdom,$cnum,$group,$description,$gpterm,$ucgpterm));

    my $available;
    foreach my $tool (sort(keys(%{$content{'functions'}}))) {
        if ($content{functions}{$tool} eq 'on') {
            push(@{$available},$tool);
        }
    }

    &roster_table($r,$cdom,$cnum,$group,$can_view,$view_details,$viewgrps,
                  $editgrps,$available,$gpterm,$ucgpterm);

    $r->print(&Apache::loncommon::end_page());
    return OK;
}

sub roster_header {
    my ($cdom,$cnum,$group,$description,$gpterm,$ucgpterm) = @_;
    my $jscript = qq|
function changeSort(caller) {
    document.grouproster.sortby.value = caller;
    document.grouproster.submit();
}\n|;
    my $output =
        &Apache::loncommon::start_page(&mt('[_1] Membership ',$ucgpterm),
                                       '<script type="text/javascript">'.
                                       $jscript.'</script>');
    &Apache::lonhtmlcommon::add_breadcrumb
        ({href=>"/adm/$cdom/$cnum/$group/grppg",
          text=>"$ucgpterm: $description",
          title=>"Go to group's home page"},
         {href=>"/adm/grouproster?group=$group",
          text=>"Membership roster",
          title=>"Display group membership"},);
    $output .= &Apache::lonhtmlcommon::breadcrumbs(&mt('[_1] membership status - [_2]',$gpterm,$description));
    return $output;
}

sub roster_table {
    my ($r,$cdom,$cnum,$group,$can_view,$view_details,$viewgrps,$editgrps,
        $available,$gpterm,$ucgpterm) = @_;

    my $fixedprivs = &Apache::longroup::get_fixed_privs();

    my ($memberinfo,$hastools,$addtools,$numitems) = 
        &Apache::longroup::group_memberlist($cdom,$cnum,$group,$fixedprivs,
                                            $available);
    my (%tooltype,$toolprivs);

    if ($hastools) {
        $toolprivs = &Apache::longroup::get_tool_privs($gpterm);
        foreach my $tool (sort(keys(%{$toolprivs}))) {
            foreach my $priv (sort(keys(%{$$toolprivs{$tool}}))) {
                $tooltype{$priv} = $tool;
            }
        }
    }
 
    my %lt = &Apache::lonlocal::texthash(
                                         'name'     => 'Name',
                                         'usnm'     => 'Username',
                                         'doma'     => 'Domain',
                                         'stid'     => 'ID',
                                         'stda'     => 'Start Date',
                                         'enda'     => 'End Date',
                                         'func'     => 'Functionality',
                                         'priv'     => 'Privileges', 
                                         'all'      => 'Any Membership status',
                                         'active'   => 'Active Member',
                                         'previous' => 'Former Member',
                                         'future'   => 'Future Member',
                                         'updi'     => 'Update Display',
                                        );
    my $status = $env{'form.status'};
    if (!defined($status)) {
        $status = 'active';
    }
    if (($viewgrps) || ($editgrps) || 
        (&Apache::lonnet::allowed('vmd',$env{'request.course.id'}.'/'.$group))) {
        if (keys(%{$memberinfo}) == 0) {
            $r->print(&mt('There are no membership data to display for this [_1]',
                      $gpterm));  
            return;  
        }  
        $r->print('<br /><form name="rosterstatus" method="post" action="/adm/grouproster">'.&mt('Membership status: ').'<select name="status">');
        foreach my $type ('active','previous','future','all') {
            $r->print('<option value="'.$type.'" ');
            if ($status eq $type) {
                $r->print('selected="selected"');
            }
            $r->print('>'.$lt{$type}.'</option>');
        }
        $r->print('</select>'."\n".
                  '<input type="submit" name="statusbutton" value="'.
                  $lt{'updi'}.'"><input type="hidden" name="sortby" value="'.
                  $env{'form.sortby'}.'"/>'.
                  '<input type="hidden" name="group" value="'.$group.
                  '"/></form><br /><br />');

    }
    if (ref($numitems) eq 'HASH') {
        foreach my $key (keys(%{$numitems})) {
            if ($status eq $key && !$$numitems{$key}) {
                $r->print(&mt('There are no [_1] members to display in this [_2]',
                              $key,$gpterm));
                return;
            }
        }
    }
    $r->print('
<form name="grouproster" action="/adm/grouproster" method="post">
 <input type="hidden" name="group" value="'.$group.'" />
 <input type="hidden" name="sortby" value="'.$env{'form.sortby'}.'" />
');
    my %Sortby = ();
    my $usercount = 0;
    foreach my $user (sort(keys(%{$memberinfo}))) {
        if ($env{'form.sortby'} eq 'fullname') {
            push(@{$Sortby{$$memberinfo{$user}{fullname}}},$user);
        } elsif ($env{'form.sortby'} eq 'username') {
            push(@{$Sortby{$$memberinfo{$user}{uname}}},$user);
        } elsif ($env{'form.sortby'} eq 'domain') {
            push(@{$Sortby{$$memberinfo{$user}{udom}}},$user);
        } elsif ($env{'form.sortby'} eq 'id') {
            push(@{$Sortby{$$memberinfo{$user}{id}}},$user);
        } else {
            push(@{$Sortby{$$memberinfo{$user}{fullname}}},$user);
        }
    }
    $r->print(&Apache::loncommon::start_data_table());
    $r->print(&members_table_header_row(\%lt,$viewgrps,$editgrps,$view_details,
                                        $hastools));
    foreach my $key (sort(keys(%Sortby))) {
        foreach my $user (@{$Sortby{$key}}) {
            if (($status eq 'all') || 
                ($status eq $$memberinfo{$user}{status})) {
                $r->print(&members_table_row($viewgrps,$editgrps,$view_details,
                          $hastools,\%tooltype,$toolprivs,$$memberinfo{$user}));
            }
        }
    }
    $r->print(&Apache::loncommon::end_data_table());
    $r->print('</form>');
    return;
}

sub members_table_header_row {
    my ($lt,$viewgrps,$editgrps,$view_details,$hastools) = @_; 
    my $output = &Apache::loncommon::start_data_table_header_row();
    $output .= "<th><a href=\"javascript:changeSort('fullname')\">".
              "$$lt{'name'}</a></th>";
    if ($viewgrps || $editgrps || $view_details ) {
        $output .= "<th><a href=\"javascript:changeSort('username')\">$$lt{'usnm'}</a></th>";
        $output .= "<th><a href=\"javascript:changeSort('domain')\">$$lt{'doma'}</a></th>";
    }
    if ($viewgrps || $editgrps) {
        $output .= "<th><a href=\"javascript:changeSort('id')\">$$lt{'stid'}</a></th>";
    }
    if ($viewgrps || $editgrps || $view_details ) {
        $output .= "<th><a href=\"javascript:changeSort('start')\">$$lt{'stda'}</a></th>";
        $output .= "<th><a href=\"javascript:changeSort('end')\">$$lt{'enda'}</a></th>";
        if ($hastools) {
            if ($viewgrps || $editgrps) {
                $output .= '<th><b>'.$$lt{'priv'}.'</b></th>';
            } elsif ($view_details) {
                $output .= '<th><b>'.$$lt{'func'}.'</b></th>';
            }
        }
    }
    $output .= &Apache::loncommon::end_data_table_header_row();
    return $output;
}

sub members_table_row {
    my ($viewgrps,$editgrps,$view_details,$hastools,$tooltype,$toolprivs,
        $userinfo) = @_;
    my $output = &Apache::loncommon::start_data_table_row();
    $output .= '<td>'.&Apache::loncommon::aboutmewrapper($$userinfo{'fullname'},
                      $$userinfo{'uname'},$$userinfo{'udom'}  ).
               '</td>';
    if ($viewgrps || $editgrps || $view_details ) {
        $output .= '<td>'.$$userinfo{'uname'}.'</td>';
        $output .= '<td>'.$$userinfo{'udom'}.'</td>';
    }
    if ($viewgrps || $editgrps) {
        $output .= '<td>'.$$userinfo{'id'}.'</td>';
    }
    if ($viewgrps || $editgrps || $view_details) {
        $output .= '<td>'.$$userinfo{'start'}.'</td>';
        $output .= '<td>'.$$userinfo{'end'}.'</td>';
    }
    if ($hastools) {
        if ($viewgrps || $editgrps) {
            my $curr_tool;
            my $privlist;
            foreach my $priv (@{$$userinfo{'privs'}}) {
                unless ($curr_tool eq $$tooltype{$priv}) {
                    $curr_tool = $$tooltype{$priv};
                    $privlist .= '<b>'.$curr_tool.'</b>: ';
                }
                $privlist .= $$toolprivs{$curr_tool}{$priv}.', ';
            }
            $privlist =~ s/, $//;
            $output .= '<td>'.$privlist.'</td>';
        } elsif ($view_details) {
            $output .= '<td><nobr>'.join('&nbsp;&nbsp;&nbsp;',
                      @{$$userinfo{'currtools'}}).'</nobr></td>';
        }
    }
    $output .= &Apache::loncommon::end_data_table_row();
    return $output;
}

1;


--raeburn1151863319--