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

1.1       www         1: # The LearningOnline Network with CAPA
                      2: # Handler to drop and add students in courses 
                      3: #
1.90    ! matthew     4: # $Id: londropadd.pm,v 1.89 2003/11/06 22:49:59 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.90    ! matthew   503:     my $Str = "</table>\n";
        !           504:     $Str .= &hidden_input('nfields',$i);
        !           505:     $Str .= &hidden_input('keyfields',$keyfields);
        !           506:     $Str .= '<h3>'.&mt('Login Type')."</h3>\n";
        !           507:     $Str .= "<p>\n".
        !           508:         &mt('Note: this will not take effect if the user already exists').
        !           509:         "</p><p>\n";
        !           510:     $Str .= $krbform."\n</p><p>\n".
        !           511:         $intform."\n</p><p>\n".
        !           512:         $locform."\n</p>\n";
        !           513:     $Str .= '<h3>'.&mt('LON-CAPA Domain for Students')."</h3>\n";
        !           514:     $Str .= "<p>\n".&mt('LON-CAPA domain: [_1]',$domform)."\n</p>\n";
        !           515:     $Str .= "<h3>".&mt('Starting and Ending Dates')."</h3>\n";
        !           516:     $Str .= "<p>\n".$date_table."</p>\n";
        !           517:     $Str .= "<h3>".&mt('Full Update')."</h3>\n";
        !           518:     $Str .= '<input type="checkbox" name="fullup" value="yes">'.
        !           519:         ' '.&mt('Full update (also print list of users not enrolled anymore)').
        !           520:         "</p>\n";
        !           521:     $Str .= "<h3>".&mt('Student Number')."</h3>\n";
        !           522:     $Str .= "<p>\n".'<input type="checkbox" name="forceid" value="yes">';
        !           523:     $Str .= &mt('Disable ID/Student Number Safeguard and Force Change '.
        !           524:                 'of Conflicting IDs (only do if you know what you are doing)').
        !           525:                 "\n</p><p>\n";
        !           526:     $Str .= '<input type="button" onClick="javascript:verify(this.form)" '.
        !           527:         'value="Update Courselist" />'."<br />\n";
        !           528:     $Str .= &mt('Note: for large courses, this operation may be time '.
        !           529:                 'consuming');
        !           530:     $r->print($Str);
        !           531:     return;
1.23      albertel  532: }
1.24      albertel  533: 
1.90    ! matthew   534: ###############################################################
        !           535: ###############################################################
1.50      matthew   536: sub print_upload_manager_form {
1.23      albertel  537:     my $r=shift;
1.82      www       538:     my $firstLine;
1.24      albertel  539:     my $datatoken;
                    540:     if (!$ENV{'form.datatoken'}) {
1.90    ! matthew   541:         $datatoken=&Apache::loncommon::upfile_store($r);
1.24      albertel  542:     } else {
1.90    ! matthew   543:         $datatoken=$ENV{'form.datatoken'};
        !           544:         &Apache::loncommon::load_tmp_file($r);
1.24      albertel  545:     }
                    546:     my @records=&Apache::loncommon::upfile_record_sep();
1.90    ! matthew   547:     if($ENV{'form.noFirstLine'}){
        !           548:         $firstLine=shift(@records);
        !           549:     }
1.23      albertel  550:     my $total=$#records;
                    551:     my $distotal=$total+1;
                    552:     my $today=time;
                    553:     my $halfyear=$today+15552000;
1.85      matthew   554:     my $defdom=$ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
1.64      albertel  555:     my ($krbdef,$krbdefdom) =
                    556:         &Apache::loncommon::get_kerberos_defaults($defdom);
1.50      matthew   557:     &print_upload_manager_header($r,$datatoken,$distotal,$krbdefdom);
1.24      albertel  558:     my $i;
                    559:     my $keyfields;
1.23      albertel  560:     if ($total>=0) {
1.90    ! matthew   561:         my @field=(['username',&mt('Username')],
        !           562:                    ['names',&mt('Last Name, First Names')],
        !           563:                    ['fname',&mt('First Name')],
        !           564:                    ['mname',&mt('Middle Names/Initials')],
        !           565:                    ['lname',&mt('Last Name')],
        !           566:                    ['gen',&mt('Generation')],
        !           567:                    ['id',&mt('ID/Student Number')],
        !           568:                    ['sec',&mt('Group/Section')],
        !           569:                    ['ipwd',&mt('Initial Password')],
        !           570:                    ['email',&mt('EMail Address')]);
1.24      albertel  571: 	if ($ENV{'form.upfile_associate'} eq 'reverse') {	
                    572: 	    &Apache::loncommon::csv_print_samples($r,\@records);
1.90    ! matthew   573: 	    $i=&Apache::loncommon::csv_print_select_table($r,\@records,
        !           574:                                                           \@field);
        !           575: 	    foreach (@field) { 
        !           576:                 $keyfields.=$_->[0].','; 
        !           577:             }
1.24      albertel  578: 	    chop($keyfields);
                    579: 	} else {
1.90    ! matthew   580: 	    unshift(@field,['none','']);
        !           581: 	    $i=&Apache::loncommon::csv_samples_select_table($r,\@records,
        !           582:                                                             \@field);
1.24      albertel  583: 	    my %sone=&Apache::loncommon::record_sep($records[0]);
                    584: 	    $keyfields=join(',',sort(keys(%sone)));
1.23      albertel  585: 	}
                    586:     }
1.50      matthew   587:     &print_upload_manager_footer($r,$i,$keyfields,$defdom,$today,$halfyear);
1.10      www       588: }
                    589: 
1.90    ! matthew   590: ###############################################################
        !           591: ###############################################################
1.12      www       592: sub enroll_single_student {
                    593:     my $r=shift;
1.80      matthew   594:     # Remove non alphanumeric values from section
                    595:     $ENV{'form.csec'}=~s/\W//g;
1.68      matthew   596:     #
                    597:     # We do the dates first because the action of making them the defaul
                    598:     # in the course is entirely seperate from the action of enrolling the
                    599:     # student.  Also, a failure in setting the dates as default is not fatal
                    600:     # to the process of enrolling / modifying a student.
                    601:     my ($startdate,$enddate) = &get_dates_from_form();
                    602:     if ($ENV{'form.makedatesdefault'}) {
                    603:         $r->print(&make_dates_default($startdate,$enddate));
                    604:     }
                    605: 
1.12      www       606:     $r->print('<h3>Enrolling Student</h3>');
1.54      matthew   607:     $r->print('<p>Enrolling '.$ENV{'form.cuname'}." \@ ".
1.34      matthew   608:               $ENV{'form.lcdomain'}.'</p>');
1.12      www       609:     if (($ENV{'form.cuname'})&&($ENV{'form.cuname'}!~/\W/)&&
1.31      matthew   610:         ($ENV{'form.lcdomain'})&&($ENV{'form.lcdomain'}!~/\W/)) {
                    611:         # Deal with home server selection
                    612:         my $domain=$ENV{'form.lcdomain'};
                    613:         my $desiredhost = $ENV{'form.lcserver'};
                    614:         if (lc($desiredhost) eq 'default') {
                    615:             $desiredhost = undef;
                    616:         } else {
1.45      matthew   617:             my %home_servers =&Apache::loncommon::get_library_servers($domain);
1.31      matthew   618:             if (! exists($home_servers{$desiredhost})) {
                    619:                 $r->print('<font color="#ff0000">Error:</font>'.
                    620:                           'Invalid home server specified');
                    621:                 return;
                    622:             }
                    623:         }
1.34      matthew   624:         $r->print(" with server $desiredhost :") if (defined($desiredhost));
1.31      matthew   625:         # End of home server selection logic
1.12      www       626: 	my $amode='';
                    627:         my $genpwd='';
                    628:         if ($ENV{'form.login'} eq 'krb') {
1.47      albertel  629:            $amode='krb';
                    630: 	   $amode.=$ENV{'form.krbver'};
1.28      matthew   631:            $genpwd=$ENV{'form.krbarg'};
1.12      www       632:         } elsif ($ENV{'form.login'} eq 'int') {
1.26      matthew   633:            $amode='internal';
1.28      matthew   634:            $genpwd=$ENV{'form.intarg'};
1.15      albertel  635:         }  elsif ($ENV{'form.login'} eq 'loc') {
                    636: 	    $amode='localauth';
                    637: 	    $genpwd=$ENV{'form.locarg'};
                    638: 	    if (!$genpwd) { $genpwd=" "; }
                    639: 	}
1.34      matthew   640:         my $home = &Apache::lonnet::homeserver($ENV{'form.cuname'},
                    641:                                                    $ENV{'form.lcdomain'});
                    642:         if ((($amode) && ($genpwd)) || ($home ne 'no_host')) {
1.55      matthew   643:             # Clean out any old roles the student has in this class.
1.33      matthew   644:             &modifystudent($ENV{'form.lcdomain'},$ENV{'form.cuname'},
                    645:                            $ENV{'request.course.id'},$ENV{'form.csec'},
                    646:                             $desiredhost);
1.55      matthew   647:             my $login_result = &Apache::lonnet::modifystudent
                    648:                 ($ENV{'form.lcdomain'},$ENV{'form.cuname'},
                    649:                  $ENV{'form.cstid'},$amode,$genpwd,
                    650:                  $ENV{'form.cfirst'},$ENV{'form.cmiddle'},
                    651:                  $ENV{'form.clast'},$ENV{'form.cgen'},
1.67      matthew   652:                  $ENV{'form.csec'},$enddate,
                    653:                  $startdate,$ENV{'form.forceid'},
1.55      matthew   654:                  $desiredhost);
                    655:             if ($login_result =~ /^ok/) {
                    656:                 $r->print($login_result);
                    657:                 $r->print("<p> If active, the new role will be available ".
                    658:                           "when the student next logs in to LON-CAPA.</p>");
                    659:             } else {
                    660:                 $r->print("unable to enroll: ".$login_result);
                    661:             }
1.12      www       662: 	} else {
1.79      matthew   663:             $r->print('<p><font color="#ff0000">ERROR</font>&nbsp;');
                    664:             if ($amode =~ /^krb/) {
                    665:                 $r->print('Missing Kerberos domain information.  ');
                    666:             } else {
                    667:                 $r->print('Invalid login mode or password.  ');
                    668:             }
                    669:             $r->print('<b>Unable to enroll '.$ENV{'form.cuname'}.'.</b></p>');
                    670:         }
1.12      www       671:     } else {
                    672:         $r->print('Invalid username or domain');
1.26      matthew   673:     }    
1.12      www       674: }
                    675: 
