--- rat/lonwrapper.pm 2016/11/30 17:40:39 1.49.2.3 +++ rat/lonwrapper.pm 2016/01/26 14:30:40 1.50 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Wrapper for external and binary files as standalone resources # -# $Id: lonwrapper.pm,v 1.49.2.3 2016/11/30 17:40:39 raeburn Exp $ +# $Id: lonwrapper.pm,v 1.50 2016/01/26 14:30:40 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -37,34 +37,23 @@ use Apache::lonlocal; use Apache::loncommon(); use Apache::lonhtmlcommon(); use Apache::lonextresedit(); +use Apache::lonexttool(); +use LONCAPA qw(:DEFAULT :match);; # ================================================================ Main Handler sub wrapper { - my ($url,$brcrum,$absolute,$is_ext,$is_pdf,$title) = @_; + my ($url,$brcrum,$absolute,$is_ext,$is_pdf,$exttool,$title) = @_; my $forcereg; unless ($env{'form.folderpath'}) { $forcereg = 1; } - my %lt = &Apache::lonlocal::texthash( 'noif' => 'No iframe support.', 'show' => 'Show content in pop-up window', ); - my $anchor; - if ($is_ext) { - if ($env{'form.symb'}) { - (undef,undef,my $res) = &Apache::lonnet::decode_symb($env{'form.symb'}); - if ($res =~ /(#[^#]+)$/) { - $anchor = $1; - } - } elsif ($env{'form.anchor'} ne '') { - $anchor = '#'.$env{'form.anchor'}; - } - } - - my $noiframe = &Apache::loncommon::modal_link($url.$anchor,$lt{'show'},500,400); + my $noiframe = &Apache::loncommon::modal_link($url,$lt{'show'},500,400); my $args = {'bgcolor' => '#FFFFFF'}; if ($forcereg) { $args->{'force_register'} = $forcereg; @@ -78,8 +67,8 @@ sub wrapper { my $startpage = &Apache::loncommon::start_page('Menu',undef,$args); my $endpage = &Apache::loncommon::end_page(); - - if ($env{'browser.mobile'}) { + + if (($env{'browser.mobile'}) || ($exttool eq 'window')) { my $output = $startpage; if ($is_pdf) { if ($title eq '') { @@ -95,9 +84,14 @@ sub wrapper { $output .= $title.'
'; } $output .= ''.&mt('Link to PDF (for mobile devices)').''; + } elsif ($exttool eq 'window') { + $output .= '
'. + ''. + &mt('Launch External Tool').''. + '
'; } else { $output .= '
'."\n". - '\n". "
\n"; @@ -105,16 +99,11 @@ sub wrapper { $output .= $endpage; return $output; } else { - my $offset = 5; - &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']); - if ($env{'form.inhibitmenu'} eq 'yes') { - $offset = 0; - } my $script = &Apache::lonhtmlcommon::scripttag(< - + $endpage ENDFRAME @@ -155,7 +144,7 @@ sub handler { return OK if $r->header_only; my $url = $r->uri; - my ($is_ext,$brcrum,$absolute,$is_pdf); + my ($is_ext,$brcrum,$absolute,$is_pdf,$exttool,$cdom,$cnum); for ($url){ s|^/adm/wrapper||; @@ -164,37 +153,47 @@ sub handler { s|:|:|g; } + if ($url =~ /\.pdf$/i) { $is_pdf = 1; + } elsif ($url =~ m{^/adm/($match_domain)/($match_courseid)/(\d+)/exttools?$}) { + $cdom = $1; + $cnum = $2; + my $marker = $3; + $exttool = 'iframe'; + my %toolhash = &Apache::lonnet::get('exttool_'.$marker,['target'],$cdom,$cnum); + if ($toolhash{'target'} eq 'window') { + $exttool = 'window'; + } } - - if ($is_ext) { + if (($is_ext) || ($exttool)) { &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, - ['forceedit','register','folderpath','symb','idx','title','anchor']); + ['forceedit','register','folderpath','symb','idx','title']); if (($env{'form.forceedit'}) && (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) && (($env{'form.folderpath'} =~ /^supplemental/) || ($env{'form.symb'} =~ /^uploaded/))) { - if ($env{'form.symb'}) { - (undef,undef,my $res) = &Apache::lonnet::decode_symb($env{'form.symb'}); - if ($res =~ /(#[^#]+)$/) { - $url .= $1; - } - } elsif ($env{'form.folderpath'} =~ /^supplemental/) { - if ($env{'form.anchor'} ne '') { - $url .= '#'.$env{'form.anchor'}; - } + my $type = 'ext'; + my %ltitools; + if ($exttool) { + $type = 'tool'; + %ltitools = &Apache::lonnet::get_domain_ltitools($cdom); } $r->print( &Apache::lonextresedit::display_editor($url,$env{'form.folderpath'}, $env{'form.symb'}, - $env{'form.idx'})); + $env{'form.idx'},$type,$cdom, + $cnum,\%ltitools)); return OK; } elsif ($env{'form.folderpath'} =~ /^supplemental/) { my $crstype = &Apache::loncommon::course_type(); my $title = $env{'form.title'}; if ($title eq '') { - $title = &mt('External Resource'); + if ($is_ext) { + $title = &mt('External Resource'); + } else { + $title = &mt('External Tool'); + } } $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1); @@ -214,7 +213,7 @@ sub handler { # # This is not homework # - if ($is_ext) { + if (($is_ext) || ($exttool)) { $absolute = $env{'request.use_absolute'}; $ENV{'QUERY_STRING'} =~ s/(^|\&)symb=[^\&]*/$1/; $ENV{'QUERY_STRING'} =~ s/\&$//; @@ -225,9 +224,11 @@ sub handler { } # encrypt url if not external - &Apache::lonenc::check_encrypt(\$url) if $url !~ /^https?\:/ ; + unless ($is_ext || $exttool) { + &Apache::lonenc::check_encrypt(\$url); + } - $r->print( wrapper($url,$brcrum,$absolute,$is_ext,$is_pdf) ); + $r->print( wrapper($url,$brcrum,$absolute,$is_ext,$is_pdf,$exttool) ); } # not just the menu