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

1.1       www         1: # The LearningOnline Network with CAPA
                      2: # Handler to drop and add students in courses 
                      3: #
1.120   ! albertel    4: # $Id: londropadd.pm,v 1.119 2004/10/16 00:46:58 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: #
1.50      matthew    29: ###############################################################
1.82      www        30: ##############################################################
1.1       www        31: 
                     32: package Apache::londropadd;
                     33: 
                     34: use strict;
1.24      albertel   35: use Apache::lonnet();
                     36: use Apache::loncommon();
1.50      matthew    37: use Apache::lonhtmlcommon();
1.1       www        38: use Apache::Constants qw(:common :http REDIRECT);
1.60      matthew    39: use Spreadsheet::WriteExcel;
1.110     matthew    40: use Apache::lonstathelpers();
1.86      www        41: use Apache::lonlocal;
1.1       www        42: 
1.50      matthew    43: ###############################################################
                     44: ###############################################################
1.10      www        45: sub header {
1.102     matthew    46:     my $bodytag=&Apache::loncommon::bodytag('Enrollment Manager');
1.88      matthew    47:     my $title = &mt('LON-CAPA Enrollment Manager');
1.27      matthew    48:     return(<<ENDHEAD);
1.1       www        49: <html>
                     50: <head>
1.88      matthew    51: <title>$title</title>
1.1       www        52: </head>
1.46      www        53: $bodytag
1.40      matthew    54: <form method="post" enctype="multipart/form-data"  
                     55:       action="/adm/dropadd" name="studentform">
1.1       www        56: ENDHEAD
1.10      www        57: }
                     58: 
1.50      matthew    59: ###############################################################
                     60: ###############################################################
                     61: # Drop student from all sections of a course, except optional $csec
1.26      matthew    62: sub modifystudent {
1.33      matthew    63:     my ($udom,$unam,$courseid,$csec,$desiredhost)=@_;
1.26      matthew    64:     # if $csec is undefined, drop the student from all the courses matching
                     65:     # this one.  If $csec is defined, drop them from all other sections of 
                     66:     # this course and add them to section $csec
1.25      matthew    67:     $courseid=~s/\_/\//g;
                     68:     $courseid=~s/^(\w)/\/$1/;
1.26      matthew    69:     my %roles = &Apache::lonnet::dump('roles',$udom,$unam);
                     70:     my ($tmp) = keys(%roles);
                     71:     # Bail out if we were unable to get the students roles
1.35      matthew    72:     return "$1" if ($tmp =~ /^(con_lost|error|no_such_host)/i);
1.26      matthew    73:     # Go through the roles looking for enrollment in this course
1.35      matthew    74:     my $result = '';
1.26      matthew    75:     foreach my $course (keys(%roles)) {
1.35      matthew    76:         if ($course=~/^$courseid(?:\/)*(?:\s+)*(\w+)*\_st$/) {
1.26      matthew    77:             # We are in this course
1.25      matthew    78:             my $section=$1;
1.26      matthew    79:             $section='' if ($course eq $courseid.'_st');
1.87      matthew    80:             if (defined($csec) && $section eq $csec) {
1.71      matthew    81:                 $result .= 'ok:';
                     82:             } elsif ( ((!$section) && (!$csec)) || ($section ne $csec) ) {
1.27      matthew    83:                 my (undef,$end,$start)=split(/\_/,$roles{$course});
1.25      matthew    84:                 my $now=time;
1.50      matthew    85:                 # if this is an active role 
1.27      matthew    86:                 if (!($start && ($now<$start)) || !($end && ($now>$end))) {
1.25      matthew    87:                     my $reply=&Apache::lonnet::modifystudent
1.70      matthew    88:                         # dom  name  id mode pass     f     m     l     g
                     89:                         ($udom,$unam,'',  '',  '',undef,undef,undef,undef,
1.33      matthew    90:                          $section,time,undef,undef,$desiredhost);
1.35      matthew    91:                     $result .= $reply.':';
1.25      matthew    92:                 }
1.10      www        93:             }
                     94:         }
1.20      harris41   95:     }
1.35      matthew    96:     if ($result eq '') {
1.62      matthew    97:         $result = 'Unable to find section for this student';
1.37      matthew    98:     } else {
                     99:         $result =~ s/(ok:)+/ok/g;
1.35      matthew   100:     }
                    101:     return $result;
1.10      www       102: }
                    103: 
1.50      matthew   104: ###############################################################
                    105: ###############################################################
                    106: # build a domain and server selection form
1.31      matthew   107: sub domain_form {
                    108:     my ($defdom) = @_;
                    109:     # Set up domain and server selection forms
                    110:     #
                    111:     # Get the domains
                    112:     my @domains = &Apache::loncommon::get_domains();
                    113:     # build up the menu information to be passed to 
                    114:     # &Apache::loncommon::linked_select_forms
                    115:     my %select_menus;
                    116:     foreach my $dom (@domains) {
                    117:         # set up the text for this domain
                    118:         $select_menus{$dom}->{'text'}= $dom;
                    119:         # we want a choice of 'default' as the default in the second menu
                    120:         $select_menus{$dom}->{'default'}= 'default';
                    121:         $select_menus{$dom}->{'select2'}->{'default'} = 'default';
                    122:         # Now build up the other items in the second menu
1.45      matthew   123:         my %servers = &Apache::loncommon::get_library_servers($dom);
1.31      matthew   124:         foreach my $server (keys(%servers)) {
                    125:             $select_menus{$dom}->{'select2'}->{$server} 
                    126:                                             = "$server $servers{$server}";
                    127:         }
                    128:     }
                    129:     my $result  = &Apache::loncommon::linked_select_forms
                    130:         ('studentform',' with home server ',$defdom,
                    131:          'lcdomain','lcserver',\%select_menus);
                    132:     return $result;
                    133: }
                    134: 
1.50      matthew   135: ###############################################################
                    136: ###############################################################
                    137: #  Menu Phase One
                    138: sub print_main_menu {
1.10      www       139:     my $r=shift;
1.88      matthew   140:     my %Text = &Apache::lonlocal::texthash
                    141:         ('upload'    => 'Upload a class list',
                    142:          'enrollone' => 'Enroll a single student',
                    143:          'modify'    => 'Modify student data',
                    144:          'view'      => 'View Class List',
1.91      raeburn   145:          'drop'      => 'Drop Students',
                    146:          'populate'  => 'Automated Enrollment Manager');
1.98      www       147:     my %help=();
                    148:     foreach ('Course_Drop_Student','Course_Add_Student',
                    149: 	     'Course_Modify_Student_Data','Course_View_Class_List',
                    150: 	     'Course_Create_Class_List') {
                    151: 	$help{$_}=&Apache::loncommon::help_open_topic($_);
                    152:     }
1.88      matthew   153: 
1.48      matthew   154:     $r->print(<<END);
                    155: <p>
1.50      matthew   156: <font size="+1">
1.98      www       157: <a href="/adm/dropadd?action=upload">$Text{'upload'}</a>
                    158: </font>$help{'Course_Create_Class_List'}
1.50      matthew   159: </p><p>
                    160: <font size="+1">
1.88      matthew   161:     <a href="/adm/dropadd?action=enrollstudent">$Text{'enrollone'}</a>
1.98      www       162:     </font>$help{'Course_Add_Student'}
1.48      matthew   163: </p><p>
1.50      matthew   164: <font size="+1">
1.88      matthew   165:     <a href="/adm/dropadd?action=modifystudent">$Text{'modify'}</a>
1.98      www       166:     </font>$help{'Course_Modify_Student_Data'}
1.48      matthew   167: </p><p>
1.50      matthew   168: <font size="+1">
1.88      matthew   169:     <a href="/adm/dropadd?action=classlist">$Text{'view'}</a>
1.98      www       170:     </font>$help{'Course_View_Class_List'}
1.48      matthew   171: </p><p>
1.50      matthew   172: <font size="+1">
1.88      matthew   173:     <a href="/adm/dropadd?action=drop">$Text{'drop'}</a>
1.98      www       174:     </font>$help{'Course_Drop_Student'}
1.91      raeburn   175: </p><p>
1.113     raeburn   176: END
                    177:     my ($cdom,$cnum) = split/_/,$ENV{'request.course.id'};
                    178:     if (&Apache::lonnet::auto_run($cnum,$cdom) ) {
                    179:         $r->print(<<END);
1.91      raeburn   180: <font size="+1">
                    181:     <a href="/adm/populate">$Text{'populate'}</a>
                    182: </font>
1.48      matthew   183: END
1.113     raeburn   184:     }
1.10      www       185: }
                    186: 
1.50      matthew   187: ###############################################################
                    188: ###############################################################
1.89      matthew   189: sub hidden_input {
                    190:     my ($name,$value) = @_;
                    191:     return '<input type="hidden" name="'.$name.'" value="'.$value.'" />'."\n";
                    192: }
                    193: 
1.50      matthew   194: sub print_upload_manager_header {
1.23      albertel  195:     my ($r,$datatoken,$distotal,$krbdefdom)=@_;
1.24      albertel  196:     my $javascript;
1.99      matthew   197:     #
1.50      matthew   198:     if (! exists($ENV{'form.upfile_associate'})) {
                    199:         $ENV{'form.upfile_associate'} = 'forward';
                    200:     }
                    201:     if ($ENV{'form.associate'} eq 'Reverse Association') {
                    202:         if ( $ENV{'form.upfile_associate'} ne 'reverse' ) {
                    203:             $ENV{'form.upfile_associate'} = 'reverse';
                    204:         } else {
                    205:             $ENV{'form.upfile_associate'} = 'forward';
                    206:         }
                    207:     }
1.24      albertel  208:     if ($ENV{'form.upfile_associate'} eq 'reverse') {
1.50      matthew   209: 	$javascript=&upload_manager_javascript_reverse_associate();
1.24      albertel  210:     } else {
1.50      matthew   211: 	$javascript=&upload_manager_javascript_forward_associate();
1.24      albertel  212:     }
1.99      matthew   213:     #
                    214:     # Deal with restored settings
                    215:     my $password_choice = '';
                    216:     if (exists($ENV{'form.ipwd_choice'}) &&
                    217:         $ENV{'form.ipwd_choice'} ne '') {
                    218:         # If a column was specified for password, assume it is for an
                    219:         # internal password.  This is a bug waiting to be filed (could be
                    220:         # local or krb auth instead of internal) but I do not have the 
                    221:         # time to mess around with this now.
                    222:         $password_choice = 'int';        
                    223:     }
                    224:     #
                    225:     my $javascript_validations=&javascript_validations('auth',$krbdefdom,
                    226:                                     $password_choice);
1.82      www       227:     my $checked=(($ENV{'form.noFirstLine'})?' checked="1"':'');
1.88      matthew   228:     $r->print('<h3>'.&mt('Uploading Class List')."</h3>\n".
                    229:               "<hr>\n".
                    230:               '<h3>'.&mt('Identify fields')."</h3>\n");
                    231:     $r->print("<p>\n".
                    232:               &mt('Total number of records found in file: [_1].',$distotal).
                    233:               "\n".
                    234:               "</p><hr>\n");
1.94      sakharuk  235:     $r->print(&mt('Enter as many fields as you can. The system will inform you and bring you back to this page if the data selected is insufficient to enroll students in your class.')."<hr>\n");
1.89      matthew   236:     $r->print(&hidden_input('action','upload').
                    237:               &hidden_input('state','got_file').
                    238:               &hidden_input('associate','').
                    239:               &hidden_input('datatoken',$datatoken).
                    240:               &hidden_input('fileupload',$ENV{'form.fileupload'}).
                    241:               &hidden_input('upfiletype',$ENV{'form.upfiletype'}).
                    242:               &hidden_input('upfile_associate',$ENV{'form.upfile_associate'}));
                    243:     $r->print('<input type="button" value="Reverse Association" '.
                    244:               'name="'.&mt('Reverse Association').'" '.
                    245:               'onClick="javascript:this.form.associate.value=\'Reverse Association\';submit(this.form);" />');
                    246:     $r->print('<input type="checkbox" name="noFirstLine" $checked />'.
                    247:               &mt('Ignore First Line'));
                    248:     $r->print("<hr />\n".
                    249:               '<script type="text/javascript" language="Javascript">'."\n".
                    250:               $javascript."\n".$javascript_validations.'</script>');
1.24      albertel  251: }
                    252: 
1.50      matthew   253: ###############################################################
                    254: ###############################################################
