--- loncom/enrollment/Autoenroll.pl 2003/12/11 15:39:37 1.5 +++ loncom/enrollment/Autoenroll.pl 2004/06/08 22:09:44 1.9 @@ -1,7 +1,7 @@ #!/usr/bin/perl # #Automated Enrollment script -# $Id: Autoenroll.pl,v 1.5 2003/12/11 15:39:37 albertel Exp $ +# $Id: Autoenroll.pl,v 1.9 2004/06/08 22:09:44 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -36,17 +36,21 @@ use Apache::lonmsg; use HTML::Entities; -# Determine the library server's domain +#only run if configured to + if (! &localenroll::run()) { exit; } + +# Determine the library server's domain and hostID my $perlvarref = LONCAPA::Configuration::read_conf('loncapa.conf'); my $dom = $$perlvarref{'lonDefDomain'}; my $logfile = $$perlvarref{'lonDaemons'}.'/logs/autoenroll.log'; $ENV{'user.domain'} = $dom; + my $hostid = $$perlvarref{'lonHostID'}; # Determine the present time; my $timenow = time(); # Determine the courses - my %courses = &Apache::lonnet::courseiddump($dom,'.',1); + my %courses = &Apache::lonnet::courseiddump($dom,'.',1,$hostid); my %affiliates = (); my %enrollvar = (); my %reply = (); @@ -69,7 +73,7 @@ $enrollvar{$crs}{$item} = &HTML::Entities::decode($settings{$item}); } } - if (($enrollvar{$crs}{autostart} <= $timenow) && ($enrollvar{$crs}{autoend} > $timenow)) { + if (($enrollvar{$crs}{autostart} <= $timenow) && ( ($enrollvar{$crs}{autoend} > $timenow) || ($enrollvar{$crs}{autoend} == 0) ) ) { if ( ($enrollvar{$crs}{autoadds} == 1) || ($enrollvar{$crs}{autodrops} == 1) ) { # Add to list of classes for retrieval $enrollvar{$crs}{sectionnums} =~ s/ //g; @@ -109,7 +113,7 @@ } } } - &localenroll::fetch_enrollment($dom,\%affiliates,\%reply); + my $outcome = &Apache::lonnet::fetch_enrollment_query($hostid,$dom,\%affiliates,\%reply); # Now go through classes and perform required enrollment changes. open (my $fh,">>$logfile"); @@ -118,7 +122,7 @@ my $logmsg = ''; my $newusermsg = ''; if ($reply{$crs} > 0) { - if (($enrollvar{$crs}{autostart} < $timenow) && ($enrollvar{$crs}{autoend} > $timenow)) { + if ( ($enrollvar{$crs}{autostart} < $timenow) && ( ($enrollvar{$crs}{autoend} > $timenow) || ($enrollvar{$crs}{autoend} == 0) ) ) { 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'); print $fh "Messages start for $crs\n"; @@ -160,7 +164,15 @@ } } } else { - print $fh "No institutional classlist data could be retrieved for $crs\n"; + if ( ($enrollvar{$crs}{autoadds} == 1) || ($enrollvar{$crs}{autodrops} == 1) ) { + 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"; + } else { + print $fh "Not within time window for auto-enrollment in $crs\n"; + } + } else { + print $fh "Auto-enrollment not currently enabled for $crs\n"; + } } } print $fh "-- ".localtime(time)." Enrollment messages end\n*******************\n\n";