1.68      matthew   676: sub setup_date_selectors {
                    677:     my ($starttime,$endtime) = @_;
                    678:     if (! defined($starttime)) {
                    679:         $starttime = time;
                    680:         if (exists($ENV{'course.'.$ENV{'request.course.id'}.
                    681:                             '.default_enrollment_start_date'})) {
                    682:             $starttime = $ENV{'course.'.$ENV{'request.course.id'}.
                    683:                                   '.default_enrollment_start_date'};
                    684:         }
                    685:     }
                    686:     if (! defined($endtime)) {
                    687:         $endtime = time+(6*30*24*60*60); # 6 months from now, approx
                    688:         if (exists($ENV{'course.'.$ENV{'request.course.id'}.
                    689:                             '.default_enrollment_end_date'})) {
                    690:             $endtime = $ENV{'course.'.$ENV{'request.course.id'}.
                    691:                                 '.default_enrollment_end_date'};
                    692:         }
                    693:     }
                    694:     my $startdateform = &Apache::lonhtmlcommon::date_setter('studentform',
                    695:                                                             'startdate',
                    696:                                                             $starttime);
                    697:     my $enddateform = &Apache::lonhtmlcommon::date_setter('studentform',
                    698:                                                           'enddate',
                    699:                                                           $endtime);
                    700:     return ($startdateform,$enddateform);
                    701: }
                    702: 
                    703: sub get_dates_from_form {
                    704:     my $startdate = &Apache::lonhtmlcommon::get_date_from_form('startdate');
                    705:     my $enddate   = &Apache::lonhtmlcommon::get_date_from_form('enddate');
                    706:     if ($ENV{'form.no_end_date'}) {
                    707:         $enddate = 0;
                    708:     }
                    709:     return ($startdate,$enddate);
                    710: }
                    711: 
                    712: sub date_setting_table {
                    713:     my ($starttime,$endtime) = @_;
                    714:     my ($startform,$endform)=&setup_date_selectors($starttime,$endtime);
                    715:     my $dateDefault = '<nobr>'.
                    716:         '<input type="checkbox" name="makedatesdefault" />'.
                    717:         ' make these dates the default for future enrollment';
                    718:     my $perpetual = '<nobr><input type="checkbox" name="no_end_date"';
                    719:     if (defined($endtime) && $endtime == 0) {
                    720:         $perpetual .= ' checked';
                    721:     }
                    722:     $perpetual.= ' />'.' no ending date</nobr>';
                    723:     my $result = '';
                    724:     $result .= "<table>\n";
                    725:     $result .= '<tr><td align="right">Starting Date</td>'.
                    726:         '<td>'.$startform.'</td>'.
                    727:         '<td>'.$dateDefault.'</td>'."</tr>\n";
                    728:     $result .= '<tr><td align="right">Ending Date</td>'.
                    729:         '<td>'.$endform.'</td>'.
                    730:         '<td>'.$perpetual.'</td>'."</tr>\n";
                    731:     $result .= "</table>\n";
                    732:     return $result;
                    733: }
                    734: 
                    735: sub make_dates_default {
                    736:     my ($startdate,$enddate) = @_;
                    737:     my $result = '';
                    738:     my $dom = $ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
                    739:     my $crs = $ENV{'course.'.$ENV{'request.course.id'}.'.num'};
                    740:     my $put_result = &Apache::lonnet::put('environment',
                    741:             {'default_enrollment_start_date'=>$startdate,
                    742:              'default_enrollment_end_date'  =>$enddate},$dom,$crs);
                    743:     if ($put_result eq 'ok') {
                    744:         $result .= "Set default start and end dates for course<br />";
1.69      matthew   745:         #
                    746:         # Refresh the course environment
                    747:         &Apache::lonnet::coursedescription($ENV{'request.course.id'});
1.68      matthew   748:     } else {
                    749:         $result .= "Unable to set default dates for course:".$put_result.
                    750:             '<br />';
                    751:     }
                    752:     return $result;
                    753: }
                    754: 
1.74      matthew   755: ##
                    756: ## Single student enrollment routines (some of them)
                    757: ##
                    758: sub get_student_username_domain_form {
                    759:     my $r = shift;
                    760:     my $domform = &Apache::loncommon::select_dom_form
1.85      matthew   761:         ($ENV{'course.'.$ENV{'request.course.id'}.'.domain'},'cudomain',0);
1.74      matthew   762:     $r->print(<<END);
                    763: <input type="hidden" name="action" value="enrollstudent" />
                    764: <input type="hidden" name="state"  value="gotusername" />
                    765: <h3>Enroll One Student</h3>
                    766: <table>
                    767: <tr><th>Username:</th>
                    768:     <td><input type="text" name="cuname"  size="15" /></td></tr>
                    769: <tr><th>Domain:</th>
                    770:     <td>$domform</td></tr>
                    771: <tr><th>&nbsp;</th>
                    772:     <td>
                    773:     <input type="submit" name="Begin Enrollment" value="Begin Enrollment" />
                    774:     </td></tr>
                    775: </table>
                    776: END
                    777:     return;
                    778: }
                    779: 