1.24      albertel  255: sub javascript_validations {
1.96      raeburn   256:     my ($mode,$krbdefdom,$curr_authtype,$curr_authfield)=@_;
1.89      matthew   257:     my $authheader;
                    258:     if ($mode eq 'auth') {
                    259:         my %param = ( formname => 'studentform',
1.99      matthew   260:                       kerb_def_dom => $krbdefdom,
                    261:                       curr_authtype => $curr_authtype);
1.89      matthew   262:         $authheader = &Apache::loncommon::authform_header(%param);
1.91      raeburn   263:     } elsif ($mode eq 'createcourse') {
                    264:         my %param = ( formname => 'ccrs',
1.99      matthew   265:                   kerb_def_dom => $krbdefdom,
                    266:                       curr_authtype => $curr_authtype );
1.91      raeburn   267:         $authheader = &Apache::loncommon::authform_header(%param);
1.96      raeburn   268:     } elsif ($mode eq 'modifycourse') {
                    269:         my %param = ( formname => 'cmod',
                    270:                   kerb_def_dom => $krbdefdom,
                    271:                   mode => 'modifycourse',
                    272:                   curr_authtype => $curr_authtype,
                    273:                   curr_autharg => $curr_authfield );
                    274:         $authheader = &Apache::loncommon::authform_header(%param);
1.89      matthew   275:     }
1.96      raeburn   276: 
1.91      raeburn   277:     
1.89      matthew   278:     my %alert = &Apache::lonlocal::texthash
                    279:         (username => 'You need to specify the username field.',
                    280:          authen   => 'You must choose an authentication type.',
                    281:          krb      => 'You need to specify the Kerberos domain.',
                    282:          ipass    => 'You need to specify the initial password.',
                    283:          name     => 'The optional name field was not specified.',
                    284:          snum     => 'The optional student number field was not specified.',
                    285:          section  => 'The optional section or group field was not specified.', 
                    286:          email    => 'The optional email address field was not specified.',
                    287:          continue => 'Continue enrollment?',
                    288:          );
                    289:     
                    290: #    my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
                    291:     my $function_name =(<<END);
1.73      www       292: function verify_message (vf,founduname,foundpwd,foundname,foundid,foundsec,foundemail) {
1.89      matthew   293: END
1.97      raeburn   294:     my $auth_checks;
1.96      raeburn   295:     if ($mode eq 'createcourse') {
                    296:         $auth_checks .= (<<END);
1.97      raeburn   297:     if (vf.autoadds[0].checked == true) {
1.96      raeburn   298:         if (current.radiovalue == null || current.radiovalue == 'nochange') {
                    299:             alert('$alert{'authen'}');
                    300:             return;
                    301:         }
                    302:     }
                    303: END
                    304:     } else {
1.91      raeburn   305:         $auth_checks .= (<<END);
1.97      raeburn   306:     var foundatype=0;
1.3       www       307:     if (founduname==0) {
1.89      matthew   308: 	alert('$alert{'username'}');
1.3       www       309:         return;
                    310:     }
1.61      matthew   311:     // alert('current.radiovalue = '+current.radiovalue);
1.119     albertel  312:     if (current.radiovalue == null || current.radiovalue == '' || current.radiovalue == 'nochange') {
1.28      matthew   313:         // They did not check any of the login radiobuttons.
1.89      matthew   314:         alert('$alert{'authen'}');
1.28      matthew   315:         return;
                    316:     }
1.96      raeburn   317: END
                    318:     }
1.97      raeburn   319:     if ($mode eq 'createcourse') {
                    320:         $auth_checks .= "
                    321:     if ( (vf.autoadds[0].checked == true) &&
                    322:          (vf.elements[current.argfield].value == null || vf.elements[current.argfield].value == '') ) {
                    323: ";
                    324:     } elsif ($mode eq 'modifycourse') {
                    325:         $auth_checks .= " 
                    326:     if (vf.elements[current.argfield].value == null || vf.elements[current.argfield].value == '') {
                    327: ";
                    328:     }
1.96      raeburn   329:     if ( ($mode eq 'createcourse') || ($mode eq 'modifycourse') ) {
1.97      raeburn   330:         $auth_checks .= (<<END);
                    331:         var alertmsg = '';
                    332:         switch (current.radiovalue) {
                    333:             case 'krb':
                    334:                 alertmsg = '$alert{'krb'}';
                    335:                 break;
                    336:             default:
                    337:                 alertmsg = '';
1.96      raeburn   338:         }
1.97      raeburn   339:         if (alertmsg != '') {
                    340:             alert(alertmsg);
                    341:             return;
1.96      raeburn   342:         }
                    343:     }
                    344: END
                    345:     } else {
                    346:         $auth_checks .= (<<END);
1.28      matthew   347:     foundatype=1;
1.29      matthew   348:     if (current.argfield == null || current.argfield == '') {
1.28      matthew   349:         var alertmsg = '';
1.29      matthew   350:         switch (current.value) {
1.28      matthew   351:             case 'krb': 
1.89      matthew   352:                 alertmsg = '$alert{'krb'}';
1.28      matthew   353:                 break;
                    354:             case 'loc':
                    355:             case 'fsys':
1.89      matthew   356:                 alertmsg = '$alert{'ipass'}';
1.28      matthew   357:                 break;
                    358:             case 'fsys':
                    359:                 alertmsg = '';
                    360:                 break;
                    361:             default: 
                    362:                 alertmsg = '';
1.3       www       363:         }
1.28      matthew   364:         if (alertmsg != '') {
                    365:             alert(alertmsg);
1.3       www       366:             return;
                    367:         }
                    368:     }
1.89      matthew   369: END
1.96      raeburn   370:     }
1.91      raeburn   371:     my $optional_checks = '';
1.96      raeburn   372:     if ( ($mode eq 'createcourse') || ($mode eq 'modifycourse') ) {
1.91      raeburn   373:         $optional_checks = (<<END);
                    374:     vf.submit();
                    375: }
                    376: END
                    377:     } else {
                    378:         $optional_checks = (<<END);
1.89      matthew   379:     var message='';
                    380:     if (foundname==0) { 
                    381:         message='$alert{'name'}';
1.24      albertel  382:     }
1.89      matthew   383:     if (foundid==0) { 
                    384:         if (message!='') { 
                    385:             message+='\\n'; 
                    386:         }
                    387:         message+='$alert{'snum'}';
                    388:     }
                    389:     if (foundsec==0) {
                    390:         if (message!='') {
                    391:             message+='\\n';
                    392:         } 
                    393:         message+='$alert{'section'}';
                    394:     }
                    395:     if (foundemail==0) {
                    396:         if (message!='') {
                    397:             message+='\\n';
                    398:         }
                    399:         message+='$alert{'email'}';
1.74      matthew   400:     }
                    401:     if (message!='') {
1.89      matthew   402:         message+= '\\n$alert{'continue'}';
                    403:         if (confirm(message)) {
                    404:             vf.state.value='enrolling';
                    405:             vf.submit();
                    406:         }
1.74      matthew   407:     } else {
1.89      matthew   408:         vf.state.value='enrolling';
                    409:         vf.submit();
1.74      matthew   410:     }
                    411: }
1.89      matthew   412: END
1.91      raeburn   413:     }
1.89      matthew   414:     my $result = $function_name;
1.96      raeburn   415:     if ( ($mode eq 'auth') || ($mode eq 'createcourse') || ($mode eq 'modifycourse')  ) {
1.89      matthew   416:         $result .= $auth_checks;
                    417:     }
                    418:     $result .= $optional_checks;
1.96      raeburn   419:     if ( ($mode eq 'auth') || ($mode eq 'createcourse') || ($mode eq 'modifycourse')  ) {
1.89      matthew   420:         $result .= $authheader;
                    421:     }
                    422:     return $result;
1.74      matthew   423: }
                    424: 
1.50      matthew   425: ###############################################################
                    426: ###############################################################
                    427: sub upload_manager_javascript_forward_associate {
1.24      albertel  428:     return(<<ENDPICK);
                    429: function verify(vf) {
                    430:     var founduname=0;
                    431:     var foundpwd=0;
                    432:     var foundname=0;
                    433:     var foundid=0;
                    434:     var foundsec=0;
1.73      www       435:     var foundemail=0;
1.24      albertel  436:     var tw;
                    437:     for (i=0;i<=vf.nfields.value;i++) {
                    438:         tw=eval('vf.f'+i+'.selectedIndex');
                    439:         if (tw==1) { founduname=1; }
                    440:         if ((tw>=2) && (tw<=6)) { foundname=1; }
                    441:         if (tw==7) { foundid=1; }
                    442:         if (tw==8) { foundsec=1; }
                    443:         if (tw==9) { foundpwd=1; }
1.73      www       444:         if (tw==10) { foundemail=1; }
1.24      albertel  445:     }
1.73      www       446:     verify_message(vf,founduname,foundpwd,foundname,foundid,foundsec,foundemail);
1.24      albertel  447: }
                    448: 
1.49      matthew   449: //
                    450: // vf = this.form
                    451: // tf = column number
                    452: //
                    453: // values of nw
                    454: //
                    455: // 0 = none
                    456: // 1 = username
                    457: // 2 = names (lastname, firstnames)
                    458: // 3 = fname (firstname)
                    459: // 4 = mname (middlename)
                    460: // 5 = lname (lastname)
                    461: // 6 = gen   (generation)
                    462: // 7 = id
                    463: // 8 = section
                    464: // 9 = ipwd  (password)
1.73      www       465: // 10 = email address
                    466: 
1.24      albertel  467: function flip(vf,tf) {
                    468:    var nw=eval('vf.f'+tf+'.selectedIndex');
                    469:    var i;
1.49      matthew   470:    // make sure no other columns are labeled the same as this one
1.24      albertel  471:    for (i=0;i<=vf.nfields.value;i++) {
                    472:       if ((i!=tf) && (eval('vf.f'+i+'.selectedIndex')==nw)) {
                    473:           eval('vf.f'+i+'.selectedIndex=0;')
                    474:       }
                    475:    }
1.49      matthew   476:    // If we set this to 'lastname, firstnames', clear out all the ones
                    477:    // set to 'fname','mname','lname','gen' (3,4,5,6) currently.
1.24      albertel  478:    if (nw==2) {
                    479:       for (i=0;i<=vf.nfields.value;i++) {
                    480:          if ((eval('vf.f'+i+'.selectedIndex')>=3) &&
                    481:              (eval('vf.f'+i+'.selectedIndex')<=6)) {
                    482:              eval('vf.f'+i+'.selectedIndex=0;')
                    483:          }
                    484:       }
                    485:    }
1.49      matthew   486:    // If we set this to one of 'fname','mname','lname','gen' (3,4,5,6),
                    487:    // clear out any that are set to 'lastname, firstnames' (2)
1.24      albertel  488:    if ((nw>=3) && (nw<=6)) {
                    489:       for (i=0;i<=vf.nfields.value;i++) {
                    490:          if (eval('vf.f'+i+'.selectedIndex')==2) {
                    491:              eval('vf.f'+i+'.selectedIndex=0;')
                    492:          }
                    493:       }
                    494:    }
1.49      matthew   495:    // If we set the password, make the password form below correspond to 
                    496:    // the new value.
1.24      albertel  497:    if (nw==9) {
1.28      matthew   498:        changed_radio('int',document.studentform);
                    499:        set_auth_radio_buttons('int',document.studentform);
                    500:        vf.intarg.value='';
                    501:        vf.krbarg.value='';
1.24      albertel  502:        vf.locarg.value='';
                    503:    }
                    504: }
                    505: 
                    506: function clearpwd(vf) {
                    507:     var i;
                    508:     for (i=0;i<=vf.nfields.value;i++) {
                    509:         if (eval('vf.f'+i+'.selectedIndex')==9) {
                    510:             eval('vf.f'+i+'.selectedIndex=0;')
                    511:         }
                    512:     }
                    513: }
                    514: 
                    515: ENDPICK
                    516: }
                    517: 
1.50      matthew   518: ###############################################################
                    519: ###############################################################
                    520: sub upload_manager_javascript_reverse_associate {
1.24      albertel  521:     return(<<ENDPICK);
                    522: function verify(vf) {
                    523:     var founduname=0;
                    524:     var foundpwd=0;
                    525:     var foundname=0;
                    526:     var foundid=0;
                    527:     var foundsec=0;
                    528:     var tw;
                    529:     for (i=0;i<=vf.nfields.value;i++) {
                    530:         tw=eval('vf.f'+i+'.selectedIndex');
                    531:         if (i==0 && tw!=0) { founduname=1; }
                    532:         if (((i>=1) && (i<=5)) && tw!=0 ) { foundname=1; }
                    533:         if (i==6 && tw!=0) { foundid=1; }
                    534:         if (i==7 && tw!=0) { foundsec=1; }
                    535:         if (i==8 && tw!=0) { foundpwd=1; }
                    536:     }
                    537:     verify_message(vf,founduname,foundpwd,foundname,foundid,foundsec);
                    538: }
                    539: 
                    540: function flip(vf,tf) {
                    541:    var nw=eval('vf.f'+tf+'.selectedIndex');
                    542:    var i;
                    543:    // picked the all one one name field, reset the other name ones to blank
                    544:    if (tf==1 && nw!=0) {
                    545:       for (i=2;i<=5;i++) {
                    546:          eval('vf.f'+i+'.selectedIndex=0;')
                    547:       }
                    548:    }
                    549:    //picked one of the piecewise name fields, reset the all in
                    550:    //one field to blank
                    551:    if ((tf>=2) && (tf<=5) && (nw!=0)) {
                    552:       eval('vf.f1.selectedIndex=0;')
                    553:    }
                    554:    // intial password specified, pick internal authentication
                    555:    if (tf==8 && nw!=0) {
1.28      matthew   556:        changed_radio('int',document.studentform);
                    557:        set_auth_radio_buttons('int',document.studentform);
                    558:        vf.krbarg.value='';
                    559:        vf.intarg.value='';
1.24      albertel  560:        vf.locarg.value='';
                    561:    }
                    562: }
                    563: 
                    564: function clearpwd(vf) {
                    565:     var i;
                    566:     if (eval('vf.f8.selectedIndex')!=0) {
                    567:         eval('vf.f8.selectedIndex=0;')
                    568:     }
                    569: }
1.2       www       570: ENDPICK
1.23      albertel  571: }
1.10      www       572: 
1.50      matthew   573: ###############################################################
                    574: ###############################################################
                    575: sub print_upload_manager_footer {
1.23      albertel  576:     my ($r,$i,$keyfields,$defdom,$today,$halfyear)=@_;
1.64      albertel  577: 
                    578:     my ($krbdef,$krbdefdom) =
                    579:         &Apache::loncommon::get_kerberos_defaults($defdom);
                    580:     my %param = ( formname => 'document.studentform',
                    581:                   kerb_def_dom => $krbdefdom,
                    582:                   kerb_def_auth => $krbdef
                    583:                   );
1.99      matthew   584:     if (exists($ENV{'form.ipwd_choice'}) &&
                    585:         defined($ENV{'form.ipwd_choice'}) &&
                    586:         $ENV{'form.ipwd_choice'} ne '') {
                    587:         $param{'curr_authtype'} = 'int';
                    588:     }
1.28      matthew   589:     my $krbform = &Apache::loncommon::authform_kerberos(%param);
                    590:     my $intform = &Apache::loncommon::authform_internal(%param);
                    591:     my $locform = &Apache::loncommon::authform_local(%param);
1.31      matthew   592:     my $domform = &domain_form($defdom);
1.68      matthew   593:     my $date_table = &date_setting_table();
1.90      matthew   594:     my $Str = "</table>\n";
                    595:     $Str .= &hidden_input('nfields',$i);
                    596:     $Str .= &hidden_input('keyfields',$keyfields);
                    597:     $Str .= '<h3>'.&mt('Login Type')."</h3>\n";
                    598:     $Str .= "<p>\n".
                    599:         &mt('Note: this will not take effect if the user already exists').
                    600:         "</p><p>\n";
                    601:     $Str .= $krbform."\n</p><p>\n".
                    602:         $intform."\n</p><p>\n".
                    603:         $locform."\n</p>\n";
                    604:     $Str .= '<h3>'.&mt('LON-CAPA Domain for Students')."</h3>\n";
                    605:     $Str .= "<p>\n".&mt('LON-CAPA domain: [_1]',$domform)."\n</p>\n";
                    606:     $Str .= "<h3>".&mt('Starting and Ending Dates')."</h3>\n";
                    607:     $Str .= "<p>\n".$date_table."</p>\n";
                    608:     $Str .= "<h3>".&mt('Full Update')."</h3>\n";
                    609:     $Str .= '<input type="checkbox" name="fullup" value="yes">'.
                    610:         ' '.&mt('Full update (also print list of users not enrolled anymore)').
                    611:         "</p>\n";
                    612:     $Str .= "<h3>".&mt('Student Number')."</h3>\n";
                    613:     $Str .= "<p>\n".'<input type="checkbox" name="forceid" value="yes">';
                    614:     $Str .= &mt('Disable ID/Student Number Safeguard and Force Change '.
                    615:                 'of Conflicting IDs (only do if you know what you are doing)').
                    616:                 "\n</p><p>\n";
                    617:     $Str .= '<input type="button" onClick="javascript:verify(this.form)" '.
1.95      albertel  618:         'value="Update Class List" />'."<br />\n";
1.90      matthew   619:     $Str .= &mt('Note: for large courses, this operation may be time '.
                    620:                 'consuming');
                    621:     $r->print($Str);
                    622:     return;
1.23      albertel  623: }
1.24      albertel  624: 
1.90      matthew   625: ###############################################################
                    626: ###############################################################
1.50      matthew   627: sub print_upload_manager_form {
1.23      albertel  628:     my $r=shift;
1.99      matthew   629: 
1.82      www       630:     my $firstLine;
1.24      albertel  631:     my $datatoken;
                    632:     if (!$ENV{'form.datatoken'}) {
1.90      matthew   633:         $datatoken=&Apache::loncommon::upfile_store($r);
1.24      albertel  634:     } else {
1.90      matthew   635:         $datatoken=$ENV{'form.datatoken'};
                    636:         &Apache::loncommon::load_tmp_file($r);
1.24      albertel  637:     }
                    638:     my @records=&Apache::loncommon::upfile_record_sep();
1.90      matthew   639:     if($ENV{'form.noFirstLine'}){
                    640:         $firstLine=shift(@records);
                    641:     }
1.23      albertel  642:     my $total=$#records;
                    643:     my $distotal=$total+1;
                    644:     my $today=time;
                    645:     my $halfyear=$today+15552000;
1.99      matthew   646:     #
                    647:     # Restore memorized settings
                    648:     &Apache::loncommon::restore_course_settings
                    649:         ('enrollment_upload',{ 'username_choice' => 'scalar', # column settings
                    650:                                'names_choice' => 'scalar',
                    651:                                'fname_choice' => 'scalar',
                    652:                                'mname_choice' => 'scalar',
                    653:                                'lname_choice' => 'scalar',
                    654:                                'gen_choice' => 'scalar',
                    655:                                'id_choice' => 'scalar',
                    656:                                'sec_choice' => 'scalar',
                    657:                                'ipwd_choice' => 'scalar',
                    658:                                'email_choice' => 'scalar',
                    659:                            });
                    660:     #
                    661:     # Determine kerberos parameters as appropriate
1.85      matthew   662:     my $defdom=$ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
1.64      albertel  663:     my ($krbdef,$krbdefdom) =
                    664:         &Apache::loncommon::get_kerberos_defaults($defdom);
1.99      matthew   665:     #
1.50      matthew   666:     &print_upload_manager_header($r,$datatoken,$distotal,$krbdefdom);
1.24      albertel  667:     my $i;
                    668:     my $keyfields;
1.23      albertel  669:     if ($total>=0) {
1.99      matthew   670:         my @field=
                    671:             (['username',&mt('Username'),     $ENV{'form.username_choice'}],
                    672:              ['names',&mt('Last Name, First Names'),$ENV{'form.names_choice'}],
                    673:              ['fname',&mt('First Name'),      $ENV{'form.fname_choice'}],
                    674:              ['mname',&mt('Middle Names/Initials'),$ENV{'form.mname_choice'}],
                    675:              ['lname',&mt('Last Name'),       $ENV{'form.lname_choice'}],
                    676:              ['gen',  &mt('Generation'),      $ENV{'form.gen_choice'}],
                    677:              ['id',   &mt('ID/Student Number'),$ENV{'form.id_choice'}],
                    678:              ['sec',  &mt('Group/Section'),   $ENV{'form.sec_choice'}],
                    679:              ['ipwd', &mt('Initial Password'),$ENV{'form.ipwd_choice'}],
                    680:              ['email',&mt('EMail Address'),   $ENV{'form.email_choice'}]);
1.24      albertel  681: 	if ($ENV{'form.upfile_associate'} eq 'reverse') {	
                    682: 	    &Apache::loncommon::csv_print_samples($r,\@records);
1.90      matthew   683: 	    $i=&Apache::loncommon::csv_print_select_table($r,\@records,
                    684:                                                           \@field);
                    685: 	    foreach (@field) { 
                    686:                 $keyfields.=$_->[0].','; 
                    687:             }
1.24      albertel  688: 	    chop($keyfields);
                    689: 	} else {
1.90      matthew   690: 	    unshift(@field,['none','']);
                    691: 	    $i=&Apache::loncommon::csv_samples_select_table($r,\@records,
                    692:                                                             \@field);
1.24      albertel  693: 	    my %sone=&Apache::loncommon::record_sep($records[0]);
                    694: 	    $keyfields=join(',',sort(keys(%sone)));
1.23      albertel  695: 	}
                    696:     }
1.50      matthew   697:     &print_upload_manager_footer($r,$i,$keyfields,$defdom,$today,$halfyear);
1.10      www       698: }
                    699: 
