--- loncom/interface/lonmenu.pm 2017/09/10 00:11:27 1.479
+++ loncom/interface/lonmenu.pm 2018/04/27 22:07:11 1.489
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Routines to control the menu
#
-# $Id: lonmenu.pm,v 1.479 2017/09/10 00:11:27 raeburn Exp $
+# $Id: lonmenu.pm,v 1.489 2018/04/27 22:07:11 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -99,7 +99,7 @@ It gets filled in the BEGIN block of thi
=over
-=item prep_menuitems(\@menuitem)
+=item prep_menuitems(\@menuitem,$ltitarget)
This routine wraps a menuitem in proper HTML. It is used by primary_menu() and
secondary_menu().
@@ -210,16 +210,17 @@ use Apache::lonenc();
use Apache::lonlocal;
use Apache::lonmsg();
use LONCAPA qw(:DEFAULT :match);
+use LONCAPA::ltiutils;
use HTML::Entities();
use Apache::lonwishlist();
use vars qw(@desklines %category_names %category_members %category_positions
- $readdesk @primary_menu %primary_submenu @secondary_menu);
+ $readdesk @primary_menu %primary_submenu @secondary_menu %secondary_submenu);
my @inlineremote;
sub prep_menuitem {
- my ($menuitem) = @_;
+ my ($menuitem,$ltitarget) = @_;
return '' unless(ref($menuitem) eq 'ARRAY');
my $link;
if ($$menuitem[1]) { # graphical Link
@@ -229,10 +230,14 @@ sub prep_menuitem {
} else { # textual Link
$link = &mt($$menuitem[3]);
}
+ my $target = ' target="_top"';
+ if ($ltitarget eq 'iframe') {
+ $target ='';
+ }
return '
$link|;
+ . qq| href="$$menuitem[0]"$target>$link|;
}
# primary_menu() evaluates @primary_menu and returns a two item array,
@@ -260,6 +265,10 @@ sub primary_menu {
my %roles_in_env;
$rolecount = &Apache::lonroles::roles_from_env(\%roles_in_env,$update);
}
+ my $ltitarget;
+ if ($env{'request.lti.login'}) {
+ $ltitarget = $env{'request.lti.target'};
+ }
foreach my $menuitem (@primary_menu) {
# evaluate conditions
next if ref($menuitem) ne 'ARRAY'; #
@@ -293,7 +302,9 @@ sub primary_menu {
my ($link,$target);
if ($menuitem->[0] ne '') {
$link = $menuitem->[0];
- $target = '_top';
+ unless ($ltitarget eq 'iframe') {
+ $target = '_top';
+ }
} else {
$link = '#';
}
@@ -328,13 +339,13 @@ sub primary_menu {
'helpdeskmail',
$defdom,$origmail);
if ($to ne '') {
- $menu{$position} .= &prep_menuitem($menuitem);
+ $menu{$position} .= &prep_menuitem($menuitem,$ltitarget);
}
} else {
$menu{$position} .= ''.&Apache::loncommon::top_nav_help('Help').'';
}
} else {
- $menu{$position} .= prep_menuitem($menuitem);
+ $menu{$position} .= prep_menuitem($menuitem,$ltitarget);
}
}
my @output = ('','');
@@ -394,6 +405,7 @@ sub secondary_menu {
my $canmodpara = &Apache::lonnet::allowed('opa', $crs_sec);
my $canvgr = &Apache::lonnet::allowed('vgr', $crs_sec);
my $canmgr = &Apache::lonnet::allowed('mgr', $crs_sec);
+ my $canplc = &Apache::lonnet::allowed('plc', $crs_sec);
my $author = &getauthor();
my ($cdom,$cnum,$showsyllabus,$showfeeds,$showresv,$grouptools);
@@ -401,10 +413,7 @@ sub secondary_menu {
if ($env{'request.course.id'}) {
$cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
$cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
- if ($canedit || $canvieweditor) {
- $showsyllabus = 1;
- $showfeeds = 1;
- } else {
+ unless ($canedit || $canvieweditor) {
unless (&Apache::lonnet::is_on_map("public/$cdom/$cnum/syllabus")) {
if (($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'}) ||
($env{'course.'.$env{'request.course.id'}.'.uploadedsyllabus'}) ||
@@ -444,7 +453,10 @@ sub secondary_menu {
$canmodifycoauthor = 1;
}
}
- my ($roleswitcher_js,$roleswitcher_form);
+ my ($roleswitcher_js,$roleswitcher_form,$ltitarget);
+ if ($env{'request.lti.login'}) {
+ $ltitarget = $env{'request.lti.target'};
+ }
foreach my $menuitem (@secondary_menu) {
# evaluate conditions
@@ -471,25 +483,60 @@ sub secondary_menu {
&& !$canviewwnew;
next if $$menuitem[4] eq 'params'
&& (!$canmodpara && !$canviewpara);
- next if $$menuitem[4] =~ /showgroups$/
- && !$canviewgrps
- && !$grouptools;
+ next if $$menuitem[4] eq 'showgroups'
+ && ($canviewgrps || !$grouptools);
next if $$menuitem[4] eq 'showsyllabus'
&& !$showsyllabus;
next if $$menuitem[4] eq 'showfeeds'
&& !$showfeeds;
+ next if $$menuitem[4] eq 'plc'
+ && !$canplc;
next if $$menuitem[4] eq 'author'
&& !$author;
next if $$menuitem[4] eq 'cca'
&& !$canmodifycoauthor;
- if ($$menuitem[3] eq 'Roles' && $env{'request.course.id'}) {
+ my $title = $menuitem->[3];
+ if (defined($secondary_submenu{$title})) {
+ my ($link,$target);
+ if ($menuitem->[0] ne '') {
+ $link = $menuitem->[0];
+ unless ($ltitarget eq 'iframe') {
+ $target = '_top';
+ }
+ } else {
+ $link = '#';
+ }
+ my @scndsub;
+ if (ref($secondary_submenu{$title}) eq 'ARRAY') {
+ foreach my $item (@{$secondary_submenu{$title}}) {
+ if (ref($item) eq 'ARRAY') {
+ next if ($item->[2] eq 'vgr' && !$canvgr);
+ next if ($item->[2] eq 'opa' && !$canmodpara);
+ next if ($item->[2] eq 'vpa' && !$canviewpara);
+ next if ($item->[2] eq 'viewusers' && !($canmodifyuser || $canviewusers));
+ next if ($item->[2] eq 'mgr' && !$canmgr);
+ next if ($item->[2] eq 'vcg' && !$canviewgrps);
+ next if ($item->[2] eq 'crsedit' && !$canedit && !$canvieweditor);
+ next if ($item->[2] eq 'params' && !$canmodpara && !$canviewpara);
+ next if ($item->[2] eq 'author' && !$author);
+ next if ($item->[2] eq 'cca' && !$canmodifycoauthor);
+ push(@scndsub,$item);
+ }
+ }
+ if (@scndsub > 0) {
+ $menu .= &create_submenu($link,$target,$title,\@scndsub,1);
+ } elsif ($link ne '#') {
+ $menu .= ''.&mt($title).'';
+ }
+ }
+ } elsif ($$menuitem[3] eq 'Roles' && $env{'request.course.id'}) {
# special treatment for role selector
($roleswitcher_js,$roleswitcher_form,my $switcher) =
&roles_selector(
$env{'course.' . $env{'request.course.id'} . '.domain'},
$env{'course.' . $env{'request.course.id'} . '.num'},
- $httphost
+ $httphost,$ltitarget
);
$menu .= $switcher;
} else {
@@ -515,7 +562,7 @@ sub secondary_menu {
}
$$menuitem[0] = &HTML::Entities::encode($$menuitem[0],'&<>"');
}
- $menu .= &prep_menuitem(\@$menuitem);
+ $menu .= &prep_menuitem(\@$menuitem,$ltitarget);
}
}
if ($menu =~ /\[url\].*\[symb\]/) {
@@ -538,7 +585,8 @@ sub secondary_menu {
}
$menu =~ s/\[uname\]/$$author{user}/g;
$menu =~ s/\[udom\]/$$author{dom}/g;
- if ($showsyllabus || $showfeeds) {
+ $menu =~ s/\[javascript\]/javascript:/;
+ if ($env{'request.course.id'}) {
$menu =~ s/\[cnum\]/$cnum/g;
$menu =~ s/\[cdom\]/$cdom/g;
}
@@ -621,9 +669,25 @@ sub build_submenu {
next unless (($env{'user.name'} ne '') && ($env{'user.domain'} ne ''));
$href =~ s/\[domain\]/$env{'user.domain'}/g;
$href =~ s/\[user\]/$env{'user.name'}/g;
+ } elsif (($href =~ m{^/adm/preferences\?}) && ($href =~ /\[returnurl\]/)) {
+ my $returnurl = $ENV{'REQUEST_URI'};
+ if ($ENV{'REQUEST_URI'} =~ m{/adm/preferences\?action=(?:changedomcoord|authorsettings)\&returnurl=([^\&]+)$}) {
+ $returnurl = $1;
+ }
+ if (($returnurl =~ m{^/adm/createuser($|\?action=)}) ||
+ ($returnurl =~ m{^/priv/$match_domain/$match_username}) ||
+ ($returnurl =~ m{^/res(/?$|/$match_domain/$match_username)})) {
+ $returnurl =~ s{\?.*$}{};
+ $returnurl = '&returnurl='.&HTML::Entities::encode($returnurl,'"<>&\'');
+ } else {
+ undef($returnurl);
+ }
+ $href =~ s/\[returnurl\]/$returnurl/;
}
unless (($href eq '') || ($href =~ /^\#/)) {
- $target = ' target="_top"';
+ if ($target eq '_top') {
+ $target = ' target="_top"';
+ }
}
$menu .= '';
@@ -646,13 +710,18 @@ sub innerregister {
undef(@inlineremote);
- my ($mapurl,$resurl,$crstype,$navmap);
+ my ($mapurl,$resurl,$crstype,$navmap,$ltiscope,$ltiuri);
if ($env{'request.course.id'}) {
#
#course_type: Course, Community, or Placement
#
$crstype = &Apache::loncommon::course_type();
+ if (($env{'request.lti.login'}) && ($env{'request.lti.uri'})) {
+ my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
+ my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+ ($ltiscope,$ltiuri) = &LONCAPA::ltiutils::lti_provider_scope($env{'request.lti.uri'},$cdom,$cnum);
+ }
if ($env{'request.symb'}) {
my $ignorenull;
unless ($env{'request.noversionuri'} eq '/adm/navmaps') {
@@ -667,22 +736,29 @@ sub innerregister {
my (@crumbs,@mapcrumbs);
if (($env{'request.noversionuri'} ne '/adm/navmaps') && ($mapurl ne '') &&
(!(($crstype eq 'Placement') && !$env{'request.role.adv'}))) {
- $navmap = Apache::lonnavmaps::navmap->new();
- if (ref($navmap)) {
- @mapcrumbs = $navmap->recursed_crumbs($mapurl,$restitle);
+ unless ($ltiscope eq 'resource') {
+ if (($mapurl ne $env{'course.'.$env{'request.course.id'}.'.url'}) &&
+ !(($ltiscope eq 'map') && (&Apache::lonnet::clutter($resurl) eq $ltiuri))) {
+ $navmap = Apache::lonnavmaps::navmap->new();
+ if (ref($navmap)) {
+ @mapcrumbs = $navmap->recursed_crumbs($mapurl,$restitle);
+ }
+ }
}
}
unless (($forcereg) &&
($env{'request.noversionuri'} eq '/adm/navmaps') &&
($mapurl eq $env{'course.'.$env{'request.course.id'}.'.url'}) ||
- (($crstype eq 'Placement') && (!$env{'request.role.adv'}))) {
+ (($crstype eq 'Placement') && (!$env{'request.role.adv'})) ||
+ ($ltiscope eq 'map') || ($ltiscope eq 'resource')) {
@crumbs = ({text => $crstype.' Contents',
href => "Javascript:gopost('/adm/navmaps','')"});
}
if ($mapurl ne $env{'course.'.$env{'request.course.id'}.'.url'}) {
if (@mapcrumbs) {
push(@crumbs,@mapcrumbs);
- } elsif (!(($crstype eq 'Placement') && (!$env{'request.role.adv'}))) {
+ } elsif (!(($crstype eq 'Placement') && (!$env{'request.role.adv'})) &&
+ ($ltiscope ne 'map') && ($ltiscope ne 'resource')) {
push(@crumbs, {text => '...',
no_mt => 1});
}
@@ -690,8 +766,10 @@ sub innerregister {
unless ((($crstype eq 'Placement') && (!$env{'request.role.adv'})) || (@mapcrumbs) ||
(!$maptitle) || ($maptitle eq 'default.sequence') ||
- ($mapurl eq $env{'course.'.$env{'request.course.id'}.'.url'})) {
- push @crumbs, {text => $maptitle, no_mt => 1, href => $mapurl};
+ ($mapurl eq $env{'course.'.$env{'request.course.id'}.'.url'}) ||
+ ($ltiscope eq 'resource')) {
+ push @crumbs, {text => $maptitle, no_mt => 1,
+ href => &Apache::lonnet::clutter($mapurl).'?navmap=1'};
}
if ($restitle && !@mapcrumbs) {
push(@crumbs,{text => $restitle, no_mt => 1});
@@ -777,8 +855,14 @@ sub innerregister {
$perms{'mdc'} = &Apache::lonnet::allowed('mdc',$env{'request.course.id'});
$perms{'cev'} = &Apache::lonnet::allowed('cev',$env{'request.course.id'});
my @privs;
+ my $gradable_exttool;
if ($env{'request.symb'} ne '') {
- if ($env{'request.filename'}=~/$LONCAPA::assess_re/) {
+ if ($env{'request.noversionuri'} =~ m{^/adm/$cdom/$cnum/(\d+)/ext\.tool$}) {
+ if (&Apache::lonnet::EXT('resource.0.gradable') =~ /^yes$/i) {
+ $gradable_exttool = 1;
+ push(@privs,('mgr','vgr'));
+ }
+ } elsif ($env{'request.filename'}=~/$LONCAPA::assess_re/) {
push(@privs,('mgr','vgr'));
}
push(@privs,('opa','vpa'));
@@ -793,8 +877,8 @@ sub innerregister {
#
# Determine whether or not to show Grades and Submissions buttons
#
- if ($env{'request.symb'} ne '' &&
- $env{'request.filename'}=~/$LONCAPA::assess_re/) {
+ if (($env{'request.symb'} ne '') &&
+ (($env{'request.filename'}=~/$LONCAPA::assess_re/) || ($gradable_exttool))) {
if ($perms{'mgr'}) {
&switch('','',7,2,'pgrd.png','Content Grades','grades[_4]',
"gocmd('/adm/grades','gradingmenu')",
@@ -878,7 +962,35 @@ ENDMENUITEMS
# Should probably be in mydesk.tab
#
$menuitems = "c&3&1";
- if (($crstype ne 'Placement') || ($env{'request.role.adv'})) {
+ if ($ltiscope eq 'resource') {
+# Suppress display of backward arrow for LTI Provider if scope is resource.
+# Suppress display of forward arrow for LTI Provider if scope is resource.
+ } elsif ($ltiscope eq 'map') {
+# Suppress display of backward arrow for LTI Provider if scope is map and this is first resource.
+# Suppress display of forward arrow for LTI Provider if scope is map and this is the last resource.
+ my $showforw = 1;
+ my $showback = 1;
+ my $navmap = Apache::lonnavmaps::navmap->new();
+ if (ref($navmap)) {
+ my $mapres = $navmap->getResourceByUrl($ltiuri);
+ if (ref($mapres)) {
+ if ($navmap->isLastResource($mapres,$env{'request.symb'})) {
+ $showforw = 0;
+ }
+ if ($navmap->isFirstResource($mapres,$env{'request.symb'})) {
+ $showback = 0;
+ }
+ }
+ }
+ if ($showback) {
+ $menuitems.="
+s&2&1&back.png&&&gopost('/adm/flip','back:'+currentURL)&Previous content resource&&1";
+ }
+ if ($showforw) {
+ $menuitems.="
+s&2&3&forw.png&&&gopost('/adm/flip','forward:'+currentURL)&Next content resource&&3";
+ }
+ } elsif (($crstype ne 'Placement') || ($env{'request.role.adv'})) {
$menuitems.="
s&2&1&back.png&&&gopost('/adm/flip','back:'+currentURL)&Previous content resource&&1
s&2&3&forw.png&&&gopost('/adm/flip','forward:'+currentURL)&Next content resource&&3";
@@ -936,14 +1048,15 @@ if ($env{'browser.mobile'}) {
$is_mobile = 1;
}
- unless ($env{'request.noversionuri'}=~/\/(bulletinboard|smppg|navmaps|syllabus|aboutme|viewclasslist|portfolio|ext\.tool)(\?|$)/) {
- if ((!$env{'request.enc'}) && ($env{'request.noversionuri'} !~ m{^/adm/wrapper/ext/}) && ($env{'request.noversionuri'} !~ m{^/uploaded/$match_domain/$match_courseid/docs/})) {
+ unless ($env{'request.noversionuri'}=~/\/(bulletinboard|smppg|navmaps|syllabus|aboutme|viewclasslist|portfolio)(\?|$)/) {
+ if ((!$env{'request.enc'}) && ($env{'request.noversionuri'} !~ m{^/adm/wrapper/ext/}) && ($env{'request.noversionuri'} !~ m{^/uploaded/$match_domain/$match_courseid/docs/}) && ($env{'request.noversionuri'} !~ m{^/adm/.+/ext\.tool$})) {
$menuitems.=(< 0) {
@@ -1934,6 +2071,11 @@ sub utilityfunctions {
my $countdown = &countdown_toggle_js();
+ my $ltitarget;
+ if ($env{'request.lti.login'}) {
+ $ltitarget = $env{'request.lti.target'};
+ }
+
my $hostvar = '
function setLCHost() {
var lcHostname="";
@@ -2030,7 +2172,12 @@ function golist(url) {
currentURL = null;
currentSymb= null;
var lcHostname = setLCHost();
- top.location.href=lcHostname+url;
+ var ltitarget = '$ltitarget';
+ if (ltitarget == 'iframe') {
+ document.location.href=lcHostname+url;
+ } else {
+ top.location.href=lcHostname+url;
+ }
}
}
@@ -2083,6 +2230,12 @@ function open_StoredLinks_Import(rat) {
newWin.focus();
}
+function open_source() {
+ var url = escape(window.location.pathname);
+ sourcewin=window.open('/adm/source?inhibitmenu=yes&viewonly=1&filename='+url,'LONsource',
+ 'height=500,width=600,resizable=yes,location=no,menubar=no,toolbar=no,scrollbars=yes');
+}
+
(function (\$) {
\$(document).ready(function () {
\$.single=function(a){return function(b){a[0]=b;return a}}(\$([1]));
@@ -2103,8 +2256,12 @@ ENDUTILITY
}
sub serverform {
+ my $target;
+ unless (($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) {
+ $target = ' target="_top"';
+ }
return(<
+