Annotation of loncom/interface/londropadd.pm, revision 1.46

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

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