Annotation of rat/lonwrapper.pm, revision 1.42

1.1       www         1: # The LearningOnline Network with CAPA
                      2: # Wrapper for external and binary files as standalone resources
                      3: #
1.42    ! raeburn     4: # $Id: lonwrapper.pm,v 1.41 2011/11/07 20:06:29 www Exp $
1.4       www         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: #
1.1       www        28: 
1.29      jms        29: 
1.1       www        30: package Apache::lonwrapper;
                     31: 
                     32: use strict;
                     33: use Apache::Constants qw(:common);
1.38      droeschl   34: use Apache::lonenc();
1.18      albertel   35: use Apache::lonnet;
1.42    ! raeburn    36: use Apache::lonlocal;
        !            37: use Apache::loncommon();
        !            38: use Apache::lonhtmlcommon();
        !            39: use Apache::lonextresedit();
1.1       www        40: 
                     41: # ================================================================ Main Handler
1.21      albertel   42: sub wrapper {
1.42    ! raeburn    43:     my ($url,$brcrum) = @_;
1.23      albertel   44: 
1.42    ! raeburn    45:     my $forcereg;
        !            46:     unless ($env{'form.folderpath'}) {
        !            47:         $forcereg = 1;
        !            48:     }
        !            49: 
        !            50:     my $args = {'bgcolor' => '#FFFFFF'};
        !            51:     if ($forcereg) {
        !            52:         $args->{'force_register'} = $forcereg;
        !            53:     }
        !            54:     if (ref($brcrum) eq 'ARRAY') {
        !            55:          $args->{'bread_crumbs'} = $brcrum;
        !            56:     }
        !            57: 
        !            58:     my $startpage =  Apache::loncommon::start_page('Menu',undef,$args);
1.38      droeschl   59:     my $endpage =  Apache::loncommon::end_page();
                     60: 
1.39      droeschl   61:     my $script = Apache::lonhtmlcommon::scripttag(<<SCRIPT );
1.38      droeschl   62:     \$(document).ready( function() {
                     63:         \$(window).unbind('resize').resize(function(){
1.42    ! raeburn    64:             var header;
        !            65:             var offset = 5;
        !            66:             var height = 0;
        !            67:             var hdrtop = 0;
        !            68:             if (\$('div.LC_head_subbox:first').length) {
        !            69:                 header = \$('div.LC_head_subbox:first');
        !            70:                 offset = 9;
        !            71:             } else {
        !            72:                 if (\$('#LC_breadcrumbs').length) {
        !            73:                     header = \$('#LC_breadcrumbs');
        !            74:                 }
        !            75:             }
        !            76:             if (header.length) {
        !            77:                 height = header.height();
        !            78:                 hdrtop = header.position().top;
        !            79:             }
        !            80:             var pos = height + hdrtop + offset;
1.39      droeschl   81:             \$('.LC_iframecontainer').css('top', pos);
1.38      droeschl   82:         });
                     83:     });
1.39      droeschl   84:     window.onload = function(){  \$(window).trigger('resize') }; 
                     85: SCRIPT
1.38      droeschl   86: 
1.39      droeschl   87:     # javascript will position the iframe if window was resized (or zoomed)
                     88:     return <<ENDFRAME;
                     89:     $startpage
                     90:     $script
1.38      droeschl   91:     <div class="LC_iframecontainer">
                     92:         <iframe src="$url">No iframe support!</iframe>
                     93:     </div>
                     94:     $endpage
                     95: ENDFRAME
1.21      albertel   96: }
                     97: 
                     98: sub handler {
                     99:     my $r=shift;
                    100:     &Apache::loncommon::content_type($r,'text/html');
                    101:     $r->send_http_header;
                    102: 
                    103:     return OK if $r->header_only;
                    104: 
1.38      droeschl  105:     my $url = $r->uri;
1.42    ! raeburn   106:     my ($is_ext,$brcrum);
1.38      droeschl  107: 
                    108:     for ($url){
                    109:         s|^/adm/wrapper||;
                    110:         $is_ext = $_ =~ s|^/ext/|http://|;         
                    111:         s|http://https://|https://|;
                    112:         s|&colon;|:|g;              
1.21      albertel  113:     }
                    114: 
1.42    ! raeburn   115:     if ($is_ext) {
        !           116:         &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
        !           117:             ['forceedit','register','folderpath','symb','idx','title']);
        !           118:         if (($env{'form.forceedit'}) &&
        !           119:             (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) &&
        !           120:             (($env{'form.folderpath'} =~ /^supplemental/) ||
        !           121:              ($env{'form.symb'} =~ /^uploaded/))) {
        !           122:             $r->print(
        !           123:                 &Apache::lonextresedit::display_editor($url,$env{'form.folderpath'},
        !           124:                                                        $env{'form.symb'},
        !           125:                                                        $env{'form.idx'}));
        !           126:             return OK;
        !           127:         } elsif ($env{'form.folderpath'} =~ /^supplemental/) {
        !           128:             my $crstype = &Apache::loncommon::course_type();
        !           129:             $brcrum =
        !           130:                 &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$env{'form.title'},1);
        !           131:             if (ref($brcrum) eq 'ARRAY') {
        !           132:                 my $last = $env{'form.title'};
        !           133:                 if ($last eq '') {
        !           134:                     $last = &mt('External Resource');
        !           135:                 }
        !           136:                 push(@{$brcrum},
        !           137:                          {'title' => $last,
        !           138:                           'text' => $last,
        !           139:                           'no_mt' => 1,
        !           140:                          });
        !           141: 
        !           142:             }
        !           143:         }
        !           144:     }
        !           145: 
