version 1.10, 2004/06/09 17:01:56
|
version 1.37, 2022/01/13 03:50:32
|
Line 25
|
Line 25
|
# |
# |
# http://www.lon-capa.org/ |
# http://www.lon-capa.org/ |
# |
# |
|
|
use strict; |
use strict; |
use lib '/home/httpd/lib/perl'; |
use lib '/home/httpd/lib/perl'; |
use localenroll; |
use localenroll; |
Line 34
|
Line 33
|
use Apache::lonnet; |
use Apache::lonnet; |
use Apache::loncoursedata; |
use Apache::loncoursedata; |
use Apache::lonmsg; |
use Apache::lonmsg; |
|
use Apache::longroup; |
|
use Apache::loncommon; |
|
use Apache::lonlocal; |
use HTML::Entities; |
use HTML::Entities; |
|
use LONCAPA qw(:match); |
#only run if configured to |
|
if (! &localenroll::run()) { exit; } |
|
|
|
# Determine the library server's domain and hostID |
# Determine the library server's domain and hostID |
my $perlvarref = LONCAPA::Configuration::read_conf('loncapa.conf'); |
my $perlvarref = LONCAPA::Configuration::read_conf('loncapa.conf'); |
my $dom = $$perlvarref{'lonDefDomain'}; |
|
my $logfile = $$perlvarref{'lonDaemons'}.'/logs/autoenroll.log'; |
my $logfile = $$perlvarref{'lonDaemons'}.'/logs/autoenroll.log'; |
$ENV{'user.domain'} = $dom; |
my @domains = &Apache::lonnet::current_machine_domains(); |
my $hostid = $$perlvarref{'lonHostID'}; |
my @hostids = &Apache::lonnet::current_machine_ids(); |
|
|
# Determine the present time; |
# Determine the present time; |
my $timenow = time(); |
my $timenow = time(); |
|
|
# Determine the courses |
# For each domain ...... |
my %courses = &Apache::lonnet::courseiddump($dom,'.',1,$hostid); |
foreach my $dom (@domains) { |
my %affiliates = (); |
#only run if configured to |
my %enrollvar = (); |
my $run_enroll = 0; |
my %reply = (); |
my ($domsettings,$autofailsafe,$autofailsafetype); |
my %LC_code = (); |
my %domconfig = |
foreach my $key (sort keys %courses) { |
&Apache::lonnet::get_dom('configuration',['autoenroll','coursedefaults'],$dom); |
my $crs; |
if (ref($domconfig{'autoenroll'}) eq 'HASH') { |
if ($key =~ m/^($dom)_(\w+)$/) { |
$domsettings = $domconfig{'autoenroll'}; |
$crs = $2; |
if ($domsettings->{'run'} eq '1') { |
|
$run_enroll = 1; |
|
} |
|
if ($domsettings->{'autofailsafe'} ne '') { |
|
$autofailsafe = $domsettings->{'autofailsafe'}; |
|
} |
|
if ($domsettings->{'failsafe'} =~ /^(zero|any|off)$/) { |
|
$autofailsafetype = $domsettings->{'failsafe'}; |
|
} |
|
} else { |
|
$run_enroll = &localenroll::run($dom); |
} |
} |
|
next if ($run_enroll != 1); |
|
|
# Get course settings |
$env{'user.domain'} = $dom; |
my %settings = &Apache::lonnet::dump('environment',$dom,$crs); |
# Initialize language handler |
%{$enrollvar{$crs}} = (); |
&Apache::lonlocal::get_language_handle(); |
@{$affiliates{$crs}} = (); |
# Determine the courses |
%{$LC_code{$crs}} = (); |
my %courses = &Apache::lonnet::courseiddump($dom,'.',1,'.','.','.',1,\@hostids,'Course'); |
foreach my $item (keys %settings) { |
my %affiliates = (); |
if ($item =~ m/^internal\.(.+)$/) { |
my %unclutteredsec = (); |
$enrollvar{$crs}{$1} = $settings{$item}; |
my %unclutteredlcsec = (); |
} elsif ($item eq 'description') { |
my %enrollvar = (); |
$enrollvar{$crs}{$item} = &HTML::Entities::decode($settings{$item}); |
my %reply = (); |
|
my %LC_code = (); |
|
my ($showcredits,$domdefcredits); |
|
if ((ref($domconfig{'coursedefaults'}) eq 'HASH') && |
|
(ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH')) { |
|
if ($domconfig{'coursedefaults'}{'coursecredits'}{'official'}) { |
|
$showcredits = 1; |
|
$domdefcredits = $domconfig{'coursedefaults'}{'coursecredits'}{'official'}; |
} |
} |
} |
} |
if (($enrollvar{$crs}{autostart} <= $timenow) && ( ($enrollvar{$crs}{autoend} > $timenow) || ($enrollvar{$crs}{autoend} == 0) ) ) { |
foreach my $key (sort keys %courses) { |
if ( ($enrollvar{$crs}{autoadds} == 1) || ($enrollvar{$crs}{autodrops} == 1) ) { |
my %args = ( |
# Add to list of classes for retrieval |
one_time => 1, |
$enrollvar{$crs}{sectionnums} =~ s/ //g; |
); |
$enrollvar{$crs}{crosslistings} =~ s/ //g; |
# Get course settings |
my @sections = (); |
my %settings = &Apache::lonnet::coursedescription($key,\%args); |
my @crosslistings = (); |
my $crs = $settings{'num'}; |
if ($enrollvar{$crs}{sectionnums} =~ m/,/) { |
next if ($settings{'domain'} ne $dom); |
@sections = split/,/,$enrollvar{$crs}{sectionnums}; |
%{$enrollvar{$crs}} = (); |
} else { |
@{$affiliates{$crs}} = (); |
$sections[0] = $enrollvar{$crs}{sectionnums}; |
%{$LC_code{$crs}} = (); |
} |
foreach my $item (keys %settings) { |
if ($enrollvar{$crs}{crosslistings} =~ m/,/) { |
if ($item =~ m/^internal\.(.+)$/) { |
@crosslistings = split/,/,$enrollvar{$crs}{crosslistings} |
$enrollvar{$crs}{$1} = $settings{$item}; |
} else { |
} elsif ($item eq 'description') { |
@crosslistings = $enrollvar{$crs}{crosslistings}; |
$enrollvar{$crs}{$item} = &HTML::Entities::decode($settings{$item}); |
|
} elsif ($item eq 'default_enrollment_start_date') { |
|
$enrollvar{$crs}{startdate} = $settings{$item}; |
|
} elsif ($item eq 'default_enrollment_end_date') { |
|
$enrollvar{$crs}{enddate} = $settings{$item}; |
} |
} |
foreach my $sec (@sections) { |
} |
if ($sec =~ m/^(\w+):(\w*)$/ ) { |
if (($enrollvar{$crs}{autostart} <= $timenow) && ( ($enrollvar{$crs}{autoend} > $timenow) || ($enrollvar{$crs}{autoend} == 0) ) ) { |
my $course_id = $enrollvar{$crs}{coursecode}.$1; |
if ( ($enrollvar{$crs}{autoadds} == 1) || ($enrollvar{$crs}{autodrops} == 1) ) { |
my $gp = $2; |
# Add to list of classes for retrieval |
if (!grep/^$course_id$/,@{$affiliates{$crs}}) { |
$enrollvar{$crs}{sectionnums} =~ s/ //g; |
push @{$affiliates{$crs}}, $course_id; |
$enrollvar{$crs}{crosslistings} =~ s/ //g; |
$LC_code{$crs}{$course_id} = $gp; |
my @sections = (); |
|
my @crosslistings = (); |
|
if ($enrollvar{$crs}{sectionnums} =~ m/,/) { |
|
@sections = split/,/,$enrollvar{$crs}{sectionnums}; |
|
} else { |
|
$sections[0] = $enrollvar{$crs}{sectionnums}; |
|
} |
|
if ($enrollvar{$crs}{crosslistings} =~ m/,/) { |
|
@crosslistings = split/,/,$enrollvar{$crs}{crosslistings}; |
|
} else { |
|
@crosslistings = $enrollvar{$crs}{crosslistings}; |
|
} |
|
my $crscode = $enrollvar{$crs}{coursecode}; |
|
my $crskey = $crs.':'.$crscode; |
|
@{$unclutteredsec{$crskey}} = (); |
|
@{$unclutteredlcsec{$crskey}} = (); |
|
foreach my $sec (@sections) { |
|
if ($sec =~ m/^(\w+):(\w*)$/ ) { |
|
my $instsec = $1; |
|
my $gp = $2; |
|
unless (grep/^\Q$instsec\E$/,@{$unclutteredsec{$crskey}}) { |
|
push(@{$unclutteredsec{$crskey}},$instsec); |
|
push(@{$unclutteredlcsec{$crskey}},$gp); |
|
} |
} |
} |
} |
} |
} |
foreach my $xlist (@crosslistings) { |
foreach my $xlist (@crosslistings) { |
if ($xlist =~ m/^([^:]+):(\w*)$/) { |
if ($xlist =~ m/^(\w+):(\w*)$/) { |
my $course_id = $1; |
my $course_id = $1; |
my $gp = $2; |
my $gp = $2; |
if (!grep/^\Q$course_id\E$/,@{$affiliates{$crs}}) { |
if (!grep/^$course_id$/,@{$affiliates{$crs}}) { |
push @{$affiliates{$crs}}, $course_id; |
push @{$affiliates{$crs}}, $course_id; |
$LC_code{$crs}{$course_id} = $gp; |
$LC_code{$crs}{$course_id} = $gp; |
} |
} |
} |
} |
} |
} |
} |
} |
} |
} |
} |
} |
my %formattedsec = &Apache::lonnet::auto_instsec_reformat($dom,'clutter',\%unclutteredsec); |
my $outcome = &Apache::lonnet::fetch_enrollment_query('automated',$dom,\%affiliates,\%reply); |
foreach my $crskey (keys(%formattedsec)) { |
|
my ($crs,$instcode) = split(/:/,$crskey); |
|
if ((ref($formattedsec{$crskey}) eq 'ARRAY') && (ref($unclutteredlcsec{$crskey}) eq 'ARRAY')) { |
|
for (my $i=0; $i<@{$formattedsec{$crskey}}; $i++) { |
|
my $course_id = $instcode.$formattedsec{$crskey}[$i]; |
|
unless (grep/^\Q$course_id\E$/,@{$affiliates{$crs}}) { |
|
push(@{$affiliates{$crs}},$course_id); |
|
$LC_code{$crs}{$course_id} = $unclutteredlcsec{$crskey}[$i]; |
|
} |
|
} |
|
} |
|
} |
|
my $outcome = &Apache::lonnet::fetch_enrollment_query('automated',\%affiliates,\%reply,$dom); |
|
|
# Now go through classes and perform required enrollment changes. |
# Now go through classes and perform required enrollment changes. |
open (my $fh,">>$logfile"); |
open (my $fh,">>$logfile"); |
print $fh "********************\n".localtime(time)." Enrollment messages start --\n"; |
print $fh "********************\n".localtime(time).' '.&mt('Enrollment messages start').' --'."\n"; |
foreach my $crs (sort keys %enrollvar) { |
print $fh &mt("Response from [_1] was [_2]",'fetch_enrollment_query',$outcome)."\n"; |
my $logmsg = ''; |
foreach my $crs (sort keys %enrollvar) { |
my $newusermsg = ''; |
my $logmsg = ''; |
if ($reply{$crs} > 0) { |
my $newusermsg = ''; |
if ( ($enrollvar{$crs}{autostart} < $timenow) && ( ($enrollvar{$crs}{autoend} > $timenow) || ($enrollvar{$crs}{autoend} == 0) ) ) { |
if ($reply{$crs} > 0) { |
if (($enrollvar{$crs}{autoadds} == 1) || ($enrollvar{$crs}{autodrops} == 1)) { |
if ( ($enrollvar{$crs}{autostart} < $timenow) && ( ($enrollvar{$crs}{autoend} > $timenow) || ($enrollvar{$crs}{autoend} == 0) ) ) { |
my ($changecount,$response) = &LONCAPA::Enrollment::update_LC($dom,$crs,$enrollvar{$crs}{autoadds},$enrollvar{$crs}{autodrops},$enrollvar{$crs}{startdate},$enrollvar{$crs}{enddate},$enrollvar{$crs}{authtype},$enrollvar{$crs}{autharg},\@{$affiliates{$crs}},\%{$LC_code{$crs}},\$logmsg,\$newusermsg,'automated'); |
if (($enrollvar{$crs}{autoadds} == 1) || ($enrollvar{$crs}{autodrops} == 1)) { |
print $fh "Messages start for $crs\n"; |
my $defaultcredits = $domdefcredits; |
print $fh "$logmsg\n"; |
if ($enrollvar{$crs}{defaultcredits}) { |
print $fh "Messages end for $crs\n"; |
$defaultcredits = $enrollvar{$crs}{defaultcredits}; |
if ($changecount > 0) { |
} |
unless ($enrollvar{$crs}{notifylist} eq '') { |
my $failsafe = $autofailsafe; |
# Send message about enrollment changes to notifylist. |
if ($enrollvar{$crs}{'autodropfailsafe'}) { |
# Set $ENV{'user.name'}, $ENV{'user.home'} for use by logging in lonmsg |
$failsafe = $enrollvar{$crs}{'autodropfailsafe'}; |
unless ( ($enrollvar{$crs}{'courseowner'} eq '') || (!defined($enrollvar{$crs}{'courseowner'}) ) ) { |
} |
$ENV{'user.name'} = $enrollvar{$crs}{'courseowner'}; |
my $failsafetype = $autofailsafetype; |
$ENV{'user.home'} = &Apache::lonnet::homeserver($ENV{'user.name'},$dom); |
if ($enrollvar{$crs}{'autodropfailsafetype'}) { |
|
$failsafetype = $enrollvar{$crs}{'autodropfailsafetype'}; |
my $subject = "Student enrollment changes in $enrollvar{$crs}{coursecode}"; |
} |
my $message = "The following $changecount change(s) occurred in $enrollvar{$crs}{description} - $enrollvar{$crs}{coursecode} as a result of the automated classlist update:\n\n".$response; |
my ($changecount,$response) = &LONCAPA::Enrollment::update_LC($dom,$crs,$enrollvar{$crs}{autoadds},$enrollvar{$crs}{autodrops},$enrollvar{$crs}{startdate},$enrollvar{$crs}{enddate},$enrollvar{$crs}{authtype},$enrollvar{$crs}{autharg},$showcredits,$defaultcredits,$failsafe,$failsafetype,$affiliates{$crs},$LC_code{$crs},\$logmsg,\$newusermsg,'automated'); |
unless ($newusermsg eq '') |
print $fh &mt('Messages start for [_1]',$crs)."\n"; |
{ |
print $fh "$logmsg\n"; |
$message .= "\n".$newusermsg; |
print $fh &mt('Messages end for [_1]',$crs)."\n"; |
} |
if ($changecount > 0) { |
my @to_notify = (); |
# Set $env{'user.name'}, $env{'user.domain'}, $env{'user.home'} |
if ($enrollvar{$crs}{notifylist} =~ m/,/) { |
# and $env{'request.course.id'} for use by logging in lonmsg |
@to_notify = split/,/,$enrollvar{$crs}{notifylist}; |
$env{'request.course.id'} = $dom.'_'.$crs; |
|
my ($ownername,$ownerdom); |
|
if ($enrollvar{$crs}{'courseowner'} ne '') { |
|
if ($enrollvar{$crs}{'courseowner'} =~ /:/) { |
|
($ownername,$ownerdom) = |
|
split(/:/,$enrollvar{$crs}{'courseowner'}); |
} else { |
} else { |
$to_notify[0] = $enrollvar{$crs}{notifylist}; |
$ownername = $enrollvar{$crs}{'courseowner'}; |
|
$ownerdom = $dom; |
} |
} |
|
} |
|
$env{'user.name'} = $ownername; |
|
$env{'user.domain'} = $ownerdom; |
|
if (ref($domsettings) eq 'HASH') { |
|
if (($domsettings->{'sender_uname'} ne '') && |
|
($domsettings->{'sender_domain'} ne '')) { |
|
$env{'user.name'} = $domsettings->{'sender_uname'}; |
|
$env{'user.domain'} = $domsettings->{'sender_domain'}; |
|
} |
|
} |
|
if ($enrollvar{$crs}{notifylist} eq '') { |
|
if ($newusermsg ne '') { |
|
if (($ownername =~ /^$match_username$/) && |
|
($ownerdom =~ /^$match_domain$/)) { |
|
my $subject = &mt('New user accounts in [_1]',$enrollvar{$crs}{'coursecode'}); |
|
my $status = &Apache::lonmsg::user_normal_msg($ownername,$ownerdom,$subject,$newusermsg); |
|
} |
|
} |
|
} else { |
|
$env{'form.can_reply'} = 'N'; |
|
my $msgcc; |
|
# Send message about enrollment changes to notifylist. |
|
$env{'user.home'} = &Apache::lonnet::homeserver($env{'user.name'},$env{'user.domain'}); |
|
my $subject = &mt('Student enrollment changes in [_1]',$enrollvar{$crs}{coursecode}); |
|
my $message = &mt('The following [quant,_1,change] occurred in [_2] - [_3] as a result of the automated classlist update:',$changecount,$enrollvar{$crs}{description},$enrollvar{$crs}{coursecode})."\n\n".$response; |
|
unless ($newusermsg eq '') { |
|
$message .= "\n".$newusermsg; |
|
} |
|
my @to_notify = split(/,/,$enrollvar{$crs}{notifylist}); |
|
my $numsent = 0; |
|
my @recusers; |
|
my @recudoms; |
foreach my $cc (@to_notify) { |
foreach my $cc (@to_notify) { |
my ($ccname,$ccdom) = split/@/,$cc; |
my ($ccname,$ccdom); |
my $status = &Apache::lonmsg::user_normal_msg($ccname,$ccdom,$subject,$message); |
if ($cc =~ /:/) { |
|
($ccname,$ccdom) = split(/:/,$cc); |
|
} elsif ($cc =~ /\@/) { |
|
($ccname,$ccdom) = split(/\@/,$cc); |
|
} |
|
push(@recusers,$ccname); |
|
push(@recudoms,$ccdom); |
|
$msgcc->{$ccname.':'.$ccdom}=''; |
|
$numsent ++; |
} |
} |
if ( ($enrollvar{$crs}{notifylist} eq '') && ($newusermsg ne '') ) { |
my %reciphash = ( |
my $subject = "New user accounts in $enrollvar{$crs}{'coursecode'}"; |
cc => $msgcc, |
my $status = &Apache::lonmsg::user_normal_msg($ENV{'user.name'},$dom,$subject,$newusermsg); |
); |
|
my %sentmessage; |
|
my $stamp = time; |
|
my $msgcount = &Apache::lonmsg::get_uniq(); |
|
&Apache::lonmsg::process_sent_mail($subject,'',$numsent,$stamp,$env{'user.name'},$env{'user.domain'},$msgcount,$crs,$$,$message,\@recusers,\@recudoms); |
|
my ($recipid,$recipstatus) = |
|
&Apache::lonmsg::store_recipients($subject, |
|
$env{'user.name'},$env{'user.domain'},\%reciphash); |
|
foreach my $recip (sort(keys(%{$msgcc}))) { |
|
my ($ccname,$ccdom) = split(/:/,$recip); |
|
my $status = |
|
&Apache::lonmsg::user_normal_msg($ccname,$ccdom,$subject,$message,undef,undef,undef,undef,\%sentmessage,undef,undef,undef,1,$recipid); |
} |
} |
delete($ENV{'user.name'}); |
delete($env{'form.can_reply'}); |
delete($ENV{'user.home'}); |
|
} |
} |
|
delete($env{'user.name'}); |
|
delete($env{'user.home'}); |
|
delete($env{'request.course.id'}); |
|
$env{'user.domain'} = $dom; |
} |
} |
} |
} |
} |
} |
} |
} else { |
} else { |
if ( ($enrollvar{$crs}{autoadds} == 1) || ($enrollvar{$crs}{autodrops} == 1) ) { |
if ( ($enrollvar{$crs}{autoadds} == 1) || ($enrollvar{$crs}{autodrops} == 1) ) { |
if ( ($enrollvar{$crs}{autostart} < $timenow) && ( ($enrollvar{$crs}{autoend} > $timenow) || ($enrollvar{$crs}{autoend} == 0) ) ) { |
if ( ($enrollvar{$crs}{autostart} < $timenow) && ( ($enrollvar{$crs}{autoend} > $timenow) || ($enrollvar{$crs}{autoend} == 0) ) ) { |
print $fh &mt('No institutional classlist data could be retrieved for [_1]',$crs)."\n"; |
print $fh "No institutional classlist data could be retrieved for $crs\n"; |
} else { |
|
print $fh &mt('Not within time window for auto-enrollment in [_1]',$crs)."\n"; |
|
} |
} else { |
} else { |
print $fh "Not within time window for auto-enrollment in $crs\n"; |
print $fh &mt('Auto-enrollment not currently enabled for [_1]',$crs)."\n"; |
} |
} |
} else { |
|
print $fh "Auto-enrollment not currently enabled for $crs\n"; |
|
} |
} |
} |
} |
|
print $fh "-- ".localtime(time).' '.&mt('Enrollment messages end')."\n*******************\n\n"; |
|
close($fh); |
|
delete($env{'user.domain'}); |
} |
} |
print $fh "-- ".localtime(time)." Enrollment messages end\n*******************\n\n"; |
|
close($fh); |
|
delete($ENV{'user.domain'}); |
|
|
|
# Check for photos |
|
|
|
1; |
1; |