version 1.1, 2005/03/04 15:09:06
|
version 1.11, 2010/01/31 18:06:10
|
Line 2
|
Line 2
|
# |
# |
# Automated Course Creation script |
# Automated Course Creation script |
# |
# |
|
# $Id$ |
|
# |
# Copyright Michigan State University Board of Trustees |
# Copyright Michigan State University Board of Trustees |
# |
# |
# This file is part of the LearningOnline Network with CAPA (LON-CAPA). |
# This file is part of the LearningOnline Network with CAPA (LON-CAPA). |
Line 34
|
Line 36
|
use strict; |
use strict; |
use lib '/home/httpd/lib/perl'; |
use lib '/home/httpd/lib/perl'; |
use Apache::lonnet; |
use Apache::lonnet; |
|
use Apache::lonlocal; |
use LONCAPA::batchcreatecourse; |
use LONCAPA::batchcreatecourse; |
use LONCAPA::Configuration; |
use LONCAPA::Configuration; |
|
use LONCAPA(); |
|
|
my $perlvarref = &LONCAPA::Configuration::read_conf('loncapa.conf'); |
my $perlvarref = &LONCAPA::Configuration::read_conf('loncapa.conf'); |
my $logfile = $$perlvarref{'lonDaemons'}.'/logs/autocreate.log'; |
my $logfile = $$perlvarref{'lonDaemons'}.'/logs/autocreate.log'; |
Line 60
|
Line 64
|
close($fh); |
close($fh); |
exit; |
exit; |
} |
} |
|
|
|
# Initialize language handler |
|
&Apache::lonlocal::get_language_handle(); |
|
|
my $batchdir = $$perlvarref{'lonDaemons'}.'/tmp/addcourse/'.$defdom.'/auto'; |
my $batchdir = $$perlvarref{'lonDaemons'}.'/tmp/addcourse/'.$defdom.'/auto'; |
opendir(DIR,"$batchdir/pending"); |
opendir(DIR,"$batchdir/pending"); |
my @requests = grep(!/^\.\.?$/,readdir(DIR)); |
my @requests = grep(!/^\.\.?$/,readdir(DIR)); |
closedir(DIR); |
closedir(DIR); |
my %courseids = (); |
my %courseids = (); |
my $cccflag = 0; |
my @permissions = ('mau','ccc','cin','cta','cep','ccr','cst'); |
unless ($ENV{'allowed.ccc'}) { |
my %permissionflags = (); |
$ENV{'allowed.ccc'} = 'F'; |
&set_permissions(\%permissionflags,\@permissions); |
$cccflag = 1; |
$env{'user.name'} = $dcname; |
} |
$env{'user.domain'} = $dcdom; |
|
$env{'request.role.domain'} = $defdom; |
my $wwwid=getpwnam('www'); |
my $wwwid=getpwnam('www'); |
if ($wwwid!=$<) { |
if ($wwwid!=$<) { |
my $emailto=$$perlvarref{'lonAdmEMail'}; |
my $emailto=$$perlvarref{'lonAdmEMail'}; |
Line 94
|
Line 102
|
exit; |
exit; |
} |
} |
|
|
my ($output,$logmsg) = &LONCAPA::batchcreatecourse::create_courses(\@requests,\%courseids,'auto',$defdom,$dcname,$dcdom); |
print $fh "Sending to batch - auto,$defdom,$dcname,$dcdom ".join(":",@requests)."\n"; |
|
my ($result,$logmsg) = &LONCAPA::batchcreatecourse::create_courses(\@requests,\%courseids,'auto',$defdom,$dcname,$dcdom); |
|
my $outcome; |
|
if ($result ne '') { |
|
$outcome = $result."\n"; |
|
} |
|
if ($logmsg ne '') { |
|
$outcome .= $logmsg."\n"; |
|
} |
|
print $fh $outcome; |
|
|
|
my $output; |
# Copy requests from pending directory to processed directory and unlink. |
# Copy requests from pending directory to processed directory and unlink. |
foreach my $request (@requests) { |
foreach my $request (@requests) { |
if ((-e "$batchdir/pending/$request") && $request !~ /\.\./ && $request ne '' &&$request ne './') { |
if ((-e "$batchdir/pending/$request") && $request !~ /\.\./ && $request ne '' &&$request ne './') { |
open(FILE,"<$batchdir/pending/$request"); |
open(FILE,"<$batchdir/pending/$request"); |
my @buffer = <FILE>; |
my @buffer = <FILE>; |
close(FILE); |
close(FILE); |
|
if (!-e "$batchdir/processed") { |
|
mkdir("$batchdir/processed", 0755); |
|
} |
open(FILE,">$batchdir/processed/$request"); |
open(FILE,">$batchdir/processed/$request"); |
print FILE @buffer; |
print FILE @buffer; |
close(FILE); |
close(FILE); |
Line 112
|
Line 133
|
} |
} |
|
|
foreach my $key (sort keys %courseids) { |
foreach my $key (sort keys %courseids) { |
print $fh "created course: $key\n"; |
print $fh "created course: $key - $courseids{$key}\n"; |
} |
my $newcourse = &LONCAPA::escape($key.':'.$courseids{$key}); |
|
$output .= $newcourse.':'; |
if ($cccflag) { |
} |
delete($ENV{'allowed.ccc'}); |
$output =~ s/:$//; |
} |
print $output; |
|
|
|
&unset_permissions(\%permissionflags); |
|
delete($env{'user.name'}); |
|
delete($env{'user.domain'}); |
|
delete($env{'request.role.domain'}); |
print $fh "-- ".localtime(time)." Autocreation messages end\n*******************\n\n"; |
print $fh "-- ".localtime(time)." Autocreation messages end\n*******************\n\n"; |
close($fh); |
close($fh); |
|
|
Line 139 sub check_activedc {
|
Line 165 sub check_activedc {
|
} |
} |
return $activedc; |
return $activedc; |
} |
} |
|
|
|
sub set_permissions { |
|
my ($permissionflags,$permissions) = @_; |
|
foreach my $allowtype (@{$permissions}) { |
|
unless($env{"allowed.$allowtype"}) { |
|
$env{"allowed.$allowtype"} = 'F'; |
|
$permissionflags{$allowtype} = 1; |
|
} |
|
} |
|
} |
|
|
|
sub unset_permissions { |
|
my ($permissionflags) = @_; |
|
foreach my $allowtype (keys %{$permissionflags}) { |
|
delete($env{"allowed.$allowtype"}); |
|
} |
|
} |