version 1.167, 2017/08/11 00:24:53
|
version 1.172, 2019/07/26 02:28:34
|
Line 82 use Apache::lonlocal;
|
Line 82 use Apache::lonlocal;
|
use Apache::lonuserutils; |
use Apache::lonuserutils; |
use Apache::lonclonecourse; |
use Apache::lonclonecourse; |
use LONCAPA::batchcreatecourse; |
use LONCAPA::batchcreatecourse; |
use LONCAPA; |
use LONCAPA qw(:DEFAULT :match); |
|
|
|
my $registered_flush; |
|
my $registered_instcats; |
|
my $modified_dom; |
|
|
# ===================================================== Phase one: fill-in form |
# ===================================================== Phase one: fill-in form |
|
|
Line 764 sub create_course {
|
Line 768 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 889 sub upload_batchfile {
|
Line 895 sub upload_batchfile {
|
|
|
sub process_batchfile { |
sub process_batchfile { |
my $r = shift; |
my $r = shift; |
my $start_page = |
|
&Apache::loncommon::start_page('Create a New Course, Community or Placement Test'); |
|
my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('Creation Outcome','Create_Course',undef,'Create_Courses'); |
|
my $end_page = |
|
&Apache::loncommon::end_page(); |
|
my $defdom=$env{'request.role.domain'}; |
my $defdom=$env{'request.role.domain'}; |
my $batchfilepath=&Apache::lonnet::userfileupload('coursecreatorxml',undef, |
my $uname = $env{'user.name'}; |
'batchupload',undef,undef, |
my $udom = $env{'user.domain'}; |
undef,undef,$defdom); |
my $dir = &LONCAPA::tempdir().'addcourse'; |
my ($batchdir,$filename) = ($batchfilepath =~ m-^(.+)/pending/([^/]+)$-); |
my ($result,$logmsg,$keysmsg,$codesref,$instcodesref); |
my ($result,$logmsg); |
if (($defdom =~ /^$match_domain$/) && ($uname =~ /^$match_username$/) && ($udom =~/^$match_domain$/)) { |
if (-e "$batchfilepath") { |
my $batchfilepath=&Apache::lonnet::userfileupload('coursecreatorxml',undef, |
open(FILE,"<$batchfilepath"); |
'batchupload',undef,undef, |
my @buffer = <FILE>; |
undef,undef,$defdom); |
close(FILE); |
if ($batchfilepath =~ m{^(\Q$dir/$defdom/web/$uname\E_\Q$udom\E)/pending/([^/]+)$}) { |
if ((defined($filename)) && (defined($batchdir))) { |
my ($batchdir,$filename) = ($1,$2); |
my @requests = ($filename); |
if (-e "$batchfilepath") { |
my %courseids = (); |
if (open(FILE,"<",$batchfilepath)) { |
($result,$logmsg) = &LONCAPA::batchcreatecourse::create_courses( |
my @buffer = <FILE>; |
\@requests,\%courseids,'web',$defdom, |
|
$env{'user.name'},$env{'user.domain'}); |
|
if ($result) { |
|
if (!-e "$batchdir/processed") { |
|
mkdir("$batchdir/processed", 0755); |
|
open(FILE,">$batchdir/processed/$filename"); |
|
print FILE @buffer; |
|
close(FILE); |
close(FILE); |
if (-e "$batchdir/processed/$filename") { |
if ((defined($filename)) && (defined($batchdir))) { |
unlink("$batchdir/pending/$filename"); |
my @requests = ($filename); |
|
my %courseids = (); |
|
($result,$logmsg,$keysmsg,$codesref,$instcodesref) = |
|
&LONCAPA::batchcreatecourse::create_courses( |
|
\@requests,\%courseids,'web',$defdom, |
|
$uname,$udom); |
|
if (keys(%courseids) > 0) { |
|
if (!-e "$batchdir/processed") { |
|
mkdir("$batchdir/processed", 0755); |
|
} |
|
if (-d "$batchdir/processed") { |
|
if (open(FILE,">","$batchdir/processed/$filename")) { |
|
print FILE @buffer; |
|
close(FILE); |
|
} |
|
} |
|
if (-e "$batchdir/processed/$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 { |
|
$result = '<p class="LC_error">'.&mt('Could not open attributes file.').'<br />'.&mt('No courses created.').'</p>'; |
} |
} |
|
} else { |
|
$result = '<p class="LC_error">'.&mt('No uploaded attributes file found.').'<br />'.&mt('No courses created.').'</p>'; |
} |
} |
|
} else { |
|
$result = '<p class="LC_error">'.&mt('Invalid path to attributes file.').'<br />'.&mt('No courses created.').'</p>'; |
} |
} |
|
} else { |
|
$result = '<p class="LC_error">'.&mt("Your username, domain, and/or your current role's domain are missing or contain invalid characters."). |
|
'<br />'.&mt('No courses created.').'</p>'; |
} |
} |
$r->print($start_page.$crumbs.$logmsg.$result.'<br /><a href="/adm/createcourse">'. |
$r->print(&Apache::loncommon::start_page('Create a New Course, Community or Placement Test'). |
&mt('Creation options menu').'</a>'.$end_page); |
&Apache::lonhtmlcommon::breadcrumbs('Creation Outcome','Create_Course',undef,'Create_Courses'). |
|
$logmsg.$result.'<br /><a href="/adm/createcourse">'. |
|
&mt('Creation options menu').'</a>'. |
|
&Apache::loncommon::end_page()); |
|
|
} |
} |
|
|
Line 1317 sub get_permission {
|
Line 1348 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 1327 sub handler {
|
Line 1396 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; |