--- loncom/interface/lonmenu.pm 2023/09/02 15:56:34 1.369.2.83.2.9
+++ loncom/interface/lonmenu.pm 2024/07/03 04:09:36 1.369.2.85
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Routines to control the menu
#
-# $Id: lonmenu.pm,v 1.369.2.83.2.9 2023/09/02 15:56:34 raeburn Exp $
+# $Id: lonmenu.pm,v 1.369.2.85 2024/07/03 04:09:36 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,$target,$listclass,$linkattr)
+=item prep_menuitems(\@menuitem)
This routine wraps a menuitem in proper HTML. It is used by primary_menu() and
secondary_menu().
@@ -240,9 +240,9 @@ use vars qw(@desklines %category_names %
my @inlineremote;
sub prep_menuitem {
- my ($menuitem,$target,$listclass,$linkattr) = @_;
+ my ($menuitem,$listclass,$linkattr) = @_;
return '' unless(ref($menuitem) eq 'ARRAY');
- my ($link,$targetattr);
+ my $link;
if ($$menuitem[1]) { # graphical Link
$link = "':'
').'$link|;
+ . qq| href="$$menuitem[0]" target="_top" $linkattr>$link|;
}
# primary_menu() evaluates @primary_menu and returns a two item array,
@@ -266,8 +263,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,$ltimenu,$menucoll,$menuref,$links_disabled,$links_target) = @_;
- my (%menu,%ltiexc,%menuopts);
+ my ($links_disabled) = @_;
+ my %menu;
# each element of @primary contains following array:
# (link url, icon path, alt text, link text, condition, position)
my $public;
@@ -275,41 +272,6 @@ sub primary_menu {
|| (($env{'user.name'} eq '') && ($env{'user.domain'} eq ''))) {
$public = 1;
}
- my $lti;
- if ($env{'request.lti.login'}) {
- $lti = 1;
- if (ref($ltimenu) eq 'HASH') {
- foreach my $item ('fullname','logout') {
- unless ($ltimenu->{$item}) {
- $ltiexc{$item} = 1;
- }
- }
- }
- }
- my ($listclass,$linkattr,$target);
- if ($links_disabled) {
- $listclass = 'LCisDisabled';
- $linkattr = 'aria-disabled="true"';
- }
- if ($links_target ne '') {
- $target = $links_target;
- } else {
- my ($ltitarget,$deeplinktarget);
- if ($env{'request.lti.login'}) {
- $ltitarget = $env{'request.lti.target'};
- }
- if ($env{'request.deeplink.login'}) {
- $deeplinktarget = $env{'request.deeplink.target'};
- }
- if (($ltitarget eq 'iframe') || ($deeplinktarget eq '_self')) {
- $target = '_self';
- } else {
- $target = '_top';
- }
- }
- if (($menucoll) && (ref($menuref) eq 'HASH')) {
- %menuopts = %{$menuref};
- }
foreach my $menuitem (@primary_menu) {
# evaluate conditions
next if ref($menuitem) ne 'ARRAY'; #
@@ -324,41 +286,25 @@ 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
- || $lti); ##'Roles' wanted
- next if $$menuitem[4] eq 'courses' ##and not LTI access
- && (!&Apache::loncommon::show_course()
- || $lti);
- next if $$menuitem[4] eq 'notlti'
- && $lti;
- next if $$menuitem[4] eq 'ltiexc'
- && exists($ltiexc{lc($menuitem->[3])});
+ && &Apache::loncommon::show_course(); ##term 'Courses' or
+ next if $$menuitem[4] eq 'courses' ##'Roles' wanted
+ && !&Apache::loncommon::show_course(); ##
+
my $title = $menuitem->[3];
my $position = $menuitem->[5];
if ($position eq '') {
$position = 'right';
}
- if ($env{'request.course.id'} && $menucoll) {
- if (($menuitem->[6]) && (!$menuopts{$menuitem->[6]})) {
- if ($menuitem->[6] eq 'pers') {
- if ($menuopts{'name'} && !$ltiexc{'fullname'} &&
- $env{'user.name'} && $env{'user.domain'}) {
- $menu{$position} .= ''.
- &Apache::loncommon::plainname($env{'user.name'},
- $env{'user.domain'}).'';
- next;
- } else {
- next;
- }
- } else {
- next;
- }
- }
+ my ($listclass,$linkattr);
+ if ($links_disabled) {
+ $listclass = 'LCisDisabled';
+ $linkattr = 'aria-disabled="true"';
}
if (defined($primary_submenu{$title})) {
- my $link;
+ my ($link,$target);
if ($menuitem->[0] ne '') {
$link = $menuitem->[0];
+ $target = '_top';
} else {
$link = '#';
}
@@ -370,30 +316,18 @@ sub primary_menu {
($item->[2] eq 'blog')) &&
(!&Apache::lonnet::usertools_access('','',$item->[2],
undef,'tools')));
- if ($env{'request.course.id'} && $menucoll) {
- next if ($item->[3]) && (!$menuopts{$item->[3]});
- }
push(@primsub,$item);
}
- if ($title eq 'Personal') {
- if ($env{'user.name'} && $env{'user.domain'} && !$ltiexc{'fullname'}) {
- unless (($env{'request.course.id'}) && ($menucoll) && (!$menuopts{'name'})) {
- $title = &Apache::loncommon::plainname($env{'user.name'},$env{'user.domain'});
- }
- }
- next if (($env{'request.course.id'}) && ($menucoll) && ($title eq 'Personal') &&
- (!@primsub));
- if ($title eq 'Personal') {
+ if (@primsub > 0) {
+ if ($title eq 'Personal' && $env{'user.name'} && $env{'user.domain'} ) {
+ $title = &Apache::loncommon::plainname($env{'user.name'},$env{'user.domain'});
+ } else {
$title = &mt($title);
}
- } else {
- $title = &mt($title);
- }
- if (@primsub > 0) {
$menu{$position} .= &create_submenu($link,$target,$title,\@primsub,1,undef,$listclass,$linkattr);
} elsif ($link) {
$menu{$position} .= ($listclass?'':'').
- ''.$title.'';
+ ''.&mt($title).'';
}
}
} elsif ($$menuitem[3] eq 'Help') { # special treatment for helplink
@@ -404,7 +338,7 @@ sub primary_menu {
'helpdeskmail',
$defdom,$origmail);
if ($to ne '') {
- $menu{$position} .= &prep_menuitem($menuitem,$target,$listclass,$linkattr);
+ $menu{$position} .= &prep_menuitem($menuitem,$listclass,$linkattr);
}
} else {
$menu{$position} .= ($listclass?'':'').
@@ -417,9 +351,9 @@ sub primary_menu {
$$menuitem[0] = '/adm/login';
}
}
- $menu{$position} .= prep_menuitem($menuitem,$target,$listclass,$linkattr);
+ $menu{$position} .= prep_menuitem($menuitem,$listclass,$linkattr);
} else {
- $menu{$position} .= prep_menuitem($menuitem,$target,$listclass,$linkattr);
+ $menu{$position} .= prep_menuitem($menuitem,$listclass,$linkattr);
}
}
my @output = ('','');
@@ -458,8 +392,7 @@ sub getauthor{
}
sub secondary_menu {
- my ($httphost,$ltiscope,$ltimenu,$noprimary,$menucoll,$menuref,
- $links_disabled,$links_target) = @_;
+ my ($httphost,$links_disabled) = @_;
my $menu;
my $crstype = &Apache::loncommon::course_type();
@@ -480,11 +413,9 @@ 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,
- $lti,$ltimapres,%ltiexc,%menuopts);
+ my ($cdom,$cnum,$showsyllabus,$showfeeds,$showresv,$grouptools);
$grouptools = 0;
if ($env{'request.course.id'}) {
$cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
@@ -518,25 +449,9 @@ 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;
- }
- }
- }
- if (($menucoll) && (ref($menuref) eq 'HASH')) {
- %menuopts = %{$menuref};
}
- my ($listclass,$linkattr,$target);
+ my ($listclass,$linkattr);
if ($links_disabled) {
$listclass = 'LCisDisabled';
$linkattr = 'aria-disabled="true"';
@@ -552,22 +467,6 @@ sub secondary_menu {
}
my ($roleswitcher_js,$roleswitcher_form);
- if ($links_target ne '') {
- $target = $links_target;
- } else {
- my ($ltitarget,$deeplinktarget);
- if ($env{'request.lti.login'}) {
- $ltitarget = $env{'request.lti.target'};
- }
- if ($env{'request.deeplink.login'}) {
- $deeplinktarget = $env{'request.deeplink.target'};
- }
- if (($ltitarget eq 'iframe') || ($deeplinktarget eq '_self')) {
- $target = '_self';
- } else {
- $target = '_top';
- }
- }
foreach my $menuitem (@secondary_menu) {
# evaluate conditions
@@ -582,7 +481,7 @@ sub secondary_menu {
next if $$menuitem[4] eq 'crseditCommunity'
&& ($crstype eq 'Course');
next if $$menuitem[4] eq 'nvgr'
- && ($canvgr || $ltiexc{'grades'});
+ && $canvgr;
next if $$menuitem[4] eq 'vgr'
&& !$canvgr;
next if $$menuitem[4] eq 'viewusers'
@@ -603,33 +502,17 @@ 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 ($env{'request.course.id'} && $menucoll) {
- if ($$menuitem[5] eq 'main') {
- next if ($menuopts{$$menuitem[5]} eq 'n');
- } elsif ($$menuitem[5] ne 'roles') {
- next if (($$menuitem[5]) && (!$menuopts{$$menuitem[5]}));
- }
- }
if (defined($secondary_submenu{$title})) {
- my $link;
+ my ($link,$target);
if ($menuitem->[0] ne '') {
$link = $menuitem->[0];
+ $target = '_top';
} else {
$link = '#';
}
@@ -647,21 +530,9 @@ sub secondary_menu {
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,&mt($title),\@scndsub,1,undef,
$listclass,$linkattr);
@@ -673,16 +544,12 @@ sub secondary_menu {
}
} elsif ($$menuitem[3] eq 'Roles' && $env{'request.course.id'}) {
# special treatment for role selector
- my ($switcher,$has_opa_priv);
- ($roleswitcher_js,$roleswitcher_form,$switcher,$has_opa_priv) =
+ ($roleswitcher_js,$roleswitcher_form,my $switcher) =
&roles_selector(
$env{'course.' . $env{'request.course.id'} . '.domain'},
$env{'course.' . $env{'request.course.id'} . '.num'},
- $httphost,$target,$menucoll,$menuref
+ $httphost
);
- if (($$menuitem[5]) && (!$menuopts{$$menuitem[5]})) {
- next unless ($has_opa_priv);
- }
$menu .= $switcher;
} else {
if ($$menuitem[3] eq 'Syllabus' && $env{'request.course.id'}) {
@@ -709,7 +576,7 @@ sub secondary_menu {
}
$$menuitem[0] = &HTML::Entities::encode($$menuitem[0],'&<>"');
}
- $menu .= &prep_menuitem(\@$menuitem,$target,$listclass,$linkattr);
+ $menu .= &prep_menuitem(\@$menuitem,$listclass,$linkattr);
}
}
if ($menu =~ /\[url\].*\[symb\]/) {
@@ -732,7 +599,6 @@ 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;
@@ -749,12 +615,12 @@ sub secondary_menu {
sub create_submenu {
my ($link,$target,$title,$submenu,$translate,$addclass,$listclass,$linkattr) = @_;
return unless (ref($submenu) eq 'ARRAY');
- my $targetattr;
- if (($target ne '') && ($link ne '#')) {
- $targetattr = ' target="'.$target.'"';
+ my $disptarget;
+ if ($target ne '') {
+ $disptarget = ' target="'.$target.'"';
}
my $menu = ''.
- ''.
+ ''.
''.$title.
''.
' ▼'.
@@ -831,17 +697,14 @@ sub build_submenu {
}
$href =~ s/\[returnurl\]/$returnurl/;
}
- my $targetattr;
unless (($href eq '') || ($href =~ /^\#/)) {
- if ($target ne '') {
- $targetattr = ' target="'.$target.'"';
- }
+ $target = ' target="_top"';
}
$menu .= '';
- $menu .= '' . $title . '';
+ $menu .= '' . $title . '';
$menu .= '';
}
}
@@ -878,8 +741,7 @@ sub registerurl {
}
sub innerregister {
- my ($forcereg,$bread_crumbs,$group,$pagebuttonshide,$hostname,
- $ltiscope,$ltiuri,$showncrumbsref) = @_;
+ my ($forcereg,$bread_crumbs,$group,$pagebuttonshide,$hostname) = @_;
my $const_space = ($env{'request.state'} eq 'construct');
my $is_const_dir = 0;
@@ -920,33 +782,26 @@ sub innerregister {
my $restitle = &Apache::lonnet::gettitle($symb);
my (@crumbs,@mapcrumbs);
- if (($env{'request.noversionuri'} ne '/adm/navmaps') && ($mapurl ne '')) {
- 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);
- }
- }
+ if (($env{'request.noversionuri'} ne '/adm/navmaps') && ($mapurl ne '') &&
+ ($mapurl ne $env{'course.'.$env{'request.course.id'}.'.url'})) {
+ $navmap = Apache::lonnavmaps::navmap->new();
+ if (ref($navmap)) {
+ @mapcrumbs = $navmap->recursed_crumbs($mapurl,$restitle);
}
}
- unless (($ltiscope eq 'map') || ($ltiscope eq 'resource')) {
- @crumbs = ({text => $crstype.' Contents',
- href => "Javascript:gopost('/adm/navmaps','')"});
- }
+ @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 (($ltiscope ne 'map') && ($ltiscope ne 'resource')) {
+ } else {
push(@crumbs, {text => '...',
no_mt => 1});
}
}
unless ((@mapcrumbs) || (!$maptitle) || ($maptitle eq 'default.sequence') ||
- ($mapurl eq $env{'course.'.$env{'request.course.id'}.'.url'}) ||
- ($ltiscope eq 'resource')) {
+ ($mapurl eq $env{'course.'.$env{'request.course.id'}.'.url'})) {
push @crumbs, {text => $maptitle, no_mt => 1,
href => &Apache::lonnet::clutter($mapurl).'?navmap=1'};
}
@@ -975,39 +830,27 @@ sub innerregister {
if ($env{'form.title'}) {
$title = $env{'form.title'};
}
- my ($trail,$cnum,$cdom);
- if ($env{'form.folderpath'}) {
- $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
- $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
- &Apache::loncommon::validate_folderpath(1,'',$cnum,$cdom);
- }
+ my $trail;
if ($env{'form.folderpath'}) {
&prepare_functions($resurl,$forcereg,$group,undef,undef,1,$hostname);
- $title = &HTML::Entities::encode($title,'\'"<>&');
($trail) =
- &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1,1);
+ &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
} else {
&Apache::lonhtmlcommon::add_breadcrumb(
{text => "Supplemental $crstype Content",
href => "javascript:gopost('/adm/supplemental','')"});
- $title = &HTML::Entities::encode(&mt('View Resource'),'\'"<>&');
+ $title = &mt('View Resource');
($trail) =
- &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1,1);
- }
- if (ref($showncrumbsref)) {
- $$showncrumbsref = 1;
+ &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
}
return $trail;
} elsif ($resurl =~ m{^\Q/uploaded$courseurl/portfolio/syllabus/}) {
&Apache::lonhtmlcommon::clear_breadcrumbs();
&prepare_functions('/public'.$courseurl."/syllabus",
$forcereg,$group,undef,undef,1,$hostname);
- $title = &HTML::Entities::encode(&mt('Syllabus File'),'\'"<>&');
+ $title = &mt('Syllabus File');
my ($trail) =
- &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1,1);
- if (ref($showncrumbsref)) {
- $$showncrumbsref = 1;
- }
+ &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1,$hostname);
return $trail;
}
unless ($env{'request.state'} eq 'construct') {
@@ -1059,14 +902,8 @@ 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.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/) {
+ if ($env{'request.filename'}=~/$LONCAPA::assess_re/) {
push(@privs,('mgr','vgr'));
}
push(@privs,('opa','vpa'));
@@ -1081,8 +918,8 @@ sub innerregister {
#
# Determine whether or not to show Grades and Submissions buttons
#
- if (($env{'request.symb'} ne '') &&
- (($env{'request.filename'}=~/$LONCAPA::assess_re/) || ($gradable_exttool))) {
+ if ($env{'request.symb'} ne '' &&
+ $env{'request.filename'}=~/$LONCAPA::assess_re/) {
if ($perms{'mgr'}) {
$hwkadd.= &switch('','',7,2,'pgrd.png','Content Grades',
'grades[_4]',
@@ -1148,13 +985,31 @@ s&6&1&list.png&Directory&dir[_1]&golist(
s&6&2&rtrv.png&Retrieve&version[_1]&gocstr('/adm/retrieve','/priv/$udom/$uname/$cleandisfn')&Retrieve old version
s&6&3&pub.png&Publish&resource[_3]&gocstr('/adm/publish','/priv/$udom/$uname/$cleandisfn')&Publish this resource
s&7&1&del.png&Delete&resource[_2]&gocstr('/adm/cfile?action=delete','/priv/$udom/$uname/$cleandisfn')&Delete this resource
+ENDMENUITEMS
+#
+# Print only makes sense for certain mime types
+#
+ if ($thisdisfn=~/\.(xml|html|htm|xhtml|xhtm|tex)$/ || $thisdisfn=~/$LONCAPA::assess_re/) {
+ $menuitems .= (<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";
- }
- } else {
- $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";
- }
- $menuitems .= (<