--- loncom/interface/lonparmset.pm 2016/08/08 18:19:16 1.565
+++ loncom/interface/lonparmset.pm 2018/09/03 16:43:47 1.585
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Handler to set parameters for assessments
#
-# $Id: lonparmset.pm,v 1.565 2016/08/08 18:19:16 damieng Exp $
+# $Id: lonparmset.pm,v 1.585 2018/09/03 16:43:47 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -36,7 +36,8 @@ lonparmset - Handler to set parameters f
=head1 SYNOPSIS
-lonparmset provides an interface to setting course parameters.
+lonparmset provides an interface to setting content parameters in a
+course.
It contains all the code for the "Content and Problem Settings" UI, except
for the helpers parameter.helper and resettimes.helper, and lonhelper.pm,
@@ -137,7 +138,7 @@ javascript function 'pjump'.
=item print_td()
-=item print_usergroups()
+=item check_other_groups()
=item parm_control_group()
@@ -371,10 +372,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 +395,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 +598,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 +608,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,7 +720,7 @@ 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} $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
@@ -737,7 +739,7 @@ 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} $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
@@ -807,7 +809,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
@@ -845,17 +847,36 @@ sub storeparm_by_symb_inner {
my $courselevelm=$env{'request.course.id'}.'.'.$mapparm;
my $storeunder='';
+ my $possreplace='';
if (($snum==18) || ($snum==4)) { $storeunder=$courselevel; }
- if (($snum==17) || ($snum==3)) { $storeunder=$courseleveli; }
- if (($snum==16) || ($snum==2)) { $storeunder=$courselevelm; }
+ if (($snum==17) || ($snum==3)) {
+ $storeunder=$courseleveli;
+ $possreplace=$courselevelm;
+ }
+ if (($snum==16) || ($snum==2)) {
+ $storeunder=$courselevelm;
+ $possreplace=$courseleveli;
+ }
if (($snum==13) || ($snum==1)) { $storeunder=$courselevelr; }
if ($snum==12) { $storeunder=$seclevel; }
- if ($snum==11) { $storeunder=$secleveli; }
- if ($snum==10) { $storeunder=$seclevelm; }
+ if ($snum==11) {
+ $storeunder=$secleveli;
+ $possreplace=$seclevelm;
+ }
+ if ($snum==10) {
+ $storeunder=$seclevelm;
+ $possreplace=$secleveli;
+ }
if ($snum==9) { $storeunder=$seclevelr; }
if ($snum==8) { $storeunder=$grplevel; }
- if ($snum==7) { $storeunder=$grpleveli; }
- if ($snum==6) { $storeunder=$grplevelm; }
+ if ($snum==7) {
+ $storeunder=$grpleveli;
+ $possreplace=$grplevelm;
+ }
+ if ($snum==6) {
+ $storeunder=$grplevelm;
+ $possreplace=$grpleveli;
+ }
if ($snum==5) { $storeunder=$grplevelr; }
@@ -874,7 +895,7 @@ sub storeparm_by_symb_inner {
&Apache::lonnet::expirespread('','','studentcalc');
if (($snum==13) || ($snum==9) || ($snum==5)) {
&Apache::lonnet::expirespread('','','assesscalc',$symb);
- } elsif (($snum==14) || ($snum==10) || ($snum==6)) {
+ } elsif (($snum==17) || ($snum==16) || ($snum==11) || ($snum==10) || ($snum==7) || ($snum==6)) {
&Apache::lonnet::expirespread('','','assesscalc',$map);
} else {
&Apache::lonnet::expirespread('','','assesscalc');
@@ -888,6 +909,17 @@ sub storeparm_by_symb_inner {
$reply=&Apache::lonnet::cput
('resourcedata',\%storecontent,$cdom,$cnum);
&log_parmset(\%storecontent);
+ if ($possreplace) {
+ my $resdata = &Apache::lonnet::get_courseresdata($cnum,$cdom);
+ if (ref($resdata) eq 'HASH') {
+ if (exists($resdata->{$possreplace})) {
+ if (&Apache::lonnet::del
+ ('resourcedata',[$possreplace,$possreplace.'.type'],$cdom,$cnum) eq 'ok') {
+ &log_parmset({$possreplace => '', $possreplace.'.type' => $ntype},1);
+ }
+ }
+ }
+ }
}
&Apache::lonnet::devalidatecourseresdata($cnum,$cdom);
} else {
@@ -898,7 +930,7 @@ sub storeparm_by_symb_inner {
if ($snum==1) {
&Apache::lonnet::expirespread
($uname,$udom,'assesscalc',$symb);
- } elsif ($snum==2) {
+ } elsif (($snum==2) || ($snum==3)) {
&Apache::lonnet::expirespread
($uname,$udom,'assesscalc',$map);
} else {
@@ -913,6 +945,18 @@ sub storeparm_by_symb_inner {
$reply=&Apache::lonnet::cput
('resourcedata',\%storecontent,$udom,$uname);
&log_parmset(\%storecontent,0,$uname,$udom);
+ if ($possreplace) {
+ my $resdata = &Apache::lonnet::get_userresdata($uname,$udom);
+ if (ref($resdata) eq 'HASH') {
+ if (exists($resdata->{$possreplace})) {
+ if (&Apache::lonnet::del
+ ('resourcedata',[$possreplace,$possreplace.'.type'],$udom,$uname) eq 'ok') {
+ &log_parmset({$possreplace => '',$possreplace.'.type' => $ntype},1,
+ $uname,$udom);
+ }
+ }
+ }
+ }
}
&Apache::lonnet::devalidateuserresdata($uname,$udom);
}
@@ -1021,8 +1065,9 @@ sub valout {
# @param {string} $marker - identifier for the parameter, "resource id&part_parameter name&level", will be passed as pres_marker when the user submits a change.
# @param {string} $return - prefix for the name of the form and field names that will be used to submit the form ('parmform.pres')
# @param {string} $call - javascript function to call to submit the form ('psub')
+# @param {boolean} $recursive - true if link is for a map/folder where parameter is currently set to be recursive.
sub plink {
- my ($type,$dis,$value,$marker,$return,$call)=@_;
+ my ($type,$dis,$value,$marker,$return,$call,$recursive)=@_;
my $winvalue=$value;
unless ($winvalue) {
if (&isdateparm($type)) {
@@ -1044,7 +1089,9 @@ sub plink {
return '
');
+ }
if ($parmlev eq 'full') {
my $sessionval=&Apache::lonnet::EXT('resource.'.$$part{$which}.
'.'.$$name{$which},$$symbp{$rid});
@@ -1513,6 +1644,9 @@ sub print_row {
}
$r->print('');
$r->print("\n");
+ if (($numlinks) && (ref($reclinks))) {
+ $$reclinks = $numlinks;
+ }
}
# Prints a cell for table mode.
@@ -1531,44 +1665,72 @@ 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.
+# @param {boolean} $ismaplevel - true if level is for a map.
sub print_td {
- my ($r,$which,$defbg,$result,$outpar,$mprefix,$value,$typeoutpar,$display,$noeditgrp)=@_;
- $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) {
- $nolink = 1;
- }
- } elsif ($mprefix =~ /availablestudent\&$/) {
- if ($which > 4) {
+ } else {
+ if ($which == 14 || $which == 15 || $mprefix =~ /mapalias\&$/) {
$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;
+ }
}
}
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($currval,$currtype,$parmname));
} else {
- $r->print(&plink($$typeoutpar[$which],
- $$display{$value},$$outpar[$which],
- $mprefix."$which",'parmform.pres','psub'));
+ $r->print(&plink($currtype,
+ $$display{$value},$currval,
+ $mprefix.$currlevel,'parmform.pres','psub',$recursive));
}
$r->print('
'."\n");
}
-# FIXME: Despite the name, this does not print anything, the $r parameter is unused.
# Returns HTML and other info for the cell added when a user is selected
# and that user is in several groups. This is the cell with the title "Control by other group".
#
-# @param {Apache2::RequestRec} $r - the Apache request (unused)
# @param {string} $what - parameter part.'.'.parameter name
# @param {string} $rid - resource id
# @param {string} $cgroup - group name
@@ -1576,9 +1738,9 @@ sub print_td {
# @param {array reference} $usersgroups - list of groups the user belongs to, if any
# @param {integer} $result - level
# @param {hash reference} $courseopt - course parameters hash (result of lonnet::get_courseresdata, dump of course's resourcedata.db)
-# @returns {Array} - array (parameter value for the other group, HTML for the cell, HTML with the value, name of the other group)
-sub print_usergroups {
- my ($r,$what,$rid,$cgroup,$defbg,$usersgroups,$result,$courseopt) = @_;
+# @returns {Array} - array (parameter value for the other group, HTML for the cell, HTML with the value, name of the other group, true if recursive)
+sub check_other_groups {
+ my ($what,$rid,$cgroup,$defbg,$usersgroups,$result,$courseopt) = @_;
my $courseid = $env{'request.course.id'};
my $output;
my $symb = &symbcache($rid);
@@ -1590,16 +1752,22 @@ sub print_usergroups {
&parm_control_group($courseid,$usersgroups,$symbparm,$mapparm,
$recurseparm,$what,$courseopt);
my $bgcolor = $defbg;
- my $grp_parm;
+ my ($grp_parm,$grp_is_rec);
if (($coursereply) && ($cgroup ne $resultgroup)) {
+ my ($parmname) = ($what =~ /\.([^.]+)$/);
if ($result > 3) {
$bgcolor = '#AAFFAA';
- $grp_parm = &valout($coursereply,$resulttype,$what);
}
- $grp_parm = &valout($coursereply,$resulttype,$what);
+ $grp_parm = &valout($coursereply,$resulttype,$parmname);
$output = '
';
}
- return ($coursereply,$output,$grp_parm,$resultgroup);
+ return ($coursereply,$output,$grp_parm,$resultgroup,$grp_is_rec);
}
# Looks for a group with a defined parameter for given user and parameter.
-# Used by print_usergroups.
+# Used by check_other_groups.
#
# @param {string} $courseid - the course id
# @param {array reference} $usersgroups - list of groups the user belongs to, if any
@@ -1650,16 +1818,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 {
@@ -1688,23 +1856,27 @@ sub extractResourceInformation {
my $srcf=$resource->src();
$srcf=~/\.(\w+)$/;
$$typep{$id}=$1;
+ my $toolsymb;
+ if ($srcf =~ /ext\.tool$/) {
+ $toolsymb = $resource->symb();
+ }
$$keyp{$id}='';
$$uris{$id}=$srcf;
- foreach my $key (split(/\,/,&Apache::lonnet::metadata($srcf,'allpossiblekeys'))) {
+ foreach my $key (split(/\,/,&Apache::lonnet::metadata($srcf,'allpossiblekeys',$toolsymb))) {
next if ($key!~/^parameter_/);
# Hidden parameters
- next if (&Apache::lonnet::metadata($srcf,$key.'.hidden') eq 'parm');
+ next if (&Apache::lonnet::metadata($srcf,$key.'.hidden',$toolsymb) eq 'parm');
#
# allparms is a hash of parameter names
#
- my $name=&Apache::lonnet::metadata($srcf,$key.'.name');
+ my $name=&Apache::lonnet::metadata($srcf,$key.'.name',$toolsymb);
if (!exists($$allparms{$name}) || $$allparms{$name} =~ m/^\s*$/ ) {
my ($display,$parmdis);
$display = &standard_parameter_names($name);
if ($display eq '') {
- $display= &Apache::lonnet::metadata($srcf,$key.'.display');
+ $display= &Apache::lonnet::metadata($srcf,$key.'.display',$toolsymb);
$parmdis = $display;
$parmdis =~ s/\s*\[Part.*$//g;
} else {
@@ -1713,14 +1885,14 @@ sub extractResourceInformation {
$$allparms{$name}=$parmdis;
if (ref($defkeytype)) {
$$defkeytype{$name}=
- &Apache::lonnet::metadata($srcf,$key.'.type');
+ &Apache::lonnet::metadata($srcf,$key.'.type',$toolsymb);
}
}
#
# allparts is a hash of all parts
#
- my $part= &Apache::lonnet::metadata($srcf,$key.'.part');
+ my $part= &Apache::lonnet::metadata($srcf,$key.'.part',$toolsymb);
$$allparts{$part} = &mt('Part: [_1]',$part);
#
# Remember all keys going with this resource
@@ -1761,6 +1933,29 @@ sub extractResourceInformation {
}
}
+sub get_recursive {
+ my ($recurseup,$resdata,$what,$prefix) = @_;
+ if ((ref($resdata) eq 'HASH') && (ref($recurseup) eq 'ARRAY')) {
+ foreach my $item (@{$recurseup}) {
+ my $norecursechk=$prefix.'.'.$item.'___(all).'.$what;
+ if (defined($resdata->{$norecursechk})) {
+ if ($what =~ /\.(encrypturl|hiddenresource)$/) {
+ my $type = $resdata->{$norecursechk.'.type'};
+ return [$resdata->{$norecursechk},$type,$item];
+ } else {
+ last;
+ }
+ }
+ my $recursechk=$prefix.'.'.$item.'___(rec).'.$what;
+ if (defined($resdata->{$recursechk})) {
+ my $type = $resdata->{$recursechk.'.type'};
+ return [$resdata->{$recursechk},$type,$item];
+ }
+ }
+ }
+ return;
+}
+
# Tells if a parameter type is a date.
#
@@ -1772,15 +1967,10 @@ sub isdateparm {
}
# Prints the HTML and Javascript to select parameters, with various shortcuts.
-# FIXME: remove unused parameters
#
-# @param {Apache2::RequestRec} $r - the Apache request (unused)
-# @param {hash reference} $allparms - hash parameter name -> parameter title
-# @param {array reference} $pscat - list of selected parameter names (unused)
-# @param {hash reference} $keyorder - hash parameter key -> appearance rank (unused)
+# @param {Apache2::RequestRec} $r - the Apache request
sub parmmenu {
- my ($r,$allparms,$pscat,$keyorder)=@_;
- my $tempkey;
+ my ($r)=@_;
$r->print(<
// print('');
- &shortCuts($r,$allparms,$pscat,$keyorder);
+ &shortCuts($r);
$r->print('');
}
@@ -1926,8 +2116,8 @@ sub lookUpTableParameter {
'lenient' => 'grading',
'retrypartial' => 'tries',
'discussvote' => 'misc',
- 'examcode' => 'high_level_randomization',
- );
+ 'examcode' => 'high_level_randomization',
+ );
}
# Adds the given parameter name to an array of arrays listing all parameters for each category.
@@ -2021,6 +2211,7 @@ sub parmboxes {
$r->print('
'
.'
'.&mt($categories{$key}).'
'."\n");
foreach my $tempkey (&keysindisplayorderCategory($categoryList{$key},$keyorder)) {
+ next if ($tempkey eq '');
$r->print(''
.'