File:  [LON-CAPA] / loncom / interface / lonviewclasslist.pm
Revision 1.4: download - view: text, annotated - select for diffs
Thu Feb 17 08:29:43 2005 UTC (19 years, 4 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- <html> -> &Apache::lonxml::xmlbegin, thus valid doctypes are now getting output, Yeah! StandardsCmpliance

- backing out the encoding changes for now

- some xhtml cleanups
- one icon -> lonhttpd

    1: # The LearningOnline Network with CAPA
    2: # Handler to display the classlist 
    3: #
    4: # $Id: lonviewclasslist.pm,v 1.4 2005/02/17 08:29:43 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: 
   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:     my $html=&Apache::lonxml::xmlbegin();
   82:     $r->print(<<ENDHEADER);
   83: $html
   84: <head>
   85: <title>Classlist</title>
   86: </head>
   87: $bodytag
   88: $breadcrumbs
   89: ENDHEADER
   90:     #
   91:     # Print classlist
   92:     my $cid = $ENV{'request.course.id'};
   93:     my $viewpermission = 'course.'.$cid.'.student_classlist_view';
   94:     if (&allowed_to_view_classlist()) {
   95:         $r->print(&html_classlist());
   96:     } else {
   97:         $r->print('<h2>'.
   98:                   &mt("You are not authorized to view the classlist for your course.").
   99:                   '</h2>');
  100:     }
  101:     #
  102:     # Finish up
  103:     $r->print('</body></html>');
  104:     return OK;
  105: }
  106: 
  107: sub allowed_to_view_classlist {
  108:     return 0 if (! exists($ENV{'request.course.id'}));
  109:     my $cid = $ENV{'request.course.id'};
  110:     my $viewpermission = 'course.'.$cid.'.student_classlist_view';
  111:     if (exists($ENV{$viewpermission}) &&
  112:         $ENV{$viewpermission} =~ /^(all|section)$/) {
  113:         return $ENV{$viewpermission};
  114:     } else {
  115:         return 0;
  116:     }
  117: }
  118: 
  119: sub html_classlist {
  120:     my $limit_to_section = (&allowed_to_view_classlist()=~ /^section$/i);
  121:     my $Str;
  122:     if ($limit_to_section) {
  123:         if ($ENV{'request.course.sec'} eq '') {
  124:             $Str .= '<h2>'.
  125:                 &mt('Students with no section').'</h2>';
  126:         } else {
  127:             $Str.='<h2>'.
  128:                 &mt('Students in section "[_1]"',
  129:                     $ENV{'request.course.sec'}).
  130:                     '</h2>';
  131:         }
  132:     }
  133:     # 
  134:     my $classlist = &Apache::loncoursedata::get_classlist();
  135:     #
  136:     # Set up a couple variables.
  137:     my $usernameidx = &Apache::loncoursedata::CL_SNAME();
  138:     my $domainidx   = &Apache::loncoursedata::CL_SDOM();
  139:     my $fullnameidx = &Apache::loncoursedata::CL_FULLNAME();
  140:     my $sectionidx  = &Apache::loncoursedata::CL_SECTION();
  141:     my $statusidx   = &Apache::loncoursedata::CL_STATUS();
  142:     #
  143:     # Sort the students
  144:     my $sortby = $fullnameidx;
  145:     my @Sorted_Students = sort {
  146:         lc($classlist->{$a}->[$sortby])  cmp lc($classlist->{$b}->[$sortby])
  147:         } (keys(%$classlist));
  148:     $Str .= '<table>'.$/.
  149:         '<tr>'.
  150:         '<th></th>'. # for the count
  151:         '<th>'.&mt('Student').'</th>'.
  152:         '<th>'.&mt('Username').'</th>';
  153:     if (! $limit_to_section) {
  154:         $Str .= '<th>'.&mt('Section').'</th>';
  155:     }
  156:     $Str .='</tr>'.$/;
  157:     my $count ++;
  158:     foreach my $student (@Sorted_Students) {
  159:         my $username = $classlist->{$student}->[$usernameidx];
  160:         my $domain   = $classlist->{$student}->[$domainidx];
  161:         my $fullname = $classlist->{$student}->[$fullnameidx];
  162:         if ($fullname =~ /^\s*$/) {
  163:             $fullname = &mt('Name not given');
  164:         }
  165:         my $section  = $classlist->{$student}->[$sectionidx];
  166:         my $status   = $classlist->{$student}->[$statusidx];
  167:         next if (lc($status) ne 'active');
  168:         if ($limit_to_section) {
  169:             if ($section ne $ENV{'request.course.sec'}) {
  170:                 next;
  171:             }
  172:         }
  173:         $Str .= '<tr>'.
  174:             '<td>'.$count++.'</td>'.
  175:             '<td>'.&Apache::loncommon::aboutmewrapper($fullname,
  176:                                                       $username,
  177:                                                       $domain).'</td>'.
  178:             '<td>'.('&nbsp;'x2).
  179:             &Apache::loncommon::messagewrapper
  180:             ('<img src="/adm/lonIcons/mailto.gif" border="0" />&nbsp;'.
  181:              $username.'@'.$domain,$username,$domain).'</td>';
  182:         if (! $limit_to_section) {
  183:             $Str .= '<td>'.$section.'</td>';
  184:         }
  185:         $Str .= '</tr>'.$/;
  186:     }
  187:     $Str .= '</table>';
  188:     return $Str;
  189: }
  190: 
  191: ###################################################################
  192: ###################################################################
  193: 
  194: 1;
  195: __END__
  196: 
  197: 

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