File:  [LON-CAPA] / loncom / interface / Attic / londropadd.pm
Revision 1.64: download - view: text, annotated - select for diffs
Thu Feb 13 21:35:50 2003 UTC (21 years, 3 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- Mark Lucas' code to add a domain.tab file it controls
   - domain description,
   - default authentication type
   - default argument for that auth type

- I think this will break the install hopefully I'll get this jury rigged up to work today

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

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