--- loncom/interface/lonrequestcourse.pm 2020/07/17 20:39:55 1.95.2.2.2.1
+++ loncom/interface/lonrequestcourse.pm 2021/12/14 02:54:52 1.95.2.7
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Request a course
#
-# $Id: lonrequestcourse.pm,v 1.95.2.2.2.1 2020/07/17 20:39:55 raeburn Exp $
+# $Id: lonrequestcourse.pm,v 1.95.2.7 2021/12/14 02:54:52 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -119,6 +119,10 @@ use Apache::loncoursequeueadmin;
use Apache::lonuserutils;
use LONCAPA qw(:DEFAULT :match);
+my $registered_flush;
+my $registered_instcats;
+my $modified_dom;
+
sub handler {
my ($r) = @_;
&Apache::loncommon::content_type($r,'text/html');
@@ -127,6 +131,10 @@ sub handler {
return OK;
}
+ $registered_flush = 0;
+ $registered_instcats = 0;
+ $modified_dom = '';
+
&Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
['action','showdom','cnum','state','crstype','queue','tabs']);
&Apache::lonhtmlcommon::clear_breadcrumbs();
@@ -551,7 +559,6 @@ sub form_elements {
clonedom => 'selectbox',
datemode => 'radio',
dateshift => 'text',
- tinyurls => 'radio',
},
enrollment => {
accessstart_month => 'selectbox',
@@ -2388,7 +2395,7 @@ sub print_cancel_request {
&Apache::loncommon::start_data_table_row().
'
';
@@ -2742,7 +2749,7 @@ sub requestlog_display_filter {
$typename = $typenames->{$crstype};
}
}
- $output .= '
'."\n";
+ $output .= '
'."\n";
}
$output .= '';
}
@@ -2918,7 +2925,7 @@ sub print_review {
$inst_values .= '
'.$env{'form.coursecredits'}.' | ';
}
- my %ctxt = &clone_text($env{'form.crstype'});
+ my %ctxt = &clone_text();
$inst_headers .= '
'.&mt('Clone From').' | ';
if (($env{'form.cloning'}) &&
($env{'form.clonecrs'} =~ /^$match_name$/) &&
@@ -2930,8 +2937,7 @@ sub print_review {
my %courseenv = &Apache::lonnet::userenvironment($env{'form.clonedom'},
$env{'form.clonecrs'},('description','internal.coursecode'));
if (keys(%courseenv) > 0) {
- $inst_headers .= '
'.$ctxt{'dsh'}.' | '.
- '
'.$ctxt{'dpl'}.' | ';
+ $inst_headers .= '
'.$ctxt{'dsh'}.' | ';
$inst_values .= '
'.$courseenv{'description'}.' ';
my $cloneinst = $courseenv{'internal.coursecode'};
if ($cloneinst ne '') {
@@ -2947,14 +2953,6 @@ sub print_review {
} else {
$inst_values .= $ctxt{'ncd'};
}
- $inst_values .= ' | ';
- if ($env{'form.tinyurls'} eq 'delete') {
- $inst_values .= $ctxt{'nsl'};
- } elsif ($env{'form.tinyurls'} eq 'transfer') {
- $inst_values .= $ctxt{'tsl'};
- } else {
- $inst_values .= $ctxt{'csl'};
- }
$inst_values .= ' | ';
} else {
$inst_values .= '
'.&mt('Unknown').' | ';
@@ -3183,7 +3181,7 @@ sub clone_form {
if ($crstype eq 'community') {
$type = 'Community';
}
- my %lt = &clone_text($crstype);
+ my %lt = &clone_text();
my $output .=
&Apache::lonhtmlcommon::row_title($lt{'dmn'}).'
'.
@@ -3200,38 +3198,20 @@ sub clone_form {
'
'.
- '
'.
- &Apache::lonhtmlcommon::row_closure(1).
- &Apache::lonhtmlcommon::row_title($lt{'dpl'}).'
'.
+ '
'.
&Apache::lonhtmlcommon::row_closure(1);
return $output;
}
sub clone_text {
- my ($crstype) = @_;
- my %lt = &Apache::lonlocal::texthash(
+ return &Apache::lonlocal::texthash(
'cid' => 'Course ID',
'dmn' => 'Domain',
'dsh' => 'Date Shift',
'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',
- );
- if ($crstype eq 'Community') {
- $lt{'tsl'} = &mt('Transfer URL shortcuts from existing course to new community');
- $lt{'csl'} = &mt('Create new URL shortcuts in new course');
- }
- return %lt;
+ );
}
sub coursecode_form {
@@ -3257,7 +3237,7 @@ sub coursecode_form {
}
if (@{$codetitles} > 0) {
my $lastitem = pop(@{$codetitles});
- my $lastinput = '
';
+ my $lastinput = '
';
if (@{$codetitles} > 0) {
my $helplink;
if (defined($helpitem{$context})) {
@@ -3673,7 +3653,6 @@ sub print_request_outcome {
clonecrs => $clonecrs,
datemode => $env{'form.datemode'},
dateshift => $env{'form.dateshift'},
- tinyurls => $env{'form.tinyurls'},
sectotal => $sectotal,
sections => \%sections,
crosslisttotal => $crosslisttotal,
@@ -3805,9 +3784,7 @@ sub process_request {
$storeresult = 'rejected';
} elsif ($disposition eq 'process') {
my %domdefs = &Apache::lonnet::get_domain_defaults($dom);
- my ($logmsg,$newusermsg,$addresult,$enrollcount,$response,
- $keysmsg,%longroles,$code);
- my $clonemsg = [];
+ my ($logmsg,$newusermsg,$addresult,$enrollcount,$response,$keysmsg,%longroles,$code);
my $type = 'Course';
if ($crstype eq 'community') {
$type = 'Community';
@@ -3840,9 +3817,9 @@ sub process_request {
$customitems{'_LC_coursestartdate'} = $accessstart;
$customitems{'_LC_courseenddate'} = $accessend;
my ($result,$postprocess) = &Apache::loncoursequeueadmin::course_creation($dom,$cnum,
- 'autocreate',$details,\$logmsg,$clonemsg,\$newusermsg,
- \$addresult,\$enrollcount,\$response,\$keysmsg,\%domdefs,
- \%longroles,\$code,\%customitems);
+ 'autocreate',$details,\$logmsg,\$newusermsg,\$addresult,
+ \$enrollcount,\$response,\$keysmsg,\%domdefs,\%longroles,
+ \$code,\%customitems);
if (ref($postprocess) eq 'HASH') {
$customized = $postprocess->{'createdcustomized'};
}
@@ -3876,21 +3853,25 @@ sub process_request {
$output .= '
'.$role_result;
}
$output .= '';
- if ($logmsg) {
- $output .= '
'.$logmsg.'
';
- }
- if ((ref($clonemsg) eq 'ARRAY') && (@{$clonemsg})) {
- $output .= '
';
- my $user_lh = &Apache::loncommon::user_lang($env{'user.name'},$env{'user.domain'});
- foreach my $item (@{$clonemsg}) {
- if (ref($item) eq 'HASH') {
- $output .= &mt_user($user_lh,$item->{mt},
- @{$item->{args}}).'
'."\n";
+ $creationresult = 'created';
+ # 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;
+ }
+ if ($instcode ne '') {
+ &Apache::lonnet::devalidate_cache_new('instcats',$dom);
+ # Update cache of self-cataloging courses on institution's server(s).
+ if (&Apache::lonnet::shared_institution($dom)) {
+ unless ($registered_instcats) {
+ my $handlers = $r->get_handlers('PerlCleanupHandler');
+ $r->set_handlers('PerlCleanupHandler' => [\&devalidate_remote_instcats,@{$handlers}]);
+ $registered_instcats=1;
+ $modified_dom = $dom;
}
}
- $output .= '
'."\n";
}
- $creationresult = 'created';
} else {
$output = '
';
if ($crstype eq 'community') {
@@ -3999,7 +3980,7 @@ sub process_request {
} elsif ($disposition eq 'pending') {
my $pendingform;
if ($crstype ne 'official') {
- $pendingform = &pending_validation_form($dom,$cnum,$crstype,$now,$token,
+ $pendingform = &pending_validation_form($r,$dom,$cnum,$crstype,$now,$token,
$lonhost,$env{'form.cdescr'});
}
if ($pendingform) {
@@ -4026,6 +4007,22 @@ sub process_request {
}
}
+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;
+}
+
sub custom_formitems {
my ($preprocess,$customhash) = @_;
return unless ((ref($preprocess) eq 'HASH') && (ref($customhash) eq 'HASH'));
@@ -4301,7 +4298,7 @@ sub notification_information {
}
sub pending_validation_form {
- my ($cdom,$cnum,$crstype,$now,$token,$lonhost,$cdesc) = @_;
+ my ($r,$cdom,$cnum,$crstype,$now,$token,$lonhost,$cdesc) = @_;
my $output;
my %postvalues = (
'owner' => $env{'user.name'}.':'.$env{'user.domain'},
@@ -4334,9 +4331,12 @@ sub pending_validation_form {
$buttontext = &mt('Create course');
}
}
+ my $hostname = &Apache::lonnet::hostname($lonhost);
my $protocol = $Apache::lonnet::protocol{$lonhost};
$protocol = 'http' if ($protocol ne 'https');
- my $crscreator = $protocol.'://'.&Apache::lonnet::hostname($lonhost).'/cgi-bin/createpending.pl';
+ my $alias = &Apache::lonnet::use_proxy_alias($r,$lonhost);
+ $hostname = $alias if ($alias ne '');
+ my $crscreator = $protocol.'://'.$hostname.'/cgi-bin/createpending.pl';
$output .= ''."\n".
''."\n".
''."\n".
@@ -4412,7 +4412,6 @@ sub retrieve_settings {
}
$env{'form.datemode'} = $reqinfo{'datemode'};
$env{'form.dateshift'} = $reqinfo{'dateshift'};
- $env{'form.tinyurls'} = $reqinfo{'tinyurls'};
if ($reqinfo{'crstype'} eq 'official') {
$env{'form.autoadds'} = $reqinfo{'autoadds'};
$env{'form.autodrops'} = $reqinfo{'autodrops'};
@@ -4815,26 +4814,17 @@ sub print_textbook_form {
#
# Table of user's current courses (owner and/or course coordinator)
#
- my %lt = &clone_text('Course');
+ my %lt = &clone_text();
if (keys(%cloneable)) {
$r->print('');
}
#
@@ -4843,20 +4833,13 @@ sub print_textbook_form {
if (keys(%domcloneable)) {
$r->print('');
}
@@ -5087,7 +5070,6 @@ sub process_textbook_request {
} else {
$details->{dateshift} = '';
}
- $details->{tinyurls} = $env{'form.owntinyurls'};
} elsif ($reqtype eq 'colleague') {
$details->{datemode} = $env{'form.colldatemode'};
if ($details->{datemode} eq 'shift') {
@@ -5095,11 +5077,9 @@ sub process_textbook_request {
} else {
$details->{dateshift} = '';
}
- $details->{tinyurls} = $env{'form.colltinyurls'};
} elsif (($reqtype eq 'textbook') || ($reqtype eq 'template')) {
$details->{datemode} = 'delete';
$details->{dateshift} = '';
- $details->{tinyurls} = '';
}
if ($details->{dateshift} ne '') {
$details->{dateshift} =~ s/[^\d\.]+//g;
@@ -5107,7 +5087,6 @@ sub process_textbook_request {
} else {
$details->{datemode} = '';
$details->{dateshift} = '';
- $details->{tinyurls} = '';
}
my $lonhost = $r->dir_config('lonHostID');
$r->rflush();