--- loncom/interface/lonrequestcourse.pm 2017/08/07 20:22:13 1.100
+++ loncom/interface/lonrequestcourse.pm 2021/03/06 13:44:51 1.110
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Request a course
#
-# $Id: lonrequestcourse.pm,v 1.100 2017/08/07 20:22:13 raeburn Exp $
+# $Id: lonrequestcourse.pm,v 1.110 2021/03/06 13:44:51 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();
@@ -155,6 +163,23 @@ sub handler {
}
if ($canreq) {
+ if (($env{'form.crstype'} eq 'lti') && ($env{'request.lti.login'}) &&
+ ($env{'form.lti.reqrole'} eq 'cc') && ($env{'form.lti.reqcrs'}) &&
+ ($env{'form.lti.sourcecrs'} ne '')) {
+ if ($action eq 'process') {
+ if ($can_request{'lti'}) {
+ my %domconfig = &Apache::lonnet::get_dom('configuration',['requestcourses'],$dom);
+ &process_textbook_request($r,$dom,$action,\%domdefs,\%domconfig,\%can_request,'lti');
+ } else {
+ $r->print(&header('Course Request','','','',{ 'only_body' => 1}).
+ '
';
@@ -2754,7 +2781,7 @@ sub requestlog_display_filter {
$typename = $typenames->{$crstype};
}
}
- $output .= '
'."\n";
+ $output .= '
'."\n";
}
$output .= '';
}
@@ -2930,7 +2957,7 @@ sub print_review {
$inst_values .= '
'.$env{'form.coursecredits'}.' | ';
}
- my %ctxt = &clone_text();
+ my %ctxt = &clone_text($env{'form.crstype'});
$inst_headers .= '
'.&mt('Clone From').' | ';
if (($env{'form.cloning'}) &&
($env{'form.clonecrs'} =~ /^$match_name$/) &&
@@ -2942,7 +2969,8 @@ 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'}.' | ';
+ $inst_headers .= '
'.$ctxt{'dsh'}.' | '.
+ '
'.$ctxt{'dpl'}.' | ';
$inst_values .= '
'.$courseenv{'description'}.' ';
my $cloneinst = $courseenv{'internal.coursecode'};
if ($cloneinst ne '') {
@@ -2958,6 +2986,14 @@ 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').' | ';
@@ -3189,7 +3225,7 @@ sub clone_form {
} elsif ($crstype eq 'placement') {
$type = 'Placement';
}
- my %lt = &clone_text();
+ my %lt = &clone_text($crstype);
my $output .=
&Apache::lonhtmlcommon::row_title($lt{'dmn'}).'
'.
@@ -3207,19 +3243,37 @@ sub clone_form {
'
'.
$lt{'shd'}.''.
'
'.
+ &Apache::lonhtmlcommon::row_closure(1).
+ &Apache::lonhtmlcommon::row_title($lt{'dpl'}).'
'.
&Apache::lonhtmlcommon::row_closure(1);
return $output;
}
sub clone_text {
- return &Apache::lonlocal::texthash(
+ my ($crstype) = @_;
+ my %lt = &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 {
@@ -3245,7 +3299,7 @@ sub coursecode_form {
}
if (@{$codetitles} > 0) {
my $lastitem = pop(@{$codetitles});
- my $lastinput = '
';
+ my $lastinput = '
';
if (@{$codetitles} > 0) {
my $helplink;
if (defined($helpitem{$context})) {
@@ -3353,14 +3407,14 @@ sub get_course_dom {
return $env{'user.domain'};
}
}
- my (@possible_doms,%willtrust,%trustchecked);
+ my (@possible_doms,%willtrust);
foreach my $type (@{$types}) {
my $dom_str = $env{'environment.reqcrsotherdom.'.$type};
if ($dom_str ne '') {
my @domains = split(',',$dom_str);
foreach my $entry (@domains) {
my ($extdom,$extopt) = split(':',$entry);
- unless ($trustchecked{$extdom}) {
+ unless (exists($willtrust{$extdom})) {
$willtrust{$extdom} = &Apache::lonnet::will_trust('reqcrs',$env{'user.domain'},$extdom);
}
if ($willtrust{$extdom}) {
@@ -3666,6 +3720,7 @@ sub print_request_outcome {
clonecrs => $clonecrs,
datemode => $env{'form.datemode'},
dateshift => $env{'form.dateshift'},
+ tinyurls => $env{'form.tinyurls'},
sectotal => $sectotal,
sections => \%sections,
crosslisttotal => $crosslisttotal,
@@ -3799,7 +3854,9 @@ 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 ($logmsg,$newusermsg,$addresult,$enrollcount,$response,
+ $keysmsg,%longroles,$code);
+ my $clonemsg = [];
my $type = 'Course';
if ($crstype eq 'community') {
$type = 'Community';
@@ -3832,9 +3889,9 @@ sub process_request {
$customitems{'_LC_coursestartdate'} = $accessstart;
$customitems{'_LC_courseenddate'} = $accessend;
my ($result,$postprocess) = &Apache::loncoursequeueadmin::course_creation($dom,$cnum,
- 'autocreate',$details,\$logmsg,\$newusermsg,\$addresult,
- \$enrollcount,\$response,\$keysmsg,\%domdefs,\%longroles,
- \$code,\%customitems);
+ 'autocreate',$details,\$logmsg,$clonemsg,\$newusermsg,
+ \$addresult,\$enrollcount,\$response,\$keysmsg,\%domdefs,
+ \%longroles,\$code,\%customitems);
if (ref($postprocess) eq 'HASH') {
$customized = $postprocess->{'createdcustomized'};
}
@@ -3868,7 +3925,39 @@ 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";
+ }
+ }
+ $output .= '
'."\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;
+ }
+ }
+ }
} else {
$output = '
';
if ($crstype eq 'community') {
@@ -4004,6 +4093,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'));
@@ -4312,9 +4417,10 @@ 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 $crscreator = $protocol.'://'.$hostname.'/cgi-bin/createpending.pl';
$output .= ''."\n".
''."\n".
''."\n".
@@ -4390,6 +4496,7 @@ 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'};
@@ -4541,9 +4648,11 @@ sub generate_date_items {
}
sub print_textbook_form {
- my ($r,$dom,$incdoms,$domdefs,$settings,$can_request) = @_;
+ my ($r,$dom,$incdoms,$domdefs,$settings,$can_request,$crstype,$formhash) = @_;
my (%prefab,%ordered,%numprefab);
- my $crstype = 'textbook';
+ if ($crstype eq '') {
+ $crstype = 'textbook';
+ }
#
# Retrieve list of prefabricated courses (textbook courses and templates) cloneable by user
#
@@ -4603,6 +4712,7 @@ sub print_textbook_form {
owner => $courseinfo{'internal.courseowner'},
releaserequired => $courseinfo{'internal.releaserequired'},
type => $courseinfo{'type'},
+ };
}
}
@@ -4659,31 +4769,37 @@ sub print_textbook_form {
my $jscript = &textbook_request_javascript(\%numprefab,$numcurrent,$numdomcourses,$customvalidationjs);
$jscript .= $customjs;
- my %loaditems;
+ my (%loaditems,$args);
$loaditems{'onload'} = 'javascript:uncheckAllRadio();'.$customonload;
- $r->print(&header('Course Request',$jscript,\%loaditems));
+ if ($crstype eq 'lti') {
+ $args = { 'only_body' => 1};
+ }
+ $r->print(&header('Course Request',$jscript,\%loaditems,undef,$args));
if (ref($can_request) eq 'HASH') {
- unless ((scalar(keys(%{$can_request})) == 1) && ($can_request->{'textbook'})) {
+ unless (((scalar(keys(%{$can_request})) == 1) && ($can_request->{'textbook'})) ||
+ ($crstype eq 'lti')) {
&Apache::lonhtmlcommon::add_breadcrumb(
{ href => '/adm/requestcourse',
text => 'Pick action',
});
}
}
- &Apache::lonhtmlcommon::add_breadcrumb({text=>'Course Request'});
- $r->print(&Apache::lonhtmlcommon::breadcrumbs('Course Requests','Course_Requests'));
+ unless ($crstype eq 'lti') {
+ &Apache::lonhtmlcommon::add_breadcrumb({text=>'Course Request'});
+ $r->print(&Apache::lonhtmlcommon::breadcrumbs('Course Requests','Course_Requests'));
- &startContentScreen($r,'textbookrequests');
+ &startContentScreen($r,'textbookrequests');
#
# Show domain selector form, if required.
#
- if (@{$incdoms} > 1) {
- my $onchange = 'this.form.submit()';
- $r->print('