File:  [LON-CAPA] / loncom / interface / Attic / londropadd.pm
Revision 1.45.4.1: download - view: text, annotated - select for diffs
Fri Sep 13 18:55:57 2002 UTC (21 years, 10 months ago) by matthew
Branches: fixes_0_5
Diff to branchpoint 1.45: preferred, unified
Backport of bugfix for bug 742.

    1: # The LearningOnline Network with CAPA
    2: # Handler to drop and add students in courses 
    3: #
    4: # $Id: londropadd.pm,v 1.45.4.1 2002/09/13 18:55:57 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: # YEAR=2000
   35: # 05/29/00,05/30,10/11 Gerd Kortemeyer)
   36: #
   37: # 10/11,10/12,10/16 Gerd Kortemeyer)
   38: #
   39: # 11/20,11/21,11/22,11/23,11/24,11/25,11/27,11/28,
   40: # 12/08,12/12 Gerd Kortemeyer)
   41: #
   42: # 12/26,12/27,12/28,
   43: # YEAR=2001
   44: # 01/01/01,01/15,02/10,02/13,02/14,02/22 Gerd Kortemeyer
   45: # 8/6 Scott Harrison
   46: # Guy Albertelli
   47: # 9/25 Gerd Kortemeyer
   48: # 12/19 Guy Albertelli
   49: # YEAR=2002
   50: # 1/4 Gerd Kortemeyer
   51: 
   52: package Apache::londropadd;
   53: 
   54: use strict;
   55: use Apache::lonnet();
   56: use Apache::loncommon();
   57: use Apache::Constants qw(:common :http REDIRECT);
   58: 
   59: # ================================================================ Print header
   60: 
   61: sub header {
   62:     return(<<ENDHEAD);
   63: <html>
   64: <head>
   65: <title>LON-CAPA Enrollment Manager</title>
   66: </head>
   67: <body bgcolor="#FFFFFF">
   68: <img align=right src=/adm/lonIcons/lonlogos.gif>
   69: <h1>$ENV{'course.'.$ENV{'request.course.id'}.'.description'}</h1>
   70: <h2>Enrollment Manager</h2>
   71: <form method="post" enctype="multipart/form-data"  
   72:       action="/adm/dropadd" name="studentform">
   73: ENDHEAD
   74: }
   75: 
   76: # =========== Drop student from all sections of a course, except optional $csec
   77: sub modifystudent {
   78:     my ($udom,$unam,$courseid,$csec,$desiredhost)=@_;
   79:     # if $csec is undefined, drop the student from all the courses matching
   80:     # this one.  If $csec is defined, drop them from all other sections of 
   81:     # this course and add them to section $csec
   82:     $courseid=~s/\_/\//g;
   83:     $courseid=~s/^(\w)/\/$1/;
   84:     my %roles = &Apache::lonnet::dump('roles',$udom,$unam);
   85:     my ($tmp) = keys(%roles);
   86:     # Bail out if we were unable to get the students roles
   87:     return "$1" if ($tmp =~ /^(con_lost|error|no_such_host)/i);
   88:     # Go through the roles looking for enrollment in this course
   89:     my $result = '';
   90:     foreach my $course (keys(%roles)) {
   91:         if ($course=~/^$courseid(?:\/)*(?:\s+)*(\w+)*\_st$/) {
   92:             # We are in this course
   93:             my $section=$1;
   94:             $section='' if ($course eq $courseid.'_st');
   95:             if ( ((!$section) && (!$csec)) || ($section ne $csec) ) {
   96:                 my (undef,$end,$start)=split(/\_/,$roles{$course});
   97:                 my $now=time;
   98:                 if (!($start && ($now<$start)) || !($end && ($now>$end))) {
   99:                     my $reply=&Apache::lonnet::modifystudent
  100:                         ($udom,$unam,'','','','','','','',
  101:                          $section,time,undef,undef,$desiredhost);
  102:                     $result .= $reply.':';
  103:                 }
  104:             }
  105:         }
  106:     }
  107:     if ($result eq '') {
  108:         $result eq 'Unable to find section for this student';
  109:     } else {
  110:         $result =~ s/(ok:)+/ok/g;
  111:     }
  112:     return $result;
  113: }
  114: 
  115: # ============ build a domain and server selection form
  116: sub domain_form {
  117:     my ($defdom) = @_;
  118:     # Set up domain and server selection forms
  119:     #
  120:     # Get the domains
  121:     my @domains = &Apache::loncommon::get_domains();
  122:     # build up the menu information to be passed to 
  123:     # &Apache::loncommon::linked_select_forms
  124:     my %select_menus;
  125:     foreach my $dom (@domains) {
  126:         # set up the text for this domain
  127:         $select_menus{$dom}->{'text'}= $dom;
  128:         # we want a choice of 'default' as the default in the second menu
  129:         $select_menus{$dom}->{'default'}= 'default';
  130:         $select_menus{$dom}->{'select2'}->{'default'} = 'default';
  131:         # Now build up the other items in the second menu
  132:         my %servers = &Apache::loncommon::get_library_servers($dom);
  133:         foreach my $server (keys(%servers)) {
  134:             $select_menus{$dom}->{'select2'}->{$server} 
  135:                                             = "$server $servers{$server}";
  136:         }
  137:     }
  138:     my $result  = &Apache::loncommon::linked_select_forms
  139:         ('studentform',' with home server ',$defdom,
  140:          'lcdomain','lcserver',\%select_menus);
  141:     return $result;
  142: }
  143: 
  144: # ============================================================== Menu Phase One
  145: sub menu_phase_one {
  146:     my $r=shift;
  147:     my $upfile_select=&Apache::loncommon::upfile_select_html();
  148:     my $create_classlist_help = 
  149: 	&Apache::loncommon::help_open_topic("Course_Create_Class_List",
  150:            "How do I create a class list from a spreadsheet");
  151:     my $create_csv_help =
  152: 	&Apache::loncommon::help_open_topic("Course_Convert_To_CSV",
  153:            "How do I create a CSV file from a spreadsheet");
  154:     $r->print(<<ENDUPFORM);
  155: <input type=hidden name=phase value=two>
  156: <hr>
  157: <h3>Upload a courselist</h3>
  158: $upfile_select
  159: <p><input type=submit name="fileupload" value="Upload Courselist">
  160: <br />
  161: $create_classlist_help <br />
  162: $create_csv_help
  163: 
  164: <hr />
  165: <h3>Enroll a single student</h3>
  166: <p><input type=submit name="enroll" value="Enroll Student"></p>
  167: <hr />
  168: <h3>Classlist</h3>
  169: <p><input type=submit name="view" value="View Class List">
  170: <input type=submit name="viewcsv" value="Comma Separated Class List"></p>
  171: <hr />
  172: <h3>Drop students</h3>
  173: <p><input type=submit name="drop" value="Selection List"></p>
  174: ENDUPFORM
  175: }
  176: 
  177: sub phase_two_header {
  178:     my ($r,$datatoken,$distotal,$krbdefdom)=@_;
  179:     my $javascript;
  180:     if ($ENV{'form.upfile_associate'} eq 'reverse') {
  181: 	$javascript=&phase_two_javascript_reverse_associate();
  182:     } else {
  183: 	$javascript=&phase_two_javascript_forward_associate();
  184:     }
  185:     my $javascript_validations=&javascript_validations($krbdefdom);
  186:     $r->print(<<ENDPICK);
  187: <h3>Uploading Class List</h3>
  188: <hr>
  189: <h3>Identify fields</h3>
  190: Total number of records found in file: $distotal <hr />
  191: Enter as many fields as you can. The system will inform you and bring you back
  192: to this page if the data selected is insufficient to run your class.<hr />
  193: <input type="button" value="Reverse Association" onClick="javascript:this.form.associate.value='Reverse Association';submit(this.form);" />
  194: <input type="hidden" name="associate"  value="" />
  195: <input type="hidden" name="phase"      value="three" />
  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: sub javascript_validations {
  210:     my ($krbdefdom)=@_;
  211:     my %param = ( formname => 'studentform',
  212:                   kerb_def_dom => $krbdefdom );
  213:     my $authheader = &Apache::loncommon::authform_header(%param);
  214:     return (<<ENDPICK);
  215: function verify_message (vf,founduname,foundpwd,foundname,foundid,foundsec) {
  216:     var foundatype=0;
  217:     var message='';
  218:     if (founduname==0) {
  219: 	alert('You need to specify the username field');
  220:         return;
  221:     }
  222:     if (current.radiovalue == null || current.radiovalue == 'nochange') {
  223:         // They did not check any of the login radiobuttons.
  224:         alert('You must choose an authentication type');
  225:         return;
  226:     }
  227:     foundatype=1;
  228:     if (current.argfield == null || current.argfield == '') {
  229:         var alertmsg = '';
  230:         switch (current.value) {
  231:             case 'krb': 
  232:                 alertmsg = 'You need to specify the Kerberos domain';
  233:                 break;
  234:             case 'loc':
  235:             case 'fsys':
  236:                 alertmsg = 'You need to specify the initial password';
  237:                 break;
  238:             case 'fsys':
  239:                 alertmsg = '';
  240:                 break;
  241:             default: 
  242:                 alertmsg = '';
  243:         }
  244:         if (alertmsg != '') {
  245:             alert(alertmsg);
  246:             return;
  247:         }
  248:     }
  249: 
  250:     if (foundname==0) { message='No name fields specified. '; }
  251:     if (foundid==0) { message+='No ID or student number field specified. '; }
  252:     if (foundsec==0) { message+='No section or group field specified. '; }
  253:     if (vf.startdate.value=='') {
  254: 	message+='No starting date set. ';
  255:     }
  256:     if (vf.enddate.value=='') {
  257:         message+='No ending date set. ';
  258:     }
  259:     if ((vf.enddate.value!='') && (vf.startdate.value!='')) {
  260:        if (Math.round(vf.enddate.value)<Math.round(vf.startdate.value)) {
  261:           alert('Ending date is before starting date');
  262:           return;
  263:        }
  264:     }
  265:     if (message!='') {
  266:        message+='Continue enrollment?';
  267:        if (confirm(message)) {
  268: 	  pclose();
  269: 	  vf.submit();
  270:        }
  271:     } else {
  272:       pclose();
  273:       vf.submit();
  274:     }
  275: }
  276: 
  277: 
  278:     function pclose() {
  279:         parmwin=window.open("/adm/rat/empty.html","LONCAPAparms",
  280:                  "height=350,width=350,scrollbars=no,menubar=no");
  281:         parmwin.close();
  282:     }
  283: 
  284:     function pjump(type,dis,value,marker,ret,call) {
  285:         parmwin=window.open("/adm/rat/parameter.html?type="+escape(type)
  286:                  +"&value="+escape(value)+"&marker="+escape(marker)
  287:                  +"&return="+escape(ret)
  288:                  +"&call="+escape(call)+"&name="+escape(dis),"LONCAPAparms",
  289:                  "height=350,width=350,scrollbars=no,menubar=no");
  290: 
  291:     }
  292: 
  293:     function dateset() {
  294:         if (document.studentform.pres_marker.value=='end') {
  295:            document.studentform.enddate.value=
  296: 	       document.studentform.pres_value.value;
  297:         }
  298:         if (document.studentform.pres_marker.value=='start') {
  299:            document.studentform.startdate.value=
  300: 	       document.studentform.pres_value.value;
  301:         }
  302:         pclose();
  303:     }
  304: 
  305: $authheader
  306: ENDPICK
  307: 
  308: }
  309: 
  310: sub phase_two_javascript_forward_associate {
  311:     return(<<ENDPICK);
  312: function verify(vf) {
  313:     var founduname=0;
  314:     var foundpwd=0;
  315:     var foundname=0;
  316:     var foundid=0;
  317:     var foundsec=0;
  318:     var tw;
  319:     for (i=0;i<=vf.nfields.value;i++) {
  320:         tw=eval('vf.f'+i+'.selectedIndex');
  321:         if (tw==1) { founduname=1; }
  322:         if ((tw>=2) && (tw<=6)) { foundname=1; }
  323:         if (tw==7) { foundid=1; }
  324:         if (tw==8) { foundsec=1; }
  325:         if (tw==9) { foundpwd=1; }
  326:     }
  327:     verify_message(vf,founduname,foundpwd,foundname,foundid,foundsec);
  328: }
  329: 
  330: //
  331: // vf = this.form
  332: // tf = column number
  333: //
  334: // values of nw
  335: //
  336: // 0 = none
  337: // 1 = username
  338: // 2 = names (lastname, firstnames)
  339: // 3 = fname (firstname)
  340: // 4 = mname (middlename)
  341: // 5 = lname (lastname)
  342: // 6 = gen   (generation)
  343: // 7 = id
  344: // 8 = section
  345: // 9 = ipwd  (password)
  346: //
  347: function flip(vf,tf) {
  348:    var nw=eval('vf.f'+tf+'.selectedIndex');
  349:    var i;
  350:    // make sure no other columns are labeled the same as this one
  351:    for (i=0;i<=vf.nfields.value;i++) {
  352:       if ((i!=tf) && (eval('vf.f'+i+'.selectedIndex')==nw)) {
  353:           eval('vf.f'+i+'.selectedIndex=0;')
  354:       }
  355:    }
  356:    // If we set this to 'lastname, firstnames', clear out all the ones
  357:    // set to 'fname','mname','lname','gen' (3,4,5,6) currently.
  358:    if (nw==2) {
  359:       for (i=0;i<=vf.nfields.value;i++) {
  360:          if ((eval('vf.f'+i+'.selectedIndex')>=3) &&
  361:              (eval('vf.f'+i+'.selectedIndex')<=6)) {
  362:              eval('vf.f'+i+'.selectedIndex=0;')
  363:          }
  364:       }
  365:    }
  366:    // If we set this to one of 'fname','mname','lname','gen' (3,4,5,6),
  367:    // clear out any that are set to 'lastname, firstnames' (2)
  368:    if ((nw>=3) && (nw<=6)) {
  369:       for (i=0;i<=vf.nfields.value;i++) {
  370:          if (eval('vf.f'+i+'.selectedIndex')==2) {
  371:              eval('vf.f'+i+'.selectedIndex=0;')
  372:          }
  373:       }
  374:    }
  375:    // If we set the password, make the password form below correspond to 
  376:    // the new value.
  377:    if (nw==9) {
  378:        changed_radio('int',document.studentform);
  379:        set_auth_radio_buttons('int',document.studentform);
  380:        vf.intarg.value='';
  381:        vf.krbarg.value='';
  382:        vf.locarg.value='';
  383:    }
  384: }
  385: 
  386: function clearpwd(vf) {
  387:     var i;
  388:     for (i=0;i<=vf.nfields.value;i++) {
  389:         if (eval('vf.f'+i+'.selectedIndex')==9) {
  390:             eval('vf.f'+i+'.selectedIndex=0;')
  391:         }
  392:     }
  393: }
  394: 
  395: ENDPICK
  396: }
  397: 
  398: sub phase_two_javascript_reverse_associate {
  399:     return(<<ENDPICK);
  400: function verify(vf) {
  401:     var founduname=0;
  402:     var foundpwd=0;
  403:     var foundname=0;
  404:     var foundid=0;
  405:     var foundsec=0;
  406:     var tw;
  407:     for (i=0;i<=vf.nfields.value;i++) {
  408:         tw=eval('vf.f'+i+'.selectedIndex');
  409:         if (i==0 && tw!=0) { founduname=1; }
  410:         if (((i>=1) && (i<=5)) && tw!=0 ) { foundname=1; }
  411:         if (i==6 && tw!=0) { foundid=1; }
  412:         if (i==7 && tw!=0) { foundsec=1; }
  413:         if (i==8 && tw!=0) { foundpwd=1; }
  414:     }
  415:     verify_message(vf,founduname,foundpwd,foundname,foundid,foundsec);
  416: }
  417: 
  418: function flip(vf,tf) {
  419:    var nw=eval('vf.f'+tf+'.selectedIndex');
  420:    var i;
  421:    // picked the all one one name field, reset the other name ones to blank
  422:    if (tf==1 && nw!=0) {
  423:       for (i=2;i<=5;i++) {
  424:          eval('vf.f'+i+'.selectedIndex=0;')
  425:       }
  426:    }
  427:    //picked one of the piecewise name fields, reset the all in
  428:    //one field to blank
  429:    if ((tf>=2) && (tf<=5) && (nw!=0)) {
  430:       eval('vf.f1.selectedIndex=0;')
  431:    }
  432:    // intial password specified, pick internal authentication
  433:    if (tf==8 && nw!=0) {
  434:        changed_radio('int',document.studentform);
  435:        set_auth_radio_buttons('int',document.studentform);
  436:        vf.krbarg.value='';
  437:        vf.intarg.value='';
  438:        vf.locarg.value='';
  439:    }
  440: }
  441: 
  442: function clearpwd(vf) {
  443:     var i;
  444:     if (eval('vf.f8.selectedIndex')!=0) {
  445:         eval('vf.f8.selectedIndex=0;')
  446:     }
  447: }
  448: ENDPICK
  449: }
  450: 
  451: sub phase_two_end {
  452:     my ($r,$i,$keyfields,$defdom,$today,$halfyear)=@_;
  453:     my %param = ( formname => 'document.studentform');
  454:     my $krbform = &Apache::loncommon::authform_kerberos(%param);
  455:     my $intform = &Apache::loncommon::authform_internal(%param);
  456:     my $locform = &Apache::loncommon::authform_local(%param);
  457:     my $domform = &domain_form($defdom);
  458:     $r->print(<<ENDPICK);
  459: </table>
  460: <input type=hidden name=nfields value=$i>
  461: <input type=hidden name=keyfields value="$keyfields">
  462: <h3>Login Type</h3>
  463: <p>Note: this will not take effect if the user already exists</p>
  464: <p>
  465: $krbform
  466: </p>
  467: <p>
  468: $intform
  469: </p>
  470: <p>
  471: $locform
  472: </p>
  473: <h3>LON-CAPA Domain for Students</h3>
  474: LON-CAPA domain: $domform <p>
  475: <h3>Starting and Ending Dates</h3>
  476: <input type="hidden" value=''          name="pres_value"  >
  477: <input type="hidden" value=''          name="pres_type"   >
  478: <input type="hidden" value=''          name="pres_marker" >
  479: <input type="hidden" value='$today'    name="startdate"   >
  480: <input type="hidden" value='$halfyear' name="enddate"     >
  481: <a 
  482:  href="javascript:pjump('date_start','Enrollment Starting Date',document.studentform.startdate.value,'start','studentform.pres','dateset');"
  483: >Set Starting Date</a><p>
  484: 
  485: <a 
  486:  href="javascript:pjump('date_end','Enrollment Ending Date',document.studentform.enddate.value,'end','studentform.pres','dateset');"
  487: >Set Ending Date</a><p>
  488: <h3>Full Update</h3>
  489: <input type=checkbox name=fullup value=yes> Full update 
  490: (also print list of users not enrolled anymore)<p>
  491: <h3>ID/Student Number</h3>
  492: <input type=checkbox name=forceid value=yes> 
  493: Disable ID/Student Number Safeguard and Force Change of Conflicting IDs
  494: (only do if you know what you are doing)<p>
  495: <input type="button" onClick="javascript:verify(this.form)" value="Update Courselist" /><br />
  496: Note: for large courses, this operation might be time consuming.
  497: ENDPICK
  498: }
  499: 
  500: # ======================================================= Menu Phase Two Upload
  501: sub menu_phase_two_upload {
  502:     my $r=shift;
  503: 
  504:     my $datatoken;
  505:     if (!$ENV{'form.datatoken'}) {
  506:       $datatoken=&Apache::loncommon::upfile_store($r);
  507:     } else {
  508:       $datatoken=$ENV{'form.datatoken'};
  509:       &Apache::loncommon::load_tmp_file($r);
  510:     }
  511:     my @records=&Apache::loncommon::upfile_record_sep();
  512:     my $total=$#records;
  513:     my $distotal=$total+1;
  514:     $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
  515:     my $krbdefdom=$1;
  516:     $krbdefdom=~tr/a-z/A-Z/;
  517:     my $today=time;
  518:     my $halfyear=$today+15552000;
  519:     my $defdom=$r->dir_config('lonDefDomain');
  520:     &phase_two_header($r,$datatoken,$distotal,$krbdefdom);
  521:     my $i;
  522:     my $keyfields;
  523:     if ($total>=0) {
  524: 	my @d=(['username','Username'],['names','Last Name, First Names'],
  525: 	       ['fname','First Name'],['mname','Middle Names/Initials'],
  526: 	       ['lname','Last Name'],['gen','Generation'],
  527: 	       ['id','ID/Student Number'],['sec','Group/Section'],
  528: 	       ['ipwd','Initial Password']);
  529: 	if ($ENV{'form.upfile_associate'} eq 'reverse') {	
  530: 	    &Apache::loncommon::csv_print_samples($r,\@records);
  531: 	    $i=&Apache::loncommon::csv_print_select_table($r,\@records,\@d);
  532: 	    foreach (@d) { $keyfields.=$_->[0].','; }
  533: 	    chop($keyfields);
  534: 	} else {
  535: 	    unshift(@d,['none','']);
  536: 	    $i=&Apache::loncommon::csv_samples_select_table($r,\@records,\@d);
  537: 	    my %sone=&Apache::loncommon::record_sep($records[0]);
  538: 	    $keyfields=join(',',sort(keys(%sone)));
  539: 	}
  540:     }
  541:     &phase_two_end($r,$i,$keyfields,$defdom,$today,$halfyear);
  542: }
  543: 
  544: # ======================================================= Enroll single student
  545: sub enroll_single_student {
  546:     my $r=shift;
  547:     $r->print('<h3>Enrolling Student</h3>');
  548:     $r->print('<p>Enrolling '.$ENV{'form.cuname'}." in domain ".
  549:               $ENV{'form.lcdomain'}.'</p>');
  550:     if (($ENV{'form.cuname'})&&($ENV{'form.cuname'}!~/\W/)&&
  551:         ($ENV{'form.lcdomain'})&&($ENV{'form.lcdomain'}!~/\W/)) {
  552:         # Deal with home server selection
  553:         my $domain=$ENV{'form.lcdomain'};
  554:         my $desiredhost = $ENV{'form.lcserver'};
  555:         if (lc($desiredhost) eq 'default') {
  556:             $desiredhost = undef;
  557:         } else {
  558:             my %home_servers =&Apache::loncommon::get_library_servers($domain);
  559:             if (! exists($home_servers{$desiredhost})) {
  560:                 $r->print('<font color="#ff0000">Error:</font>'.
  561:                           'Invalid home server specified');
  562:                 return;
  563:             }
  564:         }
  565:         $r->print(" with server $desiredhost :") if (defined($desiredhost));
  566:         # End of home server selection logic
  567: 	my $amode='';
  568:         my $genpwd='';
  569:         if ($ENV{'form.login'} eq 'krb') {
  570:            $amode='krb4';
  571:            $genpwd=$ENV{'form.krbarg'};
  572:         } elsif ($ENV{'form.login'} eq 'int') {
  573:            $amode='internal';
  574:            $genpwd=$ENV{'form.intarg'};
  575:         }  elsif ($ENV{'form.login'} eq 'loc') {
  576: 	    $amode='localauth';
  577: 	    $genpwd=$ENV{'form.locarg'};
  578: 	    if (!$genpwd) { $genpwd=" "; }
  579: 	}
  580:         my $home = &Apache::lonnet::homeserver($ENV{'form.cuname'},
  581:                                                    $ENV{'form.lcdomain'});
  582:         if ((($amode) && ($genpwd)) || ($home ne 'no_host')) {
  583:             &modifystudent($ENV{'form.lcdomain'},$ENV{'form.cuname'},
  584:                            $ENV{'request.course.id'},$ENV{'form.csec'},
  585:                             $desiredhost);
  586:           $r->print(&Apache::lonnet::modifystudent(
  587:                       $ENV{'form.lcdomain'},$ENV{'form.cuname'},
  588:                       $ENV{'form.cstid'},$amode,$genpwd,
  589:  	              $ENV{'form.cfirst'},$ENV{'form.cmiddle'},
  590:                       $ENV{'form.clast'},$ENV{'form.cgen'},
  591:                       $ENV{'form.csec'},$ENV{'form.enddate'},
  592:                       $ENV{'form.startdate'},$ENV{'form.forceid'},
  593:                     $desiredhost));
  594: 	} else {
  595:             $r->print('<p><font color="#ff0000">ERROR</font>&nbsp;'.
  596:                       'Invalid login mode or password.  '.
  597:                       'Unable to enroll '.$ENV{'form.cuname'}.'.</p>');
  598:         }          
  599:     } else {
  600:         $r->print('Invalid username or domain');
  601:     }    
  602: }
  603: 
  604: # ======================================================= Menu Phase Two Enroll
  605: sub menu_phase_two_enroll {
  606:     my $r=shift;
  607:     $r->print("<h3>Enroll One Student</h3>");
  608:     my ($krbdefdom) = $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
  609:     $krbdefdom=~tr/a-z/A-Z/;
  610:     my $today    = time;
  611:     my $halfyear = $today+15552000;
  612:     my $defdom=$r->dir_config('lonDefDomain');
  613:     my $javascript_validations=&javascript_validations($krbdefdom);
  614:     # Set up authentication forms
  615:     my %param = ( formname => 'document.studentform');
  616:     my $krbform = &Apache::loncommon::authform_kerberos(%param);
  617:     my $intform = &Apache::loncommon::authform_internal(%param);
  618:     my $locform = &Apache::loncommon::authform_local(%param);
  619:     # Set up domain selection form
  620:     my $domform = &domain_form($defdom);
  621:     # Print it all out
  622:     $r->print(<<ENDSENROLL);
  623: <script type="text/javascript" language="Javascript">
  624: function verify(vf) {
  625:     var founduname=0;
  626:     var foundpwd=0;
  627:     var foundname=0;
  628:     var foundid=0;
  629:     var foundsec=0;
  630:     var tw;
  631:     if ((typeof(vf.cuname.value) !="undefined") && (vf.cuname.value!='') && 
  632: 	(typeof(vf.lcdomain.value)!="undefined") && (vf.lcdomain.value!='')) {
  633:         founduname=1;
  634:     }
  635:     if ((typeof(vf.cfirst.value)!="undefined") && (vf.cfirst.value!='') &&
  636: 	(typeof(vf.clast.value) !="undefined") && (vf.clast.value!='')) {
  637:         foundname=1;
  638:     }
  639:     if ((typeof(vf.csec.value)!="undefined") && (vf.csec.value!='')) {
  640:         foundsec=1;
  641:     }
  642:     if ((typeof(vf.cstid.value)!="undefined") && (vf.cstid.value!='')) {
  643: 	foundid=1;
  644:     }
  645:     if (founduname==0) {
  646: 	alert('You need to specify at least the username and domain fields');
  647:         return;
  648:     }
  649:     verify_message(vf,founduname,foundpwd,foundname,foundid,foundsec);
  650: }
  651: 
  652: $javascript_validations
  653: 
  654: function clearpwd(vf) {
  655:     //nothing else needs clearing
  656: }
  657: 
  658: </script>
  659: <h3>Personal Data</h3>
  660: First Name:  <input type="text" name="cfirst"  size="15"><br>
  661: Middle Name: <input type="text" name="cmiddle" size="15"><br>
  662: Last Name:   <input type="text" name="clast"   size="15"><br>
  663: Generation:  <input type="text" name="cgen"    size="5"> 
  664: 
  665: <p>ID/Student Number: <input type="text" name="cstid" size="10"></p>
  666: 
  667: <p>Group/Section: <input type=text name=csec size=5></p>
  668: 
  669: <h3>Login Data</h3>
  670: <p>Username: <input type="text" name="cuname"  size="15"></p>
  671: <p>Domain:   $domform</p>
  672: <p>Note: login settings below  will not take effect if the user already exists
  673: </p><p>
  674: $krbform
  675: </p><p>
  676: $intform
  677: </p><p>
  678: $locform
  679: </p><p>
  680: <h3>Starting and Ending Dates</h3>
  681: <input type="hidden" value='' name="pres_value">
  682: <input type="hidden" value='' name="pres_type">
  683: <input type="hidden" value='' name="pres_marker">
  684: <input type="hidden" value='$today' name=startdate>
  685: <input type="hidden" value='$halfyear' name=enddate>
  686: </p><p>
  687: <a 
  688:  href="javascript:pjump('date_start','Enrollment Starting Date',document.studentform.startdate.value,'start','studentform.pres','dateset');"
  689: >Set Starting Date</a>
  690: </p><p>
  691: <a 
  692:  href="javascript:pjump('date_end','Enrollment Ending Date',document.studentform.enddate.value,'end','studentform.pres','dateset');"
  693: >Set Ending Date</a>
  694: </p><p>
  695: <h3>ID/Student Number</h3>
  696: <input type="checkbox" name="forceid" value="yes"> 
  697: Disable ID/Student Number Safeguard and Force Change of Conflicting IDs
  698: (only do if you know what you are doing)<p>
  699: <input type="button" onClick="verify(this.form)" value="Enroll as student"><br>
  700: <input type="hidden" name="phase" value="five">
  701: </p>
  702: ENDSENROLL
  703: }
  704: 
  705: # =================================================== get the current classlist
  706: sub get_current_classlist {
  707:     my ($domain,$identifier) = @_;
  708:     # domain is the domain the class is being run in
  709:     # identifier is the internal, unique identifier for the class.
  710:     my %currentlist=();
  711:     my $now=time;
  712:     my %results=&Apache::lonnet::dump('classlist',$domain,$identifier);
  713:     my ($tmp) = keys(%results);
  714:     if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
  715:         foreach my $student (keys(%results)) {
  716:             # Extract the start and end dates
  717:             my ($end,$start)=split(/\:/,$results{$student});
  718:             # If the class isn't over, put it in the list
  719:             unless (($end) && ($now>$end)) { 
  720:                 $currentlist{$student}=1;
  721:             }
  722:         }
  723:         return (undef,%currentlist);
  724:     } else {
  725:         $tmp =~ s/^error://;
  726:         return ($tmp,undef);
  727:     }
  728: }
  729: 
  730: # ========================================================= Menu Phase Two Drop
  731: sub menu_phase_two_drop {
  732:     my $r=shift;
  733:     $r->print("<h3>Drop Students</h3>");
  734:     my $cid=$ENV{'request.course.id'};
  735:     my ($error,%currentlist)=&get_current_classlist
  736:         ($ENV{'course.'.$cid.'.domain'},$ENV{'course.'.$cid.'.num'});
  737:     if (defined($error)) {
  738:         if ($error =~ /^No such file or directory/) {
  739:             $r->print("There are no students currently enrolled.\n");
  740:         } else {
  741:             $r->print("<pre>ERROR:$error</pre>");
  742:         }
  743:     } elsif (!defined(%currentlist)) { 
  744:         $r->print("There are no students currently enrolled.\n");
  745:     } else {
  746:         # Print out the available choices
  747:         &show_drop_list($r,%currentlist);
  748:     }
  749: }
  750: 
  751: # ============================================== view classlist
  752: sub menu_phase_two_view {
  753:     my $r=shift;
  754:     $r->print("<h3>Current Classlist</h3>");
  755:     my $cid=$ENV{'request.course.id'};
  756:     my ($error,%currentlist)=&get_current_classlist
  757:         ($ENV{'course.'.$cid.'.domain'},$ENV{'course.'.$cid.'.num'});
  758:     if (defined($error)) {
  759:         if ($error =~ /^No such file or directory/) {
  760:             $r->print("There are no students currently enrolled.\n");
  761:         } else {
  762:             $r->print("<pre>ERROR:$error</pre>");
  763:         }
  764:     } elsif (!defined(%currentlist)) { 
  765:         $r->print("There are no students currently enrolled.\n");
  766:     } else {
  767:         # Print out the available choices
  768:         &show_class_list($r,'view',%currentlist);
  769:     }
  770: }
  771: 
  772: # ============================================== view classlist
  773: sub menu_phase_two_viewcsv {
  774:     my $r=shift;
  775:     my $cid=$ENV{'request.course.id'};
  776:     my ($error,%currentlist)=&get_current_classlist
  777:         ($ENV{'course.'.$cid.'.domain'},$ENV{'course.'.$cid.'.num'});
  778:     if (defined($error)) {
  779:         if ($error =~ /^No such file or directory/) {
  780:             $r->print("There are no students currently enrolled.\n");
  781:         } else {
  782:             $r->print("<pre>ERROR:$error</pre>");
  783:         }
  784:     } elsif (!defined(%currentlist)) { 
  785:         $r->print("There are no students currently enrolled.\n");
  786:     } else {
  787:         &show_class_list($r,'csv',%currentlist);
  788:     }
  789: }
  790: 
  791: # =================================================== Show student list to drop
  792: sub show_class_list {
  793:     my ($r,$mode,%currentlist)=@_;
  794:     my $cid=$ENV{'request.course.id'};
  795:     # Print out header 
  796:     if ($mode eq 'view') {
  797:         $r->print(<<END);
  798: <p>
  799: <table border=2>
  800: <tr><th>username</th><th>domain</th><th>ID</th>
  801:     <th>student name</th><th>generation</th><th>section</th></tr>
  802: END
  803:     } elsif ($mode eq 'csv') {
  804:         $r->print(<<END);
  805: username,domain,ID,last name,first name,middle name,generation,section
  806: END
  807:     }
  808:     foreach (sort keys %currentlist) {
  809:         my ($sname,$sdom)=split(/\:/,$_);
  810:         my %reply=&Apache::lonnet::idrget($sdom,$sname);
  811:         my $ssec=&Apache::lonnet::usection($sdom,$sname,$cid);
  812:         my %info=&Apache::lonnet::get('environment',
  813:                                       ['firstname','middlename',
  814:                                        'lastname','generation'],
  815:                                       $sdom, $sname);
  816:         my ($tmp) = keys(%info);
  817:         if ($tmp =~ /^(con_lost|error|no_such_host)/i) {
  818:             $r->print( ($mode eq 'view' ? 
  819:                        '<tr><td colspan="6"><font color="red">' :'').
  820:                        'Internal error: unable to get environment '.
  821:                        'for '.$sname.' in domain '.$sdom.
  822:                        ( $mode eq 'view' ?'</font></td></tr>' :''));
  823:         } else {
  824:             if ($mode eq 'view') {
  825:                 $r->print(<<"END");
  826: <tr>
  827:     <td>$sname</td>
  828:     <td>$sdom</td>
  829:     <td>$reply{$sname}</td>
  830:     <td>$info{'lastname'}, $info{'firstname'} $info{'middlename'}</td>
  831:     <td>$info{'generation'}</td>
  832:     <td>$ssec</td>
  833: </tr>
  834: END
  835:             } elsif ($mode eq 'csv') {
  836:                 my @line = ();
  837:                 foreach ($sname,$sdom,$reply{$sname},
  838:                          $info{'lastname'},$info{'firstname'},
  839:                          $info{'middlename'},$info{'generation'},$ssec) {
  840:                     push @line,&Apache::loncommon::csv_translate($_);
  841:                 }
  842:                 my $tmp = $";
  843:                 $" = '","';
  844:                 $r->print("\"@line\"\n");
  845:                 $" = $tmp;
  846:             }
  847:         }
  848:     }
  849:     $r->print('</table><br>') if ($mode eq 'view');
  850: }
  851: 
  852: # =================================================== Show student list to drop
  853: sub show_drop_list {
  854:     my ($r,%currentlist)=@_;
  855:     my $cid=$ENV{'request.course.id'};
  856:     $r->print(<<'END');
  857: <script>
  858: function checkAll(field)
  859: {
  860:     for (i = 0; i < field.length; i++)
  861:         field[i].checked = true ;
  862: }
  863: 
  864: function uncheckAll(field)
  865: {
  866:     for (i = 0; i < field.length; i++)
  867:         field[i].checked = false ;
  868: }
  869: </script>
  870: <p>
  871: <input type="hidden" name="phase" value="four">
  872: <table border=2>
  873: <tr><th>&nbsp;</th><th>username</th><th>domain</th>
  874: <th>ID</th><th>student name</th><th>generation</th>
  875: <th>section</th></tr>
  876: END
  877:     foreach (sort keys %currentlist) {
  878:         my ($sname,$sdom)=split(/\:/,$_);
  879:         my %reply=&Apache::lonnet::idrget($sdom,$sname);
  880:         my $ssec=&Apache::lonnet::usection($sdom,$sname,$cid);
  881:         my %info=&Apache::lonnet::get('environment',
  882:                                       ['firstname','middlename',
  883:                                        'lastname','generation'],
  884:                                       $sdom, $sname);
  885:         my ($tmp) = keys(%info);
  886:         if ($tmp =~ /^(con_lost|error|no_such_host)/i) {
  887:             $r->print('<tr><td colspan="7"><font color="red">'.
  888:                       'Internal error: unable to get environment '.
  889:                       'for '.$sname.' in domain '.$sdom.'</font></td></tr>');
  890:         } else {
  891:             $r->print(<<"END");
  892: <tr>
  893:     <td><input type="checkbox" name="droplist" value="$_"></td>
  894:     <td>$sname</td>
  895:     <td>$sdom</td>
  896:     <td>$reply{$sname}</td>
  897:     <td>$info{'lastname'}, $info{'firstname'} $info{'middlename'}</td>
  898:     <td>$info{'generation'}</td>
  899:     <td>$ssec</td>
  900: </tr>
  901: END
  902:         }
  903:     }
  904:     $r->print('</table><br>');
  905:     $r->print(<<"END");
  906: </p><p>
  907: <input type="button" value="check all" onclick="javascript:checkAll(document.studentform.droplist)"> &nbsp;
  908: <input type="button" value="uncheck all" onclick="javascript:uncheckAll(document.studentform.droplist)"> 
  909: <p><input type=submit value="Drop Students"></p>
  910: END
  911: }
  912: 
  913: # ================================================= Drop/Add from uploaded file
  914: sub upfile_drop_add {
  915:     my $r=shift;
  916:     &Apache::loncommon::load_tmp_file($r);
  917:     my @studentdata=&Apache::loncommon::upfile_record_sep();
  918:     my @keyfields = split(/\,/,$ENV{'form.keyfields'});
  919:     my $cid = $ENV{'request.course.id'};
  920:     my %fields=();
  921:     for (my $i=0; $i<=$ENV{'form.nfields'}; $i++) {
  922:         if ($ENV{'form.upfile_associate'} eq 'reverse') {
  923:             if ($ENV{'form.f'.$i} ne 'none') {
  924:                 $fields{$keyfields[$i]}=$ENV{'form.f'.$i};
  925:             }
  926:         } else {
  927:             $fields{$ENV{'form.f'.$i}}=$keyfields[$i];
  928:         }
  929:     }
  930:     #
  931:     my $startdate = $ENV{'form.startdate'};
  932:     my $enddate   = $ENV{'form.enddate'};
  933:     if ($startdate=~/\D/) { $startdate=''; }
  934:     if ($enddate=~/\D/)   { $enddate=''; }
  935:     # Determine domain and desired host (home server)
  936:     my $domain=$ENV{'form.lcdomain'};
  937:     my $desiredhost = $ENV{'form.lcserver'};
  938:     if (lc($desiredhost) eq 'default') {
  939:         $desiredhost = undef;
  940:     } else {
  941:         my %home_servers = &Apache::loncommon::get_library_servers($domain);
  942:         if (! exists($home_servers{$desiredhost})) {
  943:             $r->print('<font color="#ff0000">Error:</font>'.
  944:                       'Invalid home server specified');
  945:             return;
  946:         }
  947:     }
  948:     # Determine authentication mechanism
  949:     my $amode  = '';
  950:     my $genpwd = '';
  951:     if ($ENV{'form.login'} eq 'krb') {
  952:         $amode='krb4';
  953:         $genpwd=$ENV{'form.krbarg'};
  954:     } elsif ($ENV{'form.login'} eq 'int') {
  955:         $amode='internal';
  956:         if ((defined($ENV{'form.intarg'})) && ($ENV{'form.intarg'})) {
  957:             $genpwd=$ENV{'form.intarg'};
  958:         }
  959:     } elsif ($ENV{'form.login'} eq 'loc') {
  960:         $amode='localauth';
  961:         if ((defined($ENV{'form.locarg'})) && ($ENV{'form.locarg'})) {
  962:             $genpwd=$ENV{'form.locarg'};
  963:         }
  964:     }
  965:     unless (($domain=~/\W/) || ($amode eq '')) {
  966:         #######################################
  967:         ##         Enroll Students           ##
  968:         #######################################
  969:         $r->print('<h3>Enrolling Students</h3>');
  970:         my $count=0;
  971:         my $flushc=0;
  972:         my %student=();
  973:         # Get new classlist
  974:         foreach (@studentdata) {
  975:             my %entries=&Apache::loncommon::record_sep($_);
  976:             # Determine student name
  977:             unless (($entries{$fields{'username'}} eq '') ||
  978:                     (!defined($entries{$fields{'username'}}))) {
  979:                 my ($fname, $mname, $lname,$gen) = ('','','','');
  980:                 if (defined($fields{'names'})) {
  981:                     ($lname,$fname,$mname)=($entries{$fields{'names'}}=~
  982:                                             /([^\,]+)\,\s*(\w+)\s*(.*)$/);
  983:                 } else {
  984:                     if (defined($fields{'fname'})) {
  985:                         $fname=$entries{$fields{'fname'}};
  986:                     }
  987:                     if (defined($fields{'mname'})) {
  988:                         $mname=$entries{$fields{'mname'}};
  989:                     }
  990:                     if (defined($fields{'lname'})) {
  991:                         $lname=$entries{$fields{'lname'}};
  992:                     }
  993:                     if (defined($fields{'gen'})) {
  994:                         $gen=$entries{$fields{'gen'}};
  995:                     }
  996:                 }
  997:                 if ($entries{$fields{'username'}}=~/\W/) {
  998:                     $r->print('<p><b>Unacceptable username: '.
  999:                               $entries{$fields{'username'}}.' for user '.
 1000:                               $fname.' '.$mname.' '.$lname.' '.$gen.'</b><p>');
 1001:                 } else {
 1002:                     # determine section number
 1003:                     my $sec='';
 1004:                     my $username=$entries{$fields{'username'}};
 1005:                     if (defined($fields{'sec'})) {
 1006:                         if (defined($entries{$fields{'sec'}})) {
 1007:                             $sec=$entries{$fields{'sec'}};
 1008:                         }
 1009:                     }
 1010:                     # determine student id number
 1011:                     my $id='';
 1012:                     if (defined($fields{'id'})) {
 1013:                         if (defined($entries{$fields{'id'}})) {
 1014:                             $id=$entries{$fields{'id'}};
 1015:                         }
 1016:                         $id=~tr/A-Z/a-z/;
 1017:                     }
 1018:                     # determine student password
 1019:                     my $password='';
 1020:                     if ($genpwd) { 
 1021:                         $password=$genpwd; 
 1022:                     } else {
 1023:                         if (defined($fields{'ipwd'})) {
 1024:                             if ($entries{$fields{'ipwd'}}) {
 1025:                                 $password=$entries{$fields{'ipwd'}};
 1026:                             }
 1027:                         }
 1028:                     }
 1029:                     if ($password) {
 1030:                         &modifystudent($domain,$username,$cid,$sec,
 1031:                                        $desiredhost);
 1032:                         my $reply=&Apache::lonnet::modifystudent
 1033:                             ($domain,$username,$id,$amode,$password,
 1034:                              $fname,$mname,$lname,$gen,$sec,$enddate,
 1035:                              $startdate,$ENV{'form.forceid'},$desiredhost);
 1036:                         if ($reply ne 'ok') {
 1037:                             $r->print('<p><b>'.
 1038:                                       'Error enrolling '.$username.': '.
 1039:                                       $reply.'</b></p>');
 1040:          		} else {
 1041:                             $count++; $flushc++;
 1042:                             $student{$username}=1;
 1043:                             $r->print('. ');
 1044:                             if ($flushc>15) {
 1045: 				$r->rflush;
 1046:                                 $flushc=0;
 1047:                             }
 1048:                         }
 1049:                     } else {
 1050:                         $r->print("<p><b>No password for $username</b><p>");
 1051:                     }
 1052:                 }
 1053:             }
 1054:         } # end of foreach (@studentdata)
 1055:         $r->print('<p>Processed Students: '.$count);
 1056:         #####################################
 1057:         #           Drop students           #
 1058:         #####################################
 1059:         if ($ENV{'form.fullup'} eq 'yes') {
 1060:             $r->print('<h3>Dropping Students</h3>');
 1061:             #  Get current classlist
 1062:             my ($error,%currentlist)=&get_current_classlist
 1063:                 ($ENV{'course.'.$cid.'.domain'},
 1064:                  $ENV{'course.'.$cid.'.num'});
 1065:             if (defined($error)) {
 1066:                 $r->print('<pre>ERROR:$error</pre>');
 1067:             }
 1068:             if (defined(%currentlist)) {
 1069:                 # Drop the students
 1070:                 foreach (@studentdata) {
 1071:                     my %entries=&Apache::loncommon::record_sep($_);
 1072:                     unless (($entries{$fields{'username'}} eq '') ||
 1073:                             (!defined($entries{$fields{'username'}}))) {
 1074:                         delete($currentlist{$entries{$fields{'username'}}.
 1075:                                                 ':'.$domain});
 1076:                     }
 1077:                 }
 1078:                 # Print out list of dropped students
 1079:                 &show_drop_list($r,%currentlist);
 1080:             } else {
 1081:                 $r->print("There are no students currently enrolled.\n");
 1082:             }
 1083:         }
 1084:     } # end of unless
 1085: }
 1086: 
 1087: # ================================================================== Phase four
 1088: sub drop_student_list {
 1089:     my $r=shift;
 1090:     my $count=0;
 1091:     my @droplist;
 1092:     if (ref($ENV{'form.droplist'})) {
 1093:         @droplist = @{$ENV{'form.droplist'}};
 1094:     } else {
 1095:         @droplist = ($ENV{'form.droplist'});
 1096:     }
 1097:     foreach (@droplist) {
 1098:         my ($uname,$udom)=split(/\:/,$_);
 1099:         my $result = &modifystudent($udom,$uname,$ENV{'request.course.id'});
 1100:         if ($result eq 'ok' || $result eq 'ok:') {
 1101:             $r->print('Dropped '.$uname.' at '.$udom.'<br>');
 1102:         } else {
 1103:             $r->print('Error dropping '.$uname.' at '.$udom.': '.$result.
 1104:                       '<br />');
 1105:         }
 1106:         $count++;
 1107:     }
 1108:     $r->print('<p><b>Dropped '.$count.' student(s).</b>');
 1109:     $r->print('<p>Re-enrollment will re-activate data.');
 1110: }
 1111: 
 1112: # ================================================================ Main Handler
 1113: sub handler {
 1114:     my $r=shift;
 1115:     if ($r->header_only) {
 1116:         $r->content_type('text/html');
 1117:         $r->send_http_header;
 1118:         return OK;
 1119:     }
 1120:     #  Needs to be in a course
 1121:     if (($ENV{'request.course.fn'}) && 
 1122:         (&Apache::lonnet::allowed('cst',$ENV{'request.course.id'}))) {
 1123:         # Start page
 1124:         $r->content_type('text/html') if (! exists($ENV{'form.viewcsv'}));
 1125:         $r->send_http_header;
 1126:         $r->print(&header()) if (! exists($ENV{'form.viewcsv'}));
 1127:         # Phase one, initial screen
 1128:         unless ($ENV{'form.phase'}) {
 1129:             &menu_phase_one($r);
 1130:         }
 1131:         # Phase two
 1132:         if ($ENV{'form.associate'} eq 'Reverse Association') {
 1133:             $ENV{'form.phase'} = 'two';
 1134:             if ( $ENV{'form.upfile_associate'} ne 'reverse' ) {
 1135:                 $ENV{'form.upfile_associate'} = 'reverse';
 1136:             } else {
 1137:                 $ENV{'form.upfile_associate'} = 'forward';
 1138:             }
 1139:         }
 1140:         if ($ENV{'form.phase'} eq 'two') {
 1141:             if ($ENV{'form.fileupload'}) {
 1142:                 &menu_phase_two_upload($r);
 1143:             } elsif ($ENV{'form.enroll'}) {
 1144:                 &menu_phase_two_enroll($r);
 1145:             } elsif ($ENV{'form.drop'}) {
 1146:                 &menu_phase_two_drop($r);
 1147:             } elsif ($ENV{'form.view'}) {
 1148:                 &menu_phase_two_view($r);
 1149:             } elsif ($ENV{'form.viewcsv'}) {
 1150:                 &menu_phase_two_viewcsv($r);
 1151:             }
 1152:         }
 1153:         # Phase three
 1154:         if ($ENV{'form.phase'} eq 'three') {
 1155:             if ($ENV{'form.datatoken'}) {
 1156:                 &upfile_drop_add($r);
 1157:             }
 1158:         }
 1159:         # Phase four
 1160:         if ($ENV{'form.phase'} eq 'four') {
 1161:             &drop_student_list($r);
 1162:         }
 1163:         # Phase five
 1164:         if ($ENV{'form.phase'} eq 'five') {
 1165:             &enroll_single_student($r);
 1166:         }
 1167:          # End
 1168:         $r->print('</form></body></html>') if (! exists($ENV{'form.viewcsv'}));
 1169:     } else {
 1170:         # Not in a course, or not allowed to modify parms
 1171:         $ENV{'user.error.msg'}=
 1172:             "/adm/dropadd:cst:0:0:Cannot drop or add students";
 1173:         return HTTP_NOT_ACCEPTABLE; 
 1174:     }
 1175:     return OK;
 1176: }
 1177: 
 1178: 1;
 1179: __END__
 1180: 

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