Annotation of loncom/interface/lonviewclasslist.pm, revision 1.2

1.1       matthew     1: # The LearningOnline Network with CAPA
                      2: # Handler to display the classlist 
                      3: #
1.2     ! raeburn     4: # $Id: lonviewclasslist.pm,v 1.1 2004/07/19 17:57:25 matthew Exp $
1.1       matthew     5: #
                      6: # Copyright Michigan State University Board of Trustees
                      7: #
                      8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                      9: #
                     10: # LON-CAPA is free software; you can redistribute it and/or modify
                     11: # it under the terms of the GNU General Public License as published by
                     12: # the Free Software Foundation; either version 2 of the License, or
                     13: # (at your option) any later version.
                     14: #
                     15: # LON-CAPA is distributed in the hope that it will be useful,
                     16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     18: # GNU General Public License for more details.
                     19: #
                     20: # You should have received a copy of the GNU General Public License
                     21: # along with LON-CAPA; if not, write to the Free Software
                     22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     23: #
                     24: # /home/httpd/html/adm/gpl.txt
                     25: #
                     26: # http://www.lon-capa.org/
                     27: #
                     28: ###############################################################
                     29: ##############################################################
                     30: 
                     31: package Apache::lonviewclasslist;
                     32: 
                     33: use strict;
                     34: use Apache::loncoursedata();
                     35: use Apache::loncommon();
                     36: use Apache::lonhtmlcommon();
                     37: use Apache::Constants qw(:common :http REDIRECT);
                     38: use Apache::lonlocal;
                     39: 
                     40: 
                     41: ###################################################################
                     42: ###################################################################
                     43: 
                     44: =pod
                     45: 
                     46: =item &handler
                     47: 
                     48: The typical handler you see in all these modules.  Takes $r, the
                     49: http request, as an argument.  
                     50: 
                     51: =cut
                     52: 
                     53: ###################################################################
                     54: ###################################################################
                     55: sub handler {
                     56:     my $r=shift;
                     57:     if ($r->header_only) {
                     58:         &Apache::loncommon::content_type($r,'text/html');
                     59:         $r->send_http_header;
                     60:         return OK;
                     61:     }
                     62: #    &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
                     63: #                                            ['action','state']);
                     64:     &Apache::lonhtmlcommon::clear_breadcrumbs();
                     65:     &Apache::lonhtmlcommon::add_breadcrumb
                     66:         ({href=>"/adm/viewclasslist",
                     67:           text=>"View Classlist",
                     68:           faq=>9,bug=>'Instructor Interface',});
                     69:     #  Needs to be in a course
                     70:     if (! ($ENV{'request.course.fn'})) {
                     71:         $ENV{'user.error.msg'}=
                     72:             "/adm/viewclasslist:not in course role";
                     73:         return HTTP_NOT_ACCEPTABLE; 
                     74:     }
                     75:     &Apache::loncommon::content_type($r,'text/html');
                     76:     $r->send_http_header;
                     77:     #
                     78:     my $bodytag=&Apache::loncommon::bodytag('Classlist');
                     79:     my $breadcrumbs=&Apache::lonhtmlcommon::breadcrumbs(undef,
                     80:                                                         'Enrollment Manager');
                     81: 
                     82:     $r->print(<<ENDHEADER);
                     83: <html>
                     84: <head>
                     85: <title>Classlist</title>
                     86: </head>
                     87: $bodytag
                     88: $breadcrumbs
                     89: ENDHEADER
                     90: 
                     91:     #
                     92:     # Print classlist
                     93:     my $cid = $ENV{'request.course.id'};
                     94:     my $viewpermission = 'course.'.$cid.'.student_classlist_view';
                     95:     if (&allowed_to_view_classlist()) {
                     96:         $r->print(&html_classlist());
                     97:     } else {
                     98:         $r->print('<h2>'.
                     99:                   &mt("You are not authorized to view the classlist for your course.").
                    100:                   '</h2>');
                    101:     }
                    102:     #
                    103:     # Finish up
                    104:     $r->print('</body></html>');
                    105:     return OK;
                    106: }
                    107: 
                    108: sub allowed_to_view_classlist {
                    109:     return 0 if (! exists($ENV{'request.course.id'}));
                    110:     my $cid = $ENV{'request.course.id'};
                    111:     my $viewpermission = 'course.'.$cid.'.student_classlist_view';
                    112:     if (exists($ENV{$viewpermission}) &&
                    113:         $ENV{$viewpermission} =~ /^(all|section)$/) {
                    114:         return $ENV{$viewpermission};
                    115:     } else {
                    116:         return 0;
                    117:     }
                    118: 
                    119: }
                    120: 
                    121: sub html_classlist {
                    122:     my $limit_to_section = (&allowed_to_view_classlist()=~ /^section$/i);
                    123:     my $Str;
                    124:     if ($limit_to_section) {
                    125:         if ($ENV{'request.course.sec'} eq '') {
                    126:             $Str .= '<h2>'.
                    127:                 &mt('Students with no section').'</h2>';
                    128:         } else {
                    129:             $Str.='<h2>'.
                    130:                 &mt('Students in section "[_1]"',
                    131:                     $ENV{'request.course.sec'}).
                    132:                     '</h2>';
                    133:         }
                    134:     }
                    135:     # 
                    136:     my $classlist = &Apache::loncoursedata::get_classlist();
                    137:     #
                    138:     # Set up a couple variables.
                    139:     my $usernameidx = &Apache::loncoursedata::CL_SNAME();
                    140:     my $domainidx   = &Apache::loncoursedata::CL_SDOM();
                    141:     my $fullnameidx = &Apache::loncoursedata::CL_FULLNAME();
                    142:     my $sectionidx  = &Apache::loncoursedata::CL_SECTION();
                    143:     my $statusidx   = &Apache::loncoursedata::CL_STATUS();
                    144:     #
                    145:     # Sort the students
                    146:     my $sortby = $fullnameidx;
                    147:     my @Sorted_Students = sort {
                    148:         lc($classlist->{$a}->[$sortby])  cmp lc($classlist->{$b}->[$sortby])
                    149:         } (keys(%$classlist));
                    150:     $Str .= '<table>'.$/.
                    151:         '<tr>'.
                    152:         '<th></th>'. # for the count
                    153:         '<th>'.&mt('Student').'</th>'.
                    154:         '<th>'.&mt('Username').'</th>';
                    155:     if (! $limit_to_section) {
                    156:         $Str .= '<th>'.&mt('Section').'</th>';
                    157:     }
                    158:     $Str .='</tr>'.$/;
                    159:     my $count ++;
                    160:     foreach my $student (@Sorted_Students) {
                    161:         my $username = $classlist->{$student}->[$usernameidx];
                    162:         my $domain   = $classlist->{$student}->[$domainidx];
                    163:         my $fullname = $classlist->{$student}->[$fullnameidx];
                    164:         if ($fullname =~ /^\s*$/) {
                    165:             $fullname = &mt('Name not given');
                    166:         }
                    167:         my $section  = $classlist->{$student}->[$sectionidx];
                    168:         my $status   = $classlist->{$student}->[$statusidx];
                    169: #        next if (lc($status) ne 'active');
                    170:         if ($limit_to_section) {
                    171:             if ($section ne $ENV{'request.course.sec'}) {
                    172:                 next;
                    173:             }
                    174:         }
                    175: 
                    176:         $Str .= '<tr>'.
                    177:             '<td>'.$count++.'</td>'.
                    178:             '<td>'.&Apache::loncommon::aboutmewrapper($fullname,
                    179:                                                       $username,
                    180:                                                       $domain).'</td>'.
                    181:             '<td>'.('&nbsp;'x2).
                    182:             &Apache::loncommon::messagewrapper
1.2     ! raeburn   183:             ('<img src="/adm/lonIcons/mailto.gif" border="0" />&nbsp;'.
1.1       matthew   184:              $username.'@'.$domain,$username,$domain).'</td>';
                    185:         if (! $limit_to_section) {
                    186:             $Str .= '<td>'.$section.'</td>';
                    187:         }
                    188:         $Str .= '</tr>'.$/;
                    189:     }
                    190:     $Str .= '</table>';
                    191:     return $Str;
                    192: }
                    193: 
                    194: ###################################################################
                    195: ###################################################################
                    196: 
                    197: 1;
                    198: __END__
                    199: 
                    200: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>