Diff for /loncom/interface/loncommon.pm between versions 1.315 and 1.329

version 1.315, 2006/03/21 16:32:50 version 1.329, 2006/04/10 19:54:54
Line 58  use strict; Line 58  use strict;
 use Apache::lonnet;  use Apache::lonnet;
 use GDBM_File;  use GDBM_File;
 use POSIX qw(strftime mktime);  use POSIX qw(strftime mktime);
 use Apache::Constants qw(:common :http :methods);  
 use Apache::lonmenu();  use Apache::lonmenu();
 use Apache::lonlocal;  use Apache::lonlocal;
 use HTML::Entities;  use HTML::Entities;
Line 2737  Inputs: Line 2736  Inputs:
 =item * $forcereg, if page should register as content page (relevant for   =item * $forcereg, if page should register as content page (relevant for 
             text interface only)              text interface only)
   
 =item * $customtitle, overrides the $title in some way ????  =item * $customtitle, alternate text to use instead of $title
                         in the title box that appears, this text
                         is not auto translated like the $title is
   
 =item * $notopbar, if true, keep the 'what is this' info but remove the  =item * $notopbar, if true, keep the 'what is this' info but remove the
                    navigational links                     navigational links
   
   =item * $bgcolor, used to override the bg coor on a webpage to a specific value
   
 =back  =back
   
 Returns: A uniform header for LON-CAPA web pages.    Returns: A uniform header for LON-CAPA web pages.  
