version 1.15, 2005/11/07 15:43:22
|
version 1.33, 2013/03/01 05:20:01
|
Line 33
|
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); |
|
|
# 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'); |
Line 46
|
Line 50
|
|
|
# For each domain ...... |
# For each domain ...... |
foreach my $dom (@domains) { |
foreach my $dom (@domains) { |
#only run if configured to |
#only run if configured to |
if (! &localenroll::run($dom)) { next; } |
my $run_enroll = 0; |
|
my $domsettings; |
|
my %domconfig = |
|
&Apache::lonnet::get_dom('configuration',['autoenroll','coursedefaults'],$dom); |
|
if (ref($domconfig{'autoenroll'}) eq 'HASH') { |
|
$domsettings = $domconfig{'autoenroll'}; |
|
if ($domsettings->{'run'} eq '1') { |
|
$run_enroll = 1; |
|
} |
|
} else { |
|
$run_enroll = &localenroll::run($dom); |
|
} |
|
next if ($run_enroll != 1); |
|
|
$env{'user.domain'} = $dom; |
$env{'user.domain'} = $dom; |
# Determine the courses |
# Initialize language handler |
my %courses = &Apache::lonnet::courseiddump($dom,'.',1,'.','.','.',1,\@hostids); |
&Apache::lonlocal::get_language_handle(); |
|
# Determine the courses |
|
my %courses = &Apache::lonnet::courseiddump($dom,'.',1,'.','.','.',1,\@hostids,'Course'); |
my %affiliates = (); |
my %affiliates = (); |
my %enrollvar = (); |
my %enrollvar = (); |
my %reply = (); |
my %reply = (); |
my %LC_code = (); |
my %LC_code = (); |
foreach my $key (sort keys %courses) { |
my ($showcredits,$domdefcredits); |
my $crs; |
if ((ref($domconfig{'coursedefaults'}) eq 'HASH') && |
if ($key =~ m/^($dom)_(\w+)$/) { |
(ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH')) { |
$crs = $2; |
if ($domconfig{'coursedefaults'}{'coursecredits'}{'official'}) { |
|
$showcredits = 1; |
|
$domdefcredits = $domconfig{'coursedefaults'}{'coursecredits'}{'official'}; |
} |
} |
|
} |
|
foreach my $key (sort keys %courses) { |
|
my %args = ( |
|
one_time => 1, |
|
); |
# Get course settings |
# Get course settings |
my %settings = &Apache::lonnet::dump('environment',$dom,$crs); |
my %settings = &Apache::lonnet::coursedescription($key,\%args); |
|
my $crs = $settings{'num'}; |
|
next if ($settings{'domain'} ne $dom); |
%{$enrollvar{$crs}} = (); |
%{$enrollvar{$crs}} = (); |
@{$affiliates{$crs}} = (); |
@{$affiliates{$crs}} = (); |
%{$LC_code{$crs}} = (); |
%{$LC_code{$crs}} = (); |
Line 73
|
Line 100
|
$enrollvar{$crs}{$item} = &HTML::Entities::decode($settings{$item}); |
$enrollvar{$crs}{$item} = &HTML::Entities::decode($settings{$item}); |
} elsif ($item eq 'default_enrollment_start_date') { |
} elsif ($item eq 'default_enrollment_start_date') { |
$enrollvar{$crs}{startdate} = $settings{$item}; |
$enrollvar{$crs}{startdate} = $settings{$item}; |
} elsif ($item eq 'default_enrollment_end_date') { |
} elsif ($item eq 'default_enrollment_end_date') { |
$enrollvar{$crs}{enddate} = $settings{$item}; |
$enrollvar{$crs}{enddate} = $settings{$item}; |
} |
} |
} |
} |
Line 98
|
Line 125
|
if ($sec =~ m/^(\w+):(\w*)$/ ) { |
if ($sec =~ m/^(\w+):(\w*)$/ ) { |
my $course_id = $enrollvar{$crs}{coursecode}.$1; |
my $course_id = $enrollvar{$crs}{coursecode}.$1; |
my $gp = $2; |
my $gp = $2; |
if (!grep/^$course_id$/,@{$affiliates{$crs}}) { |
if (!grep/^\Q$course_id\E$/,@{$affiliates{$crs}}) { |
push @{$affiliates{$crs}}, $course_id; |
push @{$affiliates{$crs}}, $course_id; |
$LC_code{$crs}{$course_id} = $gp; |
$LC_code{$crs}{$course_id} = $gp; |
} |
} |
Line 108
|
Line 135
|
if ($xlist =~ m/^([^:]+):(\w*)$/) { |
if ($xlist =~ m/^([^:]+):(\w*)$/) { |
my $course_id = $1; |
my $course_id = $1; |
my $gp = $2; |
my $gp = $2; |
if (!grep/^$course_id$/,@{$affiliates{$crs}}) { |
if (!grep/^\Q$course_id\E$/,@{$affiliates{$crs}}) { |
push @{$affiliates{$crs}}, $course_id; |
push @{$affiliates{$crs}}, $course_id; |
$LC_code{$crs}{$course_id} = $gp; |
$LC_code{$crs}{$course_id} = $gp; |
} |
} |
Line 121
|
Line 148
|
|
|
# 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"; |
print $fh "Response from fetch_enrollment_query was $outcome\n"; |
print $fh &mt("Response from [_1] was [_2]",'fetch_enrollment_query',$outcome)."\n"; |
foreach my $crs (sort keys %enrollvar) { |
foreach my $crs (sort keys %enrollvar) { |
my $logmsg = ''; |
my $logmsg = ''; |
my $newusermsg = ''; |
my $newusermsg = ''; |
if ($reply{$crs} > 0) { |
if ($reply{$crs} > 0) { |
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) ) ) { |
if (($enrollvar{$crs}{autoadds} == 1) || ($enrollvar{$crs}{autodrops} == 1)) { |
if (($enrollvar{$crs}{autoadds} == 1) || ($enrollvar{$crs}{autodrops} == 1)) { |
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'); |
my $defaultcredits = $domdefcredits; |
print $fh "Messages start for $crs\n"; |
if ($enrollvar{$crs}{defaultcredits}) { |
|
$defaultcredits = $enrollvar{$crs}{defaultcredits}; |
|
} |
|
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,$affiliates{$crs},$LC_code{$crs},\$logmsg,\$newusermsg,'automated'); |
|
print $fh &mt('Messages start for [_1]',$crs)."\n"; |
print $fh "$logmsg\n"; |
print $fh "$logmsg\n"; |
print $fh "Messages end for $crs\n"; |
print $fh &mt('Messages end for [_1]',$crs)."\n"; |
if ($changecount > 0) { |
if ($changecount > 0) { |
unless ($enrollvar{$crs}{notifylist} eq '') { |
# Set $env{'user.name'}, $env{'user.domain'}, $env{'user.home'} |
# Send message about enrollment changes to notifylist. |
# and $env{'request.course.id'} for use by logging in lonmsg |
# Set $env{'user.name'}, $env{'user.home'} for use by logging in lonmsg |
$env{'request.course.id'} = $dom.'_'.$crs; |
unless ( ($enrollvar{$crs}{'courseowner'} eq '') || (!defined($enrollvar{$crs}{'courseowner'}) ) ) { |
my ($ownername,$ownerdom); |
$env{'user.name'} = $enrollvar{$crs}{'courseowner'}; |
if ($enrollvar{$crs}{'courseowner'} ne '') { |
$env{'user.home'} = &Apache::lonnet::homeserver($env{'user.name'},$dom); |
if ($enrollvar{$crs}{'courseowner'} =~ /:/) { |
|
($ownername,$ownerdom) = |
my $subject = "Student enrollment changes in $enrollvar{$crs}{coursecode}"; |
split(/:/,$enrollvar{$crs}{'courseowner'}); |
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; |
} else { |
unless ($newusermsg eq '') { |
$ownername = $enrollvar{$crs}{'courseowner'}; |
$message .= "\n".$newusermsg; |
$ownerdom = $dom; |
} |
} |
my @to_notify = (); |
} |
if ($enrollvar{$crs}{notifylist} =~ m/,/) { |
$env{'user.name'} = $ownername; |
@to_notify = split/,/,$enrollvar{$crs}{notifylist}; |
$env{'user.domain'} = $ownerdom; |
} else { |
if (ref($domsettings) eq 'HASH') { |
$to_notify[0] = $enrollvar{$crs}{notifylist}; |
if (($domsettings->{'sender_uname'} ne '') && |
} |
($domsettings->{'sender_domain'} ne '')) { |
foreach my $cc (@to_notify) { |
$env{'user.name'} = $domsettings->{'sender_uname'}; |
my ($ccname,$ccdom) = split/@/,$cc; |
$env{'user.domain'} = $domsettings->{'sender_domain'}; |
my $status = &Apache::lonmsg::user_normal_msg($ccname,$ccdom,$subject,$message); |
} |
|
} |
|
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); |
} |
} |
if ( ($enrollvar{$crs}{notifylist} eq '') && ($newusermsg ne '') ) { |
} |
my $subject = "New user accounts in $enrollvar{$crs}{'coursecode'}"; |
} else { |
my $status = &Apache::lonmsg::user_normal_msg($env{'user.name'},$dom,$subject,$newusermsg); |
$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) { |
|
my ($ccname,$ccdom); |
|
if ($cc =~ /:/) { |
|
($ccname,$ccdom) = split(/:/,$cc); |
|
} elsif ($cc =~ /\@/) { |
|
($ccname,$ccdom) = split(/\@/,$cc); |
} |
} |
delete($env{'user.name'}); |
push(@recusers,$ccname); |
delete($env{'user.home'}); |
push(@recudoms,$ccdom); |
|
$msgcc->{$ccname.':'.$ccdom}=''; |
|
$numsent ++; |
|
} |
|
my %reciphash = ( |
|
cc => $msgcc, |
|
); |
|
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{'form.can_reply'}); |
} |
} |
|
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 "No institutional classlist data could be retrieved for $crs\n"; |
print $fh &mt('No institutional classlist data could be retrieved for [_1]',$crs)."\n"; |
} else { |
} else { |
print $fh "Not within time window for auto-enrollment in $crs\n"; |
print $fh &mt('Not within time window for auto-enrollment in [_1]',$crs)."\n"; |
} |
} |
} else { |
} else { |
print $fh "Auto-enrollment not currently enabled for $crs\n"; |
print $fh &mt('Auto-enrollment not currently enabled for [_1]',$crs)."\n"; |
} |
} |
} |
} |
} |
} |
print $fh "-- ".localtime(time)." Enrollment messages end\n*******************\n\n"; |
print $fh "-- ".localtime(time).' '.&mt('Enrollment messages end')."\n*******************\n\n"; |
close($fh); |
close($fh); |
delete($env{'user.domain'}); |
delete($env{'user.domain'}); |
# Check for photos |
|
} |
} |
|
|
1; |
1; |