Annotation of loncom/interface/londropadd.pm, revision 1.89

1.1       www         1: # The LearningOnline Network with CAPA
                      2: # Handler to drop and add students in courses 
                      3: #
1.89    ! matthew     4: # $Id: londropadd.pm,v 1.88 2003/11/06 20:04:06 matthew Exp $
1.17      albertel    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: #
1.1       www        28: # (Handler to set parameters for assessments
                     29: #
                     30: # (Handler to resolve ambiguous file locations
                     31: #
                     32: # (TeX Content Handler
                     33: #
1.50      matthew    34: ###############################################################
1.82      www        35: ##############################################################
1.1       www        36: 
                     37: package Apache::londropadd;
                     38: 
                     39: use strict;
1.24      albertel   40: use Apache::lonnet();
                     41: use Apache::loncommon();
1.50      matthew    42: use Apache::lonhtmlcommon();
1.1       www        43: use Apache::Constants qw(:common :http REDIRECT);
1.60      matthew    44: use Spreadsheet::WriteExcel;
1.86      www        45: use Apache::lonlocal;
1.1       www        46: 
1.50      matthew    47: ###############################################################
                     48: ###############################################################
1.10      www        49: sub header {
1.46      www        50:     my $bodytag=&Apache::loncommon::bodytag('Enrollment Manager');
1.88      matthew    51:     my $title = &mt('LON-CAPA Enrollment Manager');
1.27      matthew    52:     return(<<ENDHEAD);
1.1       www        53: <html>
                     54: <head>
1.88      matthew    55: <title>$title</title>
1.1       www        56: </head>
1.46      www        57: $bodytag
1.40      matthew    58: <form method="post" enctype="multipart/form-data"  
                     59:       action="/adm/dropadd" name="studentform">
1.1       www        60: ENDHEAD
1.10      www        61: }
                     62: 
1.50      matthew    63: ###############################################################
                     64: ###############################################################
                     65: # Drop student from all sections of a course, except optional $csec
1.26      matthew    66: sub modifystudent {
1.33      matthew    67:     my ($udom,$unam,$courseid,$csec,$desiredhost)=@_;
1.26      matthew    68:     # if $csec is undefined, drop the student from all the courses matching
                     69:     # this one.  If $csec is defined, drop them from all other sections of 
                     70:     # this course and add them to section $csec
1.25      matthew    71:     $courseid=~s/\_/\//g;
                     72:     $courseid=~s/^(\w)/\/$1/;
1.26      matthew    73:     my %roles = &Apache::lonnet::dump('roles',$udom,$unam);
                     74:     my ($tmp) = keys(%roles);
                     75:     # Bail out if we were unable to get the students roles
1.35      matthew    76:     return "$1" if ($tmp =~ /^(con_lost|error|no_such_host)/i);
1.26      matthew    77:     # Go through the roles looking for enrollment in this course
1.35      matthew    78:     my $result = '';
1.26      matthew    79:     foreach my $course (keys(%roles)) {
1.35      matthew    80:         if ($course=~/^$courseid(?:\/)*(?:\s+)*(\w+)*\_st$/) {
1.26      matthew    81:             # We are in this course
1.25      matthew    82:             my $section=$1;
1.26      matthew    83:             $section='' if ($course eq $courseid.'_st');
1.87      matthew    84:             if (defined($csec) && $section eq $csec) {
1.71      matthew    85:                 $result .= 'ok:';
                     86:             } elsif ( ((!$section) && (!$csec)) || ($section ne $csec) ) {
1.27      matthew    87:                 my (undef,$end,$start)=split(/\_/,$roles{$course});
1.25      matthew    88:                 my $now=time;
1.50      matthew    89:                 # if this is an active role 
1.27      matthew    90:                 if (!($start && ($now<$start)) || !($end && ($now>$end))) {
1.25      matthew    91:                     my $reply=&Apache::lonnet::modifystudent
1.70      matthew    92:                         # dom  name  id mode pass     f     m     l     g
                     93:                         ($udom,$unam,'',  '',  '',undef,undef,undef,undef,
1.33      matthew    94:                          $section,time,undef,undef,$desiredhost);
1.35      matthew    95:                     $result .= $reply.':';
1.25      matthew    96:                 }
1.10      www        97:             }
                     98:         }
1.20      harris41   99:     }
1.35      matthew   100:     if ($result eq '') {
1.62      matthew   101:         $result = 'Unable to find section for this student';
1.37      matthew   102:     } else {
                    103:         $result =~ s/(ok:)+/ok/g;
1.35      matthew   104:     }
                    105:     return $result;
1.10      www       106: }
                    107: 
1.50      matthew   108: ###############################################################
                    109: ###############################################################
                    110: # build a domain and server selection form
1.31      matthew   111: sub domain_form {
                    112:     my ($defdom) = @_;
                    113:     # Set up domain and server selection forms
                    114:     #
                    115:     # Get the domains
                    116:     my @domains = &Apache::loncommon::get_domains();
                    117:     # build up the menu information to be passed to 
                    118:     # &Apache::loncommon::linked_select_forms
                    119:     my %select_menus;
                    120:     foreach my $dom (@domains) {
                    121:         # set up the text for this domain
                    122:         $select_menus{$dom}->{'text'}= $dom;
                    123:         # we want a choice of 'default' as the default in the second menu
                    124:         $select_menus{$dom}->{'default'}= 'default';
                    125:         $select_menus{$dom}->{'select2'}->{'default'} = 'default';
                    126:         # Now build up the other items in the second menu
1.45      matthew   127:         my %servers = &Apache::loncommon::get_library_servers($dom);
1.31      matthew   128:         foreach my $server (keys(%servers)) {
                    129:             $select_menus{$dom}->{'select2'}->{$server} 
                    130:                                             = "$server $servers{$server}";
                    131:         }
                    132:     }
                    133:     my $result  = &Apache::loncommon::linked_select_forms
                    134:         ('studentform',' with home server ',$defdom,
                    135:          'lcdomain','lcserver',\%select_menus);
                    136:     return $result;
                    137: }
                    138: 
1.50      matthew   139: ###############################################################
                    140: ###############################################################
                    141: #  Menu Phase One
                    142: sub print_main_menu {
1.10      www       143:     my $r=shift;
1.88      matthew   144:     my %Text = &Apache::lonlocal::texthash
                    145:         ('upload'    => 'Upload a class list',
                    146:          'enrollone' => 'Enroll a single student',
                    147:          'modify'    => 'Modify student data',
                    148:          'view'      => 'View Class List',
                    149:          'drop'      => 'Drop Students');
                    150: 
1.48      matthew   151:     $r->print(<<END);
                    152: <p>
1.50      matthew   153: <font size="+1">
1.88      matthew   154:     <a href="/adm/dropadd?action=upload">$Text{'upload'}</a>
1.50      matthew   155: </font>
                    156: </p><p>
                    157: <font size="+1">
1.88      matthew   158:     <a href="/adm/dropadd?action=enrollstudent">$Text{'enrollone'}</a>
1.50      matthew   159: </font>
1.48      matthew   160: </p><p>
1.50      matthew   161: <font size="+1">
1.88      matthew   162:     <a href="/adm/dropadd?action=modifystudent">$Text{'modify'}</a>
1.50      matthew   163: </font>
1.48      matthew   164: </p><p>
1.50      matthew   165: <font size="+1">
1.88      matthew   166:     <a href="/adm/dropadd?action=classlist">$Text{'view'}</a>
1.50      matthew   167: </font>
1.48      matthew   168: </p><p>
1.50      matthew   169: <font size="+1">
1.88      matthew   170:     <a href="/adm/dropadd?action=drop">$Text{'drop'}</a>
1.50      matthew   171: </font>
1.48      matthew   172: </p>
                    173: END
1.10      www       174: }
                    175: 
1.50      matthew   176: ###############################################################
                    177: ###############################################################
1.89    ! matthew   178: sub hidden_input {
        !           179:     my ($name,$value) = @_;
        !           180:     return '<input type="hidden" name="'.$name.'" value="'.$value.'" />'."\n";
        !           181: }
        !           182: 
1.50      matthew   183: sub print_upload_manager_header {
1.23      albertel  184:     my ($r,$datatoken,$distotal,$krbdefdom)=@_;
1.24      albertel  185:     my $javascript;
1.50      matthew   186:     if (! exists($ENV{'form.upfile_associate'})) {
                    187:         $ENV{'form.upfile_associate'} = 'forward';
                    188:     }
                    189:     if ($ENV{'form.associate'} eq 'Reverse Association') {
                    190:         if ( $ENV{'form.upfile_associate'} ne 'reverse' ) {
                    191:             $ENV{'form.upfile_associate'} = 'reverse';
                    192:         } else {
                    193:             $ENV{'form.upfile_associate'} = 'forward';
                    194:         }
                    195:     }
1.24      albertel  196:     if ($ENV{'form.upfile_associate'} eq 'reverse') {
1.50      matthew   197: 	$javascript=&upload_manager_javascript_reverse_associate();
1.24      albertel  198:     } else {
1.50      matthew   199: 	$javascript=&upload_manager_javascript_forward_associate();
1.24      albertel  200:     }
1.89    ! matthew   201:     my $javascript_validations=&javascript_validations('auth',$krbdefdom);
1.82      www       202:     my $checked=(($ENV{'form.noFirstLine'})?' checked="1"':'');
1.88      matthew   203:     $r->print('<h3>'.&mt('Uploading Class List')."</h3>\n".
                    204:               "<hr>\n".
                    205:               '<h3>'.&mt('Identify fields')."</h3>\n");
                    206:     $r->print("<p>\n".
                    207:               &mt('Total number of records found in file: [_1].',$distotal).
                    208:               "\n".
                    209:               "</p><hr>\n");
1.89    ! matthew   210:     $r->print(&mt('Enter as many fields as you can. '.
        !           211:                   'The system will inform you and bring you back to '.
        !           212:                   'this page if the data selected is insufficient to '.
        !           213:                   'enroll students in your class.')."<hr>\n");
        !           214:     $r->print(&hidden_input('action','upload').
        !           215:               &hidden_input('state','got_file').
        !           216:               &hidden_input('associate','').
        !           217:               &hidden_input('datatoken',$datatoken).
        !           218:               &hidden_input('fileupload',$ENV{'form.fileupload'}).
        !           219:               &hidden_input('upfiletype',$ENV{'form.upfiletype'}).
        !           220:               &hidden_input('upfile_associate',$ENV{'form.upfile_associate'}));
        !           221:     $r->print('<input type="button" value="Reverse Association" '.
        !           222:               'name="'.&mt('Reverse Association').'" '.
        !           223:               'onClick="javascript:this.form.associate.value=\'Reverse Association\';submit(this.form);" />');
        !           224:     $r->print('<input type="checkbox" name="noFirstLine" $checked />'.
        !           225:               &mt('Ignore First Line'));
        !           226:     $r->print("<hr />\n".
        !           227:               '<script type="text/javascript" language="Javascript">'."\n".
        !           228:               $javascript."\n".$javascript_validations.'</script>');
1.24      albertel  229: }
                    230: 
1.50      matthew   231: ###############################################################
                    232: ###############################################################
