--- loncom/interface/lonparmset.pm 2016/10/16 21:49:51 1.568 +++ loncom/interface/lonparmset.pm 2019/02/18 13:25:49 1.589 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Handler to set parameters for assessments # -# $Id: lonparmset.pm,v 1.568 2016/10/16 21:49:51 raeburn Exp $ +# $Id: lonparmset.pm,v 1.589 2019/02/18 13:25:49 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() @@ -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,11 +1065,13 @@ 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. +# @param {string} $extra - optional additional information to send as tenth arg in call to javascript pjump function. sub plink { - my ($type,$dis,$value,$marker,$return,$call)=@_; + my ($type,$dis,$value,$marker,$return,$call,$recursive,$extra)=@_; my $winvalue=$value; unless ($winvalue) { - if (&isdateparm($type)) { + if ((&isdateparm($type) || (&is_specialstring($type))) { $winvalue=$env{'form.recent_'.$type}; } else { $winvalue=$env{'form.recent_'.(split(/\_/,$type))[0]}; @@ -1038,14 +1083,16 @@ sub plink { my $valout = &valout($value,$type,$parmname,1); my $unencmarker = $marker; foreach my $item (\$type, \$dis, \$winvalue, \$marker, \$return, \$call, - \$hour, \$min, \$sec) { + \$hour, \$min, \$sec, \$extra) { $$item = &HTML::Entities::encode($$item,'"<>&'); $$item =~ s/\'/\\\'/g; } return '
'. ''. - $valout.'
'; + .$marker."','".$return."','".$call."','".$hour."','".$min."','".$sec."','".$extra."'".');">'. + $valout.''.($recursive?''. + &mt('recursive').'' : '').''; + } # Javascript for table mode. @@ -1061,12 +1108,14 @@ sub page_js { $pjump_def function psub() { + var specstring = /^string_/i; if (document.parmform.pres_marker.value!='') { document.parmform.action+='#'+document.parmform.pres_marker.value; var typedef=new Array(); typedef=document.parmform.pres_type.value.split('_'); if (document.parmform.pres_type.value!='') { - if (typedef[0]=='date') { + if ((typedef[0]=='date') || + (specstring.test(document.parmform.pres_type.value) && (typedef[1]!='yesno'))) { eval('document.parmform.recent_'+ document.parmform.pres_type.value+ '.value=document.parmform.pres_value.value;'); @@ -1191,12 +1240,16 @@ function validateParms() { var patternLenientStd = /^(yes|no|default)$/; var ipallowRegExp = /^setipallow_/; var ipdenyRegExp = /^setipdeny_/; + var deeplinkRegExp = /^deeplink_(listing|scope)_/; + var deeplinkUrlsRegExp = /^deeplink_urls_/; + var deeplinkltiRegExp = /^deeplink_lti_/; + var deeplinkkeyRegExp = /^deeplink_key_/; var patternIP = /[\[\]\*\.a-zA-Z\d\-]+/; if ((document.parmform.elements.length != 'undefined') && (document.parmform.elements.length) != 'null') { if (document.parmform.elements.length) { for (i=0; i map title +# @param {hash reference} - $allmaps_inverted - hash map src -> map pc +# @param {scalar reference} - $reclinks - number of "parameter in effect" cells with link to map where recursive param was set sub print_row { my ($r,$which,$part,$name,$symbp,$rid,$default,$defaulttype,$display,$defbgone, $defbgtwo,$defbgthree,$parmlev,$uname,$udom,$csec,$cgroup,$usersgroups,$noeditgrp, - $readonly)=@_; + $readonly,$recurseup,$maptitles,$allmaps_inverted,$reclinks)=@_; 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); + my $numlinks = 0; # get the values for the parameter in cascading order # empty levels will remain empty @@ -1424,85 +1551,182 @@ sub print_row { my $thismarker=$which; $thismarker=~s/^parameter\_//; my $mprefix=$rid.'&'.$thismarker.'&'; - my $effective_parm = &valout($outpar[$result],$typeoutpar[$result],$thismarker); - my ($othergrp,$grp_parm,$controlgrp); - + my ($parmname)=($thismarker=~/\_([^\_]+)$/); + my ($othergrp,$grp_parm,$controlgrp,$effective_parm,$effparm_rec,$effparm_level, + $eff_groupparm,$recurse_check,$recursinfo,$extra); + if ((ref($recurseup) eq 'ARRAY') && (@{$recurseup} > 0)) { + if ($result eq '') { + $recurse_check = 1; + } elsif (($uname ne '') && ($result > 3)) { + $recurse_check = 1; + } elsif (($cgroup ne '') && ($result > 7)) { + $recurse_check = 1; + } elsif (($csec ne '') && ($result > 11)) { + $recurse_check = 1; + } elsif ($result > 17) { + $recurse_check = 1; + } + if ($recurse_check) { + my $what = $$part{$which}.'.'.$$name{$which}; + my $prefix; + if (($uname ne '') && ($udom ne '')) { + my $useropt = &Apache::lonnet::get_userresdata($uname,$udom); + $prefix = $env{'request.course.id'}; + $recursinfo = &get_recursive($recurseup,$useropt,$what,$prefix); + if (ref($recursinfo) eq 'ARRAY') { + $effparm_rec = 1; + $effparm_level = &mt('user: [_1]',$uname); + } + } + if (($cgroup ne '') && (!$effparm_rec)) { + $prefix = $env{'request.course.id'}.'.['.$cgroup.']'; + $recursinfo = &get_recursive($recurseup,$courseopt,$what,$prefix); + if (ref($recursinfo) eq 'ARRAY') { + $effparm_rec = 1; + $effparm_level = &mt('group: [_1]',$cgroup); + } + } + if (($csec ne '') && (!$effparm_rec)) { + $prefix = $env{'request.course.id'}.'.['.$csec.']'; + $recursinfo = &get_recursive($recurseup,$courseopt,$what,$prefix); + if (ref($recursinfo) eq 'ARRAY') { + $effparm_rec = 1; + $effparm_level = &mt('section: [_1]',$csec); + } + } + if (!$effparm_rec) { + $prefix = $env{'request.course.id'}; + $recursinfo = &get_recursive($recurseup,$courseopt,$what,$prefix); + if (ref($recursinfo) eq 'ARRAY') { + $effparm_rec = 1; + } + } + } + } + if ((!$effparm_rec) && ($result == 17 || $result == 11 || $result == 7 || $result == 3)) { + $effparm_rec = 1; + } + if ((!$effparm_rec) && + (($$name{$which} eq 'encrypturl') || ($$name{$which} eq 'hiddenresource')) && + ($result == 16 || $result == 10 || $result == 6 || $result == 2)) { + $effparm_rec = 1; + } + if ($parmname eq 'deeplink') { + my %posslti; + my %lti = + &Apache::lonnet::get_domain_lti($env{'course.'.$env{'request.course.id'}.'.domain'}, + 'provider'); + foreach my $item (keys(%lti)) { + if (ref($lti{$item}) eq 'HASH') { + unless ($lti{$item}{'requser'}) { + $posslti{$item} = $lti{$item}{'consumer'}; + } + } + } + if (keys(%posslti)) { + $extra = 'lti_'; + foreach my $lti (sort { $a <=> $b } keys(%posslti)) { + $extra .= $lti.':'.&js_escape($posslti{$lti}).','; + } + $extra =~ s/,$//; + } + } if ($parmlev eq 'general') { if ($uname) { - &print_td($r,4,$defbgone,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly); + &print_td($r,4,$defbgone,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly,'',$extra); } elsif ($cgroup) { - &print_td($r,8,$defbgthree,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,$noeditgrp,$readonly); + &print_td($r,8,$defbgthree,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,$noeditgrp,$readonly,'',$extra); } elsif ($csec) { - &print_td($r,12,$defbgtwo,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly); + &print_td($r,12,$defbgtwo,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly,'',$extra); } else { - &print_td($r,18,$defbgone,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly); + &print_td($r,18,$defbgone,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly,'',$extra); } } elsif ($parmlev eq 'map') { if ($uname) { - &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,2,$defbgone,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly,1,$extra); } elsif ($cgroup) { - &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,6,$defbgthree,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,$noeditgrp,$readonly,1,$extra); } elsif ($csec) { - &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,10,$defbgtwo,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly,1,$extra); } else { - &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,16,$defbgone,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly,1,$extra); } } else { if ($uname) { if (@{$usersgroups} > 1) { - my ($coursereply,$grp_parm,$controlgrp); - ($coursereply,$othergrp,$grp_parm,$controlgrp) = - &print_usergroups($r,$$part{$which}.'.'.$$name{$which}, + (my $coursereply,$othergrp,$grp_parm,$controlgrp,my $grp_is_rec) = + &check_other_groups($$part{$which}.'.'.$$name{$which}, $rid,$cgroup,$defbgone,$usersgroups,$result,$courseopt); - if ($coursereply && $result > 4) { + if (($coursereply) && ($result > 4)) { if (defined($controlgrp)) { if ($cgroup ne $controlgrp) { - $effective_parm = $grp_parm; - $result = 0; + $eff_groupparm = $grp_parm; + undef($result); + undef($effparm_rec); + if ($grp_is_rec) { + $effparm_rec = 1; + } } } } } } - &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); + &print_td($r,18,$defbgone,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly,'',$extra); + &print_td($r,16,$defbgone,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly,1,$extra); + &print_td($r,15,'#FFDDDD',$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly,'',$extra); + &print_td($r,14,'#FFDDDD',$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly,'',$extra); + &print_td($r,13,$defbgone,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly,'',$extra); if ($csec) { - &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); + &print_td($r,12,$defbgtwo,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly,'',$extra); + &print_td($r,10,$defbgtwo,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly,1,$extra); + &print_td($r,9,$defbgtwo,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly,'',$extra); } if ($cgroup) { - &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); + &print_td($r,8,$defbgthree,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,$noeditgrp,$readonly,'',$extra); + &print_td($r,6,$defbgthree,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,$noeditgrp,$readonly,1,$extra); + &print_td($r,5,$defbgthree,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,$noeditgrp.$readonly,'',$extra); } if ($uname) { if ($othergrp) { $r->print($othergrp); } - &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); + &print_td($r,4,$defbgone,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly,'',$extra); + &print_td($r,2,$defbgone,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly,1,$extra); + &print_td($r,1,$defbgone,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly,'',$extra); } - } # end of $parmlev if/else - $r->print(''.$effective_parm.''); - + if (ref($recursinfo) eq 'ARRAY') { + my $rectitle = &mt('recursive'); + if ((ref($maptitles) eq 'HASH') && (exists($maptitles->{$recursinfo->[2]}))) { + if ((ref($allmaps_inverted) eq 'HASH') && (exists($allmaps_inverted->{$recursinfo->[2]}))) { + $rectitle = &mt('set in: [_1]','"'. + '{$recursinfo->[2]}."',". + "'$parmname','$$part{$which}'".');">'. + $maptitles->{$recursinfo->[2]}.'"'); + + $numlinks ++; + } + } + my ($parmname)=($thismarker=~/\_([^\_]+)$/); + $effective_parm = &valout($recursinfo->[0],$recursinfo->[1],$parmname); + $r->print(''.$effective_parm. + '
'.$rectitle.' '. + $effparm_level.''); + } else { + if ($result) { + $effective_parm = &valout($outpar[$result],$typeoutpar[$result],$parmname); + } + if ($eff_groupparm) { + $effective_parm = $eff_groupparm; + } + $r->print(''.$effective_parm. + ($effparm_rec?'
'.&mt('recursive'). + '':'').''); + } if ($parmlev eq 'full') { my $sessionval=&Apache::lonnet::EXT('resource.'.$$part{$which}. '.'.$$name{$which},$$symbp{$rid}); @@ -1516,6 +1740,9 @@ sub print_row { } $r->print(''); $r->print("\n"); + if (($numlinks) && (ref($reclinks))) { + $$reclinks = $numlinks; + } } # Prints a cell for table mode. @@ -1535,15 +1762,41 @@ sub print_row { # @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. +# @param {strring} $extra - extra informatio to pass to plink. sub print_td { - my ($r,$which,$defbg,$result,$outpar,$mprefix,$value,$typeoutpar,$display,$noeditgrp,$readonly)=@_; - $r->print(''); my $nolink = 0; if ($readonly) { $nolink = 1; } else { - if ($which == 14 || $which == 15) { + if ($which == 14 || $which == 15 || $mprefix =~ /mapalias\&$/) { $nolink = 1; } elsif (($env{'request.course.sec'} ne '') && ($which > 12)) { $nolink = 1; @@ -1562,21 +1815,20 @@ sub print_td { } } 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, + $extra)); } $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 @@ -1584,9 +1836,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); @@ -1598,16 +1850,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 = ''; if ($resultgroup && $resultlevel) { - $output .= ''.$resultgroup.' ('.$resultlevel.'): '.$grp_parm; + if ($resultlevel eq 'recursive') { + $resultlevel = 'map/folder'; + $grp_is_rec = 1; + } + $output .= ''.$resultgroup.' ('.$resultlevel.'): '.$grp_parm. + ($grp_is_rec?''.&mt('recursive').'':''); + } else { $output .= ' '; } @@ -1615,11 +1873,11 @@ sub print_usergroups { } else { $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 @@ -1696,23 +1954,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 { @@ -1721,14 +1983,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 @@ -1769,6 +2031,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. # @@ -1779,16 +2064,19 @@ sub isdateparm { return (($type=~/^date/) && (!($type eq 'date_interval'))); } +# Determine if parameter type is specialized string type (i.e., +# not just string or string_yesno. + +sub is_specialstring { + my $type=shift; + return (($type=~/^string_/) && ((!$type ne 'string_yesno'))); +} + # 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('
'); } @@ -1919,6 +2207,7 @@ sub lookUpTableParameter { 'buttonshide' => 'hiding', 'turnoffeditor' => 'hiding', 'encrypturl' => 'hiding', + 'deeplink' => 'hiding', 'randomorder' => 'high_level_randomization', 'randompick' => 'high_level_randomization', 'available' => 'slots', @@ -1934,8 +2223,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. @@ -2029,6 +2318,7 @@ sub parmboxes { $r->print('
' .'

