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

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

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