version 1.158.2.3.2.2, 2017/11/17 01:02:28
|
version 1.158.2.5, 2019/07/26 17:27:44
|
Line 84 use Apache::lonclonecourse;
|
Line 84 use Apache::lonclonecourse;
|
use LONCAPA::batchcreatecourse; |
use LONCAPA::batchcreatecourse; |
use LONCAPA qw(:DEFAULT :match); |
use LONCAPA qw(:DEFAULT :match); |
|
|
|
my $registered_flush; |
|
my $registered_instcats; |
|
my $modified_dom; |
|
|
# ===================================================== Phase one: fill-in form |
# ===================================================== Phase one: fill-in form |
|
|
sub print_course_creation_page { |
sub print_course_creation_page { |
Line 731 sub create_course {
|
Line 735 sub create_course {
|
'<p>'.&mt('Course identifier to share with students: [_1]',$code).'</p>' |
'<p>'.&mt('Course identifier to share with students: [_1]',$code).'</p>' |
); |
); |
} |
} |
# Flush the course logs so reverse user roles immediately updated |
if ($env{'form.crscode'} ne '') { |
$r->register_cleanup(\&Apache::lonnet::flushcourselogs); |
&Apache::lonnet::devalidate_cache_new('instcats',$crsudom); |
|
} |
|
®ister_cleanups($r,$crsudom,$env{'form.crscode'}); |
$r->print('<p>'.&mt('Roles will be active at next login').'.</p>'); |
$r->print('<p>'.&mt('Roles will be active at next login').'.</p>'); |
} |
} |
$r->print('<p><a href="/adm/createcourse?phase='.lc($crstype).'one">'. |
$r->print('<p><a href="/adm/createcourse?phase='.lc($crstype).'one">'. |
Line 852 sub process_batchfile {
|
Line 858 sub process_batchfile {
|
my $uname = $env{'user.name'}; |
my $uname = $env{'user.name'}; |
my $udom = $env{'user.domain'}; |
my $udom = $env{'user.domain'}; |
my $dir = &LONCAPA::tempdir().'addcourse'; |
my $dir = &LONCAPA::tempdir().'addcourse'; |
my ($result,$logmsg); |
my ($result,$logmsg,$keysmsg,$codesref,$instcodesref); |
if (($defdom =~ /^$match_domain$/) && ($uname =~ /^$match_username$/) && ($udom =~/^$match_domain$/)) { |
if (($defdom =~ /^$match_domain$/) && ($uname =~ /^$match_username$/) && ($udom =~/^$match_domain$/)) { |
my $batchfilepath=&Apache::lonnet::userfileupload('coursecreatorxml',undef, |
my $batchfilepath=&Apache::lonnet::userfileupload('coursecreatorxml',undef, |
'batchupload',undef,undef, |
'batchupload',undef,undef, |
undef,undef,$defdom); |
undef,undef,$defdom); |
if ($batchfilepath =~ m{^(\Q$dir/$defdom/web/$uname\_$udom\E)/pending/([^/]+)$}) { |
if ($batchfilepath =~ m{^(\Q$dir/$defdom/web/$uname\E_\Q$udom\E)/pending/([^/]+)$}) { |
my ($batchdir,$filename) = ($1,$2); |
my ($batchdir,$filename) = ($1,$2); |
if (-e "$batchfilepath") { |
if (-e "$batchfilepath") { |
if (open(FILE,"<",$batchfilepath)) { |
if (open(FILE,"<",$batchfilepath)) { |
Line 866 sub process_batchfile {
|
Line 872 sub process_batchfile {
|
if ((defined($filename)) && (defined($batchdir))) { |
if ((defined($filename)) && (defined($batchdir))) { |
my @requests = ($filename); |
my @requests = ($filename); |
my %courseids = (); |
my %courseids = (); |
($result,$logmsg) = &LONCAPA::batchcreatecourse::create_courses( |
($result,$logmsg,$keysmsg,$codesref,$instcodesref) = |
\@requests,\%courseids,'web',$defdom, |
&LONCAPA::batchcreatecourse::create_courses( |
$uname,$udom); |
\@requests,\%courseids,'web',$defdom, |
|
$uname,$udom); |
if (keys(%courseids) > 0) { |
if (keys(%courseids) > 0) { |
if (!-e "$batchdir/processed") { |
if (!-e "$batchdir/processed") { |
mkdir("$batchdir/processed", 0755); |
mkdir("$batchdir/processed", 0755); |
Line 882 sub process_batchfile {
|
Line 889 sub process_batchfile {
|
if (-e "$batchdir/processed/$filename") { |
if (-e "$batchdir/processed/$filename") { |
unlink("$batchdir/pending/$filename"); |
unlink("$batchdir/pending/$filename"); |
} |
} |
|
my $updatecats; |
|
if ((ref($instcodesref) eq 'HASH') && (keys(%{$instcodesref}) > 0)) { |
|
&Apache::lonnet::devalidate_cache_new('instcats',$defdom); |
|
$updatecats = 1; |
|
} |
|
®ister_cleanups($r,$defdom,$updatecats); |
|
|
} |
} |
} |
} |
} else { |
} else { |
Line 1289 sub get_permission {
|
Line 1303 sub get_permission {
|
return ($allowed,\%permission); |
return ($allowed,\%permission); |
} |
} |
|
|
|
sub register_cleanups { |
|
my ($r,$cdom,$updatecats) = @_; |
|
# Flush the course logs so reverse user roles immediately updated |
|
unless ($registered_flush) { |
|
my $handlers = $r->get_handlers('PerlCleanupHandler'); |
|
$r->set_handlers('PerlCleanupHandler' => [\&Apache::lonnet::flushcourselogs,@{$handlers}]); |
|
$registered_flush=1; |
|
} |
|
# Update cache of self-cataloging courses on institution's server(s). |
|
if ($updatecats) { |
|
if (&Apache::lonnet::shared_institution($cdom)) { |
|
unless ($registered_instcats) { |
|
my $handlers = $r->get_handlers('PerlCleanupHandler'); |
|
$r->set_handlers('PerlCleanupHandler' => [\&devalidate_remote_instcats,@{$handlers}]); |
|
$registered_instcats=1; |
|
$modified_dom = $cdom; |
|
} |
|
} |
|
} |
|
return; |
|
} |
|
|
|
sub devalidate_remote_instcats { |
|
if ($modified_dom ne '') { |
|
my %servers = &Apache::lonnet::internet_dom_servers($modified_dom); |
|
my %thismachine; |
|
map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids(); |
|
if (keys(%servers)) { |
|
foreach my $server (keys(%servers)) { |
|
next if ($thismachine{$server}); |
|
&Apache::lonnet::remote_devalidate_cache($server,['instcats:'.$modified_dom]); |
|
} |
|
} |
|
$modified_dom = ''; |
|
} |
|
return; |
|
} |
|
|
# ===================================================================== Handler |
# ===================================================================== Handler |
sub handler { |
sub handler { |
my $r = shift; |
my $r = shift; |
Line 1299 sub handler {
|
Line 1351 sub handler {
|
return OK; |
return OK; |
} |
} |
|
|
|
$registered_flush = 0; |
|
$registered_instcats = 0; |
|
$modified_dom = ''; |
|
|
my ($allowed,$permission) = &get_permission($env{'request.role.domain'}); |
my ($allowed,$permission) = &get_permission($env{'request.role.domain'}); |
if ($allowed) { |
if ($allowed) { |
my $show_all_choices = 0; |
my $show_all_choices = 0; |