File:  [LON-CAPA] / loncom / interface / Attic / londropadd.pm
Revision 1.67: download - view: text, annotated - select for diffs
Fri Jun 20 18:34:52 2003 UTC (21 years, 1 month ago) by matthew
Branches: MAIN
CVS tags: HEAD
Part of Bug:884.  Enroll single student now uses the default dates from
the course environment.  Additionally it uses the more pleasant 'date_setter'
method of getting date info from the user.

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

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