File:  [LON-CAPA] / loncom / interface / Attic / londropadd.pm
Revision 1.70: download - view: text, annotated - select for diffs
Wed Jul 2 15:25:46 2003 UTC (21 years ago) by matthew
Branches: MAIN
CVS tags: HEAD
Fix bug where users were prevented from removing name fields from the students
environment.

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

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