1.24      albertel  233: sub javascript_validations {
1.89    ! matthew   234:     my ($mode,$krbdefdom)=@_;
        !           235:     my $authheader;
        !           236:     if ($mode eq 'auth') {
        !           237:         my %param = ( formname => 'studentform',
        !           238:                       kerb_def_dom => $krbdefdom );
        !           239:         $authheader = &Apache::loncommon::authform_header(%param);
        !           240:     }
        !           241:     my %alert = &Apache::lonlocal::texthash
        !           242:         (username => 'You need to specify the username field.',
        !           243:          authen   => 'You must choose an authentication type.',
        !           244:          krb      => 'You need to specify the Kerberos domain.',
        !           245:          ipass    => 'You need to specify the initial password.',
        !           246:          name     => 'The optional name field was not specified.',
        !           247:          snum     => 'The optional student number field was not specified.',
        !           248:          section  => 'The optional section or group field was not specified.', 
        !           249:          email    => 'The optional email address field was not specified.',
        !           250:          continue => 'Continue enrollment?',
        !           251:          );
        !           252:     
        !           253: #    my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
        !           254:     my $function_name =(<<END);
1.73      www       255: function verify_message (vf,founduname,foundpwd,foundname,foundid,foundsec,foundemail) {
1.89    ! matthew   256: END
        !           257:     my $auth_checks = (<<END);
1.3       www       258:     var foundatype=0;
                    259:     if (founduname==0) {
1.89    ! matthew   260: 	alert('$alert{'username'}');
1.3       www       261:         return;
                    262:     }
1.61      matthew   263:     // alert('current.radiovalue = '+current.radiovalue);
1.29      matthew   264:     if (current.radiovalue == null || current.radiovalue == 'nochange') {
1.28      matthew   265:         // They did not check any of the login radiobuttons.
1.89    ! matthew   266:         alert('$alert{'authen'}');
1.28      matthew   267:         return;
                    268:     }
                    269:     foundatype=1;
1.29      matthew   270:     if (current.argfield == null || current.argfield == '') {
1.28      matthew   271:         var alertmsg = '';
1.29      matthew   272:         switch (current.value) {
1.28      matthew   273:             case 'krb': 
1.89    ! matthew   274:                 alertmsg = '$alert{'krb'}';
1.28      matthew   275:                 break;
                    276:             case 'loc':
                    277:             case 'fsys':
1.89    ! matthew   278:                 alertmsg = '$alert{'ipass'}';
1.28      matthew   279:                 break;
                    280:             case 'fsys':
                    281:                 alertmsg = '';
                    282:                 break;
                    283:             default: 
                    284:                 alertmsg = '';
1.3       www       285:         }
1.28      matthew   286:         if (alertmsg != '') {
                    287:             alert(alertmsg);
1.3       www       288:             return;
                    289:         }
                    290:     }
1.89    ! matthew   291: END
        !           292:     my $optional_checks = (<<END);
        !           293:     var message='';
        !           294:     if (foundname==0) { 
        !           295:         message='$alert{'name'}';
1.24      albertel  296:     }
1.89    ! matthew   297:     if (foundid==0) { 
        !           298:         if (message!='') { 
        !           299:             message+='\\n'; 
        !           300:         }
        !           301:         message+='$alert{'snum'}';
        !           302:     }
        !           303:     if (foundsec==0) {
        !           304:         if (message!='') {
        !           305:             message+='\\n';
        !           306:         } 
        !           307:         message+='$alert{'section'}';
        !           308:     }
        !           309:     if (foundemail==0) {
        !           310:         if (message!='') {
        !           311:             message+='\\n';
        !           312:         }
        !           313:         message+='$alert{'email'}';
1.74      matthew   314:     }
                    315:     if (message!='') {
1.89    ! matthew   316:         message+= '\\n$alert{'continue'}';
        !           317:         if (confirm(message)) {
        !           318:             vf.state.value='enrolling';
        !           319:             vf.submit();
        !           320:         }
1.74      matthew   321:     } else {
1.89    ! matthew   322:         vf.state.value='enrolling';
        !           323:         vf.submit();
1.74      matthew   324:     }
                    325: }
                    326: 
1.89    ! matthew   327: END
        !           328:     my $result = $function_name;
        !           329:     if ($mode eq 'auth') {
        !           330:         $result .= $auth_checks;
        !           331:     }
        !           332:     $result .= $optional_checks;
        !           333:     if ($mode eq 'auth') {
        !           334:         $result .= $authheader;
        !           335:     }
        !           336:     return $result;
1.74      matthew   337: }
                    338: 
1.50      matthew   339: ###############################################################
                    340: ###############################################################
                    341: sub upload_manager_javascript_forward_associate {
1.24      albertel  342:     return(<<ENDPICK);
                    343: function verify(vf) {
                    344:     var founduname=0;
                    345:     var foundpwd=0;
                    346:     var foundname=0;
                    347:     var foundid=0;
                    348:     var foundsec=0;
1.73      www       349:     var foundemail=0;
1.24      albertel  350:     var tw;
                    351:     for (i=0;i<=vf.nfields.value;i++) {
                    352:         tw=eval('vf.f'+i+'.selectedIndex');
                    353:         if (tw==1) { founduname=1; }
                    354:         if ((tw>=2) && (tw<=6)) { foundname=1; }
                    355:         if (tw==7) { foundid=1; }
                    356:         if (tw==8) { foundsec=1; }
                    357:         if (tw==9) { foundpwd=1; }
1.73      www       358:         if (tw==10) { foundemail=1; }
1.24      albertel  359:     }
1.73      www       360:     verify_message(vf,founduname,foundpwd,foundname,foundid,foundsec,foundemail);
1.24      albertel  361: }
                    362: 
1.49      matthew   363: //
                    364: // vf = this.form
                    365: // tf = column number
                    366: //
                    367: // values of nw
                    368: //
                    369: // 0 = none
                    370: // 1 = username
                    371: // 2 = names (lastname, firstnames)
                    372: // 3 = fname (firstname)
                    373: // 4 = mname (middlename)
                    374: // 5 = lname (lastname)
                    375: // 6 = gen   (generation)
                    376: // 7 = id
                    377: // 8 = section
                    378: // 9 = ipwd  (password)
1.73      www       379: // 10 = email address
                    380: 
1.24      albertel  381: function flip(vf,tf) {
                    382:    var nw=eval('vf.f'+tf+'.selectedIndex');
                    383:    var i;
1.49      matthew   384:    // make sure no other columns are labeled the same as this one
1.24      albertel  385:    for (i=0;i<=vf.nfields.value;i++) {
                    386:       if ((i!=tf) && (eval('vf.f'+i+'.selectedIndex')==nw)) {
                    387:           eval('vf.f'+i+'.selectedIndex=0;')
                    388:       }
                    389:    }
1.49      matthew   390:    // If we set this to 'lastname, firstnames', clear out all the ones
                    391:    // set to 'fname','mname','lname','gen' (3,4,5,6) currently.
1.24      albertel  392:    if (nw==2) {
                    393:       for (i=0;i<=vf.nfields.value;i++) {
                    394:          if ((eval('vf.f'+i+'.selectedIndex')>=3) &&
                    395:              (eval('vf.f'+i+'.selectedIndex')<=6)) {
                    396:              eval('vf.f'+i+'.selectedIndex=0;')
                    397:          }
                    398:       }
                    399:    }
1.49      matthew   400:    // If we set this to one of 'fname','mname','lname','gen' (3,4,5,6),
                    401:    // clear out any that are set to 'lastname, firstnames' (2)
1.24      albertel  402:    if ((nw>=3) && (nw<=6)) {
                    403:       for (i=0;i<=vf.nfields.value;i++) {
                    404:          if (eval('vf.f'+i+'.selectedIndex')==2) {
                    405:              eval('vf.f'+i+'.selectedIndex=0;')
                    406:          }
                    407:       }
                    408:    }
1.49      matthew   409:    // If we set the password, make the password form below correspond to 
                    410:    // the new value.
1.24      albertel  411:    if (nw==9) {
1.28      matthew   412:        changed_radio('int',document.studentform);
                    413:        set_auth_radio_buttons('int',document.studentform);
                    414:        vf.intarg.value='';
                    415:        vf.krbarg.value='';
1.24      albertel  416:        vf.locarg.value='';
                    417:    }
                    418: }
                    419: 
                    420: function clearpwd(vf) {
                    421:     var i;
                    422:     for (i=0;i<=vf.nfields.value;i++) {
                    423:         if (eval('vf.f'+i+'.selectedIndex')==9) {
                    424:             eval('vf.f'+i+'.selectedIndex=0;')
                    425:         }
                    426:     }
                    427: }
                    428: 
                    429: ENDPICK
                    430: }
                    431: 
1.50      matthew   432: ###############################################################
                    433: ###############################################################
                    434: sub upload_manager_javascript_reverse_associate {
1.24      albertel  435:     return(<<ENDPICK);
                    436: function verify(vf) {
                    437:     var founduname=0;
                    438:     var foundpwd=0;
                    439:     var foundname=0;
                    440:     var foundid=0;
                    441:     var foundsec=0;
                    442:     var tw;
                    443:     for (i=0;i<=vf.nfields.value;i++) {
                    444:         tw=eval('vf.f'+i+'.selectedIndex');
                    445:         if (i==0 && tw!=0) { founduname=1; }
                    446:         if (((i>=1) && (i<=5)) && tw!=0 ) { foundname=1; }
                    447:         if (i==6 && tw!=0) { foundid=1; }
                    448:         if (i==7 && tw!=0) { foundsec=1; }
                    449:         if (i==8 && tw!=0) { foundpwd=1; }
                    450:     }
                    451:     verify_message(vf,founduname,foundpwd,foundname,foundid,foundsec);
                    452: }
                    453: 
                    454: function flip(vf,tf) {
                    455:    var nw=eval('vf.f'+tf+'.selectedIndex');
                    456:    var i;
                    457:    // picked the all one one name field, reset the other name ones to blank
                    458:    if (tf==1 && nw!=0) {
                    459:       for (i=2;i<=5;i++) {
                    460:          eval('vf.f'+i+'.selectedIndex=0;')
                    461:       }
                    462:    }
                    463:    //picked one of the piecewise name fields, reset the all in
                    464:    //one field to blank
                    465:    if ((tf>=2) && (tf<=5) && (nw!=0)) {
                    466:       eval('vf.f1.selectedIndex=0;')
                    467:    }
                    468:    // intial password specified, pick internal authentication
                    469:    if (tf==8 && nw!=0) {
1.28      matthew   470:        changed_radio('int',document.studentform);
                    471:        set_auth_radio_buttons('int',document.studentform);
                    472:        vf.krbarg.value='';
                    473:        vf.intarg.value='';
1.24      albertel  474:        vf.locarg.value='';
                    475:    }
                    476: }
                    477: 
                    478: function clearpwd(vf) {
                    479:     var i;
                    480:     if (eval('vf.f8.selectedIndex')!=0) {
                    481:         eval('vf.f8.selectedIndex=0;')
                    482:     }
                    483: }
1.2       www       484: ENDPICK
1.23      albertel  485: }
1.10      www       486: 
1.50      matthew   487: ###############################################################
                    488: ###############################################################
                    489: sub print_upload_manager_footer {
1.23      albertel  490:     my ($r,$i,$keyfields,$defdom,$today,$halfyear)=@_;
1.64      albertel  491: 
                    492:     my ($krbdef,$krbdefdom) =
                    493:         &Apache::loncommon::get_kerberos_defaults($defdom);
                    494:     my %param = ( formname => 'document.studentform',
                    495:                   kerb_def_dom => $krbdefdom,
                    496:                   kerb_def_auth => $krbdef
                    497:                   );
1.28      matthew   498:     my $krbform = &Apache::loncommon::authform_kerberos(%param);
                    499:     my $intform = &Apache::loncommon::authform_internal(%param);
                    500:     my $locform = &Apache::loncommon::authform_local(%param);
1.31      matthew   501:     my $domform = &domain_form($defdom);
1.68      matthew   502:     my $date_table = &date_setting_table();
1.23      albertel  503:     $r->print(<<ENDPICK);
1.3       www       504: </table>
1.88      matthew   505: <input type="hidden" name="nfields" value="$i">
                    506: <input type="hidden" name="keyfields" value="$keyfields">
1.3       www       507: <h3>Login Type</h3>
1.15      albertel  508: <p>Note: this will not take effect if the user already exists</p>
                    509: <p>
1.28      matthew   510: $krbform
1.15      albertel  511: </p>
                    512: <p>
1.28      matthew   513: $intform
1.15      albertel  514: </p>
                    515: <p>
1.28      matthew   516: $locform
1.15      albertel  517: </p>
1.5       www       518: <h3>LON-CAPA Domain for Students</h3>
1.29      matthew   519: LON-CAPA domain: $domform <p>
1.5       www       520: <h3>Starting and Ending Dates</h3>
1.68      matthew   521: <p>
                    522: $date_table
                    523: </p>
1.5       www       524: <h3>Full Update</h3>
                    525: <input type=checkbox name=fullup value=yes> Full update 
1.11      www       526: (also print list of users not enrolled anymore)<p>
1.18      www       527: <h3>ID/Student Number</h3>
                    528: <input type=checkbox name=forceid value=yes> 
                    529: Disable ID/Student Number Safeguard and Force Change of Conflicting IDs
1.19      www       530: (only do if you know what you are doing)<p>
1.36      albertel  531: <input type="button" onClick="javascript:verify(this.form)" value="Update Courselist" /><br />
1.50      matthew   532: Note: for large courses, this operation may be time consuming.
1.3       www       533: ENDPICK
1.23      albertel  534: }
1.24      albertel  535: 
1.23      albertel  536: # ======================================================= Menu Phase Two Upload
1.50      matthew   537: sub print_upload_manager_form {
1.23      albertel  538:     my $r=shift;
1.82      www       539:     my $firstLine;
1.24      albertel  540:     my $datatoken;
                    541:     if (!$ENV{'form.datatoken'}) {
1.26      matthew   542:       $datatoken=&Apache::loncommon::upfile_store($r);
1.24      albertel  543:     } else {
1.26      matthew   544:       $datatoken=$ENV{'form.datatoken'};
                    545:       &Apache::loncommon::load_tmp_file($r);
1.24      albertel  546:     }
                    547:     my @records=&Apache::loncommon::upfile_record_sep();
1.82      www       548:     if($ENV{'form.noFirstLine'}){$firstLine=shift(@records);}
1.23      albertel  549:     my $total=$#records;
                    550:     my $distotal=$total+1;
                    551:     my $today=time;
                    552:     my $halfyear=$today+15552000;
1.85      matthew   553:     my $defdom=$ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
1.64      albertel  554:     my ($krbdef,$krbdefdom) =
                    555:         &Apache::loncommon::get_kerberos_defaults($defdom);
1.50      matthew   556:     &print_upload_manager_header($r,$datatoken,$distotal,$krbdefdom);
1.24      albertel  557:     my $i;
                    558:     my $keyfields;
1.23      albertel  559:     if ($total>=0) {
1.50      matthew   560: 	my @d=(['username','Username'],
                    561:                ['names','Last Name, First Names'],
                    562: 	       ['fname','First Name'],
                    563:                ['mname','Middle Names/Initials'],
                    564: 	       ['lname','Last Name'],
                    565:                ['gen','Generation'],
                    566: 	       ['id','ID/Student Number'],
                    567:                ['sec','Group/Section'],
1.73      www       568: 	       ['ipwd','Initial Password'],
                    569:                ['email','EMail Address']);
1.24      albertel  570: 	if ($ENV{'form.upfile_associate'} eq 'reverse') {	
                    571: 	    &Apache::loncommon::csv_print_samples($r,\@records);
                    572: 	    $i=&Apache::loncommon::csv_print_select_table($r,\@records,\@d);
                    573: 	    foreach (@d) { $keyfields.=$_->[0].','; }
                    574: 	    chop($keyfields);
                    575: 	} else {
                    576: 	    unshift(@d,['none','']);
                    577: 	    $i=&Apache::loncommon::csv_samples_select_table($r,\@records,\@d);
                    578: 	    my %sone=&Apache::loncommon::record_sep($records[0]);
                    579: 	    $keyfields=join(',',sort(keys(%sone)));
1.23      albertel  580: 	}
                    581:     }
1.50      matthew   582:     &print_upload_manager_footer($r,$i,$keyfields,$defdom,$today,$halfyear);
1.10      www       583: }
                    584: 
