# The LearningOnline Network with CAPA # Handler to display the classlist # # $Id: lonviewclasslist.pm,v 1.2 2004/08/27 04:18:11 raeburn Exp $ # # 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::lonviewclasslist; use strict; use Apache::loncoursedata(); use Apache::loncommon(); use Apache::lonhtmlcommon(); use Apache::Constants qw(:common :http REDIRECT); use Apache::lonlocal; ################################################################### ################################################################### =pod =item &handler The typical handler you see in all these modules. Takes $r, the http request, as an argument. =cut ################################################################### ################################################################### sub handler { my $r=shift; if ($r->header_only) { &Apache::loncommon::content_type($r,'text/html'); $r->send_http_header; return OK; } # &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, # ['action','state']); &Apache::lonhtmlcommon::clear_breadcrumbs(); &Apache::lonhtmlcommon::add_breadcrumb ({href=>"/adm/viewclasslist", text=>"View Classlist", faq=>9,bug=>'Instructor Interface',}); # Needs to be in a course if (! ($ENV{'request.course.fn'})) { $ENV{'user.error.msg'}= "/adm/viewclasslist:not in course role"; return HTTP_NOT_ACCEPTABLE; } &Apache::loncommon::content_type($r,'text/html'); $r->send_http_header; # my $bodytag=&Apache::loncommon::bodytag('Classlist'); my $breadcrumbs=&Apache::lonhtmlcommon::breadcrumbs(undef, 'Enrollment Manager'); $r->print(< Classlist $bodytag $breadcrumbs ENDHEADER # # Print classlist my $cid = $ENV{'request.course.id'}; my $viewpermission = 'course.'.$cid.'.student_classlist_view'; if (&allowed_to_view_classlist()) { $r->print(&html_classlist()); } else { $r->print('

'. &mt("You are not authorized to view the classlist for your course."). '

'); } # # Finish up $r->print(''); return OK; } sub allowed_to_view_classlist { return 0 if (! exists($ENV{'request.course.id'})); my $cid = $ENV{'request.course.id'}; my $viewpermission = 'course.'.$cid.'.student_classlist_view'; if (exists($ENV{$viewpermission}) && $ENV{$viewpermission} =~ /^(all|section)$/) { return $ENV{$viewpermission}; } else { return 0; } } sub html_classlist { my $limit_to_section = (&allowed_to_view_classlist()=~ /^section$/i); my $Str; if ($limit_to_section) { if ($ENV{'request.course.sec'} eq '') { $Str .= '

'. &mt('Students with no section').'

'; } else { $Str.='

'. &mt('Students in section "[_1]"', $ENV{'request.course.sec'}). '

'; } } # my $classlist = &Apache::loncoursedata::get_classlist(); # # Set up a couple variables. my $usernameidx = &Apache::loncoursedata::CL_SNAME(); my $domainidx = &Apache::loncoursedata::CL_SDOM(); my $fullnameidx = &Apache::loncoursedata::CL_FULLNAME(); my $sectionidx = &Apache::loncoursedata::CL_SECTION(); my $statusidx = &Apache::loncoursedata::CL_STATUS(); # # Sort the students my $sortby = $fullnameidx; my @Sorted_Students = sort { lc($classlist->{$a}->[$sortby]) cmp lc($classlist->{$b}->[$sortby]) } (keys(%$classlist)); $Str .= ''.$/. ''. ''. # for the count ''. ''; if (! $limit_to_section) { $Str .= ''; } $Str .=''.$/; my $count ++; foreach my $student (@Sorted_Students) { my $username = $classlist->{$student}->[$usernameidx]; my $domain = $classlist->{$student}->[$domainidx]; my $fullname = $classlist->{$student}->[$fullnameidx]; if ($fullname =~ /^\s*$/) { $fullname = &mt('Name not given'); } my $section = $classlist->{$student}->[$sectionidx]; my $status = $classlist->{$student}->[$statusidx]; # next if (lc($status) ne 'active'); if ($limit_to_section) { if ($section ne $ENV{'request.course.sec'}) { next; } } $Str .= ''. ''. ''. ''; if (! $limit_to_section) { $Str .= ''; } $Str .= ''.$/; } $Str .= '
'.&mt('Student').''.&mt('Username').''.&mt('Section').'
'.$count++.''.&Apache::loncommon::aboutmewrapper($fullname, $username, $domain).''.(' 'x2). &Apache::loncommon::messagewrapper (' '. $username.'@'.$domain,$username,$domain).''.$section.'
'; return $Str; } ################################################################### ################################################################### 1; __END__