File:  [LON-CAPA] / loncom / enrollment / Enrollment.pm
Revision 1.45: download - view: text, annotated - select for diffs
Wed Jul 24 18:21:49 2013 UTC (10 years, 10 months ago) by bisitz
Branches: MAIN
CVS tags: HEAD
- Coding style
  - Add line feeds between sentences in message sent to user, to improve readability for developers.

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

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