1.50      matthew   780: sub print_enroll_single_student_form {
1.10      www       781:     my $r=shift;
1.40      matthew   782:     $r->print("<h3>Enroll One Student</h3>");
1.74      matthew   783:     #
                    784:     my $username = $ENV{'form.cuname'};
                    785:     my $domain   = $ENV{'form.cudomain'};
                    786:     my $home = &Apache::lonnet::homeserver($username,$domain);
                    787:     # $new_user flags whether we are creating a new user or using an old one
                    788:     my $new_user = 1;
                    789:     if ($home ne 'no_host') {
                    790:         $new_user = 0;
                    791:     }
                    792:     #
                    793:     my $user_data_html = '';
                    794:     my $javascript_validations = '';
                    795:     if ($new_user) {
1.85      matthew   796:         my $defdom=$ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
1.74      matthew   797:         # Set up authentication forms
                    798:         my ($krbdef,$krbdefdom) =
1.75      matthew   799:             &Apache::loncommon::get_kerberos_defaults($domain);
1.89      matthew   800:         $javascript_validations=&javascript_validations('auth',$krbdefdom);
1.74      matthew   801:         my %param = ( formname => 'document.studentform',
                    802:                       kerb_def_dom => $krbdefdom,
                    803:                       kerb_def_auth => $krbdef
                    804:                       );
                    805:         my $krbform = &Apache::loncommon::authform_kerberos(%param);
                    806:         my $intform = &Apache::loncommon::authform_internal(%param);
                    807:         my $locform = &Apache::loncommon::authform_local(%param);
                    808:         #
                    809:         # Set up domain selection form
                    810:         my $homeserver_form = '';
                    811:         my %servers = &Apache::loncommon::get_library_servers($domain);
                    812:         $homeserver_form = '<select name="lcserver" size="1">'."\n".
                    813:             '<option value="default" selected>default</option>'."\n";
                    814:         while (my ($servername,$serverdescription) = each (%servers)) {
                    815:             $homeserver_form .= '<option value="'.$servername.'">'.
                    816:                 $serverdescription."</option>\n";
                    817:         }
                    818:         $homeserver_form .= "</select>\n";
                    819:         #
                    820:         #
                    821:         $user_data_html = <<END;
                    822: <h3>User Data for $username\@$domain</h3>
                    823: <table>
                    824: <tr><th>First Name:</th>
                    825:     <td><input type="text" name="cfirst"  size="15"></td></tr>
                    826: <tr><th>Middle Name:</th>
                    827:     <td><input type="text" name="cmiddle" size="15"></td></tr>
                    828: <tr><th>Last Name:</th>
                    829:     <td><input type="text" name="clast"   size="15"></td></tr>
                    830: <tr><th>Generation:</th>
                    831:     <td><input type="text" name="cgen"    size="5"> </td></tr>
                    832: <tr><th>Home Server:</th>
                    833:     <td>$homeserver_form</td></tr>
                    834: </table>
                    835: <h3>Password</h3>
                    836: Please select an authentication mechanism
                    837: <table>
                    838: <p>
                    839: $krbform
1.75      matthew   840: <br />
1.74      matthew   841: $intform
1.75      matthew   842: <br />
1.74      matthew   843: $locform
                    844: </p>
                    845: END
                    846:     } else {
                    847:         # User already exists.  Do not worry about authentication
                    848:         my %uenv = &Apache::lonnet::dump('environment',$domain,$username);
1.89      matthew   849:         $javascript_validations = &javascript_validations('noauth');
1.74      matthew   850:         $user_data_html = <<END;
                    851: <h3>User Data for $username\@$domain</h3>
                    852: <input type="hidden" name="lcserver" value="default" />
                    853: <table>
                    854: <tr><th>First Name:</th>
                    855:     <td>
                    856:     <input type="text" name="cfirst" value="$uenv{'firstname'}" size="15" />
                    857:     </td></tr>
                    858: <tr><th>Middle Name:</th>
                    859:     <td>
                    860:     <input type="text" name="cmiddle" value="$uenv{'middlename'}" size="15" />
                    861:     </td></tr>
                    862: <tr><th>Last Name:</th>
                    863:     <td>
                    864:     <input type="text" name="clast"value="$uenv{'lastname'}" size="15" />
                    865:     </td></tr>
                    866: <tr><th>Generation:</th>
                    867:     <td>
                    868:     <input type="text" name="cgen" value="$uenv{'generation'}" size="5" />
                    869:     </td></tr>
                    870: </table>
                    871: END
                    872:     }
1.68      matthew   873:     my $date_table = &date_setting_table();
1.74      matthew   874:         # Print it all out
1.50      matthew   875:     $r->print(<<END);
1.74      matthew   876: <input type="hidden" name="action" value="enrollstudent" />
                    877: <input type="hidden" name="state"  value="done" />
                    878: <input type="hidden" name="cuname" value="$username" />
                    879: <input type="hidden" name="lcdomain" value="$domain" />
1.28      matthew   880: <script type="text/javascript" language="Javascript">
1.12      www       881: function verify(vf) {
                    882:     var founduname=0;
                    883:     var foundpwd=0;
                    884:     var foundname=0;
                    885:     var foundid=0;
                    886:     var foundsec=0;
                    887:     var tw;
1.26      matthew   888:     if ((typeof(vf.cuname.value) !="undefined") && (vf.cuname.value!='') && 
1.31      matthew   889: 	(typeof(vf.lcdomain.value)!="undefined") && (vf.lcdomain.value!='')) {
1.12      www       890:         founduname=1;
                    891:     }
1.14      harris41  892:     if ((typeof(vf.cfirst.value)!="undefined") && (vf.cfirst.value!='') &&
1.26      matthew   893: 	(typeof(vf.clast.value) !="undefined") && (vf.clast.value!='')) {
1.12      www       894:         foundname=1;
                    895:     }
1.14      harris41  896:     if ((typeof(vf.csec.value)!="undefined") && (vf.csec.value!='')) {
1.12      www       897:         foundsec=1;
                    898:     }
1.14      harris41  899:     if ((typeof(vf.cstid.value)!="undefined") && (vf.cstid.value!='')) {
1.12      www       900: 	foundid=1;
                    901:     }
                    902:     if (founduname==0) {
                    903: 	alert('You need to specify at least the username and domain fields');
                    904:         return;
                    905:     }
1.24      albertel  906:     verify_message(vf,founduname,foundpwd,foundname,foundid,foundsec);
1.12      www       907: }
                    908: 
1.24      albertel  909: $javascript_validations
1.12      www       910: 
1.24      albertel  911: function clearpwd(vf) {
                    912:     //nothing else needs clearing
1.15      albertel  913: }
                    914: 
1.12      www       915: </script>
1.11      www       916: 
1.74      matthew   917: $user_data_html
1.50      matthew   918: 
                    919: <h3>Course Data</h3>
                    920: 
                    921: <p>Group/Section: <input type="text" name="csec" size="5" />
                    922: <p>
1.68      matthew   923: $date_table
1.50      matthew   924: </p>
                    925: <h3>ID/Student Number</h3>
                    926: <p>
                    927: ID/Student Number: <input type="text" name="cstid" size="10">
1.26      matthew   928: </p><p>
                    929: <input type="checkbox" name="forceid" value="yes"> 
1.18      www       930: Disable ID/Student Number Safeguard and Force Change of Conflicting IDs
1.50      matthew   931: (only do if you know what you are doing)
                    932: </p><p>
                    933: <input type="button" onClick="verify(this.form)" value="Enroll as student">
1.26      matthew   934: </p>
1.50      matthew   935: END
                    936:     return;
1.10      www       937: }
                    938: 
                    939: # ========================================================= Menu Phase Two Drop
1.51      matthew   940: sub print_drop_menu {
1.10      www       941:     my $r=shift;
1.40      matthew   942:     $r->print("<h3>Drop Students</h3>");
1.11      www       943:     my $cid=$ENV{'request.course.id'};
1.56      matthew   944:     my ($classlist,$keylist) = &Apache::loncoursedata::get_classlist();
                    945:     if (! defined($classlist)) {
1.27      matthew   946:         $r->print("There are no students currently enrolled.\n");
1.51      matthew   947:         return;
1.25      matthew   948:     }
1.51      matthew   949:     # Print out the available choices
1.56      matthew   950:     &show_drop_list($r,$classlist,$keylist);
1.51      matthew   951:     return;
1.11      www       952: }
                    953: 
1.40      matthew   954: # ============================================== view classlist
1.50      matthew   955: sub print_html_classlist {
1.40      matthew   956:     my $r=shift;
1.57      matthew   957:     if (! exists($ENV{'form.sortby'})) {
                    958:         $ENV{'form.sortby'} = 'username';
                    959:     }
1.59      matthew   960:     if ($ENV{'form.Status'} !~ /^(Any|Expired|Active)$/) {
1.57      matthew   961:         $ENV{'form.Status'} = 'Active';
                    962:     }
                    963:     my $status_select = &Apache::lonhtmlcommon::StatusOptions
                    964:         ($ENV{'form.Status'},'studentform');
1.48      matthew   965:     $r->print(<<END);
1.58      matthew   966: <input type="hidden" name="action" value="$ENV{'form.action'}" />
1.57      matthew   967: <input type="hidden" name="state"  value="" />
1.50      matthew   968: <p>
1.76      albertel  969: <font size="+1">Current Class List</font>
1.57      matthew   970: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
1.59      matthew   971: END
                    972:     if ($ENV{'form.action'} ne 'modifystudent') {
                    973:         $r->print(<<END);
1.57      matthew   974: <font size="+1">
                    975: <a href="javascript:document.studentform.state.value='csv';document.studentform.submit();">CSV format</a>
1.61      matthew   976: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
1.60      matthew   977: <a href="javascript:document.studentform.state.value='excel';document.studentform.submit();">Excel format</a>
1.57      matthew   978: </font>
                    979: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
1.61      matthew   980: Student Status:
1.48      matthew   981: END
1.59      matthew   982:     }
                    983:     $r->print($status_select."</p>\n");
1.40      matthew   984:     my $cid=$ENV{'request.course.id'};
1.56      matthew   985:     my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist();
                    986:     if (! defined($classlist)) {
1.40      matthew   987:         $r->print("There are no students currently enrolled.\n");
                    988:     } else {
                    989:         # Print out the available choices
1.50      matthew   990:         if ($ENV{'form.action'} eq 'modifystudent') {
1.53      matthew   991:             &show_class_list($r,'view','modify','modifystudent',
1.57      matthew   992:                              $ENV{'form.Status'},$classlist,$keylist);
1.50      matthew   993:         } else {
1.53      matthew   994:             &show_class_list($r,'view','aboutme','classlist',
1.57      matthew   995:                              $ENV{'form.Status'},$classlist,$keylist);
1.50      matthew   996:         }
1.41      matthew   997:     }
                    998: }
                    999: 
                   1000: # ============================================== view classlist