1.21      albertel  146: #
                    147: # Actual URL
                    148: #
1.41      www       149:     if ($url=~/$LONCAPA::assess_re/) {
1.21      albertel  150: #
                    151: # This is uploaded homework
                    152: #
1.38      droeschl  153:         $env{'request.state'}='uploaded';
                    154:         &Apache::lonhomework::renderpage($r,$url);
1.21      albertel  155:     } else {
                    156: #
                    157: # This is not homework
                    158: #
1.38      droeschl  159:         if ($is_ext) {
                    160:             $ENV{'QUERY_STRING'} =~ s/(^|\&)symb=[^\&]*/$1/;
1.42    ! raeburn   161:             $ENV{'QUERY_STRING'} =~ s/\&$//;
1.38      droeschl  162:         }
                    163: 
1.35      raeburn   164:         unless ($ENV{'QUERY_STRING'} eq '') {
1.38      droeschl  165:             $url.=(($url=~/\?/)?'&':'?').$ENV{'QUERY_STRING'};
1.35      raeburn   166:         }
1.38      droeschl  167: 
                    168:         # encrypt url if not external
                    169:         &Apache::lonenc::check_encrypt(\$url) if $url !~ /^https?\:/ ;
                    170: 
1.42    ! raeburn   171:         $r->print( wrapper($url,$brcrum) );
1.38      droeschl  172: 
1.21      albertel  173:     } # not just the menu
1.38      droeschl  174:     
1.21      albertel  175:     return OK;
1.13      www       176: } # handler
1.1       www       177: 
                    178: 1;
                    179: __END__
                    180: 
1.30      jms       181: =pod
1.1       www       182: 
1.30      jms       183: =head1 NAME
                    184: 
                    185: Apache::lonwrapper - External and binary file management.
                    186: 
                    187: =head1 SYNOPSIS
                    188: 
                    189: Wrapper for external and binary files as standalone resources. Edit handler for rat maps; TeX content handler.
                    190: 
                    191: This is part of the LearningOnline Network with CAPA project
                    192: described at http://www.lon-capa.org.
                    193: 
                    194: =head1 Subroutines
                    195: 
                    196: =over
                    197: 
1.42    ! raeburn   198: =item wrapper($url,$brcrum)
1.30      jms       199: 
1.38      droeschl  200: Wraps $url in an iframe and generates a page for it.
1.42    ! raeburn   201: $brcrum contains breadcrumbs for unregistered urls
        !           202: (i.e., external resources in Supplemental Content).
1.38      droeschl  203: Returns markup for the entire page.
1.30      jms       204: 
                    205: =item handler()
                    206: 
                    207: =back
                    208: 
                    209: =cut
1.1       www       210: 
                    211: 
                    212: 
                    213: 
                    214: 
1.29      jms       215: 
                    216: 

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