Annotation of rat/lonwrapper.pm, revision 1.86

1.1       www         1: # The LearningOnline Network with CAPA
                      2: # Wrapper for external and binary files as standalone resources
                      3: #
1.86    ! raeburn     4: # $Id: lonwrapper.pm,v 1.85 2023/11/18 21:50:06 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.50      raeburn    40: use Apache::lonexttool();
1.68      raeburn    41: use Apache::lonhomework();
1.78      raeburn    42: use Apache::lonnavmaps();
1.64      raeburn    43: use LONCAPA qw(:DEFAULT :match);
                     44: use HTML::Entities();
1.78      raeburn    45: use Digest::MD5();
1.1       www        46: 
                     47: # ================================================================ Main Handler
1.21      albertel   48: sub wrapper {
1.69      raeburn    49:     my ($r,$url,$brcrum,$absolute,$is_ext,$is_pdf,$exttool,$linktext,$explanation,
1.80      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.77      raeburn    61:     (undef,undef,undef,undef,undef,undef,my $clientmobile) =
                     62:         &Apache::loncommon::decode_user_agent($r);
                     63: 
1.69      raeburn    64:     my ($anchor,$uselink);
1.53      raeburn    65:     if ($is_ext) {
                     66:         if ($env{'form.symb'}) {
                     67:             (undef,undef,my $res) = &Apache::lonnet::decode_symb($env{'form.symb'});
                     68:             if ($res =~ /(#[^#]+)$/) {
                     69:                 $anchor = $1;
                     70:             }
                     71:         } elsif ($env{'form.anchor'} ne '') {
                     72:             $anchor = '#'.$env{'form.anchor'};
1.51      raeburn    73:         }
1.78      raeburn    74:         if (($is_ext eq 'tab') || ($is_ext eq 'window')) {
                     75:             $uselink = 1;
                     76:         }
                     77:         unless (($is_pdf && $clientmobile) || $uselink) {
1.69      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.51      raeburn    83:     }
                     84: 
1.84      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.57      raeburn    94:         $args->{'use_absolute'} = $absolute;
1.44      raeburn    95:     }
1.56      raeburn    96:     if ($env{'form.only_body'}) {
                     97:         $args->{'only_body'} = $env{'form.only_body'};
1.83      raeburn    98:     } elsif (($is_supp) && ($env{'form.folderpath'} ne '')) {
                     99:         $args->{'bread_crumbs_nomenu'} = 1;
1.56      raeburn   100:     }
1.42      raeburn   101: 
1.73      raeburn   102:     my ($countdown,$donemsg,$headjs);
1.67      raeburn   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'}) {
1.68      raeburn   106:             my $symb=&Apache::lonnet::symbread($url);
                    107:             my @interval=&Apache::lonnet::EXT('resource.0.interval',$symb);
1.67      raeburn   108:             my ($timelimit) = split(/_/,$interval[0]);
1.68      raeburn   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:             }
1.67      raeburn   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 ='
1.66      raeburn   129: <script type="text/javascript">
                    130: // <![CDATA['."\n".
                    131:                              &Apache::lonhtmlcommon::countdown().'
                    132: // ]]>
                    133: </script>'."\n".
1.67      raeburn   134:                     &Apache::lonhtmlcommon::set_due_date($resource_due);
                    135:                 }
1.66      raeburn   136:             }
1.67      raeburn   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();
1.66      raeburn   145:         }
                    146:     }
                    147: 
1.73      raeburn   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.77      raeburn   155:     unless ($clientmobile || ($exttool eq 'window') || ($exttool eq 'tab') || $uselink) {
1.85      raeburn   156:         $headjs = &Apache::loncommon::iframe_wrapper_headjs();
1.74      raeburn   157:     }
1.73      raeburn   158: 
                    159:     my $startpage = &Apache::loncommon::start_page('Menu',$headjs,$args).$countdown.$donemsg;
1.67      raeburn   160:     my $endpage = &Apache::loncommon::end_page();
                    161: 
1.69      raeburn   162:     if (($uselink) && ($title eq '')) {
                    163:         if ($env{'form.symb'}) {
                    164:             $title=&Apache::lonnet::gettitle($env{'form.symb'});
1.80      raeburn   165:         } elsif (!$is_supp) {
1.69      raeburn   166:             my $symb=&Apache::lonnet::symbread($r->uri);
                    167:             if ($symb) {
                    168:                 $title=&Apache::lonnet::gettitle($symb);
                    169:             }
                    170:         }
                    171:     }
1.78      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.69      raeburn   176:             $linktext = &mt('Link to PDF (for mobile devices)');
                    177:             $output .= &create_link($url,$anchor,$title,$linktext);