1.12      www       585: # ======================================================= Enroll single student
                    586: sub enroll_single_student {
                    587:     my $r=shift;
1.80      matthew   588:     # Remove non alphanumeric values from section
                    589:     $ENV{'form.csec'}=~s/\W//g;
1.68      matthew   590:     #
                    591:     # We do the dates first because the action of making them the defaul
                    592:     # in the course is entirely seperate from the action of enrolling the
                    593:     # student.  Also, a failure in setting the dates as default is not fatal
                    594:     # to the process of enrolling / modifying a student.
                    595:     my ($startdate,$enddate) = &get_dates_from_form();
                    596:     if ($ENV{'form.makedatesdefault'}) {
                    597:         $r->print(&make_dates_default($startdate,$enddate));
                    598:     }
                    599: 
1.12      www       600:     $r->print('<h3>Enrolling Student</h3>');
1.54      matthew   601:     $r->print('<p>Enrolling '.$ENV{'form.cuname'}." \@ ".
1.34      matthew   602:               $ENV{'form.lcdomain'}.'</p>');
1.12      www       603:     if (($ENV{'form.cuname'})&&($ENV{'form.cuname'}!~/\W/)&&
1.31      matthew   604:         ($ENV{'form.lcdomain'})&&($ENV{'form.lcdomain'}!~/\W/)) {
                    605:         # Deal with home server selection
                    606:         my $domain=$ENV{'form.lcdomain'};
                    607:         my $desiredhost = $ENV{'form.lcserver'};
                    608:         if (lc($desiredhost) eq 'default') {
                    609:             $desiredhost = undef;
                    610:         } else {
1.45      matthew   611:             my %home_servers =&Apache::loncommon::get_library_servers($domain);
1.31      matthew   612:             if (! exists($home_servers{$desiredhost})) {
                    613:                 $r->print('<font color="#ff0000">Error:</font>'.
                    614:                           'Invalid home server specified');
                    615:                 return;
                    616:             }
                    617:         }
1.34      matthew   618:         $r->print(" with server $desiredhost :") if (defined($desiredhost));
1.31      matthew   619:         # End of home server selection logic
1.12      www       620: 	my $amode='';
                    621:         my $genpwd='';
                    622:         if ($ENV{'form.login'} eq 'krb') {
1.47      albertel  623:            $amode='krb';
                    624: 	   $amode.=$ENV{'form.krbver'};
1.28      matthew   625:            $genpwd=$ENV{'form.krbarg'};
1.12      www       626:         } elsif ($ENV{'form.login'} eq 'int') {
1.26      matthew   627:            $amode='internal';
1.28      matthew   628:            $genpwd=$ENV{'form.intarg'};
1.15      albertel  629:         }  elsif ($ENV{'form.login'} eq 'loc') {
                    630: 	    $amode='localauth';
                    631: 	    $genpwd=$ENV{'form.locarg'};
                    632: 	    if (!$genpwd) { $genpwd=" "; }
                    633: 	}
1.34      matthew   634:         my $home = &Apache::lonnet::homeserver($ENV{'form.cuname'},
                    635:                                                    $ENV{'form.lcdomain'});
                    636:         if ((($amode) && ($genpwd)) || ($home ne 'no_host')) {
1.55      matthew   637:             # Clean out any old roles the student has in this class.
1.33      matthew   638:             &modifystudent($ENV{'form.lcdomain'},$ENV{'form.cuname'},
                    639:                            $ENV{'request.course.id'},$ENV{'form.csec'},
                    640:                             $desiredhost);
1.55      matthew   641:             my $login_result = &Apache::lonnet::modifystudent
                    642:                 ($ENV{'form.lcdomain'},$ENV{'form.cuname'},
                    643:                  $ENV{'form.cstid'},$amode,$genpwd,
                    644:                  $ENV{'form.cfirst'},$ENV{'form.cmiddle'},
                    645:                  $ENV{'form.clast'},$ENV{'form.cgen'},
1.67      matthew   646:                  $ENV{'form.csec'},$enddate,
                    647:                  $startdate,$ENV{'form.forceid'},
1.55      matthew   648:                  $desiredhost);
                    649:             if ($login_result =~ /^ok/) {
                    650:                 $r->print($login_result);
                    651:                 $r->print("<p> If active, the new role will be available ".
                    652:                           "when the student next logs in to LON-CAPA.</p>");
                    653:             } else {
                    654:                 $r->print("unable to enroll: ".$login_result);
                    655:             }
1.12      www       656: 	} else {
1.79      matthew   657:             $r->print('<p><font color="#ff0000">ERROR</font>&nbsp;');
                    658:             if ($amode =~ /^krb/) {
                    659:                 $r->print('Missing Kerberos domain information.  ');
                    660:             } else {
                    661:                 $r->print('Invalid login mode or password.  ');
                    662:             }
                    663:             $r->print('<b>Unable to enroll '.$ENV{'form.cuname'}.'.</b></p>');
                    664:         }
1.12      www       665:     } else {
                    666:         $r->print('Invalid username or domain');
1.26      matthew   667:     }    
1.12      www       668: }
                    669: 
1.68      matthew   670: sub setup_date_selectors {
                    671:     my ($starttime,$endtime) = @_;
                    672:     if (! defined($starttime)) {
                    673:         $starttime = time;
                    674:         if (exists($ENV{'course.'.$ENV{'request.course.id'}.
                    675:                             '.default_enrollment_start_date'})) {
                    676:             $starttime = $ENV{'course.'.$ENV{'request.course.id'}.
                    677:                                   '.default_enrollment_start_date'};
                    678:         }
                    679:     }
                    680:     if (! defined($endtime)) {
                    681:         $endtime = time+(6*30*24*60*60); # 6 months from now, approx
                    682:         if (exists($ENV{'course.'.$ENV{'request.course.id'}.
                    683:                             '.default_enrollment_end_date'})) {
                    684:             $endtime = $ENV{'course.'.$ENV{'request.course.id'}.
                    685:                                 '.default_enrollment_end_date'};
                    686:         }
                    687:     }
                    688:     my $startdateform = &Apache::lonhtmlcommon::date_setter('studentform',
                    689:                                                             'startdate',
                    690:                                                             $starttime);
                    691:     my $enddateform = &Apache::lonhtmlcommon::date_setter('studentform',
                    692:                                                           'enddate',
                    693:                                                           $endtime);
                    694:     return ($startdateform,$enddateform);
                    695: }
                    696: 
                    697: sub get_dates_from_form {
                    698:     my $startdate = &Apache::lonhtmlcommon::get_date_from_form('startdate');
                    699:     my $enddate   = &Apache::lonhtmlcommon::get_date_from_form('enddate');
                    700:     if ($ENV{'form.no_end_date'}) {
                    701:         $enddate = 0;
                    702:     }
                    703:     return ($startdate,$enddate);
                    704: }
                    705: 
                    706: sub date_setting_table {
                    707:     my ($starttime,$endtime) = @_;
                    708:     my ($startform,$endform)=&setup_date_selectors($starttime,$endtime);
                    709:     my $dateDefault = '<nobr>'.
                    710:         '<input type="checkbox" name="makedatesdefault" />'.
                    711:         ' make these dates the default for future enrollment';
                    712:     my $perpetual = '<nobr><input type="checkbox" name="no_end_date"';
                    713:     if (defined($endtime) && $endtime == 0) {
                    714:         $perpetual .= ' checked';
                    715:     }
                    716:     $perpetual.= ' />'.' no ending date</nobr>';
                    717:     my $result = '';
                    718:     $result .= "<table>\n";
                    719:     $result .= '<tr><td align="right">Starting Date</td>'.
                    720:         '<td>'.$startform.'</td>'.
                    721:         '<td>'.$dateDefault.'</td>'."</tr>\n";
                    722:     $result .= '<tr><td align="right">Ending Date</td>'.
                    723:         '<td>'.$endform.'</td>'.
                    724:         '<td>'.$perpetual.'</td>'."</tr>\n";
                    725:     $result .= "</table>\n";
                    726:     return $result;
                    727: }
                    728: 
                    729: sub make_dates_default {
                    730:     my ($startdate,$enddate) = @_;
                    731:     my $result = '';
                    732:     my $dom = $ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
                    733:     my $crs = $ENV{'course.'.$ENV{'request.course.id'}.'.num'};
                    734:     my $put_result = &Apache::lonnet::put('environment',
                    735:             {'default_enrollment_start_date'=>$startdate,
                    736:              'default_enrollment_end_date'  =>$enddate},$dom,$crs);
                    737:     if ($put_result eq 'ok') {
                    738:         $result .= "Set default start and end dates for course<br />";
1.69      matthew   739:         #
                    740:         # Refresh the course environment
                    741:         &Apache::lonnet::coursedescription($ENV{'request.course.id'});
1.68      matthew   742:     } else {
                    743:         $result .= "Unable to set default dates for course:".$put_result.
                    744:             '<br />';
                    745:     }
                    746:     return $result;
                    747: }
                    748: 