1.60      matthew  1001: sub print_formatted_classlist {
1.41      matthew  1002:     my $r=shift;
1.60      matthew  1003:     my $mode = shift;
1.41      matthew  1004:     my $cid=$ENV{'request.course.id'};
1.56      matthew  1005:     my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist();
                   1006:     if (! defined($classlist)) {
1.41      matthew  1007:         $r->print("There are no students currently enrolled.\n");
                   1008:     } else {
1.60      matthew  1009:         &show_class_list($r,$mode,'nolink','csv',
1.57      matthew  1010:                          $ENV{'form.Status'},$classlist,$keylist);
1.40      matthew  1011:     }
                   1012: }
                   1013: 
                   1014: # =================================================== Show student list to drop
                   1015: sub show_class_list {
1.56      matthew  1016:     my ($r,$mode,$linkto,$action,$statusmode,$classlist,$keylist)=@_;
1.40      matthew  1017:     my $cid=$ENV{'request.course.id'};
1.60      matthew  1018:     #
                   1019:     # Variables for excel output
                   1020:     my ($excel_workbook, $excel_sheet, $excel_filename,$row);
                   1021:     #
1.53      matthew  1022:     my $sortby = $ENV{'form.sortby'};
                   1023:     if ($sortby !~ /^(username|domain|section|fullname|id)$/) {
                   1024:         $sortby = 'username';
                   1025:     }
1.42      matthew  1026:     # Print out header 
1.41      matthew  1027:     if ($mode eq 'view') {
1.50      matthew  1028:         if ($linkto eq 'aboutme') {
1.56      matthew  1029:             $r->print('Select a user name to view the users personal page.');
1.50      matthew  1030:         } elsif ($linkto eq 'modify') {
                   1031:             $r->print('Select a user name to modify the students information');
                   1032:         }
1.41      matthew  1033:         $r->print(<<END);
1.59      matthew  1034: 
1.53      matthew  1035: <input type="hidden" name="sortby" value="$sortby" />
1.59      matthew  1036: <input type="hidden" name="sname"  value="" />
                   1037: <input type="hidden" name="sdom"   value="" />
1.40      matthew  1038: <p>
                   1039: <table border=2>
1.53      matthew  1040: <tr><th>
1.57      matthew  1041:        <a href="javascript:document.studentform.sortby.value='username';document.studentform.submit();">username</a>
1.53      matthew  1042:     </th><th>
1.57      matthew  1043:        <a href="javascript:document.studentform.sortby.value='domain';document.studentform.submit();">domain</a>
1.53      matthew  1044:     </th><th>
1.57      matthew  1045:        <a href="javascript:document.studentform.sortby.value='id';document.studentform.submit();">ID</a>
1.53      matthew  1046:     </th><th>
1.57      matthew  1047:        <a href="javascript:document.studentform.sortby.value='fullname';document.studentform.submit();">student name</a>
1.53      matthew  1048:     </th><th>
1.57      matthew  1049:        <a href="javascript:document.studentform.sortby.value='section';document.studentform.submit();">section</a>
1.53      matthew  1050:     </th>
                   1051: </tr>
1.40      matthew  1052: END
1.41      matthew  1053:     } elsif ($mode eq 'csv') {
1.58      matthew  1054:         if($statusmode eq 'Expired') {
                   1055:             $r->print('"Students with expired roles"');
                   1056:         }
                   1057:         if ($statusmode eq 'Any') {
                   1058:             $r->print('"'.join('","',("username","domain","ID","student name",
                   1059:                                       "section","status")).'"'."\n");
                   1060:         } else {
                   1061:             $r->print('"'.join('","',("username","domain","ID","student name",
                   1062:                                       "section")).'"'."\n");
                   1063:         }
1.60      matthew  1064:     } elsif ($mode eq 'excel') {
                   1065:         # Create the excel spreadsheet
                   1066:         $excel_filename = '/prtspool/'.
                   1067:             $ENV{'user.name'}.'_'.$ENV{'user.domain'}.'_'.
                   1068:                 time.'_'.rand(1000000000).'.xls';
                   1069:         $excel_workbook = Spreadsheet::WriteExcel->new('/home/httpd'.
                   1070:                                                        $excel_filename);
                   1071:         $excel_workbook->set_tempdir('/home/httpd/perl/tmp');
                   1072:         $excel_sheet = $excel_workbook->addworksheet('classlist');
                   1073:         #
1.76      albertel 1074:         my $description = 'Class List for '.
1.60      matthew  1075:             $ENV{'course.'.$ENV{'request.course.id'}.'.description'};
                   1076:         $excel_sheet->write($row++,0,$description);
                   1077:         #
                   1078:         $excel_sheet->write($row++,0,["username","domain","ID",
                   1079:                                       "student name","section","status"]);
1.41      matthew  1080:     }
1.56      matthew  1081:     #
                   1082:     # Sort the students
                   1083:     my %index;
                   1084:     my $i;
                   1085:     foreach (@$keylist) {
                   1086:         $index{$_} = $i++;
                   1087:     }
                   1088:     my $index  = $index{$sortby};
                   1089:     my $second = $index{'username'};
                   1090:     my $third  = $index{'domain'};
1.53      matthew  1091:     my @Sorted_Students = sort {
1.56      matthew  1092:         lc($classlist->{$a}->[$index])  cmp lc($classlist->{$b}->[$index])
                   1093:             ||
                   1094:         lc($classlist->{$a}->[$second]) cmp lc($classlist->{$b}->[$second])
                   1095:             ||
                   1096:         lc($classlist->{$a}->[$third]) cmp lc($classlist->{$b}->[$third])
                   1097:         } (keys(%$classlist));
1.53      matthew  1098:     foreach my $student (@Sorted_Students) {
1.56      matthew  1099:         my $username = $classlist->{$student}->[$index{'username'}];
                   1100:         my $domain   = $classlist->{$student}->[$index{'domain'}];
                   1101:         my $section  = $classlist->{$student}->[$index{'section'}];
                   1102:         my $name     = $classlist->{$student}->[$index{'fullname'}];
                   1103:         my $id       = $classlist->{$student}->[$index{'id'}];
                   1104:         my $status   = $classlist->{$student}->[$index{'status'}];
1.57      matthew  1105:         next if (($statusmode ne 'Any') && ($status ne $statusmode));
1.51      matthew  1106:         if ($mode eq 'view') {
                   1107:             $r->print("<tr>\n    <td>\n        ");
                   1108:             if ($linkto eq 'nothing') {
                   1109:                 $r->print($username);
                   1110:             } elsif ($linkto eq 'aboutme') {
                   1111:                 $r->print(&Apache::loncommon::aboutmewrapper($username,
                   1112:                                                              $username,
                   1113:                                                              $domain));
                   1114:             } elsif ($linkto eq 'modify') {
1.59      matthew  1115:                 $r->print('<a href="'.
                   1116:                           "javascript:document.studentform.sname.value='".
                   1117:                           $username.
                   1118:                           "';document.studentform.sdom.value='".$domain.
                   1119:                           "';document.studentform.state.value='selected".
                   1120:                           "';document.studentform.submit();".'">'.
1.53      matthew  1121:                           $username."</a>\n");
1.50      matthew  1122:             }
1.51      matthew  1123:             $r->print(<<"END");
1.50      matthew  1124:     </td>
1.51      matthew  1125:     <td>$domain</td>
                   1126:     <td>$id</td>
                   1127:     <td>$name</td>
                   1128:     <td>$section</td>
1.40      matthew  1129: </tr>
                   1130: END
1.51      matthew  1131:         } elsif ($mode eq 'csv') {
                   1132:             # no need to bother with $linkto
                   1133:             my @line = ();
                   1134:             foreach ($username,$domain,$id,$name,$section) {
                   1135:                 push @line,&Apache::loncommon::csv_translate($_);
1.58      matthew  1136:             }
                   1137:             if ($statusmode eq 'Any') {
                   1138:                 push @line,&Apache::loncommon::csv_translate($status);
1.41      matthew  1139:             }
1.51      matthew  1140:             my $tmp = $";
                   1141:             $" = '","';
                   1142:             $r->print("\"@line\"\n");
                   1143:             $" = $tmp;
1.60      matthew  1144:         } elsif ($mode eq 'excel') {
                   1145:             $excel_sheet->write($row++,0,[$username,$domain,$id,
                   1146:                                           $name,$section,$status]);
1.40      matthew  1147:         }
                   1148:     }
1.60      matthew  1149:     if ($mode eq 'view') {
                   1150:         $r->print('</table><br>');
                   1151:     } elsif ($mode eq 'excel') {
                   1152:         $excel_workbook->close();
                   1153:         $r->print('<p><a href="'.$excel_filename.'">'.
                   1154:                   'Your Excel spreadsheet</a> is ready for download.</p>'."\n");
                   1155:     }
1.40      matthew  1156: }
                   1157: 
1.50      matthew  1158: 
                   1159: #
                   1160: # print out form for modification of a single students data
                   1161: #
                   1162: sub print_modify_student_form {
                   1163:     my $r = shift();
                   1164:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.59      matthew  1165:                                             ['sdom','sname']);    
1.53      matthew  1166:     my $sname  = $ENV{'form.sname'};
                   1167:     my $sdom   = $ENV{'form.sdom'};
                   1168:     my $sortby = $ENV{'form.sortby'};
1.50      matthew  1169:     # determine the students name information
                   1170:     my %info=&Apache::lonnet::get('environment',
                   1171:                                   ['firstname','middlename',
1.52      matthew  1172:                                    'lastname','generation','id'],
1.50      matthew  1173:                                   $sdom, $sname);
                   1174:     my ($tmp) = keys(%info);
                   1175:     if ($tmp =~ /^(con_lost|error|no_such_host)/i) {
                   1176:         $r->print('<font color="#ff0000" size="+2">Error</font>'.
                   1177:                   '<p>'.
                   1178:                   'Unable to retrieve environment data for '.$sname.
                   1179:                   'in domain '.$sdom.'</p><p>'.
                   1180:                   'Please contact your LON-CAPA administrator '.
                   1181:                   'regarding this situation.</p></body></html>');
                   1182:         return;
                   1183:     }
                   1184:     # determine the students starting and ending times and section
                   1185:     my ($starttime,$endtime,$section) = &get_enrollment_data($sname,$sdom);
1.87      matthew  1186:     if ($starttime =~ /^error/) {
                   1187:         $r->print('<h2>Error</h2>');
                   1188:         $r->print('<p>'.$starttime.'</p>');
                   1189:         return;
                   1190:     }
1.50      matthew  1191:     # Deal with date forms
1.68      matthew  1192:     my $date_table = &date_setting_table($starttime,$endtime);
1.59      matthew  1193:     #
                   1194:     if (! exists($ENV{'form.Status'}) || 
                   1195:         $ENV{'form.Status'} !~ /^(Any|Expired|Active)$/) {
                   1196:         $ENV{'form.Status'} = 'crap';
                   1197:     }
1.50      matthew  1198:     # Make sure student is enrolled in course    
                   1199:     $r->print(<<END);
1.52      matthew  1200: <p>
                   1201: <font size="+1">
                   1202: Only domain coordinators can change a users password.
                   1203: </font>
                   1204: </p>
1.50      matthew  1205: <input type="hidden" name="slogin"  value="$sname"  />
                   1206: <input type="hidden" name="sdomain" value="$sdom" />
                   1207: <input type="hidden" name="action"  value="modifystudent" />
1.53      matthew  1208: <input type="hidden" name="state"   value="done" />
                   1209: <input type="hidden" name="sortby"  value="$sortby" />
1.59      matthew  1210: <input type="hidden" name="Status"  value="$ENV{'form.Status'}" />
                   1211: 
