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

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

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