1.74      matthew   749: ##
                    750: ## Single student enrollment routines (some of them)
                    751: ##
                    752: sub get_student_username_domain_form {
                    753:     my $r = shift;
                    754:     my $domform = &Apache::loncommon::select_dom_form
1.85      matthew   755:         ($ENV{'course.'.$ENV{'request.course.id'}.'.domain'},'cudomain',0);
1.74      matthew   756:     $r->print(<<END);
                    757: <input type="hidden" name="action" value="enrollstudent" />
                    758: <input type="hidden" name="state"  value="gotusername" />
                    759: <h3>Enroll One Student</h3>
                    760: <table>
                    761: <tr><th>Username:</th>
                    762:     <td><input type="text" name="cuname"  size="15" /></td></tr>
                    763: <tr><th>Domain:</th>
                    764:     <td>$domform</td></tr>
                    765: <tr><th>&nbsp;</th>
                    766:     <td>
                    767:     <input type="submit" name="Begin Enrollment" value="Begin Enrollment" />
                    768:     </td></tr>
                    769: </table>
                    770: END
                    771:     return;
                    772: }
                    773: 
1.50      matthew   774: sub print_enroll_single_student_form {
1.10      www       775:     my $r=shift;
1.40      matthew   776:     $r->print("<h3>Enroll One Student</h3>");
1.74      matthew   777:     #
                    778:     my $username = $ENV{'form.cuname'};
                    779:     my $domain   = $ENV{'form.cudomain'};
                    780:     my $home = &Apache::lonnet::homeserver($username,$domain);
                    781:     # $new_user flags whether we are creating a new user or using an old one
                    782:     my $new_user = 1;
                    783:     if ($home ne 'no_host') {
                    784:         $new_user = 0;
                    785:     }
                    786:     #
                    787:     my $user_data_html = '';
                    788:     my $javascript_validations = '';
                    789:     if ($new_user) {
1.85      matthew   790:         my $defdom=$ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
1.74      matthew   791:         # Set up authentication forms
                    792:         my ($krbdef,$krbdefdom) =
1.75      matthew   793:             &Apache::loncommon::get_kerberos_defaults($domain);
1.89    ! matthew   794:         $javascript_validations=&javascript_validations('auth',$krbdefdom);
1.74      matthew   795:         my %param = ( formname => 'document.studentform',
                    796:                       kerb_def_dom => $krbdefdom,
                    797:                       kerb_def_auth => $krbdef
                    798:                       );
                    799:         my $krbform = &Apache::loncommon::authform_kerberos(%param);
                    800:         my $intform = &Apache::loncommon::authform_internal(%param);
                    801:         my $locform = &Apache::loncommon::authform_local(%param);
                    802:         #
                    803:         # Set up domain selection form
                    804:         my $homeserver_form = '';
                    805:         my %servers = &Apache::loncommon::get_library_servers($domain);
                    806:         $homeserver_form = '<select name="lcserver" size="1">'."\n".
                    807:             '<option value="default" selected>default</option>'."\n";
                    808:         while (my ($servername,$serverdescription) = each (%servers)) {
                    809:             $homeserver_form .= '<option value="'.$servername.'">'.
                    810:                 $serverdescription."</option>\n";
                    811:         }
                    812:         $homeserver_form .= "</select>\n";
                    813:         #
                    814:         #
                    815:         $user_data_html = <<END;
                    816: <h3>User Data for $username\@$domain</h3>
                    817: <table>
                    818: <tr><th>First Name:</th>
                    819:     <td><input type="text" name="cfirst"  size="15"></td></tr>
                    820: <tr><th>Middle Name:</th>
                    821:     <td><input type="text" name="cmiddle" size="15"></td></tr>
                    822: <tr><th>Last Name:</th>
                    823:     <td><input type="text" name="clast"   size="15"></td></tr>
                    824: <tr><th>Generation:</th>
                    825:     <td><input type="text" name="cgen"    size="5"> </td></tr>
                    826: <tr><th>Home Server:</th>
                    827:     <td>$homeserver_form</td></tr>
                    828: </table>
                    829: <h3>Password</h3>
                    830: Please select an authentication mechanism
                    831: <table>
                    832: <p>
                    833: $krbform
1.75      matthew   834: <br />
1.74      matthew   835: $intform
1.75      matthew   836: <br />
1.74      matthew   837: $locform
                    838: </p>
                    839: END
                    840:     } else {
                    841:         # User already exists.  Do not worry about authentication
                    842:         my %uenv = &Apache::lonnet::dump('environment',$domain,$username);
1.89    ! matthew   843:         $javascript_validations = &javascript_validations('noauth');
1.74      matthew   844:         $user_data_html = <<END;
                    845: <h3>User Data for $username\@$domain</h3>
                    846: <input type="hidden" name="lcserver" value="default" />
                    847: <table>
                    848: <tr><th>First Name:</th>
                    849:     <td>
                    850:     <input type="text" name="cfirst" value="$uenv{'firstname'}" size="15" />
                    851:     </td></tr>
                    852: <tr><th>Middle Name:</th>
                    853:     <td>
                    854:     <input type="text" name="cmiddle" value="$uenv{'middlename'}" size="15" />
                    855:     </td></tr>
                    856: <tr><th>Last Name:</th>
                    857:     <td>
                    858:     <input type="text" name="clast"value="$uenv{'lastname'}" size="15" />
                    859:     </td></tr>
                    860: <tr><th>Generation:</th>
                    861:     <td>
                    862:     <input type="text" name="cgen" value="$uenv{'generation'}" size="5" />
                    863:     </td></tr>
                    864: </table>
                    865: END
                    866:     }
1.68      matthew   867:     my $date_table = &date_setting_table();
1.74      matthew   868:         # Print it all out
1.50      matthew   869:     $r->print(<<END);
1.74      matthew   870: <input type="hidden" name="action" value="enrollstudent" />
                    871: <input type="hidden" name="state"  value="done" />
                    872: <input type="hidden" name="cuname" value="$username" />
                    873: <input type="hidden" name="lcdomain" value="$domain" />
1.28      matthew   874: <script type="text/javascript" language="Javascript">
1.12      www       875: function verify(vf) {
                    876:     var founduname=0;
                    877:     var foundpwd=0;
                    878:     var foundname=0;
                    879:     var foundid=0;
                    880:     var foundsec=0;
                    881:     var tw;
1.26      matthew   882:     if ((typeof(vf.cuname.value) !="undefined") && (vf.cuname.value!='') && 
1.31      matthew   883: 	(typeof(vf.lcdomain.value)!="undefined") && (vf.lcdomain.value!='')) {
1.12      www       884:         founduname=1;
                    885:     }
1.14      harris41  886:     if ((typeof(vf.cfirst.value)!="undefined") && (vf.cfirst.value!='') &&
1.26      matthew   887: 	(typeof(vf.clast.value) !="undefined") && (vf.clast.value!='')) {
1.12      www       888:         foundname=1;
                    889:     }
1.14      harris41  890:     if ((typeof(vf.csec.value)!="undefined") && (vf.csec.value!='')) {
1.12      www       891:         foundsec=1;
                    892:     }
1.14      harris41  893:     if ((typeof(vf.cstid.value)!="undefined") && (vf.cstid.value!='')) {
1.12      www       894: 	foundid=1;
                    895:     }
                    896:     if (founduname==0) {
                    897: 	alert('You need to specify at least the username and domain fields');
                    898:         return;
                    899:     }
1.24      albertel  900:     verify_message(vf,founduname,foundpwd,foundname,foundid,foundsec);
1.12      www       901: }
                    902: 
1.24      albertel  903: $javascript_validations
1.12      www       904: 
1.24      albertel  905: function clearpwd(vf) {
                    906:     //nothing else needs clearing
1.15      albertel  907: }
                    908: 
1.12      www       909: </script>
1.11      www       910: 
1.74      matthew   911: $user_data_html
1.50      matthew   912: 
                    913: <h3>Course Data</h3>
                    914: 
                    915: <p>Group/Section: <input type="text" name="csec" size="5" />
                    916: <p>
1.68      matthew   917: $date_table
1.50      matthew   918: </p>
                    919: <h3>ID/Student Number</h3>
                    920: <p>
                    921: ID/Student Number: <input type="text" name="cstid" size="10">
1.26      matthew   922: </p><p>
                    923: <input type="checkbox" name="forceid" value="yes"> 
1.18      www       924: Disable ID/Student Number Safeguard and Force Change of Conflicting IDs
1.50      matthew   925: (only do if you know what you are doing)
                    926: </p><p>
                    927: <input type="button" onClick="verify(this.form)" value="Enroll as student">
1.26      matthew   928: </p>
1.50      matthew   929: END
                    930:     return;
1.10      www       931: }
                    932: 
                    933: # ========================================================= Menu Phase Two Drop
1.51      matthew   934: sub print_drop_menu {
1.10      www       935:     my $r=shift;
1.40      matthew   936:     $r->print("<h3>Drop Students</h3>");
1.11      www       937:     my $cid=$ENV{'request.course.id'};
1.56      matthew   938:     my ($classlist,$keylist) = &Apache::loncoursedata::get_classlist();
                    939:     if (! defined($classlist)) {
1.27      matthew   940:         $r->print("There are no students currently enrolled.\n");
1.51      matthew   941:         return;
1.25      matthew   942:     }
1.51      matthew   943:     # Print out the available choices
1.56      matthew   944:     &show_drop_list($r,$classlist,$keylist);
1.51      matthew   945:     return;
1.11      www       946: }
                    947: 
1.40      matthew   948: # ============================================== view classlist
1.50      matthew   949: sub print_html_classlist {
1.40      matthew   950:     my $r=shift;
1.57      matthew   951:     if (! exists($ENV{'form.sortby'})) {
                    952:         $ENV{'form.sortby'} = 'username';
                    953:     }
1.59      matthew   954:     if ($ENV{'form.Status'} !~ /^(Any|Expired|Active)$/) {
1.57      matthew   955:         $ENV{'form.Status'} = 'Active';
                    956:     }
                    957:     my $status_select = &Apache::lonhtmlcommon::StatusOptions
                    958:         ($ENV{'form.Status'},'studentform');
1.48      matthew   959:     $r->print(<<END);
1.58      matthew   960: <input type="hidden" name="action" value="$ENV{'form.action'}" />
1.57      matthew   961: <input type="hidden" name="state"  value="" />
1.50      matthew   962: <p>
1.76      albertel  963: <font size="+1">Current Class List</font>
1.57      matthew   964: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
1.59      matthew   965: END
                    966:     if ($ENV{'form.action'} ne 'modifystudent') {
                    967:         $r->print(<<END);
1.57      matthew   968: <font size="+1">
                    969: <a href="javascript:document.studentform.state.value='csv';document.studentform.submit();">CSV format</a>
1.61      matthew   970: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
1.60      matthew   971: <a href="javascript:document.studentform.state.value='excel';document.studentform.submit();">Excel format</a>
1.57      matthew   972: </font>
                    973: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
1.61      matthew   974: Student Status:
1.48      matthew   975: END
1.59      matthew   976:     }
                    977:     $r->print($status_select."</p>\n");
1.40      matthew   978:     my $cid=$ENV{'request.course.id'};
1.56      matthew   979:     my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist();
                    980:     if (! defined($classlist)) {
1.40      matthew   981:         $r->print("There are no students currently enrolled.\n");
                    982:     } else {
                    983:         # Print out the available choices
1.50      matthew   984:         if ($ENV{'form.action'} eq 'modifystudent') {
1.53      matthew   985:             &show_class_list($r,'view','modify','modifystudent',
1.57      matthew   986:                              $ENV{'form.Status'},$classlist,$keylist);
1.50      matthew   987:         } else {
1.53      matthew   988:             &show_class_list($r,'view','aboutme','classlist',
1.57      matthew   989:                              $ENV{'form.Status'},$classlist,$keylist);
1.50      matthew   990:         }
1.41      matthew   991:     }
                    992: }
                    993: 
                    994: # ============================================== view classlist
