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