--- loncom/interface/loncreatecourse.pm 2020/07/17 23:28:21 1.158.2.3.2.3 +++ loncom/interface/loncreatecourse.pm 2019/07/26 17:27:44 1.158.2.5 @@ -1,7 +1,7 @@ # The LearningOnline Network # Create a course # -# $Id: loncreatecourse.pm,v 1.158.2.3.2.3 2020/07/17 23:28:21 raeburn Exp $ +# $Id: loncreatecourse.pm,v 1.158.2.5 2019/07/26 17:27:44 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -80,9 +80,14 @@ use Apache::loncommon; use Apache::londocs; use Apache::lonlocal; use Apache::lonuserutils; +use Apache::lonclonecourse; use LONCAPA::batchcreatecourse; use LONCAPA qw(:DEFAULT :match); +my $registered_flush; +my $registered_instcats; +my $modified_dom; + # ===================================================== Phase one: fill-in form sub print_course_creation_page { @@ -182,10 +187,6 @@ function validate(formname) { 'ncd' => "Do not clone date parameters", 'prd' => 'Clone date parameters as-is', 'shd' => 'Shift date parameters by number of days', - 'dpl' => 'URL shortcuts (for deep linking)', - 'nsl' => 'Do not clone URL shortcuts', - 'tsl' => 'Transfer URL shortcuts from existing course to new course', - 'csl' => 'Create new URL shortcuts in new course', 'assp' => "Assessment Parameters", 'oaas' => "Open all assessments", 'mssg' => "Messaging", @@ -249,8 +250,6 @@ function validate(formname) { $lt{'cc'} = &mt('(will be assigned Coordinator role)'); $lt{'cgrs'} = &mt('Community Group Settings'); $lt{'cgrq'} = &mt('Set a quota for the total disk space available for storage of community group portfolio files'); - $lt{'tsl'} = &mt('Transfer URL shortcuts from existing community to new community'); - $lt{'csl'} = &mt('Create new URL shortcuts in new community'); } my $js = < @@ -400,7 +399,6 @@ END .''.$lt{'navi'} .''); } - my $tinyurlhelp=&Apache::loncommon::help_open_topic('Clone_Tiny_URLs'); $r->print('
('.$lt{'stco'}.')' .&Apache::lonhtmlcommon::row_closure(1) .&Apache::lonhtmlcommon::end_pick_box() @@ -432,17 +430,6 @@ END .'' .' ' .&Apache::lonhtmlcommon::row_closure() - .&Apache::lonhtmlcommon::row_title($tinyurlhelp.$lt{'dpl'}) - .'
' - .'
' - .'' - .&Apache::lonhtmlcommon::row_closure() .&Apache::lonhtmlcommon::row_headline() .''.$lt{'asov'}.'' .&Apache::lonhtmlcommon::row_closure(1) @@ -653,7 +640,6 @@ sub create_course { clonedomain => $env{'form.clonedomain'}, datemode => $env{'form.datemode'}, dateshift => $env{'form.dateshift'}, - tinyurls => $env{'form.tinyurls'}, crsid => $env{'form.crsid'}, curruser => $env{'user.name'}.':'.$env{'user.domain'}, crssections => $env{'form.crssections'}, @@ -720,20 +706,12 @@ sub create_course { return; } my ($courseid,$crsudom,$crsunum,$code); - my ($success,$output,$clonemsgref) = + my ($success,$output) = &Apache::loncommon::construct_course($args,\$logmsg,\$courseid, \$crsudom,\$crsunum, $env{'user.domain'}, $env{'user.name'},'dc_create',undef,undef,\$code); $r->print($output); - if (ref($clonemsgref) eq 'ARRAY') { - my $user_lh = &Apache::loncommon::user_lang($env{'user.name'},$env{'user.domain'}); - foreach my $item (@{$clonemsgref}) { - if (ref($item) eq 'HASH') { - $r->print(&mt($item->{mt},@{$item->{args}}).'
'."\n"); - } - } - } if ($success) { # # Make the requested user a course coordinator or group coordinator @@ -757,8 +735,10 @@ sub create_course { '

'.&mt('Course identifier to share with students: [_1]',$code).'

' ); } - # Flush the course logs so reverse user roles immediately updated - $r->register_cleanup(\&Apache::lonnet::flushcourselogs); + if ($env{'form.crscode'} ne '') { + &Apache::lonnet::devalidate_cache_new('instcats',$crsudom); + } + ®ister_cleanups($r,$crsudom,$env{'form.crscode'}); $r->print('

'.&mt('Roles will be active at next login').'.

'); } $r->print('

'. @@ -878,12 +858,12 @@ sub process_batchfile { my $uname = $env{'user.name'}; my $udom = $env{'user.domain'}; my $dir = &LONCAPA::tempdir().'addcourse'; - my ($result,$logmsg,$clonemsg,$keysmsg,$codesref,$instcodesref + my ($result,$logmsg,$keysmsg,$codesref,$instcodesref); if (($defdom =~ /^$match_domain$/) && ($uname =~ /^$match_username$/) && ($udom =~/^$match_domain$/)) { my $batchfilepath=&Apache::lonnet::userfileupload('coursecreatorxml',undef, 'batchupload',undef,undef, 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); if (-e "$batchfilepath") { if (open(FILE,"<",$batchfilepath)) { @@ -892,7 +872,7 @@ sub process_batchfile { if ((defined($filename)) && (defined($batchdir))) { my @requests = ($filename); my %courseids = (); - ($result,$logmsg,$clonemsg,$keysmsg,$codesref,$instcodesref) = + ($result,$logmsg,$keysmsg,$codesref,$instcodesref) = &LONCAPA::batchcreatecourse::create_courses( \@requests,\%courseids,'web',$defdom, $uname,$udom); @@ -909,9 +889,13 @@ sub process_batchfile { if (-e "$batchdir/processed/$filename") { unlink("$batchdir/pending/$filename"); } - } - if ($clonemsg) { - $clonemsg = '

'.$clonemsg.'

'."\n"; + 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 { @@ -929,7 +913,7 @@ sub process_batchfile { } $r->print(&Apache::loncommon::start_page('Create a New Course, Community or Placement Test'). &Apache::lonhtmlcommon::breadcrumbs('Creation Outcome','Create_Course',undef,'Create_Courses'). - $logmsg.$clonemsg.$result.'
'. + $logmsg.$result.'
'. &mt('Creation options menu').''. &Apache::loncommon::end_page()); } @@ -1319,6 +1303,44 @@ sub get_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 sub handler { my $r = shift; @@ -1329,6 +1351,10 @@ sub handler { return OK; } + $registered_flush = 0; + $registered_instcats = 0; + $modified_dom = ''; + my ($allowed,$permission) = &get_permission($env{'request.role.domain'}); if ($allowed) { my $show_all_choices = 0; @@ -1466,9 +1492,7 @@ sub handler { my $start_page=&Apache::loncommon::start_page('Requests Validation Result',$js); my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('Validation Attempted','Course_Requests',undef,'Course_Requests'); $r->print($start_page.$crumbs."\n".'
'. - &Apache::loncoursequeueadmin::process_official_reqs('domain',$env{'request.role.domain'}, - $env{'user.name'},$env{'user.domain'}). - '
'. + &Apache::loncoursequeueadmin::process_official_reqs('domain',$env{'request.role.domain'}).''. &Apache::loncommon::end_page()); } elsif (($env{'form.phase'} eq 'creationlog') && ($show_all_choices)) { &Apache::lonhtmlcommon::add_breadcrumb