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

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

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