1.90      matthew   700: ###############################################################
                    701: ###############################################################
1.12      www       702: sub enroll_single_student {
                    703:     my $r=shift;
1.80      matthew   704:     # Remove non alphanumeric values from section
                    705:     $ENV{'form.csec'}=~s/\W//g;
1.68      matthew   706:     #
                    707:     # We do the dates first because the action of making them the defaul
1.107     www       708:     # in the course is entirely separate from the action of enrolling the
1.68      matthew   709:     # student.  Also, a failure in setting the dates as default is not fatal
                    710:     # to the process of enrolling / modifying a student.
                    711:     my ($startdate,$enddate) = &get_dates_from_form();
                    712:     if ($ENV{'form.makedatesdefault'}) {
                    713:         $r->print(&make_dates_default($startdate,$enddate));
                    714:     }
                    715: 
1.94      sakharuk  716:     $r->print('<h3>'.&mt('Enrolling Student').'</h3>');
                    717:     $r->print('<p>'.&mt('Enrolling').' '.$ENV{'form.cuname'}." \@ ".
1.34      matthew   718:               $ENV{'form.lcdomain'}.'</p>');
1.12      www       719:     if (($ENV{'form.cuname'})&&($ENV{'form.cuname'}!~/\W/)&&
1.31      matthew   720:         ($ENV{'form.lcdomain'})&&($ENV{'form.lcdomain'}!~/\W/)) {
                    721:         # Deal with home server selection
                    722:         my $domain=$ENV{'form.lcdomain'};
                    723:         my $desiredhost = $ENV{'form.lcserver'};
                    724:         if (lc($desiredhost) eq 'default') {
                    725:             $desiredhost = undef;
                    726:         } else {
1.45      matthew   727:             my %home_servers =&Apache::loncommon::get_library_servers($domain);
1.31      matthew   728:             if (! exists($home_servers{$desiredhost})) {
1.94      sakharuk  729:                 $r->print('<font color="#ff0000">'.&mt('Error').':</font>'.
                    730:                           &mt('Invalid home server specified'));
1.31      matthew   731:                 return;
                    732:             }
                    733:         }
1.94      sakharuk  734:         $r->print(" ".&mt('with server')." $desiredhost :") if (defined($desiredhost));
1.31      matthew   735:         # End of home server selection logic
1.12      www       736: 	my $amode='';
                    737:         my $genpwd='';
                    738:         if ($ENV{'form.login'} eq 'krb') {
1.47      albertel  739:            $amode='krb';
                    740: 	   $amode.=$ENV{'form.krbver'};
1.28      matthew   741:            $genpwd=$ENV{'form.krbarg'};
1.12      www       742:         } elsif ($ENV{'form.login'} eq 'int') {
1.26      matthew   743:            $amode='internal';
1.28      matthew   744:            $genpwd=$ENV{'form.intarg'};
1.15      albertel  745:         }  elsif ($ENV{'form.login'} eq 'loc') {
                    746: 	    $amode='localauth';
                    747: 	    $genpwd=$ENV{'form.locarg'};
                    748: 	    if (!$genpwd) { $genpwd=" "; }
                    749: 	}
1.34      matthew   750:         my $home = &Apache::lonnet::homeserver($ENV{'form.cuname'},
                    751:                                                    $ENV{'form.lcdomain'});
                    752:         if ((($amode) && ($genpwd)) || ($home ne 'no_host')) {
1.55      matthew   753:             # Clean out any old roles the student has in this class.
1.33      matthew   754:             &modifystudent($ENV{'form.lcdomain'},$ENV{'form.cuname'},
                    755:                            $ENV{'request.course.id'},$ENV{'form.csec'},
                    756:                             $desiredhost);
1.55      matthew   757:             my $login_result = &Apache::lonnet::modifystudent
                    758:                 ($ENV{'form.lcdomain'},$ENV{'form.cuname'},
                    759:                  $ENV{'form.cstid'},$amode,$genpwd,
                    760:                  $ENV{'form.cfirst'},$ENV{'form.cmiddle'},
                    761:                  $ENV{'form.clast'},$ENV{'form.cgen'},
1.67      matthew   762:                  $ENV{'form.csec'},$enddate,
                    763:                  $startdate,$ENV{'form.forceid'},
1.55      matthew   764:                  $desiredhost);
                    765:             if ($login_result =~ /^ok/) {
                    766:                 $r->print($login_result);
1.94      sakharuk  767:                 $r->print("<p> ".&mt('If active, the new role will be available when the student next logs in to LON-CAPA.')."</p>");
1.55      matthew   768:             } else {
1.94      sakharuk  769:                 $r->print(&mt('unable to enroll').": ".$login_result);
1.55      matthew   770:             }
1.12      www       771: 	} else {
1.94      sakharuk  772:             $r->print('<p><font color="#ff0000">'.&mt('ERROR').'</font>&nbsp;');
1.79      matthew   773:             if ($amode =~ /^krb/) {
1.94      sakharuk  774:                 $r->print(&mt('Missing Kerberos domain information.').'  ');
1.79      matthew   775:             } else {
1.94      sakharuk  776:                 $r->print(&mt('Invalid login mode or password.').'  ');
1.79      matthew   777:             }
1.94      sakharuk  778:             $r->print('<b>'.&mt('Unable to enroll').' '.$ENV{'form.cuname'}.'.</b></p>');
1.79      matthew   779:         }
1.12      www       780:     } else {
1.94      sakharuk  781:         $r->print(&mt('Invalid username or domain'));
1.26      matthew   782:     }    
1.12      www       783: }
                    784: 
1.68      matthew   785: sub setup_date_selectors {
1.91      raeburn   786:     my ($starttime,$endtime,$mode) = @_;
1.68      matthew   787:     if (! defined($starttime)) {
                    788:         $starttime = time;
1.114     raeburn   789:         unless ($mode eq 'create_enrolldates' || $mode eq 'create_defaultdates') {
1.91      raeburn   790:             if (exists($ENV{'course.'.$ENV{'request.course.id'}.
1.68      matthew   791:                             '.default_enrollment_start_date'})) {
1.91      raeburn   792:                 $starttime = $ENV{'course.'.$ENV{'request.course.id'}.
1.68      matthew   793:                                   '.default_enrollment_start_date'};
1.91      raeburn   794:             }
1.68      matthew   795:         }
                    796:     }
                    797:     if (! defined($endtime)) {
                    798:         $endtime = time+(6*30*24*60*60); # 6 months from now, approx
1.91      raeburn   799:         unless ($mode eq 'createcourse') {
                    800:             if (exists($ENV{'course.'.$ENV{'request.course.id'}.
1.68      matthew   801:                             '.default_enrollment_end_date'})) {
1.91      raeburn   802:                 $endtime = $ENV{'course.'.$ENV{'request.course.id'}.
1.68      matthew   803:                                 '.default_enrollment_end_date'};
1.91      raeburn   804:             }
1.68      matthew   805:         }
                    806:     }
                    807:     my $startdateform = &Apache::lonhtmlcommon::date_setter('studentform',
                    808:                                                             'startdate',
                    809:                                                             $starttime);
                    810:     my $enddateform = &Apache::lonhtmlcommon::date_setter('studentform',
                    811:                                                           'enddate',
                    812:                                                           $endtime);
1.114     raeburn   813:     if ($mode eq 'create_enrolldates') {
                    814:         $startdateform = &Apache::lonhtmlcommon::date_setter('ccrs',
                    815:                                                             'startenroll',
                    816:                                                             $starttime);
                    817:         $enddateform = &Apache::lonhtmlcommon::date_setter('ccrs',
                    818:                                                           'endenroll',
                    819:                                                           $endtime);
                    820:     }
                    821:     if ($mode eq 'create_defaultdates') {
1.91      raeburn   822:         $startdateform = &Apache::lonhtmlcommon::date_setter('ccrs',
1.114     raeburn   823:                                                             'startaccess',
1.91      raeburn   824:                                                             $starttime);
                    825:         $enddateform = &Apache::lonhtmlcommon::date_setter('ccrs',
1.114     raeburn   826:                                                           'endaccess',
1.91      raeburn   827:                                                           $endtime);
                    828:     }
1.68      matthew   829:     return ($startdateform,$enddateform);
                    830: }
                    831: 
                    832: sub get_dates_from_form {
                    833:     my $startdate = &Apache::lonhtmlcommon::get_date_from_form('startdate');
                    834:     my $enddate   = &Apache::lonhtmlcommon::get_date_from_form('enddate');
                    835:     if ($ENV{'form.no_end_date'}) {
                    836:         $enddate = 0;
                    837:     }
                    838:     return ($startdate,$enddate);
                    839: }
                    840: 
                    841: sub date_setting_table {
1.91      raeburn   842:     my ($starttime,$endtime,$mode) = @_;
                    843:     my ($startform,$endform)=&setup_date_selectors($starttime,$endtime,$mode);
1.68      matthew   844:     my $dateDefault = '<nobr>'.
1.94      sakharuk  845:         '<input type="checkbox" name="makedatesdefault" /> '.
                    846:         &mt('make these dates the default for future enrollment');
1.114     raeburn   847:     if ($mode eq 'create_enrolldates' || $mode eq 'create_defaultdates') {
1.91      raeburn   848:         $dateDefault = '&nbsp;';
                    849:     }
1.68      matthew   850:     my $perpetual = '<nobr><input type="checkbox" name="no_end_date"';
                    851:     if (defined($endtime) && $endtime == 0) {
                    852:         $perpetual .= ' checked';
                    853:     }
1.94      sakharuk  854:     $perpetual.= ' /> '.&mt('no ending date').'</nobr>';
1.114     raeburn   855:     if ($mode eq 'create_enrolldates') {
                    856:         $perpetual = '&nbsp;';
                    857:     }
1.68      matthew   858:     my $result = '';
                    859:     $result .= "<table>\n";
1.94      sakharuk  860:     $result .= '<tr><td align="right">'.&mt('Starting Date').'</td>'.
1.68      matthew   861:         '<td>'.$startform.'</td>'.
                    862:         '<td>'.$dateDefault.'</td>'."</tr>\n";
1.94      sakharuk  863:     $result .= '<tr><td align="right">'.&mt('Ending Date').'</td>'.
1.68      matthew   864:         '<td>'.$endform.'</td>'.
                    865:         '<td>'.$perpetual.'</td>'."</tr>\n";
                    866:     $result .= "</table>\n";
                    867:     return $result;
                    868: }
                    869: 
                    870: sub make_dates_default {
                    871:     my ($startdate,$enddate) = @_;
                    872:     my $result = '';
                    873:     my $dom = $ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
                    874:     my $crs = $ENV{'course.'.$ENV{'request.course.id'}.'.num'};
                    875:     my $put_result = &Apache::lonnet::put('environment',
                    876:             {'default_enrollment_start_date'=>$startdate,
                    877:              'default_enrollment_end_date'  =>$enddate},$dom,$crs);
                    878:     if ($put_result eq 'ok') {
                    879:         $result .= "Set default start and end dates for course<br />";
1.69      matthew   880:         #
                    881:         # Refresh the course environment
                    882:         &Apache::lonnet::coursedescription($ENV{'request.course.id'});
1.68      matthew   883:     } else {
1.94      sakharuk  884:         $result .= &mt('Unable to set default dates for course').":".$put_result.
1.68      matthew   885:             '<br />';
                    886:     }
                    887:     return $result;
                    888: }
                    889: 
1.74      matthew   890: ##
                    891: ## Single student enrollment routines (some of them)
                    892: ##
                    893: sub get_student_username_domain_form {
                    894:     my $r = shift;
                    895:     my $domform = &Apache::loncommon::select_dom_form
1.85      matthew   896:         ($ENV{'course.'.$ENV{'request.course.id'}.'.domain'},'cudomain',0);
1.94      sakharuk  897:     my %lt=&Apache::lonlocal::texthash(
                    898: 		    'eos'  => "Enroll One Student",
                    899: 		    'usr'  => "Username",
                    900:                     'dom'  => "Domain",
                    901:                     'been' => "Begin Enrollment",
                    902: 				       );
1.74      matthew   903:     $r->print(<<END);
                    904: <input type="hidden" name="action" value="enrollstudent" />
                    905: <input type="hidden" name="state"  value="gotusername" />
1.94      sakharuk  906: <h3>$lt{'eos'}</h3>
1.74      matthew   907: <table>
1.94      sakharuk  908: <tr><th>$lt{'usr'}:</th>
1.74      matthew   909:     <td><input type="text" name="cuname"  size="15" /></td></tr>
1.94      sakharuk  910: <tr><th>$lt{'dom'}:</th>
1.74      matthew   911:     <td>$domform</td></tr>
                    912: <tr><th>&nbsp;</th>
                    913:     <td>
1.94      sakharuk  914:     <input type="submit" name="Begin Enrollment" value="$lt{'been'}" />
1.74      matthew   915:     </td></tr>
                    916: </table>
1.120   ! albertel  917: <script type="text/javascript">
        !           918: // the if prevents the script error if the browser can not handle this
        !           919: if ( document.studentform.cuname ) { document.studentform.cuname.focus(); }
        !           920: </script>
1.74      matthew   921: END
                    922:     return;
                    923: }
                    924: 
