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

1.1       matthew     1: # The LearningOnline Network with CAPA
                      2: # Handler to display the classlist 
                      3: #
1.7     ! raeburn     4: # $Id: lonviewclasslist.pm,v 1.6 2006/03/15 19:41:26 albertel 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;
1.5       albertel   39: use Apache::lonnet;
1.1       matthew    40: 
                     41: 
                     42: ###################################################################
                     43: ###################################################################
                     44: 
                     45: =pod
                     46: 
                     47: =item &handler
                     48: 
                     49: The typical handler you see in all these modules.  Takes $r, the
                     50: http request, as an argument.  
                     51: 
                     52: =cut
                     53: 
                     54: ###################################################################
                     55: ###################################################################
                     56: sub handler {
                     57:     my $r=shift;
                     58:     if ($r->header_only) {
                     59:         &Apache::loncommon::content_type($r,'text/html');
                     60:         $r->send_http_header;
                     61:         return OK;
                     62:     }
                     63: #    &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
                     64: #                                            ['action','state']);
                     65:     &Apache::lonhtmlcommon::clear_breadcrumbs();
                     66:     &Apache::lonhtmlcommon::add_breadcrumb
                     67:         ({href=>"/adm/viewclasslist",
                     68:           text=>"View Classlist",
                     69:           faq=>9,bug=>'Instructor Interface',});
                     70:     #  Needs to be in a course
1.5       albertel   71:     if (! ($env{'request.course.fn'})) {
                     72:         $env{'user.error.msg'}=
1.1       matthew    73:             "/adm/viewclasslist:not in course role";
                     74:         return HTTP_NOT_ACCEPTABLE; 
                     75:     }
                     76:     &Apache::loncommon::content_type($r,'text/html');
                     77:     $r->send_http_header;
                     78:     #
1.7     ! raeburn    79:     my $start_page = &Apache::loncommon::start_page('Classlist');
1.6       albertel   80:     my $breadcrumbs= &Apache::lonhtmlcommon::breadcrumbs(undef,
                     81: 							 'Enrollment Manager');
1.1       matthew    82:     $r->print(<<ENDHEADER);
1.6       albertel   83: $start_page
1.1       matthew    84: $breadcrumbs
                     85: ENDHEADER
                     86:     #
                     87:     # Print classlist
1.5       albertel   88:     my $cid = $env{'request.course.id'};
1.1       matthew    89:     my $viewpermission = 'course.'.$cid.'.student_classlist_view';
                     90:     if (&allowed_to_view_classlist()) {
                     91:         $r->print(&html_classlist());
                     92:     } else {
                     93:         $r->print('<h2>'.
                     94:                   &mt("You are not authorized to view the classlist for your course.").
                     95:                   '</h2>');
                     96:     }
                     97:     #
                     98:     # Finish up
1.6       albertel   99:     $r->print(&Apache::loncommon::end_page());
1.1       matthew   100:     return OK;
                    101: }
                    102: 
                    103: sub allowed_to_view_classlist {
1.5       albertel  104:     return 0 if (! exists($env{'request.course.id'}));
                    105:     my $cid = $env{'request.course.id'};
1.1       matthew   106:     my $viewpermission = 'course.'.$cid.'.student_classlist_view';
1.5       albertel  107:     if (exists($env{$viewpermission}) &&
                    108:         $env{$viewpermission} =~ /^(all|section)$/) {
                    109:         return $env{$viewpermission};
1.1       matthew   110:     } else {
                    111:         return 0;
                    112:     }
                    113: }
                    114: 
                    115: sub html_classlist {
                    116:     my $limit_to_section = (&allowed_to_view_classlist()=~ /^section$/i);
                    117:     my $Str;
                    118:     if ($limit_to_section) {
1.5       albertel  119:         if ($env{'request.course.sec'} eq '') {
1.1       matthew   120:             $Str .= '<h2>'.
                    121:                 &mt('Students with no section').'</h2>';
                    122:         } else {
                    123:             $Str.='<h2>'.
                    124:                 &mt('Students in section "[_1]"',
1.5       albertel  125:                     $env{'request.course.sec'}).
1.1       matthew   126:                     '</h2>';
                    127:         }
                    128:     }
                    129:     # 
                    130:     my $classlist = &Apache::loncoursedata::get_classlist();
                    131:     #
                    132:     # Set up a couple variables.
                    133:     my $usernameidx = &Apache::loncoursedata::CL_SNAME();
                    134:     my $domainidx   = &Apache::loncoursedata::CL_SDOM();
                    135:     my $fullnameidx = &Apache::loncoursedata::CL_FULLNAME();
                    136:     my $sectionidx  = &Apache::loncoursedata::CL_SECTION();
                    137:     my $statusidx   = &Apache::loncoursedata::CL_STATUS();
                    138:     #
                    139:     # Sort the students
                    140:     my $sortby = $fullnameidx;
                    141:     my @Sorted_Students = sort {
                    142:         lc($classlist->{$a}->[$sortby])  cmp lc($classlist->{$b}->[$sortby])
                    143:         } (keys(%$classlist));
                    144:     $Str .= '<table>'.$/.
                    145:         '<tr>'.
                    146:         '<th></th>'. # for the count
                    147:         '<th>'.&mt('Student').'</th>'.
                    148:         '<th>'.&mt('Username').'</th>';
                    149:     if (! $limit_to_section) {
                    150:         $Str .= '<th>'.&mt('Section').'</th>';
                    151:     }
                    152:     $Str .='</tr>'.$/;
                    153:     my $count ++;
                    154:     foreach my $student (@Sorted_Students) {
                    155:         my $username = $classlist->{$student}->[$usernameidx];
                    156:         my $domain   = $classlist->{$student}->[$domainidx];
                    157:         my $fullname = $classlist->{$student}->[$fullnameidx];
                    158:         if ($fullname =~ /^\s*$/) {
                    159:             $fullname = &mt('Name not given');
                    160:         }
                    161:         my $section  = $classlist->{$student}->[$sectionidx];
                    162:         my $status   = $classlist->{$student}->[$statusidx];
1.3       matthew   163:         next if (lc($status) ne 'active');
1.1       matthew   164:         if ($limit_to_section) {
1.5       albertel  165:             if ($section ne $env{'request.course.sec'}) {
1.1       matthew   166:                 next;
                    167:             }
                    168:         }
                    169:         $Str .= '<tr>'.
                    170:             '<td>'.$count++.'</td>'.
                    171:             '<td>'.&Apache::loncommon::aboutmewrapper($fullname,
                    172:                                                       $username,
                    173:                                                       $domain).'</td>'.
                    174:             '<td>'.('&nbsp;'x2).
                    175:             &Apache::loncommon::messagewrapper
1.2       raeburn   176:             ('<img src="/adm/lonIcons/mailto.gif" border="0" />&nbsp;'.
1.1       matthew   177:              $username.'@'.$domain,$username,$domain).'</td>';
                    178:         if (! $limit_to_section) {
                    179:             $Str .= '<td>'.$section.'</td>';
                    180:         }
                    181:         $Str .= '</tr>'.$/;
                    182:     }
                    183:     $Str .= '</table>';
                    184:     return $Str;
                    185: }
                    186: 
                    187: ###################################################################
                    188: ###################################################################
                    189: 
                    190: 1;
                    191: __END__
                    192: 
                    193: 

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