1.78      raeburn   178:         } elsif (($exttool eq 'window') || ($exttool eq 'tab') ||
                    179:                  ($is_ext eq 'tab') || ($is_ext eq 'window')) {
                    180:             my $preamble;
1.60      raeburn   181:             if ($linktext eq '') {
1.78      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.60      raeburn   192:             }
1.78      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.63      raeburn   209:                            $linktext.'</a>'.
                    210:                            '</div>';
                    211:             } else {
1.78      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.80      raeburn   224:                             unless (($is_supp) || ($env{'form.folderpath'} =~ /^supplemental/)) {
1.78      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.63      raeburn   245:                 $output .= <<"ENDLINK";
                    246: <script type="text/javascript">
1.64      raeburn   247: // <![CDATA[
1.70      raeburn   248: var windowObjectReference = null;
                    249: var PreviousUrl;
                    250: 
1.63      raeburn   251: function openSinglePopup(strUrl) {
                    252:     if (windowObjectReference == null || windowObjectReference.closed) {
1.78      raeburn   253:         windowObjectReference = window.open(strUrl, "$target",
1.63      raeburn   254:                                             "height=$height,width=$width,scrollbars=yes,resizable=yes,status=yes,menubar=no,location=no'");
                    255:     } else if(PreviousUrl != strUrl) {
1.78      raeburn   256:         windowObjectReference = window.open(strUrl, "$target",
1.63      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: }
1.64      raeburn   264: // ]]>
1.63      raeburn   265: </script>
1.78      raeburn   266: <div>$preamble
                    267: <a href="$url" target="$target" onclick="openSinglePopup(this.href); return false;">
                    268: $linktext$extlinkimg</a>
1.63      raeburn   269: </div>
                    270: ENDLINK
                    271:             }
1.78      raeburn   272:             if ($exttool) {
                    273:                 if ($explanation ne '') {
                    274:                     $output .= '<div>'.$explanation.'</div>';
                    275:                 }
                    276:                 if (&Apache::lonnet::EXT('resource.0.gradable')) {
                    277:                     $output .= &Apache::lonfeedback::list_discussion('tool','OPEN');
                    278:                 }
1.66      raeburn   279:             }
1.47      raeburn   280:         } else {
1.69      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.69      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.85      raeburn   300:         my $script = &Apache::loncommon::iframe_wrapper_resizejs();
1.64      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.64      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.69      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.60      raeburn   341:     my ($is_ext,$brcrum,$absolute,$is_pdf,$exttool,$cdom,$cnum,$hostname,
1.80      raeburn   342:         $linktext,$explanation,$width,$height,$reuse,$is_supp);
1.38      droeschl  343: 
                    344:     for ($url){
                    345:         s|^/adm/wrapper||;
1.73      raeburn   346:         $is_ext = $_ =~ s|^/ext/|http://|;
1.76      raeburn   347:         s|http://https://|https://| if ($is_ext);
1.70      raeburn   348:         s|&colon;|:|g;
1.21      albertel  349:     }
                    350: 
1.47      raeburn   351:     if ($url =~ /\.pdf$/i) {
                    352:         $is_pdf = 1;
1.78      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 = '';
1.79      raeburn   367:                 }
1.78      raeburn   368:             } else {
                    369:                 $width = '';
                    370:                 $height = '';
                    371:                 $reuse = '';
                    372:             }
                    373:         }
1.62      raeburn   374:     } elsif ($url =~ m{^/adm/($match_domain)/($match_courseid)/(\d+)/ext\.tool$}) {
1.50      raeburn   375:         $cdom = $1;
                    376:         $cnum = $2;
                    377:         my $marker = $3;
                    378:         $exttool = 'iframe';
1.61      raeburn   379:         my $exttoolremote;
1.63      raeburn   380:         my %toolhash = &Apache::lonnet::get('exttool_'.$marker,['target','linktext','explanation','id','width','height'],
1.60      raeburn   381:                                             $cdom,$cnum);
1.61      raeburn   382:         if ($toolhash{'id'}) {
1.82      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.61      raeburn   393:             }
                    394:         }
