--- loncom/interface/lonparmset.pm 2016/07/15 22:24:37 1.562 +++ loncom/interface/lonparmset.pm 2017/07/04 21:20:14 1.573 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Handler to set parameters for assessments # -# $Id: lonparmset.pm,v 1.562 2016/07/15 22:24:37 damieng Exp $ +# $Id: lonparmset.pm,v 1.573 2017/07/04 21:20:14 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -367,14 +367,14 @@ sub endSettingsScreen { ################################################## -# TABLE MODE +# (mostly) TABLE MODE # (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,26 +1534,35 @@ 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) { $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) { @@ -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 { @@ -2261,10 +2272,10 @@ sub displaymenu { # Used by table mode and overview mode. # # @param {Apache2::RequestRec} $r - the Apache request -# @param {hash reference} $allmaps - hash map id -> map src -# @param {string} $pschp - selected map id, or 'all' +# @param {hash reference} $allmaps - hash map pc -> map src +# @param {string} $pschp - selected map pc, or 'all' # @param {hash reference} $maptitles - hash map id or src -> map title -# @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} $symbp - hash map pc or resource/map id -> map src.'___(all)' or resource symb sub mapmenu { my ($r,$allmaps,$pschp,$maptitles,$symbp)=@_; my %allmaps_inverted = reverse %$allmaps; @@ -2416,8 +2427,12 @@ sub mapmenu { } } -# Build up the select Box to choose if your parameter specification should work for the resource, map/folder or the course level -# The value of default selection in the select box is set by the value that is given by the argument in $parmlev. +# Prints HTML to select the parameter level (resource, map/folder or course). +# Used by table and overview modes. +# +# @param {Apache2::RequestRec} $r - the Apache request +# @param {hash reference} $alllevs - all parameter levels, hash English title -> value +# @param {string} $parmlev - selected level value (full|map|general), or '' sub levelmenu { my ($r,$alllevs,$parmlev)=@_; @@ -2435,6 +2450,11 @@ sub levelmenu { } +# Returns HTML to select a section (with a select HTML element). +# Used by overview mode. +# +# @param {array reference} $selectedsections - list of selected section ids +# @returns {string} sub sectionmenu { my ($selectedsections)=@_; my %sectionhash = &Apache::loncommon::get_sections(); @@ -2460,6 +2480,11 @@ sub sectionmenu { return $output; } +# Returns HTML to select a group (with a select HTML element). +# Used by overview mode. +# +# @param {array reference} $selectedgroups - list of selected group names +# @returns {string} sub groupmenu { my ($selectedgroups)=@_; my %grouphash; @@ -2482,11 +2507,23 @@ sub groupmenu { return $output; } +# Returns an array with the given parameter split by comma. +# Used by assessparms (table mode). +# +# @param {string} $keyp - the string to split +# @returns {Array} sub keysplit { my $keyp=shift; return (split(/\,/,$keyp)); } +# Returns the keys in $name, sorted using $keyorder. +# Parameters are sorted by key, which means they are sorted by part first, then by name. +# Used by assessparms (table mode) for resource level. +# +# @param {hash reference} $name - parameter key -> parameter name +# @param {hash reference} $keyorder - hash parameter key -> appearance rank +# @returns {Array} sub keysinorder { my ($name,$keyorder)=@_; return sort { @@ -2494,10 +2531,16 @@ sub keysinorder { } (keys(%{$name})); } +# Returns the keys in $name, sorted using $keyorder to sort parameters by name first, then by part. +# Used by assessparms (table mode) for map and general levels. +# +# @param {hash reference} $name - parameter key -> parameter name +# @param {hash reference} $keyorder - hash parameter key -> appearance rank +# @returns {Array} sub keysinorder_bytype { my ($name,$keyorder)=@_; return sort { - my $ta=(split('_',$a))[-1]; + my $ta=(split('_',$a))[-1]; # parameter name my $tb=(split('_',$b))[-1]; if ($$keyorder{'parameter_0_'.$ta} == $$keyorder{'parameter_0_'.$tb}) { return ($a cmp $b); @@ -2506,6 +2549,12 @@ sub keysinorder_bytype { } (keys(%{$name})); } +# Returns the keys in $name, sorted using $keyorder to sort parameters by name. +# Used by defaultsetter (parameter settings default actions). +# +# @param {hash reference} $name - hash parameter name -> parameter title +# @param {hash reference} $keyorder - hash parameter key -> appearance rank +# @returns {Array} sub keysindisplayorder { my ($name,$keyorder)=@_; return sort { @@ -2513,6 +2562,11 @@ sub keysindisplayorder { } (keys(%{$name})); } +# Prints HTML with a choice to sort results by realm or student first. +# Used by overview mode. +# +# @param {Apache2::RequestRec} $r - the Apache request +# @param {string} $sortorder - realmstudent|studentrealm sub sortmenu { my ($r,$sortorder)=@_; $r->print('