Annotation of loncom/enrollment/Enrollment.pm, revision 1.7

1.7     ! albertel    1: # Automated Enrollment manager
        !             2: # $Id: gplheader.pl,v 1.1 2001/11/29 18:19:27 www Exp $
        !             3: #
        !             4: # Copyright Michigan State University Board of Trustees
        !             5: #
        !             6: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
        !             7: #
        !             8: # LON-CAPA is free software; you can redistribute it and/or modify
        !             9: # it under the terms of the GNU General Public License as published by
        !            10: # the Free Software Foundation; either version 2 of the License, or
        !            11: # (at your option) any later version.
        !            12: #
        !            13: # LON-CAPA is distributed in the hope that it will be useful,
        !            14: # but WITHOUT ANY WARRANTY; without even the implied warranty of
        !            15: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        !            16: # GNU General Public License for more details.
        !            17: #
        !            18: # You should have received a copy of the GNU General Public License
        !            19: # along with LON-CAPA; if not, write to the Free Software
        !            20: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
        !            21: #
        !            22: # /home/httpd/html/adm/gpl.txt
        !            23: #
        !            24: # http://www.lon-capa.org/
        !            25: #
1.1       raeburn    26: package LONCAPA::Enrollment;
                     27: 
                     28: use Apache::loncoursedata;
                     29: use Apache::lonnet;
                     30: use HTML::Entities;
                     31: use LONCAPA::Configuration;
                     32: 
                     33: use strict;
                     34: 
                     35: sub update_LC {
                     36:     my ($dom,$crs,$adds,$drops,$startdate,$enddate,$authtype,$autharg,$classesref,$groupref,$logmsg,$context) = @_; 
                     37: # Get current LON-CAPA student enrollment for this class
                     38:     my $configvars = &LONCAPA::Configuration::read_conf('loncapa.conf');
                     39:     my $cid = $dom."_".$crs;
                     40:     my $roster = &Apache::loncoursedata::get_classlist($cid,$dom,$crs);
                     41:     my $cend = &Apache::loncoursedata::CL_END;
                     42:     my $cstart = &Apache::loncoursedata::CL_START; 
                     43:     my $stuid=&Apache::loncoursedata::CL_ID;
                     44:     my $sec=&Apache::loncoursedata::CL_SECTION;
                     45:     my $status=&Apache::loncoursedata::CL_STATUS;
                     46:     my $type=&Apache::loncoursedata::CL_TYPE;
                     47:     my @localstudents = ();
                     48:     my $currlist;
                     49:     foreach my $uname (keys %{$roster} ) {
                     50:         if ($uname =~ m/^(.+):$dom$/) {
                     51:             if ($$roster{$uname}[$status] eq "Active") {
                     52:                 push @localstudents, $1;
                     53:                 @{$$currlist{$1}} = @{$$roster{$uname}};
                     54:             }
                     55:         }
                     56:     }
                     57:     my $linefeed = '';
                     58:     my $addresult = '';
                     59:     my $dropresult = '';
                     60:     if ($context eq "updatenow") {
                     61:         $linefeed = "</li>\n<li>"; 
                     62:     } elsif ($context eq "automated") {
                     63:         $linefeed = "\n";
                     64:     }
                     65:     my $enrollcount = 0;
                     66:     my $dropcount = 0;
                     67: 
                     68: # Get mapping of IDs to usernames for current LON-CAPA student enrollment for this class 
                     69:     my @LCids = ();
                     70:     my %unameFromLCid = ();
                     71:     foreach my $uname (sort keys %{$currlist}) {
                     72:         my $stuID = $$currlist{$uname}[$stuid];
                     73:         if (!grep/^$stuID$/,@LCids) {
                     74:             push @LCids, $stuID;
                     75:             @{$unameFromLCid{$stuID}} = ();
                     76:         }
                     77:         push @{$unameFromLCid{$stuID}},$uname;
                     78:     }
                     79:  
                     80: # Get latest institutional enrollment for this class.
                     81:     my %allenrolled = ();
                     82:     my @reg_students = ();
                     83:     my %place = ();
                     84:     $place{'autharg'} = &CL_autharg();
                     85:     $place{'authtype'} = &CL_authtype();
                     86:     $place{'email'} = &CL_email();
                     87:     $place{'enddate'} = &CL_enddate();
                     88:     $place{'firstname'} = &CL_firstname();
                     89:     $place{'generation'} = &CL_generation();
                     90:     $place{'groupID'} = &CL_groupID();
                     91:     $place{'lastname'} = &CL_lastname();
                     92:     $place{'middlename'} = &CL_middlename();
                     93:     $place{'startdate'} = &CL_startdate();
                     94:     $place{'studentID'} = &CL_studentID();
                     95:     my %ucount = ();
                     96:     my %enrollinfo = ();
                     97:     foreach my $class (@{$classesref}) {
                     98:         my %enrolled = ();
                     99:         &parse_classlist($$configvars{'lonDaemons'},$dom,$crs,$class,\%place,$$groupref{$class},\%enrolled);
                    100:         foreach my $uname (sort keys %enrolled ) {
                    101:             if (!grep/^$uname$/,@reg_students) {
                    102:                 push @reg_students,$uname;
                    103:                 $ucount{$uname} = 0;
                    104:                 @{$allenrolled{$uname}} = ();
                    105:             }
                    106:             @{$allenrolled{$uname}[$ucount{$uname}]} = @{$enrolled{$uname}};
                    107:             $ucount{$uname} ++;
                    108:         }
                    109:     }
                    110: 
                    111: # Check for multiple sections for a single student 
                    112:     my @okusers = ();
                    113:     foreach my $uname (@reg_students)  {
                    114:         if (@{$allenrolled{$uname}} > 1) {
                    115:             my @sections = ();
                    116:             my $saved;
                    117:             for (my $i=0; $i<@{$allenrolled{$uname}}; $i++) {
                    118:                 my @stuinfo = @{$allenrolled{$uname}[$i]};
                    119:                 my $secnum = $stuinfo[ $place{'groupID'} ];
                    120:                 unless ($secnum eq '') {
                    121:                     unless (grep/^$secnum$/,@sections) {
                    122:                         $saved = $i; 
                    123:                         push @sections,$secnum;
                    124:                     }
                    125:                 }
                    126:             }
                    127:             if (@sections == 0) {
                    128:                 @{$enrollinfo{$uname}} = @{$allenrolled{$uname}[0]};
                    129:                 push @okusers, $uname;
                    130:             }
                    131:             elsif (@sections == 1) {
                    132:                 @{$enrollinfo{$uname}} = @{$allenrolled{$uname}[$saved]};
                    133:                 push @okusers, $uname;
                    134:             }
                    135:             elsif (@sections > 1) {
1.5       raeburn   136:                 $$logmsg =  "$uname appears in classlists for the more than one section of this course, i.e. in sections: ";
1.1       raeburn   137:                 foreach (@sections) {
1.5       raeburn   138:                     $$logmsg .= " $_,";
1.1       raeburn   139:                 }
1.5       raeburn   140:                 chop($$logmsg);
1.6       raeburn   141:                 $$logmsg .= ". Because of this ambiguity, no enrollment action was taken for this student.".$linefeed;
1.1       raeburn   142:             }
                    143:         } else {
                    144:             @{$enrollinfo{$uname}} = @{$allenrolled{$uname}[0]};
                    145:             push @okusers, $uname;
                    146:         }
                    147:     }
                    148: # Get mapping of student IDs to usernames for users in institutional data for this class  
                    149:     my @allINids = ();
1.3       raeburn   150:     my %unameFromINid = ();
1.1       raeburn   151:     foreach my $uname (@okusers) {
                    152:         $enrollinfo{$uname}[ $place{'studentID'} ] =~ tr/A-Z/a-z/;
                    153:         my $stuID = $enrollinfo{$uname}[ $place{'studentID'} ];
                    154:         if (grep/^$stuID$/,@allINids)  {
                    155:             push @{$unameFromINid{$stuID}},$uname;
                    156:         } else {
                    157:             push @allINids, $stuID;
                    158:             @{$unameFromINid{$stuID}} = $uname; 
                    159:         }
                    160:     }
1.5       raeburn   161: # Explicitly allow access to creation/modification of students if called as an automated process.
                    162:     if ($context eq 'automated') {
                    163:         $ENV{'allowed.cst'}='F';
                    164:     }
                    165: 
1.1       raeburn   166: # Compare IDs with existing LON-CAPA enrollment for this class
                    167:     foreach my $uname (@okusers) {
1.5       raeburn   168:         unless ($uname eq '') {
                    169:             my %uidhash=&Apache::lonnet::idrget($dom,$uname);
                    170:             my @stuinfo = @{$enrollinfo{$uname}};
                    171:             if (grep/^$uname$/,@localstudents) {
1.1       raeburn   172: # Check for studentID changes
1.5       raeburn   173:                 if ( ($uidhash{$uname}) && ($uidhash{$uname} !~ /error\:/) )  {
                    174:                     unless ( ($uidhash{$uname}) eq ($stuinfo[ $place{studentID} ]) ) {
1.6       raeburn   175:                         $$logmsg .= "Change in ID for $uname. StudentID in LON-CAPA system is $uidhash{$uname}; StudentID in institutional data is $stuinfo[ $place{studentID} ]".$linefeed; 
1.5       raeburn   176:                     }
1.1       raeburn   177:                 }
                    178: 
                    179: # Check for section changes
1.5       raeburn   180:                 unless ($$currlist{$uname}[$sec] eq $stuinfo[ $place{groupID} ]) {
                    181:                     if ( ($$currlist{$uname}[$type] eq "auto") && ($adds == 1) ) {
                    182:                         my $modify_section_result = &Apache::lonnet::modify_student_enrollment($dom,$uname,undef,undef,undef,undef,undef,$stuinfo[ $place{groupID} ],$$currlist{$uname}[$cend],$$currlist{$uname}[$cstart],'auto',$cid);
                    183:                         if ($modify_section_result =~ /^ok/) {
1.6       raeburn   184:                             $$logmsg .= "Section for $uname switched from old section: ".$$currlist{$uname}[$sec] ." to new section: ".$stuinfo[ $place{groupID} ].".".$linefeed;
1.5       raeburn   185:                         } else {
                    186:                             $$logmsg .= "Error when attempting section change for $uname from old section ".$$currlist{$uname}[$sec]." to new section: ".$stuinfo[ $place{groupID} ]." -error: $modify_section_result".$linefeed;
                    187:                         }
1.1       raeburn   188:                     }
                    189:                 }
1.5       raeburn   190:             } else {
1.1       raeburn   191: # Check for changed usernames by checking studentIDs
1.5       raeburn   192:                 if ( ($stuinfo[ $place{studentID} ] ne '') && (grep/^$stuinfo[ $place{studentID} ]$/,@LCids) ) {
                    193:                     if (grep/^$$currlist{$uname}[ $place{'studentID'} ]$/,@allINids) {
                    194:                         foreach my $match ( @{ $unameFromLCid{ $stuinfo[ $place{studentID} ] } }  ) {
                    195:                             if (grep/^$match$/,@okusers) {
1.6       raeburn   196:                                 $$logmsg .= "A possible change in username has been detected for a student enrolled in this course. The existing LON-CAPA classlist contains user: $uname and student ID: ".$$currlist{$uname}[ $place{studentID} ].".  This username has been dropped from the institutional classlist, but the same student ID is used for user: $match who still appears in the institutional classlist. You may need to contact your Domain Coordinator to request a move of the student data files for user: $uname to $match".$linefeed;
1.5       raeburn   197:                             }
1.1       raeburn   198:                         }
                    199:                     }
1.5       raeburn   200:                 } elsif ($adds == 1) {
1.1       raeburn   201: # Add student to LON-CAPA classlist
1.5       raeburn   202:                     my $auth = $stuinfo[ $place{'authtype'} ];
                    203:                     my $authparam = $stuinfo[ $place{'autharg'} ];
                    204:                     my $first = $stuinfo[ $place{'firstname'} ];
                    205:                     my $middle = $stuinfo[ $place{'middlename'} ];
                    206:                     my $last = $stuinfo[ $place{'lastname'} ];
                    207:                     my $gene = $stuinfo[ $place{'generation'} ];
                    208:                     my $usec = $stuinfo[ $place{'groupID'} ];
                    209:                     my $end = $stuinfo[ $place{'enddate'} ];
                    210:                     my $start = $stuinfo[ $place{'startdate'} ];
                    211:                     my $emailaddr = $stuinfo[ $place{'email'} ];
                    212:                     my $pid = $stuinfo[ $place{'studentID'} ];
1.1       raeburn   213: 
                    214: # remove non alphanumeric values from section
1.5       raeburn   215:                     $usec =~ s/\W//g;
1.1       raeburn   216: 
1.5       raeburn   217:                     unless ($emailaddr =~/^[^\@]+\@[^\@]+$/) { $emailaddr =''; }
                    218:                     my $emailenc = &HTML::Entities::encode($emailaddr); 
1.1       raeburn   219: 
                    220: # Use course defaults where entry is absent
1.5       raeburn   221:                     if ( ($auth eq '') || (!defined($auth)) ) {
                    222:                         $auth =  $authtype;
                    223:                     }
                    224:                     if ( ($authparam eq '')  || (!defined($authparam)) )  {
                    225:                         $authparam = $autharg;
                    226:                     }
                    227:                     if ($auth =~ m/^krb/) {
                    228:                         $auth .= ":".$authparam;
                    229:                     }
                    230:                     if ( ($end eq '') || (!defined($end)) )  {
                    231:                          $end = $enddate;
                    232:                     }
                    233:                     if ( ($start eq '')  || (!defined($start)) )  {
                    234:                          $start = $startdate;
                    235:                     }
1.1       raeburn   236: # Clean up whitespace
1.5       raeburn   237:                     foreach (\$dom,\$uname,\$pid,\$first,\$middle,\$last,\$gene,\$usec) {
                    238:                          $$_ =~ s/(\s+$|^\s+)//g;
                    239:                     }
1.1       raeburn   240: 
                    241: # Check for existing account in this LON-CAPA domain for this username
1.5       raeburn   242:                     my $uhome=&Apache::lonnet::homeserver($uname,$dom);
                    243:                     if ($uhome eq 'no_host') { # User does not exist
                    244:                         my $create_passwd = 0;
                    245:                         my $authchk = '';
                    246:                         unless ($authparam eq '') { $authchk = 'ok'; };
1.1       raeburn   247: # If no account exists and passwords should be generated
1.5       raeburn   248:                         if ($authtype eq "int") {
                    249:                             if ($authparam eq '') {
                    250:                                 ($authparam,$create_passwd,$authchk) = &create_password();
                    251:                             }
                    252:                         } elsif ($authtype eq "local") {
                    253:                             if ($authparam eq '') {
                    254:                                 ($authparam,$create_passwd,$authchk) = &create_password();
                    255:                             }
                    256:                         } elsif ($authtype =~ m/^krb/) {
                    257:                             if ($authparam eq '') {
1.6       raeburn   258:                                 $$logmsg .= "No Kerberos domain was provided for the new user - $uname, so the new student was not enrolled in the course.".$linefeed;
1.5       raeburn   259:                                 $authchk = 'invalid';
                    260:                             }
                    261:                         } else {
1.3       raeburn   262:                             $authchk = 'invalid';
1.6       raeburn   263:                             $$logmsg .= "An invalid authentication type was provided for the new user - $uname, so the student was not enrolled in the course.".$linefeed;
1.3       raeburn   264:                         }
1.5       raeburn   265:                         if ($authchk eq 'ok') { 
1.1       raeburn   266: # Now create user.
1.5       raeburn   267:                             my $reply=&Apache::lonnet::modifystudent($dom,$uname,$pid,$auth,$authparam,$first,$middle,$last,$gene,$usec,$end,$start,'',undef,$emailaddr,'auto',$cid);
                    268:                             if ($reply eq 'ok') {
                    269:                                 $enrollcount ++;
                    270:                                 $addresult .= "$first $last ($pid) - $uname enrolled in section/group $usec.".$linefeed;
1.6       raeburn   271:                                 if ($context eq 'automated') {
                    272:                                     $$logmsg .= "New $dom user $uname added successfully.".$linefeed;
                    273:                                 }
1.5       raeburn   274:                                 unless ($emailenc eq '') {
                    275:                                     my %emailHash;
                    276:                                     $emailHash{'critnotification'}  = $emailenc;
                    277:                                     $emailHash{'notification'} = $emailenc;
                    278:                                     my $putresult = &Apache::lonnet::put('environment',\%emailHash,$dom,$uname);
                    279:                                 }
                    280:                                 if ($create_passwd) {
1.1       raeburn   281: # Send e-mail with inital password to new user at $emailaddr
1.5       raeburn   282:                                     $$logmsg .= "Initial password -  - sent to ".$emailaddr.$linefeed;
                    283:                                 } else {
                    284:                                     $$logmsg .= $linefeed;
                    285:                                 }
1.3       raeburn   286:                             } else {
1.5       raeburn   287:                                 $$logmsg .= "An error occurred adding new user $uname - ".$reply.$linefeed;
1.3       raeburn   288:                             }
1.1       raeburn   289:                         }
1.5       raeburn   290:                     } else {
1.1       raeburn   291: # Get the user's information and authentication
1.5       raeburn   292:                         my %userenv = &Apache::lonnet::get('environment',['firstname','middlename','lastname','generation','id','critnotification','notification'],$dom,$uname);
                    293:                         my ($tmp) = keys(%userenv);
                    294:                         if ($tmp =~ /^(con_lost|error)/i) {
                    295:                             %userenv = ();
                    296:                         }
1.1       raeburn   297: # Get the user's e-mail address
1.5       raeburn   298:                         if ($userenv{critnotification} =~ m/%40/) {
                    299:                             unless ($emailenc eq $userenv{critnotification}) {
                    300:                                 $$logmsg .= "Current critical notification e-mail - ".$userenv{critnotification}." for $uname is different to e-mail address in Institutional classlist - ".$emailenc.$linefeed;
                    301:                             }
                    302:                         }
                    303:                         if ($userenv{notification} =~ m/%40/) {
                    304:                             unless ($emailenc eq $userenv{critnotification}) {
                    305:                                 $$logmsg .= "Current standard notification e-mail - ".$userenv{notification}." for $uname is different to e-mail address in institutional classlist - ".$emailenc.$linefeed;
                    306:                             }
                    307:                         }                            
                    308:                         my $krbdefdom = '';
                    309:                         my $currentauth=&Apache::lonnet::queryauthenticate($uname,$dom);
                    310:                         if ($currentauth=~/^krb(4|5):/) {
                    311:                             $currentauth=~/^krb(4|5):(.*)/;
                    312:                             $krbdefdom=$1;
                    313:                         }
                    314:                         if ($currentauth=~/^krb(4|5):/ || 
                    315:                             $currentauth=~/^unix:/ ||
                    316:                             $currentauth=~/^internal:/ ||
                    317:                             $currentauth=~/^localauth:/) {
1.1       raeburn   318:                                
1.5       raeburn   319:                         } else {
                    320:                             $$logmsg .= "Invalid authentication method $currentauth for $uname.".$linefeed;  
                    321:                         }
1.1       raeburn   322: # Report if authentication methods are different.
1.5       raeburn   323:                         if ($currentauth ne $auth ) {
1.6       raeburn   324:                             $$logmsg .= "Authentication mismatch for $uname - $currentauth in system, $auth based on information in classlist or default for this course.".$linefeed;
1.5       raeburn   325:                         }
1.1       raeburn   326: # Check user data
1.5       raeburn   327:                         if ($first  ne $userenv{'firstname'}  ||
                    328:                             $middle ne $userenv{'middlename'} ||
                    329:                             $last   ne $userenv{'lastname'}   ||
                    330:                             $gene   ne $userenv{'generation'} ||
                    331:                             $pid    ne $userenv{'id'} ) {         
1.1       raeburn   332: # Make the change(s)
1.5       raeburn   333:                             my %changeHash;
                    334:                             $changeHash{'firstname'}  = $first;
                    335:                             $changeHash{'middlename'} = $middle;
                    336:                             $changeHash{'lastname'}   = $last;
                    337:                             $changeHash{'generation'} = $gene;
                    338:                             $changeHash{'id'} = $pid;
                    339:                             my $putresult = &Apache::lonnet::put('environment',\%changeHash,$dom,$uname);
                    340:                             if ($putresult eq 'ok') {
                    341:                                 $$logmsg .= "User information updated for user: $uname prior to enrollment.".$linefeed;
                    342:                             } else {
                    343:                                 $$logmsg .= "There was a problem modifying user data for existing user - $uname -error: $putresult, enrollment will still be attempted.".$linefeed;
                    344:                             }
1.1       raeburn   345:                         }
1.3       raeburn   346:  
                    347: # Assign the role of student in the course.
1.5       raeburn   348:                         my $classlist_reply = &Apache::lonnet::modify_student_enrollment($dom,$uname,$pid,$first,$middle,$last,$gene,$usec,$end,$start,'auto',$cid);
                    349:                         if ($classlist_reply eq 'ok') {
                    350:                             $enrollcount ++;
                    351:                             $addresult .= "$first $last ($pid) - $uname enrolled in section/group $usec.".$linefeed;
1.6       raeburn   352:                             if ($context eq 'automated') {
                    353:                                 $$logmsg .= "Existing $dom user $uname enrolled successfully.".$linefeed;
                    354:                             }
1.5       raeburn   355:                         } else {
                    356:                             $$logmsg .= "There was a problem updating the classlist db file for user $uname to show the new enrollment -error: $classlist_reply, so no enrollment occurred for this user.".$linefeed;
                    357:                         }
1.3       raeburn   358:                     }
1.1       raeburn   359:                 }
                    360:             }
                    361:         }
                    362:     }
                    363: # Do drops
                    364:     if ( ($drops == 1) && (@reg_students > 0) ) {
                    365:         foreach my $uname (@localstudents) {
                    366:             if ($$currlist{$uname}[$type] eq "auto") {
                    367:                 my @saved = ();
                    368:                 if (!grep/^$uname$/,@reg_students) {
                    369: # Check for changed usernames by checking studentIDs
                    370:                     if (grep/^$$currlist{$uname}[ $stuid ]$/,@allINids) {
                    371:                         foreach my $match (@{$unameFromINid{$$currlist{$uname}[ $stuid ]}} ) {
1.6       raeburn   372:                             $$logmsg .= "A possible change in username has been detected for a student enrolled in this course. The existing LON-CAPA classlist contains user: $uname and student ID: $$currlist{$uname}[ $place{studentID} ].  This username has been dropped from the institutional classlist, but the same student ID is used for user: $match who still appears in the institutional classlist. You may need to move the student data files for user: $uname to $match.".$linefeed;
1.1       raeburn   373:                             push @saved,$uname;
                    374:                         }
                    375:                     } elsif (@saved == 0) {
                    376:                         my $drop_reply = &Apache::lonnet::modifystudent($dom,$uname,'','','',undef,undef,undef,undef,$$currlist{$uname}[$sec],time,undef,undef,undef,undef,undef,$cid);
                    377:                         if ($drop_reply !~ /^ok/) {
1.5       raeburn   378:                             $$logmsg .= "An error occured during the attempt to expire the $uname from the old section $$currlist{$uname}[$sec] - $drop_reply.".$linefeed;
1.1       raeburn   379:                         } else {
                    380:                             $dropcount ++;
                    381:                             my %userenv = &Apache::lonnet::get('environment',['firstname','lastname','id'],$dom,$uname);
                    382:                             $dropresult .= $userenv{'firstname'}." ".$userenv{'lastname'}." (".$userenv{'id'}.") - ".$uname." dropped from section/group ".$$currlist{$uname}[$sec].$linefeed; 
                    383:                         }
                    384:                     }
                    385:                 }
                    386:             }
                    387:         }
                    388:     }
1.5       raeburn   389: 
                    390: # Terminated explictly allowed access to student creation/modification
                    391:     if ($context eq 'automated') {
                    392:         delete($ENV{'allowed.cst'});
                    393:     }
1.1       raeburn   394:     if ($enrollcount > 0) {
                    395:         if ($context eq "updatenow") {
1.6       raeburn   396:             $addresult = substr($addresult,0,rindex($addresult,"<li>"));
1.1       raeburn   397:             $addresult = "The following $enrollcount student(s) was/were added to this LON-CAPA course:<br/><ul><li>".$addresult."</li></ul><br/><br/>";
                    398:         } else {
                    399:             $addresult = "The following $enrollcount student(s) was/were added to this LON-CAPA course:\n\n".$addresult."\n\n";    
                    400:         }      
                    401:     }
                    402:     if ($dropcount > 0) {
                    403:         if ($context eq "updatenow") {
1.6       raeburn   404:             $dropresult = substr($dropresult,0,rindex($dropresult,"<li>"));
1.1       raeburn   405:             $dropresult = "The following $dropcount student(s) was/were expired from this LON-CAPA course:<br/><ul><li>".$dropresult."</li></ul><br/><br/>";
                    406:         } else {
                    407:             $dropresult = "The following $dropcount student(s) was/were expired from this LON-CAPA course:\n\n".$dropresult."\n\n";
                    408:         }
                    409:     }
                    410:     if ( ($adds) && ($enrollcount == 0) ) {
                    411:         $addresult = "There were no new students to add to the course.";
                    412:         if ($context eq "updatenow") {
                    413:             $addresult .="<br/><br/>";
                    414:         } else {
                    415:             $addresult .="\n";
                    416:         }
                    417:     }
                    418:     if ( ($drops) && ($dropcount == 0) ) {
                    419:         $dropresult = "There were no students with roles to expire because all active students previously added to the course from institutional classlist(s) are still officially registered.";
                    420:         if ($context eq "updatenow") {
                    421:             $dropresult .="<br/>";
                    422:         } else {
                    423:             $dropresult .="\n";
                    424:         }
                    425:     }
1.5       raeburn   426:     my $changecount = $enrollcount + $dropcount;
                    427:     return ($changecount,$addresult.$dropresult); 
1.6       raeburn   428: }
1.1       raeburn   429: 
                    430: sub parse_classlist {
1.6       raeburn   431:     my ($tmpdir,$dom,$crs,$class,$placeref,$groupID,$studentsref) = @_;
1.5       raeburn   432:     my $xmlfile = $tmpdir."/tmp/".$dom."_".$crs."_".$class."_classlist.xml";
1.6       raeburn   433:     my $uname = '';
                    434:     my @state;
                    435:     my @items = ('autharg','authtype','email','enddate','firstname','generation','lastname','middlename','startdate','studentID');
                    436:     my $p = HTML::Parser->new
                    437:     (
                    438:         xml_mode => 1,
                    439:         start_h =>
                    440:             [sub {
                    441:                  my ($tagname, $attr) = @_;
                    442:                  push @state, $tagname;
                    443:                  if ("@state" eq "students student") {
                    444:                      $uname = $attr->{username};
                    445:                  }
                    446:             }, "tagname, attr"],
                    447:          text_h =>
                    448:              [sub {
                    449:                  my ($text) = @_;
                    450:                  if ("@state" eq "students student groupID") {
                    451:                      $$studentsref{$uname}[ $$placeref{'groupID'} ] = $groupID;
                    452:                  } else {
                    453:                      foreach my $item (@items) {
                    454:                          if ("@state" eq "students student $item") {
                    455:                              $$studentsref{$uname}[ $$placeref{$item} ] = $text;
                    456:                          }
                    457:                      }
                    458:                  }
                    459:                }, "dtext"],
                    460:          end_h =>
                    461:                [sub {
                    462:                    my ($tagname) = @_;
                    463:                    pop @state;
                    464:                 }, "tagname"],
                    465:     );
                    466:                                                                                                              
                    467:     $p->parse_file($xmlfile);
                    468:     $p->eof;
1.3       raeburn   469: #    if (-e "$xmlfile") {
                    470: #        unlink $xmlfile;
                    471: #    }
                    472:     return;
1.1       raeburn   473: }
                    474: 
                    475: sub create_password {
1.3       raeburn   476:     my ($authparam,$create_passwd,$authreply);
                    477:     return ($authparam,$create_passwd,$authreply);
1.1       raeburn   478: }
                    479: 
                    480: sub CL_autharg { return 0; }
                    481: sub CL_authtype { return 1;}
                    482: sub CL_email { return 2;}
                    483: sub CL_enddate { return 3;}
                    484: sub CL_firstname { return 4;}
                    485: sub CL_generation { return 5;}
                    486: sub CL_groupID { return 6;}
                    487: sub CL_lastname { return 7;}
                    488: sub CL_middlename { return 8;}
                    489: sub CL_startdate { return 9; }
                    490: sub CL_studentID { return 10; }
                    491: 
                    492: 1;

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