1.50      matthew   925: sub print_enroll_single_student_form {
1.10      www       926:     my $r=shift;
1.94      sakharuk  927:     $r->print("<h3>".&mt('Enroll One Student')."</h3>");
1.74      matthew   928:     #
                    929:     my $username = $ENV{'form.cuname'};
                    930:     my $domain   = $ENV{'form.cudomain'};
1.116     albertel  931:     $username=~s/[\W|_]//gs;
                    932:     $domain=~s/[\W|_]//gs;
1.74      matthew   933:     my $home = &Apache::lonnet::homeserver($username,$domain);
                    934:     # $new_user flags whether we are creating a new user or using an old one
                    935:     my $new_user = 1;
                    936:     if ($home ne 'no_host') {
                    937:         $new_user = 0;
                    938:     }
                    939:     #
                    940:     my $user_data_html = '';
                    941:     my $javascript_validations = '';
                    942:     if ($new_user) {
1.85      matthew   943:         my $defdom=$ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
1.74      matthew   944:         # Set up authentication forms
                    945:         my ($krbdef,$krbdefdom) =
1.75      matthew   946:             &Apache::loncommon::get_kerberos_defaults($domain);
1.89      matthew   947:         $javascript_validations=&javascript_validations('auth',$krbdefdom);
1.74      matthew   948:         my %param = ( formname => 'document.studentform',
                    949:                       kerb_def_dom => $krbdefdom,
                    950:                       kerb_def_auth => $krbdef
                    951:                       );
                    952:         my $krbform = &Apache::loncommon::authform_kerberos(%param);
                    953:         my $intform = &Apache::loncommon::authform_internal(%param);
                    954:         my $locform = &Apache::loncommon::authform_local(%param);
                    955:         #
                    956:         # Set up domain selection form
                    957:         my $homeserver_form = '';
                    958:         my %servers = &Apache::loncommon::get_library_servers($domain);
                    959:         $homeserver_form = '<select name="lcserver" size="1">'."\n".
                    960:             '<option value="default" selected>default</option>'."\n";
                    961:         while (my ($servername,$serverdescription) = each (%servers)) {
                    962:             $homeserver_form .= '<option value="'.$servername.'">'.
                    963:                 $serverdescription."</option>\n";
                    964:         }
                    965:         $homeserver_form .= "</select>\n";
                    966:         #
                    967:         #
1.94      sakharuk  968: 	my %lt=&Apache::lonlocal::texthash(
                    969: 		       'udf'  => "User Data for",
                    970:                        'fn'   => "First Name",
                    971:                        'mn'   => "Middle Name",
                    972:                        'ln'   => "Last Name",
                    973:                        'gen'  => "Generation",
                    974:                        'hs'   => "Home Server",
                    975:                        'pswd' => "Password",
                    976: 		       'psam' => "Please select an authentication mechanism",
                    977: 					   );
1.74      matthew   978:         $user_data_html = <<END;
1.94      sakharuk  979: <h3>$lt{'udf'} $username\@$domain</h3>
1.74      matthew   980: <table>
1.94      sakharuk  981: <tr><th>$lt{'fn'}:</th>
1.74      matthew   982:     <td><input type="text" name="cfirst"  size="15"></td></tr>
1.94      sakharuk  983: <tr><th>$lt{'mn'}:</th>
1.74      matthew   984:     <td><input type="text" name="cmiddle" size="15"></td></tr>
1.94      sakharuk  985: <tr><th>$lt{'ln'}:</th>
1.74      matthew   986:     <td><input type="text" name="clast"   size="15"></td></tr>
1.94      sakharuk  987: <tr><th>$lt{'gen'}:</th>
1.74      matthew   988:     <td><input type="text" name="cgen"    size="5"> </td></tr>
1.94      sakharuk  989: <tr><th>$lt{'hs'}:</th>
1.74      matthew   990:     <td>$homeserver_form</td></tr>
                    991: </table>
1.94      sakharuk  992: <h3>$lt{'pswd'}</h3>
                    993: $lt{'psam'}
1.74      matthew   994: <table>
                    995: <p>
                    996: $krbform
1.75      matthew   997: <br />
1.74      matthew   998: $intform
1.75      matthew   999: <br />
1.74      matthew  1000: $locform
                   1001: </p>
                   1002: END
                   1003:     } else {
                   1004:         # User already exists.  Do not worry about authentication
                   1005:         my %uenv = &Apache::lonnet::dump('environment',$domain,$username);
1.89      matthew  1006:         $javascript_validations = &javascript_validations('noauth');
1.94      sakharuk 1007: 	my %lt=&Apache::lonlocal::texthash(
                   1008: 		       'udf'  => "User Data for",
                   1009:                        'fn'   => "First Name",
                   1010:                        'mn'   => "Middle Name",
                   1011:                        'ln'   => "Last Name",
                   1012:                        'gen'  => "Generation",
                   1013: 					   );
1.74      matthew  1014:         $user_data_html = <<END;
1.94      sakharuk 1015: <h3>$lt{'udf'} $username\@$domain</h3>
1.74      matthew  1016: <input type="hidden" name="lcserver" value="default" />
                   1017: <table>
1.94      sakharuk 1018: <tr><th>$lt{'fn'}:</th>
1.74      matthew  1019:     <td>
                   1020:     <input type="text" name="cfirst" value="$uenv{'firstname'}" size="15" />
                   1021:     </td></tr>
1.94      sakharuk 1022: <tr><th>$lt{'mn'}:</th>
1.74      matthew  1023:     <td>
                   1024:     <input type="text" name="cmiddle" value="$uenv{'middlename'}" size="15" />
                   1025:     </td></tr>
1.94      sakharuk 1026: <tr><th>$lt{'ln'}:</th>
1.74      matthew  1027:     <td>
                   1028:     <input type="text" name="clast"value="$uenv{'lastname'}" size="15" />
                   1029:     </td></tr>
1.94      sakharuk 1030: <tr><th>$lt{'gen'}:</th>
1.74      matthew  1031:     <td>
                   1032:     <input type="text" name="cgen" value="$uenv{'generation'}" size="5" />
                   1033:     </td></tr>
                   1034: </table>
                   1035: END
                   1036:     }
1.68      matthew  1037:     my $date_table = &date_setting_table();
1.74      matthew  1038:         # Print it all out
1.94      sakharuk 1039:     my %lt=&Apache::lonlocal::texthash(
                   1040: 		   'cd'   => "Course Data",
                   1041:                    'gs'   => "Group/Section",
                   1042:                    'idsn' => "ID/Student Number",
                   1043:                    'disn' => "Disable ID/Student Number Safeguard and Force Change of Conflicting IDs (only do if you know what you are doing)",
                   1044:                    'eas'  => "Enroll as student",
                   1045: 				       );
1.50      matthew  1046:     $r->print(<<END);
1.74      matthew  1047: <input type="hidden" name="action" value="enrollstudent" />
                   1048: <input type="hidden" name="state"  value="done" />
                   1049: <input type="hidden" name="cuname" value="$username" />
                   1050: <input type="hidden" name="lcdomain" value="$domain" />
1.28      matthew  1051: <script type="text/javascript" language="Javascript">
1.12      www      1052: function verify(vf) {
                   1053:     var founduname=0;
                   1054:     var foundpwd=0;
                   1055:     var foundname=0;
                   1056:     var foundid=0;
                   1057:     var foundsec=0;
                   1058:     var tw;
1.26      matthew  1059:     if ((typeof(vf.cuname.value) !="undefined") && (vf.cuname.value!='') && 
1.31      matthew  1060: 	(typeof(vf.lcdomain.value)!="undefined") && (vf.lcdomain.value!='')) {
1.12      www      1061:         founduname=1;
                   1062:     }
1.14      harris41 1063:     if ((typeof(vf.cfirst.value)!="undefined") && (vf.cfirst.value!='') &&
1.26      matthew  1064: 	(typeof(vf.clast.value) !="undefined") && (vf.clast.value!='')) {
1.12      www      1065:         foundname=1;
                   1066:     }
1.14      harris41 1067:     if ((typeof(vf.csec.value)!="undefined") && (vf.csec.value!='')) {
1.12      www      1068:         foundsec=1;
                   1069:     }
1.14      harris41 1070:     if ((typeof(vf.cstid.value)!="undefined") && (vf.cstid.value!='')) {
1.12      www      1071: 	foundid=1;
                   1072:     }
                   1073:     if (founduname==0) {
                   1074: 	alert('You need to specify at least the username and domain fields');
                   1075:         return;
                   1076:     }
1.24      albertel 1077:     verify_message(vf,founduname,foundpwd,foundname,foundid,foundsec);
1.12      www      1078: }
                   1079: 
1.24      albertel 1080: $javascript_validations
1.12      www      1081: 
1.24      albertel 1082: function clearpwd(vf) {
                   1083:     //nothing else needs clearing
1.15      albertel 1084: }
                   1085: 
1.12      www      1086: </script>
1.11      www      1087: 
1.74      matthew  1088: $user_data_html
1.50      matthew  1089: 
1.94      sakharuk 1090: <h3>$lt{'cd'}</h3>
1.50      matthew  1091: 
1.94      sakharuk 1092: <p>$lt{'gs'}: <input type="text" name="csec" size="5" />
1.50      matthew  1093: <p>
1.68      matthew  1094: $date_table
1.50      matthew  1095: </p>
1.94      sakharuk 1096: <h3>$lt{'idsn'}</h3>
1.50      matthew  1097: <p>
1.94      sakharuk 1098: $lt{'idsn'}: <input type="text" name="cstid" size="10">
1.26      matthew  1099: </p><p>
                   1100: <input type="checkbox" name="forceid" value="yes"> 
1.94      sakharuk 1101: $lt{'disn'}
1.50      matthew  1102: </p><p>
1.94      sakharuk 1103: <input type="button" onClick="verify(this.form)" value="$lt{'eas'}">
1.26      matthew  1104: </p>
1.50      matthew  1105: END
                   1106:     return;
1.10      www      1107: }
                   1108: 
                   1109: # ========================================================= Menu Phase Two Drop
1.51      matthew  1110: sub print_drop_menu {
1.10      www      1111:     my $r=shift;
1.92      sakharuk 1112:     $r->print("<h3>".&mt('Drop Students')."</h3>");
1.11      www      1113:     my $cid=$ENV{'request.course.id'};
1.56      matthew  1114:     my ($classlist,$keylist) = &Apache::loncoursedata::get_classlist();
                   1115:     if (! defined($classlist)) {
1.94      sakharuk 1116:         $r->print(&mt('There are no students currently enrolled.')."\n");
1.51      matthew  1117:         return;
1.25      matthew  1118:     }
1.51      matthew  1119:     # Print out the available choices
1.56      matthew  1120:     &show_drop_list($r,$classlist,$keylist);
1.51      matthew  1121:     return;
1.11      www      1122: }
                   1123: 
1.40      matthew  1124: # ============================================== view classlist
1.50      matthew  1125: sub print_html_classlist {
1.103     matthew  1126:     my ($r,$mode) = @_;
1.57      matthew  1127:     if (! exists($ENV{'form.sortby'})) {
                   1128:         $ENV{'form.sortby'} = 'username';
                   1129:     }
1.59      matthew  1130:     if ($ENV{'form.Status'} !~ /^(Any|Expired|Active)$/) {
1.57      matthew  1131:         $ENV{'form.Status'} = 'Active';
                   1132:     }
                   1133:     my $status_select = &Apache::lonhtmlcommon::StatusOptions
1.103     matthew  1134:         ($ENV{'form.Status'});
1.100     www      1135:     my $cid=$ENV{'request.course.id'};
                   1136:     my $cdom=$ENV{'course.'.$cid.'.domain'};
                   1137:     my $cnum=$ENV{'course.'.$cid.'.num'};
1.103     matthew  1138:     #
                   1139:     # List course personnel
1.100     www      1140:     my %coursepersonnel=&Apache::lonnet::get_course_adv_roles($cdom.'/'.$cnum);
1.110     matthew  1141:     #
                   1142:     if (! defined($ENV{'form.output'}) ||
                   1143:         $ENV{'form.output'} !~ /^(csv|excel|html)$/ ) {
                   1144:         $ENV{'form.output'} = 'html';
                   1145:     }
                   1146:     #
1.103     matthew  1147:     $r->print('<br /><table border="2">');
1.110     matthew  1148:     foreach my $role (sort keys %coursepersonnel) {
                   1149:         next if ($role =~ /^\s*$/);
                   1150: 	$r->print('<tr><td>'.$role.'</td><td>');
                   1151:         foreach my $user (split(',',$coursepersonnel{$role})) {
                   1152: 	    my ($puname,$pudom)=split(':',$user);
1.100     www      1153: 	    $r->print(' '.&Apache::loncommon::aboutmewrapper(
1.110     matthew  1154:                                     &Apache::loncommon::plainname($puname,
                   1155:                                                                   $pudom),
                   1156:                                                              $puname,$pudom));
1.100     www      1157: 	}
                   1158:         $r->print('</td></tr>');
                   1159:     }
                   1160:     $r->print('</table>');
1.103     matthew  1161:     #
                   1162:     # Interface output
                   1163:     $r->print('<input type="hidden" name="action" value="'.
                   1164:               $ENV{'form.action'}.'" />');
                   1165:     $r->print("<p>\n");
1.59      matthew  1166:     if ($ENV{'form.action'} ne 'modifystudent') {
1.103     matthew  1167: 	my %lt=&Apache::lonlocal::texthash('csv' => "CSV",
                   1168:                                            'excel' => "Excel",
                   1169:                                            'html'  => 'HTML');
1.110     matthew  1170:         my $output_selector = '<select size="1" name="output" >';
1.103     matthew  1171:         foreach my $outputformat ('html','csv','excel') {
                   1172:             my $option = '<option value="'.$outputformat.'" ';
1.110     matthew  1173:             if ($outputformat eq $ENV{'form.output'}) {
1.104     matthew  1174:                 $option .= 'selected ';
1.103     matthew  1175:             }
                   1176:             $option .='>'.$lt{$outputformat}.'</option>';
                   1177:             $output_selector .= "\n".$option;
                   1178:         }
                   1179:         $output_selector .= '</select>';
                   1180:         $r->print(&mt('Output Format: [_1]',$output_selector).('&nbsp;'x3));
1.59      matthew  1181:     }
1.103     matthew  1182:     $r->print(&mt('Student Status: [_1]',$status_select)."\n");
1.105     matthew  1183:     $r->print('<input type="submit" value="'.&mt('Update Display').'" />'.
                   1184:               "\n</p>\n");
1.103     matthew  1185:     #
                   1186:     # Print the classlist
                   1187:     $r->print('<h2>'.&mt('Current Class List').'</h2>');
1.56      matthew  1188:     my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist();
                   1189:     if (! defined($classlist)) {
1.94      sakharuk 1190:         $r->print(&mt('There are no students currently enrolled.')."\n");
1.40      matthew  1191:     } else {
                   1192:         # Print out the available choices
1.50      matthew  1193:         if ($ENV{'form.action'} eq 'modifystudent') {
1.110     matthew  1194:             &show_class_list($r,'view','modify',
1.57      matthew  1195:                              $ENV{'form.Status'},$classlist,$keylist);
1.110     matthew  1196:         } else {
                   1197:             &show_class_list($r,$ENV{'form.output'},'aboutme',
1.103     matthew  1198:                              $ENV{'form.Status'},$classlist,$keylist);
1.50      matthew  1199:         }
1.41      matthew  1200:     }
                   1201: }
                   1202: 
