--- loncom/interface/lonextresedit.pm 2025/02/03 22:52:36 1.35
+++ loncom/interface/lonextresedit.pm 2025/06/14 02:50:25 1.37
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Documents
#
-# $Id: lonextresedit.pm,v 1.35 2025/02/03 22:52:36 raeburn Exp $
+# $Id: lonextresedit.pm,v 1.37 2025/06/14 02:50:25 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -309,12 +309,33 @@ sub update_exttool {
my ($marker,$cdom,$cnum,$supplementalflag,$args) = @_;
my (%newhash,$changed,$newgradable,@deleted,$errormsg);
($newhash{'target'},$newhash{'width'},$newhash{'height'},$newhash{'linktext'},$newhash{'explanation'},
- $newhash{'crslabel'},$newhash{'crstitle'},$newhash{'crsappend'},$newhash{'gradable'}) = split(/:/,$args);
- foreach my $item ('linktext','explanation','crslabel','crstitle','crsappend') {
+ $newhash{'crslabel'},$newhash{'crstitle'},$newhash{'crsappend'},$newhash{'gradable'},
+ $newhash{'returnurl'},$newhash{'backtourl'},$newhash{'desturl'},$newhash{'delay'}) = split(/:/,$args);
+ foreach my $item ('linktext','explanation','crslabel','crstitle','crsappend','backtourl','desturl','delay') {
$newhash{$item} = &unescape($newhash{$item});
}
my %toolhash=&Apache::lonnet::dump('exttool_'.$marker,$cdom,$cnum);
- foreach my $item ('target','width','height','linktext','explanation','crslabel','crstitle','crsappend','gradable') {
+ my ($tooltype,$tool,$ltihash);
+ if ($toolhash{'id'} =~/^c(\d+)$/) {
+ $tool = $1;
+ $tooltype = 'crs';
+ } elsif ($toolhash{'id'} =~/^\d+$/) {
+ $tooltype = 'dom';
+ $tool = $toolhash{'id'};
+ }
+ if (($tool ne '') && ($tooltype ne '')) {
+ my %tools;
+ my %tooltypes = &Apache::loncommon::usable_exttools();
+ if ($tooltypes{$tooltype}) {
+ if ($tooltype eq 'dom') {
+ %tools = &Apache::lonnet::get_domain_lti($cdom,'consumer');
+ } elsif ($tooltypes{'crs'}) {
+ %tools = &Apache::lonnet::get_course_lti($cnum,$cdom,'consumer');
+ }
+ $ltihash = $tools{$tool};
+ }
+ }
+ foreach my $item ('target','width','height','linktext','explanation','crslabel','crstitle','crsappend','gradable','returnurl','backtourl','desturl','delay') {
$newhash{$item} =~ s/^\s+//;
$newhash{$item} =~ s/\s+$//;
if (($item eq 'width') || ($item eq 'height') || ($item eq 'linktext') || ($item eq 'explanation')) {
@@ -329,6 +350,26 @@ sub update_exttool {
unless ($newhash{$item} == 1) {
$newhash{$item} = '';
}
+ } elsif ($item eq 'backtourl') {
+ unless ($newhash{'returnurl'} eq 'custom') {
+ $newhash{$item} = '';
+ }
+ } elsif ($item eq 'desturl') {
+ my $nocrsdest = 1;
+ if ((ref($ltihash) eq 'HASH') && (ref($ltihash->{'crsconf'}) eq 'HASH') &&
+ ($ltihash->{'crsconf'}->{'desturl'})) {
+ undef($nocrsdest);
+ }
+ if ($nocrsdest) {
+ $newhash{$item} = '';
+ }
+ } elsif ($item eq 'delay') {
+ if ($newhash{'desturl'} eq '') {
+ $newhash{$item} = '';
+ }
+ unless ($newhash{$item} =~ /^(\d+\.?\d*)$/) {
+ $newhash{$item} = '';
+ }
}
if ($toolhash{$item} ne $newhash{$item}) {
if (($item eq 'gradable') && (!$supplementalflag)) {
@@ -352,7 +393,7 @@ sub update_exttool {
}
} else {
$toolhash{$item} = $newhash{$item};
- $changed = 1;
+ $changed = 1;
}
}
}
@@ -395,17 +436,20 @@ sub extedit_form {
$tabid = 'ee';
}
my ($formname,$formid,$toggle,$fieldsetid,$urlid,$subdivid,$dispdivstyle,$dimendivstyle,
- $windivstyle,$linktextstyle,$explanationstyle,$labelstyle,$titlestyle,
- $appendstyle,$gradablestyle,$subdivstyle,$legend,$urlelem,$toolelem,%toolattr);
+ $windivstyle,$linktextstyle,$explanationstyle,$labelstyle,$titlestyle,$providerstyle,
+ $appendstyle,$gradablestyle,$returnurlstyle,$subdivstyle,$desturlstyle,
+ $desturlinfostyle,$desturlfixedstyle,$legend,$urlelem,$toolelem,%toolattr);
$formname = 'new'.$type;
$toggle = $type;
$fieldsetid = 'external'.$type.'form';
$urlid = $type.'url';
map { $toolattr{$_} = $type.$_; } ('dispdiv','dimendiv','dimenwidth','dimenheight',
'crstitlediv','crslabeldiv','crsappenddiv',
- 'gradablediv','crstitle','crslabel','crsappend',
- 'windiv','linktextdiv','explanationdiv',
- 'linktext','explanation','providerurl');
+ 'gradablediv','returnurldiv','crstitle','crslabel',
+ 'crsappend','windiv','linktextdiv','explanationdiv',
+ 'linktext','explanation','provider','providerpath','customreturnurl',
+ 'desturl','delay','providerdiv','desturldiv','desturlinfodiv',
+ 'desturlfixeddiv','fixeddest','fixeddelay');
$dispdivstyle = 'display:none';
$dimendivstyle = 'display:none';
$windivstyle = 'display:none';
@@ -413,8 +457,13 @@ sub extedit_form {
$explanationstyle = 'display:none';
$labelstyle = 'display:none';
$titlestyle = 'display:none';
+ $providerstyle = 'display:none';
$appendstyle = 'display:none';
$gradablestyle = 'display:none';
+ $returnurlstyle = 'display:none';
+ $desturlstyle = 'display:none';
+ $desturlinfostyle = 'display:none';
+ $desturlfixedstyle = 'display:none';
$subdivstyle = 'display:block';
if ($supplementalflag) {
$formname = 'newsupp'.$type;
@@ -425,7 +474,9 @@ sub extedit_form {
}
my ($link,$legend,$active,$srcclass,$extsrc,$preview,$title,$save,$crstitle,$crslabel,
$crsappend,$fieldsetstyle,$action,$hiddenelem,$form,$width,$height,$tooltarget,
- $linktext,$explanation,$providerurl,$chkgrd,$chknogrd,%chkstate);
+ $linktext,$explanation,$path,$returnurl,$chkgrd,$chknogrd,%chkstate,
+ $chknoreturn,$chkreturndef,$chkreturncust,$customreturn,$backtourl,$desturl,$delay,
+ $chknodest,$chkdest);
$fieldsetstyle = 'display: none;';
$action = '/adm/coursedocs';
my $protocol = ($ENV{'SERVER_PORT'} == 443?'https':'http');
@@ -499,6 +550,7 @@ sub extedit_form {
$urlelem = '';
} else {
my $class = 'LC_nobreak';
+ my ($nocrsdest,$fixeddest,$fixeddelay,$showprovider,$provider,$scheme);
if ($residx) {
$class = 'LC_docs_ext_edit LC_nobreak';
if ($orig_url =~ m{^/adm/$cdom/$cnum/(\d+)/ext\.tool$}) {
@@ -508,18 +560,13 @@ sub extedit_form {
if ($toolhash{'id'} =~/^c(\d+)$/) {
$tool = $1;
$tooltype = 'crs';
- if (ref($ltitools) eq 'HASH') {
- if (ref($ltitools->{'crs'}) eq 'HASH') {
- $ltihash = $ltitools->{'crs'}->{$tool};
- }
- }
} elsif ($toolhash{'id'} =~/^\d+$/) {
$tooltype = 'dom';
$tool = $toolhash{'id'};
- if (ref($ltitools) eq 'HASH') {
- if (ref($ltitools->{'dom'}) eq 'HASH') {
- $ltihash = $ltitools->{'dom'}->{$tool};
- }
+ }
+ if (($tool ne '') && ($tooltype ne '') && (ref($ltitools) eq 'HASH')) {
+ if (ref($ltitools->{$tooltype}) eq 'HASH') {
+ $ltihash = $ltitools->{$tooltype}->{$tool};
}
}
if (($tool ne '') && (ref($ltihash) eq 'HASH')) {
@@ -529,10 +576,10 @@ sub extedit_form {
if ($icon) {
$image = '';
}
- if ($ltihash->{'url'} =~ m{://}) {
- (my $prot,my $host,$providerurl) = ($ltihash->{'url'} =~ m{^([^/]+)://([^/]+)(|/.+)$});
+ if ($ltihash->{'url'} =~ m{^https?\://}) {
+ ($scheme,$provider,$path) = ($ltihash->{'url'} =~ m{^(https?\://)([^/]+)(|/.+)$});
} else {
- $providerurl = $ltihash->{'url'};
+ $path = $ltihash->{'url'};
}
$tooltarget = $toolhash{'target'};
if ($tooltarget eq 'window') {
@@ -566,6 +613,7 @@ sub extedit_form {
if ($ltihash->{'crsconf'}->{'append'}) {
$crsappend = $toolhash{'crsappend'};
$appendstyle = 'display:inline';
+ $showprovider = 1;
}
if ($ltihash->{'crsconf'}->{'target'}) {
$dispdivstyle = 'display:block';
@@ -576,9 +624,52 @@ sub extedit_form {
if ($ltihash->{'crsconf'}->{'explanation'}) {
$explanationstyle = 'padding:0;display:inline';
}
+ if ($ltihash->{'crsconf'}->{'returnurl'}) {
+ $returnurl = $toolhash{'returnurl'};
+ $returnurlstyle = 'display:inline';
+ $backtourl = $toolhash{'backtourl'};
+ if ($returnurl eq 'none') {
+ $chknoreturn = ' checked="checked"';
+ $customreturn = 'hidden';
+ } elsif (($returnurl eq 'custom') && ($backtourl ne '')) {
+ $chkreturncust = ' checked="checked"';
+ $customreturn = 'text';
+ } else {
+ $chkreturndef = ' checked="checked"';
+ $customreturn = 'hidden';
+ }
+ }
+ if ($ltihash->{'crsconf'}->{'desturl'}) {
+ $desturl = $toolhash{'desturl'};
+ $desturlstyle = 'display:inline';
+ $delay = $toolhash{'delay'};
+ $showprovider = 1;
+ if ($desturl ne '') {
+ $desturlinfostyle = 'display:inline';
+ $chkdest = ' checked="checked"';
+ $chknodest = '';
+ } else {
+ $desturlinfostyle = 'display:none';
+ $chkdest = '';
+ $chknodest = ' checked="checked"';
+ }
+ } else {
+ $nocrsdest = 1;
+ }
}
$toolelem = ''.$image.' '.$tooltitle.'
';
$gradablestyle = 'display:inline';
+ if (($ltihash->{'desturl'}) && ($nocrsdest) && ($ltihash->{'defdest'} =~ m{^(https?\://|/)})) {
+ $fixeddest = $ltihash->{'defdest'};
+ if ($ltihash->{'defdelay'} =~ /^\d+\.?\d*$/) {
+ $fixeddelay = $ltihash->{'defdelay'};
+ }
+ $desturlfixedstyle = 'display:inline-block';
+ $showprovider = 1;
+ }
+ if (($showprovider) && ($provider ne '')) {
+ $providerstyle = 'display:inline-block';
+ }
}
}
} else {
@@ -658,9 +749,49 @@ sub extedit_form {
$crslabel = $env{'course.'.$cdom.'_'.$cnum.'.internal.coursecode'};
$crstitle = $env{'course.'.$cdom.'_'.$cnum.'.description'};
$crsappend = '';
+ $returnurl = '';
+ $backtourl = '';
+ $customreturn = 'hidden';
$chknogrd = ' checked="checked"';
- }
- $toolelem .= '