1.50      matthew  1212: <h2>Modify Enrollment for $info{'firstname'} $info{'middlename'} 
                   1213: $info{'lastname'} $info{'generation'}, $sname\@$sdom</h2>
                   1214: <p>
                   1215: <b>Student Name</b>
                   1216: <table>
                   1217: <tr><th>First</th><th>Middle</th><th>Last</th><th>Generation</th></tr>
                   1218: <tr><td>
                   1219: <input type="text" name="firstname"  value="$info{'firstname'}"  /></td><td>
                   1220: <input type="text" name="middlename" value="$info{'middlename'}" /></td><td>
                   1221: <input type="text" name="lastname"   value="$info{'lastname'}"   /></td><td>
                   1222: <input type="text" name="generation" value="$info{'generation'}" /></td></tr>
                   1223: </table>
                   1224: </p><p>
1.52      matthew  1225: <b>Student ID</b>: <input type="text" name="id" value="$info{'id'}" size="12"/>
                   1226: </p><p>
1.53      matthew  1227: <input type="checkbox" name="forceid" > 
                   1228: Disable ID/Student Number Safeguard and Force Change of Conflicting IDs
                   1229: (only do if you know what you are doing)
                   1230: </p><p>
1.50      matthew  1231: <b>Section</b>: <input type="text" name="section" value="$section" size="4"/>
                   1232: </p>
