--- loncom/interface/lonparmset.pm 2016/07/19 21:55:12 1.563
+++ loncom/interface/lonparmset.pm 2017/07/15 02:49:10 1.580
@@ -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.580 2017/07/15 02:49:10 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,8 +720,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 +739,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 +778,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 +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
@@ -846,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; }
@@ -875,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');
@@ -889,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 {
@@ -899,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 {
@@ -914,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);
}
@@ -1022,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)) {
@@ -1045,7 +1089,9 @@ sub plink {
return '
');
if ($parmlev eq 'full') {
my $sessionval=&Apache::lonnet::EXT('resource.'.$$part{$which}.
@@ -1532,44 +1576,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) {
+ } 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;
+ }
}
}
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
@@ -1578,8 +1650,8 @@ sub print_td {
# @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) = @_;
+sub check_other_groups {
+ my ($what,$rid,$cgroup,$defbg,$usersgroups,$result,$courseopt) = @_;
my $courseid = $env{'request.course.id'};
my $output;
my $symb = &symbcache($rid);
@@ -1595,7 +1667,6 @@ sub print_usergroups {
if (($coursereply) && ($cgroup ne $resultgroup)) {
if ($result > 3) {
$bgcolor = '#AAFFAA';
- $grp_parm = &valout($coursereply,$resulttype,$what);
}
$grp_parm = &valout($coursereply,$resulttype,$what);
$output = '
';
@@ -1612,7 +1683,7 @@ sub print_usergroups {
}
# 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
@@ -1651,16 +1722,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 +1999,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 +2093,7 @@ sub parmboxes {
$r->print('
'
.'
'.&mt($categories{$key}).'
'."\n");
foreach my $tempkey (&keysindisplayorderCategory($categoryList{$key},$keyorder)) {
+ next if ($tempkey eq '');
$r->print(''
.'
'.&Apache::loncommon::end_data_table_row());
+ $r->print('');
+ if ($is_map) {
+ if (($name eq 'encrypturl') || ($name eq 'hiddenresource')) {
+ $r->print('