--- loncom/interface/lonmenu.pm 2017/10/07 22:20:19 1.482
+++ loncom/interface/lonmenu.pm 2020/01/18 04:37:10 1.500
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Routines to control the menu
#
-# $Id: lonmenu.pm,v 1.482 2017/10/07 22:20:19 raeburn Exp $
+# $Id: lonmenu.pm,v 1.500 2020/01/18 04:37:10 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,6 +210,7 @@ use Apache::lonenc();
use Apache::lonlocal;
use Apache::lonmsg();
use LONCAPA qw(:DEFAULT :match);
+use LONCAPA::ltiutils;
use HTML::Entities();
use Apache::lonwishlist();
@@ -219,7 +220,7 @@ use vars qw(@desklines %category_names %
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,
@@ -242,8 +247,8 @@ sub prep_menuitem {
# @primary_menu is filled within the BEGIN block of this module with
# entries from mydesk.tab
sub primary_menu {
- my ($crstype) = @_;
- my (%menu);
+ my ($crstype,$ltimenu) = @_;
+ my (%menu,%ltiexc);
# each element of @primary contains following array:
# (link url, icon path, alt text, link text, condition, position)
my $public;
@@ -260,6 +265,18 @@ sub primary_menu {
my %roles_in_env;
$rolecount = &Apache::lonroles::roles_from_env(\%roles_in_env,$update);
}
+ my ($lti,$ltitarget);
+ if ($env{'request.lti.login'}) {
+ $lti = 1;
+ $ltitarget = $env{'request.lti.target'};
+ if (ref($ltimenu) eq 'HASH') {
+ foreach my $item ('fullname','logout') {
+ unless ($ltimenu->{$item}) {
+ $ltiexc{$item} = 1;
+ }
+ }
+ }
+ }
foreach my $menuitem (@primary_menu) {
# evaluate conditions
next if ref($menuitem) ne 'ARRAY'; #
@@ -274,9 +291,15 @@ sub primary_menu {
&& !$public; # only visible to public
# users
next if $$menuitem[4] eq 'roles' ##show links depending on
- && &Apache::loncommon::show_course(); ##term 'Courses' or
- next if $$menuitem[4] eq 'courses' ##'Roles' wanted
- && !&Apache::loncommon::show_course(); ##
+ && (&Apache::loncommon::show_course() ##term 'Courses' or
+ || $env{'request.lti.login'}); ##'Roles' wanted
+ next if $$menuitem[4] eq 'courses' ##and not LTI access
+ && (!&Apache::loncommon::show_course()
+ || !$env{'request.lti.login'});
+ next if $$menuitem[4] eq 'notlti'
+ && $lti;
+ next if $$menuitem[4] eq 'ltiexc'
+ && exists($ltiexc{lc($menuitem->[3])});
my $title = $menuitem->[3];
if (($crstype eq 'Placement') && (!$env{'request.role.adv'})) {
if ($menuitem->[4] eq 'courses') {
@@ -293,7 +316,9 @@ sub primary_menu {
my ($link,$target);
if ($menuitem->[0] ne '') {
$link = $menuitem->[0];
- $target = '_top';
+ unless ($ltitarget eq 'iframe') {
+ $target = '_top';
+ }
} else {
$link = '#';
}
@@ -309,7 +334,9 @@ sub primary_menu {
push(@primsub,$item);
}
if ($title eq 'Personal' && $env{'user.name'} && $env{'user.domain'} ) {
- $title = &Apache::loncommon::plainname($env{'user.name'},$env{'user.domain'});
+ unless ($ltiexc{'fullname'}) {
+ $title = &Apache::loncommon::plainname($env{'user.name'},$env{'user.domain'});
+ }
} else {
$title = &mt($title);
}
@@ -328,13 +355,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 = ('','');
@@ -373,7 +400,7 @@ sub getauthor{
}
sub secondary_menu {
- my ($httphost) = @_;
+ my ($httphost,$ltiscope,$ltimenu,$noprimary) = @_;
my $menu;
my $crstype = &Apache::loncommon::course_type();
@@ -394,9 +421,10 @@ 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);
+ my ($cdom,$cnum,$showsyllabus,$showfeeds,$showresv,$grouptools,$lti,$ltimapres,%ltiexc);
$grouptools = 0;
if ($env{'request.course.id'}) {
$cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
@@ -420,10 +448,9 @@ sub secondary_menu {
$showresv = 1;
}
}
- my %groups = &Apache::lonnet::get_active_groups(
- $env{'user.domain'}, $env{'user.name'},$cdom,$cnum);
- if (%groups) {
- foreach my $group (keys(%groups)) {
+ if ($env{'request.course.groups'} ne '') {
+ foreach my $group (split(/:/,$env{'request.course.groups'})) {
+ next unless ($group =~ /^\w+$/);
my @privs = split(/:/,$env{"user.priv.$env{'request.role'}./$cdom/$cnum/$group"});
shift(@privs);
if (@privs) {
@@ -431,6 +458,19 @@ sub secondary_menu {
}
}
}
+ if ($env{'request.lti.login'}) {
+ $lti = 1;
+ if (ref($ltimenu) eq 'HASH') {
+ foreach my $item ('fullname','coursetitle','role','logout','grades') {
+ unless ($ltimenu->{$item}) {
+ $ltiexc{$item} = 1;
+ }
+ }
+ }
+ if (($ltiscope eq 'map') || ($ltiscope eq 'resource')) {
+ $ltimapres = 1;
+ }
+ }
}
my ($canmodifycoauthor);
@@ -441,7 +481,11 @@ 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
@@ -453,7 +497,7 @@ sub secondary_menu {
next if $$menuitem[4] =~ /^crsedit/
&& (!$canedit && !$canvieweditor);
next if $$menuitem[4] eq 'nvgr'
- && $canvgr;
+ && ($canvgr || $ltiexc{'grades'});
next if $$menuitem[4] eq 'vgr'
&& !$canvgr;
next if $$menuitem[4] eq 'viewusers'
@@ -474,17 +518,29 @@ sub secondary_menu {
&& !$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;
+ next if $$menuitem[4] eq 'notltimapres'
+ && $ltimapres;
+ next if $$menuitem[4] eq 'notlti'
+ && $lti;
+ next if $$menuitem[4] eq 'lti'
+ && (!$lti || !$noprimary);
+ next if $$menuitem[3] eq 'Logout'
+ && $ltiexc{'logout'};
my $title = $menuitem->[3];
if (defined($secondary_submenu{$title})) {
my ($link,$target);
if ($menuitem->[0] ne '') {
$link = $menuitem->[0];
- $target = '_top';
+ unless ($ltitarget eq 'iframe') {
+ $target = '_top';
+ }
} else {
$link = '#';
}
@@ -500,9 +556,23 @@ sub secondary_menu {
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);
+ next if ($item->[2] eq 'lti' && !$lti);
+ if ($item->[2] =~ /^lti(portfolio|wishlist|blog)$/) {
+ my $tool = $1;
+ next if !$lti;
+ next if (!&Apache::lonnet::usertools_access('','',$tool,
+ undef,'tools'));
+ }
push(@scndsub,$item);
}
}
+ if ($title eq 'Personal' && $env{'user.name'} && $env{'user.domain'} ) {
+ unless ($ltiexc{'fullname'}) {
+ $title = &Apache::loncommon::plainname($env{'user.name'},$env{'user.domain'});
+ }
+ }
if (@scndsub > 0) {
$menu .= &create_submenu($link,$target,$title,\@scndsub,1);
} elsif ($link ne '#') {
@@ -513,11 +583,14 @@ sub secondary_menu {
# 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
+ $env{'course.' . $env{'request.course.id'} . '.domain'},
+ $env{'course.' . $env{'request.course.id'} . '.num'},
+ $httphost,$ltitarget
);
$menu .= $switcher;
+ } elsif ($$menuitem[3] eq 'Help') { # special treatment for helplink
+ next if ($crstype eq 'Placement');
+ $menu .= ''.&Apache::loncommon::top_nav_help('Help').'';
} else {
if ($$menuitem[3] eq 'Syllabus' && $env{'request.course.id'}) {
my $url = $$menuitem[0];
@@ -531,17 +604,19 @@ sub secondary_menu {
}
if ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://}) {
if (($ENV{'SERVER_PORT'} == 443) || ($env{'request.use_absolute'} =~ m{^https://})) {
- unless ($$menuitem[0] =~ m{^https?://}) {
- $$menuitem[0] = 'http://'.$ENV{'SERVER_NAME'}.$$menuitem[0];
- }
- unless ($$menuitem[0] =~ /(\&|\?)usehttp=1/) {
- $$menuitem[0] .= (($$menuitem[0]=~/\?/) ? '&' : '?').'usehttp=1';
+ unless (&Apache::lonnet::uses_sts()) {
+ unless ($$menuitem[0] =~ m{^https?://}) {
+ $$menuitem[0] = 'http://'.$ENV{'SERVER_NAME'}.$$menuitem[0];
+ }
+ unless ($$menuitem[0] =~ /(\&|\?)usehttp=1/) {
+ $$menuitem[0] .= (($$menuitem[0]=~/\?/) ? '&' : '?').'usehttp=1';
+ }
}
}
}
$$menuitem[0] = &HTML::Entities::encode($$menuitem[0],'&<>"');
}
- $menu .= &prep_menuitem(\@$menuitem);
+ $menu .= &prep_menuitem(\@$menuitem,$ltitarget);
}
}
if ($menu =~ /\[url\].*\[symb\]/) {
@@ -564,6 +639,7 @@ sub secondary_menu {
}
$menu =~ s/\[uname\]/$$author{user}/g;
$menu =~ s/\[udom\]/$$author{dom}/g;
+ $menu =~ s/\[javascript\]/javascript:/g;
if ($env{'request.course.id'}) {
$menu =~ s/\[cnum\]/$cnum/g;
$menu =~ s/\[cdom\]/$cdom/g;
@@ -647,9 +723,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 .= '';
@@ -662,7 +754,7 @@ sub build_submenu {
}
sub innerregister {
- my ($forcereg,$bread_crumbs,$group,$pagebuttonshide,$hostname) = @_;
+ my ($forcereg,$bread_crumbs,$group,$pagebuttonshide,$hostname,$ltiscope,$ltiuri) = @_;
my $const_space = ($env{'request.state'} eq 'construct');
my $is_const_dir = 0;
@@ -693,22 +785,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});
}
@@ -716,8 +815,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});
@@ -803,8 +904,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'));
@@ -819,8 +926,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')",
@@ -904,7 +1011,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";
@@ -962,14 +1097,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.=(<