'.&mt($categories{$key}).'

'."\n"); foreach my $tempkey (&keysindisplayorderCategory($categoryList{$key},$keyorder)) { + next if ($tempkey eq ''); $r->print('' .'
' @@ -3443,6 +3760,10 @@ ENDTABLEHEADFOUR my $rid = $id; my $uri=&Apache::lonnet::declutter($uris{$rid}); + my $toolsymb; + if ($uri =~ /ext\.tool$/) { + $toolsymb = $symbp{$rid}; + } #-------------------------------------------------------------------- # @catmarker contains list of all possible parameters including part #s @@ -3456,8 +3777,8 @@ ENDTABLEHEADFOUR $tempkeyp =~ s/_\w+_/_0_/; if ((grep $_ eq $fullkeyp, @catmarker) &&(!$name{$tempkeyp})) { $part{$tempkeyp}="0"; - $name{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.name'); - my $parmdis=&Apache::lonnet::metadata($uri,$fullkeyp.'.display'); + $name{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.name',$toolsymb); + my $parmdis=&Apache::lonnet::metadata($uri,$fullkeyp.'.display',$toolsymb); if ($allparms{$name{$tempkeyp}} ne '') { my $identifier; if ($parmdis =~ /(\s*\[Part.*)$/) { @@ -3470,8 +3791,8 @@ ENDTABLEHEADFOUR unless ($display{$tempkeyp}) { $display{$tempkeyp}=''; } $display{$tempkeyp}.=' ('.$name{$tempkeyp}.')'; $display{$tempkeyp} =~ s/_\w+_/_0_/; - $default{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp); - $type{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.type'); + $default{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp,$toolsymb); + $type{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.type',$toolsymb); } } # end loop through keys } # end loop through ids @@ -3516,6 +3837,25 @@ ENDMAPONE } # end of $parmlev eq general } $r->print(''); + if ($numreclinks) { + $r->print(<<"END"); +
+ + + + +
+ +END + } &endSettingsScreen($r); $r->print(&Apache::loncommon::end_page()); } # end sub assessparms @@ -3532,7 +3872,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 { @@ -3541,7 +3881,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; @@ -3597,7 +3941,7 @@ sub readdata { # Stores parameter data, using form parameters directly. # # Uses the following form parameters. The variable part in the names is a resourcedata key (except for a modification for user data). -# set_* (except settext, setipallow, setipdeny) - set a parameter value +# set_* (except settext, setipallow, setipdeny, setdeeplink) - set a parameter value # del_* - remove a parameter # datepointer_* - set a date parameter (value is key_* refering to a set of other form parameters) # dateinterval_* - set a date interval parameter (value refers to more form parameters) @@ -3620,6 +3964,8 @@ sub storedata { my %newdata=(); undef %newdata; my @deldata=(); + my @delrec=(); + my @delnonrec=(); undef @deldata; my ($got_chostname,$chostname,$cmajor,$cminor); my $now = time; @@ -3627,11 +3973,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' || $cmd eq 'setdeeplink'); + 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); @@ -3643,8 +4005,8 @@ sub storedata { $text = &mt('Saved modified parameter for'); if ($typeof eq 'string_questiontype') { $name = 'type'; - } elsif ($typeof eq 'string_lenient') { - $name = 'lenient'; + } elsif (($typeof eq 'string_lenient') || ($typeof eq 'string_deeplink')) { + ($name) = ($typeof =~ /^string_(lenient|deeplink)$/); my $stringmatch = &standard_string_matches($typeof); if (ref($stringmatch) eq 'ARRAY') { foreach my $item (@{$stringmatch}) { @@ -3715,7 +4077,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 '')) { @@ -3762,54 +4124,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('
'. - &mt('Error saving parameters').'
'); + if (exists($$olddata{$altkey})) { + if ($$olddata{$altkey} eq $data) { + $reconlychg = 1; + } + &Apache::lonnet::del('resourcedata',[$tkeyrec,$tkeyrec.'.type'],$tudom,$tuname); + } + if (exists($$olddata{$thiskey})) { + if (defined($data) && $$olddata{$thiskey} ne $data) { + $haschange = 1; + } + } elsif ((!$reconlychg) && ($data ne '')) { + $haschange = 1; + } + $ustorekey = $tkeynonrec; + } + } else { + if (exists($$olddata{$tkey})) { + if (defined($data) && $$olddata{$tkey} ne $data) { + $haschange = 1; + } + $ustorekey = $tkey; + } + } + if ($haschange || $reconlychg) { + unless ($env{'form.del_'.$thiskey}) { + if (&Apache::lonnet::put('resourcedata',{$ustorekey=>$data, + $ustorekey.'.type' => $typeof}, + $tudom,$tuname) eq 'ok') { + &log_parmset({$ustorekey=>$data,$ustorekey.'.type' => $typeof},0,$tuname,$tudom); + $r->print('
'.$text.' '. + &Apache::loncommon::plainname($tuname,$tudom)); + } else { + $r->print('
'. + &mt('Error saving parameters').'
'); + } + &Apache::lonnet::devalidateuserresdata($tuname,$tudom); + } + } + } else { + if ($altkey) { + if ($recursive) { + if (exists($$olddata{$thiskey})) { + if ($$olddata{$thiskey} eq $data) { + $reconlychg = 1; + } + push(@delnonrec,($thiskey,$thiskey.'.type')); + } + if (exists($$olddata{$altkey})) { + if (defined($data) && $$olddata{$altkey} ne $data) { + $haschange = 1; + } + } elsif (($data ne '') && (!$reconlychg)) { + $haschange = 1; + } + $storekey = $altkey; + } else { + if (exists($$olddata{$altkey})) { + if ($$olddata{$altkey} eq $data) { + $reconlychg = 1; + } + push(@delrec,($altkey,$altkey.'.type')); + } + if (exists($$olddata{$thiskey})) { + if (defined($data) && $$olddata{$thiskey} ne $data) { + $haschange = 1; + } + } elsif (($data ne '') && (!$reconlychg)) { + $haschange = 1; + } + $storekey = $thiskey; } - &Apache::lonnet::devalidateuserresdata($tuname,$tudom); } else { - $newdata{$thiskey}=$data; - $newdata{$thiskey.'.type'}=$typeof; + if (defined($data) && $$olddata{$thiskey} ne $data) { + $haschange = 1; + $storekey = $thiskey; + } + } + } + if ($reconlychg || $haschange) { + unless ($env{'form.del_'.$thiskey}) { + $newdata{$storekey}=$data; + $newdata{$storekey.'.type'}=$typeof; } } } elsif ($cmd eq 'del') { if ($tuname) { - if (&Apache::lonnet::del('resourcedata',[$tkey],$tudom,$tuname) eq 'ok') { - &log_parmset({$tkey=>''},1,$tuname,$tudom); - $r->print('
'.&mt('Deleted parameter for').' '.&Apache::loncommon::plainname($tuname,$tudom)); + my $error; + if ($altkey) { + if (exists($$olddata{$altkey})) { + if (&Apache::lonnet::del('resourcedata',[$tkeyrec,$tkeyrec.'.type'],$tudom,$tuname) eq 'ok') { + &log_parmset({$tkeyrec=>''},1,$tuname,$tudom); + if ($recursive) { + $r->print('
'.&mt('Deleted parameter for').' '.&Apache::loncommon::plainname($tuname,$tudom)); + } + } elsif ($recursive) { + $error = 1; + } + } + if (exists($$olddata{$thiskey})) { + if (&Apache::lonnet::del('resourcedata',[$tkeynonrec,$tkeynonrec.'.type'],$tudom,$tuname) eq 'ok') { + &log_parmset({$tkeynonrec=>''},1,$tuname,$tudom); + unless ($recursive) { + $r->print('
'.&mt('Deleted parameter for').' '.&Apache::loncommon::plainname($tuname,$tudom)); + } + } elsif (!$recursive) { + $error = 1; + } + } } else { + if (exists($$olddata{$thiskey})) { + if (&Apache::lonnet::del('resourcedata',[$tkey,$tkey.'.type'],$tudom,$tuname) eq 'ok') { + &log_parmset({$tkey=>''},1,$tuname,$tudom); + $r->print('
'.&mt('Deleted parameter for').' '.&Apache::loncommon::plainname($tuname,$tudom)); + } else { + $error = 1; + } + } + } + if ($error) { $r->print('
'. &mt('Error deleting parameters').'
'); } &Apache::lonnet::devalidateuserresdata($tuname,$tudom); } else { - push (@deldata,$thiskey,$thiskey.'.type'); + if ($altkey) { + if (exists($$olddata{$altkey})) { + unless (grep(/^\Q$altkey\E$/,@delrec)) { + push(@deldata,($altkey,$altkey.'.type')); + } + } + if (exists($$olddata{$thiskey})) { + unless (grep(/^\Q$thiskey\E$/,@delnonrec)) { + push(@deldata,($thiskey,$thiskey.'.type')); + } + } + } elsif (exists($$olddata{$thiskey})) { + push(@deldata,($thiskey,$thiskey.'.type')); + } } } } } # Store all course level my $delentries=$#deldata+1; + my @alldels; + if (@delrec) { + push(@alldels,@delrec); + } + if (@delnonrec) { + push(@alldels,@delnonrec); + } + if (@deldata) { + push(@alldels,@deldata); + } my @newdatakeys=keys(%newdata); my $putentries=$#newdatakeys+1; - if ($delentries) { - if (&Apache::lonnet::del('resourcedata',\@deldata,$dom,$crs) eq 'ok') { - my %loghash=map { $_ => '' } @deldata; + my ($delresult,$devalidate); + if (@alldels) { + if (&Apache::lonnet::del('resourcedata',\@alldels,$dom,$crs) eq 'ok') { + my %loghash=map { $_ => '' } @alldels; &log_parmset(\%loghash,1); - $r->print('

