File:  [LON-CAPA] / loncom / interface / lonviewclasslist.pm
Revision 1.5: download - view: text, annotated - select for diffs
Thu Apr 7 06:56:23 2005 UTC (19 years, 1 month ago) by albertel
Branches: MAIN
CVS tags: version_2_1_X, version_2_1_3, version_2_1_2, version_2_1_1, version_2_1_0, version_2_0_X, version_2_0_99_1, version_2_0_2, version_2_0_1, version_2_0_0, version_1_99_3, version_1_99_2, version_1_99_1_tmcc, version_1_99_1, version_1_99_0_tmcc, version_1_99_0, HEAD
- ENV -> env

    1: # The LearningOnline Network with CAPA
    2: # Handler to display the classlist 
    3: #
    4: # $Id: lonviewclasslist.pm,v 1.5 2005/04/07 06:56:23 albertel Exp $
    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: use Apache::lonnet;
   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
   71:     if (! ($env{'request.course.fn'})) {
   72:         $env{'user.error.msg'}=
   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:     #
   79:     my $bodytag=&Apache::loncommon::bodytag('Classlist');
   80:     my $breadcrumbs=&Apache::lonhtmlcommon::breadcrumbs(undef,
   81:                                                         'Enrollment Manager');
   82:     my $html=&Apache::lonxml::xmlbegin();
   83:     $r->print(<<ENDHEADER);
   84: $html
   85: <head>
   86: <title>Classlist</title>
   87: </head>
   88: $bodytag
   89: $breadcrumbs
   90: ENDHEADER
   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: sub html_classlist {
  121:     my $limit_to_section = (&allowed_to_view_classlist()=~ /^section$/i);
  122:     my $Str;
  123:     if ($limit_to_section) {
  124:         if ($env{'request.course.sec'} eq '') {
  125:             $Str .= '<h2>'.
  126:                 &mt('Students with no section').'</h2>';
  127:         } else {
  128:             $Str.='<h2>'.
  129:                 &mt('Students in section "[_1]"',
  130:                     $env{'request.course.sec'}).
  131:                     '</h2>';
  132:         }
  133:     }
  134:     # 
  135:     my $classlist = &Apache::loncoursedata::get_classlist();
  136:     #
  137:     # Set up a couple variables.
  138:     my $usernameidx = &Apache::loncoursedata::CL_SNAME();
  139:     my $domainidx   = &Apache::loncoursedata::CL_SDOM();
  140:     my $fullnameidx = &Apache::loncoursedata::CL_FULLNAME();
  141:     my $sectionidx  = &Apache::loncoursedata::CL_SECTION();
  142:     my $statusidx   = &Apache::loncoursedata::CL_STATUS();
  143:     #
  144:     # Sort the students
  145:     my $sortby = $fullnameidx;
  146:     my @Sorted_Students = sort {
  147:         lc($classlist->{$a}->[$sortby])  cmp lc($classlist->{$b}->[$sortby])
  148:         } (keys(%$classlist));
  149:     $Str .= '<table>'.$/.
  150:         '<tr>'.
  151:         '<th></th>'. # for the count
  152:         '<th>'.&mt('Student').'</th>'.
  153:         '<th>'.&mt('Username').'</th>';
  154:     if (! $limit_to_section) {
  155:         $Str .= '<th>'.&mt('Section').'</th>';
  156:     }
  157:     $Str .='</tr>'.$/;
  158:     my $count ++;
  159:     foreach my $student (@Sorted_Students) {
  160:         my $username = $classlist->{$student}->[$usernameidx];
  161:         my $domain   = $classlist->{$student}->[$domainidx];
  162:         my $fullname = $classlist->{$student}->[$fullnameidx];
  163:         if ($fullname =~ /^\s*$/) {
  164:             $fullname = &mt('Name not given');
  165:         }
  166:         my $section  = $classlist->{$student}->[$sectionidx];
  167:         my $status   = $classlist->{$student}->[$statusidx];
  168:         next if (lc($status) ne 'active');
  169:         if ($limit_to_section) {
  170:             if ($section ne $env{'request.course.sec'}) {
  171:                 next;
  172:             }
  173:         }
  174:         $Str .= '<tr>'.
  175:             '<td>'.$count++.'</td>'.
  176:             '<td>'.&Apache::loncommon::aboutmewrapper($fullname,
  177:                                                       $username,
  178:                                                       $domain).'</td>'.
  179:             '<td>'.('&nbsp;'x2).
  180:             &Apache::loncommon::messagewrapper
  181:             ('<img src="/adm/lonIcons/mailto.gif" border="0" />&nbsp;'.
  182:              $username.'@'.$domain,$username,$domain).'</td>';
  183:         if (! $limit_to_section) {
  184:             $Str .= '<td>'.$section.'</td>';
  185:         }
  186:         $Str .= '</tr>'.$/;
  187:     }
  188:     $Str .= '</table>';
  189:     return $Str;
  190: }
  191: 
  192: ###################################################################
  193: ###################################################################
  194: 
  195: 1;
  196: __END__
  197: 
  198: 

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