--- loncom/interface/lonparmset.pm 2018/11/13 03:59:00 1.587 +++ loncom/interface/lonparmset.pm 2019/01/06 15:27:48 1.588 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Handler to set parameters for assessments # -# $Id: lonparmset.pm,v 1.587 2018/11/13 03:59:00 raeburn Exp $ +# $Id: lonparmset.pm,v 1.588 2019/01/06 15:27:48 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -1065,9 +1065,10 @@ 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 {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,$recursive)=@_; + my ($type,$dis,$value,$marker,$return,$call,$recursive,$extra)=@_; my $winvalue=$value; unless ($winvalue) { if (&isdateparm($type)) { @@ -1082,13 +1083,13 @@ 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 ''.($recursive?'' : '').'
'. ''. + .$marker."','".$return."','".$call."','".$hour."','".$min."','".$sec."','".$extra."'".');">'. $valout.'
'. &mt('recursive').'
'; @@ -1237,12 +1238,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 0)) { if ($result eq '') { $recurse_check = 1; @@ -1535,25 +1609,45 @@ sub print_row { ($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,2,$defbgone,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly,1); + &print_td($r,2,$defbgone,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly,1,$extra); } elsif ($cgroup) { - &print_td($r,6,$defbgthree,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,$noeditgrp,$readonly,1); + &print_td($r,6,$defbgthree,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,$noeditgrp,$readonly,1,$extra); } elsif ($csec) { - &print_td($r,10,$defbgtwo,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly,1); + &print_td($r,10,$defbgtwo,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly,1,$extra); } else { - &print_td($r,16,$defbgone,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly,1); + &print_td($r,16,$defbgone,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly,1,$extra); } } else { if ($uname) { @@ -1576,31 +1670,31 @@ sub print_row { } } - &print_td($r,18,$defbgone,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly); - &print_td($r,16,$defbgone,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly,1); - &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,10,$defbgtwo,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly,1); - &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,6,$defbgthree,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,$noeditgrp,$readonly,1); - &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,2,$defbgone,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly,1); - &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 if (ref($recursinfo) eq 'ARRAY') { @@ -1666,10 +1760,11 @@ 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 {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,$ismaplevel)=@_; + $noeditgrp,$readonly,$ismaplevel,$extra)=@_; my ($ineffect,$recursive,$currval,$currtype,$currlevel); $ineffect = 0; $currval = $$outpar[$which]; @@ -1723,7 +1818,8 @@ sub print_td { } else { $r->print(&plink($currtype, $$display{$value},$currval, - $mprefix.$currlevel,'parmform.pres','psub',$recursive)); + $mprefix.$currlevel,'parmform.pres','psub',$recursive, + $extra)); } $r->print(''."\n"); } @@ -3832,7 +3928,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) @@ -3865,7 +3961,7 @@ sub storedata { my $cmd=$1; my $thiskey=$2; my ($altkey,$recursive,$tkey,$tkeyrec,$tkeynonrec); - next if ($cmd eq 'rec' || $cmd eq 'settext' || $cmd eq 'setipallow' || $cmd eq 'setipdeny'); + 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)$/) { @@ -3896,8 +3992,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}) { @@ -4628,6 +4724,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) @@ -4663,11 +4892,7 @@ my %strings = => [['_allowfrom_','Hostname(s), or IP(s) from which access is allowed'], ['_denyfrom_','Hostname(s) or IP(s) from which access is disallowed']], 'string_deeplink' - => [['full','Displayed (linked) in Contents and Grades'], - ['absent','Not displayed in Contents or Grades'], - ['grades','Displayed in Grades only'], - ['details','Displayed (unlinked) in Contents and Grades'], - ['datestatus','Displayed (with status), but unlinked in Contents and Grades']], + => [['on','Set choices for link protection, resource listing, and access scope']], ); @@ -4677,6 +4902,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 = ( @@ -4746,6 +4973,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} }) { @@ -4784,6 +5012,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); @@ -5198,6 +5428,7 @@ sub newoverview { &validateparms_js()."\n". &ipacc_boxes_js()."\n". &done_proctor_js()."\n". + &deeplink_js()."\n". '// ]]> '; @@ -5419,6 +5650,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',