1.40      matthew  1203: # =================================================== Show student list to drop
                   1204: sub show_class_list {
1.110     matthew  1205:     my ($r,$mode,$linkto,$statusmode,$classlist,$keylist)=@_;
1.40      matthew  1206:     my $cid=$ENV{'request.course.id'};
1.60      matthew  1207:     #
                   1208:     # Variables for excel output
1.104     matthew  1209:     my ($excel_workbook, $excel_sheet, $excel_filename,$row,$format);
1.60      matthew  1210:     #
1.103     matthew  1211:     # Variables for csv output
                   1212:     my ($CSVfile,$CSVfilename);
                   1213:     #
1.53      matthew  1214:     my $sortby = $ENV{'form.sortby'};
1.114     raeburn  1215:     if ($sortby !~ /^(username|domain|section|fullname|id|start|end|type)$/) {
1.53      matthew  1216:         $sortby = 'username';
                   1217:     }
1.42      matthew  1218:     # Print out header 
1.114     raeburn  1219:     unless ($mode eq 'autoenroll') {
                   1220:         $r->print(<<END);
                   1221: <input type="hidden" name="state" value="$ENV{'form.state'}" />
                   1222: END
                   1223:     }
1.103     matthew  1224:     $r->print(<<END);
                   1225: <input type="hidden" name="sortby" value="$sortby" />
                   1226: END
1.114     raeburn  1227:     if ($mode eq 'html' || $mode eq 'view' || $mode eq 'autoenroll') {
1.50      matthew  1228:         if ($linkto eq 'aboutme') {
1.94      sakharuk 1229:             $r->print(&mt('Select a user name to view the users personal page.'));
1.50      matthew  1230:         } elsif ($linkto eq 'modify') {
1.94      sakharuk 1231:             $r->print(&mt('Select a user name to modify the students information'));
1.50      matthew  1232:         }
1.94      sakharuk 1233: 	my %lt=&Apache::lonlocal::texthash(
1.110     matthew  1234:                                            'usrn'   => "username",
                   1235:                                            'dom'    => "domain",
                   1236:                                            'sn'     => "student name",
                   1237:                                            'sec'    => "section",
                   1238:                                            'start'  => "start date",
                   1239:                                            'end'    => "end date",
1.115     raeburn  1240:                                            'type'   => "enroll type/action"
1.94      sakharuk 1241: 					   );
1.114     raeburn  1242:         unless ($mode eq 'autoenroll') {
                   1243:             $r->print(<<END);
1.59      matthew  1244: <input type="hidden" name="sname"  value="" />
                   1245: <input type="hidden" name="sdom"   value="" />
1.114     raeburn  1246: END
                   1247:         }
1.115     raeburn  1248:         $r->print("
1.40      matthew  1249: <p>
                   1250: <table border=2>
1.115     raeburn  1251: <tr>
                   1252:         ");
                   1253:         if ($mode eq 'autoenroll') {
                   1254:             $r->print("
                   1255:  <th><a href=\"javascript:document.studentform.sortby.value='type';document.studentform.submit();\">$lt{'type'}</a></th>
                   1256:             ");
                   1257:         } else {
                   1258:             $r->print("
                   1259: <th>Count</th>
                   1260:             ");
                   1261:         }
                   1262:         $r->print(<<END);
                   1263:     <th>
1.94      sakharuk 1264:        <a href="javascript:document.studentform.sortby.value='username';document.studentform.submit();">$lt{'usrn'}</a>
1.53      matthew  1265:     </th><th>
1.94      sakharuk 1266:        <a href="javascript:document.studentform.sortby.value='domain';document.studentform.submit();">$lt{'dom'}</a>
1.53      matthew  1267:     </th><th>
1.57      matthew  1268:        <a href="javascript:document.studentform.sortby.value='id';document.studentform.submit();">ID</a>
1.53      matthew  1269:     </th><th>
1.94      sakharuk 1270:        <a href="javascript:document.studentform.sortby.value='fullname';document.studentform.submit();">$lt{'sn'}</a>
1.53      matthew  1271:     </th><th>
1.94      sakharuk 1272:        <a href="javascript:document.studentform.sortby.value='section';document.studentform.submit();">$lt{'sec'}</a>
1.110     matthew  1273:     </th><th>
                   1274:        <a href="javascript:document.studentform.sortby.value='start';document.studentform.submit();">$lt{'start'}</a>
                   1275:     </th><th>
                   1276:        <a href="javascript:document.studentform.sortby.value='end';document.studentform.submit();">$lt{'end'}</a>
1.53      matthew  1277:     </th>
1.115     raeburn  1278:   </tr>
1.40      matthew  1279: END
1.41      matthew  1280:     } elsif ($mode eq 'csv') {
1.103     matthew  1281: 	#
                   1282: 	# Open a file
                   1283: 	$CSVfilename = '/prtspool/'.
                   1284: 	    $ENV{'user.name'}.'_'.$ENV{'user.domain'}.'_'.
                   1285:             time.'_'.rand(1000000000).'.csv';
                   1286: 	unless ($CSVfile = Apache::File->new('>/home/httpd'.$CSVfilename)) {
                   1287: 	    $r->log_error("Couldn't open $CSVfilename for output $!");
                   1288: 	    $r->print("Problems occured in writing the csv file.  ".
                   1289: 		      "This error has been logged.  ".
                   1290: 		      "Please alert your LON-CAPA administrator.");
                   1291: 	    $CSVfile = undef;
                   1292: 	}
                   1293: 	#
                   1294: 	# Write headers and data to file
1.58      matthew  1295:         if($statusmode eq 'Expired') {
1.103     matthew  1296:             print $CSVfile '"'.&mt('Students with expired roles').'"'."\n";
1.58      matthew  1297:         }
                   1298:         if ($statusmode eq 'Any') {
1.103     matthew  1299:             print $CSVfile '"'.join('","',map {
                   1300: 		&Apache::loncommon::csv_translate(&mt($_))
                   1301:                 } ("username","domain","ID","student name",
1.110     matthew  1302:                    "section","start date","end date","status")).'"'."\n";
1.58      matthew  1303:         } else {
1.103     matthew  1304:             print $CSVfile '"'.join('","',map {
                   1305: 		&Apache::loncommon::csv_translate(&mt($_))
                   1306:                 } ("username","domain","ID","student name",
1.110     matthew  1307:                    "section","start date","end date")).'"'."\n";
1.58      matthew  1308:         }
1.60      matthew  1309:     } elsif ($mode eq 'excel') {
                   1310:         # Create the excel spreadsheet
                   1311:         $excel_filename = '/prtspool/'.
                   1312:             $ENV{'user.name'}.'_'.$ENV{'user.domain'}.'_'.
                   1313:                 time.'_'.rand(1000000000).'.xls';
                   1314:         $excel_workbook = Spreadsheet::WriteExcel->new('/home/httpd'.
                   1315:                                                        $excel_filename);
                   1316:         $excel_workbook->set_tempdir('/home/httpd/perl/tmp');
1.104     matthew  1317:         #
                   1318:         $format = &Apache::loncommon::define_excel_formats($excel_workbook);
1.60      matthew  1319:         $excel_sheet = $excel_workbook->addworksheet('classlist');
                   1320:         #
1.76      albertel 1321:         my $description = 'Class List for '.
1.60      matthew  1322:             $ENV{'course.'.$ENV{'request.course.id'}.'.description'};
1.104     matthew  1323:         $excel_sheet->write($row++,0,$description,$format->{'h1'});
1.60      matthew  1324:         #
                   1325:         $excel_sheet->write($row++,0,["username","domain","ID",
1.110     matthew  1326:                                       "student name","section",
                   1327:                                       "start date","end date","status"],
                   1328:                             $format->{'bold'});
1.41      matthew  1329:     }
1.56      matthew  1330:     #
                   1331:     # Sort the students
                   1332:     my %index;
                   1333:     my $i;
                   1334:     foreach (@$keylist) {
                   1335:         $index{$_} = $i++;
                   1336:     }
                   1337:     my $index  = $index{$sortby};
                   1338:     my $second = $index{'username'};
                   1339:     my $third  = $index{'domain'};
1.53      matthew  1340:     my @Sorted_Students = sort {
1.56      matthew  1341:         lc($classlist->{$a}->[$index])  cmp lc($classlist->{$b}->[$index])
                   1342:             ||
                   1343:         lc($classlist->{$a}->[$second]) cmp lc($classlist->{$b}->[$second])
                   1344:             ||
                   1345:         lc($classlist->{$a}->[$third]) cmp lc($classlist->{$b}->[$third])
                   1346:         } (keys(%$classlist));
1.108     matthew  1347:     my $studentcount = 0;
1.115     raeburn  1348:     my $autocount = 0;
                   1349:     my $manualcount = 0;
                   1350:     my $unlockcount = 0;
                   1351:     my $lockcount = 0;
1.53      matthew  1352:     foreach my $student (@Sorted_Students) {
1.110     matthew  1353:         my $sdata = $classlist->{$student};
                   1354:         my $username = $sdata->[$index{'username'}];
                   1355:         my $domain   = $sdata->[$index{'domain'}];
                   1356:         my $section  = $sdata->[$index{'section'}];
                   1357:         my $name     = $sdata->[$index{'fullname'}];
                   1358:         my $id       = $sdata->[$index{'id'}];
                   1359:         my $status   = $sdata->[$index{'status'}];
                   1360:         my $start    = $sdata->[$index{'start'}];
                   1361:         my $end      = $sdata->[$index{'end'}];
1.115     raeburn  1362:         my $type     = $sdata->[$index{'type'}];
1.57      matthew  1363:         next if (($statusmode ne 'Any') && ($status ne $statusmode));
1.114     raeburn  1364:         if ($mode eq 'view' || $mode eq 'html' || $mode eq 'autoenroll') {
                   1365:             if (! defined($start) || $start == 0) {
                   1366:                 $start = &mt('none');
                   1367:             } else {
                   1368:                 $start = &Apache::lonlocal::locallocaltime($start);
                   1369:             }
                   1370:             if (! defined($end) || $end == 0) {
                   1371:                 $end = &mt('none');
                   1372:             } else {
                   1373:                 $end = &Apache::lonlocal::locallocaltime($end);
                   1374:             }
1.115     raeburn  1375:             $r->print("<tr>\n    ");
                   1376:             if ($mode eq 'autoenroll') {
                   1377:                 my $lockedtype = $sdata->[$index{'lockedtype'}];
                   1378:                 $studentcount++;
                   1379:                 my $cellentry;
                   1380:                 if ($type eq 'auto') {
                   1381:                     $cellentry = '<b>'.&mt('auto').'</b>&nbsp;<input type="checkbox" name="chgauto" value="'.$username.':'.$domain.'" />&nbsp;Change';
                   1382:                     $autocount ++;
                   1383:                 } else {
1.118     raeburn  1384:                     $cellentry = '<table border="0" cellspacing="0"><tr><td rowspan="2"><b>'.&mt('manual').'</b></td><td><nobr><input type="checkbox" name="chgmanual" value="'.$username.':'.$domain.'" />&nbsp;Change</nobr></td></tr><tr><td><nobr>';
1.115     raeburn  1385:                     $manualcount ++;
                   1386:                     if ($lockedtype) {
                   1387:                         $cellentry .= '<input type="checkbox" name="unlockchg" value="'.$username.':'.$domain.'" />&nbsp;'.&mt('Unlock');
                   1388:                         $unlockcount ++;
                   1389:                     } else {
                   1390:                         $cellentry .= '<input type="checkbox" name="lockchg" value="'.$username.':'.$domain.'" />&nbsp;'.&mt('Lock');
                   1391:                         $lockcount ++;
                   1392:                     }
1.118     raeburn  1393:                     $cellentry .= '</nobr></td></tr></table>';
1.115     raeburn  1394:                 }
                   1395:                 $r->print("<td>$cellentry<td>\n    ");
                   1396:             } else {
                   1397:                 $r->print("<td>".(++$studentcount)."</td><td>\n    ");
                   1398:             }
1.51      matthew  1399:             if ($linkto eq 'nothing') {
                   1400:                 $r->print($username);
                   1401:             } elsif ($linkto eq 'aboutme') {
                   1402:                 $r->print(&Apache::loncommon::aboutmewrapper($username,
                   1403:                                                              $username,
                   1404:                                                              $domain));
                   1405:             } elsif ($linkto eq 'modify') {
1.59      matthew  1406:                 $r->print('<a href="'.
                   1407:                           "javascript:document.studentform.sname.value='".
                   1408:                           $username.
                   1409:                           "';document.studentform.sdom.value='".$domain.
                   1410:                           "';document.studentform.state.value='selected".
                   1411:                           "';document.studentform.submit();".'">'.
1.53      matthew  1412:                           $username."</a>\n");
1.50      matthew  1413:             }
1.51      matthew  1414:             $r->print(<<"END");
1.50      matthew  1415:     </td>
1.51      matthew  1416:     <td>$domain</td>
                   1417:     <td>$id</td>
                   1418:     <td>$name</td>
                   1419:     <td>$section</td>
1.110     matthew  1420:     <td>$start</td>
                   1421:     <td>$end</td>
1.115     raeburn  1422:    </tr>
1.114     raeburn  1423: END
1.51      matthew  1424:         } elsif ($mode eq 'csv') {
1.103     matthew  1425:             next if (! defined($CSVfile));
1.51      matthew  1426:             # no need to bother with $linkto
1.114     raeburn  1427:             if (! defined($start) || $start == 0) {
                   1428:                 $start = &mt('none');
                   1429:             } else {
                   1430:                 $start = &Apache::lonlocal::locallocaltime($start);
                   1431:             }
                   1432:             if (! defined($end) || $end == 0) {
                   1433:                 $end = &mt('none');
                   1434:             } else {
                   1435:                 $end = &Apache::lonlocal::locallocaltime($end);
                   1436:             }
1.51      matthew  1437:             my @line = ();
1.110     matthew  1438:             foreach ($username,$domain,$id,$name,$section,$start,$end) {
1.51      matthew  1439:                 push @line,&Apache::loncommon::csv_translate($_);
1.58      matthew  1440:             }
                   1441:             if ($statusmode eq 'Any') {
                   1442:                 push @line,&Apache::loncommon::csv_translate($status);
1.41      matthew  1443:             }
1.103     matthew  1444:             print $CSVfile '"'.join('","',@line).'"'."\n";
1.60      matthew  1445:         } elsif ($mode eq 'excel') {
1.110     matthew  1446:             $excel_sheet->write($row,0,[$username,$domain,$id,
                   1447:                                           $name,$section]);
                   1448:             my $col = 5;
                   1449:             foreach my $time ($start,$end) {
                   1450:                 $excel_sheet->write($row,$col++,
                   1451:                                    &Apache::lonstathelpers::calc_serial($time),
                   1452:                                     $format->{'date'});
                   1453:             }
                   1454:             $excel_sheet->write($row,$col++,$status);
                   1455:             $row++;
1.40      matthew  1456:         }
                   1457:     }
1.114     raeburn  1458:     if ($mode eq 'view' || $mode eq 'html' || $mode eq 'autoenroll') {
1.60      matthew  1459:         $r->print('</table><br>');
                   1460:     } elsif ($mode eq 'excel') {
                   1461:         $excel_workbook->close();
                   1462:         $r->print('<p><a href="'.$excel_filename.'">'.
1.94      sakharuk 1463:                   &mt('Your Excel spreadsheet').'</a> '.&mt('is ready for download').'.</p>'."\n");
1.103     matthew  1464:     } elsif ($mode eq 'csv') {
                   1465:         close($CSVfile);
                   1466:         $r->print('<a href="'.$CSVfilename.'">'.
                   1467:                   &mt('Your CSV file').'</a> is ready for download.'.
                   1468:                   "\n");
                   1469:         $r->rflush();
1.60      matthew  1470:     }
1.114     raeburn  1471:     if ($mode eq 'autoenroll') {
1.115     raeburn  1472:         return ($studentcount,$autocount,$manualcount,$lockcount,$unlockcount);
1.114     raeburn  1473:     }
1.115     raeburn  1474:     return;
1.40      matthew  1475: }
                   1476: 
1.50      matthew  1477: 
                   1478: #
                   1479: # print out form for modification of a single students data
                   1480: #
                   1481: sub print_modify_student_form {
                   1482:     my $r = shift();
                   1483:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.59      matthew  1484:                                             ['sdom','sname']);    
1.53      matthew  1485:     my $sname  = $ENV{'form.sname'};
                   1486:     my $sdom   = $ENV{'form.sdom'};
                   1487:     my $sortby = $ENV{'form.sortby'};
1.50      matthew  1488:     # determine the students name information
                   1489:     my %info=&Apache::lonnet::get('environment',
                   1490:                                   ['firstname','middlename',
1.52      matthew  1491:                                    'lastname','generation','id'],
1.50      matthew  1492:                                   $sdom, $sname);
                   1493:     my ($tmp) = keys(%info);
                   1494:     if ($tmp =~ /^(con_lost|error|no_such_host)/i) {
1.94      sakharuk 1495:         $r->print('<font color="#ff0000" size="+2">'.&mt('Error').'</font>'.
1.50      matthew  1496:                   '<p>'.
1.94      sakharuk 1497:                   &mt('Unable to retrieve environment data for').' '.$sname.
                   1498:                   &mt('in domain').' '.$sdom.'</p><p>'.
                   1499:                   &mt('Please contact your LON-CAPA administrator regarding this situation.').'</p></body></html>');
1.50      matthew  1500:         return;
                   1501:     }
                   1502:     # determine the students starting and ending times and section
                   1503:     my ($starttime,$endtime,$section) = &get_enrollment_data($sname,$sdom);
1.87      matthew  1504:     if ($starttime =~ /^error/) {
1.94      sakharuk 1505:         $r->print('<h2>'&mt('Error').'</h2>');
1.87      matthew  1506:         $r->print('<p>'.$starttime.'</p>');
                   1507:         return;
                   1508:     }
1.101     matthew  1509:     #
1.50      matthew  1510:     # Deal with date forms
1.101     matthew  1511:     my $current_date_description = '';
                   1512:     my $textdate = '';
                   1513: 
                   1514:     if (! defined($starttime) || $starttime == 0) {
                   1515:         $current_date_description = &mt('Current Starting Date: not set').
                   1516:             '<br />';
                   1517:     } else {
                   1518:         $current_date_description = 
                   1519:             &mt('Current Starting Date: [_1]',
                   1520:                 &Apache::lonlocal::locallocaltime($starttime)).'<br />';
                   1521:     }
                   1522:     if (! defined($endtime) || $endtime == 0) {
                   1523:         $current_date_description.= &mt('Current Ending Date: not set').
                   1524:             '<br />';
                   1525:     } else {
                   1526:         $current_date_description.= 
                   1527:             &mt('Current Ending Date: [_1]',
                   1528:                 &Apache::lonlocal::locallocaltime($endtime)).'<br />';
                   1529: 
                   1530:     }
1.68      matthew  1531:     my $date_table = &date_setting_table($starttime,$endtime);
1.59      matthew  1532:     #
                   1533:     if (! exists($ENV{'form.Status'}) || 
                   1534:         $ENV{'form.Status'} !~ /^(Any|Expired|Active)$/) {
                   1535:         $ENV{'form.Status'} = 'crap';
                   1536:     }
1.94      sakharuk 1537:     # Make sure student is enrolled in course
                   1538:     my %lt=&Apache::lonlocal::texthash(
                   1539: 	           'mef'   => "Modify Enrollment for",
                   1540:                    'odcc'  => "Only domain coordinators can change a users password.",
                   1541:                    'sn'    => "Student Name",
                   1542:                    'fn'    => "First",
                   1543:                    'mn'    => "Middle",
                   1544:                    'ln'    => "Last",
                   1545:                    'gen'   => "Generation",
                   1546:                    'sid'   => "Student ID",
                   1547:                    'disn'  => "Disable ID/Student Number Safeguard and Force Change of Conflicting IDs (only do if you know what you are doing)",
                   1548:                    'sec'   => "Section",
                   1549:                    'sm'    => "Submit Modifications",
                   1550: 				       );
1.50      matthew  1551:     $r->print(<<END);
1.52      matthew  1552: <p>
                   1553: <font size="+1">
1.94      sakharuk 1554: $lt{'odcc'}
1.52      matthew  1555: </font>
                   1556: </p>
1.50      matthew  1557: <input type="hidden" name="slogin"  value="$sname"  />
                   1558: <input type="hidden" name="sdomain" value="$sdom" />
                   1559: <input type="hidden" name="action"  value="modifystudent" />
1.53      matthew  1560: <input type="hidden" name="state"   value="done" />
                   1561: <input type="hidden" name="sortby"  value="$sortby" />
1.59      matthew  1562: <input type="hidden" name="Status"  value="$ENV{'form.Status'}" />
1.94      sakharuk 1563: <h2>$lt{'mef'} $info{'firstname'} $info{'middlename'} 
1.50      matthew  1564: $info{'lastname'} $info{'generation'}, $sname\@$sdom</h2>
                   1565: <p>
1.94      sakharuk 1566: <b>$lt{'sn'}</b>
1.50      matthew  1567: <table>
1.94      sakharuk 1568: <tr><th>$lt{'fn'}</th><th>$lt{'mn'}</th><th>$lt{'ln'}</th><th>$lt{'gen'}</th></tr>
1.50      matthew  1569: <tr><td>
                   1570: <input type="text" name="firstname"  value="$info{'firstname'}"  /></td><td>
                   1571: <input type="text" name="middlename" value="$info{'middlename'}" /></td><td>
                   1572: <input type="text" name="lastname"   value="$info{'lastname'}"   /></td><td>
                   1573: <input type="text" name="generation" value="$info{'generation'}" /></td></tr>
                   1574: </table>
                   1575: </p><p>
1.94      sakharuk 1576: <b>$lt{'sid'}</b>: <input type="text" name="id" value="$info{'id'}" size="12"/>
1.52      matthew  1577: </p><p>
1.53      matthew  1578: <input type="checkbox" name="forceid" > 
1.94      sakharuk 1579: $lt{'disn'}
1.53      matthew  1580: </p><p>
1.101     matthew  1581: <b>$lt{'sec'}</b>: <input type="text" name="section" value="$section" size="14"/>
1.50      matthew  1582: </p>
1.101     matthew  1583: <p>$current_date_description</p>
1.68      matthew  1584: <p>$date_table</p>
1.94      sakharuk 1585: <input type="submit" value="$lt{'sm'}" />
1.50      matthew  1586: </body></html>
                   1587: END
                   1588:     return;
                   1589: }
                   1590: 
                   1591: #
                   1592: # modify a single students section 
                   1593: #
                   1594: sub modify_single_student {
                   1595:     my $r = shift;
1.68      matthew  1596:     #
1.80      matthew  1597:     # Remove non alphanumeric values from the section
                   1598:     $ENV{'form.section'} =~ s/\W//g;
1.77      matthew  1599:     #
1.68      matthew  1600:     # Do the date defaults first
                   1601:     my ($starttime,$endtime) = &get_dates_from_form();
                   1602:     if ($ENV{'form.makedatesdefault'}) {
                   1603:         $r->print(&make_dates_default($starttime,$endtime));
                   1604:     }
1.59      matthew  1605:     # Get the 'sortby' and 'Status' variables so the user goes back to their
                   1606:     # previous screen
1.53      matthew  1607:     my $sortby = $ENV{'form.sortby'};
1.59      matthew  1608:     my $status = $ENV{'form.Status'};
1.53      matthew  1609:     #
                   1610:     # We always need this information
                   1611:     my $slogin     = $ENV{'form.slogin'};
                   1612:     my $sdom       = $ENV{'form.sdomain'};
                   1613:     #
                   1614:     # Get the old data
                   1615:     my %old=&Apache::lonnet::get('environment',
                   1616:                                  ['firstname','middlename',
                   1617:                                   'lastname','generation','id'],
                   1618:                                  $sdom, $slogin);
1.59      matthew  1619:     $old{'section'} = &Apache::lonnet::getsection($sdom,$slogin,
                   1620:                                                   $ENV{'request.course.id'});
1.53      matthew  1621:     my ($tmp) = keys(%old);
                   1622:     if ($tmp =~ /^(con_lost|error|no_such_host)/i) {
1.94      sakharuk 1623:         $r->print(&mt('There was an error determining the environment values for')." $slogin \@ $sdom.");
1.53      matthew  1624:         return;
                   1625:     }
                   1626:     undef $tmp;
                   1627:     #
                   1628:     # Get the new data
1.50      matthew  1629:     my $firstname  = $ENV{'form.firstname'};
                   1630:     my $middlename = $ENV{'form.middlename'};
                   1631:     my $lastname   = $ENV{'form.lastname'};
                   1632:     my $generation = $ENV{'form.generation'};
                   1633:     my $section    = $ENV{'form.section'};
                   1634:     my $courseid   = $ENV{'request.course.id'};
1.52      matthew  1635:     my $sid        = $ENV{'form.id'};
1.50      matthew  1636:     my $displayable_starttime = localtime($starttime);
                   1637:     my $displayable_endtime   = localtime($endtime);
1.53      matthew  1638:     # 
                   1639:     # check for forceid override
1.63      matthew  1640:     if ((defined($old{'id'})) && ($old{'id'} ne '') && 
                   1641:         ($sid ne $old{'id'}) && (! exists($ENV{'form.forceid'}))) {
1.94      sakharuk 1642:         $r->print("<font color=\"ff0000\">".&mt('You changed the students id but did not disable the ID change safeguard. The students id will not be changed.')."</font>");
1.53      matthew  1643:         $sid = $old{'id'};
                   1644:     }
                   1645:     #
1.50      matthew  1646:     # talk to the user about what we are going to do
1.94      sakharuk 1647:     my %lt=&Apache::lonlocal::texthash(
                   1648: 	           'mdu'   => "Modifying data for user",
                   1649:                    'si'    => "Student Information",
                   1650:                    'fd'    => "Field",
                   1651:                    'ov'    => "Old Value",
                   1652:                    'nv'    => "New Value",
                   1653:                    'fn'    => "First name",
                   1654:                    'mn'    => "Middle name",
                   1655:                    'ln'    => "Last name",
                   1656:                    'gen'   => "Generation",
                   1657:                    'sec'   => "Section",
                   1658:                    'ri'    => "Role Information",
                   1659:                    'st'    => "Start Time",
                   1660:                    'et'    => "End Time",
                   1661: 				       );
1.50      matthew  1662:     $r->print(<<END);
1.94      sakharuk 1663:     <h2>$lt{'mdu'} $slogin \@ $sdom </h2>
                   1664: <h3>$lt{'si'}</h3>
1.53      matthew  1665: <table rules="rows" border="1" cellpadding="3" >
                   1666: <tr>
1.94      sakharuk 1667:     <th> $lt{'fd'} </th>
                   1668:     <th> $lt{'ov'} </th>
                   1669:     <th> $lt{'nv'} </th>
1.53      matthew  1670: </tr>
                   1671: <tr>
1.94      sakharuk 1672:     <td> <b>$lt{'fn'}</b> </td>
1.53      matthew  1673:     <td> $old{'firstname'} </td>
                   1674:     <td> $firstname </td>
                   1675: </tr><tr>
1.94      sakharuk 1676:     <td> <b>$lt{'mn'}</b> </td>
1.53      matthew  1677:     <td> $old{'middlename'} </td>
                   1678:     <td> $middlename </td>
                   1679: </tr><tr>
1.94      sakharuk 1680:     <td> <b>$lt{'ln'}</b> </td>
1.53      matthew  1681:     <td> $old{'lastname'} </td>
                   1682:     <td> $lastname </td>
                   1683: </tr><tr>
1.94      sakharuk 1684:     <td> <b>$lt{'gen'}</b> </td>
1.53      matthew  1685:     <td> $old{'generation'} </td>
                   1686:     <td> $generation </td>
                   1687: </tr><tr>
                   1688:     <td> <b>ID</b> </td>
                   1689:     <td> $old{'id'} </td>
                   1690:     <td> $sid </td>
1.59      matthew  1691: </tr><tr>
1.94      sakharuk 1692:     <td> <b>$lt{'sec'}</b> </td>
1.59      matthew  1693:     <td> $old{'section'} </td>
                   1694:     <td> $section</td>
1.53      matthew  1695: </tr>
1.50      matthew  1696: </table>
1.94      sakharuk 1697: <h3>$lt{'ri'}</h3>
1.50      matthew  1698: <table>
1.94      sakharuk 1699: <tr><td align="right"><b>$lt{'st'}:</b></td><td> $displayable_starttime </td></tr>
                   1700: <tr><td align="right"><b>$lt{'et'}:</b></td><td> $displayable_endtime   </td></tr>
1.50      matthew  1701: </table>
1.52      matthew  1702: <p>
1.50      matthew  1703: END
1.53      matthew  1704:     #
1.63      matthew  1705:     # Send request(s) to modify data (final undef is for 'desiredhost',
                   1706:     # which is a moot point because the student already has an account.
                   1707:     my $modify_section_results = &modifystudent($sdom,$slogin,
                   1708:                                                 $ENV{'request.course.id'},
                   1709:                                                 $section,undef);
                   1710:     if ($modify_section_results !~ /^ok/) {
1.94      sakharuk 1711:         $r->print(&mt('An error occured during the attempt to change the section for this student.')."<br />");
1.63      matthew  1712:     }
1.52      matthew  1713:     my $roleresults = &Apache::lonnet::modifystudent
1.53      matthew  1714:         ($sdom,$slogin,$sid,undef,undef,$firstname,$middlename,$lastname,
                   1715:          $generation,$section,$endtime,$starttime,$ENV{'form.forceid'});
                   1716:     if ($roleresults eq 'refused' ) {
1.94      sakharuk 1717:         $r->print(&mt('Your request to change the role information for this student was refused. You do not appear to have sufficient authority to change student information.'));
1.50      matthew  1718:     } elsif ($roleresults !~ /ok/) {
1.94      sakharuk 1719:         $r->print(&mt('An error occurred during the attempt to change the role information for this student.')."  <br />".
                   1720:                   &mt('The error reported was')." ".
1.50      matthew  1721:                   $roleresults);
1.53      matthew  1722:         &Apache::lonnet::logthis("londropadd:failed attempt to modify student".
                   1723:                                  " data for ".$slogin." \@ ".$sdom." by ".
                   1724:                                  $ENV{'user.name'}." \@ ".$ENV{'user.domain'}.
                   1725:                                  ":".$roleresults);
1.50      matthew  1726:     } else { # everything is okay!
1.94      sakharuk 1727:         $r->print(&mt('Student information updated successfully.')." <br />".
                   1728:                   &mt('The student must log out and log in again to see these changes.'));
1.50      matthew  1729:     }
1.94      sakharuk 1730:     my $Masd=&mt('Modify another students data');
1.50      matthew  1731:     $r->print(<<END);
1.52      matthew  1732: </p><p>
1.59      matthew  1733: <input type="hidden" name="action" value="modifystudent" />
                   1734: <input type="hidden" name="sortby" value="$sortby" />
                   1735: <input type="hidden" name="Status" value="$status" />
1.94      sakharuk 1736: <a href="javascript:document.studentform.submit();">$Masd</a>
1.50      matthew  1737: </body></html>
                   1738: END
                   1739:     return;
                   1740: }
                   1741: 
                   1742: sub get_enrollment_data {
                   1743:     my ($sname,$sdomain) = @_;
                   1744:     my $courseid = $ENV{'request.course.id'};
                   1745:     $courseid =~ s:_:/:g;
                   1746:     my %roles = &Apache::lonnet::dump('roles',$sdomain,$sname);
                   1747:     my ($tmp) = keys(%roles);
                   1748:     # Bail out if we were unable to get the students roles
1.87      matthew  1749:     return ('error'.$tmp) if ($tmp =~ /^(con_lost|error|no_such_host)/i);
1.50      matthew  1750:     # Go through the roles looking for enrollment in this course
                   1751:     my ($end,$start) = (undef,undef);
                   1752:     my $section = '';
                   1753:     my $count = scalar(keys(%roles));
                   1754:     while (my ($course,$role) = each(%roles)) {
                   1755:         if ($course=~ /^\/$courseid\/*\s*(\w+)*_st$/ ) {
                   1756:             #
                   1757:             # Get active role
                   1758:             $section=$1;
                   1759:             (undef,$end,$start)=split(/\_/,$role);
                   1760:             my $now=time;
                   1761:             my $notactive=0;
                   1762:             if ($start) {
                   1763:                 if ($now<$start) { $notactive=1; }
                   1764:             }
                   1765:             if ($end) {
                   1766:                 if ($now>$end) { $notactive=1; }
                   1767:             } 
                   1768:             unless ($notactive) { return ($start,$end,$section); }
                   1769:         }
                   1770:     }
                   1771:     return ($start,$end,$section);
                   1772: }
                   1773: 
1.56      matthew  1774: #################################################
                   1775: #################################################
                   1776: 
                   1777: =pod
                   1778: 
                   1779: =item show_drop_list
                   1780: 
                   1781: Display a list of students to drop
                   1782: Inputs: 
                   1783: 
                   1784: =over 4
                   1785: 
                   1786: =item $r, Apache request
                   1787: 
                   1788: =item $classlist, hash pointer returned from loncoursedata::get_classlist();
                   1789: 
                   1790: =item $keylist, array pointer returned from loncoursedata::get_classlist() 
                   1791: which describes the order elements are stored in the %$classlist values.
                   1792: 
                   1793: =item $nosort, if true, sorting links are omitted.
                   1794: 
                   1795: =back
                   1796: 
                   1797: =cut
                   1798: 
                   1799: #################################################
                   1800: #################################################
1.11      www      1801: sub show_drop_list {
1.56      matthew  1802:     my ($r,$classlist,$keylist,$nosort)=@_;
1.11      www      1803:     my $cid=$ENV{'request.course.id'};
1.59      matthew  1804:     if (! exists($ENV{'form.sortby'})) {
                   1805:         &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
                   1806:                                                 ['sortby']);
                   1807:     }
1.54      matthew  1808:     my $sortby = $ENV{'form.sortby'};
1.110     matthew  1809:     if ($sortby !~ /^(username|domain|section|fullname|id|start|end)$/) {
1.54      matthew  1810:         $sortby = 'username';
                   1811:     }
1.56      matthew  1812:     #
1.54      matthew  1813:     my $action = "drop";
                   1814:     $r->print(<<END);
                   1815: <input type="hidden" name="sortby" value="$sortby" />
                   1816: <input type="hidden" name="action" value="$action" />
1.50      matthew  1817: <input type="hidden" name="state"  value="done" />
1.32      matthew  1818: <script>
1.51      matthew  1819: function checkAll(field) {
1.32      matthew  1820:     for (i = 0; i < field.length; i++)
                   1821:         field[i].checked = true ;
                   1822: }
                   1823: 
1.51      matthew  1824: function uncheckAll(field) {
1.32      matthew  1825:     for (i = 0; i < field.length; i++)
                   1826:         field[i].checked = false ;
                   1827: }
                   1828: </script>
                   1829: <p>
1.26      matthew  1830: <input type="hidden" name="phase" value="four">
1.56      matthew  1831: END
                   1832: 
1.110     matthew  1833: my %lt=&Apache::lonlocal::texthash('usrn'   => "username",
                   1834:                                    'dom'    => "domain",
                   1835:                                    'sn'     => "student name",
                   1836:                                    'sec'    => "section",
                   1837:                                    'start'  => "start date",
                   1838:                                    'end'    => "end date",
                   1839:                                    );
1.56      matthew  1840:     if ($nosort) {
                   1841:         $r->print(<<END);
                   1842: <table border=2>
                   1843: <tr>
                   1844:     <th>&nbsp;</th>
1.94      sakharuk 1845:     <th>$lt{'usrn'}</th>
                   1846:     <th>$lt{'dom'}</th>
1.56      matthew  1847:     <th>ID</th>
1.94      sakharuk 1848:     <th>$lt{'sn'}</th>
                   1849:     <th>$lt{'sec'}</th>
1.110     matthew  1850:     <th>$lt{'start'}</th>
                   1851:     <th>$lt{'end'}</th>
1.56      matthew  1852: </tr>
                   1853: END
                   1854: 
                   1855:     } else  {
                   1856:         $r->print(<<END);
1.26      matthew  1857: <table border=2>
1.54      matthew  1858: <tr><th>&nbsp;</th>
                   1859:     <th>
1.94      sakharuk 1860:        <a href="/adm/dropadd?action=$action&sortby=username">$lt{'usrn'}</a>
1.54      matthew  1861:     </th><th>
1.94      sakharuk 1862:        <a href="/adm/dropadd?action=$action&sortby=domain">$lt{'dom'}</a>
1.54      matthew  1863:     </th><th>
                   1864:        <a href="/adm/dropadd?action=$action&sortby=id">ID</a>
                   1865:     </th><th>
1.94      sakharuk 1866:        <a href="/adm/dropadd?action=$action&sortby=fullname">$lt{'sn'}</a>
1.54      matthew  1867:     </th><th>
1.94      sakharuk 1868:        <a href="/adm/dropadd?action=$action&sortby=section">$lt{'sec'}</a>
1.110     matthew  1869:     </th><th>
                   1870:        <a href="/adm/dropadd?action=$action&sortby=start">$lt{'start'}</a>
                   1871:     </th><th>
                   1872:        <a href="/adm/dropadd?action=$action&sortby=end">$lt{'end'}</a>
1.54      matthew  1873:     </th>
                   1874: </tr>
1.26      matthew  1875: END
1.56      matthew  1876:     }
                   1877:     #
                   1878:     # Sort the students
                   1879:     my %index;
                   1880:     my $i;
                   1881:     foreach (@$keylist) {
                   1882:         $index{$_} = $i++;
                   1883:     }
                   1884:     my $index  = $index{$sortby};
                   1885:     my $second = $index{'username'};
                   1886:     my $third  = $index{'domain'};
1.54      matthew  1887:     my @Sorted_Students = sort {
1.56      matthew  1888:         lc($classlist->{$a}->[$index])  cmp lc($classlist->{$b}->[$index])
                   1889:             ||
                   1890:         lc($classlist->{$a}->[$second]) cmp lc($classlist->{$b}->[$second])
                   1891:             ||
                   1892:         lc($classlist->{$a}->[$third]) cmp lc($classlist->{$b}->[$third])
                   1893:         } (keys(%$classlist));
1.54      matthew  1894:     foreach my $student (@Sorted_Students) {
1.52      matthew  1895:         my $error;
1.110     matthew  1896:         my $sdata = $classlist->{$student};
                   1897:         my $username = $sdata->[$index{'username'}];
                   1898:         my $domain   = $sdata->[$index{'domain'}];
                   1899:         my $section  = $sdata->[$index{'section'}];
                   1900:         my $name     = $sdata->[$index{'fullname'}];
                   1901:         my $id       = $sdata->[$index{'id'}];
                   1902:         my $start    = $sdata->[$index{'start'}];
                   1903:         my $end      = $sdata->[$index{'end'}];
                   1904:         if (! defined($start) || $start == 0) {
                   1905:             $start = &mt('none');
                   1906:         } else {
                   1907:             $start = &Apache::lonlocal::locallocaltime($start);
                   1908:         }
                   1909:         if (! defined($end) || $end == 0) {
                   1910:             $end = &mt('none');
                   1911:         } else {
                   1912:             $end = &Apache::lonlocal::locallocaltime($end);
                   1913:         }
                   1914:         my $status   = $sdata->[$index{'status'}];
1.51      matthew  1915:         next if ($status ne 'Active');
                   1916:         #
                   1917:         $r->print(<<"END");
1.26      matthew  1918: <tr>
1.51      matthew  1919:     <td><input type="checkbox" name="droplist" value="$student"></td>
                   1920:     <td>$username</td>
                   1921:     <td>$domain</td>
                   1922:     <td>$id</td>
                   1923:     <td>$name</td>
                   1924:     <td>$section</td>
1.110     matthew  1925:     <td>$start</td>
                   1926:     <td>$end</td>
1.26      matthew  1927: </tr>
                   1928: END
1.25      matthew  1929:     }
                   1930:     $r->print('</table><br>');
1.111     matthew  1931:     %lt=&Apache::lonlocal::texthash(
1.94      sakharuk 1932: 	               'dp'   => "Drop Students",
                   1933:                        'ca'   => "check all",
                   1934:                        'ua'   => "uncheck all",
                   1935: 				       );
1.32      matthew  1936:     $r->print(<<"END");
                   1937: </p><p>
1.94      sakharuk 1938: <input type="button" value="$lt{'ca'}" onclick="javascript:checkAll(document.studentform.droplist)"> &nbsp;
                   1939: <input type="button" value="$lt{'ua'}" onclick="javascript:uncheckAll(document.studentform.droplist)"> 
                   1940: <p><input type=submit value="$lt{'dp'}"></p>
1.32      matthew  1941: END
1.51      matthew  1942:     return;
1.10      www      1943: }
                   1944: 
1.48      matthew  1945: #
                   1946: # Print out the initial form to get the courselist file
                   1947: #
                   1948: sub print_first_courselist_upload_form {
                   1949:     my $r=shift;
1.88      matthew  1950:     my $str;
                   1951:     $str  = '<input type="hidden" name="phase" value="two">';
                   1952:     $str .= '<input type="hidden" name="action" value="upload" />';
                   1953:     $str .= '<input type="hidden"   name="state"  value="got_file" />';
                   1954:     $str .= "<h3>".&mt('Upload a class list')."</h3>\n";
                   1955:     $str .= &Apache::loncommon::upfile_select_html();
                   1956:     $str .= "<p>\n";
                   1957:     $str .= '<input type="submit" name="fileupload" value="'.
                   1958:         &mt('Upload class list').'">'."\n";
                   1959:     $str .= '<input type="checkbox" name="noFirstLine" /> '.
                   1960:         &mt('Ignore First Line')."</p>\n";
                   1961:     $str .= &Apache::loncommon::help_open_topic("Course_Create_Class_List",
1.92      sakharuk 1962:                          &mt("How do I create a class list from a spreadsheet")).
1.88      matthew  1963:                              "<br />\n";
                   1964:     $str .= &Apache::loncommon::help_open_topic("Course_Convert_To_CSV",
1.92      sakharuk 1965:                            &mt("How do I create a CSV file from a spreadsheet")).
1.88      matthew  1966:                                "<br />\n";
                   1967:     $str .= "</body>\n</html>\n";
                   1968:     $r->print($str);
1.48      matthew  1969:     return;
                   1970: }
                   1971: 
1.10      www      1972: # ================================================= Drop/Add from uploaded file
                   1973: sub upfile_drop_add {
                   1974:     my $r=shift;
1.24      albertel 1975:     &Apache::loncommon::load_tmp_file($r);
                   1976:     my @studentdata=&Apache::loncommon::upfile_record_sep();
1.82      www      1977:     if($ENV{'form.noFirstLine'}){shift(@studentdata);}
1.26      matthew  1978:     my @keyfields = split(/\,/,$ENV{'form.keyfields'});
                   1979:     my $cid = $ENV{'request.course.id'};
1.25      matthew  1980:     my %fields=();
1.26      matthew  1981:     for (my $i=0; $i<=$ENV{'form.nfields'}; $i++) {
1.25      matthew  1982:         if ($ENV{'form.upfile_associate'} eq 'reverse') {
                   1983:             if ($ENV{'form.f'.$i} ne 'none') {
                   1984:                 $fields{$keyfields[$i]}=$ENV{'form.f'.$i};
                   1985:             }
                   1986:         } else {
                   1987:             $fields{$ENV{'form.f'.$i}}=$keyfields[$i];
                   1988:         }
                   1989:     }
1.99      matthew  1990:     #
                   1991:     # Store the field choices away
                   1992:     foreach my $field (qw/username names 
                   1993:                        fname mname lname gen id sec ipwd email/) {
                   1994:         $ENV{'form.'.$field.'_choice'}=$fields{$field};
                   1995:     }
                   1996:     &Apache::loncommon::store_course_settings('enrollment_upload',
                   1997:                                               { 'username_choice' => 'scalar',
                   1998:                                                 'names_choice' => 'scalar',
                   1999:                                                 'fname_choice' => 'scalar',
                   2000:                                                 'mname_choice' => 'scalar',
                   2001:                                                 'lname_choice' => 'scalar',
                   2002:                                                 'gen_choice' => 'scalar',
                   2003:                                                 'id_choice' => 'scalar',
                   2004:                                                 'sec_choice' => 'scalar',
                   2005:                                                 'ipwd_choice' => 'scalar',
                   2006:                                                 'email_choice' => 'scalar' });
                   2007: 
1.26      matthew  2008:     #
1.68      matthew  2009:     my ($startdate,$enddate) = &get_dates_from_form();
                   2010:     if ($ENV{'form.makedatesdefault'}) {
                   2011:         $r->print(&make_dates_default($startdate,$enddate));
                   2012:     }
1.31      matthew  2013:     # Determine domain and desired host (home server)
1.25      matthew  2014:     my $domain=$ENV{'form.lcdomain'};
1.31      matthew  2015:     my $desiredhost = $ENV{'form.lcserver'};
                   2016:     if (lc($desiredhost) eq 'default') {
                   2017:         $desiredhost = undef;
                   2018:     } else {
1.45      matthew  2019:         my %home_servers = &Apache::loncommon::get_library_servers($domain);
1.31      matthew  2020:         if (! exists($home_servers{$desiredhost})) {
1.88      matthew  2021:             $r->print('<font color="#ff0000">'.&mt('Error').'</font>'.
                   2022:                       &mt('Invalid home server specified'));
                   2023:             $r->print("</body>\n</html>\n");
1.31      matthew  2024:             return;
                   2025:         }
                   2026:     }
1.26      matthew  2027:     # Determine authentication mechanism
                   2028:     my $amode  = '';
                   2029:     my $genpwd = '';
1.25      matthew  2030:     if ($ENV{'form.login'} eq 'krb') {
1.47      albertel 2031:         $amode='krb';
                   2032: 	$amode.=$ENV{'form.krbver'};
1.28      matthew  2033:         $genpwd=$ENV{'form.krbarg'};
1.25      matthew  2034:     } elsif ($ENV{'form.login'} eq 'int') {
                   2035:         $amode='internal';
1.28      matthew  2036:         if ((defined($ENV{'form.intarg'})) && ($ENV{'form.intarg'})) {
                   2037:             $genpwd=$ENV{'form.intarg'};
1.25      matthew  2038:         }
                   2039:     } elsif ($ENV{'form.login'} eq 'loc') {
                   2040:         $amode='localauth';
                   2041:         if ((defined($ENV{'form.locarg'})) && ($ENV{'form.locarg'})) {
                   2042:             $genpwd=$ENV{'form.locarg'};
1.79      matthew  2043:         }
                   2044:     }
                   2045:     if ($amode =~ /^krb/) {
                   2046:         if (! defined($genpwd) || $genpwd eq '') {
                   2047:             $r->print('<font color="red" size="+1">'.
1.88      matthew  2048:                       &mt('Unable to enroll students').'</font>  '.
                   2049:                       &mt('No Kerberos domain was specified.').'</p>');
1.79      matthew  2050:             $amode = ''; # This causes the loop below to be skipped
1.25      matthew  2051:         }
                   2052:     }
                   2053:     unless (($domain=~/\W/) || ($amode eq '')) {
1.26      matthew  2054:         #######################################
                   2055:         ##         Enroll Students           ##
                   2056:         #######################################
1.88      matthew  2057:         $r->print('<h3>'.&mt('Enrolling Students')."</h3>\n<p>\n");
1.25      matthew  2058:         my $count=0;
                   2059:         my $flushc=0;
                   2060:         my %student=();
1.26      matthew  2061:         # Get new classlist
1.25      matthew  2062:         foreach (@studentdata) {
                   2063:             my %entries=&Apache::loncommon::record_sep($_);
1.26      matthew  2064:             # Determine student name
1.25      matthew  2065:             unless (($entries{$fields{'username'}} eq '') ||
                   2066:                     (!defined($entries{$fields{'username'}}))) {
1.26      matthew  2067:                 my ($fname, $mname, $lname,$gen) = ('','','','');
1.25      matthew  2068:                 if (defined($fields{'names'})) {
1.26      matthew  2069:                     ($lname,$fname,$mname)=($entries{$fields{'names'}}=~
                   2070:                                             /([^\,]+)\,\s*(\w+)\s*(.*)$/);
1.25      matthew  2071:                 } else {
                   2072:                     if (defined($fields{'fname'})) {
                   2073:                         $fname=$entries{$fields{'fname'}};
                   2074:                     }
                   2075:                     if (defined($fields{'mname'})) {
                   2076:                         $mname=$entries{$fields{'mname'}};
                   2077:                     }
                   2078:                     if (defined($fields{'lname'})) {
                   2079:                         $lname=$entries{$fields{'lname'}};
                   2080:                     }
                   2081:                     if (defined($fields{'gen'})) {
                   2082:                         $gen=$entries{$fields{'gen'}};
                   2083:                     }
                   2084:                 }
                   2085:                 if ($entries{$fields{'username'}}=~/\W/) {
1.88      matthew  2086:                     $r->print('<br />'.
                   2087:       &mt('<b>[_1]</b>: Unacceptable username for user [_2] [_3] [_4] [_5]',
                   2088:           $entries{$fields{'username'}},$fname,$mname,$lname,$gen).
                   2089:                               '</b>');
1.25      matthew  2090:                 } else {
1.26      matthew  2091:                     # determine section number
1.25      matthew  2092:                     my $sec='';
                   2093:                     my $username=$entries{$fields{'username'}};
                   2094:                     if (defined($fields{'sec'})) {
                   2095:                         if (defined($entries{$fields{'sec'}})) {
                   2096:                             $sec=$entries{$fields{'sec'}};
                   2097:                         }
                   2098:                     }
1.80      matthew  2099:                     # remove non alphanumeric values from section
                   2100:                     $sec =~ s/\W//g;
1.26      matthew  2101:                     # determine student id number
1.25      matthew  2102:                     my $id='';
                   2103:                     if (defined($fields{'id'})) {
                   2104:                         if (defined($entries{$fields{'id'}})) {
                   2105:                             $id=$entries{$fields{'id'}};
                   2106:                         }
                   2107:                         $id=~tr/A-Z/a-z/;
                   2108:                     }
1.73      www      2109:                     # determine email address
                   2110:                     my $email='';
                   2111:                     if (defined($fields{'email'})) {
                   2112:                         if (defined($entries{$fields{'email'}})) {
                   2113:                             $email=$entries{$fields{'email'}};
                   2114:                             unless ($email=~/^[^\@]+\@[^\@]+$/) { $email=''; }
                   2115:                         }
                   2116:                     }
1.26      matthew  2117:                     # determine student password
1.25      matthew  2118:                     my $password='';
                   2119:                     if ($genpwd) { 
                   2120:                         $password=$genpwd; 
                   2121:                     } else {
                   2122:                         if (defined($fields{'ipwd'})) {
                   2123:                             if ($entries{$fields{'ipwd'}}) {
                   2124:                                 $password=$entries{$fields{'ipwd'}};
                   2125:                             }
                   2126:                         }
                   2127:                     }
1.56      matthew  2128:                     # Clean up whitespace
                   2129:                     foreach (\$domain,\$username,\$id,\$fname,\$mname,
                   2130:                              \$lname,\$gen,\$sec) {
                   2131:                         $$_ =~ s/(\s+$|^\s+)//g;
                   2132:                     }
1.84      albertel 2133:                     if ($password || $ENV{'form.login'} eq 'loc') {
1.33      matthew  2134:                         &modifystudent($domain,$username,$cid,$sec,
                   2135:                                        $desiredhost);
1.25      matthew  2136:                         my $reply=&Apache::lonnet::modifystudent
                   2137:                             ($domain,$username,$id,$amode,$password,
                   2138:                              $fname,$mname,$lname,$gen,$sec,$enddate,
1.73      www      2139:                              $startdate,$ENV{'form.forceid'},$desiredhost,
                   2140:                              $email);
1.26      matthew  2141:                         if ($reply ne 'ok') {
1.72      matthew  2142:                             $reply =~ s/^error://;
1.88      matthew  2143:                             $r->print('<br />'.
                   2144:                 &mt('<b>[_1]</b>:  Unable to enroll: [_2]',$username,$reply));
1.10      www      2145:          		} else {
1.7       www      2146:                             $count++; $flushc++;
                   2147:                             $student{$username}=1;
1.6       www      2148:                             $r->print('. ');
1.7       www      2149:                             if ($flushc>15) {
                   2150: 				$r->rflush;
                   2151:                                 $flushc=0;
                   2152:                             }
1.6       www      2153:                         }
1.25      matthew  2154:                     } else {
1.88      matthew  2155:                         $r->print('<br />'.
                   2156:       &mt('<b>[_1]</b>: Unable to enroll.  No password specified.',$username)
                   2157:                                   );
1.25      matthew  2158:                     }
                   2159:                 }
1.26      matthew  2160:             }
                   2161:         } # end of foreach (@studentdata)
1.88      matthew  2162:         $r->print("</p>\n<p>\n".&mt('Processed [_1] student(s).',$count).
                   2163:                   "</p>\n");
                   2164:         $r->print("<p>\n".
                   2165:                   &mt('If active, the new role will be available when the '.
                   2166:                   'students next log in to LON-CAPA.')."</p>\n");
1.26      matthew  2167:         #####################################
                   2168:         #           Drop students           #
                   2169:         #####################################
1.25      matthew  2170:         if ($ENV{'form.fullup'} eq 'yes') {
1.88      matthew  2171:             $r->print('<h3>'.&mt('Dropping Students')."</h3>\n");
1.26      matthew  2172:             #  Get current classlist
1.56      matthew  2173:             my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist();
                   2174:             if (! defined($classlist)) {
1.88      matthew  2175:                 $r->print(&mt('There are no students currently enrolled.').
                   2176:                           "\n");
1.56      matthew  2177:             } else {
                   2178:                 # Remove the students we just added from the list of students.
1.25      matthew  2179:                 foreach (@studentdata) {
                   2180:                     my %entries=&Apache::loncommon::record_sep($_);
                   2181:                     unless (($entries{$fields{'username'}} eq '') ||
                   2182:                             (!defined($entries{$fields{'username'}}))) {
1.56      matthew  2183:                         delete($classlist->{$entries{$fields{'username'}}.
1.26      matthew  2184:                                                 ':'.$domain});
1.25      matthew  2185:                     }
                   2186:                 }
1.56      matthew  2187:                 # Print out list of dropped students.
                   2188:                 &show_drop_list($r,$classlist,$keylist,'nosort');
1.25      matthew  2189:             }
                   2190:         }
1.26      matthew  2191:     } # end of unless
1.10      www      2192: }
                   2193: 
1.11      www      2194: # ================================================================== Phase four
                   2195: sub drop_student_list {
                   2196:     my $r=shift;
                   2197:     my $count=0;
1.35      matthew  2198:     my @droplist;
                   2199:     if (ref($ENV{'form.droplist'})) {
                   2200:         @droplist = @{$ENV{'form.droplist'}};
                   2201:     } else {
                   2202:         @droplist = ($ENV{'form.droplist'});
                   2203:     }
                   2204:     foreach (@droplist) {
1.26      matthew  2205:         my ($uname,$udom)=split(/\:/,$_);
1.56      matthew  2206:         # drop student
1.35      matthew  2207:         my $result = &modifystudent($udom,$uname,$ENV{'request.course.id'});
1.37      matthew  2208:         if ($result eq 'ok' || $result eq 'ok:') {
1.88      matthew  2209:             $r->print(&mt('Dropped [_1]',$uname.'@'.$udom).'<br>');
1.59      matthew  2210:             $count++;
1.35      matthew  2211:         } else {
1.88      matthew  2212:             $r->print(
                   2213:           &mt('Error dropping [_1]:[_2]',$uname.'@'.$udom,$result).
1.35      matthew  2214:                       '<br />');
                   2215:         }
1.20      harris41 2216:     }
1.88      matthew  2217:     $r->print('<p><b>'.&mt('Dropped [_1] student(s).',$count).'</b></p>');
                   2218:     $r->print('<p>'.&mt('Re-enrollment will re-activate data.')) if ($count);
1.11      www      2219: }
                   2220: 
1.50      matthew  2221: ###################################################################
                   2222: ###################################################################
                   2223: 
                   2224: =pod
                   2225: 
                   2226: =item &handler
                   2227: 
                   2228: The typical handler you see in all these modules.  Takes $r, the
                   2229: http request, as an argument.  
                   2230: 
                   2231: The response to the request is governed by two form variables
                   2232: 
                   2233:  form.action      form.state     response
                   2234:  ---------------------------------------------------
                   2235:  undefined        undefined      print main menu
                   2236:  upload           undefined      print courselist upload menu
                   2237:  upload           got_file       deal with uploaded file,
                   2238:                                  print the upload managing menu
                   2239:  upload           enrolling      enroll students based on upload
                   2240:  drop             undefined      print the classlist ready to drop
                   2241:  drop             done           drop the selected students
1.74      matthew  2242:  enrollstudent    undefined      print student username domain form
                   2243:  enrollstudent    gotusername    print single student enroll menu
1.50      matthew  2244:  enrollstudent    enrolling      enroll student
                   2245:  classlist        undefined      print html classlist
                   2246:  classlist        csv            print csv classlist
                   2247:  modifystudent    undefined      print classlist to select student to modify
                   2248:  modifystudent    selected       print modify student menu
                   2249:  modifystudent    done           make modifications to student record
                   2250: 
                   2251: =cut
                   2252: 
                   2253: ###################################################################
                   2254: ###################################################################
1.10      www      2255: sub handler {
1.26      matthew  2256:     my $r=shift;
                   2257:     if ($r->header_only) {
1.86      www      2258:         &Apache::loncommon::content_type($r,'text/html');
1.26      matthew  2259:         $r->send_http_header;
                   2260:         return OK;
                   2261:     }
1.48      matthew  2262:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.50      matthew  2263:                                             ['action','state']);
1.102     matthew  2264: 
                   2265:     &Apache::lonhtmlcommon::clear_breadcrumbs();
                   2266:     &Apache::lonhtmlcommon::add_breadcrumb
                   2267:         ({href=>"/adm/dropadd",
                   2268:           text=>"Enrollment Manager",
                   2269:           faq=>9,bug=>'Instructor Interface',});
1.26      matthew  2270:     #  Needs to be in a course
1.50      matthew  2271:     if (! (($ENV{'request.course.fn'}) &&
                   2272:           (&Apache::lonnet::allowed('cst',$ENV{'request.course.id'})))) {
                   2273:         # Not in a course, or not allowed to modify parms
                   2274:         $ENV{'user.error.msg'}=
                   2275:             "/adm/dropadd:cst:0:0:Cannot drop or add students";
                   2276:         return HTTP_NOT_ACCEPTABLE; 
                   2277:     }
                   2278:     #
                   2279:     # Only output the header information if they did not request csv format
                   2280:     #
1.102     matthew  2281:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
                   2282:                                             ['state','action']);
1.103     matthew  2283:     # Start page
                   2284:     &Apache::loncommon::content_type($r,'text/html');
                   2285:     $r->send_http_header;
                   2286:     $r->print(&header());
1.50      matthew  2287:     #
                   2288:     # Main switch on form.action and form.state, as appropriate
                   2289:     if (! exists($ENV{'form.action'})) {
1.102     matthew  2290:         $r->print(&Apache::lonhtmlcommon::breadcrumbs
                   2291:                   (undef,'Enrollment Manager'));
1.50      matthew  2292:         &print_main_menu($r);
                   2293:     } elsif ($ENV{'form.action'} eq 'upload') {
1.102     matthew  2294:         &Apache::lonhtmlcommon::add_breadcrumb
                   2295:             ({href=>'/adm/dropadd?action=upload&state=',
1.106     matthew  2296:               text=>"Upload Classlist"});
1.102     matthew  2297:         $r->print(&Apache::lonhtmlcommon::breadcrumbs
1.117     albertel 2298:                   (undef,'Upload Classlist','Course_Create_Class_List'));
1.50      matthew  2299:         if (! exists($ENV{'form.state'})) {
                   2300:             &print_first_courselist_upload_form($r);            
                   2301:         } elsif ($ENV{'form.state'} eq 'got_file') {
                   2302:             &print_upload_manager_form($r);
                   2303:         } elsif ($ENV{'form.state'} eq 'enrolling') {
1.26      matthew  2304:             if ($ENV{'form.datatoken'}) {
                   2305:                 &upfile_drop_add($r);
1.50      matthew  2306:             } else {
                   2307:                 # Hmmm, this is an error
1.26      matthew  2308:             }
1.50      matthew  2309:         } else {
                   2310:             &print_first_courselist_upload_form($r);            
1.26      matthew  2311:         }
1.50      matthew  2312:     } elsif ($ENV{'form.action'} eq 'drop') {
1.102     matthew  2313:         &Apache::lonhtmlcommon::add_breadcrumb
                   2314:             ({href=>'/adm/dropadd?action=drop',
1.106     matthew  2315:               text=>"Drop Students"});
1.102     matthew  2316:         $r->print(&Apache::lonhtmlcommon::breadcrumbs
1.117     albertel 2317:                   (undef,'Drop Students','Course_Drop_Student'));
1.50      matthew  2318:         if (! exists($ENV{'form.state'})) {
1.51      matthew  2319:             &print_drop_menu($r);
1.50      matthew  2320:         } elsif ($ENV{'form.state'} eq 'done') {
1.26      matthew  2321:             &drop_student_list($r);
1.50      matthew  2322:         } else {
1.55      matthew  2323:             &print_drop_menu($r);
1.26      matthew  2324:         }
1.50      matthew  2325:     } elsif ($ENV{'form.action'} eq 'enrollstudent') {
1.102     matthew  2326:         &Apache::lonhtmlcommon::add_breadcrumb
                   2327:             ({href=>'/adm/dropadd?action=enrollstudent',
1.106     matthew  2328:               text=>"Enroll Student"});
1.102     matthew  2329:         $r->print(&Apache::lonhtmlcommon::breadcrumbs
1.117     albertel 2330:                   (undef,'Enroll Student','Course_Add_Student'));
1.50      matthew  2331:         if (! exists($ENV{'form.state'})) {
1.74      matthew  2332:             &get_student_username_domain_form($r);
                   2333:         } elsif ($ENV{'form.state'} eq 'gotusername') {
1.50      matthew  2334:             &print_enroll_single_student_form($r);
                   2335:         } elsif ($ENV{'form.state'} eq 'enrolling') {
1.26      matthew  2336:             &enroll_single_student($r);
1.50      matthew  2337:         } else {
1.74      matthew  2338:             &get_student_username_domain_form($r);
1.26      matthew  2339:         }
1.50      matthew  2340:     } elsif ($ENV{'form.action'} eq 'classlist') {
1.102     matthew  2341:         &Apache::lonhtmlcommon::add_breadcrumb
                   2342:             ({href=>'/adm/dropadd?action=classlist',
1.106     matthew  2343:               text=>"View Classlist"});
1.102     matthew  2344:         $r->print(&Apache::lonhtmlcommon::breadcrumbs
1.117     albertel 2345:                   (undef,'View Classlist','Course_View_Class_List'));
1.50      matthew  2346:         if (! exists($ENV{'form.state'})) {
1.103     matthew  2347:             &print_html_classlist($r,undef);
1.50      matthew  2348:         } elsif ($ENV{'form.state'} eq 'csv') {
1.103     matthew  2349:             &print_html_classlist($r,'csv');
1.60      matthew  2350:         } elsif ($ENV{'form.state'} eq 'excel') {
1.103     matthew  2351:             &print_html_classlist($r,'excel');
1.50      matthew  2352:         } else {
1.103     matthew  2353:             &print_html_classlist($r,undef);
1.50      matthew  2354:         }
                   2355:     } elsif ($ENV{'form.action'} eq 'modifystudent') {
1.102     matthew  2356:         &Apache::lonhtmlcommon::add_breadcrumb
                   2357:             ({href=>'/adm/dropadd?action=modifystudent',
1.106     matthew  2358:               text=>"Modify Student Data"});
1.102     matthew  2359:         $r->print(&Apache::lonhtmlcommon::breadcrumbs
1.117     albertel 2360:                   (undef,'Modify Student Data','Course_Modify_Student_Data'));
1.50      matthew  2361:         if (! exists($ENV{'form.state'})) {
                   2362:             &print_html_classlist($r);
                   2363:         } elsif ($ENV{'form.state'} eq 'selected') {
                   2364:             &print_modify_student_form($r);
                   2365:         } elsif ($ENV{'form.state'} eq 'done') {
                   2366:             &modify_single_student($r);
                   2367:         } else {
                   2368:             &print_html_classlist($r);
                   2369:         }        
                   2370:     } else {
                   2371:         # We should not end up here, but I guess it is possible
                   2372:         &Apache::lonnet::logthis("Undetermined state in londropadd.pm.  ".
                   2373:                                  "form.action = ".$ENV{'form.action'}.
                   2374:                                  "Someone should fix this.");
1.102     matthew  2375:         $r->print(&Apache::lonhtmlcommon::breadcrumbs
                   2376:                   (undef,'Enrollment Manager'));
1.50      matthew  2377:         &print_main_menu($r);
                   2378:     }
                   2379:     #
                   2380:     # Finish up
1.103     matthew  2381:     $r->print('</form></body></html>');
1.26      matthew  2382:     return OK;
1.1       www      2383: }
                   2384: 
1.50      matthew  2385: ###################################################################
                   2386: ###################################################################
                   2387: 
1.1       www      2388: 1;
                   2389: __END__
1.50      matthew  2390: 
1.1       www      2391: 

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