Line 2764  sub bodytag { Line 2768  sub bodytag {
     my $vlink=&designparm($function.'.vlink',$domain);      my $vlink=&designparm($function.'.vlink',$domain);
     my $sidebg=&designparm($function.'.sidebg',$domain);      my $sidebg=&designparm($function.'.sidebg',$domain);
 # Accessibility font enhance  # Accessibility font enhance
     unless ($addentries) { $addentries=''; }  
     my $addstyle='';      my $addstyle='';
     if ($env{'browser.fontenhance'} eq 'on') {      if ($env{'browser.fontenhance'} eq 'on') {
  $addstyle=' font-size: x-large;';   $addstyle=' font-size: x-large;';
Line 2783  sub bodytag { Line 2786  sub bodytag {
 # Port for miniserver  # Port for miniserver
     my $lonhttpdPort=$Apache::lonnet::perlvar{'lonhttpdPort'};      my $lonhttpdPort=$Apache::lonnet::perlvar{'lonhttpdPort'};
     if (!defined($lonhttpdPort)) { $lonhttpdPort='8080'; }      if (!defined($lonhttpdPort)) { $lonhttpdPort='8080'; }
       my $extra_body_attr;
       if ($forcereg) {
    if (ref($addentries)) {
       $addentries->{'onload'}   = &Apache::lonmenu::loadevents().
    $addentries->{'onload'};
       $addentries->{'onunload'} = &Apache::lonmenu::unloadevents().
    $addentries->{'onunload'};
    } else {
       $extra_body_attr.=' onload="'.&Apache::lonmenu::loadevents().
    '" onunload="'.&Apache::lonmenu::unloadevents().'"';
    }
       }
       if (!ref($addentries)) {
    $extra_body_attr .= $addentries;
       } else {
    foreach my $attr (keys(%$addentries)) {
       $extra_body_attr .= " $attr=\"".$addentries->{$attr}.'" ';
    }
       }
   
 # construct main body tag  # construct main body tag
     my $bodytag = <<END;      my $bodytag = <<END;
 <style type="text/css">  <style type="text/css">
Line 2795  form, .inline { display: inline; } Line 2818  form, .inline { display: inline; }
 .filename {font-family: monospace;}  .filename {font-family: monospace;}
 </style>  </style>
 <body bgcolor="$pgbg" text="$font" alink="$alink" vlink="$vlink" link="$link"  <body bgcolor="$pgbg" text="$font" alink="$alink" vlink="$vlink" link="$link"
 style="margin-top: 0px;$addstyle" $addentries>  style="margin-top: 0px;$addstyle" $extra_body_attr>
 END  END
     &Apache::lontexconvert::jsMath_reset();      &Apache::lontexconvert::jsMath_reset();
     if ($env{'environment.texengine'} eq 'jsMath') {      if ($env{'environment.texengine'} eq 'jsMath' ||
    $env{'form.texengine'}        eq 'jsMath' ) {
  $bodytag.=&Apache::lontexconvert::jsMath_header();   $bodytag.=&Apache::lontexconvert::jsMath_header();
     }      }
   
Line 2973  Returns a uniform footer for LON-CAPA we Line 2997  Returns a uniform footer for LON-CAPA we
 Inputs: $title - optional title for the head  Inputs: $title - optional title for the head
         $head_extra - optional extra HTML to put inside the <head>          $head_extra - optional extra HTML to put inside the <head>
         $args - optional arguments          $args - optional arguments
               force_register - if is true call registerurl so the remote is 
                                informed
                                
             redirect - array ref of seconds before redirect occurs              redirect - array ref of seconds before redirect occurs
                                     url to redirect to                                      url to redirect to
                            (side effect of setting                              (side effect of setting 
Line 2989  sub headtag { Line 3016  sub headtag {
  '<head>'.   '<head>'.
  &Apache::lonxml::fontsettings().   &Apache::lonxml::fontsettings().
  &Apache::lonhtmlcommon::htmlareaheaders();   &Apache::lonhtmlcommon::htmlareaheaders();
       
       if ($args->{'force_register'}) {
    $result .= &Apache::lonmenu::registerurl(1);
       }
   
     if (ref($args->{'redirect'})) {      if (ref($args->{'redirect'})) {
  my ($time,$url) = @{$args->{'redirect'}};   my ($time,$url) = @{$args->{'redirect'}};
  $url = &Apache::lonenc::check_encrypt($url);   $url = &Apache::lonenc::check_encrypt($url);
  $env{'internal.head.redirect'} = $url;   $env{'internal.head.redirect'} = $url;
  $result.=<<ADDMETA   $result.=<<ADDMETA
 <meta http-equiv="pragma" content="no-cache" />  <meta http-equiv="pragma" content="no-cache" />
 <meta HTTP-EQUIV="Refresh" CONTENT="2; url=$url" />  <meta HTTP-EQUIV="Refresh" CONTENT="$time; url=$url" />
 ADDMETA  ADDMETA
     }      }
     if (!defined($title)) {      if (!defined($title)) {
Line 3004  ADDMETA Line 3035  ADDMETA
     }      }
           
     $result .= '<title> LON-CAPA '.&mt($title).'</title>'.$head_extra;      $result .= '<title> LON-CAPA '.&mt($title).'</title>'.$head_extra;
       
     return $result;      return $result;
 }  }
   
Line 3041  Inputs: $title - optional title for the Line 3071  Inputs: $title - optional title for the
 =cut  =cut
   
 sub head {  sub head {
     my ($title,$head_extra) = @_;      my ($title,$head_extra,$args) = @_;
     return &headtag($title,$head_extra).&endheadtag();      return &headtag($title,$head_extra,$args).&endheadtag();
 }  }
   
 =pod  =pod
Line 3056  Returns a complete <html> .. <body> sect Line 3086  Returns a complete <html> .. <body> sect
 Inputs: $title - optional title for the page  Inputs: $title - optional title for the page
         $head_extra - optional extra HTML to incude inside the <head>          $head_extra - optional extra HTML to incude inside the <head>
         $args - additional optional args supported are:          $args - additional optional args supported are:
                   only_body   -> is true will set &bodytag() onlybodytag arg on                    only_body      -> is true will set &bodytag() onlybodytag
                   no_nav_bar  -> is true will set &bodytag() notopbar arg on                                      arg on
                   add_entries -> additional attributes to add to the  <body>                    no_nav_bar     -> is true will set &bodytag() notopbar arg on
                   domain      -> force to color decorate a page for a                     add_entries    -> additional attributes to add to the  <body>
                                  specific domain                    domain         -> force to color decorate a page for a 
                   function    -> force usage of a specific rolish color scheme                                      specific domain
                   redirect    -> see &headtag()                    function       -> force usage of a specific rolish color
                   bgcolor     -> override the default page bg color                                      scheme
                  js_ready     -> return a string ready for being used in                     redirect       -> see &headtag()
                                  a javascript writeln                    bgcolor        -> override the default page bg color
                     js_ready       -> return a string ready for being used in 
                                       a javascript writeln
                     html_encode    -> return a string ready for being used in 
                                       a html attribute
                     force_register -> if is true will turn on the &bodytag()
                                       $forcereg arg
                     body_title     -> alternate text to use instead of $title
                                       in the title box that appears, this text
                                       is not auto translated like the $title is
   
 =back  =back
   
Line 3073  Inputs: $title - optional title for the Line 3112  Inputs: $title - optional title for the
   
 sub start_page {  sub start_page {
     my ($title,$head_extra,$args) = @_;      my ($title,$head_extra,$args) = @_;
       #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
     my %head_args;      my %head_args;
     if (defined($args->{'redirect'})) {      foreach my $arg ('redirect','force_register') {
  $head_args{'redirect'} = $args->{'redirect'};   if (defined($args->{$arg})) {
       $head_args{$arg} = $args->{$arg};
    }
     }      }
   
     $env{'internal.start_page'}++;      $env{'internal.start_page'}++;
     my $result =       my $result = 
  &Apache::lonxml::xmlbegin().   &Apache::lonxml::xmlbegin().
  &headtag($title,$head_extra,\%head_args).&endheadtag().   &headtag($title,$head_extra,\%head_args).&endheadtag().
  &bodytag($title, $args->{'function'}, $args->{'add_entries'},   &bodytag($title, 
  $args->{'only_body'},   $args->{'function'},       $args->{'add_entries'},
  undef,undef,undef,$args->{'no_nav_bar'},$args->{'bgcolor'});   $args->{'only_body'},      $args->{'domain'},
    $args->{'force_register'}, $args->{'body_title'},
    $args->{'no_nav_bar'},     $args->{'bgcolor'});
     if ($args->{'js_ready'}) {      if ($args->{'js_ready'}) {
  $result =~ s/[\n\r]/ /g;   $result = &js_ready($result);
  $result =~ s/'/\\'/g;      }
       if ($args->{'html_encode'}) {
    $result = &html_encode($result);
     }      }
     return $result;      return $result;
 }  }
Line 3102  Returns a complete </body></html> sectio Line 3149  Returns a complete </body></html> sectio
 Inputs:         $args - additional optional args supported are:  Inputs:         $args - additional optional args supported are:
                  js_ready     -> return a string ready for being used in                    js_ready     -> return a string ready for being used in 
                                  a javascript writeln                                   a javascript writeln
                    html_encode  -> return a string ready for being used in 
                                    a html attribute
 =back  =back
   
 =cut  =cut
   
 sub end_page {  sub end_page {
     my ($args) = @_;      my ($args) = @_;
       #&Apache::lonnet::logthis("end_page ".join(':',caller(0)));
     $env{'internal.end_page'}++;      $env{'internal.end_page'}++;
     my $result = &endbodytag()."\n</html>";      my $result = &endbodytag()."\n</html>";
     if ($args->{'js_ready'}) {      if ($args->{'js_ready'}) {
  $result =~ s/[\n\r]/ /g;   $result = &js_ready($result);
  $result =~ s/'/\\'/g;  
     }      }
       if ($args->{'html_encode'}) {
    $result = &html_encode($result);
       }
       return $result;
   }
   
   sub html_encode {
       my ($result) = @_;
   
       $result = &HTML::Entities::encode($result,'<>&"');
       
       return $result;
   }
   sub js_ready {
       my ($result) = @_;
   
       $result =~ s/[\n\r]/ /xmsg;
       $result =~ s/\\/\\\\/xmsg;
       $result =~ s/'/\\'/xmsg;
       $result =~ s{</script>}{</scrip'+'t>}xmsg;
       
     return $result;      return $result;
 }  }
   
 sub validate_page {  sub validate_page {
     if (  exists($env{'internal.start_page'})      if (  exists($env{'internal.start_page'})
   &&    $env{'internal.start_page'} > 1) {    &&     $env{'internal.start_page'} > 1) {
  &Apache::lonnet::logthis('start_page called multiple times');   &Apache::lonnet::logthis('start_page called multiple times '.
    $env{'internal.start_page'}.' '.
    $ENV{'request.filename'});
     }      }
     if (  exists($env{'internal.end_page'})      if (  exists($env{'internal.end_page'})
   &&    $env{'internal.end_page'} > 1) {    &&     $env{'internal.end_page'} > 1) {
  &Apache::lonnet::logthis('end_page called multiple times');   &Apache::lonnet::logthis('end_page called multiple times '.
    $env{'internal.end_page'}.' '.
    $env{'request.filename'});
     }      }
     if (     exists($env{'internal.start_page'})      if (     exists($env{'internal.start_page'})
  && ! exists($env{'internal.end_page'})) {   && ! exists($env{'internal.end_page'})) {
  &Apache::lonnet::logthis('start_page called without end_page');   &Apache::lonnet::logthis('start_page called without end_page '.
    $env{'request.filename'});
     }      }
     if (   ! exists($env{'internal.start_page'})      if (   ! exists($env{'internal.start_page'})
  &&   exists($env{'internal.end_page'})) {   &&   exists($env{'internal.end_page'})) {
  &Apache::lonnet::logthis('end_page called without start_page');   &Apache::lonnet::logthis('end_page called without start_page'.
    $env{'request.filename'});
     }      }
 }  }
   
   sub simple_error_page {
       my ($r,$title,$msg) = @_;
       my $page =
    &Apache::loncommon::start_page($title).
    &mt($msg).
    &Apache::loncommon::end_page();
       if (ref($r)) {
    $r->print($page);
    return;
       }
       return $page;
   }
 ###############################################  ###############################################
   
 =pod  =pod
Line 3620  sub get_posted_cgi { Line 3708  sub get_posted_cgi {
     }      }
  }   }
     }      }
   #
   # Digested POSTed values
   #
   # Remember the way this was originally done (GET or POST)
   #
     $env{'request.method'}=$ENV{'REQUEST_METHOD'};      $env{'request.method'}=$ENV{'REQUEST_METHOD'};
     $r->method_number(M_GET);  #
   # There may also be stuff in the query string
   # Tell subsequent handlers that this was GET, not POST, so they can access query string.
   # Also, unset POSTed content length to cover all tracks.
   #
   
   # This does not work, because M_GET is not defined (if it's defined, it is just 0). 
   # Commenting out for now ... not sure if harm is done.
   #    $r->method_number(M_GET);
   
     $r->method('GET');      $r->method('GET');
     $r->headers_in->unset('Content-length');      $r->headers_in->unset('Content-length');
 }  }

Removed from v.1.315  
changed lines
  Added in v.1.329


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