File:  [LON-CAPA] / loncom / interface / lonviewclasslist.pm
Revision 1.6: download - view: text, annotated - select for diffs
Wed Mar 15 19:41:26 2006 UTC (18 years, 2 months ago) by albertel
Branches: MAIN
CVS tags: version_2_2_0, version_2_1_99_3, version_2_1_99_2, version_2_1_99_1, version_2_1_99_0, HEAD
- converting some interface pages to stop generating </body> <head> </head> </html> and use the helper functions instead

    1: # The LearningOnline Network with CAPA
    2: # Handler to display the classlist 
    3: #
    4: # $Id: lonviewclasslist.pm,v 1.6 2006/03/15 19:41:26 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 $start      = &Apache::loncommon::start_page('Classlist');
   80:     my $breadcrumbs= &Apache::lonhtmlcommon::breadcrumbs(undef,
   81: 							 'Enrollment Manager');
   82:     $r->print(<<ENDHEADER);
   83: $start_page
   84: $breadcrumbs
   85: ENDHEADER
   86:     #
   87:     # Print classlist
   88:     my $cid = $env{'request.course.id'};
   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
   99:     $r->print(&Apache::loncommon::end_page());
  100:     return OK;
  101: }
  102: 
  103: sub allowed_to_view_classlist {
  104:     return 0 if (! exists($env{'request.course.id'}));
  105:     my $cid = $env{'request.course.id'};
  106:     my $viewpermission = 'course.'.$cid.'.student_classlist_view';
  107:     if (exists($env{$viewpermission}) &&
  108:         $env{$viewpermission} =~ /^(all|section)$/) {
  109:         return $env{$viewpermission};
  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) {
  119:         if ($env{'request.course.sec'} eq '') {
  120:             $Str .= '<h2>'.
  121:                 &mt('Students with no section').'</h2>';
  122:         } else {
  123:             $Str.='<h2>'.
  124:                 &mt('Students in section "[_1]"',
  125:                     $env{'request.course.sec'}).
  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];
  163:         next if (lc($status) ne 'active');
  164:         if ($limit_to_section) {
  165:             if ($section ne $env{'request.course.sec'}) {
  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
  176:             ('<img src="/adm/lonIcons/mailto.gif" border="0" />&nbsp;'.
  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>