'.&mt('Deleted [quant,_1,parameter]',$delentries/2).'

'); - } else { + if ($delentries) { + $r->print('

'.&mt('Deleted [quant,_1,parameter]',$delentries/2).'

'); + } + } elsif ($delentries) { $r->print('
'. &mt('Error deleting parameters').'
'); } - &Apache::lonnet::devalidatecourseresdata($crs,$dom); + $devalidate = 1; } if ($putentries) { if (&Apache::lonnet::put('resourcedata',\%newdata,$dom,$crs) eq 'ok') { @@ -3819,6 +4322,9 @@ sub storedata { $r->print('
'. &mt('Error saving parameters').'
'); } + $devalidate = 1; + } + if ($devalidate) { &Apache::lonnet::devalidatecourseresdata($crs,$dom); } } @@ -3886,11 +4392,11 @@ sub listdata { if (&Apache::lonnet::allowed('mdg',$env{'request.course.id'})) { %grouphash = &Apache::longroup::coursegroups(); } elsif ($env{'request.course.groups'} ne '') { - map { $grouphash{$_} = 1; } split(/,/,$env{'request.course.groups'}); + map { $grouphash{$_} = 1; } split(/:/,$env{'request.course.groups'}); } } - foreach my $thiskey (sort { + foreach my $key (sort { my ($astudent,$ares,$apart,$aparm) = &parse_listdata_key($a,$listdata); my ($bstudent,$bres,$bpart,$bparm) = &parse_listdata_key($b,$listdata); @@ -3930,16 +4436,17 @@ sub listdata { $result; - } keys(%{$listdata})) { # foreach my $thiskey - + } keys(%{$listdata})) { # foreach my $key + my $thiskey = $key; if ($$listdata{$thiskey.'.type'}) { my $thistype=$$listdata{$thiskey.'.type'}; if ($$resourcedata{$thiskey.'.type'}) { $thistype=$$resourcedata{$thiskey.'.type'}; } my ($middle,$part,$name)= - ($thiskey=~/^$env{'request.course.id'}\.(?:(.+)\.)*([\w\s]+)\.(\w+)$/); + ($thiskey=~/^$env{'request.course.id'}\.(?:(.+)\.)*([\w\s\-]+)\.(\w+)$/); my $section=&mt('All Students'); + my $showval = $$resourcedata{$thiskey}; if ($middle=~/^\[(.*)\]/) { my $issection=$1; if ($issection=~/^useropt\:($match_username)\:($match_domain)/) { @@ -3972,12 +4479,37 @@ sub listdata { $middle=~s/\.+$//; $middle=~s/^\.+//; my $realm=''.&mt('All Resources').''; - if ($middle=~/^(.+)\_\_\_\((all|rec)\)$/) { - my $mapurl = $1; - my $maplevel = $2; + my ($is_map,$is_recursive,$mapurl,$maplevel); + if ($caller eq 'overview') { + if ($middle=~/^(.+)\_\_\_\((all|rec)\)$/) { + $mapurl = $1; + $maplevel = $2; + $is_map = 1; + } + } elsif ($caller eq 'newoverview') { + if ($middle=~/^(.+)\_\_\_\((all)\)$/) { + $mapurl = $1; + $maplevel = $2; + $is_map = 1; + } + } + if ($is_map) { my $leveltitle = &mt('Folder/Map'); - if ($maplevel eq 'rec') { - $leveltitle = &mt('Recursive'); + unless (($name eq 'hiddenresource') || ($name eq 'encrypturl')) { + if ($caller eq 'newoverview') { + my $altkey = $thiskey; + $altkey =~ s/\Q___(all)\E/___(rec)/; + if ((exists($$resourcedata{$altkey})) & (!exists($$resourcedata{$thiskey}))) { + $is_recursive = 1; + if ($$resourcedata{$altkey.'.type'}) { + $thistype=$$resourcedata{$altkey.'.type'}; + } + $showval = $$resourcedata{$altkey}; + } + } elsif (($caller eq 'overview') && ($maplevel eq 'rec')) { + $thiskey =~ s/\Q___(rec)\E/___(all)/; + $is_recursive = 1; + } } $realm=''.$leveltitle.': '.&Apache::lonnet::gettitle($mapurl).'
('.$mapurl.')
'; } elsif ($middle) { @@ -4019,7 +4551,7 @@ sub listdata { # Ready to print # my $parmitem = &standard_parameter_names($name); - $r->print(&tablestart($readonly). + $r->print(&tablestart($readonly,$is_map). &Apache::loncommon::start_data_table_row(). ''.&mt($parmitem). ''); @@ -4039,30 +4571,48 @@ sub listdata { $r->print( &Apache::lonhtmlcommon::date_setter('parmform', $jskey, - $$resourcedata{$thiskey}, + $showval, '',1,$state)); unless ($readonly) { $r->print( ''. - (($$resourcedata{$thiskey}!=0)?''. + (($showval!=0)?''. &mt('Shift all dates based on this date').'':''). - &date_sanity_info($$resourcedata{$thiskey}) + &date_sanity_info($showval) ); } } elsif ($thistype eq 'date_interval') { $r->print(&date_interval_selector($thiskey,$name, - $$resourcedata{$thiskey},$readonly)); + $showval,$readonly)); } elsif ($thistype =~ m/^string/) { $r->print(&string_selector($thistype,$thiskey, - $$resourcedata{$thiskey},$name,$readonly)); + $showval,$name,$readonly)); } else { - $r->print(&default_selector($thiskey,$$resourcedata{$thiskey},$readonly)); + $r->print(&default_selector($thiskey,$showval,$readonly)); } unless ($readonly) { $r->print(''); } - $r->print(''.&Apache::loncommon::end_data_table_row()); + $r->print(''); + if ($is_map) { + if (($name eq 'encrypturl') || ($name eq 'hiddenresource')) { + $r->print('
'.&mt('Yes').'
'); + } else { + my ($disabled,$recon,$recoff); + if ($readonly) { + $disabled = ' disabled="disabled"'; + } + if ($is_recursive) { + $recon = ' checked="checked"'; + } else { + $recoff = ' checked="checked"'; + } + $r->print('
'. + '
'); + } + } + $r->print(&Apache::loncommon::end_data_table_row()); } } return $foundkeys; @@ -4187,6 +4737,139 @@ sub string_ip_selector { return $output; } +sub string_deeplink_selector { + my ($thiskey, $showval, $readonly) = @_; + my (@components,%values,@current,%titles,%options,%optiontext,%defaults,%posslti); + @components = ('listing','scope','urls'); + %titles = &Apache::lonlocal::texthash ( + listing => 'In Contents and/or Gradebook', + scope => 'Access scope for link', + urls => 'Supported link types', + ); + %options = ( + listing => ['full','absent','grades','details','datestatus'], + scope => ['res','map','rec'], + urls => ['any','only','key','lti'], + ); + %optiontext = &Apache::lonlocal::texthash ( + full => 'Listed (linked) in both', + absent => 'Not listed', + grades => 'Listed in grades only', + details => 'Listed (unlinked) in both', + datestatus => 'Listed (unlinked) inc. status in both', + res => 'resource only', + map => 'enclosing map/folder', + rec => 'recursive map/folder', + any => 'regular + deep', + only => 'deep only', + key => 'deep with key', + lti => 'deep with LTI launch', + ); + if ($showval =~ /,/) { + @current = split(/,/,$showval); + ($values{'listing'}) = ($current[0] =~ /^(full|absent|grades|details|datestatus)$/); + ($values{'scope'}) = ($current[1] =~ /^(res|map|rec)$/); + ($values{'urls'}) = ($current[2] =~ /^(any|only|key:\w+|lti:\d+)$/); + } else { + $defaults{'listing'} = 'full'; + $defaults{'scope'} = 'res'; + $defaults{'urls'} = 'any'; + } + my $disabled; + if ($readonly) { + $disabled=' disabled="disabled"'; + } + my %lti = + &Apache::lonnet::get_domain_lti($env{'course.'.$env{'request.course.id'}.'.domain'}, + 'provider'); + foreach my $item (keys(%lti)) { + if (ref($lti{$item}) eq 'HASH') { + unless ($lti{$item}{'requser'}) { + $posslti{$item} = $lti{$item}{'consumer'}; + } + } + } + my $output = ''; + foreach my $item ('listing','scope','urls') { + $output .= ''; + } + $output .= ''; + foreach my $item (@components) { + $output .= ''; + } + $output .= '
'.$titles{$item}.'
'; + if ($item eq 'urls') { + my $selected = $values{$item}; + foreach my $option (@{$options{$item}}) { + if ($option eq 'lti') { + next unless (keys(%posslti)); + } + my $checked; + if ($selected =~ /^\Q$option\E/) { + $checked = ' checked="checked"'; + } + my $onclick; + unless ($readonly) { + my $esc_key = &js_escape($thiskey); + $onclick = ' onclick="toggleDeepLink(this.form,'."'$item','$esc_key'".');"'; + } + $output .= ''; + if ($option eq 'key') { + my $visibility="hidden"; + my $currkey; + if ($checked) { + $visibility = "text"; + $currkey = (split(/\:/,$values{$item}))[1]; + } + $output .= ' '. + ''; + } elsif ($option eq 'lti') { + my $display="none"; + my ($currlti,$blankcheck); + if ($checked) { + $display = 'inline-block'; + $currlti = (split(/\:/,$values{$item}))[1]; + } else { + $blankcheck = ' selected="selected"'; + } + $output .= '
 
