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

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

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