1.68      matthew  1233: <p>$date_table</p>
1.50      matthew  1234: <input type="submit" value="Submit Modifications" />
                   1235: </body></html>
                   1236: END
                   1237:     return;
                   1238: }
                   1239: 
                   1240: #
                   1241: # modify a single students section 
                   1242: #
                   1243: sub modify_single_student {
                   1244:     my $r = shift;
1.68      matthew  1245:     #
1.80      matthew  1246:     # Remove non alphanumeric values from the section
                   1247:     $ENV{'form.section'} =~ s/\W//g;
1.77      matthew  1248:     #
1.68      matthew  1249:     # Do the date defaults first
                   1250:     my ($starttime,$endtime) = &get_dates_from_form();
                   1251:     if ($ENV{'form.makedatesdefault'}) {
                   1252:         $r->print(&make_dates_default($starttime,$endtime));
                   1253:     }
1.59      matthew  1254:     # Get the 'sortby' and 'Status' variables so the user goes back to their
                   1255:     # previous screen
1.53      matthew  1256:     my $sortby = $ENV{'form.sortby'};
1.59      matthew  1257:     my $status = $ENV{'form.Status'};
1.53      matthew  1258:     #
                   1259:     # We always need this information
                   1260:     my $slogin     = $ENV{'form.slogin'};
                   1261:     my $sdom       = $ENV{'form.sdomain'};
                   1262:     #
                   1263:     # Get the old data
                   1264:     my %old=&Apache::lonnet::get('environment',
                   1265:                                  ['firstname','middlename',
                   1266:                                   'lastname','generation','id'],
                   1267:                                  $sdom, $slogin);
1.59      matthew  1268:     $old{'section'} = &Apache::lonnet::getsection($sdom,$slogin,
                   1269:                                                   $ENV{'request.course.id'});
1.53      matthew  1270:     my ($tmp) = keys(%old);
                   1271:     if ($tmp =~ /^(con_lost|error|no_such_host)/i) {
                   1272:         $r->print("There was an error determining the environment values ".
                   1273:                   " for $slogin \@ $sdom.");
                   1274:         return;
                   1275:     }
                   1276:     undef $tmp;
                   1277:     #
                   1278:     # Get the new data
1.50      matthew  1279:     my $firstname  = $ENV{'form.firstname'};
                   1280:     my $middlename = $ENV{'form.middlename'};
                   1281:     my $lastname   = $ENV{'form.lastname'};
                   1282:     my $generation = $ENV{'form.generation'};
                   1283:     my $section    = $ENV{'form.section'};
                   1284:     my $courseid   = $ENV{'request.course.id'};
1.52      matthew  1285:     my $sid        = $ENV{'form.id'};
1.50      matthew  1286:     my $displayable_starttime = localtime($starttime);
                   1287:     my $displayable_endtime   = localtime($endtime);
1.53      matthew  1288:     # 
                   1289:     # check for forceid override
1.63      matthew  1290:     if ((defined($old{'id'})) && ($old{'id'} ne '') && 
                   1291:         ($sid ne $old{'id'}) && (! exists($ENV{'form.forceid'}))) {
1.53      matthew  1292:         $r->print("<font color=\"ff0000\">You changed the students id ".
                   1293:                   " but did not disable the ID change safeguard.".
                   1294:                   "  The students id will not be changed.</font>");
                   1295:         $sid = $old{'id'};
                   1296:     }
                   1297:     #
1.50      matthew  1298:     # talk to the user about what we are going to do
                   1299:     $r->print(<<END);
1.53      matthew  1300:     <h2>Modifying data for user $slogin \@ $sdom </h2>
1.50      matthew  1301: <h3>Student Information</h3>
1.53      matthew  1302: <table rules="rows" border="1" cellpadding="3" >
                   1303: <tr>
                   1304:     <th> Field </th>
                   1305:     <th> Old Value </th>
                   1306:     <th> New Value </th>
                   1307: </tr>
                   1308: <tr>
                   1309:     <td> <b>First name</b> </td>
                   1310:     <td> $old{'firstname'} </td>
                   1311:     <td> $firstname </td>
                   1312: </tr><tr>
                   1313:     <td> <b>Middle name</b> </td>
                   1314:     <td> $old{'middlename'} </td>
                   1315:     <td> $middlename </td>
                   1316: </tr><tr>
                   1317:     <td> <b>Last name</b> </td>
                   1318:     <td> $old{'lastname'} </td>
                   1319:     <td> $lastname </td>
                   1320: </tr><tr>
                   1321:     <td> <b>Generation</b> </td>
                   1322:     <td> $old{'generation'} </td>
                   1323:     <td> $generation </td>
                   1324: </tr><tr>
                   1325:     <td> <b>ID</b> </td>
                   1326:     <td> $old{'id'} </td>
                   1327:     <td> $sid </td>
1.59      matthew  1328: </tr><tr>
                   1329:     <td> <b>Section</b> </td>
                   1330:     <td> $old{'section'} </td>
                   1331:     <td> $section</td>
1.53      matthew  1332: </tr>
1.50      matthew  1333: </table>
                   1334: <h3>Role Information</h3>
                   1335: <table>
1.68      matthew  1336: <tr><td align="right"><b>Start Time:</b></td><td> $displayable_starttime </td></tr>
                   1337: <tr><td align="right"><b>End Time:</b></td><td> $displayable_endtime   </td></tr>
1.50      matthew  1338: </table>
1.52      matthew  1339: <p>
1.50      matthew  1340: END
1.53      matthew  1341:     #
1.63      matthew  1342:     # Send request(s) to modify data (final undef is for 'desiredhost',
                   1343:     # which is a moot point because the student already has an account.
                   1344:     my $modify_section_results = &modifystudent($sdom,$slogin,
                   1345:                                                 $ENV{'request.course.id'},
                   1346:                                                 $section,undef);
                   1347:     if ($modify_section_results !~ /^ok/) {
                   1348:         $r->print("An error occured during the attempt to change the ".
                   1349:                   "section for this student.<br />");
                   1350:     }
1.52      matthew  1351:     my $roleresults = &Apache::lonnet::modifystudent
1.53      matthew  1352:         ($sdom,$slogin,$sid,undef,undef,$firstname,$middlename,$lastname,
                   1353:          $generation,$section,$endtime,$starttime,$ENV{'form.forceid'});
                   1354:     if ($roleresults eq 'refused' ) {
1.50      matthew  1355:         $r->print("Your request to change the role information for this ".
1.53      matthew  1356:                   "student was refused.  You do not appear to have ".
                   1357:                   "sufficient authority to change student information.");
1.50      matthew  1358:     } elsif ($roleresults !~ /ok/) {
                   1359:         $r->print("An error occurred during the attempt to change the role".
1.52      matthew  1360:                   " information for this student.  <br />".
                   1361:                   "The error reported was ".
1.50      matthew  1362:                   $roleresults);
1.53      matthew  1363:         &Apache::lonnet::logthis("londropadd:failed attempt to modify student".
                   1364:                                  " data for ".$slogin." \@ ".$sdom." by ".
                   1365:                                  $ENV{'user.name'}." \@ ".$ENV{'user.domain'}.
                   1366:                                  ":".$roleresults);
1.50      matthew  1367:     } else { # everything is okay!
1.52      matthew  1368:         $r->print("Student information updated successfully. <br />".
                   1369:                   "The student must log out and log in again to see ".
                   1370:                   "these changes.");
1.50      matthew  1371:     }
                   1372:     $r->print(<<END);
1.52      matthew  1373: </p><p>
1.59      matthew  1374: <input type="hidden" name="action" value="modifystudent" />
                   1375: <input type="hidden" name="sortby" value="$sortby" />
                   1376: <input type="hidden" name="Status" value="$status" />
                   1377: <a href="javascript:document.studentform.submit();">Modify another students data</a>
1.50      matthew  1378: </body></html>
                   1379: END
                   1380:     return;
                   1381: }
                   1382: 
                   1383: sub get_enrollment_data {
                   1384:     my ($sname,$sdomain) = @_;
                   1385:     my $courseid = $ENV{'request.course.id'};
                   1386:     $courseid =~ s:_:/:g;
                   1387:     my %roles = &Apache::lonnet::dump('roles',$sdomain,$sname);
                   1388:     my ($tmp) = keys(%roles);
                   1389:     # Bail out if we were unable to get the students roles
1.87      matthew  1390:     return ('error'.$tmp) if ($tmp =~ /^(con_lost|error|no_such_host)/i);
1.50      matthew  1391:     # Go through the roles looking for enrollment in this course
                   1392:     my ($end,$start) = (undef,undef);
                   1393:     my $section = '';
                   1394:     my $count = scalar(keys(%roles));
                   1395:     while (my ($course,$role) = each(%roles)) {
                   1396:         if ($course=~ /^\/$courseid\/*\s*(\w+)*_st$/ ) {
                   1397:             #
                   1398:             # Get active role
                   1399:             $section=$1;
                   1400:             (undef,$end,$start)=split(/\_/,$role);
                   1401:             my $now=time;
                   1402:             my $notactive=0;
                   1403:             if ($start) {
                   1404:                 if ($now<$start) { $notactive=1; }
                   1405:             }
                   1406:             if ($end) {
                   1407:                 if ($now>$end) { $notactive=1; }
                   1408:             } 
                   1409:             unless ($notactive) { return ($start,$end,$section); }
                   1410:         }
                   1411:     }
                   1412:     return ($start,$end,$section);
                   1413: }
                   1414: 
1.56      matthew  1415: #################################################
                   1416: #################################################
                   1417: 
                   1418: =pod
                   1419: 
                   1420: =item show_drop_list
                   1421: 
                   1422: Display a list of students to drop
                   1423: Inputs: 
                   1424: 
                   1425: =over 4
                   1426: 
                   1427: =item $r, Apache request
                   1428: 
                   1429: =item $classlist, hash pointer returned from loncoursedata::get_classlist();
                   1430: 
                   1431: =item $keylist, array pointer returned from loncoursedata::get_classlist() 
                   1432: which describes the order elements are stored in the %$classlist values.
                   1433: 
                   1434: =item $nosort, if true, sorting links are omitted.
                   1435: 
                   1436: =back
                   1437: 
                   1438: =cut
                   1439: 
                   1440: #################################################
                   1441: #################################################
1.11      www      1442: sub show_drop_list {
1.56      matthew  1443:     my ($r,$classlist,$keylist,$nosort)=@_;
1.11      www      1444:     my $cid=$ENV{'request.course.id'};
1.59      matthew  1445:     if (! exists($ENV{'form.sortby'})) {
                   1446:         &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
                   1447:                                                 ['sortby']);
                   1448:     }
1.54      matthew  1449:     my $sortby = $ENV{'form.sortby'};
                   1450:     if ($sortby !~ /^(username|domain|section|fullname|id)$/) {
                   1451:         $sortby = 'username';
                   1452:     }
1.56      matthew  1453:     #
1.54      matthew  1454:     my $action = "drop";
                   1455:     $r->print(<<END);
                   1456: <input type="hidden" name="sortby" value="$sortby" />
                   1457: <input type="hidden" name="action" value="$action" />
1.50      matthew  1458: <input type="hidden" name="state"  value="done" />
1.32      matthew  1459: <script>
1.51      matthew  1460: function checkAll(field) {
1.32      matthew  1461:     for (i = 0; i < field.length; i++)
                   1462:         field[i].checked = true ;
                   1463: }
                   1464: 
1.51      matthew  1465: function uncheckAll(field) {
1.32      matthew  1466:     for (i = 0; i < field.length; i++)
                   1467:         field[i].checked = false ;
                   1468: }
                   1469: </script>
                   1470: <p>
1.26      matthew  1471: <input type="hidden" name="phase" value="four">
1.56      matthew  1472: END
                   1473: 
                   1474:     if ($nosort) {
                   1475:         $r->print(<<END);
                   1476: <table border=2>
                   1477: <tr>
                   1478:     <th>&nbsp;</th>
                   1479:     <th>username</th>
                   1480:     <th>domain</th>
                   1481:     <th>ID</th>
                   1482:     <th>student name</th>
                   1483:     <th>section</th>
                   1484: </tr>
                   1485: END
                   1486: 
                   1487:     } else  {
                   1488:         $r->print(<<END);
1.26      matthew  1489: <table border=2>
1.54      matthew  1490: <tr><th>&nbsp;</th>
                   1491:     <th>
                   1492:        <a href="/adm/dropadd?action=$action&sortby=username">username</a>
                   1493:     </th><th>
                   1494:        <a href="/adm/dropadd?action=$action&sortby=domain">domain</a>
                   1495:     </th><th>
                   1496:        <a href="/adm/dropadd?action=$action&sortby=id">ID</a>
                   1497:     </th><th>
                   1498:        <a href="/adm/dropadd?action=$action&sortby=fullname">student name</a>
                   1499:     </th><th>
                   1500:        <a href="/adm/dropadd?action=$action&sortby=section">section</a>
                   1501:     </th>
                   1502: </tr>
1.26      matthew  1503: END
1.56      matthew  1504:     }
                   1505:     #
                   1506:     # Sort the students
                   1507:     my %index;
                   1508:     my $i;
                   1509:     foreach (@$keylist) {
                   1510:         $index{$_} = $i++;
                   1511:     }
                   1512:     my $index  = $index{$sortby};
                   1513:     my $second = $index{'username'};
                   1514:     my $third  = $index{'domain'};
1.54      matthew  1515:     my @Sorted_Students = sort {
1.56      matthew  1516:         lc($classlist->{$a}->[$index])  cmp lc($classlist->{$b}->[$index])
                   1517:             ||
                   1518:         lc($classlist->{$a}->[$second]) cmp lc($classlist->{$b}->[$second])
                   1519:             ||
                   1520:         lc($classlist->{$a}->[$third]) cmp lc($classlist->{$b}->[$third])
                   1521:         } (keys(%$classlist));
1.54      matthew  1522:     foreach my $student (@Sorted_Students) {
1.52      matthew  1523:         my $error;
1.56      matthew  1524:         my $username = $classlist->{$student}->[$index{'username'}];
                   1525:         my $domain   = $classlist->{$student}->[$index{'domain'}];
                   1526:         my $section  = $classlist->{$student}->[$index{'section'}];
                   1527:         my $name     = $classlist->{$student}->[$index{'fullname'}];
                   1528:         my $id       = $classlist->{$student}->[$index{'id'}];
                   1529:         my $status   = $classlist->{$student}->[$index{'status'}];
1.51      matthew  1530:         next if ($status ne 'Active');
                   1531:         #
                   1532:         $r->print(<<"END");
1.26      matthew  1533: <tr>
1.51      matthew  1534:     <td><input type="checkbox" name="droplist" value="$student"></td>
                   1535:     <td>$username</td>
                   1536:     <td>$domain</td>
                   1537:     <td>$id</td>
                   1538:     <td>$name</td>
                   1539:     <td>$section</td>
1.26      matthew  1540: </tr>
                   1541: END
1.25      matthew  1542:     }
                   1543:     $r->print('</table><br>');
1.32      matthew  1544:     $r->print(<<"END");
                   1545: </p><p>
                   1546: <input type="button" value="check all" onclick="javascript:checkAll(document.studentform.droplist)"> &nbsp;
                   1547: <input type="button" value="uncheck all" onclick="javascript:uncheckAll(document.studentform.droplist)"> 
                   1548: <p><input type=submit value="Drop Students"></p>
                   1549: END
1.51      matthew  1550:     return;
1.10      www      1551: }
                   1552: 
1.48      matthew  1553: #
                   1554: # Print out the initial form to get the courselist file
                   1555: #
                   1556: sub print_first_courselist_upload_form {
                   1557:     my $r=shift;
1.88      matthew  1558:     my $str;
                   1559:     $str  = '<input type="hidden" name="phase" value="two">';
                   1560:     $str .= '<input type="hidden" name="action" value="upload" />';
                   1561:     $str .= '<input type="hidden"   name="state"  value="got_file" />';
                   1562:     $str .= "<h3>".&mt('Upload a class list')."</h3>\n";
                   1563:     $str .= &Apache::loncommon::upfile_select_html();
                   1564:     $str .= "<p>\n";
                   1565:     $str .= '<input type="submit" name="fileupload" value="'.
                   1566:         &mt('Upload class list').'">'."\n";
                   1567:     $str .= '<input type="checkbox" name="noFirstLine" /> '.
                   1568:         &mt('Ignore First Line')."</p>\n";
                   1569:     $str .= &Apache::loncommon::help_open_topic("Course_Create_Class_List",
                   1570:                          "How do I create a class list from a spreadsheet").
                   1571:                              "<br />\n";
                   1572:     $str .= &Apache::loncommon::help_open_topic("Course_Convert_To_CSV",
                   1573:                            "How do I create a CSV file from a spreadsheet").
                   1574:                                "<br />\n";
                   1575:     $str .= "</body>\n</html>\n";
                   1576:     $r->print($str);
1.48      matthew  1577:     return;
                   1578: }
                   1579: 
1.10      www      1580: # ================================================= Drop/Add from uploaded file
                   1581: sub upfile_drop_add {
                   1582:     my $r=shift;
1.24      albertel 1583:     &Apache::loncommon::load_tmp_file($r);
                   1584:     my @studentdata=&Apache::loncommon::upfile_record_sep();
1.82      www      1585:     if($ENV{'form.noFirstLine'}){shift(@studentdata);}
1.26      matthew  1586:     my @keyfields = split(/\,/,$ENV{'form.keyfields'});
                   1587:     my $cid = $ENV{'request.course.id'};
1.25      matthew  1588:     my %fields=();
1.26      matthew  1589:     for (my $i=0; $i<=$ENV{'form.nfields'}; $i++) {
1.25      matthew  1590:         if ($ENV{'form.upfile_associate'} eq 'reverse') {
                   1591:             if ($ENV{'form.f'.$i} ne 'none') {
                   1592:                 $fields{$keyfields[$i]}=$ENV{'form.f'.$i};
                   1593:             }
                   1594:         } else {
                   1595:             $fields{$ENV{'form.f'.$i}}=$keyfields[$i];
                   1596:         }
                   1597:     }
1.26      matthew  1598:     #
1.68      matthew  1599:     my ($startdate,$enddate) = &get_dates_from_form();
                   1600:     if ($ENV{'form.makedatesdefault'}) {
                   1601:         $r->print(&make_dates_default($startdate,$enddate));
                   1602:     }
1.31      matthew  1603:     # Determine domain and desired host (home server)
1.25      matthew  1604:     my $domain=$ENV{'form.lcdomain'};
1.31      matthew  1605:     my $desiredhost = $ENV{'form.lcserver'};
                   1606:     if (lc($desiredhost) eq 'default') {
                   1607:         $desiredhost = undef;
                   1608:     } else {
1.45      matthew  1609:         my %home_servers = &Apache::loncommon::get_library_servers($domain);
1.31      matthew  1610:         if (! exists($home_servers{$desiredhost})) {
1.88      matthew  1611:             $r->print('<font color="#ff0000">'.&mt('Error').'</font>'.
                   1612:                       &mt('Invalid home server specified'));
                   1613:             $r->print("</body>\n</html>\n");
1.31      matthew  1614:             return;
                   1615:         }
                   1616:     }
1.26      matthew  1617:     # Determine authentication mechanism
                   1618:     my $amode  = '';
                   1619:     my $genpwd = '';
1.25      matthew  1620:     if ($ENV{'form.login'} eq 'krb') {
1.47      albertel 1621:         $amode='krb';
                   1622: 	$amode.=$ENV{'form.krbver'};
1.28      matthew  1623:         $genpwd=$ENV{'form.krbarg'};
1.25      matthew  1624:     } elsif ($ENV{'form.login'} eq 'int') {
                   1625:         $amode='internal';
1.28      matthew  1626:         if ((defined($ENV{'form.intarg'})) && ($ENV{'form.intarg'})) {
                   1627:             $genpwd=$ENV{'form.intarg'};
1.25      matthew  1628:         }
                   1629:     } elsif ($ENV{'form.login'} eq 'loc') {
                   1630:         $amode='localauth';
                   1631:         if ((defined($ENV{'form.locarg'})) && ($ENV{'form.locarg'})) {
                   1632:             $genpwd=$ENV{'form.locarg'};
1.79      matthew  1633:         }
                   1634:     }
                   1635:     if ($amode =~ /^krb/) {
                   1636:         if (! defined($genpwd) || $genpwd eq '') {
                   1637:             $r->print('<font color="red" size="+1">'.
1.88      matthew  1638:                       &mt('Unable to enroll students').'</font>  '.
                   1639:                       &mt('No Kerberos domain was specified.').'</p>');
1.79      matthew  1640:             $amode = ''; # This causes the loop below to be skipped
1.25      matthew  1641:         }
                   1642:     }
                   1643:     unless (($domain=~/\W/) || ($amode eq '')) {
1.26      matthew  1644:         #######################################
                   1645:         ##         Enroll Students           ##
                   1646:         #######################################
1.88      matthew  1647:         $r->print('<h3>'.&mt('Enrolling Students')."</h3>\n<p>\n");
1.25      matthew  1648:         my $count=0;
                   1649:         my $flushc=0;
                   1650:         my %student=();
1.26      matthew  1651:         # Get new classlist
1.25      matthew  1652:         foreach (@studentdata) {
                   1653:             my %entries=&Apache::loncommon::record_sep($_);
1.26      matthew  1654:             # Determine student name
1.25      matthew  1655:             unless (($entries{$fields{'username'}} eq '') ||
                   1656:                     (!defined($entries{$fields{'username'}}))) {
1.26      matthew  1657:                 my ($fname, $mname, $lname,$gen) = ('','','','');
1.25      matthew  1658:                 if (defined($fields{'names'})) {
1.26      matthew  1659:                     ($lname,$fname,$mname)=($entries{$fields{'names'}}=~
                   1660:                                             /([^\,]+)\,\s*(\w+)\s*(.*)$/);
1.25      matthew  1661:                 } else {
                   1662:                     if (defined($fields{'fname'})) {
                   1663:                         $fname=$entries{$fields{'fname'}};
                   1664:                     }
                   1665:                     if (defined($fields{'mname'})) {
                   1666:                         $mname=$entries{$fields{'mname'}};
                   1667:                     }
                   1668:                     if (defined($fields{'lname'})) {
                   1669:                         $lname=$entries{$fields{'lname'}};
                   1670:                     }
                   1671:                     if (defined($fields{'gen'})) {
                   1672:                         $gen=$entries{$fields{'gen'}};
                   1673:                     }
                   1674:                 }
                   1675:                 if ($entries{$fields{'username'}}=~/\W/) {
1.88      matthew  1676:                     $r->print('<br />'.
                   1677:       &mt('<b>[_1]</b>: Unacceptable username for user [_2] [_3] [_4] [_5]',
                   1678:           $entries{$fields{'username'}},$fname,$mname,$lname,$gen).
                   1679:                               '</b>');
1.25      matthew  1680:                 } else {
1.26      matthew  1681:                     # determine section number
1.25      matthew  1682:                     my $sec='';
                   1683:                     my $username=$entries{$fields{'username'}};
                   1684:                     if (defined($fields{'sec'})) {
                   1685:                         if (defined($entries{$fields{'sec'}})) {
                   1686:                             $sec=$entries{$fields{'sec'}};
                   1687:                         }
                   1688:                     }
1.80      matthew  1689:                     # remove non alphanumeric values from section
                   1690:                     $sec =~ s/\W//g;
1.26      matthew  1691:                     # determine student id number
1.25      matthew  1692:                     my $id='';
                   1693:                     if (defined($fields{'id'})) {
                   1694:                         if (defined($entries{$fields{'id'}})) {
                   1695:                             $id=$entries{$fields{'id'}};
                   1696:                         }
                   1697:                         $id=~tr/A-Z/a-z/;
                   1698:                     }
1.73      www      1699:                     # determine email address
                   1700:                     my $email='';
                   1701:                     if (defined($fields{'email'})) {
                   1702:                         if (defined($entries{$fields{'email'}})) {
                   1703:                             $email=$entries{$fields{'email'}};
                   1704:                             unless ($email=~/^[^\@]+\@[^\@]+$/) { $email=''; }
                   1705:                         }
                   1706:                     }
1.26      matthew  1707:                     # determine student password
1.25      matthew  1708:                     my $password='';
                   1709:                     if ($genpwd) { 
                   1710:                         $password=$genpwd; 
                   1711:                     } else {
                   1712:                         if (defined($fields{'ipwd'})) {
                   1713:                             if ($entries{$fields{'ipwd'}}) {
                   1714:                                 $password=$entries{$fields{'ipwd'}};
                   1715:                             }
                   1716:                         }
                   1717:                     }
1.56      matthew  1718:                     # Clean up whitespace
                   1719:                     foreach (\$domain,\$username,\$id,\$fname,\$mname,
                   1720:                              \$lname,\$gen,\$sec) {
                   1721:                         $$_ =~ s/(\s+$|^\s+)//g;
                   1722:                     }
1.84      albertel 1723:                     if ($password || $ENV{'form.login'} eq 'loc') {
1.33      matthew  1724:                         &modifystudent($domain,$username,$cid,$sec,
                   1725:                                        $desiredhost);
1.25      matthew  1726:                         my $reply=&Apache::lonnet::modifystudent
                   1727:                             ($domain,$username,$id,$amode,$password,
                   1728:                              $fname,$mname,$lname,$gen,$sec,$enddate,
1.73      www      1729:                              $startdate,$ENV{'form.forceid'},$desiredhost,
                   1730:                              $email);
1.26      matthew  1731:                         if ($reply ne 'ok') {
1.72      matthew  1732:                             $reply =~ s/^error://;
1.88      matthew  1733:                             $r->print('<br />'.
                   1734:                 &mt('<b>[_1]</b>:  Unable to enroll: [_2]',$username,$reply));
1.10      www      1735:          		} else {
1.7       www      1736:                             $count++; $flushc++;
                   1737:                             $student{$username}=1;
1.6       www      1738:                             $r->print('. ');
1.7       www      1739:                             if ($flushc>15) {
                   1740: 				$r->rflush;
                   1741:                                 $flushc=0;
                   1742:                             }
1.6       www      1743:                         }
1.25      matthew  1744:                     } else {
1.88      matthew  1745:                         $r->print('<br />'.
                   1746:       &mt('<b>[_1]</b>: Unable to enroll.  No password specified.',$username)
                   1747:                                   );
1.25      matthew  1748:                     }
                   1749:                 }
1.26      matthew  1750:             }
                   1751:         } # end of foreach (@studentdata)
1.88      matthew  1752:         $r->print("</p>\n<p>\n".&mt('Processed [_1] student(s).',$count).
                   1753:                   "</p>\n");
                   1754:         $r->print("<p>\n".
                   1755:                   &mt('If active, the new role will be available when the '.
                   1756:                   'students next log in to LON-CAPA.')."</p>\n");
1.26      matthew  1757:         #####################################
                   1758:         #           Drop students           #
                   1759:         #####################################
1.25      matthew  1760:         if ($ENV{'form.fullup'} eq 'yes') {
1.88      matthew  1761:             $r->print('<h3>'.&mt('Dropping Students')."</h3>\n");
1.26      matthew  1762:             #  Get current classlist
1.56      matthew  1763:             my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist();
                   1764:             if (! defined($classlist)) {
1.88      matthew  1765:                 $r->print(&mt('There are no students currently enrolled.').
                   1766:                           "\n");
1.56      matthew  1767:             } else {
                   1768:                 # Remove the students we just added from the list of students.
1.25      matthew  1769:                 foreach (@studentdata) {
                   1770:                     my %entries=&Apache::loncommon::record_sep($_);
                   1771:                     unless (($entries{$fields{'username'}} eq '') ||
                   1772:                             (!defined($entries{$fields{'username'}}))) {
1.56      matthew  1773:                         delete($classlist->{$entries{$fields{'username'}}.
1.26      matthew  1774:                                                 ':'.$domain});
1.25      matthew  1775:                     }
                   1776:                 }
1.56      matthew  1777:                 # Print out list of dropped students.
                   1778:                 &show_drop_list($r,$classlist,$keylist,'nosort');
1.25      matthew  1779:             }
                   1780:         }
1.26      matthew  1781:     } # end of unless
1.10      www      1782: }
                   1783: 
1.11      www      1784: # ================================================================== Phase four
                   1785: sub drop_student_list {
                   1786:     my $r=shift;
                   1787:     my $count=0;
1.35      matthew  1788:     my @droplist;
                   1789:     if (ref($ENV{'form.droplist'})) {
                   1790:         @droplist = @{$ENV{'form.droplist'}};
                   1791:     } else {
                   1792:         @droplist = ($ENV{'form.droplist'});
                   1793:     }
                   1794:     foreach (@droplist) {
1.26      matthew  1795:         my ($uname,$udom)=split(/\:/,$_);
1.56      matthew  1796:         # drop student
1.35      matthew  1797:         my $result = &modifystudent($udom,$uname,$ENV{'request.course.id'});
1.37      matthew  1798:         if ($result eq 'ok' || $result eq 'ok:') {
1.88      matthew  1799:             $r->print(&mt('Dropped [_1]',$uname.'@'.$udom).'<br>');
1.59      matthew  1800:             $count++;
1.35      matthew  1801:         } else {
1.88      matthew  1802:             $r->print(
                   1803:           &mt('Error dropping [_1]:[_2]',$uname.'@'.$udom,$result).
1.35      matthew  1804:                       '<br />');
                   1805:         }
1.20      harris41 1806:     }
1.88      matthew  1807:     $r->print('<p><b>'.&mt('Dropped [_1] student(s).',$count).'</b></p>');
                   1808:     $r->print('<p>'.&mt('Re-enrollment will re-activate data.')) if ($count);
1.11      www      1809: }
                   1810: 
1.50      matthew  1811: ###################################################################
                   1812: ###################################################################
                   1813: 
                   1814: =pod
                   1815: 
                   1816: =item &handler
                   1817: 
                   1818: The typical handler you see in all these modules.  Takes $r, the
                   1819: http request, as an argument.  
                   1820: 
                   1821: The response to the request is governed by two form variables
                   1822: 
                   1823:  form.action      form.state     response
                   1824:  ---------------------------------------------------
                   1825:  undefined        undefined      print main menu
                   1826:  upload           undefined      print courselist upload menu
                   1827:  upload           got_file       deal with uploaded file,
                   1828:                                  print the upload managing menu
                   1829:  upload           enrolling      enroll students based on upload
                   1830:  drop             undefined      print the classlist ready to drop
                   1831:  drop             done           drop the selected students
1.74      matthew  1832:  enrollstudent    undefined      print student username domain form
                   1833:  enrollstudent    gotusername    print single student enroll menu
1.50      matthew  1834:  enrollstudent    enrolling      enroll student
                   1835:  classlist        undefined      print html classlist
                   1836:  classlist        csv            print csv classlist
                   1837:  modifystudent    undefined      print classlist to select student to modify
                   1838:  modifystudent    selected       print modify student menu
                   1839:  modifystudent    done           make modifications to student record
                   1840: 
                   1841: =cut
                   1842: 
                   1843: ###################################################################
                   1844: ###################################################################
1.10      www      1845: sub handler {
1.26      matthew  1846:     my $r=shift;
                   1847:     if ($r->header_only) {
1.86      www      1848:         &Apache::loncommon::content_type($r,'text/html');
1.26      matthew  1849:         $r->send_http_header;
                   1850:         return OK;
                   1851:     }
1.48      matthew  1852:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.50      matthew  1853:                                             ['action','state']);
1.26      matthew  1854:     #  Needs to be in a course
1.50      matthew  1855:     if (! (($ENV{'request.course.fn'}) &&
                   1856:           (&Apache::lonnet::allowed('cst',$ENV{'request.course.id'})))) {
                   1857:         # Not in a course, or not allowed to modify parms
                   1858:         $ENV{'user.error.msg'}=
                   1859:             "/adm/dropadd:cst:0:0:Cannot drop or add students";
                   1860:         return HTTP_NOT_ACCEPTABLE; 
                   1861:     }
                   1862:     #
                   1863:     # Only output the header information if they did not request csv format
                   1864:     #
                   1865:     if (exists($ENV{'form.state'}) && ($ENV{'form.state'} eq 'csv')) {
                   1866:         $r->content_type('text/csv');
                   1867:     } else {
1.26      matthew  1868:         # Start page
1.86      www      1869:         &Apache::loncommon::content_type($r,'text/html');
1.26      matthew  1870:         $r->send_http_header;
1.50      matthew  1871:         $r->print(&header());
                   1872:     }
                   1873:     #
                   1874:     # Main switch on form.action and form.state, as appropriate
                   1875:     if (! exists($ENV{'form.action'})) {
                   1876:         &print_main_menu($r);
                   1877:     } elsif ($ENV{'form.action'} eq 'upload') {
                   1878:         if (! exists($ENV{'form.state'})) {
                   1879:             &print_first_courselist_upload_form($r);            
                   1880:         } elsif ($ENV{'form.state'} eq 'got_file') {
                   1881:             &print_upload_manager_form($r);
                   1882:         } elsif ($ENV{'form.state'} eq 'enrolling') {
1.26      matthew  1883:             if ($ENV{'form.datatoken'}) {
                   1884:                 &upfile_drop_add($r);
1.50      matthew  1885:             } else {
                   1886:                 # Hmmm, this is an error
1.26      matthew  1887:             }
1.50      matthew  1888:         } else {
                   1889:             &print_first_courselist_upload_form($r);            
1.26      matthew  1890:         }
1.50      matthew  1891:     } elsif ($ENV{'form.action'} eq 'drop') {
                   1892:         if (! exists($ENV{'form.state'})) {
1.51      matthew  1893:             &print_drop_menu($r);
1.50      matthew  1894:         } elsif ($ENV{'form.state'} eq 'done') {
1.26      matthew  1895:             &drop_student_list($r);
1.50      matthew  1896:         } else {
1.55      matthew  1897:             &print_drop_menu($r);
1.26      matthew  1898:         }
1.50      matthew  1899:     } elsif ($ENV{'form.action'} eq 'enrollstudent') {
                   1900:         if (! exists($ENV{'form.state'})) {
1.74      matthew  1901:             &get_student_username_domain_form($r);
                   1902:         } elsif ($ENV{'form.state'} eq 'gotusername') {
1.50      matthew  1903:             &print_enroll_single_student_form($r);
                   1904:         } elsif ($ENV{'form.state'} eq 'enrolling') {
1.26      matthew  1905:             &enroll_single_student($r);
1.50      matthew  1906:         } else {
1.74      matthew  1907:             &get_student_username_domain_form($r);
1.26      matthew  1908:         }
1.50      matthew  1909:     } elsif ($ENV{'form.action'} eq 'classlist') {
                   1910:         if (! exists($ENV{'form.state'})) {
                   1911:             &print_html_classlist($r);
                   1912:         } elsif ($ENV{'form.state'} eq 'csv') {
1.60      matthew  1913:             &print_formatted_classlist($r,'csv');
                   1914:         } elsif ($ENV{'form.state'} eq 'excel') {
                   1915:             &print_formatted_classlist($r,'excel');
1.50      matthew  1916:         } else {
                   1917:             &print_html_classlist($r);
                   1918:         }
                   1919:     } elsif ($ENV{'form.action'} eq 'modifystudent') {
                   1920:         if (! exists($ENV{'form.state'})) {
                   1921:             &print_html_classlist($r);
                   1922:         } elsif ($ENV{'form.state'} eq 'selected') {
                   1923:             &print_modify_student_form($r);
                   1924:         } elsif ($ENV{'form.state'} eq 'done') {
                   1925:             &modify_single_student($r);
                   1926:         } else {
                   1927:             &print_html_classlist($r);
                   1928:         }        
                   1929:     } else {
                   1930:         # We should not end up here, but I guess it is possible
                   1931:         &Apache::lonnet::logthis("Undetermined state in londropadd.pm.  ".
                   1932:                                  "form.action = ".$ENV{'form.action'}.
                   1933:                                  "Someone should fix this.");
                   1934:         &print_main_menu($r);
                   1935:     }
                   1936:     #
                   1937:     # Finish up
                   1938:     if (exists($ENV{'form.state'}) && ($ENV{'form.state'} eq 'csv')) {
                   1939:         $r->print("\n");
1.26      matthew  1940:     } else {
1.50      matthew  1941:         $r->print('</form></body></html>');
1.26      matthew  1942:     }
                   1943:     return OK;
1.1       www      1944: }
                   1945: 
1.50      matthew  1946: ###################################################################
                   1947: ###################################################################
                   1948: 
1.1       www      1949: 1;
                   1950: __END__
1.50      matthew  1951: 
1.1       www      1952: 

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