'; + } + $output .= '
'; + } + } else { + my $selected = $values{$item}; + my $defsel; + if ($selected eq '') { + $defsel = ' selected="selected"'; + } + $output .= ''; + } + $output .= '
'."\n"; + return $output; +} + { # block using some constants related to parameter types (overview mode) @@ -4220,8 +4903,11 @@ my %strings = ['no','No']], 'string_ip' => [['_allowfrom_','Hostname(s), or IP(s) from which access is allowed'], - ['_denyfrom_',], 'Hostname(s) or IP(s) from which access is disallowed'], - ); + ['_denyfrom_','Hostname(s) or IP(s) from which access is disallowed']], + 'string_deeplink' + => [['on','Set choices for link protection, resource listing, and access scope']], + ); + my %stringmatches = ( 'string_lenient' @@ -4229,6 +4915,8 @@ my %stringmatches = ( 'string_ip' => [['_allowfrom_','[^\!]+'], ['_denyfrom_','\!']], + 'string_deeplink' + => [['on','^(full|absent|grades|details|datestatus)\,(res|map|rec)\,(any|only|key\:\w+|lti\:\d+)$']], ); my %stringtypes = ( @@ -4238,6 +4926,7 @@ my %stringtypes = ( discussvote => 'string_discussvote', examcode => 'string_examcode', acc => 'string_ip', + deeplink => 'string_deeplink', ); # Returns the possible values and titles for a given string type, or undef if there are none. @@ -4297,6 +4986,7 @@ sub string_selector { ($thistype eq 'string_lenient') || ($thistype eq 'string_discussvote') || ($thistype eq 'string_ip') || + ($thistype eq 'string_deeplink') || ($name eq 'retrypartial')) { my ($got_chostname,$chostname,$cmajor,$cminor); foreach my $possibilities (@{ $strings{$thistype} }) { @@ -4335,6 +5025,8 @@ sub string_selector { if ($thistype eq 'string_ip') { return &string_ip_selector($thiskey,$showval,$readonly); + } elsif ($thistype eq 'string_deeplink') { + return &string_deeplink_selector($thiskey,$showval,$readonly); } my ($result,$disabled); @@ -4749,6 +5441,7 @@ sub newoverview { &validateparms_js()."\n". &ipacc_boxes_js()."\n". &done_proctor_js()."\n". + &deeplink_js()."\n". '// ]]> '; @@ -4835,7 +5528,7 @@ ENDOVER $r->print('
'); $r->print('
'); - &displaymenu($r,\%allparms,\@pscat,\%keyorder); # FIXME: wrong parameters, could make keysindisplayorderCategory crash because $keyorder is undefined + &displaymenu($r,\%allparms,\@pscat,\%keyorder); $r->print(&Apache::lonhtmlcommon::start_pick_box()); $r->print(&Apache::lonhtmlcommon::row_title(&mt('Select Parts to View'))); my $sectionselector = §ionmenu(\@selected_sections); @@ -4936,9 +5629,6 @@ sub secgroup_lister { my $newparmkey=$rootparmkey.'.'.$$allmaps{$mapid}.'___(all).'.$part.'.'.$cat; $$listdata{$newparmkey}=1; $$listdata{$newparmkey.'.type'}=$$defkeytype{$cat}; - $newparmkey=$rootparmkey.'.'.$$allmaps{$mapid}.'___(rec).'.$part.'.'.$cat; - $$listdata{$newparmkey}=1; - $$listdata{$newparmkey.'.type'}=$$defkeytype{$cat}; } } else { # resource-level parameter @@ -4973,6 +5663,7 @@ sub overview { &validateparms_js()."\n". &ipacc_boxes_js()."\n". &done_proctor_js()."\n". + &deeplink_js()."\n". '// ]]>'."\n". ''."\n"; &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=setoverview', @@ -5084,10 +5775,8 @@ ENDOVER $r->print(&mt('All users')); } elsif ($data{'scope_type'} eq 'user') { $r->print(&mt('User: [_1]',join(':',@{$data{'scope'}}))); - } elsif ($data{'scope_type'} eq 'section') { - $r->print(&mt('Section: [_1]',$data{'scope'})); - } elsif ($data{'scope_type'} eq 'group') { - $r->print(&mt('Group: [_1]',$data{'scope'})); + } elsif ($data{'scope_type'} eq 'secgroup') { + $r->print(&mt('Group/Section: [_1]',$data{'scope'})); } $r->print('
'); if ($data{'realm_type'} eq 'all') { @@ -5186,7 +5875,7 @@ sub parse_key { my ($key) = @_; my %data; my ($middle,$part,$name)= - ($key=~/^$env{'request.course.id'}\.(?:(.+)\.)*([\w\s]+)\.(\w+)$/); + ($key=~/^$env{'request.course.id'}\.(?:(.+)\.)*([\w\s\-]+)\.(\w+)$/); $data{'scope_type'} = 'all'; if ($middle=~/^\[(.*)\]/) { $data{'scope'} = $1; @@ -5194,8 +5883,7 @@ sub parse_key { $data{'scope_type'} = 'user'; $data{'scope'} = [$1,$2]; } else { - #FIXME check for group scope - $data{'scope_type'} = 'section'; + $data{'scope_type'} = 'secgroup'; } $middle=~s/^\[(.*)\]//; } @@ -5351,7 +6039,7 @@ ENDMAINFORMHEAD }]}, { categorytitle => 'Existing Parameter Settings for Resources', items => [ - { linktext => $linktext{'setoverview'},, + { linktext => $linktext{'setoverview'}, url => '/adm/parmset?action=setoverview', permission => $parm_permission->{'setoverview'}, linktitle => $linktitle{'setoverview'}, @@ -5541,7 +6229,7 @@ sub continue { my $output; $output .= '
'; $output .= ''; - $output .= ''; + $output .= ''; return ($output); } @@ -5569,7 +6257,10 @@ sub addmetafield { my $put_result = &Apache::lonnet::put('environment', {'metadata.'.$meta_field.'.options'=>$options},$dom,$crs); - $r->print('Undeleted Metadata Field '.$env{'course.'.$env{'request.course.id'}.'.metadata.'.$meta_field.'.added'}." with result ".$put_result.'
'); + $r->print(&mt('Undeleted Metadata Field [_1] with result [_2]', + ''.$env{'course.'.$env{'request.course.id'}.'.metadata.'.$meta_field.'.added'}. + '',$put_result). + '
'); } $r->print(&continue()); } elsif (exists($env{'form.fieldname'})) { @@ -5581,24 +6272,32 @@ sub addmetafield { {'metadata.'.$meta_field.'.values'=>"", 'metadata.'.$meta_field.'.added'=>"$display_field", 'metadata.'.$meta_field.'.options'=>""},$dom,$crs); - $r->print('Added new Metadata Field '.$env{'form.fieldname'}." with result ".$put_result.'
'); + $r->print(&mt('Added new Metadata Field [_1] with result [_2]', + ''.$env{'form.fieldname'}.'',$put_result). + '
'); $r->print(&continue()); } else { my $fields = &get_deleted_meta_fieldnames($env{'request.course.id'}); if ($fields) { - $r->print('You may undelete previously deleted fields.
Check those you wish to undelete and click Undelete.
'); + $r->print(&mt('You may undelete previously deleted fields.'). + '
'. + &mt('Check those you wish to undelete and click Undelete.'). + '
'); $r->print(''); foreach my $key(keys(%$fields)) { - $r->print(''.$$fields{$key}.'
print('
print(''); + $r->print(''); $r->print('
'); } - $r->print('
Or you may enter a new metadata field name.
print('
'. + &mt('[_1]Or[_2] you may enter a new metadata field name.', + '',''). + ''); $r->print('
'); - $r->print(''); + $r->print(''); + $r->print('
'); } - $r->print(''); &endSettingsScreen($r); } @@ -5623,6 +6322,11 @@ sub setrestrictmeta { &startSettingsScreen($r,'parmset',$crstype); my $key_base = $env{'course.'.$env{'request.course.id'}.'.'}; my $save_field = ''; + my %lt = &Apache::lonlocal::texthash( + addm => 'Add Metadata Field', + ordm => 'Order Metadata Fields', + save => 'Save', + ); if ($env{'form.restrictmeta'}) { foreach my $field (sort(keys(%env))) { if ($field=~m/^form.(.+)_(.+)$/) { @@ -5661,28 +6365,25 @@ sub setrestrictmeta { my %metadata_fields = &Apache::lonmeta::fieldnames('portfolio'); # Now get possible added metadata fields my $added_metadata_fields = &get_added_meta_fieldnames($env{'request.course.id'}); - my $row_alt = 1; $output .= &Apache::loncommon::start_data_table(); foreach my $field (sort(keys(%metadata_fields))) { if ($field ne 'courserestricted') { - $row_alt = $row_alt ? 0 : 1; - $output.= &output_row($r, $field, $metadata_fields{$field}); + $output.= &output_row($r,$field,$metadata_fields{$field}); } } my $buttons = (< +
- +

- + ENDButtons my $added_flag = 1; foreach my $field (sort(keys(%$added_metadata_fields))) { - $row_alt = $row_alt ? 0 : 1; - $output.= &output_row($r, $field, $$added_metadata_fields{$field},$added_flag, $row_alt); # FIXME: wrong parameters + $output.= &output_row($r,$field,$$added_metadata_fields{$field},$added_flag); } $output .= &Apache::loncommon::end_data_table(); $r->print(<) { if ($configline !~ /\S/ || $configline=~/^\#/) { next; } chomp($configline); @@ -5998,6 +6695,7 @@ sub load_parameter_names { close($config); $standard_parms{'int_pos'} = 'Positive Integer'; $standard_parms{'int_zero_pos'} = 'Positive Integer or Zero'; + $standard_parms{'scoreformat'} = 'Format for display of score'; } # Returns a parameter title for standard parameters, the name for others. @@ -6056,7 +6754,7 @@ sub parm_change_log { my ($r,$parm_permission)=@_; my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; - my $crstype = $env{'course.'.$env{'request.course.id'}.'.type'} + my $crstype = $env{'course.'.$env{'request.course.id'}.'.type'}; &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=settable', text=>"Parameter Change Log"}); my $js = '