Annotation of rat/lonwrapper.pm, revision 1.49.2.11.2.3

1.1       www         1: # The LearningOnline Network with CAPA
                      2: # Wrapper for external and binary files as standalone resources
                      3: #
1.49.2.11.2.3! (raeburn    4:: # $Id: lonwrapper.pm,v 1.49.2.11.2.2 2022/08/30 11:48:33 raeburn 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.49.2.11.2.1  (raeburn   40:: use Apache::lonexttool();
1.49.2.11.2.2  (raeburn   41:: use Apache::lonnavmaps();
1.49.2.11.2.1  (raeburn   42:: use LONCAPA qw(:DEFAULT :match);
                     43:: use HTML::Entities();
1.49.2.11.2.2  (raeburn   44:: use Digest::MD5();
1.1       www        45: 
                     46: # ================================================================ Main Handler
1.21      albertel   47: sub wrapper {
1.49.2.11.2.1  (raeburn   48::     my ($r,$url,$brcrum,$absolute,$is_ext,$is_pdf,$exttool,$linktext,$explanation,
1.49.2.11.2.3! (raeburn   49::         $title,$width,$height,$reuse,$is_supp) = @_;
1.23      albertel   50: 
1.42      raeburn    51:     my $forcereg;
                     52:     unless ($env{'form.folderpath'}) {
                     53:         $forcereg = 1;
                     54:     }
                     55: 
1.46      raeburn    56:     my %lt = &Apache::lonlocal::texthash(
                     57:                                           'noif' => 'No iframe support.',
                     58:                                           'show' => 'Show content in pop-up window',
                     59:                                         );
                     60: 
1.49.2.11  raeburn    61:     (undef,undef,undef,undef,undef,undef,my $clientmobile) =
                     62:         &Apache::loncommon::decode_user_agent($r);
                     63: 
1.49.2.11.2.1  (raeburn   64::     my ($anchor,$uselink);
1.49.2.2  raeburn    65:     if ($is_ext) {
                     66:         if ($env{'form.symb'}) {
                     67:             (undef,undef,my $res) = &Apache::lonnet::decode_symb($env{'form.symb'});
1.49.2.3  raeburn    68:             if ($res =~ /(#[^#]+)$/) {
1.49.2.2  raeburn    69:                 $anchor = $1;
                     70:             }
                     71:         } elsif ($env{'form.anchor'} ne '') {
                     72:             $anchor = '#'.$env{'form.anchor'};
1.49.2.1  raeburn    73:         }
1.49.2.11.2.2  (raeburn   74::         if (($is_ext eq 'tab') || ($is_ext eq 'window')) {
                     75::             $uselink = 1;
                     76::         }
                     77::         unless (($is_pdf && $clientmobile) || $uselink) {
1.49.2.6  raeburn    78:             my $hostname = $r->hostname();
                     79:             my $lonhost = $r->dir_config('lonHostID');
                     80:             my $ip = &Apache::lonnet::get_host_ip($lonhost);
                     81:             $uselink = &Apache::loncommon::is_nonframeable($url,$absolute,$hostname,$ip);
                     82:         }
1.49.2.1  raeburn    83:     }
                     84: 
                     85:     my $noiframe = &Apache::loncommon::modal_link($url.$anchor,$lt{'show'},500,400);
1.42      raeburn    86:     my $args = {'bgcolor' => '#FFFFFF'};
                     87:     if ($forcereg) {
                     88:         $args->{'force_register'} = $forcereg;
                     89:     }
                     90:     if (ref($brcrum) eq 'ARRAY') {
1.45      raeburn    91:         $args->{'bread_crumbs'} = $brcrum;
1.42      raeburn    92:     }
1.44      raeburn    93:     if ($absolute) {
1.49.2.4  raeburn    94:         $args->{'use_absolute'} = $absolute;
                     95:     }
                     96:     if ($env{'form.only_body'}) {
                     97:         $args->{'only_body'} = $env{'form.only_body'};
1.44      raeburn    98:     }
1.42      raeburn    99: 
1.49.2.8  raeburn   100:     my $headjs;
                    101: 
                    102: #
                    103: # Where iframe is in use, if window.onload() executes before the custom resize function
                    104: # has been defined (jQuery), two global javascript vars (LCnotready and LCresizedef)
                    105: # are used to ensure document.ready() triggers a call to resize, so the iframe contents
                    106: # do not obscure the Functions menu.
                    107: #
                    108: 
1.49.2.11.2.1  (raeburn  109::     unless ($clientmobile || ($exttool eq 'window') || ($exttool eq 'tab') || $uselink) {
1.49.2.8  raeburn   110:         $headjs = '
                    111: <script type="text/javascript">
                    112: // <![CDATA[
                    113: var LCnotready = 0;
                    114: var LCresizedef = 0;
                    115: // ]]>
                    116: </script>'."\n";
1.49.2.9  raeburn   117:     }
1.49.2.8  raeburn   118: 
                    119:     my $startpage = &Apache::loncommon::start_page('Menu',$headjs,$args);
1.46      raeburn   120:     my $endpage = &Apache::loncommon::end_page();
1.38      droeschl  121: 
1.49.2.6  raeburn   122:     if (($uselink) && ($title eq '')) {
                    123:         if ($env{'form.symb'}) {
                    124:             $title=&Apache::lonnet::gettitle($env{'form.symb'});
1.49.2.11.2.3! (raeburn  125::         } elsif (!$is_supp) {
1.49.2.6  raeburn   126:             my $symb=&Apache::lonnet::symbread($r->uri);
                    127:             if ($symb) {
                    128:                 $title=&Apache::lonnet::gettitle($symb);
                    129:             }
                    130:         }
                    131:     }
1.49.2.11.2.2  (raeburn  132::     if ($clientmobile || ($exttool eq 'window') || ($exttool eq 'tab') ||
                    133::         ($is_ext eq 'tab') || ($is_ext eq 'window')) {
1.47      raeburn   134:         my $output = $startpage;
                    135:         if ($is_pdf) {
1.49.2.6  raeburn   136:             $linktext = &mt('Link to PDF (for mobile devices)');
                    137:             $output .= &create_link($url,$anchor,$title,$linktext);
1.49.2.11.2.2  (raeburn  138::         } elsif (($exttool eq 'window') || ($exttool eq 'tab') ||
                    139::                  ($is_ext eq 'tab') || ($is_ext eq 'window')) {
                    140::             my $preamble;
1.49.2.11.2.1  (raeburn  141::             if ($linktext eq '') {
1.49.2.11.2.2  (raeburn  142::                 if ($exttool) {
                    143::                     $linktext = &mt('Launch External Tool');
                    144::                 } else {
                    145::                     $linktext = &mt('Link to External Resource');
                    146::                 }
                    147::             }
                    148::             if ($exttool) {
                    149::                 $url = &HTML::Entities::encode($url,'"<>&');
                    150::             } else {
                    151::                 $url = &HTML::Entities::encode($url.$anchor,'&<>"');
1.49.2.11.2.1  (raeburn  152::             }
1.49.2.11.2.2  (raeburn  153::             if (($exttool eq 'tab') || ($is_ext eq 'tab')) {
                    154::                 my $target;
                    155::                 if ($exttool) {
                    156::                     $target = 'LCExternalToolTab';
                    157::                 } else {
                    158::                     if ($reuse) {
                    159::                         $target = 'LCExternalResTab';
                    160::                     } else {
                    161::                         $target = '_blank';
                    162::                     }
                    163::                     if ($title ne '') {
                    164::                         $preamble = '<span style="font-weight:bold;">'.$title.'</span><br />';
                    165::                     }
                    166::                 }
                    167::                 $output .= '<div>'.$preamble.
                    168::                            '<a href="'.$url.'" target="'.$target.'" style="padding:0;clear:both;margin:0;border:0">'.
1.49.2.11.2.1  (raeburn  169::                            $linktext.'</a>'.
                    170::                            '</div>';
                    171::             } else {
1.49.2.11.2.2  (raeburn  172::                 my ($target,$extlinkimg);
                    173::                 if ($exttool) {
                    174::                     $target = 'LCExternalToolPopUp';
                    175::                 } else {
                    176::                     $target = 'LCExternalResPopUp';
                    177::                     if ($title ne '') {
                    178::                         $preamble = '<span style="font-weight:bold;">'.$title.'</span><br />';
                    179::                     }
                    180::                     $extlinkimg = '<img src="'.&Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL').'/externallink.gif').'" width="19" height="18" border="0" />';
                    181::                     unless ($reuse) {
                    182::                         my $resid;
                    183::                         if ($env{'request.course.id'}) {
1.49.2.11.2.3! (raeburn  184::                             unless (($is_supp) || ($env{'form.folderpath'} =~ /^supplemental/)) {
1.49.2.11.2.2  (raeburn  185::                                 my $symb=&Apache::lonnet::symbread($r->uri);
                    186::                                 if ($symb) {
                    187::                                     my $navmap = Apache::lonnavmaps::navmap->new();
                    188::                                     if (ref($navmap)) {
                    189::                                         my $res = $navmap->getBySymb($symb);
                    190::                                         if (ref($res)) {
                    191::                                             $resid = $res->id;
                    192::                                             $resid =~ s/\./_/g;
                    193::                                         }
                    194::                                     }
                    195::                                 }
                    196::                             }
                    197::                         }
                    198::                         if ($resid eq '') {
                    199::                             $resid = substr(Digest::MD5::md5_hex(Digest::MD5::md5_hex(time(). {}. rand(). $$)), 0, 8);
                    200::                         }
                    201::                         &js_escape(\$resid);
                    202::                         $target .= $resid;
                    203::                     }
                    204::                 }
1.49.2.11.2.1  (raeburn  205::                 $output .= <<"ENDLINK";
                    206:: <script type="text/javascript">
                    207:: // <![CDATA[
                    208:: var windowObjectReference = null;
                    209:: var PreviousUrl;
                    210:: 
                    211:: function openSinglePopup(strUrl) {
                    212::     if (windowObjectReference == null || windowObjectReference.closed) {
1.49.2.11.2.2  (raeburn  213::         windowObjectReference = window.open(strUrl, "$target",
1.49.2.11.2.1  (raeburn  214::                                             "height=$height,width=$width,scrollbars=yes,resizable=yes,status=yes,menubar=no,location=no'");
                    215::     } else if(PreviousUrl != strUrl) {
1.49.2.11.2.2  (raeburn  216::         windowObjectReference = window.open(strUrl, "$target",
1.49.2.11.2.1  (raeburn  217::                                             "height=$height,width=$width,scrollbars=yes,resizable=yes,status=yes,menubar=no,location=no'");
                    218::         windowObjectReference.focus();
                    219::     } else {
                    220::         windowObjectReference.focus();
                    221::     };
                    222::     PreviousUrl = strUrl;
                    223:: }
                    224:: // ]]>
                    225:: </script>
1.49.2.11.2.2  (raeburn  226:: <div>$preamble
                    227:: <a href="$url" target="$target" onclick="openSinglePopup(this.href); return false;">
                    228:: $linktext$extlinkimg</a>
1.49.2.11.2.1  (raeburn  229:: </div>
                    230:: ENDLINK
                    231::             }
1.49.2.11.2.2  (raeburn  232::             if ($exttool) {
                    233::                 if ($explanation ne '') {
                    234::                     $output .= '<div>'.$explanation.'</div>';
                    235::                 }
1.49.2.11.2.1  (raeburn  236::             }
1.47      raeburn   237:         } else {
1.49.2.6  raeburn   238:             if ($uselink) {
                    239:                 $linktext = &mt('Link to resource');
                    240:                 $output .= &create_link($url,$anchor,$title,$linktext);
                    241:             } else {
                    242:                 my $dest = &HTML::Entities::encode($url.$anchor,'&<>"');
                    243:                 $output .= '<div style="overflow:scroll; -webkit-overflow-scrolling:touch;">'."\n".
                    244:                            '<iframe src="'.$dest.'" height="100%" width="100%" frameborder="0">'."\n".
                    245:                            "$lt{'noif'} $noiframe\n".
                    246:                            "</iframe>\n".
                    247:                            "</div>\n";
                    248:             }
1.47      raeburn   249:         }
                    250:         $output .= $endpage;
                    251:         return $output;
1.49.2.6  raeburn   252:     } elsif ($uselink) {
                    253:         $linktext = &mt('Link to resource');
                    254:         return $startpage.&create_link($url,$anchor,$title,$linktext).$endpage;
1.46      raeburn   255:     } else {
1.49.2.3  raeburn   256:         my $offset = 5;
                    257:         &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']);
                    258:         if ($env{'form.inhibitmenu'} eq 'yes') {
                    259:             $offset = 0;
                    260:         }
1.46      raeburn   261:         my $script = &Apache::lonhtmlcommon::scripttag(<<SCRIPT);
                    262:         \$(document).ready( function() {
                    263:             \$(window).unbind('resize').resize(function(){
1.49.2.3  raeburn   264:                 var header = null;
                    265:                 var offset = $offset;
1.46      raeburn   266:                 var height = 0;
                    267:                 var hdrtop = 0;
                    268:                 if (\$('div.LC_head_subbox:first').length) {
                    269:                     header = \$('div.LC_head_subbox:first');
                    270:                     offset = 9;
                    271:                 } else {
                    272:                     if (\$('#LC_breadcrumbs').length) {
                    273:                         header = \$('#LC_breadcrumbs');
                    274:                     }
                    275:                 }
1.49.2.3  raeburn   276:                 if (header != null && header.length) {
1.46      raeburn   277:                     height = header.height();
                    278:                     hdrtop = header.position().top;
1.42      raeburn   279:                 }
1.46      raeburn   280:                 var pos = height + hdrtop + offset;
                    281:                 \$('.LC_iframecontainer').css('top', pos);
                    282:             });
1.49.2.8  raeburn   283:             LCresizedef = 1;
                    284:             if (LCnotready == 1) {
                    285:                 LCnotready = 0;
                    286:                 \$(window).trigger('resize');
                    287:             }
1.38      droeschl  288:         });
1.49.2.8  raeburn   289:         window.onload = function(){
                    290:             if (LCresizedef) {
                    291:                 LCnotready = 0;
1.49.2.9  raeburn   292:                 \$(window).trigger('resize');
1.49.2.8  raeburn   293:             } else {
                    294:                 LCnotready = 1;
                    295:             }
                    296:         };
1.39      droeschl  297: SCRIPT
1.46      raeburn   298:         # javascript will position the iframe if window was resized (or zoomed)
1.49.2.11.2.1  (raeburn  299::         my $dest = &HTML::Entities::encode($url.$anchor,'&<>"');
1.46      raeburn   300:         return <<ENDFRAME;
                    301:         $startpage
                    302:         $script
                    303:         <div class="LC_iframecontainer">
1.49.2.11.2.1  (raeburn  304::             <iframe src="$dest">$lt{'noif'} $noiframe</iframe>
1.46      raeburn   305:         </div>
                    306:         $endpage
1.38      droeschl  307: ENDFRAME
1.46      raeburn   308:     }
1.21      albertel  309: }
                    310: 
1.49.2.6  raeburn   311: sub create_link {
                    312:     my ($url,$anchor,$title,$linktext) = @_;
                    313:     my $shownlink;
                    314:     if ($title eq '') {
                    315:         $title = $env{'form.title'};
                    316:         if ($title eq '') {
                    317:             unless ($env{'request.enc'}) {
                    318:                 ($title) = ($url =~ m{/([^/]+)$});
                    319:                 $title =~ s/(\?[^\?]+)$//;
                    320:             }
                    321:         }
                    322:     }
                    323:     unless ($title eq '') {
                    324:         $shownlink = '<span style="font-weight:bold;">'.$title.'</span><br />';
                    325:     }
                    326:     my $dest = &HTML::Entities::encode($url.$anchor,'&<>"');
                    327:     $shownlink .= '<a href="'.$dest.'">'.$linktext.'</a>';
                    328:     return $shownlink;
                    329: }
                    330: 
1.21      albertel  331: sub handler {
                    332:     my $r=shift;
                    333:     &Apache::loncommon::content_type($r,'text/html');
                    334:     $r->send_http_header;
                    335: 
                    336:     return OK if $r->header_only;
                    337: 
1.38      droeschl  338:     my $url = $r->uri;
1.49.2.11.2.1  (raeburn  339::     my ($is_ext,$brcrum,$absolute,$is_pdf,$exttool,$cdom,$cnum,$hostname,
1.49.2.11.2.3! (raeburn  340::         $linktext,$explanation,$width,$height,$reuse,$is_supp);
1.38      droeschl  341: 
                    342:     for ($url){
                    343:         s|^/adm/wrapper||;
1.49.2.8  raeburn   344:         $is_ext = $_ =~ s|^/ext/|http://|;
1.49.2.10  raeburn   345:         s|http://https://|https://| if ($is_ext);
1.49.2.8  raeburn   346:         s|&colon;|:|g;
1.21      albertel  347:     }
                    348: 
1.47      raeburn   349:     if ($url =~ /\.pdf$/i) {
                    350:         $is_pdf = 1;
1.49.2.11.2.2  (raeburn  351::     } elsif (($is_ext) && ($env{'request.course.id'})) {
                    352::         if ($env{'course.'.$env{'request.course.id'}.'.extresource'}) {
                    353::             (my $selected,$reuse,$width,$height) = split(/:/,$env{'course.'.$env{'request.course.id'}.'.extresource'});
                    354::             if ($selected eq 'tab') {
                    355::                 $is_ext = 'tab';
                    356::                 $width = '';
                    357::                 $height = '';
                    358::             } elsif ($selected eq 'window') {
                    359::                 $is_ext = 'window';
                    360::                 unless ($width =~ /^\d+$/) {
                    361::                     $width = '';
                    362::                 }
                    363::                 unless ($height =~ /^\d+$/) {
                    364::                     $height = '';
                    365::                 }
                    366::             } else {
                    367::                 $width = '';
                    368::                 $height = '';
                    369::                 $reuse = '';
                    370::             }
                    371::         }
1.49.2.11.2.1  (raeburn  372::     } elsif ($url =~ m{^/adm/($match_domain)/($match_courseid)/(\d+)/ext\.tool$}) {
                    373::         $cdom = $1;
                    374::         $cnum = $2;
                    375::         my $marker = $3;
                    376::         $exttool = 'iframe';
                    377::         my $exttoolremote;
                    378::         my %toolhash = &Apache::lonnet::get('exttool_'.$marker,['target','linktext','explanation','id','width','height'],
                    379::                                             $cdom,$cnum);
                    380::         if ($toolhash{'id'}) {
                    381::             my %ltitools = &Apache::lonnet::get_domain_lti($cdom,'consumer');
                    382::             if (ref($ltitools{$toolhash{'id'}}) eq 'HASH') {
                    383::                 $exttoolremote = $ltitools{$toolhash{'id'}}{'url'};
                    384::             }
                    385::         }
                    386::         if ($toolhash{'target'} eq 'window') {
                    387::             $exttool = 'window';
                    388::             $width = $toolhash{'width'};
                    389::             $height = $toolhash{'height'};
                    390::         } elsif ($toolhash{'target'} eq 'tab') {
                    391::             $exttool = 'tab';
                    392::         }
                    393::         if (($exttool eq 'window') || ($exttool eq 'tab')) {
                    394::             $linktext = $toolhash{'linktext'};
                    395::             $explanation = $toolhash{'explanation'};
                    396::         } elsif (($exttoolremote =~ /^http:/) && ($ENV{'SERVER_PORT'} == 443)) {
                    397::             $exttool = 'tab';
                    398::         }
1.47      raeburn   399:     }
1.49.2.11.2.1  (raeburn  400::     if (($is_ext) || ($exttool)) {
1.42      raeburn   401:         &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.49.2.2  raeburn   402:             ['forceedit','register','folderpath','symb','idx','title','anchor']);
1.42      raeburn   403:         if (($env{'form.forceedit'}) &&
                    404:             (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) &&
                    405:             (($env{'form.folderpath'} =~ /^supplemental/) ||
                    406:              ($env{'form.symb'} =~ /^uploaded/))) {
1.49.2.2  raeburn   407:             if ($env{'form.symb'}) {
                    408:                 (undef,undef,my $res) = &Apache::lonnet::decode_symb($env{'form.symb'});
                    409:                 if ($res =~ /(#[^#]+)$/) {
                    410:                     $url .= $1;
                    411:                 }
                    412:             } elsif ($env{'form.folderpath'} =~ /^supplemental/) {
                    413:                 if ($env{'form.anchor'} ne '') {
                    414:                     $url .= '#'.$env{'form.anchor'};
                    415:                 }
1.49.2.11.2.3! (raeburn  416::                 $is_supp = 1;
1.49.2.2  raeburn   417:             }
1.49.2.11.2.1  (raeburn  418::             my $type = 'ext';
                    419::             if ($exttool) {
                    420::                 $type = 'tool';
                    421::             } elsif (($url =~ /^http:/) && ($ENV{'SERVER_PORT'} == 443)) {
1.49.2.5  raeburn   422:                 $hostname = $r->hostname();
                    423:             }
1.42      raeburn   424:             $r->print(
                    425:                 &Apache::lonextresedit::display_editor($url,$env{'form.folderpath'},
                    426:                                                        $env{'form.symb'},
1.49.2.5  raeburn   427:                                                        $env{'form.idx'},$type,$cdom,
                    428:                                                        $cnum,$hostname));
1.42      raeburn   429:             return OK;
                    430:         } elsif ($env{'form.folderpath'} =~ /^supplemental/) {
                    431:             my $crstype = &Apache::loncommon::course_type();
1.43      raeburn   432:             my $title = $env{'form.title'};
                    433:             if ($title eq '') {
1.49.2.11.2.1  (raeburn  434::                 if ($is_ext) {
                    435::                     $title = &mt('External Resource');
                    436::                 } else {
                    437::                     $title = &mt('External Tool');
                    438::                 }
1.43      raeburn   439:             }
1.49.2.11.2.3! (raeburn  440::             $title = &HTML::Entities::encode($title,'\'"<>&');
        !           441::             $is_supp = 1;
        !           442::             if ($env{'request.course.id'}) {
        !           443::                 $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
        !           444::                 $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
        !           445::                 &Apache::loncommon::validate_folderpath(1,'',$cnum,$cdom);
        !           446::             }
1.42      raeburn   447:             $brcrum =
1.43      raeburn   448:                 &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
1.42      raeburn   449:         }
1.49.2.11.2.3! (raeburn  450::     } elsif ($env{'request.course.id'}) {
        !           451::         my $courseurl = &Apache::lonnet::courseid_to_courseurl($env{'request.course.id'});
        !           452::         $courseurl =~ s{^/}{};
        !           453::         if ($url =~ m{^\Q/uploaded/$courseurl/supplemental/\E}) {
        !           454::             $is_supp = 1;
        !           455::             &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
        !           456::                                                     ['folderpath','title']);
        !           457::             if ($env{'form.folderpath'}) {
        !           458::                 $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
        !           459::                 $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
        !           460::                 &Apache::loncommon::validate_folderpath(1,'',$cnum,$cdom);
        !           461::             }
        !           462::             my $title = $env{'form.title'};
        !           463::             $title = &HTML::Entities::encode($title,'\'"<>&');
        !           464::             my $crstype = &Apache::loncommon::course_type();
        !           465::             $brcrum =
        !           466::                 &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
        !           467:: 
        !           468::         }
1.42      raeburn   469:     }
                    470: 
1.21      albertel  471: #
                    472: # Actual URL
                    473: #
1.49.2.11.2.1  (raeburn  474::     if (($url=~/$LONCAPA::assess_re/) && (!$exttool)) {
1.21      albertel  475: #
                    476: # This is uploaded homework
                    477: #
1.38      droeschl  478:         $env{'request.state'}='uploaded';
                    479:         &Apache::lonhomework::renderpage($r,$url);
1.21      albertel  480:     } else {
                    481: #
                    482: # This is not homework
                    483: #
1.49.2.11.2.1  (raeburn  484::         if (($is_ext) || ($exttool)) {
1.49      raeburn   485:             $absolute = $env{'request.use_absolute'};
1.38      droeschl  486:             $ENV{'QUERY_STRING'} =~ s/(^|\&)symb=[^\&]*/$1/;
1.42      raeburn   487:             $ENV{'QUERY_STRING'} =~ s/\&$//;
1.38      droeschl  488:         }
                    489: 
1.35      raeburn   490:         unless ($ENV{'QUERY_STRING'} eq '') {
1.38      droeschl  491:             $url.=(($url=~/\?/)?'&':'?').$ENV{'QUERY_STRING'};
1.35      raeburn   492:         }
1.38      droeschl  493: 
                    494:         # encrypt url if not external
1.49.2.11.2.1  (raeburn  495::         unless ($is_ext) {
                    496::             &Apache::lonenc::check_encrypt(\$url);
                    497::         }
1.38      droeschl  498: 
1.49.2.11.2.1  (raeburn  499::         $r->print( wrapper($r,$url,$brcrum,$absolute,$is_ext,$is_pdf,$exttool,
1.49.2.11.2.3! (raeburn  500::                            $linktext,$explanation,undef,$width,$height,$reuse,
        !           501::                            $is_supp) );
1.38      droeschl  502: 
1.21      albertel  503:     } # not just the menu
1.38      droeschl  504:     
1.21      albertel  505:     return OK;
1.13      www       506: } # handler
1.1       www       507: 
                    508: 1;
                    509: __END__
                    510: 
1.30      jms       511: =pod
1.1       www       512: 
1.30      jms       513: =head1 NAME
                    514: 
                    515: Apache::lonwrapper - External and binary file management.
                    516: 
                    517: =head1 SYNOPSIS
                    518: 
                    519: Wrapper for external and binary files as standalone resources. Edit handler for rat maps; TeX content handler.
                    520: 
                    521: This is part of the LearningOnline Network with CAPA project
                    522: described at http://www.lon-capa.org.
                    523: 
                    524: =head1 Subroutines
                    525: 
                    526: =over
                    527: 
1.49.2.11.2.3! (raeburn  528:: =item wrapper($r,$url,$brcrum,$absolute,$is_ext,$is_pdf,$exttool,$linktext,$explanation,$title,$width,$height,$reuse,$is_supp)
1.30      jms       529: 
1.45      raeburn   530: =over
                    531: 
1.49.2.6  raeburn   532: =item $r
                    533: 
                    534: request object
                    535: 
1.46      raeburn   536: =item $url
                    537: 
1.49.2.11.2.2  (raeburn  538:: url to display either by including in an iframe within a
                    539:: LON-CAPA page which has a standard LON-CAPA inline menu,
                    540:: or in some cases launched in a separate tab or window,
                    541:: launched via a link in a LON-CAPA page with standard inline
                    542:: menu.
1.45      raeburn   543: 
                    544: =item $brcrum
                    545: 
                    546: breadcrumbs for unregistered urls
1.42      raeburn   547: (i.e., external resources in Supplemental Content).
1.45      raeburn   548: 
1.46      raeburn   549: =item $absolute
1.45      raeburn   550: 
                    551: contains protocol (http or https) followed by
                    552: the hostname, if menu items in the standard LON-CAPA
                    553: interface created by the call to loncommon::start_page()
                    554: within &wrapper() need to use absolute URLs rather than
                    555: relative URLs.
                    556: 
                    557: That will be the case where an external resource has been 
                    558: served from port 80, when the server customarily serves
                    559: requests using Apache/SSL (i.e., port 443). mod_rewrite 
1.49      raeburn   560: is used to switch requests for external resources and
                    561: the syllabus: /public/<domain>/<courseid>/syllabus
                    562: (which might also point at an external resource)
1.45      raeburn   563: from https:// to http:// where the the URL of the remote site 
                    564: specified in the resource itself is http://.
                    565: 
                    566: This is done to avoid default mixed content blocking
                    567: in Firefox 23 and later, when serving from Apache/SSL.
                    568: 
                    569: =item $is_ext
                    570: 
1.49.2.11.2.2  (raeburn  571:: true if URL is for an external resource. Default true value
                    572:: is 1 (display in iframe, unless $uselink is true).
                    573:: If external resource is to be displayed in a tab,
                    574:: value of $is_ext will be tab, if to be displayed in a pop-up window,
                    575:: value of $is_ext will be window.
1.45      raeburn   576: 
1.47      raeburn   577: =item $is_pdf
                    578: 
                    579: true if URL is for a PDF (based on file extension).
                    580: 
1.49.2.11.2.2  (raeburn  581:: =item $exttool
                    582:: 
                    583:: If URL is for an External Tool, will contain the target type: iframe, window or tab.
                    584:: 
                    585:: =item $linktext
                    586:: 
                    587:: optional. If URL is for an External Tool, and target type is window or tab,
                    588:: then the link text may be an option set in the course for each tool instance,
                    589:: or may be a default defined in the domain for all instances of the tool.
                    590:: 
                    591:: =item $explanation
                    592:: 
                    593:: optional. If URL is for an External Tool, and target type is window or tab,
                    594:: then the explanation is an option set in the course for each tool instance,
                    595:: or may be a default defined in the domain for all instances of the tool.
                    596:: 
1.49      raeburn   597: =item $title
                    598: 
1.49.2.11  raeburn   599: optional. If wrapped item is a PDF, and $clientmobile is true,
                    600: a link to a PDF is shown. The "title" will be displayed
1.49      raeburn   601: above the link, but if not provided as an arg, $env{'form.title'}
                    602: will be used, otherwise, the filename will be displayed (unless
                    603: hidden URL set for the resource).
                    604: 
1.49.2.11.2.2  (raeburn  605:: =item $width
                    606:: 
                    607:: optional. If URL is for an External Tool, and target type is window,
                    608:: then a default width may have been defined in the domain for all instances of
                    609:: the tool.  If so, that width will be used for the window opened (via a link)
                    610:: to launch the external tool. If the URL is for an External Resource, and
                    611:: $is_ext is window, then a default width (px) may have been defined in the current
                    612:: course for all external resource instances.
                    613:: 
                    614:: =item $height
                    615:: 
                    616:: optional. If URL is for an External Tool, and target type is window,
                    617:: then a default height may have been defined in the domain for all instances of
                    618:: the tool.  If so, that height will be used for the window opened (via a link)
                    619:: to launch the external tool.  If the URL is for an External Resource, and
                    620:: $is_ext is window, then a default height (px) may have been defined in the current
                    621:: course for all external resource instances.
                    622:: 
                    623:: =item $reuse
                    624:: 
                    625:: optional. If the URL is for an External Resource, and $is_ext is tab or window,
                    626:: then $reuse will be true if the same tab or window is to be reused for display
                    627:: of all external resource instances in a a course.
                    628:: 
1.45      raeburn   629: =back
                    630: 
1.38      droeschl  631: Returns markup for the entire page.
1.30      jms       632: 
                    633: =item handler()
                    634: 
1.49.2.11.2.2  (raeburn  635:: Content handler for requests for: /adm/wrapper/...
                    636:: used for content to be displayed in an iframe, or launched in a separate tab
                    637:: or window via a link.  The target URL is extracted from the requested URL, by
                    638:: removing the /adm/wrapper prefix.
                    639:: 
                    640:: The target URL will typically be a PDF served from the current server, an
                    641:: external resource URL served from a different server, or an external tool
                    642:: (from an LTI Provider) launched from LON-CAPA (as LTI Consumer) and launched
                    643:: via a link.
                    644:: 
                    645:: If the request included forceedit in the query string, and the requester has
                    646:: rights to modify course content, then the editor will be displayed to allow
                    647:: changes to be made to the resource (e.g., change the URL of the external resource,
                    648:: or change the setting for the external tool instance).
                    649:: 
                    650:: If not in edit mode, then the wrapper() subroutine will be called to generate the
                    651:: standard LON-CAPA inline menu, and then either a link to launch a separate tab or
                    652:: window, or an iframe to display the content inline.
                    653:: 
1.30      jms       654: =back
                    655: 
                    656: =cut
1.1       www       657: 

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