--- loncom/interface/lonextresedit.pm 2022/09/09 14:24:30 1.30
+++ 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.30 2022/09/09 14:24:30 raeburn Exp $
+# $Id: lonextresedit.pm,v 1.37 2025/06/14 02:50:25 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -98,7 +98,18 @@ sub handler {
}
my %ltitools;
if ($type eq 'tool') {
- %ltitools = &Apache::lonnet::get_domain_lti($cdom,'consumer');
+ my (%domtools,%crstools);
+ my %tooltypes = &Apache::loncommon::usable_exttools();
+ if ($tooltypes{'dom'}) {
+ %domtools = &Apache::lonnet::get_domain_lti($cdom,'consumer');
+ }
+ if ($tooltypes{'crs'}) {
+ %crstools = &Apache::lonnet::get_course_lti($cnum,$cdom,'consumer');
+ }
+ %ltitools = (
+ dom => \%domtools,
+ crs => \%crstools,
+ );
}
my $js = &Apache::lonhtmlcommon::scripttag(&extedit_javascript());
my $pathitem = '';
} 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$}) {
my $marker = $1;
my %toolhash=&Apache::lonnet::dump('exttool_'.$marker,$cdom,$cnum);
- if ($toolhash{'id'}) {
- if (ref($ltitools) eq 'HASH') {
- if (keys(%{$ltitools})) {
- if (ref($ltitools->{$toolhash{'id'}}) eq 'HASH') {
- my $tooltitle = $ltitools->{$toolhash{'id'}}->{'title'};
- my $icon = $ltitools->{$toolhash{'id'}}->{'image'};
- my $image;
- if ($icon) {
- $image = '
';
- }
- if ($ltitools->{$toolhash{'id'}}->{'url'} =~ m{://}) {
- (my $prot,my $host,$providerurl) = ($ltitools->{$toolhash{'id'}}->{'url'} =~ m{^([^/]+)://([^/]+)(|/.+)$});
- } else {
- $providerurl = $ltitools->{$toolhash{'id'}}->{'url'};
- }
- $tooltarget = $toolhash{'target'};
- if ($tooltarget eq 'window') {
- $dimendivstyle = 'display:block';
- $windivstyle = 'display:block';
- $chkstate{'window'} = 'checked="checked" ';
- } elsif ($tooltarget eq 'tab') {
- $windivstyle = 'display:block';
- $chkstate{'tab'} = 'checked="checked" ';
- } else {
- $chkstate{'iframe'} = 'checked="checked" ';
- }
- $width = $toolhash{'width'};
- $height = $toolhash{'height'};
- $linktext = $toolhash{'linktext'};
- $explanation = $toolhash{'explanation'};
- if ($toolhash{'gradable'}) {
- $chkgrd = ' checked="checked"';
- } else {
- $chknogrd = ' checked="checked"';
- }
- if (ref($ltitools->{$toolhash{'id'}}->{'crsconf'}) eq 'HASH') {
- if ($ltitools->{$toolhash{'id'}}->{'crsconf'}->{'title'}) {
- $crstitle = $toolhash{'crstitle'};
- $titlestyle = 'display:inline';
- }
- if ($ltitools->{$toolhash{'id'}}->{'crsconf'}->{'label'}) {
- $crslabel = $toolhash{'crslabel'};
- $labelstyle = 'display:inline';
- }
- if ($ltitools->{$toolhash{'id'}}->{'crsconf'}->{'append'}) {
- $crsappend = $toolhash{'crsappend'};
- $appendstyle = 'display:inline';
- }
- if ($ltitools->{$toolhash{'id'}}->{'crsconf'}->{'target'}) {
- $dispdivstyle = 'display:block';
- }
- if ($ltitools->{$toolhash{'id'}}->{'crsconf'}->{'linktext'}) {
- $linktextstyle = 'padding:0;display:inline';
- }
- if ($ltitools->{$toolhash{'id'}}->{'crsconf'}->{'explanation'}) {
- $explanationstyle = 'padding:0;display:inline';
- }
- }
- $toolelem = ''.$image.' '.$tooltitle.'
';
- $gradablestyle = 'display:inline';
+ 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 '') && (ref($ltitools) eq 'HASH')) {
+ if (ref($ltitools->{$tooltype}) eq 'HASH') {
+ $ltihash = $ltitools->{$tooltype}->{$tool};
+ }
+ }
+ if (($tool ne '') && (ref($ltihash) eq 'HASH')) {
+ my $tooltitle = $ltihash->{'title'};
+ my $icon = $ltihash->{'image'};
+ my $image;
+ if ($icon) {
+ $image = '
';
+ }
+ if ($ltihash->{'url'} =~ m{^https?\://}) {
+ ($scheme,$provider,$path) = ($ltihash->{'url'} =~ m{^(https?\://)([^/]+)(|/.+)$});
+ } else {
+ $path = $ltihash->{'url'};
+ }
+ $tooltarget = $toolhash{'target'};
+ if ($tooltarget eq 'window') {
+ $dimendivstyle = 'display:block';
+ $windivstyle = 'display:block';
+ $chkstate{'window'} = 'checked="checked" ';
+ } elsif ($tooltarget eq 'tab') {
+ $windivstyle = 'display:block';
+ $chkstate{'tab'} = 'checked="checked" ';
+ } else {
+ $chkstate{'iframe'} = 'checked="checked" ';
+ }
+ $width = $toolhash{'width'};
+ $height = $toolhash{'height'};
+ $linktext = $toolhash{'linktext'};
+ $explanation = $toolhash{'explanation'};
+ if ($toolhash{'gradable'}) {
+ $chkgrd = ' checked="checked"';
+ } else {
+ $chknogrd = ' checked="checked"';
+ }
+ if (ref($ltihash->{'crsconf'}) eq 'HASH') {
+ if ($ltihash->{'crsconf'}->{'title'}) {
+ $crstitle = $toolhash{'crstitle'};
+ $titlestyle = 'display:inline';
+ }
+ if ($ltihash->{'crsconf'}->{'label'}) {
+ $crslabel = $toolhash{'crslabel'};
+ $labelstyle = 'display:inline';
+ }
+ if ($ltihash->{'crsconf'}->{'append'}) {
+ $crsappend = $toolhash{'crsappend'};
+ $appendstyle = 'display:inline';
+ $showprovider = 1;
+ }
+ if ($ltihash->{'crsconf'}->{'target'}) {
+ $dispdivstyle = 'display:block';
+ }
+ if ($ltihash->{'crsconf'}->{'linktext'}) {
+ $linktextstyle = 'padding:0;display:inline';
+ }
+ 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 {
- $toolelem = ''."\n".
- '
';
+ foreach my $type ('crs','dom') {
+ $toolelem .= ' '."\n";
+ }
+ $toolelem .= '
'.
+ '
'."\n".
+ ''.
+ $exttypeofftext.
+ '
'."\n";
$crslabel = $env{'course.'.$cdom.'_'.$cnum.'.internal.coursecode'};
$crstitle = $env{'course.'.$cdom.'_'.$cnum.'.description'};
$crsappend = '';
+ $returnurl = '';
+ $backtourl = '';
+ $customreturn = 'hidden';
$chknogrd = ' checked="checked"';
- }
- $toolelem .= '';
- $toolelem .= '';
- $toolelem .= ''.
+ '
'.
+ ''.
+ ''.
''.&mt('Course label:').' '.
'
'.
- '
'.
+ ''."\n".
''.
''.&mt('Course title:').' '.
'
'.
- '
'.
- ''.
- ''.&mt('Append to URL[_1]',
- ' ('.$providerurl.')
').
- '
'.
- '
'.
+ ''."\n".
''.
''.&mt('Gradable').' '.
''.(' 'x2).
'
';
+ ' />'.&mt('No').'
'."\n".
+ ''.
+ ''.&mt('Include return URL').': '.
+ ''.(' 'x2).
+ ''.(' 'x2).
+ '
'."\n".
+ ''.
+ '
'."\n";
}
my $chooser = $toolelem;
if ($type eq 'ext') {
$chooser = "
+
$preview
";
}
+ my $idattr;
+ unless ($subdivid eq '') {
+ $idattr = 'id="'.$subdivid.'"';
+ }
$form = <