File:  [LON-CAPA] / loncom / enrollment / Enrollment.pm
Revision 1.48: download - view: text, annotated - select for diffs
Fri Jun 3 01:22:36 2016 UTC (8 years, 1 month ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Bug 5787. Automated enrollment process needs mdg priv.

    1: # Automated Enrollment manager
    2: # $Id: Enrollment.pm,v 1.48 2016/06/03 01:22:36 raeburn 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: #
   26: package LONCAPA::Enrollment;
   27: 
   28: use Apache::loncoursedata;
   29: use Apache::lonnet;
   30: use Apache::loncommon();
   31: use Apache::lonmsg;
   32: use Apache::lonlocal;
   33: use HTML::Entities;
   34: use LONCAPA::Configuration;
   35: use Time::Local;
   36: use lib '/home/httpd/lib/perl';
   37: 
   38: use strict;
   39: 
   40: sub update_LC {
   41:     my ($dom,$crs,$adds,$drops,$startdate,$enddate,$authtype,$autharg,
   42:         $showcredits,$defaultcredits,$classesref,$groupref,$logmsg,$newusermsg,
   43:         $context,$phototypes) = @_;
   44: # Get institutional code and title of this class
   45:     my %courseinfo = ();
   46:     &get_courseinfo($dom,$crs,\%courseinfo);
   47: # Get current LON-CAPA student enrollment for this class
   48:     my $configvars = &LONCAPA::Configuration::read_conf('loncapa.conf');
   49:     my $cid = $dom."_".$crs;
   50:     my $roster = &Apache::loncoursedata::get_classlist($dom,$crs);
   51:     my $cend = &Apache::loncoursedata::CL_END;
   52:     my $cstart = &Apache::loncoursedata::CL_START; 
   53:     my $stuid=&Apache::loncoursedata::CL_ID;
   54:     my $sec=&Apache::loncoursedata::CL_SECTION;
   55:     my $status=&Apache::loncoursedata::CL_STATUS;
   56:     my $type=&Apache::loncoursedata::CL_TYPE;
   57:     my $lockedtype=&Apache::loncoursedata::CL_LOCKEDTYPE;
   58:     my $credidx=&Apache::loncoursedata::CL_CREDITS;
   59:     my @localstudents = ();
   60:     my @futurestudents = ();
   61:     my @activestudents = ();
   62:     my @excludedstudents = ();
   63:     my $currlist;
   64:     my $now = time;
   65:     foreach my $uname (keys %{$roster} ) {
   66:         if ($uname =~ m/^(.+):$dom$/) {
   67:             if ($$roster{$uname}[$status] eq "Active") {
   68:                 push @activestudents, $1;
   69:                 @{$$currlist{$1}} = @{$$roster{$uname}};
   70:                 push @localstudents, $1;
   71:             } elsif ( ($$roster{$uname}[$cstart] > time)  && ($$roster{$uname}[$cend] > time || $$roster{$uname}[$cend] == 0 || $$roster{$uname}[$cend] eq '') ) {
   72:                 push @futurestudents, $1;
   73:                 @{$$currlist{$1}} = @{$$roster{$uname}};
   74:                 push @localstudents, $1;
   75:             } elsif ($$roster{$uname}[$lockedtype] == 1) {
   76:                 push @excludedstudents, $1;
   77:             }
   78:         }
   79:     }
   80:     my $linefeed = '';
   81:     my $addresult = '';
   82:     my $dropresult = '';
   83:     my $switchresult = '';
   84:     my $photoresult = '';
   85:     if ($context eq "updatenow") {
   86:         $linefeed = "</li>\n<li>"; 
   87:     } elsif ($context eq "automated") {
   88:         $linefeed = "\n";
   89:     }
   90:     my $enrollcount = 0;
   91:     my $dropcount = 0;
   92:     my $switchcount = 0;
   93: 
   94: # Get role names
   95:     my %longroles = ();
   96:     open(FILE,"<$$configvars{'lonTabDir'}.'/rolesplain.tab");
   97:     my @rolesplain = <FILE>;
   98:     close(FILE);
   99:     foreach my $item (@rolesplain) {
  100:         if ($_ =~ /^(st|ta|ex|ad|in|cc|co):([\w\s]+):?([\w\s]*)/) {
  101:             if ($courseinfo{'type'} eq 'Community') {
  102:                 unless($1 eq 'cc') {
  103:                     $longroles{$1} = $3;
  104:                 }
  105:             } else {
  106:                 unless($1 eq 'co') { 
  107:                     $longroles{$1} = $2;
  108:                 }
  109:             }
  110:         }
  111:     }
  112: 
  113:     srand( time() ^ ($$ + ($$ << 15))  ); # Seed rand in case initial passwords have to be generated for new users.
  114: 
  115: # Get mapping of IDs to usernames for current LON-CAPA student enrollment for this class 
  116:     my @LCids = ();
  117:     my %unameFromLCid = ();
  118:     foreach my $uname (sort keys %{$currlist}) {
  119:         my $stuID = $$currlist{$uname}[$stuid];
  120:         if (!grep/^$stuID$/,@LCids) {
  121:             push @LCids, $stuID;
  122:             @{$unameFromLCid{$stuID}} = ();
  123:         }
  124:         push @{$unameFromLCid{$stuID}},$uname;
  125:     }
  126:  
  127: # Get latest institutional enrollment for this class.
  128:     my %allenrolled = ();
  129:     my @reg_students = ();
  130:     my %place = &place_hash(); 
  131:     my %ucount = ();
  132:     my %enrollinfo = ();
  133:     foreach my $class (@{$classesref}) {
  134:         my %enrolled = ();
  135:         &parse_classlist($$configvars{'lonDaemons'},$dom,$crs,$class,\%place,$$groupref{$class},\%enrolled);
  136:         foreach my $uname (sort keys %enrolled ) {
  137:             if (!grep/^$uname$/,@reg_students) {
  138:                 push @reg_students,$uname;
  139:                 $ucount{$uname} = 0;
  140:                 @{$allenrolled{$uname}} = ();
  141:             }
  142:             @{$allenrolled{$uname}[$ucount{$uname}]} = @{$enrolled{$uname}};
  143:             $ucount{$uname} ++;
  144:         }
  145:     }
  146: 
  147: # Check for multiple sections for a single student 
  148:     my @okusers = ();
  149:     foreach my $uname (@reg_students)  {
  150:         if (grep/^$uname$/,@excludedstudents) {
  151:             $$logmsg .= &mt('No re-enrollment for [_1] - user was previously manually unenrolled and locked.',$uname).$linefeed;
  152:         } elsif (@{$allenrolled{$uname}} > 1) {
  153:             my @sections = ();
  154:             my $saved;
  155:             for (my $i=0; $i<@{$allenrolled{$uname}}; $i++) {
  156:                 my @stuinfo = @{$allenrolled{$uname}[$i]};
  157:                 my $secnum = $stuinfo[ $place{'groupID'} ];
  158:                 unless ($secnum eq '') {
  159:                     unless (grep/^$secnum$/,@sections) {
  160:                         $saved = $i; 
  161:                         push @sections,$secnum;
  162:                     }
  163:                 }
  164:             }
  165:             if (@sections == 0) {
  166:                 @{$enrollinfo{$uname}} = @{$allenrolled{$uname}[0]};
  167:                 push @okusers, $uname;
  168:             }
  169:             elsif (@sections == 1) {
  170:                 @{$enrollinfo{$uname}} = @{$allenrolled{$uname}[$saved]};
  171:                 push @okusers, $uname;
  172:             }
  173:             elsif (@sections > 1) {
  174:                 $$logmsg .=  &mt('[_1] appears in classlists for more than one section of this course, i.e. in sections: ',$uname);
  175:                 foreach (@sections) {
  176:                     $$logmsg .= " $_,";
  177:                 }
  178:                 chop($$logmsg);
  179:                 $$logmsg .= '. '.&mt('Because of this ambiguity, no enrollment action was taken for this student.').$linefeed;
  180:             }
  181:         } else {
  182:             @{$enrollinfo{$uname}} = @{$allenrolled{$uname}[0]};
  183:             push @okusers, $uname;
  184:         }
  185:     }
  186: # Get mapping of student/employee IDs to usernames for users in institutional data for this class  
  187:     my @allINids = ();
  188:     my %unameFromINid = ();
  189:     foreach my $uname (@okusers) {
  190:         $enrollinfo{$uname}[ $place{'studentID'} ] =~ tr/A-Z/a-z/;
  191:         my $stuID = $enrollinfo{$uname}[ $place{'studentID'} ];
  192:         if (grep/^$stuID$/,@allINids)  {
  193:             push @{$unameFromINid{$stuID}},$uname;
  194:         } else {
  195:             push @allINids, $stuID;
  196:             @{$unameFromINid{$stuID}} = $uname; 
  197:         }
  198:     }
  199: 
  200: # Explicitly allow access to creation/modification of students and group membership changes 
  201: # when called as an automated process.
  202:     if ($context eq 'automated') {
  203:         $env{'allowed.cst'}='F';
  204:         $env{'allowed.mdg'}='F';
  205:     }
  206: 
  207: # Compare IDs with existing LON-CAPA enrollment for this class
  208:     foreach my $uname (@okusers) {
  209:         unless ($uname eq '') {
  210:             my %uidhash=&Apache::lonnet::idrget($dom,$uname);
  211:             my @stuinfo = @{$enrollinfo{$uname}};
  212:             my ($access,$added,$inststatus);
  213:             my $credits;
  214:             if ($showcredits) {
  215:                 $credits = $stuinfo[$place{'credits'}];
  216:                 $credits =~ s/[^\d\.]//g;
  217:                 if ($credits eq $defaultcredits) {
  218:                     undef($credits);
  219:                 }
  220:             }
  221:             $inststatus = $stuinfo[$place{inststatus}];
  222:             if (grep/^$uname$/,@localstudents) {
  223: # Check for studentID changes
  224:                 if ( ($uidhash{$uname}) && ($uidhash{$uname} !~ /error\:/) )  {
  225:                     unless ( ($uidhash{$uname}) eq ($stuinfo[ $place{studentID} ]) ) {
  226:                         $$logmsg .= &mt('Change in ID for [_1]. StudentID in LON-CAPA system is [_2]; StudentID in institutional data is [_3].',$uname,$uidhash{$uname},$stuinfo[ $place{studentID} ]).$linefeed; 
  227:                     }
  228:                 }
  229: # Check for switch from manual to auto
  230:                 unless (($$currlist{$uname}[$type] eq "auto") || ($$currlist{$uname}[$lockedtype] eq "1") || (!$adds) ) {
  231: # drop manually added student
  232:                     my $drop_reply = &Apache::lonnet::modifystudent($dom,$uname,'','','',undef,undef,undef,undef,$$currlist{$uname}[$sec],time,undef,undef,undef,undef,'auto','',$cid,'',$context);
  233: # re-enroll as auto student
  234:                     if ($drop_reply !~ /^ok/) {
  235:                             $$logmsg .= &mt('An error occurred during the attempt to convert [_1] from a manual type to an auto type student - [_2].',$uname,$drop_reply).$linefeed;
  236:                     } else {
  237: # re-enroll as auto student
  238:                         my ($auth,$authparam,$first,$middle,$last,$gene,$usec,$end,$start,$emailaddr,$pid,$emailenc);
  239:                         &prepare_add($authtype,$autharg,$enddate,$startdate,\@stuinfo,\%place,\$dom,\$uname,\$auth,\$authparam,\$first,\$middle,\$last,\$gene,\$usec,\$end,\$start,\$emailaddr,\$pid,\$emailenc);
  240:                         if ($$currlist{$uname}[$sec] ne $usec) {
  241:                             my $showoldsec = $$currlist{$uname}[$sec];
  242:                             if ($$currlist{$uname}[$sec] eq '') {
  243:                                 $showoldsec = &mt('none');
  244:                             }
  245:                             my $showsec = $usec;
  246:                             if ($usec eq '') {
  247:                                 $showsec = &mt('none');
  248:                             }
  249:                             $switchresult .= &mt('Section for [_1] switched from [_2] to [_3].',$uname,$showoldsec,$showsec).$linefeed;
  250:                             if ($context eq 'automated') {
  251:                                 $$logmsg .= &mt('Section switch for [_1] from [_2] to [_3].',$uname,$showoldsec,$usec).$linefeed;
  252:                             }
  253:                             $switchcount ++;
  254:                         }
  255:                         &execute_add($context,'switchtype',$uname,$dom,$auth,
  256:                                      $authparam,$first,$middle,$last,$gene,
  257:                                      $pid,$usec,$end,$start,$emailenc,
  258:                                      $credits,$cid,\$addresult,\$enrollcount,
  259:                                      $linefeed,$logmsg);
  260:                         $added = 1;
  261:                     }
  262:                 }
  263: # Check for section changes
  264:                 if ($$currlist{$uname}[$sec] eq $stuinfo[ $place{groupID} ]) {
  265: # Check for access date changes for students with access starting in the future.
  266:                     if ( (grep/^$uname$/,@futurestudents) && ($$currlist{$uname}[$type] eq "auto") && ($adds == 1) ) {
  267:                         my $datechange = &datechange_check($$currlist{$uname}[$cstart],$$currlist{$uname}[$cend],$startdate,$enddate);
  268:                         if ($datechange) {
  269:                             my $modify_access_result = &Apache::lonnet::modify_student_enrollment($dom,$uname,undef,undef,undef,undef,undef,$stuinfo[ $place{groupID} ],$enddate,$startdate,'auto','',$cid,'',$context,$credits);
  270:                             $access = &showaccess($enddate,$startdate);
  271:                             if ($modify_access_result =~ /^ok/) {
  272:                                 $$logmsg .= &mt('Change in access dates for [_1].',$uname).$access.$linefeed;
  273:                                 $added = 1;
  274:                             } else {
  275:                                 $$logmsg .= &mt('Error when attempting to change start and/or end access dates for [_1] in section: [_2] -error [_3].',$uname,$stuinfo[$place{groupID}],$modify_access_result).$linefeed;
  276:                             }
  277:                         }
  278:                     }
  279:                 } else {
  280:                     if ( ($$currlist{$uname}[$type] eq "auto") && ($adds == 1) ) {
  281: # Delete from roles.db for current section
  282:                         my $expiretime = time;
  283:                         my $uurl='/'.$cid;
  284:                         $uurl=~s/\_/\//g;
  285:                         if ($$currlist{$uname}[$sec]) {
  286:                             $uurl.='/'.$$currlist{$uname}[$sec];
  287:                         }
  288:                         my $expire_role_result = &Apache::lonnet::assignrole($dom,$uname,$uurl,'st',$expiretime,'','','',$context);
  289:                         if ($expire_role_result eq 'ok') {
  290:                             my $modify_section_result;
  291:                             if (grep/^$uname$/,@activestudents) {
  292:                                 $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,'',$context,$credits);
  293:                             } else {
  294:                                 $modify_section_result =  &Apache::lonnet::modify_student_enrollment($dom,$uname,undef,undef,undef,undef,undef,$stuinfo[ $place{groupID} ],$enddate,$startdate,'auto','',$cid,'',$context,$credits);
  295:                                 $access =  &showaccess($enddate,$startdate);
  296:                             }
  297:                             if ($modify_section_result =~ /^ok/) {
  298:                                 $switchresult .= &mt('Section for [_1] switched from old section: [_2] to new section: [_3].',$uname,$$currlist{$uname}[$sec],$stuinfo[ $place{groupID} ]).$access.$linefeed;
  299:                                 $added = 1;
  300:                                 if ($context eq 'automated') {
  301:                                     $$logmsg .= &mt('Section switch for [_1] from [_2] to [_3].',$uname,$$currlist{$uname}[$sec],$stuinfo[ $place{groupID} ]).$linefeed;
  302:                                 }
  303:                                 $switchcount ++;
  304:                             } else {
  305:                                 $$logmsg .= &mt("Error when attempting section change for [_1], from old section: '[_2]' to new section: '[_3]' -error: [_4]",$uname,$$currlist{$uname}[$sec],$stuinfo[ $place{groupID} ],$modify_section_result).$linefeed;
  306:                             }
  307:                         } else {
  308:                             $$logmsg .= &mt("Error when attempting to expire role for [_1] in old section: '[_2]' -error: '[_3]'.",$uname,$$currlist{$uname}[$sec],$expire_role_result).$linefeed;
  309:                         }
  310:                     }
  311:                 }
  312: # Check for credits changes
  313:                 if (($showcredits) && 
  314:                     ($$currlist{$uname}[$credidx] ne $credits) && (!$added)) {
  315:                     my $modify_credits_result =
  316:                         &Apache::lonnet::modify_student_enrollment($dom,$uname,undef,undef,undef,undef,undef,$stuinfo[ $place{groupID} ],$enddate,$startdate,'auto','',$cid,'',$context,$credits);
  317:                     if ($modify_credits_result =~ /^ok/) {
  318:                         if ($credits ne '') {
  319:                             $$logmsg .= &mt('Credits change for [_1] from [_2] to [_3].',$uname,$$currlist{$uname}[$credidx],$credits).$linefeed;
  320:                         } else {
  321:                             $$logmsg .= &mt('Credits change for [_1] from [_2] to course default [_3].',$uname,$$currlist{$uname}[$credidx],$defaultcredits).$linefeed;
  322:                         }
  323:                     } else {
  324:                         $$logmsg .= &mt('Error when attempting to change credits for [_1] in section: [_2] -error [_3].',$uname,$stuinfo[$place{groupID}],$modify_credits_result).$linefeed;
  325:                     }
  326:                 }
  327:             } else {
  328: # Check for changed usernames by checking studentIDs
  329:                 if ( ($stuinfo[ $place{studentID} ] ne '') && (grep/^$stuinfo[ $place{studentID} ]$/,@LCids) ) {
  330:                     foreach my $match ( @{ $unameFromLCid{ $stuinfo[ $place{studentID} ] } }  ) {
  331:                         $$logmsg .= &mt('A possible change in username has been detected for a student enrolled in this course.').' '.&mt('The existing LON-CAPA classlist contains user: [_1] and student/employee ID: [_2].',$match,$stuinfo[ $place{studentID} ]);
  332:                         if (grep/^$match$/,@okusers) {
  333:                             $$logmsg .= &mt('The username [_1] remains in the institutional classlist, but the same student/employee ID is used for new user: [_2] now found in the institutional classlist.',$match,$uname).' '.&mt('You may need to contact your Domain Coordinator to determine how to resolve this issue and whether to move student data files for user: [_1] to [_2].',$match,$uname).' ';
  334:                         } else {
  335:                             unless ($drops == 1) {
  336:                                 $$logmsg .= &mt('This username - [_1] - has been dropped from the institutional classlist, but the student/employee ID of this user is also used by [_2] who now appears in the institutional classlist.',$match,$uname).' '.&mt('You may need to contact your Domain Coordinator to request a move of the student data files for user: [_1] to [_2].',$match,$uname).' ';
  337:                             }
  338:                         }
  339:                         $$logmsg .= &mt('Because of this student/employee ID conflict, the new username - [_1] - has not been added to the LON-CAPA classlist',$uname).$linefeed;
  340:                     }
  341:                 } elsif ($adds == 1) {
  342:                     my ($auth,$authparam,$first,$middle,$last,$gene,$usec,$end,$start,$emailaddr,$pid,$emailenc,$credithours);
  343:                     &prepare_add($authtype,$autharg,$enddate,$startdate,\@stuinfo,\%place,\$dom,\$uname,\$auth,\$authparam,\$first,\$middle,\$last,\$gene,\$usec,\$end,\$start,\$emailaddr,\$pid,\$emailenc);
  344: # Check for existing account in this LON-CAPA domain for this username
  345:                     next if (($end) && ($end < $now));
  346:                     my $uhome=&Apache::lonnet::homeserver($uname,$dom);
  347:                     if ($uhome eq 'no_host') { # User does not exist
  348:                         my $args = {'auth' => $auth,
  349:                                     'authparam' => $authparam,
  350:                                     'emailenc' => $emailenc,
  351:                                     'udom' => $dom,
  352:                                     'uname' => $uname,
  353:                                     'pid' => $pid,
  354:                                     'first' => $first,
  355:                                     'middle' => $middle,
  356:                                     'last' => $last,
  357:                                     'gene' => $gene,
  358:                                     'usec' => $usec,
  359:                                     'end' => $end,
  360:                                     'start' => $start,
  361:                                     'emailaddr' => $emailaddr,
  362:                                     'cid' => $cid,
  363:                                     'crs' => $crs,
  364:                                     'cdom' => $dom,
  365:                                     'context' => $context,
  366:                                     'linefeed' => $linefeed,
  367:                                     'inststatus' => $inststatus,
  368:                                     'role' => 'st',
  369:                                    };
  370:                         if ($credits) {
  371:                             $args->{'credits'} = $credits;
  372:                         }
  373:                         my $outcome = &create_newuser($args,$logmsg,$newusermsg,\$enrollcount,\$addresult,\%longroles,\%courseinfo,$context);
  374:                     } else {
  375:                         &execute_add($context,'newstudent',$uname,$dom,$auth,
  376:                                      $authparam,$first,$middle,$last,$gene,$pid,
  377:                                      $usec,$end,$start,$emailenc,$credits,
  378:                                      $cid,\$addresult,\$enrollcount,$linefeed,
  379:                                      $logmsg);
  380:                     }
  381:                     if ($courseinfo{'showphoto'}) {
  382:                         my ($result,$resulttype) = 
  383:                            &Apache::lonnet::auto_checkphotos($uname,$dom,$pid);
  384:                         if ($resulttype) {
  385:                             push(@{$$phototypes{$resulttype}},$uname);
  386:                         }
  387:                     }
  388:                 }
  389:             }
  390:         }
  391:     }
  392:     if ($courseinfo{'showphoto'}) {
  393:         if (keys(%{$phototypes})>0) {
  394:             my %lt = &photo_response_types();
  395:             foreach my $type (sort(keys(%{$phototypes}))) {
  396:                 my $numphoto = @{$$phototypes{$type}};
  397:                 if ($numphoto > 0) {
  398:                     if ($context eq 'updatenow') {
  399:                         $photoresult .=  '<br /><b>'.
  400: 			    &mt('For [_1] students, photos ',$numphoto).
  401: 			    $lt{$type}.'</b><ul><li>';
  402:                     } else {
  403:                         $photoresult .=  "\n".&mt("For [quant,_1,student], photos ",$numphoto).
  404: 			    $lt{$type}."\n";
  405:                     }
  406:                     foreach my $user (@{$$phototypes{$type}}) { 
  407:                         $photoresult .= $user.$linefeed;
  408:                     }
  409:                     if ($context eq 'updatenow') {
  410:                         $photoresult = substr($photoresult,0,
  411: 					      rindex($photoresult,"<li>"));
  412:                         $photoresult .= '</ul><br />';
  413:                     } else {
  414:                         $photoresult .= "\n";
  415:                     }
  416:                 }
  417:             }
  418:         }
  419:     }
  420: 
  421: # Do drops
  422:     if ( ($drops == 1) && (@reg_students > 0) ) {
  423:         foreach my $uname (@localstudents) {
  424:             if ($$currlist{$uname}[$type] eq "auto") {
  425:                 my @saved = ();
  426:                 if (!grep/^$uname$/,@reg_students) {
  427: # Check for changed usernames by checking studentIDs
  428:                     if (grep/^$$currlist{$uname}[ $stuid ]$/,@allINids) {
  429:                         foreach my $match (@{$unameFromINid{$$currlist{$uname}[ $stuid ]}} ) {
  430:                             $$logmsg .= &mt('A possible change in username has been detected for a student enrolled in this course.').' '.&mt('The existing LON-CAPA classlist contains user: [_1] and student/employee ID: [_2].',$uname,$$currlist{$uname}[ $place{studentID} ]).' '.&mt('This username has been dropped from the institutional classlist, but the same student/employee ID is used for user: [_1] who still appears in the institutional classlist.',$match).' '.&mt('You may need to move the student data files for user: [_1] to [_2]',$uname,$match).' '.&mt('Because of this, user [_1] has not been dropped from the course.',$uname).$linefeed;
  431:                             push @saved,$uname;
  432:                         }
  433:                     } elsif (@saved == 0) {
  434:                         my $drop_reply = &Apache::lonnet::modifystudent($dom,$uname,'','','',undef,undef,undef,undef,$$currlist{$uname}[$sec],time,undef,undef,undef,undef,'auto','',$cid,'',$context);
  435:                         if ($drop_reply !~ /^ok/) {
  436:                             $$logmsg .= &mt('An error occurred during the attempt to expire the [_1] from the old section [_2] - [_3].',$uname,$$currlist{$uname}[$sec],$drop_reply).$linefeed;
  437:                         } else {
  438:                             $dropcount ++;
  439:                             my %userenv = &Apache::lonnet::get('environment',['firstname','lastname','id'],$dom,$uname);
  440:                             $dropresult .= $userenv{'firstname'}." ".$userenv{'lastname'}." (".$userenv{'id'}.") - ".$uname.' '.&mt("dropped from section: '[_1]'.",$$currlist{$uname}[$sec]).$linefeed; 
  441:                             if ($context eq 'automated') {
  442:                                 $$logmsg .= &mt('User [_1] student role expired from course.',$uname).$linefeed;
  443:                             }
  444:                         }
  445:                     }
  446:                 }
  447:             }
  448:         }
  449:     }
  450: 
  451: # Terminated explictly allowed access to student creation/modification 
  452: # and group membership changes
  453:     if ($context eq 'automated') {
  454:         delete($env{'allowed.cst'});
  455:         delete($env{'allowed.mdg'});
  456:     }
  457:     if ($enrollcount > 0) {
  458:         if ($context eq "updatenow") {
  459:             $addresult = substr($addresult,0,rindex($addresult,"<li>"));
  460:             $addresult = &mt("The following [quant,_1,student was,students were] added to this LON-CAPA course:",$enrollcount).'<br/><ul><li>'.$addresult.'</ul><br/><br/>';
  461:         } else {
  462:             $addresult = &mt("The following [quant,_1,student was,students were] added to this LON-CAPA course:",$enrollcount)."\n\n".$addresult."\n\n";
  463:         }
  464:     }
  465:     if ($dropcount > 0) {
  466:         if ($context eq "updatenow") {
  467:             $dropresult = substr($dropresult,0,rindex($dropresult,"<li>"));
  468:             $dropresult = &mt("The following [quant,_1,student was,students were] expired from this LON-CAPA course:",$dropcount).'<br/><ul><li>'.$dropresult.'</ul><br/><br/>';
  469:         } else {
  470:             $dropresult = &mt("The following [quant,_1,student was,students were] expired from this LON-CAPA course:",$dropcount)."\n\n".$dropresult."\n\n";
  471:         }
  472:     }
  473:     if ($switchcount > 0) {
  474:         if ($context eq "updatenow") {
  475:             $switchresult = substr($switchresult,0,rindex($switchresult,"<li>"));
  476:             $switchresult = &mt("The following [quant,_1,student] switched sections in this LON-CAPA course:",$switchcount).'<br/><ul><li>'.$switchresult.'</ul><br/><br/>';
  477:         } else {
  478:             $switchresult = &mt("The following [quant,_1,student] switched sections in this LON-CAPA course:",$switchcount)."\n\n".$switchresult."\n\n";
  479:         }
  480:     }
  481:     if ( ($adds) && ($enrollcount == 0) ) {
  482:         $addresult = &mt('There were no new students to add to the course.');
  483:         if ($context eq "updatenow") {
  484:             $addresult .="<br/><br/>";
  485:         } else {
  486:             $addresult .="\n";
  487:         }
  488:     }
  489:     if ( ($drops) && ($dropcount == 0) ) {
  490:         $dropresult = &mt('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.');
  491:         if ($context eq "updatenow") {
  492:             $dropresult .="<br/>";
  493:         } else {
  494:             $dropresult .="\n";
  495:         }
  496:     }
  497:     my $changecount = $enrollcount + $dropcount + $switchcount;
  498:     return ($changecount,$addresult.$photoresult.$dropresult.$switchresult);
  499: }
  500: 
  501: sub create_newuser {
  502:     my ($args,$logmsg,$newusermsg,$enrollcount,$addresult,$longroles,
  503: 	$courseinfo,$called_context) = @_;
  504:     my $auth = $args->{'auth'};
  505:     my $authparam = $args->{'authparam'};
  506:     my $emailenc = $args->{'emailenc'};
  507:     my $udom = $args->{'udom'};
  508:     my $uname = $args->{'uname'};
  509:     my $pid = $args->{'pid'};
  510:     my $first = $args->{'first'};
  511:     my $middle = $args->{'middle'};
  512:     my $last = $args->{'last'} ;
  513:     my $gene = $args->{'gene'};
  514:     my $usec = $args->{'usec'};
  515:     my $end = $args->{'end'};
  516:     my $start = $args->{'start'};
  517:     my $emailaddr = $args->{'emailaddr'};
  518:     my $cid = $args->{'cid'};
  519:     my $crs = $args->{'crs'};
  520:     my $cdom = $args->{'cdom'};
  521:     my $context = $args->{'context'};
  522:     my $linefeed = $args->{'linefeed'};
  523:     my $role = $args->{'role'};
  524:     my $inststatus = $args->{'inststatus'};
  525:     my $credits = $args->{'credits'};
  526:     my $create_passwd = 0;
  527:     my $authchk = '';
  528:     my $outcome;
  529:     unless ($authparam eq '') { $authchk = 'ok'; };
  530: # If no account exists and passwords should be generated
  531:     if ($auth eq "internal") {
  532:         if ($authparam eq '') {
  533:             $authparam = &create_password();
  534:             if ($authparam eq '') {
  535:                 $authchk = '';
  536:             } else {
  537:                 $create_passwd = 1;
  538:                 $authchk = 'ok';
  539:             }
  540:         }
  541:     } elsif ($auth eq "localauth") {
  542:         ($authparam,$create_passwd,$authchk) = &Apache::lonnet::auto_create_password($crs,$cdom,$authparam,$udom);
  543:     } elsif ($auth =~ m/^krb/) {
  544:         if ($authparam eq '') {
  545:             $$logmsg .= &mt('No Kerberos domain was provided for the new user - [_1], so the new user was not enrolled in the course',$uname).$linefeed;
  546:             $authchk = 'invalid';
  547:         }
  548:     } else {
  549:         $authchk = 'invalid';
  550:         $$logmsg .= &mt('An invalid authentication type was provided for the new user - [_1], so the user was not enrolled in the course.',$uname).$linefeed;
  551:     }
  552:     if ($authchk eq 'ok') {
  553: # Now create user.
  554:         my $type = 'auto';
  555:         my $userurl = '/'.$cdom.'/'.$crs;
  556:         if ($usec ne '') {
  557:             $userurl .= '/'.$usec;
  558:         }
  559:         if ($context eq 'createowner' || $context eq 'createcourse') {
  560:             my $result = &Apache::lonnet::modifyuser($udom,$uname,$pid,$auth,$authparam,$first,$middle,$last,$gene,'1',undef,$emailaddr);
  561:             if ($result eq 'ok' && $context eq 'createcourse') {
  562:                 $outcome = &Apache::loncommon::commit_standardrole($udom,$uname,$userurl,$role,$start,$end,$cdom,$crs,$usec,$called_context);
  563:                 unless ($outcome =~ /^Error:/) {
  564:                     $outcome = 'ok';
  565:                 }
  566:             } else {
  567:                 $outcome = $result;
  568:             }
  569:         } else {
  570:             $outcome=&Apache::lonnet::modifystudent($udom,$uname,$pid,$auth,$authparam,$first,$middle,$last,$gene,$usec,$end,$start,'',undef,$emailaddr,'auto','',$cid,'',$called_context,$inststatus,$credits);
  571:         }
  572:         if ($outcome eq 'ok') {
  573:             my $access = &showaccess($end,$start);
  574:             my $showsec = $usec;
  575:             if ($usec eq '') {
  576:                 $showsec = &mt('none');
  577:             }
  578:             $$addresult .= "$first $last ($pid) - $uname ".&mt("enrolled in section: '[_1]'.",$showsec).$access.$linefeed;
  579:             unless ($context eq 'createowner' || $context eq 'createcourse') {
  580:                 $$enrollcount ++;
  581:             }
  582:             if ($called_context eq 'automated') {
  583:                 $$logmsg .= &mt('New [_1] user [_2] added successfully.',$udom,$uname);
  584:             }
  585:             unless ($emailenc eq '' || $context eq 'createowner' || $context eq 'createcourse') {
  586:                 my %emailHash;
  587:                 $emailHash{'critnotification'}  = $emailenc;
  588:                 $emailHash{'notification'} = $emailenc;
  589:                 $emailHash{'permanentemail'} = $emailenc;
  590:                 my $putresult = &Apache::lonnet::put('environment',\%emailHash,$udom,$uname);
  591:             }
  592:             if ($create_passwd) {
  593: # Send e-mail with initial password to new user at $emailaddr.
  594: # If e-mail address is invalid, send password via message to courseowner i
  595: # (if automated call) or to user if roster update.
  596:                 if ($emailaddr eq '') {
  597:                     $$newusermsg .= &mt(' username: [_1], password: [_2]',$uname,$authparam).$linefeed."\n";
  598:                 } else {
  599:                     my $subject = &mt('New LON-CAPA account');
  600:                     my $body;
  601:                     my $portalurl = 'http://'.$ENV{'SERVER_NAME'};
  602:                     my $protocol = 'http';
  603:                     my $lonhost=&Apache::lonnet::domain($udom,'primary');
  604:                     if ($lonhost ne '') {
  605:                         my $ip = &Apache::lonnet::get_host_ip($lonhost);
  606:                         if ($Apache::lonnet::protocol{$lonhost} eq 'https') {
  607:                             $protocol = 'https';
  608:                         }
  609:                         if ($ip ne '') {
  610:                             $portalurl = $protocol.'://'.$ip
  611:                         }
  612:                     }
  613:                     if ($context eq 'createowner') {
  614:                         $body = &mt('A user account has been created for you while creating your new course in the LON-CAPA course management and online homework system.')."\n\n".&mt('You should log-in to the system using the following credentials:')."\n".&mt('username: ').$uname."\n".&mt('password: ').$authparam."\n\n".&mt('The URL you should use to access the LON-CAPA system at your institution is: ').$portalurl."\n\n";
  615:                     } elsif ($context eq 'createcourse') {
  616:                         $body = &mt('You have been assigned the role of [_1] in a new course: [_2] - [_3] in the LON-CAPA course management and online homework system.',$$longroles{$role},$$courseinfo{'description'},$$courseinfo{'inst_code'}).' '.&mt('As you did not have an existing user account in the system, one has been created for you.')."\n\n".&mt("You should log-in to the system using the following credentials:\nusername: [_1]\npassword: [_2]",$uname,$authparam)."\n\n".&mt('The URL you should use to access the LON-CAPA system at your institution is: ').$portalurl."\n\n"; 
  617:                     } else {
  618:                         my $access_start = 'immediately';
  619:                         if ($start > 0) {
  620:                             $access_start = localtime($start)
  621:                         }
  622:                         $body =
  623:                             &mt('You have been enrolled in the LON-CAPA system at your institution, because you are a registered student in a class which is using the LON-CAPA course management and online homework system.')."\n\n"
  624:                            .&mt("You should log-in to the system using the following credentials:\nusername: [_1]\npassword: [_2]",$uname,$authparam)."\n\n"
  625:                            .&mt('The URL you should use to access the LON-CAPA system at your institution is: ').$portalurl."\n\n"
  626:                            .&mt('When you log-in you will be able to access the LON-CAPA course for [_1] - [_2] starting [_3].',$$courseinfo{'description'},$$courseinfo{'inst_code'},$access_start)."\n";
  627:                     }
  628:                     &Apache::lonmsg::sendemail($emailaddr,$subject,$body);
  629:                 }
  630:                 if ($called_context eq 'automated') {
  631:                     $$logmsg .= &mt(' Initial password - sent to ').$emailaddr.$linefeed;
  632:                 }
  633:             } else {
  634:                 if ($called_context eq 'automated') {
  635:                     $$logmsg .= $linefeed;
  636:                 }
  637:             }
  638:         } else {
  639:             $$logmsg .= &mt('An error occurred adding new user [_1] - [_2].',$uname,$outcome).$linefeed;
  640:         }
  641:     } else {
  642:         $$logmsg .= &mt('An error occurred adding the new user [_1] because the authcheck failed for authtype [_2] and parameter [_3].',$uname,$auth,$authparam).' '.&mt('The authcheck response was [_1].',$authchk).$linefeed;
  643:     }
  644:     return $outcome;
  645: }
  646: 
  647: sub prepare_add {
  648:     my ($authtype,$autharg,$enddate,$startdate,$stuinfo,$place,$dom,$uname,$auth,$authparam,$first,$middle,$last,$gene,$usec,$end,$start,$emailaddr,$pid,$emailenc) = @_;
  649:     $$auth = $$stuinfo[ $$place{'authtype'} ];
  650:     $$authparam = $$stuinfo[ $$place{'autharg'} ];
  651:     $$first = $$stuinfo[ $$place{'firstname'} ];
  652:     $$middle = $$stuinfo[ $$place{'middlename'} ];
  653:     $$last = $$stuinfo[ $$place{'lastname'} ];
  654:     $$gene = $$stuinfo[ $$place{'generation'} ];
  655:     $$usec = $$stuinfo[ $$place{'groupID'} ];
  656:     $$end = $$stuinfo[ $$place{'enddate'} ];
  657:     $$start = $$stuinfo[ $$place{'startdate'} ];
  658:     $$emailaddr = $$stuinfo[ $$place{'email'} ];
  659:     $$pid = $$stuinfo[ $$place{'studentID'} ];
  660: 
  661: # remove non alphanumeric values from section
  662:     $$usec =~ s/\W//g;
  663:                                                                                   
  664:     unless ($$emailaddr =~/^[^\@]+\@[^\@]+$/) { $$emailaddr =''; }
  665:     $$emailenc = &HTML::Entities::encode($$emailaddr,'<>&"');
  666:                                                                                   
  667: # Use course defaults where entry is absent
  668:     if ( ($$auth eq '') || (!defined($$auth)) ) {
  669:         $$auth =  $authtype;
  670:     }
  671:     if ( ($$authparam eq '')  || (!defined($$authparam)) )  {
  672:         $$authparam = $autharg;
  673:     }
  674:     if ( ($$end eq '') || (!defined($$end)) )  {
  675:         $$end = $enddate;
  676:     }
  677:     if ( ($$start eq '')  || (!defined($$start)) )  {
  678:         $$start = $startdate;
  679:     }
  680: # Clean up whitespace
  681:     foreach ($dom,$uname,$pid,$first,$middle,$last,$gene,$usec) {
  682:         $$_ =~ s/(\s+$|^\s+)//g;
  683:     }
  684:     return;
  685: }
  686: 
  687: sub execute_add {
  688:     my ($context,$caller,$uname,$dom,$auth,$authparam,$first,$middle,$last,
  689:         $gene,$pid,$usec,$end,$start,$emailenc,$credits,$cid,$addresult,
  690:         $enrollcount,$linefeed,$logmsg) = @_;
  691: # Get the user's information and authentication
  692:     my %userenv = &Apache::lonnet::get('environment',['firstname','middlename','lastname','generation','id','critnotification','notification','permanentemail','inststatus'],$dom,$uname);
  693:     my ($tmp) = keys(%userenv);
  694:     if ($tmp =~ /^(con_lost|error)/i) {
  695:         %userenv = ();
  696:     }
  697: # Get the user's e-mail address
  698:     if ($userenv{critnotification} =~ m/%40/) {
  699:         unless ($emailenc eq $userenv{critnotification}) {
  700:             $$logmsg .= &mt('Current critical notification e-mail - [_1] for [_2] is different to e-mail address in institutional classlist - [_3].',
  701:                            $userenv{critnotification},$uname,$emailenc).
  702:                         $linefeed;
  703:         }
  704:     }
  705:     if ($userenv{notification} =~ m/%40/) {
  706:         unless ($emailenc eq $userenv{notification}) {
  707:             $$logmsg .= &mt('Current standard notification e-mail - [_1] for [_2] is different to e-mail address in institutional classlist - [_3].',
  708:                             $userenv{notification},$uname,$emailenc).
  709:                         $linefeed;
  710:         }
  711:     }
  712:     if ($userenv{permanentemail} =~ m/%40/) {
  713:         unless ($emailenc eq $userenv{permanentemail}) {
  714:             $$logmsg .= &mt('Current permanent e-mail
  715: - [_1] for [_2] is different to e-mail address in institutional classlist - [_3]',$userenv{permanentemail},$uname,$emailenc).$linefeed;
  716:         }
  717:     }
  718:     my $krbdefdom = '';
  719:     my $currentauth=&Apache::lonnet::queryauthenticate($uname,$dom);
  720:     if ($currentauth=~/^(krb[45]):(.*)/) {
  721:         $currentauth = $1;
  722:         $krbdefdom = $2;
  723:     } elsif ($currentauth=~ /^(unix|internal|localauth):/) {
  724:         $currentauth = $1;
  725:     } else {
  726:         $$logmsg .= &mt('Invalid authentication method [_1] for [_2].',$currentauth,$uname).$linefeed;
  727:     }
  728: # Report if authentication methods are different.
  729:     if ($currentauth ne $auth) {
  730:         $$logmsg .= &mt("Authentication type mismatch for [_1] - '[_2]' in system, '[_3]' based on information in classlist or default for this course.",$uname,$currentauth,$auth).$linefeed;
  731:     } elsif ($auth =~ m/^krb/) {
  732:         if ($krbdefdom ne $authparam) {
  733:             $$logmsg .= &mt("Kerberos domain mismatch for [_1] - '[_2]' in system, '[_3]' based on information in classlist or default for this course.",$uname,$krbdefdom,$authparam).$linefeed;
  734:         }
  735:     }
  736:                                                                                   
  737: # Check user data
  738:     if ($first  ne $userenv{'firstname'}  ||
  739:         $middle ne $userenv{'middlename'} ||
  740:         $last   ne $userenv{'lastname'}   ||
  741:         $gene   ne $userenv{'generation'} ||
  742:         $pid    ne $userenv{'id'} ||
  743:         $emailenc ne $userenv{'permanentemail'} ) {
  744: # Make the change(s)
  745:         my %changeHash;
  746:         $changeHash{'firstname'}  = $first;
  747:         $changeHash{'middlename'} = $middle;
  748:         $changeHash{'lastname'}   = $last;
  749:         $changeHash{'generation'} = $gene;
  750:         $changeHash{'id'} = $pid;
  751:         $changeHash{'permanentemail'} = $emailenc;
  752:         my $putresult = &Apache::lonnet::put('environment',\%changeHash,$dom,$uname);
  753:         if ($putresult eq 'ok') {
  754:             $$logmsg .= &mt('User information updated for user: [_1] prior to enrollment.',$uname).$linefeed;
  755:         } else {
  756:             $$logmsg .= &mt('There was a problem modifying user data for existing user - [_1] -error: [_2], enrollment will still be attempted.',$uname,$putresult).$linefeed;
  757:         }
  758:     }
  759:                                                                                   
  760: # Assign the role of student in the course.
  761:     my $classlist_reply = 
  762:         &Apache::lonnet::modify_student_enrollment($dom,$uname,$pid,$first,$middle,
  763:                                                    $last,$gene,$usec,$end,$start,
  764:                                                    'auto','',$cid,'',$context,
  765:                                                    $credits);
  766:     if ($classlist_reply eq 'ok') {
  767:         my $access = &showaccess($end,$start);
  768:         my $showsec = $usec;
  769:         if ($usec eq '') {
  770:             $showsec = &mt('none');
  771:         }
  772:         if ($caller eq 'switchtype') {
  773:             $$logmsg .= &mt("Existing user [_1] detected in institutional classlist - switched from 'manual' to 'auto' enrollment in section [_2].",$uname,$showsec).$access.$linefeed;
  774:         } elsif ($caller eq 'newstudent') {
  775:             $$enrollcount ++;
  776:             $$addresult .= "$first $last ($pid) - $uname ".&mt("enrolled in section '[_1]'.",$showsec).$access.$linefeed;
  777:         }
  778:         if ($context eq 'automated') {
  779:             $$logmsg .= &mt('Existing [_1] user [_2] enrolled successfully.',$dom,$uname).$linefeed;
  780:         }
  781:     } else {
  782:            $$logmsg .= &mt('There was a problem updating the classlist db file for user [_1] to show the new enrollment -error: [_2], so no enrollment occurred for this user.',$uname,$classlist_reply).$linefeed;
  783:     }
  784:     return;
  785: }
  786: 
  787: sub datechange_check {
  788:     my ($oldstart,$oldend,$startdate,$enddate) = @_;
  789:     my $datechange = 0;
  790:     unless ($oldstart eq $startdate) {
  791:         $datechange = 1;
  792:     }
  793:     if (!$datechange) {
  794:         if (!$oldend) {
  795:             if ($enddate) {
  796:                 $datechange = 1;
  797:             }
  798:         } elsif ($oldend ne $enddate) {
  799:             $datechange = 1;
  800:         }
  801:     }
  802:     return $datechange;
  803: }
  804: 
  805: sub showaccess {
  806:     my ($end,$start) = @_;
  807:     my $showstart;
  808:     my $showend;
  809:     if ( (!$start) || ($start <= time) ) {
  810:         $showstart = 'immediately';
  811:     } else {
  812:         $showstart = &Apache::lonlocal::locallocaltime($start);
  813:     }
  814:     if (!$end) {
  815:         $showend = 'no end date';
  816:     } else {
  817:         $showend = &Apache::lonlocal::locallocaltime($end);
  818:     }
  819:     my $access_msg = ' '.&mt('Access starts: [_1], ends: [_2].',$showstart,$showend);
  820:     return $access_msg;
  821: }
  822: 
  823: sub parse_classlist {
  824:     my ($tmpdir,$dom,$crs,$class,$placeref,$groupID,$studentsref) = @_;
  825:     my $xmlfile = $tmpdir."/tmp/".$dom."_".$crs."_".$class."_classlist.xml";
  826:     my $uname = '';
  827:     my @state;
  828:     my @items = ('autharg','authtype','email','firstname','generation','lastname','middlename','studentID','credits','inststatus');
  829:     my $p = HTML::Parser->new
  830:     (
  831:         xml_mode => 1,
  832:         start_h =>
  833:             [sub {
  834:                  my ($tagname, $attr) = @_;
  835:                  push @state, $tagname;
  836:                  if ("@state" eq "students student") {
  837:                      $uname = $attr->{username};
  838:                      $$studentsref{$uname}[ $$placeref{'groupID'} ] = $groupID;
  839:                  }
  840:             }, "tagname, attr"],
  841:          text_h =>
  842:              [sub {
  843:                  my ($text) = @_;
  844:                  if ("@state" eq "students student startdate") {
  845:                      my $start = $text;
  846:                      unless ($text eq '') {
  847:                          $start = &process_date($text);
  848:                      }
  849:                      $$studentsref{$uname}[ $$placeref{'startdate'} ] = $start; 
  850:                  } elsif ("@state" eq "students student enddate") {
  851:                      my $end = $text;
  852:                      unless ($text eq '') {
  853:                          $end = &process_date($text);
  854:                      }
  855:                      $$studentsref{$uname}[ $$placeref{'enddate'} ] = $end;
  856:                  } else {
  857:                      foreach my $item (@items) {
  858:                          if ("@state" eq "students student $item") {
  859:                              $$studentsref{$uname}[ $$placeref{$item} ] = $text;
  860:                          }
  861:                      }
  862:                  }
  863:                }, "dtext"],
  864:          end_h =>
  865:                [sub {
  866:                    my ($tagname) = @_;
  867:                    pop @state;
  868:                 }, "tagname"],
  869:     );
  870:                                                                                                              
  871:     $p->parse_file($xmlfile);
  872:     $p->eof;
  873:     if (-e "$xmlfile") {
  874:         unlink $xmlfile;
  875:     }
  876:     return;
  877: }
  878: 
  879: sub process_date {
  880:     my $timestr = shift;
  881:     my $timestamp = '';
  882:     if ($timestr =~ m/^\d{4}:\d{2}:\d{2}/) {
  883:         my @entries = split/:/,$timestr;
  884:         for (my $j=0; $j<@entries; $j++) {
  885:             if ( length($entries[$j]) > 1 ) {
  886:                 $entries[$j] =~ s/^0//;
  887:             }
  888:         }
  889:         $entries[1] = $entries[1] - 1;
  890:         $timestamp =  timelocal($entries[5],$entries[4],$entries[3],$entries[2],$entries[1],$entries[0]);
  891:     }
  892:     return $timestamp;
  893: }
  894: 
  895: sub create_password {
  896:     my $passwd = '';
  897:     my @letts = ("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z");
  898:     for (my $i=0; $i<8; $i++) {
  899:         my $lettnum = int (rand 2);
  900:         my $item = '';
  901:         if ($lettnum) {
  902:             $item = $letts[int( rand(26) )];
  903:             my $uppercase = int(rand 2);
  904:             if ($uppercase) {
  905:                 $item =~ tr/a-z/A-Z/;
  906:             }
  907:         } else {
  908:             $item = int( rand(10) );
  909:         } 
  910:         $passwd .= $item;
  911:     }
  912:     return ($passwd);
  913: }
  914: 
  915: sub get_courseinfo {
  916:     my ($dom,$crs,$courseinfo) = @_;
  917:     my $owner;
  918:     if (defined($dom) && defined($crs)) {
  919:         my %settings = &Apache::lonnet::get('environment',['internal.coursecode','internal.showphoto','description','internal.defaultcredits'],$dom,$crs);
  920:         if ( defined($settings{'internal.coursecode'}) ) {
  921:             $$courseinfo{'inst_code'} = $settings{'internal.coursecode'};
  922:         }
  923:         if ( defined($settings{'description'}) ) {
  924:             $$courseinfo{'description'} = $settings{'description'};
  925:         }
  926:         if ( defined($settings{'internal.showphoto'}) ) {
  927:             $$courseinfo{'showphoto'} = $settings{'internal.showphoto'};
  928:         }
  929:         if ( defined($settings{'internal.credithours'}) ) {
  930:             $$courseinfo{'defaultcredits'} = $settings{'internal.defaultcredits'};
  931:         }
  932:     }
  933:     return;
  934: }
  935: 
  936: sub place_hash {
  937:     my %place = (
  938:                   autharg   => 0,
  939:                   authtype  => 1,
  940:                   email     => 2,
  941:                   enddate   => 3,
  942:                   firstname => 4,
  943:                   generation => 5,
  944:                   groupID    => 6,
  945:                   lastname   => 7,
  946:                   middlename => 8,
  947:                   startdate  => 9,
  948:                   studentID  => 10,
  949:                   credits    => 11,
  950:                   inststatus => 12,
  951:                 );
  952:     return %place;
  953: }
  954: 
  955: sub photo_response_types {
  956:     my %lt = &Apache::lonlocal::texthash(
  957:                       'same' => 'remained unchanged',
  958:                       'update' => 'were updated',
  959:                       'new' => 'were added',
  960:                       'missing' => 'were missing',
  961:                       'error' => 'were not imported because an error occurred',
  962:                       'nouser' => 'were for users without accounts',
  963:                       'noid' => 'were for users without student/employee IDs',
  964: 					 );
  965:     return %lt;
  966: }
  967: 
  968: 
  969: 1;

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