--- loncom/interface/lonextresedit.pm 2023/07/11 23:17:40 1.8.2.4.4.3 +++ loncom/interface/lonextresedit.pm 2025/03/15 03:10:09 1.8.2.4.4.4 @@ -1,7 +1,7 @@ # The LearningOnline Network # Documents # -# $Id: lonextresedit.pm,v 1.8.2.4.4.3 2023/07/11 23:17:40 raeburn Exp $ +# $Id: lonextresedit.pm,v 1.8.2.4.4.4 2025/03/15 03:10:09 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -311,12 +311,13 @@ 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'}) = split(/:/,$args); + foreach my $item ('linktext','explanation','crslabel','crstitle','crsappend','backtourl') { $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') { + foreach my $item ('target','width','height','linktext','explanation','crslabel','crstitle','crsappend','gradable','returnurl','backtourl') { $newhash{$item} =~ s/^\s+//; $newhash{$item} =~ s/\s+$//; if (($item eq 'width') || ($item eq 'height') || ($item eq 'linktext') || ($item eq 'explanation')) { @@ -331,6 +332,10 @@ sub update_exttool { unless ($newhash{$item} == 1) { $newhash{$item} = ''; } + } elsif ($item eq 'backtourl') { + unless ($newhash{'returnurl'} eq 'custom') { + $newhash{$item} = ''; + } } if ($toolhash{$item} ne $newhash{$item}) { if (($item eq 'gradable') && (!$supplementalflag)) { @@ -354,7 +359,7 @@ sub update_exttool { } } else { $toolhash{$item} = $newhash{$item}; - $changed = 1; + $changed = 1; } } } @@ -398,16 +403,17 @@ sub extedit_form { } my ($formname,$formid,$toggle,$fieldsetid,$urlid,$subdivid,$dispdivstyle,$dimendivstyle, $windivstyle,$linktextstyle,$explanationstyle,$labelstyle,$titlestyle, - $appendstyle,$gradablestyle,$subdivstyle,$legend,$urlelem,$toolelem,%toolattr); + $appendstyle,$gradablestyle,$returnurlstyle,$subdivstyle,$legend,$urlelem, + $toolelem,%toolattr); $formname = 'new'.$type; $toggle = $type; $fieldsetid = 'upload'.$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','providerurl','customreturnurl'); $dispdivstyle = 'display:none'; $dimendivstyle = 'display:none'; $windivstyle = 'display:none'; @@ -417,6 +423,7 @@ sub extedit_form { $titlestyle = 'display:none'; $appendstyle = 'display:none'; $gradablestyle = 'display:none'; + $returnurlstyle = 'display:none'; $subdivstyle = 'display:block'; if ($supplementalflag) { $formname = 'newsupp'.$type; @@ -427,7 +434,8 @@ 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,$providerurl,$returnurl,$chkgrd,$chknogrd,%chkstate, + $chknoreturn,$chkreturndef,$chkreturncust,$customreturn,$backtourl); $fieldsetstyle = 'display: none;'; $action = '/adm/coursedocs'; my $protocol = ($ENV{'SERVER_PORT'} == 443?'https':'http'); @@ -578,6 +586,21 @@ 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'; + } + } } $toolelem = ''.$image.' '.$tooltitle.'
'; $gradablestyle = 'display:inline'; @@ -660,8 +683,15 @@ sub extedit_form { $crslabel = $env{'course.'.$cdom.'_'.$cnum.'.internal.coursecode'}; $crstitle = $env{'course.'.$cdom.'_'.$cnum.'.description'}; $crsappend = ''; + $returnurl = ''; + $backtourl = ''; + $customreturn = 'hidden'; $chknogrd = ' checked="checked"'; + $chknoreturn = ''; + $chkreturndef = ' checked="checked"'; + $chkreturncust = ''; } + my $onclickreturl = ' onclick="updateReturnUrl('."this.form,'$toolattr{'customreturnurl'}','$toolattr{'returnurldiv'}','exttoolreturnurl'".');"'; $toolelem .= '
'. ''.&mt('Display target:').' '. '
'. + ''."\n". '
'. ''.&mt('Course title:').' '. '
'. - '
'. + ''."\n". '
'. ''.&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') { @@ -840,7 +880,8 @@ sub extedit_javascript { " var ltitoolsExplain = new Array();\n". " var ltitoolsLabel = new Array();\n". " var ltitoolsTitle = new Array();\n". - " var ltitoolsAppend = new Array();\n"; + " var ltitoolsAppend = new Array();\n". + " var ltitoolsReturnUrl = new Array();\n"; $exttoolnums = " var ltitoolsnum = new Array();\n". " var tooloptval = new Array();\n". " var toolopttxt = new Array();\n"; @@ -860,7 +901,8 @@ sub extedit_javascript { " ltitoolsExplain[$idx] = new Array($num);\n". " ltitoolsLabel[$idx] = new Array($num);\n". " ltitoolsTitle[$idx] = new Array($num);\n". - " ltitoolsAppend[$idx] = new Array($num);\n"; + " ltitoolsAppend[$idx] = new Array($num);\n". + " ltitoolsReturnUrl[$idx] = new Array($num);\n"; my $i=0; foreach my $key (sort { $a <=> $b } keys(%{$toolsref->{$type}})) { if (ref($toolsref->{$type}->{$key}) eq 'HASH') { @@ -899,6 +941,8 @@ sub extedit_javascript { $toolsjs .= " ltitoolsTitle[$idx][$i] = '$title';\n"; my $append = $toolsref->{$type}->{$key}->{'crsconf'}->{'append'}; $toolsjs .= " ltitoolsAppend[$idx][$i] = '$append';\n"; + my $returnurl = $toolsref->{$type}->{$key}->{'crsconf'}->{'returnurl'}; + $toolsjs .= " ltitoolsReturnUrl[$idx][$i] = '$returnurl';\n"; } } $i++; @@ -1056,10 +1100,12 @@ function setExternal(extform,residx,type var labelinput = prefix+'toolcrslabel'; var titleinput = prefix+'toolcrstitle'; var appendinput = prefix+'toolcrsappend'; + var customreturnurl = prefix+'customreturnurl'; if (residx > 0) { labelinput += '_'+residx; titleinput += '_'+residx; appendinput += '_'+residx; + customreturnurl += '_'+residx; } if (document.getElementById(labelinput)) { var crslabel = document.getElementById(labelinput).value; @@ -1108,6 +1154,33 @@ function setExternal(extform,residx,type } else { info += ':'; } + var returnurldiv = prefix+'toolreturnurldiv'; + if (residx > 0) { + returnurldiv += '_'+residx; + } + if (document.getElementById(returnurldiv)) { + if (document.getElementById(returnurldiv).style.display == 'inline') { + if (extform.exttoolreturnurl.length) { + for (var i=0; i 0) { eval("extform.importdetail.value=title+'='+info+'='+residx;extform.submit();"); @@ -1290,6 +1363,7 @@ function updateExttool(caller,form,suppl titlediv = prefix+'toolcrstitlediv'; appenddiv = prefix+'toolcrsappenddiv'; gradablediv = prefix+'toolgradablediv'; + returnurldiv = prefix+'toolreturnurldiv'; providerurl = prefix+'toolproviderurl'; labelinput = prefix+'toolcrslabel'; titleinput = prefix+'toolcrstitle'; @@ -1330,6 +1404,9 @@ function updateExttool(caller,form,suppl if (document.getElementById(gradablediv)) { document.getElementById(gradablediv).style.display = 'none'; } + if (document.getElementById(returnurldiv)) { + document.getElementById(returnurldiv).style.display = 'none'; + } } else { var tooltype = ''; var typeelem = form.elements[prefix+'exttooltype']; @@ -1447,6 +1524,13 @@ function updateExttool(caller,form,suppl document.getElementById(gradablediv).style.display = 'inline'; } } + if (document.getElementById(returnurldiv)) { + if (ltitoolsReturnUrl[i][j]) { + document.getElementById(returnurldiv).style.display = 'inline'; + } else { + document.getElementById(returnurldiv).style.display = 'none'; + } + } break; } } @@ -1456,6 +1540,30 @@ function updateExttool(caller,form,suppl } } +function updateReturnUrl(form,typeid,divid,radioname) { + if ((document.getElementById(typeid)) && + (document.getElementById(divid))) { + if (document.getElementById(divid).style.display == 'inline') { + var radelem = form.elements[radioname]; + var inputtype = 'hidden'; + if (radelem.length) { + for (var i=0; i