Diff for /rat/lonwrapper.pm between versions 1.17 and 1.45

version 1.17, 2005/02/17 09:09:57 version 1.45, 2013/10/15 10:17:19
Line 26 Line 26
 # http://www.lon-capa.org/  # http://www.lon-capa.org/
 #  #
   
   
 package Apache::lonwrapper;  package Apache::lonwrapper;
   
 use strict;  use strict;
 use Apache::Constants qw(:common);  use Apache::Constants qw(:common);
 use Apache::lonnet();  use Apache::lonenc();
 use Apache::lonxml();  use Apache::lonnet;
 use Apache::lonmenu;  use Apache::lonlocal;
   use Apache::loncommon();
   use Apache::lonhtmlcommon();
   use Apache::lonextresedit();
   
 # ================================================================ Main Handler  # ================================================================ Main Handler
   sub wrapper {
       my ($url,$brcrum,$absolute,$is_ext) = @_;
   
       my $forcereg;
       unless ($env{'form.folderpath'}) {
           $forcereg = 1;
       }
   
       my $args = {'bgcolor' => '#FFFFFF'};
       if ($forcereg) {
           $args->{'force_register'} = $forcereg;
       }
       if (ref($brcrum) eq 'ARRAY') {
           $args->{'bread_crumbs'} = $brcrum;
       }
       if ($absolute) {
           $args->{'use_absolute'} = $absolute; 
       }
   
       my $startpage =  Apache::loncommon::start_page('Menu',undef,$args);
       my $endpage =  Apache::loncommon::end_page();
   
       my $script = Apache::lonhtmlcommon::scripttag(<<SCRIPT );
       \$(document).ready( function() {
           \$(window).unbind('resize').resize(function(){
               var header;
               var offset = 5;
               var height = 0;
               var hdrtop = 0;
               if (\$('div.LC_head_subbox:first').length) {
                   header = \$('div.LC_head_subbox:first');
                   offset = 9;
               } else {
                   if (\$('#LC_breadcrumbs').length) {
                       header = \$('#LC_breadcrumbs');
                   }
               }
               if (header.length) {
                   height = header.height();
                   hdrtop = header.position().top;
               }
               var pos = height + hdrtop + offset;
               \$('.LC_iframecontainer').css('top', pos);
           });
       });
       window.onload = function(){  \$(window).trigger('resize') }; 
   SCRIPT
   
       # javascript will position the iframe if window was resized (or zoomed)
       return <<ENDFRAME;
       $startpage
       $script
       <div class="LC_iframecontainer">
           <iframe src="$url">No iframe support!</iframe>
       </div>
       $endpage
   ENDFRAME
   }
   
 sub handler {  sub handler {
   my $r=shift;      my $r=shift;
   &Apache::loncommon::content_type($r,'text/html');      &Apache::loncommon::content_type($r,'text/html');
   $r->send_http_header;      $r->send_http_header;
   
   return OK if $r->header_only;      return OK if $r->header_only;
   
   &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},      my $url = $r->uri;
                                           ['wrapperdisplay']);      my ($is_ext,$brcrum,$absolute);
   my $orgurl=$r->uri;  
   my $url=$orgurl;      for ($url){
   $orgurl.=(($orgurl=~/\?/)?'&':'?').$ENV{'QUERY_STRING'};          s|^/adm/wrapper||;
   $orgurl.=(($orgurl=~/\?/)?'&':'?').'wrapperdisplay=menu';          $is_ext = $_ =~ s|^/ext/|http://|;         
   $url=~s/^\/adm\/wrapper//;          s|http://https://|https://|;
   $url=~s/^\/ext\//http\:\/\//;          s|&colon;|:|g;              
   $url=~s|&colon;|:|g;      }
   if ($ENV{'form.wrapperdisplay'} eq 'menu') {  
 #      if ($is_ext) {
 # Producing the menu buttons          my $hostname = $r->hostname();
 #          my $lonhost = &Apache::lonnet::host_from_dns($hostname);
       $r->print('<html><body bgcolor="#FFFFFF">'.          if ($lonhost) {
                 &Apache::lonmenu::menubuttons(1,'web',1).'</body></html>');              my $actual = &Apache::lonnet::absolute_url($hostname);
   } else {              my $expected = $Apache::lonnet::protocol{$lonhost}.'://'.$hostname; 
               unless ($actual eq $expected) {
                   $absolute = $expected;
               }
           }
           &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
               ['forceedit','register','folderpath','symb','idx','title']);
           if (($env{'form.forceedit'}) &&
               (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) &&
               (($env{'form.folderpath'} =~ /^supplemental/) ||
                ($env{'form.symb'} =~ /^uploaded/))) {
               $r->print(
                   &Apache::lonextresedit::display_editor($url,$env{'form.folderpath'},
                                                          $env{'form.symb'},
                                                          $env{'form.idx'}));
               return OK;
           } elsif ($env{'form.folderpath'} =~ /^supplemental/) {
               my $crstype = &Apache::loncommon::course_type();
               my $title = $env{'form.title'};
               if ($title eq '') {
                   $title = &mt('External Resource');
               }
               $brcrum =
                   &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
           }
       }
   
 #  #
 # Actual URL  # Actual URL
 #  #
       if ($url=~/\.(problem|exam|quiz|assess|survey|form|library)$/) {      if ($url=~/$LONCAPA::assess_re/) {
 #  #
 # This is uploaded homework  # This is uploaded homework
 #  #
           $ENV{'request.state'}='uploaded';          $env{'request.state'}='uploaded';
           &Apache::lonhomework::renderpage($r,$url);          &Apache::lonhomework::renderpage($r,$url);
       } else {      } else {
 #  #
 # This is not homework  # This is not homework
 #  #
   $url.=(($url=~/\?/)?'&':'?').$ENV{'QUERY_STRING'};           if ($is_ext) {
                                                  # reappend the query arguments              $ENV{'QUERY_STRING'} =~ s/(^|\&)symb=[^\&]*/$1/;
   my $events='onLoad="'.&Apache::lonmenu::loadevents.              $ENV{'QUERY_STRING'} =~ s/\&$//;
       '" onUnload="'.&Apache::lonmenu::unloadevents.'"';          }
   my $script=&Apache::lonmenu::registerurl(1,undef);  
           unless ($ENV{'QUERY_STRING'} eq '') {
   if ($ENV{'browser.interface'} eq 'textual') {              $url.=(($url=~/\?/)?'&':'?').$ENV{'QUERY_STRING'};
 #          }
 # ssi-based rendering for text-based interface  
 #          # encrypt url if not external
       $r->print('<html><head>'.          &Apache::lonenc::check_encrypt(\$url) if $url !~ /^https?\:/ ;
  &Apache::lonmenu::registerurl(1).  
  '</head><body bgcolor="#FFFFFF">'.          $r->print( wrapper($url,$brcrum,$absolute,$is_ext) );
  &Apache::lonmenu::menubuttons(1).  
  &Apache::lonnet::ssi_body($url).'</body></html>');      } # not just the menu
   } elsif ($ENV{'environment.remote'} eq 'off') {      
 #      return OK;
 # This is inline remote  
 #   
       $r->print(<<ENDDOCUMENTINL);  
 <html>  
 <head>  
 $script  
 </head>  
 <frameset rows="180,*" border=0 $events>  
 <frame src="$orgurl">  
 <frame src="$url">  
 </frameset>  
 </html>  
 ENDDOCUMENTINL  
           } else {  
 #  
 # frame-based rendering for graphical interface  
 #  
   $r->print(<<ENDDOCUMENT);  
 <html>  
 <head>  
 $script  
 </head>  
 <frameset rows="1,*" border=0 $events>  
 <frame src="/adm/rat/empty.html">  
 <frame src="$url">  
 </frameset>  
 </html>  
 ENDDOCUMENT  
           }  
       } # not homework  
   } # not just the menu  
   return OK;  
 } # handler  } # handler
   
 1;  1;
 __END__  __END__
   
   =pod
   
   =head1 NAME
   
   Apache::lonwrapper - External and binary file management.
   
   =head1 SYNOPSIS
   
   Wrapper for external and binary files as standalone resources. Edit handler for rat maps; TeX content handler.
   
   This is part of the LearningOnline Network with CAPA project
   described at http://www.lon-capa.org.
   
   =head1 Subroutines
   
   =over
   
   =item wrapper($url,$brcrum,$absolute,$is_ext)
   
   =over
   
   =item $url 
    
   url to display by including in an iframe within a
   LON-CAPA page which has a standard LON-CAPA inline menu.
   
   =item $brcrum
   
   breadcrumbs for unregistered urls
   (i.e., external resources in Supplemental Content).
   
   =item $absolute 
   
   contains protocol (http or https) followed by
   the hostname, if menu items in the standard LON-CAPA
   interface created by the call to loncommon::start_page()
   within &wrapper() need to use absolute URLs rather than
   relative URLs.
   
   That will be the case where an external resource has been 
   served from port 80, when the server customarily serves
   requests using Apache/SSL (i.e., port 443). mod_rewrite 
   is used to switch requests for external resources  
   from https:// to http:// where the the URL of the remote site 
   specified in the resource itself is http://.
   
   This is done to avoid default mixed content blocking
   in Firefox 23 and later, when serving from Apache/SSL.
   
   =item $is_ext
   
   true if URL is for an external resource.
   
   =back
   
   Returns markup for the entire page.
   
   =item handler()
   
   =back
   
   =cut
   
   
   
   

Removed from v.1.17  
changed lines
  Added in v.1.45


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