Diff for /loncom/interface/lonparmset.pm between versions 1.522.2.26 and 1.522.2.26.2.1

version 1.522.2.26, 2018/12/01 15:34:55 version 1.522.2.26.2.1, 2020/01/15 00:38:38
Line 767  sub valout { Line 767  sub valout {
         }          }
     } else {      } else {
         if ($type eq 'date_interval') {          if ($type eq 'date_interval') {
             my ($sec,$min,$hour,$mday,$mon,$year)=gmtime($value);              my ($totalsecs,$donesuffix) = split(/_/,$value,2);
               my ($usesdone,$donebuttontext,$proctor,$secretkey);
               if ($donesuffix =~ /^done\:([^\:]+)\:(.*)$/) {
                   $donebuttontext = $1;
                   (undef,$proctor,$secretkey) = split(/_/,$2);
                   $usesdone = 'done';
               } elsif ($donesuffix =~ /^done(|_.+)$/) {
                   $donebuttontext = &mt('Done');
                   ($usesdone,$proctor,$secretkey) = split(/_/,$donesuffix);
               }
               my ($sec,$min,$hour,$mday,$mon,$year)=gmtime($totalsecs);
             my @timer;              my @timer;
             $year=$year-70;              $year=$year-70;
             $mday--;              $mday--;
Line 800  sub valout { Line 810  sub valout {
                 push(@timer,&mt('[quant,_1,sec]',0));                  push(@timer,&mt('[quant,_1,sec]',0));
             }              }
             $result.=join(", ",@timer);              $result.=join(", ",@timer);
               if ($usesdone eq 'done') {
                   if ($secretkey) {
                       $result .= ' '.&mt('+ "[_1]" with proctor key: [_2]',$donebuttontext,$secretkey);
                   } else {
                       $result .= ' + "'.$donebuttontext.'"';
                   }
               }
         } elsif (&isdateparm($type)) {          } elsif (&isdateparm($type)) {
             $result = &Apache::lonlocal::locallocaltime($value).              $result = &Apache::lonlocal::locallocaltime($value).
         &date_sanity_info($value);          &date_sanity_info($value);
Line 817  sub plink { Line 834  sub plink {
     my ($type,$dis,$value,$marker,$return,$call)=@_;      my ($type,$dis,$value,$marker,$return,$call)=@_;
     my $winvalue=$value;      my $winvalue=$value;
     unless ($winvalue) {      unless ($winvalue) {
     if (&isdateparm($type)) {          if ((&isdateparm($type)) || (&is_specialstring($type))) {
             $winvalue=$env{'form.recent_'.$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 {          } else {
             $winvalue=$env{'form.recent_'.(split(/\_/,$type))[0]};              $winvalue=$env{'form.recent_'.(split(/\_/,$type))[0]};
         }          }
Line 851  sub page_js { Line 872  sub page_js {
     $pjump_def      $pjump_def
   
     function psub() {      function psub() {
           var specstring = /^string_!(yesno|any)/i;
         if (document.parmform.pres_marker.value!='') {          if (document.parmform.pres_marker.value!='') {
             document.parmform.action+='#'+document.parmform.pres_marker.value;              document.parmform.action+='#'+document.parmform.pres_marker.value;
             var typedef=new Array();              var typedef=new Array();
             typedef=document.parmform.pres_type.value.split('_');              typedef=document.parmform.pres_type.value.split('_');
            if (document.parmform.pres_type.value!='') {              if (document.parmform.pres_type.value!='') {
             if (typedef[0]=='date') {                  if ((typedef[0]=='date') ||
                 eval('document.parmform.recent_'+                      (specstring.test(document.parmform.pres_type.value)))  {
                      document.parmform.pres_type.value+                      eval('document.parmform.recent_'+
              '.value=document.parmform.pres_value.value;');                          document.parmform.pres_type.value+
             } else {                          '.value=document.parmform.pres_value.value;');
                 eval('document.parmform.recent_'+typedef[0]+                  } else {
              '.value=document.parmform.pres_value.value;');                      eval('document.parmform.recent_'+typedef[0]+
                           '.value=document.parmform.pres_value.value;');
                   }
             }              }
        }  
             document.parmform.submit();              document.parmform.submit();
         } else {          } else {
             document.parmform.pres_value.value='';              document.parmform.pres_value.value='';
Line 906  function showHide_courseContent() { Line 929  function showHide_courseContent() {
 COURSECONTENTSCRIPT  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<document.parmform.elements.length; i++) {
                   var name=document.parmform.elements[i].name;
                   if (ipallowRegExp.test(name)) {
                       var identifier = name.replace(ipallowRegExp,'');
                       var possallow = document.parmform.elements[i].value;
                       possallow = possallow.replace(/^\s+|\s+$/g,'');
                       if (patternIP.test(possallow)) {
                           if (document.parmform.elements['set_'+identifier].value) {
                               possallow = ','+possallow;
                           }
                           document.parmform.elements['set_'+identifier].value += possallow;
                       }
                   } else if (ipdenyRegExp.test(name)) {
                       var identifier = name.replace(ipdenyRegExp,'');
                       var possdeny = document.parmform.elements[i].value;
                       possdeny = possdeny.replace(/^\s+|\s+$/g,'');
                       if (patternIP.test(possdeny)) {
                           possdeny = '!'+possdeny;
                           if (document.parmform.elements['set_'+identifier].value) {
                               possdeny = ','+possdeny;
                           }
                       }
                   }
               }
           }
       }
       return true;
   }
   
   ENDSCRIPT
   }
   
   # Javascript initialization, for overview mode
   sub ipacc_boxes_js  {
       my $remove = &mt('Remove');
       return <<"END";
   \$(document).ready(function() {
       var wrapper         = \$(".LC_string_ipacc_wrap");
       var add_button      = \$(".LC_add_ipacc_button");
       var ipaccRegExp     = /^LC_string_ipacc_/;
   
       \$(add_button).click(function(e){
           e.preventDefault();
           var identifier = \$(this).closest("div").attr("id");
           identifier = identifier.replace(ipaccRegExp,'');
           \$(this).closest('div').find('.LC_string_ipacc_inner').append('<div><input type="text" name="setip'+identifier+'" /><a href="#" class="LC_remove_ipacc">$remove</a></div>');
       });
   
       \$(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) {
       var radios = form[radio+key];
       if (radios.length) {
           for (var i=0; i<radios.length; i++) {
               if (radios[i].checked) {
                   if (radios[i].value == '_done_proctor') {
                       if (document.getElementById('done_'+key+'_proctorkey')) {
                           document.getElementById('done_'+key+'_proctorkey').type='text';
                       }
                   } else {
                       if (document.getElementById('done_'+key+'_proctorkey')) {
                           document.getElementById('done_'+key+'_proctorkey').type='hidden';
                           document.getElementById('done_'+key+'_proctorkey').value='';
                       }
                   }
               }
           }
       }
   }
   END
   
   }
   
 sub startpage {  sub startpage {
     my ($r,$psymb) = @_;      my ($r,$psymb) = @_;
   
Line 1279  sub isdateparm { Line 1393  sub isdateparm {
     return (($type=~/^date/) && (!($type eq 'date_interval')));      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.  # parmmenu displays a list of the selected parameters.
 # It also offers a link to show/hide the complete parameter list  # It also offers a link to show/hide the complete parameter list
Line 2279  sub assessparms { Line 2401  sub assessparms {
   
     &startpage($r,$pssymb);      &startpage($r,$pssymb);
   
     foreach ('tolerance','date_default','date_start','date_end',      foreach my $item ('tolerance','date_default','date_start','date_end',
         'date_interval','int','float','string') {                        'date_interval','int','float','string','string_lenient',
                         'string_examcode','string_deeplink','string_discussvote',
                         'string_useslots','string_problemstatus','string_ip',
                         'string_questiontype') {
         $r->print('<input type="hidden" value="'.          $r->print('<input type="hidden" value="'.
           &HTML::Entities::encode($env{'form.recent_'.$_},'"&<>').            &HTML::Entities::encode($env{'form.recent_'.$item},'"&<>').
           '" name="recent_'.$_.'" />');            '" name="recent_'.$item.'" />');
     }      }
   
     # ----- Start Parameter Selection      # ----- Start Parameter Selection
Line 2895  sub storedata { Line 3020  sub storedata {
     if ($key =~ /^form\.([a-z]+)\_(.+)$/) {      if ($key =~ /^form\.([a-z]+)\_(.+)$/) {
         my $cmd=$1;          my $cmd=$1;
         my $thiskey=$2;          my $thiskey=$2;
           next if ($cmd eq 'setipallow' || $cmd eq 'setipdeny');
         my ($tuname,$tudom)=&extractuser($thiskey);          my ($tuname,$tudom)=&extractuser($thiskey);
         my $tkey=$thiskey;          my $tkey=$thiskey;
             if ($tuname) {              if ($tuname) {
Line 3225  sub listdata { Line 3351  sub listdata {
               );                );
             }              }
         } elsif ($thistype eq 'date_interval') {          } elsif ($thistype eq 'date_interval') {
             $r->print(&date_interval_selector($thiskey,              $r->print(&date_interval_selector($thiskey,$name,
                       $$resourcedata{$thiskey},$readonly));                        $$resourcedata{$thiskey},$readonly));
         } elsif ($thistype =~ m/^string/) {          } elsif ($thistype =~ m/^string/) {
             $r->print(&string_selector($thistype,$thiskey,              $r->print(&string_selector($thistype,$thiskey,
Line 3245  sub listdata { Line 3371  sub listdata {
   
   
 sub date_interval_selector {  sub date_interval_selector {
     my ($thiskey, $showval, $readonly) = @_;      my ($thiskey, $pname, $showval, $readonly) = @_;
     my $result;      my ($result,%skipval);
       my $currval = $showval;
     foreach my $which (['days', 86400, 31],      foreach my $which (['days', 86400, 31],
                ['hours', 3600, 23],                 ['hours', 3600, 23],
                ['minutes', 60, 59],                 ['minutes', 60, 59],
Line 3260  sub date_interval_selector { Line 3387  sub date_interval_selector {
                            \%select,'',$readonly);                             \%select,'',$readonly);
     $result .= ' '.&mt($name);      $result .= ' '.&mt($name);
     }      }
       if ($pname eq 'interval') {
           unless ($skipval{'done'}) {
               my $checkedon = '';
               my $checkedproc = '';
               my $currproctorkey = '';
               my $currprocdisplay = 'hidden';
               my $currdonetext = &mt('Done');
               my $checkedoff = ' checked="checked"';
               if ($currval =~ /^(?:\d+)_done$/) {
                   $checkedon = ' checked="checked"';
                   $checkedoff = '';
               } elsif ($currval =~ /^(?:\d+)_done\:([^\:]+)\:$/) {
                   $currdonetext = $1;
                   $checkedon = ' checked="checked"';
                   $checkedoff = '';
               } elsif ($currval =~ /^(?:\d+)_done_proctor_(.+)$/) {
                   $currproctorkey = $1;
                   $checkedproc = ' checked="checked"';
                   $checkedoff = '';
                   $currprocdisplay = 'text';
               } elsif ($currval =~ /^(?:\d+)_done\:([^\:]+)\:_proctor_(.+)$/) {
                   $currdonetext = $1;
                   $currproctorkey = $2;
                   $checkedproc = ' checked="checked"';
                   $checkedoff = '';
                   $currprocdisplay = 'text';
               }
               my $onclick = ' onclick="toggleSecret(this.form,'."'done_','$thiskey'".');"';
               my $disabled;
               if ($readonly) {
                   $disabled = ' disabled="disabled"';
               }
               $result .= '<br /><span class="LC_nobreak">'.&mt('Include "done" button').
                          '<label><input type="radio" value="" name="done_'.$thiskey.'"'.$checkedoff.$onclick.$disabled.' />'.
                          &mt('No').'</label>'.('&nbsp;'x2).
                          '<label><input type="radio" value="_done" name="done_'.$thiskey.'"'.$checkedon.$onclick.$disabled.' />'.
                          &mt('Yes').'</label>'.('&nbsp;'x2).
                          '<label><input type="radio" value="_done_proctor" name="done_'.$thiskey.'"'.$checkedproc.$onclick.$disabled.' />'.
                          &mt('Yes, with proctor key').'</label>'.
                          '<input type="'.$currprocdisplay.'" id="done_'.$thiskey.'_proctorkey" '.
                          'name="done_'.$thiskey.'_proctorkey" value="'.&HTML::Entities::encode($currproctorkey,'"<>&').'"'.$disabled.' /></span><br />'.
                          '<span class="LC_nobreak">'.&mt('Button text').': '.
                          '<input type="text" name="done_'.$thiskey.'_buttontext" value="'.&HTML::Entities::encode($currdonetext,'"<>&').'"'.$disabled.' /></span>';
           }
       }
     unless ($readonly) {      unless ($readonly) {
         $result .= '<input type="hidden" name="dateinterval_'.$thiskey.'" />';          $result .= '<input type="hidden" name="dateinterval_'.$thiskey.'" />';
     }      }
Line 3292  sub default_selector { Line 3464  sub default_selector {
     return '<input type="text" name="set_'.$thiskey.'" value="'.$showval.'"'.$disabled.' />';      return '<input type="text" name="set_'.$thiskey.'" value="'.$showval.'"'.$disabled.' />';
 }  }
   
   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".'<button class="LC_add_ipacc_button">'.&mt('Add more').'</button>';
       }
       my $output = '<input type="hidden" name="set_'.$thiskey.'" />
   <table><tr><th>'.&mt('Allow from').'</th><th>'.&mt('Deny from').'</th></tr><tr>';
       foreach my $acctype ('allow','deny') {
           $output .= '
   <td valign="top">
   <div class="LC_string_ipacc_wrap" id="LC_string_ipacc_'.$acctype.'_'.$thiskey.'">
     <div class="LC_string_ipacc_inner">'."\n";
           my $num = 0;
           foreach my $curr (@{$access{$acctype}}) {
               $output .= '<div><input type="text" name="setip'.$acctype.'_'.$thiskey.'" value="'.$curr.'"'.$disabled.' />';
               if ($num > 0) {
                   $output .= '<a href="#" class="LC_remove_ipacc">'.&mt('Remove').'</a>';
               }
               $output .= '</div>'."\n";
               $num ++;
           }
           $output .= '
     </div>'.$addmore.'
   </div>
   </td>';
      }
      $output .= '
   </tr>
   </table>'."\n";
       return $output;
   }
   
   {
   
 my %strings =  my %strings =
     (      (
      'string_yesno'       'string_yesno'
Line 3319  my %strings = Line 3553  my %strings =
              => [['yes','Yes'],               => [['yes','Yes'],
                  ['notended','Yes, unless discussion ended'],                   ['notended','Yes, unless discussion ended'],
                  ['no','No']],                   ['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 {  sub standard_string_options {
Line 3359  sub string_selector { Line 3596  sub string_selector {
             }              }
         }          }
     }      }
   
       if ($thistype eq 'string_ip') {
           return &string_ip_selector($thiskey,$showval,$readonly);
       }
     
     my ($result,$disabled);      my ($result,$disabled);
   
Line 3413  sub string_selector { Line 3654  sub string_selector {
     return $result;      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 '<p class="LC_warning">'.
              &mt('[_1] was [_2]not[_3] set to [_4].',
                  $standard_name,'<b>','</b>','"'.$desc.'"').'<br />'.
              &mt('LON-CAPA version ([_1]) installed on home server ([_2]) does not meet version requirements ([_3] or newer).',
              $cmajor.'.'.$cminor,$chostname,
              $needsrelease).
              '</p>';
   }
   
   }
   
 #  #
 # Shift all start and end dates by $shift  # Shift all start and end dates by $shift
 #  #
Line 3469  sub newoverview { Line 3759  sub newoverview {
 '.  '.
             &Apache::lonhtmlcommon::resize_scrollbox_js('params')."\n".              &Apache::lonhtmlcommon::resize_scrollbox_js('params')."\n".
             &showhide_js()."\n".              &showhide_js()."\n".
               &done_proctor_js()."\n".
 '// ]]>  '// ]]>
 </script>  </script>
 ';  ';
Line 3658  sub overview { Line 3949  sub overview {
     my ($r,$parm_permission) = @_;      my ($r,$parm_permission) = @_;
     my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};      my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
     my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};      my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
       my $crstype = $env{'course.'.$env{'request.course.id'}.'.type'};
       my $js = '<script type="text/javascript">'."\n".
                '// <![CDATA['."\n".
                &done_proctor_js()."\n".
                '// ]]>'."\n".
                '</script>'."\n";
     my $readonly = 1;      my $readonly = 1;
     if ($parm_permission->{'edit'}) {      if ($parm_permission->{'edit'}) {
         undef($readonly);          undef($readonly);
     }      }
     &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=setoverview',      &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=setoverview',
     text=>"Overview Mode"});      text=>"Overview Mode"});
     my $start_page=&Apache::loncommon::start_page('Modify Parameters');      my $start_page=&Apache::loncommon::start_page('Modify Parameters',$js);
     my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs('Overview');      my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs('Overview');
     $r->print($start_page.$breadcrumbs);      $r->print($start_page.$breadcrumbs);
     $r->print('<form method="post" action="/adm/parmset?action=setoverview" name="parmform">');      $r->print('<form method="post" action="/adm/parmset?action=setoverview" name="parmform">');
Line 4909  sub parameter_releasecheck { Line 5206  sub parameter_releasecheck {
     return $needsnewer;      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 '<p class="LC_warning">'.  
            &mt('[_1] was [_2]not[_3] set to [_4].',  
                $standard_name,'<b>','</b>','"'.$desc.'"').'<br />'.  
            &mt('LON-CAPA version ([_1]) installed on home server ([_2]) does not meet version requirements ([_3] or newer).',  
            $cmajor.'.'.$cminor,$chostname,  
            $needsrelease).  
            '</p>';  
 }  
   
 sub get_permission {  sub get_permission {
     my %permission;      my %permission;
     my $allowed = 0;      my $allowed = 0;

Removed from v.1.522.2.26  
changed lines
  Added in v.1.522.2.26.2.1


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>