--- loncom/interface/lonparmset.pm 2016/07/19 21:55:12 1.563
+++ loncom/interface/lonparmset.pm 2017/07/13 13:57:48 1.577
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Handler to set parameters for assessments
#
-# $Id: lonparmset.pm,v 1.563 2016/07/19 21:55:12 damieng Exp $
+# $Id: lonparmset.pm,v 1.577 2017/07/13 13:57:48 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -371,10 +371,10 @@ sub endSettingsScreen {
# (parmval is also used for the log of parameter changes)
##################################################
-# Calls parmval_by_symb, getting the symb from $id (the big hash resource id) with &symbcache.
+# Calls parmval_by_symb, getting the symb from $id with &symbcache.
#
# @param {string} $what - part info and parameter name separated by a dot, e.g. '0.weight'
-# @param {string} $id - big hash resource id
+# @param {string} $id - resource id or map pc
# @param {string} $def - the resource's default value for this parameter
# @param {string} $uname - user name
# @param {string} $udom - user domain
@@ -394,7 +394,7 @@ sub parmval {
# (level 1 is the most specific and will have precedence)
#
# @param {string} $what - part info and parameter name separated by a dot, e.g. '0.weight'
-# @param {string} $symb - resource symb
+# @param {string} $symb - resource symb or map src
# @param {string} $def - the resource's default value for this parameter
# @param {string} $uname - user name
# @param {string} $udom - user domain
@@ -597,7 +597,7 @@ sub reset_caches {
}
}
-# cache big hash id -> symb, using lonnavmaps to find association
+# cache resource id or map pc -> resource symb or map src, using lonnavmaps to find association
{
my $symbsid; # course identifier, to initialize the cache only once for a course
my %symbs; # hash id->symb
@@ -607,7 +607,8 @@ sub reset_caches {
undef(%symbs);
}
- # returns the symb corresponding to a big hash id (using lonnavmaps and a cache)
+ # returns the resource symb or map src corresponding to a resource id or map pc
+ # (using lonnavmaps and a cache)
sub symbcache {
my $id=shift;
if ($symbsid ne $env{'request.course.id'}) {
@@ -718,8 +719,8 @@ sub date_sanity_info {
# Store a parameter value and type by ID, also triggering more parameter changes based on parameter default actions.
#
-# @param {string} $sresid - resource big hash id
-# @param {string} $spnam - part info and parameter name separated by a dot, e.g. '0.weight'
+# @param {string} $sresid - resource id or map pc
+# @param {string} $spnam - part info and parameter name separated by a dot or underscore, e.g. '0.weight'
# @param {integer} $snum - level
# @param {string} $nval - new value
# @param {string} $ntype - new type
@@ -737,8 +738,8 @@ my %recstack; # hash parameter name -> 1
# Store a parameter value and type by symb, also triggering more parameter changes based on parameter default actions.
# Uses storeparm_by_symb_inner to actually store the parameter, ignoring any returned error.
#
-# @param {string} $symb - resource symb
-# @param {string} $spnam - part info and parameter name separated by a dot, e.g. '0.weight'
+# @param {string} $symb - resource symb or map src
+# @param {string} $spnam - part info and parameter name separated by a dot or underscore, e.g. '0.weight'
# @param {integer} $snum - level
# @param {string} $nval - new value
# @param {string} $ntype - new type
@@ -776,8 +777,7 @@ sub storeparm_by_symb {
# are there restrictions?
if (&rulescache($triggered.'_triggervalue')=~/\w/) {
$active=0;
- foreach my $possiblevalue (split(/\s*\,
- \s*/,&rulescache($triggered.'_triggervalue'))) {
+ foreach my $possiblevalue (split(/\s*\,\s*/,&rulescache($triggered.'_triggervalue'))) {
if (lc($possiblevalue) eq lc($nval)) { $active=1; }
}
}
@@ -808,7 +808,7 @@ sub log_parmset {
# Store a parameter value and type by symb, without using the parameter default actions.
# Expire related sheets.
#
-# @param {string} $symb - resource symb
+# @param {string} $symb - resource symb or map src
# @param {string} $spnam - part info and parameter name separated by a dot, e.g. '0.weight'
# @param {integer} $snum - level
# @param {string} $nval - new value
@@ -1365,7 +1365,7 @@ ENDHEAD
# @param {string} $which - parameter key ('parameter_'.part.'_'.name)
# @param {hash reference} $part - parameter key -> parameter part (can be problem part.'_'.response id for response parameters)
# @param {hash reference} $name - parameter key -> parameter name
-# @param {hash reference} $symbp - resource id -> symb
+# @param {hash reference} $symbp - map pc or resource/map id -> map src.'___(all)' or resource symb
# @param {string} $rid - resource id
# @param {hash reference} $default - parameter key -> resource parameter default value
# @param {hash reference} $defaulttype - parameter key -> resource parameter default type
@@ -1380,9 +1380,11 @@ ENDHEAD
# @param {string} $cgroup - group name
# @param {array reference} $usersgroups - list of groups the user belongs to, if any
# @param {boolean} $noeditgrp - true if no edit is allowed for group level parameters
+# @param {boolean} $readonly - true if no editing allowed.
sub print_row {
my ($r,$which,$part,$name,$symbp,$rid,$default,$defaulttype,$display,$defbgone,
- $defbgtwo,$defbgthree,$parmlev,$uname,$udom,$csec,$cgroup,$usersgroups,$noeditgrp)=@_;
+ $defbgtwo,$defbgthree,$parmlev,$uname,$udom,$csec,$cgroup,$usersgroups,$noeditgrp,
+ $readonly)=@_;
my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
my $courseopt=&Apache::lonnet::get_courseresdata($cnum,$cdom);
@@ -1427,27 +1429,27 @@ sub print_row {
if ($parmlev eq 'general') {
if ($uname) {
- &print_td($r,4,$defbgone,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display);
+ &print_td($r,4,$defbgone,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly);
} elsif ($cgroup) {
- &print_td($r,8,$defbgthree,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,$noeditgrp);
+ &print_td($r,8,$defbgthree,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,$noeditgrp,$readonly);
} elsif ($csec) {
- &print_td($r,12,$defbgtwo,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display);
+ &print_td($r,12,$defbgtwo,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly);
} else {
- &print_td($r,18,$defbgone,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display);
+ &print_td($r,18,$defbgone,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly);
}
} elsif ($parmlev eq 'map') {
if ($uname) {
- &print_td($r,3,$defbgone,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display);
- &print_td($r,2,$defbgone,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display);
+ &print_td($r,3,$defbgone,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly);
+ &print_td($r,2,$defbgone,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly);
} elsif ($cgroup) {
- &print_td($r,7,$defbgthree,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,$noeditgrp);
- &print_td($r,6,$defbgthree,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,$noeditgrp);
+ &print_td($r,7,$defbgthree,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,$noeditgrp,$readonly);
+ &print_td($r,6,$defbgthree,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,$noeditgrp,$readonly);
} elsif ($csec) {
- &print_td($r,11,$defbgtwo,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display);
- &print_td($r,10,$defbgtwo,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display);
+ &print_td($r,11,$defbgtwo,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly);
+ &print_td($r,10,$defbgtwo,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly);
} else {
- &print_td($r,17,$defbgone,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display);
- &print_td($r,16,$defbgone,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display);
+ &print_td($r,17,$defbgone,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly);
+ &print_td($r,16,$defbgone,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly);
}
} else {
if ($uname) {
@@ -1467,35 +1469,35 @@ sub print_row {
}
}
- &print_td($r,18,$defbgone,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display);
- &print_td($r,17,$defbgone,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display);
- &print_td($r,16,$defbgone,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display);
- &print_td($r,15,'#FFDDDD',$result,\@outpar,$mprefix,$which,\@typeoutpar,$display);
- &print_td($r,14,'#FFDDDD',$result,\@outpar,$mprefix,$which,\@typeoutpar,$display);
- &print_td($r,13,$defbgone,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display);
+ &print_td($r,18,$defbgone,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly);
+ &print_td($r,17,$defbgone,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly);
+ &print_td($r,16,$defbgone,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly);
+ &print_td($r,15,'#FFDDDD',$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly);
+ &print_td($r,14,'#FFDDDD',$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly);
+ &print_td($r,13,$defbgone,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly);
if ($csec) {
- &print_td($r,12,$defbgtwo,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display);
- &print_td($r,11,$defbgtwo,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display);
- &print_td($r,10,$defbgtwo,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display);
- &print_td($r,9,$defbgtwo,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display);
+ &print_td($r,12,$defbgtwo,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly);
+ &print_td($r,11,$defbgtwo,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly);
+ &print_td($r,10,$defbgtwo,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly);
+ &print_td($r,9,$defbgtwo,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly);
}
if ($cgroup) {
- &print_td($r,8,$defbgthree,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,$noeditgrp);
- &print_td($r,7,$defbgthree,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,$noeditgrp);
- &print_td($r,6,$defbgthree,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,$noeditgrp);
- &print_td($r,5,$defbgthree,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,$noeditgrp);
+ &print_td($r,8,$defbgthree,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,$noeditgrp,$readonly);
+ &print_td($r,7,$defbgthree,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,$noeditgrp,$readonly);
+ &print_td($r,6,$defbgthree,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,$noeditgrp,$readonly);
+ &print_td($r,5,$defbgthree,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,$noeditgrp.$readonly);
}
if ($uname) {
if ($othergrp) {
$r->print($othergrp);
}
- &print_td($r,4,$defbgone,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display);
- &print_td($r,3,$defbgone,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display);
- &print_td($r,2,$defbgone,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display);
- &print_td($r,1,$defbgone,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display);
+ &print_td($r,4,$defbgone,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly);
+ &print_td($r,3,$defbgone,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly);
+ &print_td($r,2,$defbgone,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly);
+ &print_td($r,1,$defbgone,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly);
}
} # end of $parmlev if/else
@@ -1532,31 +1534,40 @@ sub print_row {
# @param {array reference} $typeoutpar - array level -> parameter type (when defined)
# @param {hash reference} $display - parameter key -> full title for the parameter
# @param {boolean} $noeditgrp - true if no edit is allowed for group level parameters
+# @param {boolean} $readonly -true if editing not allowed.
sub print_td {
- my ($r,$which,$defbg,$result,$outpar,$mprefix,$value,$typeoutpar,$display,$noeditgrp)=@_;
+ my ($r,$which,$defbg,$result,$outpar,$mprefix,$value,$typeoutpar,$display,$noeditgrp,$readonly)=@_;
$r->print('
');
my $nolink = 0;
- if ($which == 14 || $which == 15) {
- $nolink = 1;
- } elsif (($env{'request.course.sec'} ne '') && ($which > 12)) {
+ if ($readonly) {
$nolink = 1;
- } elsif ($which == 5 || $which == 6 || $which == 7 || $which == 8) {
- if ($noeditgrp) {
+ } else {
+ if ($which == 14 || $which == 15 || $mprefix =~ /mapalias\&/) {
$nolink = 1;
- }
- } elsif ($mprefix =~ /availablestudent\&$/) {
- if ($which > 4) {
- $nolink = 1;
- }
- } elsif ($mprefix =~ /examcode\&$/) {
- unless ($which == 2) {
+ } elsif (($env{'request.course.sec'} ne '') && ($which > 12)) {
$nolink = 1;
+ } elsif ($which == 5 || $which == 6 || $which == 7 || $which == 8) {
+ if ($noeditgrp) {
+ $nolink = 1;
+ }
+ } elsif ($mprefix =~ /availablestudent\&$/) {
+ if ($which > 4) {
+ $nolink = 1;
+ }
+ } elsif ($mprefix =~ /examcode\&$/) {
+ unless ($which == 2) {
+ $nolink = 1;
+ }
+ } elsif ($mprefix =~ /(encrypturl|hiddenresource)/) {
+ if ($which == 16 || $which == 10 || $which == 6 || $which == 2) {
+ $nolink = 1;
+ }
}
}
if ($nolink) {
- $r->print(&valout($$outpar[$which],$$typeoutpar[$which],$mprefix));
-# FIXME: probably a good thing that mprefix is not used in valout, because it does not look like a parameter name !
+ my ($parmname)=((split(/\&/,$mprefix))[1]=~/\_([^\_]+)$/);
+ $r->print(&valout($$outpar[$which],$$typeoutpar[$which],$parmname));
} else {
$r->print(&plink($$typeoutpar[$which],
$$display{$value},$$outpar[$which],
@@ -1651,16 +1662,16 @@ sub parm_control_group {
# Extracts lots of information about all of the the course's resources into a variety of hashes, using lonnavmaps and lonnet::metadata.
# All the parameters are references and are filled by the sub.
#
-# @param {array reference} $ids - resource ids
-# @param {hash reference} $typep - hash resource id (from big hash) -> resource type (file extension)
-# @param {hash reference} $keyp - hash resource id -> comma-separated list of parameter keys from lonnet::metadata
+# @param {array reference} $ids - resource and map ids
+# @param {hash reference} $typep - hash resource/map id -> resource type (file extension)
+# @param {hash reference} $keyp - hash resource/map id -> comma-separated list of parameter keys from lonnet::metadata
# @param {hash reference} $allparms - hash parameter name -> parameter title
# @param {hash reference} $allparts - hash parameter part -> part title (a parameter part can be problem part.'_'.response id for response parameters)
-# @param {hash reference} $allmaps - hash map id (from big hash) -> map src
-# @param {hash reference} $mapp - hash resource id -> enclosing map src
-# @param {hash reference} $symbp - hash map id or resource id -> map src.'___(all)' for a map or resource symb for a resource
-# @param {hash reference} $maptitles - hash map id or src -> map title (this should really be two separate hashes)
-# @param {hash reference} $uris - hash resource id -> resource src
+# @param {hash reference} $allmaps - hash map pc -> map src
+# @param {hash reference} $mapp - hash map pc or resource/map id -> enclosing map src
+# @param {hash reference} $symbp - hash map pc or resource/map id -> map src.'___(all)' for a map or resource symb for a resource
+# @param {hash reference} $maptitles - hash map pc or src -> map title (this should really be two separate hashes)
+# @param {hash reference} $uris - hash resource/map id -> resource src
# @param {hash reference} $keyorder - hash parameter key -> appearance rank for this parameter when looking through every resource and every parameter, starting at 100 (integer)
# @param {hash reference} $defkeytype - hash parameter name -> parameter type
sub extractResourceInformation {
@@ -1928,7 +1939,7 @@ sub lookUpTableParameter {
'retrypartial' => 'tries',
'discussvote' => 'misc',
'examcode' => 'high_level_randomization',
- );
+ );
}
# Adds the given parameter name to an array of arrays listing all parameters for each category.
@@ -2022,6 +2033,7 @@ sub parmboxes {
$r->print('
'
.'
'.&mt($categories{$key}).'
'."\n");
foreach my $tempkey (&keysindisplayorderCategory($categoryList{$key},$keyorder)) {
+ next if ($tempkey eq '');
$r->print(''
.'
'
@@ -3491,8 +3510,9 @@ ENDMAPONE
foreach my $item (&keysinorder(\%name,\%keyorder)) {
$r->print(&Apache::loncommon::start_data_table_row());
&print_row($r,$item,\%part,\%name,\%symbp,$mapid,\%default,
- \%type,\%display,$defbgone,$defbgtwo,$defbgthree,
- $parmlev,$uname,$udom,$csec,$cgroup,'',$noeditgrp);
+ \%type,\%display,$defbgone,$defbgtwo,$defbgthree,
+ $parmlev,$uname,$udom,$csec,$cgroup,'',$noeditgrp,
+ $readonly);
}
$r->print(&Apache::loncommon::end_data_table()
.''
@@ -3517,7 +3537,7 @@ my $tableopen; # boolean, true if HTML t
# @param {boolean} $readonly - true if values cannot be edited (otherwise more columns are added)
# @returns {string}
sub tablestart {
- my ($readonly) = @_;
+ my ($readonly,$is_map) = @_;
if ($tableopen) {
return '';
} else {
@@ -3526,7 +3546,11 @@ sub tablestart {
if ($readonly) {
$output .= '
'.&mt('Current value').'
';
} else {
- $output .= '
'.&mt('Delete').'
'.&mt('Set to ...').'
';
+ $output .= '
'.&mt('Delete').'
'.
+ '
'.&mt('Set to ...').'
';
+ if ($is_map) {
+ $output .= '
'.&mt('Recursive?').'
';
+ }
}
$output .= '';
return $output;
@@ -3605,6 +3629,8 @@ sub storedata {
my %newdata=();
undef %newdata;
my @deldata=();
+ my @delrec=();
+ my @delnonrec=();
undef @deldata;
my ($got_chostname,$chostname,$cmajor,$cminor);
my $now = time;
@@ -3612,11 +3638,27 @@ sub storedata {
if ($key =~ /^form\.([a-z]+)\_(.+)$/) {
my $cmd=$1;
my $thiskey=$2;
- next if ($cmd eq 'settext' || $cmd eq 'setipallow' || $cmd eq 'setipdeny');
+ my ($altkey,$recursive,$tkey,$tkeyrec,$tkeynonrec);
+ next if ($cmd eq 'rec' || $cmd eq 'settext' || $cmd eq 'setipallow' || $cmd eq 'setipdeny');
+ if ((($cmd eq 'set') || ($cmd eq 'datepointer') || ($cmd eq 'dateinterval') || ($cmd eq 'del')) &&
+ ($thiskey =~ /(?:sequence|page)\Q___(all)\E/)) {
+ unless ($thiskey =~ /(encrypturl|hiddenresource)$/) {
+ $altkey = $thiskey;
+ $altkey =~ s/\Q___(all)\E/___(rec)/;
+ if ($env{'form.rec_'.$thiskey}) {
+ $recursive = 1;
+ }
+ }
+ }
my ($tuname,$tudom)=&extractuser($thiskey);
- my $tkey=$thiskey;
if ($tuname) {
+ $tkey=$thiskey;
$tkey=~s/\.\[useropt\:$tuname\:$tudom\]\./\./;
+ if ($altkey) {
+ $tkeynonrec = $tkey;
+ $tkeyrec = $altkey;
+ $tkeyrec=~s/\.\[useropt\:$tuname\:$tudom\]\./\./;
+ }
}
if ($cmd eq 'set' || $cmd eq 'datepointer' || $cmd eq 'dateinterval') {
my ($data, $typeof, $text, $name, $valchk, $valmatch, $namematch);
@@ -3700,7 +3742,7 @@ sub storedata {
$typeof=$env{'form.typeof_'.$thiskey};
$text = &mt('Saved modified date for');
}
- if ($thiskey =~ m{\.(?:sequence|page)___\(rec\)}) {
+ if ($recursive) {
$namematch = 'maplevelrecurse';
}
if (($name ne '') || ($namematch ne '')) {
@@ -3747,54 +3789,195 @@ sub storedata {
next;
}
}
- if (defined($data) and $$olddata{$thiskey} ne $data) {
- if ($tuname) {
- if (&Apache::lonnet::put('resourcedata',{$tkey=>$data,
- $tkey.'.type' => $typeof},
- $tudom,$tuname) eq 'ok') {
- &log_parmset({$tkey=>$data,$tkey.'.type' => $typeof},0,$tuname,$tudom);
- $r->print(' '.$text.' '.
- &Apache::loncommon::plainname($tuname,$tudom));
+ my ($reconlychg,$haschange,$storekey);
+ if ($tuname) {
+ my $ustorekey;
+ if ($altkey) {
+ if ($recursive) {
+ if (exists($$olddata{$thiskey})) {
+ if ($$olddata{$thiskey} eq $data) {
+ $reconlychg = 1;
+ }
+ &Apache::lonnet::del('resourcedata',[$tkeynonrec,$tkeynonrec.'.type'],$tudom,$tuname);
+ }
+ if (exists($$olddata{$altkey})) {
+ if (defined($data) && $$olddata{$altkey} ne $data) {
+ $haschange = 1;
+ }
+ } elsif ((!$reconlychg) && ($data ne '')) {
+ $haschange = 1;
+ }
+ $ustorekey = $tkeyrec;
} else {
- $r->print('