Annotation of rat/lonwrapper.pm, revision 1.49.2.11.2.5

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

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