File:  [LON-CAPA] / loncom / interface / Attic / londropadd.pm
Revision 1.69: download - view: text, annotated - select for diffs
Mon Jun 23 14:38:53 2003 UTC (21 years ago) by matthew
Branches: MAIN
CVS tags: version_0_99_3, HEAD
Automatic refreshing of the course environment after setting the enrollment
dates as default for the course.

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

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