--- loncom/interface/lonparmset.pm 2017/06/19 19:04:51 1.522.2.23.2.2 +++ loncom/interface/lonparmset.pm 2019/03/02 16:25:45 1.522.2.23.2.3 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Handler to set parameters for assessments # -# $Id: lonparmset.pm,v 1.522.2.23.2.2 2017/06/19 19:04:51 raeburn Exp $ +# $Id: lonparmset.pm,v 1.522.2.23.2.3 2019/03/02 16:25:45 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -833,8 +833,12 @@ sub plink { my ($type,$dis,$value,$marker,$return,$call)=@_; my $winvalue=$value; unless ($winvalue) { - if (&isdateparm($type)) { + if ((&isdateparm($type)) || (&is_specialstring($type))) { $winvalue=$env{'form.recent_'.$type}; + } elsif ($type eq 'string_yesno') { + if ($env{'form.recent_string'} =~ /^(yes|no)$/i) { + $winvalue=$env{'form.recent_string'}; + } } else { $winvalue=$env{'form.recent_'.(split(/\_/,$type))[0]}; } @@ -867,12 +871,14 @@ sub page_js { $pjump_def function psub() { + var specstring = /^string_!(yesno|any)/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))) { eval('document.parmform.recent_'+ document.parmform.pres_type.value+ '.value=document.parmform.pres_value.value;'); @@ -922,6 +928,72 @@ function showHide_courseContent() { COURSECONTENTSCRIPT } +sub validateparms_js { + return <<'ENDSCRIPT'; + +function validateParms() { + var ipallowRegExp = /^setipallow_/; + var ipdenyRegExp = /^setipdeny_/; + 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$remove'); + }); + + \$(wrapper).delegate(".LC_remove_ipacc","click", function(e){ + e.preventDefault(); \$(this).closest("div").remove(); + }) +}); + + +END +} + sub done_proctor_js { return <<"END"; function toggleSecret(form,radio,key) { @@ -1315,6 +1387,14 @@ 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'))); +} + # # parmmenu displays a list of the selected parameters. # It also offers a link to show/hide the complete parameter list @@ -2194,7 +2274,6 @@ sub assessparms { my ($got_chostname,$chostname,$cmajor,$cminor); my $totalstored = 0; my $now = time; - for (my $i=0;$i<=$#markers;$i++) { my ($needsrelease,$needsnewer,$name); if ($markers[$i] =~ /^[\d.]+\&0_availablestudent\&(1|2|3)$/) { @@ -2286,11 +2365,14 @@ sub assessparms { &startpage($r,$pssymb); - foreach ('tolerance','date_default','date_start','date_end', - 'date_interval','int','float','string') { + foreach my $item ('tolerance','date_default','date_start','date_end', + 'date_interval','int','float','string','string_lenient', + 'string_examcode','string_deeplink','string_discussvote', + 'string_useslots','string_problemstatus','string_ip', + 'string_questiontype') { $r->print(''). - '" name="recent_'.$_.'" />'); + &HTML::Entities::encode($env{'form.recent_'.$item},'"&<>'). + '" name="recent_'.$item.'" />'); } # ----- Start Parameter Selection @@ -2902,6 +2984,7 @@ sub storedata { if ($key =~ /^form\.([a-z]+)\_(.+)$/) { my $cmd=$1; my $thiskey=$2; + next if ($cmd eq 'setipallow' || $cmd eq 'setipdeny'); my ($tuname,$tudom)=&extractuser($thiskey); my $tkey=$thiskey; if ($tuname) { @@ -3314,6 +3397,68 @@ sub default_selector { return ''; } +sub string_ip_selector { + my ($thiskey, $showval, $readonly) = @_; + my %access = ( + allow => [], + deny => [], + ); + if ($showval ne '') { + my @current; + if ($showval =~ /,/) { + @current = split(/,/,$showval); + } else { + @current = ($showval); + } + foreach my $item (@current) { + if ($item =~ /^\!([\[\]a-zA-Z\.\d\*\-]+)$/) { + push(@{$access{'deny'}},$1); + } elsif ($item =~ /^([\[\]a-zA-Z\.\d\*\-]+)$/) { + push(@{$access{'allow'}},$item); + } + } + } + if (!@{$access{'allow'}}) { + @{$access{'allow'}} = (''); + } + if (!@{$access{'deny'}}) { + @{$access{'deny'}} = (''); + } + my ($disabled,$addmore); + if ($readonly) { + $disabled=' disabled="disabled"'; + } else { + $addmore = "\n".''; + } + my $output = ' +'; + foreach my $acctype ('allow','deny') { + $output .= ' +'; + } + $output .= ' + +
'.&mt('Allow from').''.&mt('Deny from').'
+
+
'."\n"; + my $num = 0; + foreach my $curr (@{$access{$acctype}}) { + $output .= '
'; + if ($num > 0) { + $output .= ''.&mt('Remove').''; + } + $output .= '
'."\n"; + $num ++; + } + $output .= ' +
'.$addmore.' +
+
'."\n"; + return $output; +} + +{ + my %strings = ( 'string_yesno' @@ -3341,7 +3486,10 @@ my %strings = => [['yes','Yes'], ['notended','Yes, unless discussion ended'], ['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']], + ); sub standard_string_options { my ($string_type) = @_; @@ -3382,6 +3530,10 @@ sub string_selector { } } + if ($thistype eq 'string_ip') { + return &string_ip_selector($thiskey,$showval,$readonly); + } + my ($result,$disabled); if ($readonly) { @@ -3435,6 +3587,55 @@ sub string_selector { return $result; } +sub oldversion_warning { + my ($name,$value,$chostname,$cmajor,$cminor,$needsrelease) = @_; + my $desc; + my %stringtypes = ( + type => 'string_questiontype', + lenient => 'string_lenient', + retrypartial => 'string_yesno', + discussvote => 'string_discussvote', + examcode => 'string_examcode', + ); + if (exists($stringtypes{$name})) { + if ($name eq 'examcode') { + $desc = $value; + } elsif (ref($strings{$stringtypes{$name}}) eq 'ARRAY') { + foreach my $possibilities (@{ $strings{$stringtypes{$name}} }) { + next unless (ref($possibilities) eq 'ARRAY'); + my ($parmval, $description) = @{ $possibilities }; + if ($parmval eq $value) { + $desc = $description; + last; + } + } + } + } elsif (($name eq 'printstartdate') || ($name eq 'printenddate')) { + my $now = time; + if ($value =~ /^\d+$/) { + if ($name eq 'printstartdate') { + if ($value > $now) { + $desc = &Apache::lonlocal::locallocaltime($value); + } + } elsif ($name eq 'printenddate') { + if ($value < $now) { + $desc = &Apache::lonlocal::locallocaltime($value); + } + } + } + } + my $standard_name = &standard_parameter_names($name); + return '