1.50      raeburn   395:         if ($toolhash{'target'} eq 'window') {
1.63      raeburn   396:             $exttool = 'window';
                    397:             $width = $toolhash{'width'};
                    398:             $height = $toolhash{'height'};
                    399:         } elsif ($toolhash{'target'} eq 'tab') {
1.70      raeburn   400:             $exttool = 'tab';
1.63      raeburn   401:         }
                    402:         if (($exttool eq 'window') || ($exttool eq 'tab')) {
1.70      raeburn   403:             $linktext = $toolhash{'linktext'};
1.60      raeburn   404:             $explanation = $toolhash{'explanation'};
1.61      raeburn   405:         } elsif (($exttoolremote =~ /^http:/) && ($ENV{'SERVER_PORT'} == 443)) {
1.63      raeburn   406:             $exttool = 'tab';
1.50      raeburn   407:         }
1.47      raeburn   408:     }
1.50      raeburn   409:     if (($is_ext) || ($exttool)) {
1.42      raeburn   410:         &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.83      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.53      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.80      raeburn   425:                 $is_supp = 1;
1.52      raeburn   426:             }
1.50      raeburn   427:             my $type = 'ext';
                    428:             if ($exttool) {
                    429:                 $type = 'tool';
1.58      raeburn   430:             } elsif (($url =~ /^http:/) && ($ENV{'SERVER_PORT'} == 443)) {
                    431:                 $hostname = $r->hostname();
1.50      raeburn   432:             }
1.42      raeburn   433:             $r->print(
                    434:                 &Apache::lonextresedit::display_editor($url,$env{'form.folderpath'},
                    435:                                                        $env{'form.symb'},
1.50      raeburn   436:                                                        $env{'form.idx'},$type,$cdom,
1.58      raeburn   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.50      raeburn   443:                 if ($is_ext) {
                    444:                     $title = &mt('External Resource');
                    445:                 } else {
                    446:                     $title = &mt('External Tool');
                    447:                 }
1.43      raeburn   448:             }
1.81      raeburn   449:             $title = &HTML::Entities::encode($title,'\'"<>&');
1.80      raeburn   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.83      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.80      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.83      raeburn   467:                                                     ['folderpath','title','only_body']);
1.80      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'};
1.81      raeburn   474:             $title = &HTML::Entities::encode($title,'\'"<>&');
1.80      raeburn   475:             my $crstype = &Apache::loncommon::course_type();
1.83      raeburn   476:             unless ($env{'form.only_body'}) {
                    477:                 $brcrum =
                    478:                     &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
                    479:             }
1.80      raeburn   480:         }
1.42      raeburn   481:     }
                    482: 
1.21      albertel  483: #
                    484: # Actual URL
                    485: #
1.62      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.50      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.59      raeburn   507:         unless ($is_ext) {
1.50      raeburn   508:             &Apache::lonenc::check_encrypt(\$url);
                    509:         }
