--- loncom/interface/lonmenu.pm 2020/01/19 00:54:47 1.369.2.79.2.1
+++ loncom/interface/lonmenu.pm 2023/01/23 05:40:00 1.369.2.83.2.7
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Routines to control the menu
#
-# $Id: lonmenu.pm,v 1.369.2.79.2.1 2020/01/19 00:54:47 raeburn Exp $
+# $Id: lonmenu.pm,v 1.369.2.83.2.7 2023/01/23 05:40:00 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,$target,$listclass,$linkattr)
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) = @_;
+ my ($menuitem,$target,$listclass,$linkattr) = @_;
return '' unless(ref($menuitem) eq 'ARRAY');
- my $link;
+ my ($link,$targetattr);
if ($$menuitem[1]) { # graphical Link
$link = "':'').'$link|;
+ . qq| href="$$menuitem[0]"$targetattr $linkattr>$link|;
}
# primary_menu() evaluates @primary_menu and returns a two item array,
@@ -263,7 +266,8 @@ sub prep_menuitem {
# @primary_menu is filled within the BEGIN block of this module with
# entries from mydesk.tab
sub primary_menu {
- my %menu;
+ my ($crstype,$ltimenu,$menucoll,$menuref,$links_disabled,$links_target) = @_;
+ my (%menu,%menuopts);
# each element of @primary contains following array:
# (link url, icon path, alt text, link text, condition, position)
my $public;
@@ -271,6 +275,27 @@ sub primary_menu {
|| (($env{'user.name'} eq '') && ($env{'user.domain'} eq ''))) {
$public = 1;
}
+ my ($listclass,$linkattr,$target);
+ if ($links_disabled) {
+ $listclass = 'LCisDisabled';
+ $linkattr = 'aria-disabled="true"';
+ }
+ if ($links_target ne '') {
+ $target = $links_target;
+ } else {
+ my $deeplinktarget;
+ if ($env{'request.deeplink.login'}) {
+ $deeplinktarget = $env{'request.deeplink.target'};
+ }
+ if ($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'; #
@@ -294,11 +319,27 @@ sub primary_menu {
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'} &&
+ $env{'user.name'} && $env{'user.domain'}) {
+ $menu{$position} .= '
'.
+ &Apache::loncommon::plainname($env{'user.name'},
+ $env{'user.domain'}).'';
+ next;
+ } else {
+ next;
+ }
+ } else {
+ next;
+ }
+ }
+ }
if (defined($primary_submenu{$title})) {
- my ($link,$target);
+ my $link;
if ($menuitem->[0] ne '') {
$link = $menuitem->[0];
- $target = '_top';
} else {
$link = '#';
}
@@ -310,17 +351,30 @@ 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 (@primsub > 0) {
- if ($title eq 'Personal' && $env{'user.name'} && $env{'user.domain'} ) {
- $title = &Apache::loncommon::plainname($env{'user.name'},$env{'user.domain'});
- } else {
+ if ($title eq 'Personal') {
+ if ($env{'user.name'} && $env{'user.domain'}) {
+ 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') {
$title = &mt($title);
}
- $menu{$position} .= &create_submenu($link,$target,$title,\@primsub,1);
+ } else {
+ $title = &mt($title);
+ }
+ if (@primsub > 0) {
+ $menu{$position} .= &create_submenu($link,$target,$title,\@primsub,1,undef,$listclass,$linkattr);
} elsif ($link) {
- $menu{$position} .= ''.&mt($title).'';
+ $menu{$position} .= ($listclass?'':'').
+ ''.$title.'';
}
}
} elsif ($$menuitem[3] eq 'Help') { # special treatment for helplink
@@ -331,13 +385,22 @@ sub primary_menu {
'helpdeskmail',
$defdom,$origmail);
if ($to ne '') {
- $menu{$position} .= &prep_menuitem($menuitem);
+ $menu{$position} .= &prep_menuitem($menuitem,$target,$listclass,$linkattr);
}
} else {
- $menu{$position} .= ''.&Apache::loncommon::top_nav_help('Help').'';
+ $menu{$position} .= ($listclass?'':'').
+ &Apache::loncommon::top_nav_help('Help',$linkattr).
+ '';
}
+ } elsif ($$menuitem[3] eq 'Log In') {
+ if ($public) {
+ if (&Apache::lonnet::get_saml_landing()) {
+ $$menuitem[0] = '/adm/login';
+ }
+ }
+ $menu{$position} .= prep_menuitem($menuitem,$target,$listclass,$linkattr);
} else {
- $menu{$position} .= prep_menuitem($menuitem);
+ $menu{$position} .= prep_menuitem($menuitem,$target,$listclass,$linkattr);
}
}
my @output = ('','');
@@ -376,7 +439,8 @@ sub getauthor{
}
sub secondary_menu {
- my ($httphost) = @_;
+ my ($httphost,$ltiscope,$ltimenu,$noprimary,$menucoll,$menuref,
+ $links_disabled,$links_target) = @_;
my $menu;
my $crstype = &Apache::loncommon::course_type();
@@ -397,9 +461,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,%menuopts);
$grouptools = 0;
if ($env{'request.course.id'}) {
$cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
@@ -434,6 +499,15 @@ sub secondary_menu {
}
}
}
+ if (($menucoll) && (ref($menuref) eq 'HASH')) {
+ %menuopts = %{$menuref};
+ }
+
+ my ($listclass,$linkattr,$target);
+ if ($links_disabled) {
+ $listclass = 'LCisDisabled';
+ $linkattr = 'aria-disabled="true"';
+ }
my ($canmodifycoauthor);
if ($env{'request.role'} eq "au./$env{'user.domain'}/") {
@@ -445,6 +519,19 @@ sub secondary_menu {
}
my ($roleswitcher_js,$roleswitcher_form);
+ if ($links_target ne '') {
+ $target = $links_target;
+ } else {
+ my $deeplinktarget;
+ if ($env{'request.deeplink.login'}) {
+ $deeplinktarget = $env{'request.deeplink.target'};
+ }
+ if ($deeplinktarget eq '_self') {
+ $target = '_self';
+ } else {
+ $target = '_top';
+ }
+ }
foreach my $menuitem (@secondary_menu) {
# evaluate conditions
@@ -480,17 +567,25 @@ 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;
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,$target);
+ my $link;
if ($menuitem->[0] ne '') {
$link = $menuitem->[0];
- $target = '_top';
} else {
$link = '#';
}
@@ -512,19 +607,26 @@ sub secondary_menu {
}
}
if (@scndsub > 0) {
- $menu .= &create_submenu($link,$target,$title,\@scndsub,1);
+ $menu .= &create_submenu($link,$target,&mt($title),\@scndsub,1,undef,
+ $listclass,$linkattr);
} elsif ($link ne '#') {
- $menu .= ''.&mt($title).'';
+ $menu .= ($listclass?'':'').
+ ''.
+ &mt($title).'';
}
}
} elsif ($$menuitem[3] eq 'Roles' && $env{'request.course.id'}) {
# special treatment for role selector
- ($roleswitcher_js,$roleswitcher_form,my $switcher) =
+ my ($switcher,$has_opa_priv);
+ ($roleswitcher_js,$roleswitcher_form,$switcher,$has_opa_priv) =
&roles_selector(
$env{'course.' . $env{'request.course.id'} . '.domain'},
$env{'course.' . $env{'request.course.id'} . '.num'},
- $httphost
+ $httphost,$target,$menucoll,$menuref
);
+ if (($$menuitem[5]) && (!$menuopts{$$menuitem[5]})) {
+ next unless ($has_opa_priv);
+ }
$menu .= $switcher;
} else {
if ($$menuitem[3] eq 'Syllabus' && $env{'request.course.id'}) {
@@ -539,7 +641,7 @@ 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 (&Apache::lonnet::uses_sts()) {
+ unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl())) {
unless ($$menuitem[0] =~ m{^https?://}) {
$$menuitem[0] = 'http://'.$ENV{'SERVER_NAME'}.$$menuitem[0];
}
@@ -551,7 +653,7 @@ sub secondary_menu {
}
$$menuitem[0] = &HTML::Entities::encode($$menuitem[0],'&<>"');
}
- $menu .= &prep_menuitem(\@$menuitem);
+ $menu .= &prep_menuitem(\@$menuitem,$target,$listclass,$linkattr);
}
}
if ($menu =~ /\[url\].*\[symb\]/) {
@@ -574,6 +676,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;
@@ -588,14 +691,14 @@ sub secondary_menu {
}
sub create_submenu {
- my ($link,$target,$title,$submenu,$translate,$addclass) = @_;
+ my ($link,$target,$title,$submenu,$translate,$addclass,$listclass,$linkattr) = @_;
return unless (ref($submenu) eq 'ARRAY');
- my $disptarget;
- if ($target ne '') {
- $disptarget = ' target="'.$target.'"';
+ my $targetattr;
+ if (($target ne '') && ($link ne '#')) {
+ $targetattr = ' target="'.$target.'"';
}
my $menu = ''.
- ''.
+ ''.
''.$title.
''.
' ▼'.
@@ -603,7 +706,7 @@ sub create_submenu {
# $link and $title are only used in the initial string written in $menu
# as seen above, not needed for nested submenus
- $menu .= &build_submenu($target, $submenu, $translate, '1');
+ $menu .= &build_submenu($target, $submenu, $translate, '1', $listclass, $linkattr);
$menu .= '';
return $menu;
@@ -613,7 +716,7 @@ sub create_submenu {
# build the dropdown (and nested submenus) recursively
# see perldoc create_submenu documentation for further information
sub build_submenu {
- my ($target, $submenu, $translate, $first_level) = @_;
+ my ($target, $submenu, $translate, $first_level, $listclass, $linkattr) = @_;
unless (@{$submenu}) {
return '';
}
@@ -672,12 +775,17 @@ sub build_submenu {
}
$href =~ s/\[returnurl\]/$returnurl/;
}
+ my $targetattr;
unless (($href eq '') || ($href =~ /^\#/)) {
- $target = ' target="_top"';
+ if ($target ne '') {
+ $targetattr = ' target="'.$target.'"';
+ }
}
- $menu .= '';
- $menu .= '' . $title . '';
+ $menu .= '';
+ $menu .= '' . $title . '';
$menu .= '';
}
}
@@ -714,7 +822,8 @@ sub registerurl {
}
sub innerregister {
- my ($forcereg,$bread_crumbs,$group,$pagebuttonshide,$hostname) = @_;
+ my ($forcereg,$bread_crumbs,$group,$pagebuttonshide,$hostname,
+ $ltiscope,$ltiuri,$showncrumbsref) = @_;
my $const_space = ($env{'request.state'} eq 'construct');
my $is_const_dir = 0;
@@ -762,12 +871,8 @@ sub innerregister {
@mapcrumbs = $navmap->recursed_crumbs($mapurl,$restitle);
}
}
- unless (($forcereg) &&
- ($env{'request.noversionuri'} eq '/adm/navmaps') &&
- ($mapurl eq $env{'course.'.$env{'request.course.id'}.'.url'})) {
- @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);
@@ -807,27 +912,39 @@ sub innerregister {
if ($env{'form.title'}) {
$title = $env{'form.title'};
}
- my $trail;
+ 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);
+ }
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);
+ &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1,1);
} else {
&Apache::lonhtmlcommon::add_breadcrumb(
{text => "Supplemental $crstype Content",
href => "javascript:gopost('/adm/supplemental','')"});
- $title = &mt('View Resource');
+ $title = &HTML::Entities::encode(&mt('View Resource'),'\'"<>&');
($trail) =
- &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
+ &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1,1);
+ }
+ if (ref($showncrumbsref)) {
+ $$showncrumbsref = 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 = &mt('Syllabus File');
+ $title = &HTML::Entities::encode(&mt('Syllabus File'),'\'"<>&');
my ($trail) =
- &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1,$hostname);
+ &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1,1);
+ if (ref($showncrumbsref)) {
+ $$showncrumbsref = 1;
+ }
return $trail;
}
unless ($env{'request.state'} eq 'construct') {
@@ -1018,14 +1135,17 @@ 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/|default_\d+\.page$)}) &&
+ ($env{'request.noversionuri'} !~ m{^/adm/.+/ext\.tool$})) {
$menuitems.=(< 'Key:',
nokey => 'A proctor key is required',
);
+ my $shownsymb = &HTML::Entities::encode(&Apache::lonenc::check_encrypt($env{'request.symb'}));
my $navmap = Apache::lonnavmaps::navmap->new();
my ($missing,$tried) = (0,0);
if (ref($navmap)) {
@@ -2278,6 +2428,7 @@ sub done_button_js {
@@ -2359,6 +2510,7 @@ END
@@ -2441,6 +2593,11 @@ sub utilityfunctions {
my $countdown = &countdown_toggle_js();
+ my $deeplinktarget;
+ if ($env{'request.deeplink.login'}) {
+ $deeplinktarget = $env{'request.deeplink.target'};
+ }
+
my $annotateurl = '/adm/annotation';
if ($httphost) {
$annotateurl = '/adm/annotations';
@@ -2541,17 +2698,22 @@ function golist(url) {
currentURL = null;
currentSymb= null;
var lcHostname = setLCHost();
- top.location.href=lcHostname+url;
+ var deeplinktarget = '$deeplinktarget';
+ if (deeplinktarget == '_self') {
+ document.location.href=lcHostname+url;
+ } else {
+ top.location.href=lcHostname+url;
+ }
}
}
-function catalog_info(isMobile) {
+function catalog_info(url,isMobile) {
if (isMobile == 1) {
- openMyModal(window.location.pathname+'.meta?modal=1',500,400,'yes');
+ openMyModal(url+'.meta?modal=1',500,400,'yes');
} else {
- loncatinfo=window.open(window.location.pathname+'.meta',"LONcatInfo",'height=500,width=400,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no');
+ loncatinfo=window.open(url+'.meta',"LONcatInfo",'height=500,width=400,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no');
}
}
@@ -2619,8 +2781,14 @@ ENDUTILITY
}
sub serverform {
+ my $target;
+ if (($env{'request.deeplink.login'}) && ($env{'request.deeplink.target'} eq '_self')) {
+ $target = ' target="_self"';
+ } else {
+ $target = ' target="_top"';
+ }
return(<
+