'. + &mt('[_1] was [_2]not[_3] set to [_4].', + $standard_name,'','','"'.$desc.'"').'
'. + &mt('LON-CAPA version ([_1]) installed on home server ([_2]) does not meet version requirements ([_3] or newer).', + $cmajor.'.'.$cminor,$chostname, + $needsrelease). + '

'; +} + +} + # # Shift all start and end dates by $shift # @@ -4907,53 +5108,6 @@ sub parameter_releasecheck { return $needsnewer; } -sub oldversion_warning { - my ($name,$value,$chostname,$cmajor,$cminor,$needsrelease) = @_; - my $desc; - my %stringtypes = ( - type => 'string_questiontype', - lenient => 'string_lenient', - retrypartial => 'string_yesno', - discussvote => 'string_discussvote', - examcode => 'string_examcode', - ); - if (exists($stringtypes{$name})) { - if ($name eq 'examcode') { - $desc = $value; - } elsif (ref($strings{$stringtypes{$name}}) eq 'ARRAY') { - foreach my $possibilities (@{ $strings{$stringtypes{$name}} }) { - next unless (ref($possibilities) eq 'ARRAY'); - my ($parmval, $description) = @{ $possibilities }; - if ($parmval eq $value) { - $desc = $description; - last; - } - } - } - } elsif (($name eq 'printstartdate') || ($name eq 'printenddate')) { - my $now = time; - if ($value =~ /^\d+$/) { - if ($name eq 'printstartdate') { - if ($value > $now) { - $desc = &Apache::lonlocal::locallocaltime($value); - } - } elsif ($name eq 'printenddate') { - if ($value < $now) { - $desc = &Apache::lonlocal::locallocaltime($value); - } - } - } - } - my $standard_name = &standard_parameter_names($name); - return '

'. - &mt('[_1] was [_2]not[_3] set to [_4].', - $standard_name,'','','"'.$desc.'"').'
'. - &mt('LON-CAPA version ([_1]) installed on home server ([_2]) does not meet version requirements ([_3] or newer).', - $cmajor.'.'.$cminor,$chostname, - $needsrelease). - '

'; -} - sub get_permission { my %permission; my $allowed = 0;