File:  [LON-CAPA] / rat / lonwrapper.pm
Revision 1.34: download - view: text, annotated - select for diffs
Wed Oct 21 22:46:31 2009 UTC (14 years, 6 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Some external web sites can't handle a trailing & in the query string.

    1: # The LearningOnline Network with CAPA
    2: # Wrapper for external and binary files as standalone resources
    3: #
    4: # $Id: lonwrapper.pm,v 1.34 2009/10/21 22:46:31 raeburn Exp $
    5: #
    6: # Copyright Michigan State University Board of Trustees
    7: #
    8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    9: #
   10: # LON-CAPA is free software; you can redistribute it and/or modify
   11: # it under the terms of the GNU General Public License as published by
   12: # the Free Software Foundation; either version 2 of the License, or
   13: # (at your option) any later version.
   14: #
   15: # LON-CAPA is distributed in the hope that it will be useful,
   16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18: # GNU General Public License for more details.
   19: #
   20: # You should have received a copy of the GNU General Public License
   21: # along with LON-CAPA; if not, write to the Free Software
   22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   23: #
   24: # /home/httpd/html/adm/gpl.txt
   25: #
   26: # http://www.lon-capa.org/
   27: #
   28: 
   29: 
   30: package Apache::lonwrapper;
   31: 
   32: use strict;
   33: use Apache::Constants qw(:common);
   34: use Apache::lonnet;
   35: use Apache::lonxml();
   36: use Apache::lonenc();
   37: use Apache::lonmenu();
   38: 
   39: # ================================================================ Main Handler
   40: 
   41: sub simple_menu {
   42: #
   43: # Producing the menu buttons
   44: #
   45:     return &Apache::loncommon::start_page('Menu',undef,
   46: 					  {'only_body' => 1,
   47: 					   'bgcolor'   => '#FFFFFF',}).
   48: 	&Apache::lonmenu::menubuttons(1,'web',1).
   49: 	&Apache::loncommon::end_page();
   50: }
   51: 
   52: 
   53: sub wrapper {
   54:     my ($topurl,$bottomurl) = @_;
   55: 
   56:     my %layout = ('border' => 0);
   57:     if ($env{'environment.remote'} eq 'off') {
   58:         if ($env{'environment.icons'} eq 'iconsonly') {
   59:            $layout{'rows'} = "100,*";
   60:         } else {
   61: 	   $layout{'rows'} = "200,*";
   62:         }
   63:     } else {
   64: 	$layout{'rows'} = "1,*";
   65: 	$topurl = "/adm/rat/empty.html";
   66:     }
   67: 
   68:     my $start_page = 
   69: 	&Apache::loncommon::start_page(undef,undef,
   70: 				       {'force_register' => 1,
   71: 					'frameset'       => 1,
   72: 					'add_entries'    => \%layout, });
   73: 
   74:     my $end_page = 
   75: 	&Apache::loncommon::end_page({'frameset' => 1});
   76:     
   77:     foreach my $url ($topurl,$bottomurl) {
   78: 	if ($url !~ /^https?\:/) {
   79: 	    $url = &Apache::lonenc::check_encrypt($url);
   80: 	}
   81:     }
   82: #
   83: # frame-based rendering for graphical interface
   84: #
   85:     my $result =<<ENDDOCUMENT;
   86: $start_page
   87: test
   88: <frame src="$topurl" />
   89: <frame src="$bottomurl" />
   90: $end_page
   91: ENDDOCUMENT
   92: 
   93:     return $result;
   94: }
   95: 
   96: sub handler {
   97:     my $r=shift;
   98:     &Apache::loncommon::content_type($r,'text/html');
   99:     $r->send_http_header;
  100: 
  101:     return OK if $r->header_only;
  102: 
  103:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
  104: 					    ['wrapperdisplay']);
  105:     if ($env{'form.wrapperdisplay'} eq 'menu') {
  106: 	$r->print(&simple_menu());
  107: 	return OK;
  108:     }
  109: 
  110:     my $orgurl=$r->uri;
  111:     my $url=$orgurl;
  112:     $orgurl.=(($orgurl=~/\?/)?'&':'?').$ENV{'QUERY_STRING'};
  113:     $orgurl.=(($orgurl=~/\?/)?'&':'?').'wrapperdisplay=menu';
  114:     $url=~s/^\/adm\/wrapper//;
  115:     my $is_ext = $url =~ m|^/ext/|;
  116:     $url=~s{^/ext/}{http://};
  117:     $url=~s|http://https://|https://|;
  118:     $url=~s|&colon;|:|g;
  119: #
  120: # Actual URL
  121: #
  122:     if ($url=~/\.(problem|exam|quiz|assess|survey|form|library)$/) {
  123: #
  124: # This is uploaded homework
  125: #
  126: 	$env{'request.state'}='uploaded';
  127: 	&Apache::lonhomework::renderpage($r,$url);
  128:     } else {
  129: #
  130: # This is not homework
  131: #
  132: 	if ($is_ext) {
  133: 	    $ENV{'QUERY_STRING'}=~s/(^|\&)symb=[^\&]*/$1/;
  134:             $ENV{'QUERY_STRING'} =~ s/\&$//;  
  135: 	}
  136: 	$url.=(($url=~/\?/)?'&':'?').$ENV{'QUERY_STRING'}; 
  137: 	# reappend the query arguments
  138: 	$r->print(&wrapper($orgurl,$url));
  139:     } # not just the menu
  140:     return OK;
  141: } # handler
  142: 
  143: 1;
  144: __END__
  145: 
  146: =pod
  147: 
  148: =head1 NAME
  149: 
  150: Apache::lonwrapper - External and binary file management.
  151: 
  152: =head1 SYNOPSIS
  153: 
  154: Wrapper for external and binary files as standalone resources. Edit handler for rat maps; TeX content handler.
  155: 
  156: This is part of the LearningOnline Network with CAPA project
  157: described at http://www.lon-capa.org.
  158: 
  159: =head1 Subroutines
  160: 
  161: =over
  162: 
  163: =item simple_menu()
  164: 
  165: =item wrapper()
  166: 
  167: =item handler()
  168: 
  169: =back
  170: 
  171: =cut
  172: 
  173: 
  174: 
  175: 
  176: 
  177: 
  178: 

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