--- loncom/interface/lonmenu.pm 2024/02/28 19:08:32 1.369.2.83.2.18
+++ loncom/interface/lonmenu.pm 2022/09/13 12:22:14 1.527
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Routines to control the menu
#
-# $Id: lonmenu.pm,v 1.369.2.83.2.18 2024/02/28 19:08:32 raeburn Exp $
+# $Id: lonmenu.pm,v 1.527 2022/09/13 12:22:14 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -118,72 +118,51 @@ Same as primary_menu() but operates on @
=item create_submenu()
-Creates XHTML for unordered list of sub-menu items which belong to a
+Creates XHTML for unordered list of sub-menu items which belong to a
particular top-level menu item. Uses hover pseudo class in css to display
-dropdown list when mouse hovers over top-level item. Support for IE6
+dropdown list when mouse hovers over top-level item. Support for IE6
(no hover psuedo class) via LC_hoverable class for
tag for top-
level item, which employs jQuery to handle behavior on mouseover.
Inputs: 6 - (a) link and (b) target for anchor href in top level item,
- (c) title for text wrapped by anchor tag in top level item.
- (d) reference to array of arrays of sub-menu items.
- (e) boolean to indicate whether to call &mt() to translate
+ (c) title for text wrapped by anchor tag in top level item,
+ (d) reference to array of arrays of sub-menu items,
+ (e) boolean to indicate whether to call &mt() to translate
name of menu item,
(f) optional class for
element in primary menu, for which
sub menu is being generated.
-The underlying datastructure used in (d) contains data from mydesk.tab.
-It consists of an array which has an array for each item appearing in
-the menu (e.g. [["link", "title", "condition"]] for a single-item menu).
-create_submenu() supports also the creation of XHTML for nested dropdown
-menus represented by unordered lists. This is done by replacing the
-scalar used for the link with an arrayreference containing the menuitems
-for the nested menu. This can be done recursively so that the next menu
-may also contain nested submenus.
+ The underlying datastructure used in (d) contains data from mydesk.tab.
+ It consists of an array which has an array for each item appearing in
+ the menu (e.g. [["link", "title", "condition"]] for a single-item menu).
+ create_submenu() supports also the creation of XHTML for nested dropdown
+ menus represented by unordered lists. This is done by replacing the
+ scalar used for the link with an arrayreference containing the menuitems
+ for the nested menu. This can be done recursively so that the next menu
+ may also contain nested submenus.
Example:
- [ # begin of datastructure
- ["/home/", "Home", "condition1"], # 1st item of the 1st layer menu
- [ # 2nd item of the 1st layer menu
- [ # anon. array for nested menu
- ["/path1", "Path1", undef], # 1st item of the 2nd layer menu
- ["/path2", "Path2", undef], # 2nd item of the 2nd layer menu
- [ # 3rd item of the 2nd layer menu
- [[...], [...], ..., [...]], # containing another menu layer
- "Sub-Sub-Menu", # title for this container
- undef
- ]
- ], # end of array/nested menu
- "Sub-Menu", # title for the container item
- undef
- ] # end of 2nd item of the 1st layer menu
+ [ # begin of datastructure
+ ["/home/", "Home", "condition1"], # 1st item of the 1st layer menu
+ [ # 2nd item of the 1st layer menu
+ [ # anon. array for nested menu
+ ["/path1", "Path1", undef], # 1st item of the 2nd layer menu
+ ["/path2", "Path2", undef], # 2nd item of the 2nd layer menu
+ [ # 3rd item of the 2nd layer menu
+ [[...], [...], ..., [...]], # containing another menu layer
+ "Sub-Sub-Menu", # title for this container
+ undef
+ ]
+ ], # end of array/nested menu
+ "Sub-Menu", # title for the container item
+ undef
+ ] # end of 2nd item of the 1st layer menu
]
-
=item innerregister()
This gets called in order to register a URL in the body of the document
-=item loadevents()
-
-=item unloadevents()
-
-=item startupremote()
-
-=item setflags()
-
-=item maincall()
-
-=item load_remote_msg()
-
-=item get_menu_name()
-
-=item reopenmenu()
-
-=item open()
-
-Open the menu
-
=item clear()
=item switch()
@@ -231,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();
@@ -266,7 +246,7 @@ 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,$collapsible) = @_;
+ my ($crstype,$ltimenu,$menucoll,$menuref,$links_disabled,$links_target) = @_;
my (%menu,%ltiexc,%menuopts);
# each element of @primary contains following array:
# (link url, icon path, alt text, link text, condition, position)
@@ -275,6 +255,15 @@ sub primary_menu {
|| (($env{'user.name'} eq '') && ($env{'user.domain'} eq ''))) {
$public = 1;
}
+ my $rolecount;
+ if (($crstype eq 'Placement') && (!$env{'request.role.adv'})) {
+ my $update=$env{'user.update.time'};
+ if (!$update) {
+ $update = $env{'user.login.time'};
+ }
+ my %roles_in_env;
+ $rolecount = &Apache::lonroles::roles_from_env(\%roles_in_env,$update);
+ }
my $lti;
if ($env{'request.lti.login'}) {
$lti = 1;
@@ -293,7 +282,7 @@ sub primary_menu {
}
if ($links_target ne '') {
$target = $links_target;
- } else {
+ } else {
my ($ltitarget,$deeplinktarget);
if ($env{'request.lti.login'}) {
$ltitarget = $env{'request.lti.target'};
@@ -324,7 +313,7 @@ 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
+ && (&Apache::loncommon::show_course() ##term 'Courses' or
|| $lti); ##'Roles' wanted
next if $$menuitem[4] eq 'courses' ##and not LTI access
&& (!&Apache::loncommon::show_course()
@@ -334,6 +323,13 @@ sub primary_menu {
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') {
+ next unless ($rolecount>1);
+ } else {
+ next unless (($title eq 'Personal') || ($title eq 'Logout'));
+ }
+ }
my $position = $menuitem->[5];
if ($position eq '') {
$position = 'right';
@@ -365,24 +361,12 @@ sub primary_menu {
my @primsub;
if (ref($primary_submenu{$title}) eq 'ARRAY') {
foreach my $item (@{$primary_submenu{$title}}) {
- next if (($item->[2] eq 'wishlist') && (!$env{'user.adv'}));
- next if ((($item->[2] eq 'portfolio') ||
- ($item->[2] eq 'blog')) &&
+ next if (($crstype eq 'Placement') && (!$env{'request.role.adv'}));
+ next if (($item->[2] eq 'wishlist') && (!$env{'user.adv'}));
+ next if ((($item->[2] eq 'portfolio') ||
+ ($item->[2] eq 'blog')) &&
(!&Apache::lonnet::usertools_access('','',$item->[2],
undef,'tools')));
- if (($item->[2] eq 'browsepub') && ($item->[0] eq '/res/')) {
- if ($env{'request.role'} =~ /^au\./) {
- $item->[0] .= $env{'request.role.domain'}.'/?launch=1';
- } elsif ($env{'request.role'} =~ m{^ca\./($match_domain)/($match_username)$}) {
- $item->[0] .= $1.'/'.$2.'/?launch=1';
- } elsif (&Apache::lonnet::allowed('bre',$env{'user.domain'})) {
- $item->[0] .= $env{'user.domain'}.'/?launch=1';
- } elsif (&Apache::lonnet::allowed('bro','/res/')) {
- $item->[0] .= '?launch=1';
- } else {
- next;
- }
- }
if ($env{'request.course.id'} && $menucoll) {
next if ($item->[3]) && (!$menuopts{$item->[3]});
}
@@ -410,6 +394,7 @@ sub primary_menu {
}
}
} elsif ($$menuitem[3] eq 'Help') { # special treatment for helplink
+ next if ($crstype eq 'Placement');
if ($public) {
my $origmail = $Apache::lonnet::perlvar{'lonSupportEMail'};
my $defdom = &Apache::lonnet::default_login_domain();
@@ -437,10 +422,6 @@ sub primary_menu {
}
my @output = ('','');
if ($menu{'left'} ne '') {
- if ($collapsible) {
- $menu{'left'} = ($listclass?'
':'
').
- '
'.$menu{'left'};
- }
$output[0] = "$menu{'left'}";
}
if ($menu{'right'} ne '') {
@@ -484,29 +465,29 @@ sub secondary_menu {
? "/$env{'request.course.sec'}"
: '');
my $canedit = &Apache::lonnet::allowed('mdc', $env{'request.course.id'});
- my $canvieweditor = &Apache::lonnet::allowed('cev', $env{'request.course.id'});
+ my $canvieweditor = &Apache::lonnet::allowed('cev', $env{'request.course.id'});
my $canviewroster = $env{'course.'.$env{'request.course.id'}.'.student_classlist_view'};
if ($canviewroster eq 'disabled') {
undef($canviewroster);
}
- my $canviewgrps = &Apache::lonnet::allowed('vcg', $crs_sec);
+ my $canviewgrps = &Apache::lonnet::allowed('vcg', $crs_sec);
my $canmodifyuser = &Apache::lonnet::allowed('cst', $crs_sec);
- my $canviewusers = &Apache::lonnet::allowed('vcl', $crs_sec);
- my $canviewwnew = &Apache::lonnet::allowed('whn', $crs_sec);
+ my $canviewusers = &Apache::lonnet::allowed('vcl', $crs_sec);
+ my $canviewwnew = &Apache::lonnet::allowed('whn', $crs_sec);
my $canviewpara = &Apache::lonnet::allowed('vpa', $crs_sec);
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 $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);
- $grouptools = 0;
+ $grouptools = 0;
if ($env{'request.course.id'}) {
$cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
$cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
- unless ($canedit || $canvieweditor) {
+ 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'}) ||
@@ -559,7 +540,7 @@ sub secondary_menu {
$linkattr = 'aria-disabled="true"';
}
- my ($canmodifycoauthor);
+ my ($canmodifycoauthor);
if ($env{'request.role'} eq "au./$env{'user.domain'}/") {
my $extent = "$env{'user.domain'}/$env{'user.name'}";
if ((&Apache::lonnet::allowed('cca',$extent)) ||
@@ -589,15 +570,12 @@ sub secondary_menu {
foreach my $menuitem (@secondary_menu) {
# evaluate conditions
next if ref($menuitem) ne 'ARRAY';
+ next if (($crstype eq 'Placement') && ($$menuitem[3] ne 'Roles') && (!$env{'request.role.adv'}));
next if $$menuitem[4] ne 'always'
- && ($$menuitem[4] ne 'author' && $$menuitem[4] ne 'cca')
+ && ($$menuitem[4] ne 'author' && $$menuitem[4] ne 'cca')
&& !$env{'request.course.id'};
next if $$menuitem[4] =~ /^crsedit/
&& (!$canedit && !$canvieweditor);
- next if $$menuitem[4] eq 'crseditCourse'
- && ($crstype eq 'Community');
- next if $$menuitem[4] eq 'crseditCommunity'
- && ($crstype eq 'Course');
next if $$menuitem[4] eq 'nvgr'
&& ($canvgr || $ltiexc{'grades'});
next if $$menuitem[4] eq 'vgr'
@@ -614,7 +592,7 @@ sub secondary_menu {
&& !$canviewwnew;
next if $$menuitem[4] eq 'params'
&& (!$canmodpara && !$canviewpara);
- next if $$menuitem[4] eq 'nvcg'
+ next if $$menuitem[4] eq 'showgroups'
&& ($canviewgrps || !$grouptools);
next if $$menuitem[4] eq 'showsyllabus'
&& !$showsyllabus;
@@ -637,9 +615,7 @@ sub secondary_menu {
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') {
+ unless ($$menuitem[5] eq 'roles') {
next if (($$menuitem[5]) && (!$menuopts{$$menuitem[5]}));
}
}
@@ -671,7 +647,7 @@ sub secondary_menu {
next if (!&Apache::lonnet::usertools_access('','',$tool,
undef,'tools'));
}
- push(@scndsub,$item);
+ push(@scndsub,$item);
}
}
if ($title eq 'Personal' && $env{'user.name'} && $env{'user.domain'}) {
@@ -693,14 +669,17 @@ sub secondary_menu {
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,$target,$menucoll,$menuref
+ $env{'course.' . $env{'request.course.id'} . '.domain'},
+ $env{'course.' . $env{'request.course.id'} . '.num'},
+ $httphost,$target,$menucoll,$menuref
);
if (($$menuitem[5]) && (!$menuopts{$$menuitem[5]})) {
next unless ($has_opa_priv);
}
$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];
@@ -750,7 +729,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'}) {
+ if ($env{'request.course.id'}) {
$menu =~ s/\[cnum\]/$cnum/g;
$menu =~ s/\[cdom\]/$cdom/g;
}
@@ -789,7 +768,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, $listclass, $linkattr) = @_;
+ my ($target, $submenu, $translate, $first_level, $listclass, $linkattr) = @_;
unless (@{$submenu}) {
return '';
}
@@ -822,11 +801,11 @@ sub build_submenu {
if (ref($href) eq 'ARRAY') {
$menu .= '