Diff for /loncom/interface/lonhtmlcommon.pm between versions 1.374 and 1.392

version 1.374, 2016/10/16 21:20:51 version 1.392, 2018/04/14 02:29:44
Line 78  sub java_not_enabled { Line 78  sub java_not_enabled {
 sub coursepreflink {  sub coursepreflink {
    my ($text,$category)=@_;     my ($text,$category)=@_;
    if (&Apache::lonnet::allowed('opa',$env{'request.course.id'})) {     if (&Apache::lonnet::allowed('opa',$env{'request.course.id'})) {
       return '<a target="_top" href="'.&HTML::Entities::encode("/adm/courseprefs?phase=display&actions=$category",'<>&"').'"><span class="LC_setting">'.$text.'</span></a>';         my $target =' target="_top"';
          if (($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) {
              $target ='';
          }
          return '<a'.$target.' href="'.&HTML::Entities::encode("/adm/courseprefs?phase=display&actions=$category",'<>&"').'"><span class="LC_setting">'.$text.'</span></a>';
    } else {     } else {
       return '';        return '';
    }     }
Line 92  sub raw_href_to_link { Line 96  sub raw_href_to_link {
   
 sub entity_encode {  sub entity_encode {
     my ($text)=@_;      my ($text)=@_;
     return &HTML::Entities::encode($text, '<>&"');      return &HTML::Entities::encode($text, '\'<>&"');
 }  }
   
 sub direct_parm_link {  sub direct_parm_link {
Line 407  sub textbox { Line 411  sub textbox {
 ##############################################  ##############################################
 ##############################################  ##############################################
 sub checkbox {  sub checkbox {
     my ($name,$checked,$value) = @_;      my ($name,$checked,$value,$special) = @_;
     my $Str = '<input type="checkbox" name="'.$name.'" ';      my $Str = '<input type="checkbox" name="'.$name.'" ';
     if (defined($value)) {      if (defined($value)) {
         $Str .= 'value="'.$value.'"';          $Str .= 'value="'.$value.'"';
Line 415  sub checkbox { Line 419  sub checkbox {
     if ($checked) {      if ($checked) {
         $Str .= ' checked="checked"';          $Str .= ' checked="checked"';
     }      }
     $Str .= ' />';      $Str .= $special.' />';
     return $Str;      return $Str;
 }  }
   
Line 1025  data structure used for bookkeeping. Line 1029  data structure used for bookkeeping.
   
 =item $number_to_do The total number of items being processed.  =item $number_to_do The total number of items being processed.
   
   =item $preamble Optional HTML to display before the progress bar.
   
 =back  =back
   
 =back  =back
   
 Returns a hash containing the progress state data structure.  Returns a hash containing the progress state data structure.
   If $number_to_do is zero or null, an indeterminate progress bar will
   be used.
   
 =item &Update_PrgWin()  =item &Update_PrgWin()
   
Line 1118  Returns: none Line 1126  Returns: none
   
 # Create progress  # Create progress
 sub Create_PrgWin {  sub Create_PrgWin {
     my ($r,$number_to_do)=@_;      my ($r,$number_to_do,$preamble)=@_;
     my %prog_state;      my %prog_state;
     $prog_state{'done'}=0;      $prog_state{'done'}=0;
     $prog_state{'firststart'}=&Time::HiRes::time();      $prog_state{'firststart'}=&Time::HiRes::time();
     $prog_state{'laststart'}=&Time::HiRes::time();      $prog_state{'laststart'}=&Time::HiRes::time();
     $prog_state{'max'}=$number_to_do;      $prog_state{'max'}=$number_to_do;
     &Apache::loncommon::LCprogressbar($r);       &Apache::loncommon::LCprogressbar($r,$prog_state{'max'},$preamble); 
     return %prog_state;      return %prog_state;
 }  }
   
 # update progress  # update progress
 sub Update_PrgWin {  sub Update_PrgWin {
     my ($r,$prog_state,$displayString)=@_;      my ($r,$prog_state,$displayString)=@_;
     &Apache::loncommon::LCprogressbarUpdate($r,undef,$displayString);      &Apache::loncommon::LCprogressbarUpdate($r,undef,$displayString,$$prog_state{'max'});
     $$prog_state{'laststart'}=&Time::HiRes::time();      $$prog_state{'laststart'}=&Time::HiRes::time();
 }  }
   
Line 1181  sub Increment_PrgWin { Line 1189  sub Increment_PrgWin {
     if ($$prog_state{'max'}) {      if ($$prog_state{'max'}) {
        $percent=int(100.*$current/$$prog_state{'max'});         $percent=int(100.*$current/$$prog_state{'max'});
     }      }
     &Apache::loncommon::LCprogressbarUpdate($r,$percent,$timeinfo);      &Apache::loncommon::LCprogressbarUpdate($r,$percent,$timeinfo,$$prog_state{'max'});
     $$prog_state{'laststart'}=&Time::HiRes::time();      $$prog_state{'laststart'}=&Time::HiRes::time();
 }  }
   
Line 1198  sub Close_PrgWin { Line 1206  sub Close_PrgWin {
 sub crumbs {  sub crumbs {
     my ($uri,$target,$prefix,$form,$skiplast,$onclick)=@_;      my ($uri,$target,$prefix,$form,$skiplast,$onclick)=@_;
 # You cannot crumbnify uploaded or adm resources  # You cannot crumbnify uploaded or adm resources
     if ($uri=~/^\/*(uploaded|adm)\//) { return &mt('(Internal Course/Group Content)'); }      if ($uri=~/^\/*(uploaded|adm)\//) { return &mt('(Internal Course/Community Content)'); }
     if ($target) {      if ($target) {
         $target = ' target="'.          $target = ' target="'.
                   &Apache::loncommon::escape_single($target).'"';                    &Apache::loncommon::escape_single($target).'"';
Line 1218  sub crumbs { Line 1226  sub crumbs {
             } else {              } else {
                 $path.='/';                   $path.='/'; 
             }              }
               if ($path eq '/res/') {
                   unless (&Apache::lonnet::allowed('bre',$path)) {
                       $output.="$dir/";
                       next;
                   }
               }
             my $href_path = &HTML::Entities::encode($path,'<>&"');              my $href_path = &HTML::Entities::encode($path,'<>&"');
             &Apache::loncommon::inhibit_menu_check(\$href_path);              &Apache::loncommon::inhibit_menu_check(\$href_path);
             if ($form) {              if ($form) {
Line 1295  sub htmlareaheaders { Line 1309  sub htmlareaheaders {
 ENDEDITOR  ENDEDITOR
  }   }
     $s.=(<<ENDJQUERY);      $s.=(<<ENDJQUERY);
 <script type="text/javascript" src="/adm/jQuery/js/jquery-1.11.3.min.js"></script>  <script type="text/javascript" src="/adm/jQuery/js/jquery-3.2.1.min.js"></script>
 <script type="text/javascript" src="/adm/jQuery/js/jquery-ui-1.11.4.custom.min.js"></script>  <script type="text/javascript" src="/adm/jQuery/js/jquery-ui-1.12.1.custom.min.js"></script>
 <link rel="stylesheet" type="text/css" href="/adm/jQuery/css/smoothness/jquery-ui-1.11.4.custom.css" />  <link rel="stylesheet" type="text/css" href="/adm/jQuery/css/smoothness/jquery-ui-1.12.1.custom.min.css" />
 <script type="text/javascript" src="/adm/jpicker/js/jpicker-1.1.6.min.js" >  <script type="text/javascript" src="/adm/jpicker/js/jpicker-1.1.6.min.js" >
 </script>  </script>
 <link rel="stylesheet" type="text/css" href="/adm/jpicker/css/jPicker-1.1.6.min.css" />  <link rel="stylesheet" type="text/css" href="/adm/jpicker/css/jPicker-1.1.6.min.css" />
Line 1334  $(document).ready(function(){ Line 1348  $(document).ready(function(){
 });';  });';
 }  }
   
   sub countdown {
   
       # Code to put a due date countdown in 'duedatecountdown' span.
       # This is currently located in the breadcrumb headers.
       # note that the dueDateLayout is internatinoalized below.
       # Here document is used to support the substitution into the javascript below.
       # ..which unforunately necessitates escaping the $'s in the javascript.
       # There are several times of importance
       #
       # serverDueDate -  The absolute time at which the problem expires.
       # serverTime    -  The server's time when the problem finished computing.
       # clientTime    -  The client's time...as close to serverTime as possible.
       #                  The clientTime will be slightly later due to
       #                  1. The latency between problem computation and
       #                     the first network action.
       #                  2. The time required between the page load-start and the actual
       #                     initial javascript execution that got clientTime.
       # These are used as follows:
       #   The difference between clientTime and serverTime are used to
       #   correct for differences in clock settings between the browser's system and the
       #   server's.
       #
       #   The difference between clientTime and the time at which the ready() method
       #   starts executing is used to estimate latencies for page load and submission.
       #   Since this is an estimate, it is doubled.  The latency estimate + one minute
       #   is used to determine when the countdown timer turns red to warn the user
       #   to think about submitting.
   
   
       my $dueDateLayout = &mt('Due in: {dn} {dl} {hnn}{sep}{mnn}{sep}{snn} [_1]',
                               "<span id='submitearly'></span>");
       my $early = '- <b>'.&mt('Submit Early').'</b>';
       my $pastdue = '- <b>'.&mt('Past Due').'</b>';
       return <<"JAVASCRIPT";
   
       var documentReadyTime;
   
   \$(document).ready(function() {
      if (typeof(dueDate) != "undefined") {
          documentReadyTime = (new Date()).getTime();
         \$("#duedatecountdown").countdown({until: dueDate, compact: true,
            layout: "$dueDateLayout",
            onTick: function (periods) {
               var latencyEstimate = (documentReadyTime - clientTime) * 2;
               if(\$.countdown.periodsToSeconds(periods) < (300 + latencyEstimate)) {
                  \$("#submitearly").html("$early");
                  if (\$.countdown.periodsToSeconds(periods) < 1) {
                       \$("#submitearly").html("$pastdue");
                  }
               }
               if(\$.countdown.periodsToSeconds(periods) < (60 + latencyEstimate)) {
                  \$(this).css("color", "red");   //Highlight last minute.
               }
            }
         });
      }
   });
   
   JAVASCRIPT
   
   }
   
 # ----------------------------------------- Script to activate only some fields  # ----------------------------------------- Script to activate only some fields
   
 sub htmlareaselectactive {  sub htmlareaselectactive {
Line 1557  sub htmlareaselectactive { Line 1633  sub htmlareaselectactive {
   
  });   });
 ';  ';
     $output .= &color_picker;      $output .= &color_picker();
   
     # Code to put a due date countdown in 'duedatecountdown' span.      $output .= &countdown();
     # This is currently located in the breadcrumb headers.  
     # note that the dueDateLayout is internatinoalized below.  
     # Here document is used to support the substitution into the javascript below.  
     # ..which unforunately necessitates escaping the $'s in the javascript.  
     # There are several times of importance  
     #  
     # serverDueDate -  The absolute time at which the problem expires.  
     # serverTime    -  The server's time when the problem finished computing.  
     # clientTime    -  The client's time...as close to serverTime as possible.  
     #                  The clientTime will be slightly later due to  
     #                  1. The latency between problem computation and   
     #                     the first network action.  
     #                  2. The time required between the page load-start and the actual  
     #                     initial javascript execution that got clientTime.  
     # These are used as follows:  
     #   The difference between clientTime and serverTime are used to   
     #   correct for differences in clock settings between the browser's system and the  
     #   server's.  
     #  
     #   The difference between clientTime and the time at which the ready() method  
     #   starts executing is used to estimate latencies for page load and submission.  
     #   Since this is an estimate, it is doubled.  The latency estimate + one minute  
     #   is used to determine when the countdown timer turns red to warn the user  
     #   to think about submitting.  
   
     my $dueDateLayout = &mt('Due in: {dn} {dl} {hnn}{sep}{mnn}{sep}{snn} [_1]',  
                             "<span id='submitearly'></span>");  
     my $early = '- <b>'.&mt('Submit Early').'</b>';  
     my $pastdue = '- <b>'.&mt('Past Due').'</b>';  
     $output .= <<JAVASCRIPT;  
   
     var documentReadyTime;      $output .= <<"JAVASCRIPT";
   
 \$(document).ready(function() {  
    if (typeof(dueDate) != "undefined") {  
        documentReadyTime = (new Date()).getTime();  
       \$("#duedatecountdown").countdown({until: dueDate, compact: true,   
          layout: "$dueDateLayout",  
          onTick: function (periods) {  
     var latencyEstimate = (documentReadyTime - clientTime) * 2;  
             if(\$.countdown.periodsToSeconds(periods) < (300 + latencyEstimate)) {  
                \$("#submitearly").html("$early");  
                if (\$.countdown.periodsToSeconds(periods) < 1) {  
                     \$("#submitearly").html("$pastdue");  
                }  
             }  
             if(\$.countdown.periodsToSeconds(periods) < (60 + latencyEstimate)) {  
                \$(this).css("color", "red");   //Highlight last minute.  
             }  
          }  
       });  
    }  
 });  
   
     /* This code describes the spellcheck options that will be used for      /* This code describes the spellcheck options that will be used for
        items with class 'spellchecked'.  It is necessary for those objects'         items with class 'spellchecked'.  It is necessary for those objects'
Line 1721  sub show_return_link { Line 1746  sub show_return_link {
             (($env{'request.noversionuri'}=~/^\/adm\//) &&              (($env{'request.noversionuri'}=~/^\/adm\//) &&
              ($env{'request.noversionuri'}!~/^\/adm\/wrapper\//) &&               ($env{'request.noversionuri'}!~/^\/adm\/wrapper\//) &&
              ($env{'request.noversionuri'}!~               ($env{'request.noversionuri'}!~
               m{^/adm/.*/(smppg|bulletinboard|exttools?)($|\?)})                m{^/adm/.*/(smppg|bulletinboard|ext\.tool)($|\?)})
            ));             ));
 }  }
   
Line 1886  returns: nothing Line 1911  returns: nothing
         #          #
         # The first one should be the course or a menu link          # The first one should be the course or a menu link
         if (!defined($menulink)) { $menulink=1; }          if (!defined($menulink)) { $menulink=1; }
         if ((($crstype eq 'Placement') || (($env{'request.course.id'}) &&  
             ($env{'course.'.$env{'request.course.id'}.'.type'} eq 'Placement'))) &&  
             (!$env{'request.role.adv'})) {  
             undef($menulink);  
         }  
         if ($menulink) {          if ($menulink) {
             my $description = 'Menu';              my $description = 'Menu';
             my $no_mt_descr = 0;              my $no_mt_descr = 0;
Line 1901  returns: nothing Line 1921  returns: nothing
                     $env{'course.'.$env{'request.course.id'}.'.description'};                      $env{'course.'.$env{'request.course.id'}.'.description'};
                 $no_mt_descr = 1;                  $no_mt_descr = 1;
                 if ($env{'request.noversionuri'} =~                   if ($env{'request.noversionuri'} =~ 
                     m{^/public/($match_domain)/($match_courseid)/syllabus$}) {                      m{^/?public/($match_domain)/($match_courseid)/syllabus$}) {
                     unless (($env{'course.'.$env{'request.course.id'}.'.domain'} eq $1) &&                      unless (($env{'course.'.$env{'request.course.id'}.'.domain'} eq $1) &&
                             ($env{'course.'.$env{'request.course.id'}.'.num'} eq $2)) {                              ($env{'course.'.$env{'request.course.id'}.'.num'} eq $2)) {
                         $description = 'Menu';                          $description = 'Menu';
Line 1909  returns: nothing Line 1929  returns: nothing
                     }                      }
                 }                  }
             }              }
               my $target;
               unless (($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) {
                   $target='_top';
               }
             $menulink =  {  href   =>'/adm/menu',              $menulink =  {  href   =>'/adm/menu',
                             title  =>'Go to main menu',                              title  =>'Go to main menu',
                             target =>'_top',                              target =>$target,
                             text   =>$description,                              text   =>$description,
                             no_mt  =>$no_mt_descr, };                              no_mt  =>$no_mt_descr, };
             if($last) {              if($last) {
Line 2200  sub docs_breadcrumbs { Line 2224  sub docs_breadcrumbs {
         my $foldername=shift(@folders);          my $foldername=shift(@folders);
         if ($folderpath) {$folderpath.='&';}          if ($folderpath) {$folderpath.='&';}
         $folderpath.=$folder.'&'.$foldername;          $folderpath.=$folder.'&'.$foldername;
         my $url;          my $url = $env{'request.use_absolute'};
         if ($allowed) {          if ($allowed) {
             $url = '/adm/coursedocs?folderpath=';              $url .= '/adm/coursedocs?folderpath=';
         } else {          } else {
             $url = '/adm/supplemental?folderpath=';              $url .= '/adm/supplemental?folderpath=';
         }          }
         $url .= &escape($folderpath);          $url .= &escape($folderpath);
         my $name=&unescape($foldername);          my $name=&unescape($foldername);
Line 3476  function go(url) { Line 3500  function go(url) {
    if (url!='' && url!= null) {     if (url!='' && url!= null) {
        currentURL = null;         currentURL = null;
        currentSymb= null;         currentSymb= null;
        window.location.href=url;         var lcHostname = setLCHost();
          window.location.href=lcHostname+url;
    }     }
 }  }
   
Line 3495  ENDUTILITY Line 3520  ENDUTILITY
   
 sub jump_to_editres {  sub jump_to_editres {
     my ($cfile,$home,$switchserver,$forceedit,$forcereg,$symb,$folderpath,      my ($cfile,$home,$switchserver,$forceedit,$forcereg,$symb,$folderpath,
         $title,$idx,$suppurl,$todocs) = @_;          $title,$hostname,$idx,$suppurl,$todocs,$suppanchor) = @_;
     my $jscall;      my ($jscall,$anchor,$usehttp,$usehttps,$is_ext);
     if ($switchserver) {      if ($switchserver) {
         if ($home) {          if ($home) {
             $cfile = '/adm/switchserver?otherserver='.$home.'&amp;role='.              $cfile = '/adm/switchserver?otherserver='.$home.'&amp;role='.
Line 3516  sub jump_to_editres { Line 3541  sub jump_to_editres {
         }          }
     } else {      } else {
         unless ($cfile =~ m{^/priv/}) {          unless ($cfile =~ m{^/priv/}) {
               if ($cfile =~ m{^(/adm/wrapper/ext/([^#]+))#([^#]+)$}) {
                   $cfile = $1;
                   my $extlink = $2;
                   $anchor = $3;
                   $is_ext = 1;
                   if (($extlink !~ /^https:/) && ($ENV{'SERVER_PORT'} == 443)) {
                       $usehttp = 1;
                   } elsif ($env{'request.use_absolute'}) {
                       if ($env{'request.use_absolute'} =~ m{^https://}) {
                           $usehttps = 1;
                       }
                   } 
               } elsif ($cfile =~ m{^/?public/($match_domain)/($match_courseid)/syllabus}) {
                   if ($ENV{'SERVER_PORT'} == 443) {
                       my ($cdom,$cnum) = ($1,$2);
                       if (($env{'request.course.id'}) &&
                           ($env{'course.'.$env{'request.course.id'}.'.num'} eq $cnum) &&
                           ($env{'course.'.$env{'request.course.id'}.'.domain'} eq $cdom)) {
                           if ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://}) {
                               $usehttp = 1;
                           }
                       }
                   } elsif ($env{'request.use_absolute'}) {
                       if ($env{'request.use_absolute'} =~ m{^https://}) {
                           $usehttps = 1;
                       }
                   }
               }
             if ($symb) {              if ($symb) {
                   if ($anchor ne '') {
                       if ($symb =~ m{^([^#]+)\Q#$anchor\E$}) {
                           $symb = $1.&escape(&escape('#')).$anchor;
                       }
                   }
                 $cfile .= (($cfile=~/\?/)?'&amp;':'?')."symb=$symb";                  $cfile .= (($cfile=~/\?/)?'&amp;':'?')."symb=$symb";
             } elsif ($folderpath) {              } elsif ($folderpath) {
                 $cfile .= (($cfile=~/\?/)?'&amp;':'?').                  $cfile .= (($cfile=~/\?/)?'&amp;':'?').
Line 3535  sub jump_to_editres { Line 3593  sub jump_to_editres {
             }              }
             if ($forceedit) {              if ($forceedit) {
                 $cfile .= (($cfile=~/\?/)?'&amp;':'?').'forceedit=1';                  $cfile .= (($cfile=~/\?/)?'&amp;':'?').'forceedit=1';
                   if ($usehttps) {
                       $cfile = $env{'request.use_absolute'}.(($cfile =~ /^\//)? '':'/').$cfile;
                   }
               } elsif ($usehttp) {
                   if ($hostname ne '') {
                       $cfile = 'http://'.$hostname.(($cfile =~ /^\//)? '':'/').$cfile;
                   }
                   unless ($is_ext) {
                       $cfile .= (($cfile=~/\?/)?'&amp;':'?').'usehttp=1';
                   }
               } elsif ($usehttps) {
                   $cfile = $env{'request.use_absolute'}.(($cfile =~ /^\//)? '':'/').$cfile;
             }              }
             if ($forcereg) {              if ($forcereg) {
                 $cfile .= (($cfile=~/\?/)?'&amp;':'?').'register=1';                  $cfile .= (($cfile=~/\?/)?'&amp;':'?').'register=1';
             }              }
             if ($todocs) {              if ($todocs) {
                $cfile .= (($cfile=~/\?/)?'&amp;':'?').'todocs=1';                  $cfile .= (($cfile=~/\?/)?'&amp;':'?').'todocs=1';
             }              }
               if ($suppanchor ne '') {
                   $cfile .= (($cfile=~/\?/)?'&amp;':'?').'anchor='.
                             &HTML::Entities::encode($suppanchor,'"<>&');
               }
           }
           if ($anchor ne '') {
               $cfile .= '#'.$anchor;
         }          }
         $jscall = "go('".&Apache::loncommon::escape_single($cfile)."')";          $jscall = "go('".&Apache::loncommon::escape_single($cfile)."')";
     }      }
Line 3554  sub jump_to_editres { Line 3631  sub jump_to_editres {
 # javascript_valid_email  # javascript_valid_email
 #  #
 # Generates javascript to validate an e-mail address.  # Generates javascript to validate an e-mail address.
 # Returns a javascript function which accetps a form field as argumnent, and  # Returns a javascript function which accepts a form field as argument, and
 # returns false if field.value does not satisfy two regular expression matches  # returns false if field.value does not satisfy two regular expression matches
 # for a valid e-mail address.  Backwards compatible with old browsers without  # for a valid e-mail address.  Backwards compatible with old browsers without
 # support for javascript RegExp (just checks for @ in field.value in this case).   # support for javascript RegExp (just checks for @ in field.value in this case). 
   
 sub javascript_valid_email {  sub javascript_valid_email {
     my $scripttag .= <<'END';      my $scripttag .= <<'END';
 function validmail(field) {  function validmail(field,suffix) {
     var str = field.value;      var str = field.value;
       if (suffix != '' && suffix != undefined) {
           str += suffix;
       }
     if (window.RegExp) {      if (window.RegExp) {
         var reg1str = "(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)";          var reg1str = "(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)";
         var reg2str = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$"; //"          var reg2str = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$"; //"

Removed from v.1.374  
changed lines
  Added in v.1.392


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