--- loncom/interface/lonextresedit.pm 2022/09/09 14:29:45 1.8.2.4.2.3
+++ loncom/interface/lonextresedit.pm 2022/09/09 14:24:30 1.30
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Documents
#
-# $Id: lonextresedit.pm,v 1.8.2.4.2.3 2022/09/09 14:29:45 raeburn Exp $
+# $Id: lonextresedit.pm,v 1.30 2022/09/09 14:24:30 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -161,6 +161,9 @@ sub process_changes {
$newurl = $1;
$marker = $2;
$args = $3;
+ if ((!$symb) && (!$supplementalflag)) {
+ $symb = "uploaded/$cdom/$cnum/$folder.$container"."___$newidx"."___adm/$cdom/$cnum/$marker/ext.tool";
+ }
}
}
if ($supplementalflag) {
@@ -170,7 +173,7 @@ sub process_changes {
}
if ($folder && $container) {
if ($env{'form.importdetail'}) {
- my ($errtext,$fatal,$mismatchedid,@imports);
+ my ($errtext,$fatal,$mismatchedid,$needreload,$newgradable,@imports);
if (!$supplementalflag) {
if (($oldidx) && ($oldidx != $newidx)) {
$mismatchedid = 1;
@@ -181,9 +184,27 @@ sub process_changes {
} elsif (($newtitle eq $oldtitle) && ($newurl eq $oldurl)) {
if ($type eq 'tool') {
if ($args) {
- ($updated,$errormsg) = &update_exttool($marker,$cdom,$cnum,$args);
- unless ($updated) {
- $output = &mt('No change');
+ ($updated,$newgradable,$errormsg) = &update_exttool($marker,$cdom,$cnum,
+ $supplementalflag,$args);
+ if ($updated) {
+ if ($newgradable) {
+ my $map = "/uploaded/$cdom/$cnum/$folder.$container";
+ my ($errtext,$fatal) = &LONCAPA::map::mapread($map);
+ if ($fatal) {
+ $errormsg = &mt('Update failed: [_1].',$errtext);
+ } else {
+ &LONCAPA::map::storeparameter($residx,'parameter_0_gradable',
+ $newgradable,'string_yesno');
+ my ($outtext,$errtext) = &LONCAPA::map::storemap($map,1,1);
+ if ($errtext) {
+ $errormsg = &mt('Update failed: [_1].',$errtext);
+ } else {
+ $needreload = 1;
+ }
+ }
+ }
+ } else {
+ $output = &mt('No change');
}
} else {
$output = &mt('No change');
@@ -202,13 +223,25 @@ sub process_changes {
my $ext = 'true';
if ($type eq 'tool') {
if ($args) {
- ($updated,$errormsg) = &update_exttool($marker,$cdom,$cnum,$args);
+ ($updated,$newgradable,$errormsg) = &update_exttool($marker,$cdom,$cnum,
+ $supplementalflag,$args);
+ if ($newgradable) {
+ &LONCAPA::map::storeparameter($residx,'parameter_0_gradable',$newgradable,
+ 'string_yesno');
+ $needreload = 1;
+ }
}
$ext = 'false';
}
+ my $dotimeupdate;
+ unless ($supplementalflag) {
+ if (($newgradable) || ($newurl ne $oldurl)) {
+ $dotimeupdate = 1;
+ }
+ }
$LONCAPA::map::resources[$residx] =
join(':', ($savetitle,$saveurl,$ext,'normal','res'));
- my ($outtext,$errtext) = &LONCAPA::map::storemap($map,1);
+ my ($outtext,$errtext) = &LONCAPA::map::storemap($map,1,$dotimeupdate);
if ($errtext) {
$errormsg = &mt('Update failed: [_1].',$errtext);
} else {
@@ -230,19 +263,24 @@ sub process_changes {
&Apache::lonnet::devalidate_title_cache($symb);
}
}
- }
- my ($furl,$ferr) =
- &Apache::lonuserstate::readmap("$cdom/$cnum");
- if ($ferr) {
- $errormsg = &mt('Reload failed: [_1].',$ferr);
- } else {
- unless ($supplementalflag) {
- &Apache::loncommon::update_content_constraints($cdom,$cnum,$chome,$cdom.'_'.$cnum);
- }
+ $needreload = 1;
}
}
}
}
+ if ($needreload) {
+ my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
+ if ($ferr) {
+ $errormsg = &mt('Reload failed: [_1].',$ferr);
+ } else {
+ &Apache::loncommon::update_content_constraints($cdom,$cnum,$chome,
+ $cdom.'_'.$cnum);
+ }
+ }
+ if (($type eq 'tool') && ($newgradable)) {
+ my $uri = &Apache::lonnet::declutter($url);
+ &Apache::lonnet::devalidate_cache_new('meta',$uri);
+ }
} else {
$output = &mt('No change');
}
@@ -257,15 +295,15 @@ sub process_changes {
}
sub update_exttool {
- my ($marker,$cdom,$cnum,$args) = @_;
- my (%newhash,$changed,@deleted,$errormsg);
+ 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'}) = split(/:/,$args);
+ $newhash{'crslabel'},$newhash{'crstitle'},$newhash{'crsappend'},$newhash{'gradable'}) = split(/:/,$args);
foreach my $item ('linktext','explanation','crslabel','crstitle','crsappend') {
$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') {
+ foreach my $item ('target','width','height','linktext','explanation','crslabel','crstitle','crsappend','gradable') {
$newhash{$item} =~ s/^\s+//;
$newhash{$item} =~ s/\s+$//;
if (($item eq 'width') || ($item eq 'height') || ($item eq 'linktext') || ($item eq 'explanation')) {
@@ -276,8 +314,19 @@ sub update_exttool {
$newhash{$item} = '';
}
}
+ } elsif ($item eq 'gradable') {
+ unless ($newhash{$item} == 1) {
+ $newhash{$item} = '';
+ }
}
if ($toolhash{$item} ne $newhash{$item}) {
+ if (($item eq 'gradable') && (!$supplementalflag)) {
+ if ($newhash{$item}) {
+ $newgradable = 'yes';
+ } else {
+ $newgradable = 'no';
+ }
+ }
if ($newhash{$item} eq '') {
unless (($item eq 'target') ||
((($item eq 'width') || ($item eq 'height')) &&
@@ -305,7 +354,7 @@ sub update_exttool {
if (@deleted) {
&Apache::lonnet::del('exttool_'.$marker,\@deleted,$cdom,$cnum);
}
- return ($changed,$errormsg);
+ return ($changed,$newgradable,$errormsg);
}
sub extedit_form {
@@ -334,16 +383,16 @@ sub extedit_form {
}
my ($formname,$formid,$toggle,$fieldsetid,$urlid,$dispdivstyle,$dimendivstyle,
$windivstyle,$linktextstyle,$explanationstyle,$labelstyle,$titlestyle,
- $appendstyle,$legend,$urlelem,$toolelem,%toolattr);
+ $appendstyle,$gradablestyle,$legend,$urlelem,$toolelem,%toolattr);
$formname = 'new'.$type;
$toggle = $type;
- $fieldsetid = 'upload'.$type.'form';
+ $fieldsetid = 'external'.$type.'form';
$urlid = $type.'url';
map { $toolattr{$_} = $type.$_; } ('dispdiv','dimendiv','dimenwidth','dimenheight',
'crstitlediv','crslabeldiv','crsappenddiv',
- 'crstitle','crslabel','crsappend','windiv',
- 'linktextdiv','explanationdiv','linktext',
- 'explanation','providerurl');
+ 'gradablediv','crstitle','crslabel','crsappend',
+ 'windiv','linktextdiv','explanationdiv',
+ 'linktext','explanation','providerurl');
$dispdivstyle = 'display:none';
$dimendivstyle = 'display:none';
$windivstyle = 'display:none';
@@ -352,16 +401,17 @@ sub extedit_form {
$labelstyle = 'display:none';
$titlestyle = 'display:none';
$appendstyle = 'display:none';
+ $gradablestyle = 'display:none';
if ($supplementalflag) {
$formname = 'newsupp'.$type;
$toggle = 'supp'.$type;
- $fieldsetid = 'uploadsupp'.$type.'form';
+ $fieldsetid = 'externalsupp'.$type.'form';
$urlid = 'supp'.$type.'url';
map { $toolattr{$_} = 'supp'.$toolattr{$_}; } (keys(%toolattr));
}
my ($link,$legend,$active,$srcclass,$extsrc,$preview,$title,$save,$crstitle,$crslabel,
$crsappend,$fieldsetstyle,$action,$hiddenelem,$form,$width,$height,$tooltarget,
- $linktext,$explanation,$providerurl,%chkstate);
+ $linktext,$explanation,$providerurl,$chkgrd,$chknogrd,%chkstate);
$fieldsetstyle = 'display: none;';
$action = '/adm/coursedocs';
my $protocol = ($ENV{'SERVER_PORT'} == 443?'https':'http');
@@ -393,7 +443,7 @@ sub extedit_form {
$active = '';
}
$formname = 'edit'.$type.'_'.$residx;
- $fieldsetid = 'upload'.$type.$residx;
+ $fieldsetid = 'external'.$type.$residx;
$urlid = $type.'url_'.$residx;
map { $toolattr{$_} .= '_'.$residx; } (keys(%toolattr));
$srcclass = ' class="LC_nobreak"';
@@ -408,7 +458,7 @@ sub extedit_form {
if ($type eq 'tool') {
$link = $lt{'et'};
}
- $link = ''.$link.''.$helpitem;
+ $link = ''.$link.''.$helpitem;
if ($type eq 'tool') {
$legend = $lt{'te'};
} else {
@@ -470,6 +520,11 @@ sub extedit_form {
$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'};
@@ -494,6 +549,7 @@ sub extedit_form {
}
}
$toolelem = ''.$image.' '.$tooltitle.'
';
+ $gradablestyle = 'display:inline';
}
}
}
@@ -526,6 +582,7 @@ sub extedit_form {
$crslabel = $env{'course.'.$cdom.'_'.$cnum.'.internal.coursecode'};
$crstitle = $env{'course.'.$cdom.'_'.$cnum.'.description'};
$crsappend = '';
+ $chknogrd = ' checked="checked"';
}
$toolelem .= '