1.38      droeschl  510: 
1.69      raeburn   511:         $r->print( wrapper($r,$url,$brcrum,$absolute,$is_ext,$is_pdf,$exttool,
1.80      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.86    ! raeburn   540: =item wrapper()
        !           541: 
        !           542: Args: $r,$url,$brcrum,$absolute,$is_ext,$is_pdf,$exttool,$linktext,$explanation,$title,$width,$height,$reuse,$is_supp
1.30      jms       543: 
1.45      raeburn   544: =over
                    545: 
1.69      raeburn   546: =item $r
                    547: 
                    548: request object
                    549: 
1.46      raeburn   550: =item $url
                    551: 
1.71      raeburn   552: url to display either by including in an iframe within a
                    553: LON-CAPA page which has a standard LON-CAPA inline menu,
                    554: or in some cases launched in a separate tab or window,
                    555: launched via a link in a LON-CAPA page with standard inline
                    556: menu.
1.45      raeburn   557: 
                    558: =item $brcrum
                    559: 
                    560: breadcrumbs for unregistered urls
1.42      raeburn   561: (i.e., external resources in Supplemental Content).
1.45      raeburn   562: 
1.46      raeburn   563: =item $absolute
1.45      raeburn   564: 
                    565: contains protocol (http or https) followed by
                    566: the hostname, if menu items in the standard LON-CAPA
                    567: interface created by the call to loncommon::start_page()
                    568: within &wrapper() need to use absolute URLs rather than
                    569: relative URLs.
                    570: 
                    571: That will be the case where an external resource has been 
                    572: served from port 80, when the server customarily serves
                    573: requests using Apache/SSL (i.e., port 443). mod_rewrite 
1.49      raeburn   574: is used to switch requests for external resources and
                    575: the syllabus: /public/<domain>/<courseid>/syllabus
                    576: (which might also point at an external resource)
1.45      raeburn   577: from https:// to http:// where the the URL of the remote site 
                    578: specified in the resource itself is http://.
                    579: 
                    580: This is done to avoid default mixed content blocking
                    581: in Firefox 23 and later, when serving from Apache/SSL.
                    582: 
                    583: =item $is_ext
                    584: 
1.78      raeburn   585: true if URL is for an external resource. Default true value
1.79      raeburn   586: is 1 (display in iframe, unless $uselink is true).
1.78      raeburn   587: If external resource is to be displayed in a tab,
                    588: value of $is_ext will be tab, if to be displayed in a pop-up window,
1.79      raeburn   589: value of $is_ext will be window.
1.45      raeburn   590: 
1.47      raeburn   591: =item $is_pdf
                    592: 
                    593: true if URL is for a PDF (based on file extension).
                    594: 
1.71      raeburn   595: =item $exttool
                    596: 
                    597: If URL is for an External Tool, will contain the target type: iframe, window or tab.
                    598: 
                    599: =item $linktext
                    600: 
1.79      raeburn   601: optional. If URL is for an External Tool, and target type is window or tab,
1.71      raeburn   602: then the link text may be an option set in the course for each tool instance,
                    603: or may be a default defined in the domain for all instances of the tool.
                    604: 
                    605: =item $explanation
                    606: 
1.79      raeburn   607: optional. If URL is for an External Tool, and target type is window or tab,
1.71      raeburn   608: then the explanation is an option set in the course for each tool instance,
                    609: or may be a default defined in the domain for all instances of the tool.
                    610: 
1.49      raeburn   611: =item $title
                    612: 
1.77      raeburn   613: optional. If wrapped item is a PDF, and $clientmobile is true,
                    614: a link to a PDF is shown. The "title" will be displayed
1.49      raeburn   615: above the link, but if not provided as an arg, $env{'form.title'}
                    616: will be used, otherwise, the filename will be displayed (unless
                    617: hidden URL set for the resource).
                    618: 
1.71      raeburn   619: =item $width
                    620: 
                    621: optional. If URL is for an External Tool, and target type is window,
1.79      raeburn   622: then a default width may have been defined in the domain for all instances of
1.71      raeburn   623: the tool.  If so, that width will be used for the window opened (via a link)
1.79      raeburn   624: to launch the external tool. If the URL is for an External Resource, and
1.78      raeburn   625: $is_ext is window, then a default width (px) may have been defined in the current
                    626: course for all external resource instances.
1.71      raeburn   627: 
                    628: =item $height
                    629: 
                    630: optional. If URL is for an External Tool, and target type is window,
1.79      raeburn   631: then a default height may have been defined in the domain for all instances of
1.71      raeburn   632: the tool.  If so, that height will be used for the window opened (via a link)
1.79      raeburn   633: to launch the external tool.  If the URL is for an External Resource, and
1.78      raeburn   634: $is_ext is window, then a default height (px) may have been defined in the current
                    635: course for all external resource instances.
                    636: 
                    637: =item $reuse
                    638: 
                    639: optional. If the URL is for an External Resource, and $is_ext is tab or window,
                    640: then $reuse will be true if the same tab or window is to be reused for display
                    641: of all external resource instances in a a course.
1.71      raeburn   642: 
1.45      raeburn   643: =back
                    644: 
1.38      droeschl  645: Returns markup for the entire page.
1.30      jms       646: 
1.86    ! raeburn   647: =item create_link()
        !           648: 
        !           649: Args: $url,$anchor,$title,$linktext
        !           650: 
        !           651: =over
        !           652: 
        !           653: =item $url
        !           654: 
        !           655: URL to link to
        !           656: 
        !           657: =item $anchor
        !           658: 
        !           659: optional.  Will be the anchor to append to the URL, if there is one.
        !           660: 
        !           661: =item $title
        !           662: 
        !           663: optional. If provided will be the title displayed above the link. If
        !           664: one is not provided, then $env{'form.title'} will be used, unless empty.
        !           665: 
        !           666: =item $linktext
        !           667: 
        !           668: The text to inlcude between the <a href="$url"> and </a> tags.
        !           669: 
        !           670: =back
        !           671: 
        !           672: Returns HTML needed to show a link which can be followed to display the
        !           673: part of the original URL following the initial /adm/wrapper part 
        !           674: in the original request, in the case where an iframe is not going to be
        !           675: used to embed the content available at the URL in the existing page.
        !           676: 
1.30      jms       677: =item handler()
                    678: 
1.71      raeburn   679: Content handler for requests for: /adm/wrapper/...
                    680: used for content to be displayed in an iframe, or launched in a separate tab
                    681: or window via a link.  The target URL is extracted from the requested URL, by
1.79      raeburn   682: removing the /adm/wrapper prefix.
1.71      raeburn   683: 
1.79      raeburn   684: The target URL will typically be a PDF served from the current server, an
1.71      raeburn   685: external resource URL served from a different server, or an external tool
                    686: (from an LTI Provider) launched from LON-CAPA (as LTI Consumer) and launched
                    687: via a link.
                    688: 
                    689: If the request included forceedit in the query string, and the requester has
1.79      raeburn   690: rights to modify course content, then the editor will be displayed to allow
1.71      raeburn   691: changes to be made to the resource (e.g., change the URL of the external resource,
1.79      raeburn   692: or change the setting for the external tool instance).
1.71      raeburn   693: 
                    694: If not in edit mode, then the wrapper() subroutine will be called to generate the
                    695: standard LON-CAPA inline menu, and then either a link to launch a separate tab or
1.79      raeburn   696: window, or an iframe to display the content inline.
1.71      raeburn   697: 
1.30      jms       698: =back
                    699: 
                    700: =cut
1.1       www       701: 

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