File:  [LON-CAPA] / loncom / interface / Attic / londropadd.pm
Revision 1.73: download - view: text, annotated - select for diffs
Sat Jul 5 10:07:11 2003 UTC (21 years ago) by www
Branches: MAIN
CVS tags: HEAD
Have very limited connectivity, need to do big commit while online.
Will call this JULYone in Bugzilla. Fixes several small bugs.

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

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