--- loncom/interface/lonextresedit.pm 2025/03/15 01:03:33 1.36 +++ 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.36 2025/03/15 01:03:33 raeburn Exp $ +# $Id: lonextresedit.pm,v 1.37 2025/06/14 02:50:25 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -310,12 +310,32 @@ sub update_exttool { my (%newhash,$changed,$newgradable,@deleted,$errormsg); ($newhash{'target'},$newhash{'width'},$newhash{'height'},$newhash{'linktext'},$newhash{'explanation'}, $newhash{'crslabel'},$newhash{'crstitle'},$newhash{'crsappend'},$newhash{'gradable'}, - $newhash{'returnurl'},$newhash{'backtourl'}) = split(/:/,$args); - foreach my $item ('linktext','explanation','crslabel','crstitle','crsappend','backtourl') { + $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','returnurl','backtourl') { + 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')) { @@ -334,6 +354,22 @@ sub update_exttool { 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)) { @@ -400,9 +436,9 @@ sub extedit_form { $tabid = 'ee'; } my ($formname,$formid,$toggle,$fieldsetid,$urlid,$subdivid,$dispdivstyle,$dimendivstyle, - $windivstyle,$linktextstyle,$explanationstyle,$labelstyle,$titlestyle, - $appendstyle,$gradablestyle,$returnurlstyle,$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'; @@ -411,7 +447,9 @@ sub extedit_form { 'crstitlediv','crslabeldiv','crsappenddiv', 'gradablediv','returnurldiv','crstitle','crslabel', 'crsappend','windiv','linktextdiv','explanationdiv', - 'linktext','explanation','providerurl','customreturnurl'); + 'linktext','explanation','provider','providerpath','customreturnurl', + 'desturl','delay','providerdiv','desturldiv','desturlinfodiv', + 'desturlfixeddiv','fixeddest','fixeddelay'); $dispdivstyle = 'display:none'; $dimendivstyle = 'display:none'; $windivstyle = 'display:none'; @@ -419,9 +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; @@ -432,8 +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,$returnurl,$chkgrd,$chknogrd,%chkstate, - $chknoreturn,$chkreturndef,$chkreturncust,$customreturn,$backtourl); + $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'); @@ -507,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$}) { @@ -516,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')) { @@ -537,10 +576,10 @@ sub extedit_form { if ($icon) { $image = ''.$tooltitle.''; } - 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') { @@ -574,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'; @@ -599,9 +639,37 @@ sub extedit_form { $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 { @@ -688,9 +756,42 @@ sub extedit_form { $chknoreturn = ''; $chkreturndef = ' checked="checked"'; $chkreturncust = ''; + $chknodest = ' checked="checked"'; + $chkdest = ''; } my $onclickreturl = ' onclick="updateReturnUrl('."this.form,'$toolattr{'customreturnurl'}','$toolattr{'returnurldiv'}','exttoolreturnurl'".');"'; - $toolelem .= '
'. + my $onclickdest = ' onclick="updateDestUrl('."this.form,'$toolattr{'desturlinfodiv'}','$toolattr{'desturldiv'}','exttooldest'".');"'; + $toolelem.= '
'. + ''.&mt('Provider').': '.$scheme.$provider.'
'. + ''.&mt('Provider path').': '.$path.''."\n". + '
'."\n". + '
'. + '
'. + ''.&mt('Append to LTI login URL').':
'. + ''. + '
'."\n". + '
'. + '
'. + ''.&mt('Post-login destination different from path').': '. + ''.(' 'x2). + ''.(' 'x2). + '
'."\n". + '
'. + ''. + '
'. + '
'."\n". + '
'. + ''.&mt('Destination after provider login').': '. + '
'.$fixeddest.'
'. + '
'. + &mt('Post-login delay before redirect to destination').': '.$fixeddelay.' s'."\n". + '
'. + '
'. + '
'. ''.&mt('Display target:').' '. '
'; - $toolelem .= '
'. - '
'. - ''.&mt('Link Text').'
'. - '
'. - ''.&mt('Explanation').'
'. - '
'. - '
'; - $toolelem .= '
'. + '
'. + '
'. + '
'. + ''.&mt('Link Text').'
'. + '
'. + ''.&mt('Explanation').'
'. + '
'. + '
'. + '
'. ''.&mt('Course label:').' '. '
'. '
'."\n". @@ -722,11 +823,6 @@ sub extedit_form { ''.&mt('Course title:').' '. '
'. ''."\n". - '
'. - ''.&mt('Append to URL[_1]', - ' ('.$providerurl.')
'). - '

'. - '
'."\n". '
'. ''.&mt('Gradable').' '. '