1.60      matthew   995: sub print_formatted_classlist {
1.41      matthew   996:     my $r=shift;
1.60      matthew   997:     my $mode = shift;
1.41      matthew   998:     my $cid=$ENV{'request.course.id'};
1.56      matthew   999:     my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist();
                   1000:     if (! defined($classlist)) {
1.41      matthew  1001:         $r->print("There are no students currently enrolled.\n");
                   1002:     } else {
1.60      matthew  1003:         &show_class_list($r,$mode,'nolink','csv',
1.57      matthew  1004:                          $ENV{'form.Status'},$classlist,$keylist);
1.40      matthew  1005:     }
                   1006: }
                   1007: 
                   1008: # =================================================== Show student list to drop
                   1009: sub show_class_list {
1.56      matthew  1010:     my ($r,$mode,$linkto,$action,$statusmode,$classlist,$keylist)=@_;
1.40      matthew  1011:     my $cid=$ENV{'request.course.id'};
1.60      matthew  1012:     #
                   1013:     # Variables for excel output
                   1014:     my ($excel_workbook, $excel_sheet, $excel_filename,$row);
                   1015:     #
1.53      matthew  1016:     my $sortby = $ENV{'form.sortby'};
                   1017:     if ($sortby !~ /^(username|domain|section|fullname|id)$/) {
                   1018:         $sortby = 'username';
                   1019:     }
1.42      matthew  1020:     # Print out header 
1.41      matthew  1021:     if ($mode eq 'view') {
1.50      matthew  1022:         if ($linkto eq 'aboutme') {
1.56      matthew  1023:             $r->print('Select a user name to view the users personal page.');
1.50      matthew  1024:         } elsif ($linkto eq 'modify') {
                   1025:             $r->print('Select a user name to modify the students information');
                   1026:         }
1.41      matthew  1027:         $r->print(<<END);
1.59      matthew  1028: 
1.53      matthew  1029: <input type="hidden" name="sortby" value="$sortby" />
1.59      matthew  1030: <input type="hidden" name="sname"  value="" />
                   1031: <input type="hidden" name="sdom"   value="" />
1.40      matthew  1032: <p>
                   1033: <table border=2>
1.53      matthew  1034: <tr><th>
1.57      matthew  1035:        <a href="javascript:document.studentform.sortby.value='username';document.studentform.submit();">username</a>
1.53      matthew  1036:     </th><th>
1.57      matthew  1037:        <a href="javascript:document.studentform.sortby.value='domain';document.studentform.submit();">domain</a>
1.53      matthew  1038:     </th><th>
1.57      matthew  1039:        <a href="javascript:document.studentform.sortby.value='id';document.studentform.submit();">ID</a>
1.53      matthew  1040:     </th><th>
1.57      matthew  1041:        <a href="javascript:document.studentform.sortby.value='fullname';document.studentform.submit();">student name</a>
1.53      matthew  1042:     </th><th>
1.57      matthew  1043:        <a href="javascript:document.studentform.sortby.value='section';document.studentform.submit();">section</a>
1.53      matthew  1044:     </th>
                   1045: </tr>
1.40      matthew  1046: END
1.41      matthew  1047:     } elsif ($mode eq 'csv') {
1.58      matthew  1048:         if($statusmode eq 'Expired') {
                   1049:             $r->print('"Students with expired roles"');
                   1050:         }
                   1051:         if ($statusmode eq 'Any') {
                   1052:             $r->print('"'.join('","',("username","domain","ID","student name",
                   1053:                                       "section","status")).'"'."\n");
                   1054:         } else {
                   1055:             $r->print('"'.join('","',("username","domain","ID","student name",
                   1056:                                       "section")).'"'."\n");
                   1057:         }
1.60      matthew  1058:     } elsif ($mode eq 'excel') {
                   1059:         # Create the excel spreadsheet
                   1060:         $excel_filename = '/prtspool/'.
                   1061:             $ENV{'user.name'}.'_'.$ENV{'user.domain'}.'_'.
                   1062:                 time.'_'.rand(1000000000).'.xls';
                   1063:         $excel_workbook = Spreadsheet::WriteExcel->new('/home/httpd'.
                   1064:                                                        $excel_filename);
                   1065:         $excel_workbook->set_tempdir('/home/httpd/perl/tmp');
                   1066:         $excel_sheet = $excel_workbook->addworksheet('classlist');
                   1067:         #
1.76      albertel 1068:         my $description = 'Class List for '.
1.60      matthew  1069:             $ENV{'course.'.$ENV{'request.course.id'}.'.description'};
                   1070:         $excel_sheet->write($row++,0,$description);
                   1071:         #
                   1072:         $excel_sheet->write($row++,0,["username","domain","ID",
                   1073:                                       "student name","section","status"]);
1.41      matthew  1074:     }
1.56      matthew  1075:     #
                   1076:     # Sort the students
                   1077:     my %index;
                   1078:     my $i;
                   1079:     foreach (@$keylist) {
                   1080:         $index{$_} = $i++;
                   1081:     }
                   1082:     my $index  = $index{$sortby};
                   1083:     my $second = $index{'username'};
                   1084:     my $third  = $index{'domain'};
1.53      matthew  1085:     my @Sorted_Students = sort {
1.56      matthew  1086:         lc($classlist->{$a}->[$index])  cmp lc($classlist->{$b}->[$index])
                   1087:             ||
                   1088:         lc($classlist->{$a}->[$second]) cmp lc($classlist->{$b}->[$second])
                   1089:             ||
                   1090:         lc($classlist->{$a}->[$third]) cmp lc($classlist->{$b}->[$third])
                   1091:         } (keys(%$classlist));
1.53      matthew  1092:     foreach my $student (@Sorted_Students) {
1.56      matthew  1093:         my $username = $classlist->{$student}->[$index{'username'}];
                   1094:         my $domain   = $classlist->{$student}->[$index{'domain'}];
                   1095:         my $section  = $classlist->{$student}->[$index{'section'}];
                   1096:         my $name     = $classlist->{$student}->[$index{'fullname'}];
                   1097:         my $id       = $classlist->{$student}->[$index{'id'}];
                   1098:         my $status   = $classlist->{$student}->[$index{'status'}];
1.57      matthew  1099:         next if (($statusmode ne 'Any') && ($status ne $statusmode));
1.51      matthew  1100:         if ($mode eq 'view') {
                   1101:             $r->print("<tr>\n    <td>\n        ");
                   1102:             if ($linkto eq 'nothing') {
                   1103:                 $r->print($username);
                   1104:             } elsif ($linkto eq 'aboutme') {
                   1105:                 $r->print(&Apache::loncommon::aboutmewrapper($username,
                   1106:                                                              $username,
                   1107:                                                              $domain));
                   1108:             } elsif ($linkto eq 'modify') {
1.59      matthew  1109:                 $r->print('<a href="'.
                   1110:                           "javascript:document.studentform.sname.value='".
                   1111:                           $username.
                   1112:                           "';document.studentform.sdom.value='".$domain.
                   1113:                           "';document.studentform.state.value='selected".
                   1114:                           "';document.studentform.submit();".'">'.
1.53      matthew  1115:                           $username."</a>\n");
1.50      matthew  1116:             }
1.51      matthew  1117:             $r->print(<<"END");
1.50      matthew  1118:     </td>
1.51      matthew  1119:     <td>$domain</td>
                   1120:     <td>$id</td>
                   1121:     <td>$name</td>
                   1122:     <td>$section</td>
1.40      matthew  1123: </tr>
                   1124: END
1.51      matthew  1125:         } elsif ($mode eq 'csv') {
                   1126:             # no need to bother with $linkto
                   1127:             my @line = ();
                   1128:             foreach ($username,$domain,$id,$name,$section) {
                   1129:                 push @line,&Apache::loncommon::csv_translate($_);
1.58      matthew  1130:             }
                   1131:             if ($statusmode eq 'Any') {
                   1132:                 push @line,&Apache::loncommon::csv_translate($status);
1.41      matthew  1133:             }
1.51      matthew  1134:             my $tmp = $";
                   1135:             $" = '","';
                   1136:             $r->print("\"@line\"\n");
                   1137:             $" = $tmp;
1.60      matthew  1138:         } elsif ($mode eq 'excel') {
                   1139:             $excel_sheet->write($row++,0,[$username,$domain,$id,
                   1140:                                           $name,$section,$status]);
1.40      matthew  1141:         }
                   1142:     }
1.60      matthew  1143:     if ($mode eq 'view') {
                   1144:         $r->print('</table><br>');
                   1145:     } elsif ($mode eq 'excel') {
                   1146:         $excel_workbook->close();
                   1147:         $r->print('<p><a href="'.$excel_filename.'">'.
                   1148:                   'Your Excel spreadsheet</a> is ready for download.</p>'."\n");
                   1149:     }
1.40      matthew  1150: }
                   1151: 
1.50      matthew  1152: 
                   1153: #
                   1154: # print out form for modification of a single students data
                   1155: #
                   1156: sub print_modify_student_form {
                   1157:     my $r = shift();
                   1158:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.59      matthew  1159:                                             ['sdom','sname']);    
1.53      matthew  1160:     my $sname  = $ENV{'form.sname'};
                   1161:     my $sdom   = $ENV{'form.sdom'};
                   1162:     my $sortby = $ENV{'form.sortby'};
1.50      matthew  1163:     # determine the students name information
                   1164:     my %info=&Apache::lonnet::get('environment',
                   1165:                                   ['firstname','middlename',
1.52      matthew  1166:                                    'lastname','generation','id'],
1.50      matthew  1167:                                   $sdom, $sname);
                   1168:     my ($tmp) = keys(%info);
                   1169:     if ($tmp =~ /^(con_lost|error|no_such_host)/i) {
                   1170:         $r->print('<font color="#ff0000" size="+2">Error</font>'.
                   1171:                   '<p>'.
                   1172:                   'Unable to retrieve environment data for '.$sname.
                   1173:                   'in domain '.$sdom.'</p><p>'.
                   1174:                   'Please contact your LON-CAPA administrator '.
                   1175:                   'regarding this situation.</p></body></html>');
                   1176:         return;
                   1177:     }
                   1178:     # determine the students starting and ending times and section
                   1179:     my ($starttime,$endtime,$section) = &get_enrollment_data($sname,$sdom);
1.87      matthew  1180:     if ($starttime =~ /^error/) {
                   1181:         $r->print('<h2>Error</h2>');
                   1182:         $r->print('<p>'.$starttime.'</p>');
                   1183:         return;
                   1184:     }
1.50      matthew  1185:     # Deal with date forms
1.68      matthew  1186:     my $date_table = &date_setting_table($starttime,$endtime);
1.59      matthew  1187:     #
                   1188:     if (! exists($ENV{'form.Status'}) || 
                   1189:         $ENV{'form.Status'} !~ /^(Any|Expired|Active)$/) {
                   1190:         $ENV{'form.Status'} = 'crap';
                   1191:     }
1.50      matthew  1192:     # Make sure student is enrolled in course    
                   1193:     $r->print(<<END);
1.52      matthew  1194: <p>
                   1195: <font size="+1">
                   1196: Only domain coordinators can change a users password.
                   1197: </font>
                   1198: </p>
1.50      matthew  1199: <input type="hidden" name="slogin"  value="$sname"  />
                   1200: <input type="hidden" name="sdomain" value="$sdom" />
                   1201: <input type="hidden" name="action"  value="modifystudent" />
1.53      matthew  1202: <input type="hidden" name="state"   value="done" />
                   1203: <input type="hidden" name="sortby"  value="$sortby" />
1.59      matthew  1204: <input type="hidden" name="Status"  value="$ENV{'form.Status'}" />
                   1205: 
1.50      matthew  1206: <h2>Modify Enrollment for $info{'firstname'} $info{'middlename'} 
                   1207: $info{'lastname'} $info{'generation'}, $sname\@$sdom</h2>
                   1208: <p>
                   1209: <b>Student Name</b>
                   1210: <table>
                   1211: <tr><th>First</th><th>Middle</th><th>Last</th><th>Generation</th></tr>
                   1212: <tr><td>
                   1213: <input type="text" name="firstname"  value="$info{'firstname'}"  /></td><td>
                   1214: <input type="text" name="middlename" value="$info{'middlename'}" /></td><td>
                   1215: <input type="text" name="lastname"   value="$info{'lastname'}"   /></td><td>
                   1216: <input type="text" name="generation" value="$info{'generation'}" /></td></tr>
                   1217: </table>
                   1218: </p><p>
1.52      matthew  1219: <b>Student ID</b>: <input type="text" name="id" value="$info{'id'}" size="12"/>
                   1220: </p><p>
1.53      matthew  1221: <input type="checkbox" name="forceid" > 
                   1222: Disable ID/Student Number Safeguard and Force Change of Conflicting IDs
                   1223: (only do if you know what you are doing)
                   1224: </p><p>
1.50      matthew  1225: <b>Section</b>: <input type="text" name="section" value="$section" size="4"/>
                   1226: </p>
