Annotation of rat/lonwrapper.pm, revision 1.49.2.11.2.7

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

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