1.68      matthew  1227: <p>$date_table</p>
1.50      matthew  1228: <input type="submit" value="Submit Modifications" />
                   1229: </body></html>
                   1230: END
                   1231:     return;
                   1232: }
                   1233: 
                   1234: #
                   1235: # modify a single students section 
                   1236: #
                   1237: sub modify_single_student {
                   1238:     my $r = shift;
1.68      matthew  1239:     #
1.80      matthew  1240:     # Remove non alphanumeric values from the section
                   1241:     $ENV{'form.section'} =~ s/\W//g;
1.77      matthew  1242:     #
1.68      matthew  1243:     # Do the date defaults first
                   1244:     my ($starttime,$endtime) = &get_dates_from_form();
                   1245:     if ($ENV{'form.makedatesdefault'}) {
                   1246:         $r->print(&make_dates_default($starttime,$endtime));
                   1247:     }
1.59      matthew  1248:     # Get the 'sortby' and 'Status' variables so the user goes back to their
                   1249:     # previous screen
1.53      matthew  1250:     my $sortby = $ENV{'form.sortby'};
1.59      matthew  1251:     my $status = $ENV{'form.Status'};
1.53      matthew  1252:     #
                   1253:     # We always need this information
                   1254:     my $slogin     = $ENV{'form.slogin'};
                   1255:     my $sdom       = $ENV{'form.sdomain'};
                   1256:     #
                   1257:     # Get the old data
                   1258:     my %old=&Apache::lonnet::get('environment',
                   1259:                                  ['firstname','middlename',
                   1260:                                   'lastname','generation','id'],
                   1261:                                  $sdom, $slogin);
1.59      matthew  1262:     $old{'section'} = &Apache::lonnet::getsection($sdom,$slogin,
                   1263:                                                   $ENV{'request.course.id'});
1.53      matthew  1264:     my ($tmp) = keys(%old);
                   1265:     if ($tmp =~ /^(con_lost|error|no_such_host)/i) {
                   1266:         $r->print("There was an error determining the environment values ".
                   1267:                   " for $slogin \@ $sdom.");
                   1268:         return;
                   1269:     }
                   1270:     undef $tmp;
                   1271:     #
                   1272:     # Get the new data
1.50      matthew  1273:     my $firstname  = $ENV{'form.firstname'};
                   1274:     my $middlename = $ENV{'form.middlename'};
                   1275:     my $lastname   = $ENV{'form.lastname'};
                   1276:     my $generation = $ENV{'form.generation'};
                   1277:     my $section    = $ENV{'form.section'};
                   1278:     my $courseid   = $ENV{'request.course.id'};
1.52      matthew  1279:     my $sid        = $ENV{'form.id'};
1.50      matthew  1280:     my $displayable_starttime = localtime($starttime);
                   1281:     my $displayable_endtime   = localtime($endtime);
1.53      matthew  1282:     # 
                   1283:     # check for forceid override
1.63      matthew  1284:     if ((defined($old{'id'})) && ($old{'id'} ne '') && 
                   1285:         ($sid ne $old{'id'}) && (! exists($ENV{'form.forceid'}))) {
1.53      matthew  1286:         $r->print("<font color=\"ff0000\">You changed the students id ".
                   1287:                   " but did not disable the ID change safeguard.".
                   1288:                   "  The students id will not be changed.</font>");
                   1289:         $sid = $old{'id'};
                   1290:     }
                   1291:     #
1.50      matthew  1292:     # talk to the user about what we are going to do
                   1293:     $r->print(<<END);
1.53      matthew  1294:     <h2>Modifying data for user $slogin \@ $sdom </h2>
1.50      matthew  1295: <h3>Student Information</h3>
1.53      matthew  1296: <table rules="rows" border="1" cellpadding="3" >
                   1297: <tr>
                   1298:     <th> Field </th>
                   1299:     <th> Old Value </th>
                   1300:     <th> New Value </th>
                   1301: </tr>
                   1302: <tr>
                   1303:     <td> <b>First name</b> </td>
                   1304:     <td> $old{'firstname'} </td>
                   1305:     <td> $firstname </td>
                   1306: </tr><tr>
                   1307:     <td> <b>Middle name</b> </td>
                   1308:     <td> $old{'middlename'} </td>
                   1309:     <td> $middlename </td>
                   1310: </tr><tr>
                   1311:     <td> <b>Last name</b> </td>
                   1312:     <td> $old{'lastname'} </td>
                   1313:     <td> $lastname </td>
                   1314: </tr><tr>
                   1315:     <td> <b>Generation</b> </td>
                   1316:     <td> $old{'generation'} </td>
                   1317:     <td> $generation </td>
                   1318: </tr><tr>
                   1319:     <td> <b>ID</b> </td>
                   1320:     <td> $old{'id'} </td>
                   1321:     <td> $sid </td>
1.59      matthew  1322: </tr><tr>
                   1323:     <td> <b>Section</b> </td>
                   1324:     <td> $old{'section'} </td>
                   1325:     <td> $section</td>
1.53      matthew  1326: </tr>
1.50      matthew  1327: </table>
                   1328: <h3>Role Information</h3>
                   1329: <table>
1.68      matthew  1330: <tr><td align="right"><b>Start Time:</b></td><td> $displayable_starttime </td></tr>
                   1331: <tr><td align="right"><b>End Time:</b></td><td> $displayable_endtime   </td></tr>
1.50      matthew  1332: </table>
1.52      matthew  1333: <p>
1.50      matthew  1334: END
1.53      matthew  1335:     #
1.63      matthew  1336:     # Send request(s) to modify data (final undef is for 'desiredhost',
                   1337:     # which is a moot point because the student already has an account.
                   1338:     my $modify_section_results = &modifystudent($sdom,$slogin,
                   1339:                                                 $ENV{'request.course.id'},
                   1340:                                                 $section,undef);
                   1341:     if ($modify_section_results !~ /^ok/) {
                   1342:         $r->print("An error occured during the attempt to change the ".
                   1343:                   "section for this student.<br />");
                   1344:     }
1.52      matthew  1345:     my $roleresults = &Apache::lonnet::modifystudent
1.53      matthew  1346:         ($sdom,$slogin,$sid,undef,undef,$firstname,$middlename,$lastname,
                   1347:          $generation,$section,$endtime,$starttime,$ENV{'form.forceid'});
                   1348:     if ($roleresults eq 'refused' ) {
1.50      matthew  1349:         $r->print("Your request to change the role information for this ".
1.53      matthew  1350:                   "student was refused.  You do not appear to have ".
                   1351:                   "sufficient authority to change student information.");
1.50      matthew  1352:     } elsif ($roleresults !~ /ok/) {
                   1353:         $r->print("An error occurred during the attempt to change the role".
1.52      matthew  1354:                   " information for this student.  <br />".
                   1355:                   "The error reported was ".
1.50      matthew  1356:                   $roleresults);
1.53      matthew  1357:         &Apache::lonnet::logthis("londropadd:failed attempt to modify student".
                   1358:                                  " data for ".$slogin." \@ ".$sdom." by ".
                   1359:                                  $ENV{'user.name'}." \@ ".$ENV{'user.domain'}.
                   1360:                                  ":".$roleresults);
1.50      matthew  1361:     } else { # everything is okay!
1.52      matthew  1362:         $r->print("Student information updated successfully. <br />".
                   1363:                   "The student must log out and log in again to see ".
                   1364:                   "these changes.");
1.50      matthew  1365:     }
                   1366:     $r->print(<<END);
1.52      matthew  1367: </p><p>
1.59      matthew  1368: <input type="hidden" name="action" value="modifystudent" />
                   1369: <input type="hidden" name="sortby" value="$sortby" />
                   1370: <input type="hidden" name="Status" value="$status" />
                   1371: <a href="javascript:document.studentform.submit();">Modify another students data</a>
1.50      matthew  1372: </body></html>
                   1373: END
                   1374:     return;
                   1375: }
                   1376: 
                   1377: sub get_enrollment_data {
                   1378:     my ($sname,$sdomain) = @_;
                   1379:     my $courseid = $ENV{'request.course.id'};
                   1380:     $courseid =~ s:_:/:g;
                   1381:     my %roles = &Apache::lonnet::dump('roles',$sdomain,$sname);
                   1382:     my ($tmp) = keys(%roles);
                   1383:     # Bail out if we were unable to get the students roles
1.87      matthew  1384:     return ('error'.$tmp) if ($tmp =~ /^(con_lost|error|no_such_host)/i);
1.50      matthew  1385:     # Go through the roles looking for enrollment in this course
                   1386:     my ($end,$start) = (undef,undef);
                   1387:     my $section = '';
                   1388:     my $count = scalar(keys(%roles));
                   1389:     while (my ($course,$role) = each(%roles)) {
                   1390:         if ($course=~ /^\/$courseid\/*\s*(\w+)*_st$/ ) {
                   1391:             #
                   1392:             # Get active role
                   1393:             $section=$1;
                   1394:             (undef,$end,$start)=split(/\_/,$role);
                   1395:             my $now=time;
                   1396:             my $notactive=0;
                   1397:             if ($start) {
                   1398:                 if ($now<$start) { $notactive=1; }
                   1399:             }
                   1400:             if ($end) {
                   1401:                 if ($now>$end) { $notactive=1; }
                   1402:             } 
                   1403:             unless ($notactive) { return ($start,$end,$section); }
                   1404:         }
                   1405:     }
                   1406:     return ($start,$end,$section);
                   1407: }
                   1408: 
1.56      matthew  1409: #################################################
                   1410: #################################################
                   1411: 
                   1412: =pod
                   1413: 
                   1414: =item show_drop_list
                   1415: 
                   1416: Display a list of students to drop
                   1417: Inputs: 
                   1418: 
                   1419: =over 4
                   1420: 
                   1421: =item $r, Apache request
                   1422: 
                   1423: =item $classlist, hash pointer returned from loncoursedata::get_classlist();
                   1424: 
                   1425: =item $keylist, array pointer returned from loncoursedata::get_classlist() 
                   1426: which describes the order elements are stored in the %$classlist values.
                   1427: 
                   1428: =item $nosort, if true, sorting links are omitted.
                   1429: 
                   1430: =back
                   1431: 
                   1432: =cut
                   1433: 
                   1434: #################################################
                   1435: #################################################
1.11      www      1436: sub show_drop_list {
1.56      matthew  1437:     my ($r,$classlist,$keylist,$nosort)=@_;
1.11      www      1438:     my $cid=$ENV{'request.course.id'};
1.59      matthew  1439:     if (! exists($ENV{'form.sortby'})) {
                   1440:         &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
                   1441:                                                 ['sortby']);
                   1442:     }
1.54      matthew  1443:     my $sortby = $ENV{'form.sortby'};
                   1444:     if ($sortby !~ /^(username|domain|section|fullname|id)$/) {
                   1445:         $sortby = 'username';
                   1446:     }
1.56      matthew  1447:     #
1.54      matthew  1448:     my $action = "drop";
                   1449:     $r->print(<<END);
                   1450: <input type="hidden" name="sortby" value="$sortby" />
                   1451: <input type="hidden" name="action" value="$action" />
1.50      matthew  1452: <input type="hidden" name="state"  value="done" />
1.32      matthew  1453: <script>
1.51      matthew  1454: function checkAll(field) {
1.32      matthew  1455:     for (i = 0; i < field.length; i++)
                   1456:         field[i].checked = true ;
                   1457: }
                   1458: 
1.51      matthew  1459: function uncheckAll(field) {
1.32      matthew  1460:     for (i = 0; i < field.length; i++)
                   1461:         field[i].checked = false ;
                   1462: }
                   1463: </script>
                   1464: <p>
1.26      matthew  1465: <input type="hidden" name="phase" value="four">
1.56      matthew  1466: END
                   1467: 
                   1468:     if ($nosort) {
                   1469:         $r->print(<<END);
                   1470: <table border=2>
                   1471: <tr>
                   1472:     <th>&nbsp;</th>
                   1473:     <th>username</th>
                   1474:     <th>domain</th>
                   1475:     <th>ID</th>
                   1476:     <th>student name</th>
                   1477:     <th>section</th>
                   1478: </tr>
                   1479: END
                   1480: 
                   1481:     } else  {
                   1482:         $r->print(<<END);
1.26      matthew  1483: <table border=2>
1.54      matthew  1484: <tr><th>&nbsp;</th>
                   1485:     <th>
                   1486:        <a href="/adm/dropadd?action=$action&sortby=username">username</a>
                   1487:     </th><th>
                   1488:        <a href="/adm/dropadd?action=$action&sortby=domain">domain</a>
                   1489:     </th><th>
                   1490:        <a href="/adm/dropadd?action=$action&sortby=id">ID</a>
                   1491:     </th><th>
                   1492:        <a href="/adm/dropadd?action=$action&sortby=fullname">student name</a>
                   1493:     </th><th>
                   1494:        <a href="/adm/dropadd?action=$action&sortby=section">section</a>
                   1495:     </th>
                   1496: </tr>
1.26      matthew  1497: END
1.56      matthew  1498:     }
                   1499:     #
                   1500:     # Sort the students
                   1501:     my %index;
                   1502:     my $i;
                   1503:     foreach (@$keylist) {
                   1504:         $index{$_} = $i++;
                   1505:     }
                   1506:     my $index  = $index{$sortby};
                   1507:     my $second = $index{'username'};
                   1508:     my $third  = $index{'domain'};
1.54      matthew  1509:     my @Sorted_Students = sort {
1.56      matthew  1510:         lc($classlist->{$a}->[$index])  cmp lc($classlist->{$b}->[$index])
                   1511:             ||
                   1512:         lc($classlist->{$a}->[$second]) cmp lc($classlist->{$b}->[$second])
                   1513:             ||
                   1514:         lc($classlist->{$a}->[$third]) cmp lc($classlist->{$b}->[$third])
                   1515:         } (keys(%$classlist));
1.54      matthew  1516:     foreach my $student (@Sorted_Students) {
1.52      matthew  1517:         my $error;
1.56      matthew  1518:         my $username = $classlist->{$student}->[$index{'username'}];
                   1519:         my $domain   = $classlist->{$student}->[$index{'domain'}];
                   1520:         my $section  = $classlist->{$student}->[$index{'section'}];
                   1521:         my $name     = $classlist->{$student}->[$index{'fullname'}];
                   1522:         my $id       = $classlist->{$student}->[$index{'id'}];
                   1523:         my $status   = $classlist->{$student}->[$index{'status'}];
1.51      matthew  1524:         next if ($status ne 'Active');
                   1525:         #
                   1526:         $r->print(<<"END");
1.26      matthew  1527: <tr>
1.51      matthew  1528:     <td><input type="checkbox" name="droplist" value="$student"></td>
                   1529:     <td>$username</td>
                   1530:     <td>$domain</td>
                   1531:     <td>$id</td>
                   1532:     <td>$name</td>
                   1533:     <td>$section</td>
1.26      matthew  1534: </tr>
                   1535: END
1.25      matthew  1536:     }
                   1537:     $r->print('</table><br>');
1.32      matthew  1538:     $r->print(<<"END");
                   1539: </p><p>
                   1540: <input type="button" value="check all" onclick="javascript:checkAll(document.studentform.droplist)"> &nbsp;
                   1541: <input type="button" value="uncheck all" onclick="javascript:uncheckAll(document.studentform.droplist)"> 
                   1542: <p><input type=submit value="Drop Students"></p>
                   1543: END
1.51      matthew  1544:     return;
1.10      www      1545: }
                   1546: 
1.48      matthew  1547: #
                   1548: # Print out the initial form to get the courselist file
                   1549: #
                   1550: sub print_first_courselist_upload_form {
                   1551:     my $r=shift;
1.88      matthew  1552:     my $str;
                   1553:     $str  = '<input type="hidden" name="phase" value="two">';
                   1554:     $str .= '<input type="hidden" name="action" value="upload" />';
                   1555:     $str .= '<input type="hidden"   name="state"  value="got_file" />';
                   1556:     $str .= "<h3>".&mt('Upload a class list')."</h3>\n";
                   1557:     $str .= &Apache::loncommon::upfile_select_html();
                   1558:     $str .= "<p>\n";
                   1559:     $str .= '<input type="submit" name="fileupload" value="'.
                   1560:         &mt('Upload class list').'">'."\n";
                   1561:     $str .= '<input type="checkbox" name="noFirstLine" /> '.
                   1562:         &mt('Ignore First Line')."</p>\n";
                   1563:     $str .= &Apache::loncommon::help_open_topic("Course_Create_Class_List",
                   1564:                          "How do I create a class list from a spreadsheet").
                   1565:                              "<br />\n";
                   1566:     $str .= &Apache::loncommon::help_open_topic("Course_Convert_To_CSV",
                   1567:                            "How do I create a CSV file from a spreadsheet").
                   1568:                                "<br />\n";
                   1569:     $str .= "</body>\n</html>\n";
                   1570:     $r->print($str);
1.48      matthew  1571:     return;
                   1572: }
                   1573: 
1.10      www      1574: # ================================================= Drop/Add from uploaded file
                   1575: sub upfile_drop_add {
                   1576:     my $r=shift;
1.24      albertel 1577:     &Apache::loncommon::load_tmp_file($r);
                   1578:     my @studentdata=&Apache::loncommon::upfile_record_sep();
1.82      www      1579:     if($ENV{'form.noFirstLine'}){shift(@studentdata);}
1.26      matthew  1580:     my @keyfields = split(/\,/,$ENV{'form.keyfields'});
                   1581:     my $cid = $ENV{'request.course.id'};
1.25      matthew  1582:     my %fields=();
1.26      matthew  1583:     for (my $i=0; $i<=$ENV{'form.nfields'}; $i++) {
1.25      matthew  1584:         if ($ENV{'form.upfile_associate'} eq 'reverse') {
                   1585:             if ($ENV{'form.f'.$i} ne 'none') {
                   1586:                 $fields{$keyfields[$i]}=$ENV{'form.f'.$i};
                   1587:             }
                   1588:         } else {
                   1589:             $fields{$ENV{'form.f'.$i}}=$keyfields[$i];
                   1590:         }
                   1591:     }
1.26      matthew  1592:     #
1.68      matthew  1593:     my ($startdate,$enddate) = &get_dates_from_form();
                   1594:     if ($ENV{'form.makedatesdefault'}) {
                   1595:         $r->print(&make_dates_default($startdate,$enddate));
                   1596:     }
1.31      matthew  1597:     # Determine domain and desired host (home server)
1.25      matthew  1598:     my $domain=$ENV{'form.lcdomain'};
1.31      matthew  1599:     my $desiredhost = $ENV{'form.lcserver'};
                   1600:     if (lc($desiredhost) eq 'default') {
                   1601:         $desiredhost = undef;
                   1602:     } else {
1.45      matthew  1603:         my %home_servers = &Apache::loncommon::get_library_servers($domain);
1.31      matthew  1604:         if (! exists($home_servers{$desiredhost})) {
1.88      matthew  1605:             $r->print('<font color="#ff0000">'.&mt('Error').'</font>'.
                   1606:                       &mt('Invalid home server specified'));
                   1607:             $r->print("</body>\n</html>\n");
1.31      matthew  1608:             return;
                   1609:         }
                   1610:     }
1.26      matthew  1611:     # Determine authentication mechanism
                   1612:     my $amode  = '';
                   1613:     my $genpwd = '';
1.25      matthew  1614:     if ($ENV{'form.login'} eq 'krb') {
1.47      albertel 1615:         $amode='krb';
                   1616: 	$amode.=$ENV{'form.krbver'};
1.28      matthew  1617:         $genpwd=$ENV{'form.krbarg'};
1.25      matthew  1618:     } elsif ($ENV{'form.login'} eq 'int') {
                   1619:         $amode='internal';
1.28      matthew  1620:         if ((defined($ENV{'form.intarg'})) && ($ENV{'form.intarg'})) {
                   1621:             $genpwd=$ENV{'form.intarg'};
1.25      matthew  1622:         }
                   1623:     } elsif ($ENV{'form.login'} eq 'loc') {
                   1624:         $amode='localauth';
                   1625:         if ((defined($ENV{'form.locarg'})) && ($ENV{'form.locarg'})) {
                   1626:             $genpwd=$ENV{'form.locarg'};
1.79      matthew  1627:         }
                   1628:     }
                   1629:     if ($amode =~ /^krb/) {
                   1630:         if (! defined($genpwd) || $genpwd eq '') {
                   1631:             $r->print('<font color="red" size="+1">'.
1.88      matthew  1632:                       &mt('Unable to enroll students').'</font>  '.
                   1633:                       &mt('No Kerberos domain was specified.').'</p>');
1.79      matthew  1634:             $amode = ''; # This causes the loop below to be skipped
1.25      matthew  1635:         }
                   1636:     }
                   1637:     unless (($domain=~/\W/) || ($amode eq '')) {
1.26      matthew  1638:         #######################################
                   1639:         ##         Enroll Students           ##
                   1640:         #######################################
1.88      matthew  1641:         $r->print('<h3>'.&mt('Enrolling Students')."</h3>\n<p>\n");
1.25      matthew  1642:         my $count=0;
                   1643:         my $flushc=0;
                   1644:         my %student=();
1.26      matthew  1645:         # Get new classlist
1.25      matthew  1646:         foreach (@studentdata) {
                   1647:             my %entries=&Apache::loncommon::record_sep($_);
1.26      matthew  1648:             # Determine student name
1.25      matthew  1649:             unless (($entries{$fields{'username'}} eq '') ||
                   1650:                     (!defined($entries{$fields{'username'}}))) {
1.26      matthew  1651:                 my ($fname, $mname, $lname,$gen) = ('','','','');
1.25      matthew  1652:                 if (defined($fields{'names'})) {
1.26      matthew  1653:                     ($lname,$fname,$mname)=($entries{$fields{'names'}}=~
                   1654:                                             /([^\,]+)\,\s*(\w+)\s*(.*)$/);
1.25      matthew  1655:                 } else {
                   1656:                     if (defined($fields{'fname'})) {
                   1657:                         $fname=$entries{$fields{'fname'}};
                   1658:                     }
                   1659:                     if (defined($fields{'mname'})) {
                   1660:                         $mname=$entries{$fields{'mname'}};
                   1661:                     }
                   1662:                     if (defined($fields{'lname'})) {
                   1663:                         $lname=$entries{$fields{'lname'}};
                   1664:                     }
                   1665:                     if (defined($fields{'gen'})) {
                   1666:                         $gen=$entries{$fields{'gen'}};
                   1667:                     }
                   1668:                 }
                   1669:                 if ($entries{$fields{'username'}}=~/\W/) {
1.88      matthew  1670:                     $r->print('<br />'.
                   1671:       &mt('<b>[_1]</b>: Unacceptable username for user [_2] [_3] [_4] [_5]',
                   1672:           $entries{$fields{'username'}},$fname,$mname,$lname,$gen).
                   1673:                               '</b>');
1.25      matthew  1674:                 } else {
1.26      matthew  1675:                     # determine section number
1.25      matthew  1676:                     my $sec='';
                   1677:                     my $username=$entries{$fields{'username'}};
                   1678:                     if (defined($fields{'sec'})) {
                   1679:                         if (defined($entries{$fields{'sec'}})) {
                   1680:                             $sec=$entries{$fields{'sec'}};
                   1681:                         }
                   1682:                     }
1.80      matthew  1683:                     # remove non alphanumeric values from section
                   1684:                     $sec =~ s/\W//g;
1.26      matthew  1685:                     # determine student id number
1.25      matthew  1686:                     my $id='';
                   1687:                     if (defined($fields{'id'})) {
                   1688:                         if (defined($entries{$fields{'id'}})) {
                   1689:                             $id=$entries{$fields{'id'}};
                   1690:                         }
                   1691:                         $id=~tr/A-Z/a-z/;
                   1692:                     }
1.73      www      1693:                     # determine email address
                   1694:                     my $email='';
                   1695:                     if (defined($fields{'email'})) {
                   1696:                         if (defined($entries{$fields{'email'}})) {
                   1697:                             $email=$entries{$fields{'email'}};
                   1698:                             unless ($email=~/^[^\@]+\@[^\@]+$/) { $email=''; }
                   1699:                         }
                   1700:                     }
1.26      matthew  1701:                     # determine student password
1.25      matthew  1702:                     my $password='';
                   1703:                     if ($genpwd) { 
                   1704:                         $password=$genpwd; 
                   1705:                     } else {
                   1706:                         if (defined($fields{'ipwd'})) {
                   1707:                             if ($entries{$fields{'ipwd'}}) {
                   1708:                                 $password=$entries{$fields{'ipwd'}};
                   1709:                             }
                   1710:                         }
                   1711:                     }
1.56      matthew  1712:                     # Clean up whitespace
                   1713:                     foreach (\$domain,\$username,\$id,\$fname,\$mname,
                   1714:                              \$lname,\$gen,\$sec) {
                   1715:                         $$_ =~ s/(\s+$|^\s+)//g;
                   1716:                     }
1.84      albertel 1717:                     if ($password || $ENV{'form.login'} eq 'loc') {
1.33      matthew  1718:                         &modifystudent($domain,$username,$cid,$sec,
                   1719:                                        $desiredhost);
1.25      matthew  1720:                         my $reply=&Apache::lonnet::modifystudent
                   1721:                             ($domain,$username,$id,$amode,$password,
                   1722:                              $fname,$mname,$lname,$gen,$sec,$enddate,
1.73      www      1723:                              $startdate,$ENV{'form.forceid'},$desiredhost,
                   1724:                              $email);
1.26      matthew  1725:                         if ($reply ne 'ok') {
1.72      matthew  1726:                             $reply =~ s/^error://;
1.88      matthew  1727:                             $r->print('<br />'.
                   1728:                 &mt('<b>[_1]</b>:  Unable to enroll: [_2]',$username,$reply));
1.10      www      1729:          		} else {
1.7       www      1730:                             $count++; $flushc++;
                   1731:                             $student{$username}=1;
1.6       www      1732:                             $r->print('. ');
1.7       www      1733:                             if ($flushc>15) {
                   1734: 				$r->rflush;
                   1735:                                 $flushc=0;
                   1736:                             }
1.6       www      1737:                         }
1.25      matthew  1738:                     } else {
1.88      matthew  1739:                         $r->print('<br />'.
                   1740:       &mt('<b>[_1]</b>: Unable to enroll.  No password specified.',$username)
                   1741:                                   );
1.25      matthew  1742:                     }
                   1743:                 }
1.26      matthew  1744:             }
                   1745:         } # end of foreach (@studentdata)
1.88      matthew  1746:         $r->print("</p>\n<p>\n".&mt('Processed [_1] student(s).',$count).
                   1747:                   "</p>\n");
                   1748:         $r->print("<p>\n".
                   1749:                   &mt('If active, the new role will be available when the '.
                   1750:                   'students next log in to LON-CAPA.')."</p>\n");
1.26      matthew  1751:         #####################################
                   1752:         #           Drop students           #
                   1753:         #####################################
1.25      matthew  1754:         if ($ENV{'form.fullup'} eq 'yes') {
1.88      matthew  1755:             $r->print('<h3>'.&mt('Dropping Students')."</h3>\n");
1.26      matthew  1756:             #  Get current classlist
1.56      matthew  1757:             my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist();
                   1758:             if (! defined($classlist)) {
1.88      matthew  1759:                 $r->print(&mt('There are no students currently enrolled.').
                   1760:                           "\n");
1.56      matthew  1761:             } else {
                   1762:                 # Remove the students we just added from the list of students.
1.25      matthew  1763:                 foreach (@studentdata) {
                   1764:                     my %entries=&Apache::loncommon::record_sep($_);
                   1765:                     unless (($entries{$fields{'username'}} eq '') ||
                   1766:                             (!defined($entries{$fields{'username'}}))) {
1.56      matthew  1767:                         delete($classlist->{$entries{$fields{'username'}}.
1.26      matthew  1768:                                                 ':'.$domain});
1.25      matthew  1769:                     }
                   1770:                 }
1.56      matthew  1771:                 # Print out list of dropped students.
                   1772:                 &show_drop_list($r,$classlist,$keylist,'nosort');
1.25      matthew  1773:             }
                   1774:         }
1.26      matthew  1775:     } # end of unless
1.10      www      1776: }
                   1777: 
1.11      www      1778: # ================================================================== Phase four
                   1779: sub drop_student_list {
                   1780:     my $r=shift;
                   1781:     my $count=0;
1.35      matthew  1782:     my @droplist;
                   1783:     if (ref($ENV{'form.droplist'})) {
                   1784:         @droplist = @{$ENV{'form.droplist'}};
                   1785:     } else {
                   1786:         @droplist = ($ENV{'form.droplist'});
                   1787:     }
                   1788:     foreach (@droplist) {
1.26      matthew  1789:         my ($uname,$udom)=split(/\:/,$_);
1.56      matthew  1790:         # drop student
1.35      matthew  1791:         my $result = &modifystudent($udom,$uname,$ENV{'request.course.id'});
1.37      matthew  1792:         if ($result eq 'ok' || $result eq 'ok:') {
1.88      matthew  1793:             $r->print(&mt('Dropped [_1]',$uname.'@'.$udom).'<br>');
1.59      matthew  1794:             $count++;
1.35      matthew  1795:         } else {
1.88      matthew  1796:             $r->print(
                   1797:           &mt('Error dropping [_1]:[_2]',$uname.'@'.$udom,$result).
1.35      matthew  1798:                       '<br />');
                   1799:         }
1.20      harris41 1800:     }
1.88      matthew  1801:     $r->print('<p><b>'.&mt('Dropped [_1] student(s).',$count).'</b></p>');
                   1802:     $r->print('<p>'.&mt('Re-enrollment will re-activate data.')) if ($count);
1.11      www      1803: }
                   1804: 
1.50      matthew  1805: ###################################################################
                   1806: ###################################################################
                   1807: 
                   1808: =pod
                   1809: 
                   1810: =item &handler
                   1811: 
                   1812: The typical handler you see in all these modules.  Takes $r, the
                   1813: http request, as an argument.  
                   1814: 
                   1815: The response to the request is governed by two form variables
                   1816: 
                   1817:  form.action      form.state     response
                   1818:  ---------------------------------------------------
                   1819:  undefined        undefined      print main menu
                   1820:  upload           undefined      print courselist upload menu
                   1821:  upload           got_file       deal with uploaded file,
                   1822:                                  print the upload managing menu
                   1823:  upload           enrolling      enroll students based on upload
                   1824:  drop             undefined      print the classlist ready to drop
                   1825:  drop             done           drop the selected students
1.74      matthew  1826:  enrollstudent    undefined      print student username domain form
                   1827:  enrollstudent    gotusername    print single student enroll menu
1.50      matthew  1828:  enrollstudent    enrolling      enroll student
                   1829:  classlist        undefined      print html classlist
                   1830:  classlist        csv            print csv classlist
                   1831:  modifystudent    undefined      print classlist to select student to modify
                   1832:  modifystudent    selected       print modify student menu
                   1833:  modifystudent    done           make modifications to student record
                   1834: 
                   1835: =cut
                   1836: 
                   1837: ###################################################################
                   1838: ###################################################################
1.10      www      1839: sub handler {
1.26      matthew  1840:     my $r=shift;
                   1841:     if ($r->header_only) {
1.86      www      1842:         &Apache::loncommon::content_type($r,'text/html');
1.26      matthew  1843:         $r->send_http_header;
                   1844:         return OK;
                   1845:     }
1.48      matthew  1846:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.50      matthew  1847:                                             ['action','state']);
1.26      matthew  1848:     #  Needs to be in a course
1.50      matthew  1849:     if (! (($ENV{'request.course.fn'}) &&
                   1850:           (&Apache::lonnet::allowed('cst',$ENV{'request.course.id'})))) {
                   1851:         # Not in a course, or not allowed to modify parms
                   1852:         $ENV{'user.error.msg'}=
                   1853:             "/adm/dropadd:cst:0:0:Cannot drop or add students";
                   1854:         return HTTP_NOT_ACCEPTABLE; 
                   1855:     }
                   1856:     #
                   1857:     # Only output the header information if they did not request csv format
                   1858:     #
                   1859:     if (exists($ENV{'form.state'}) && ($ENV{'form.state'} eq 'csv')) {
                   1860:         $r->content_type('text/csv');
                   1861:     } else {
1.26      matthew  1862:         # Start page
1.86      www      1863:         &Apache::loncommon::content_type($r,'text/html');
1.26      matthew  1864:         $r->send_http_header;
1.50      matthew  1865:         $r->print(&header());
                   1866:     }
                   1867:     #
                   1868:     # Main switch on form.action and form.state, as appropriate
                   1869:     if (! exists($ENV{'form.action'})) {
                   1870:         &print_main_menu($r);
                   1871:     } elsif ($ENV{'form.action'} eq 'upload') {
                   1872:         if (! exists($ENV{'form.state'})) {
                   1873:             &print_first_courselist_upload_form($r);            
                   1874:         } elsif ($ENV{'form.state'} eq 'got_file') {
                   1875:             &print_upload_manager_form($r);
                   1876:         } elsif ($ENV{'form.state'} eq 'enrolling') {
1.26      matthew  1877:             if ($ENV{'form.datatoken'}) {
                   1878:                 &upfile_drop_add($r);
1.50      matthew  1879:             } else {
                   1880:                 # Hmmm, this is an error
1.26      matthew  1881:             }
1.50      matthew  1882:         } else {
                   1883:             &print_first_courselist_upload_form($r);            
1.26      matthew  1884:         }
1.50      matthew  1885:     } elsif ($ENV{'form.action'} eq 'drop') {
                   1886:         if (! exists($ENV{'form.state'})) {
1.51      matthew  1887:             &print_drop_menu($r);
1.50      matthew  1888:         } elsif ($ENV{'form.state'} eq 'done') {
1.26      matthew  1889:             &drop_student_list($r);
1.50      matthew  1890:         } else {
1.55      matthew  1891:             &print_drop_menu($r);
1.26      matthew  1892:         }
1.50      matthew  1893:     } elsif ($ENV{'form.action'} eq 'enrollstudent') {
                   1894:         if (! exists($ENV{'form.state'})) {
1.74      matthew  1895:             &get_student_username_domain_form($r);
                   1896:         } elsif ($ENV{'form.state'} eq 'gotusername') {
1.50      matthew  1897:             &print_enroll_single_student_form($r);
                   1898:         } elsif ($ENV{'form.state'} eq 'enrolling') {
1.26      matthew  1899:             &enroll_single_student($r);
1.50      matthew  1900:         } else {
1.74      matthew  1901:             &get_student_username_domain_form($r);
1.26      matthew  1902:         }
1.50      matthew  1903:     } elsif ($ENV{'form.action'} eq 'classlist') {
                   1904:         if (! exists($ENV{'form.state'})) {
                   1905:             &print_html_classlist($r);
                   1906:         } elsif ($ENV{'form.state'} eq 'csv') {
1.60      matthew  1907:             &print_formatted_classlist($r,'csv');
                   1908:         } elsif ($ENV{'form.state'} eq 'excel') {
                   1909:             &print_formatted_classlist($r,'excel');
1.50      matthew  1910:         } else {
                   1911:             &print_html_classlist($r);
                   1912:         }
                   1913:     } elsif ($ENV{'form.action'} eq 'modifystudent') {
                   1914:         if (! exists($ENV{'form.state'})) {
                   1915:             &print_html_classlist($r);
                   1916:         } elsif ($ENV{'form.state'} eq 'selected') {
                   1917:             &print_modify_student_form($r);
                   1918:         } elsif ($ENV{'form.state'} eq 'done') {
                   1919:             &modify_single_student($r);
                   1920:         } else {
                   1921:             &print_html_classlist($r);
                   1922:         }        
                   1923:     } else {
                   1924:         # We should not end up here, but I guess it is possible
                   1925:         &Apache::lonnet::logthis("Undetermined state in londropadd.pm.  ".
                   1926:                                  "form.action = ".$ENV{'form.action'}.
                   1927:                                  "Someone should fix this.");
                   1928:         &print_main_menu($r);
                   1929:     }
                   1930:     #
                   1931:     # Finish up
                   1932:     if (exists($ENV{'form.state'}) && ($ENV{'form.state'} eq 'csv')) {
                   1933:         $r->print("\n");
1.26      matthew  1934:     } else {
1.50      matthew  1935:         $r->print('</form></body></html>');
1.26      matthew  1936:     }
                   1937:     return OK;
1.1       www      1938: }
                   1939: 
1.50      matthew  1940: ###################################################################
                   1941: ###################################################################
                   1942: 
1.1       www      1943: 1;
                   1944: __END__
1.50      matthew  1945: 
1.1       www      1946: 

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