--- loncom/interface/lonmenu.pm 2024/01/02 03:46:06 1.369.2.83.2.14
+++ loncom/interface/lonmenu.pm 2024/05/01 14:42:54 1.550
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Routines to control the menu
#
-# $Id: lonmenu.pm,v 1.369.2.83.2.14 2024/01/02 03:46:06 raeburn Exp $
+# $Id: lonmenu.pm,v 1.550 2024/05/01 14:42:54 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()
@@ -266,7 +245,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) = @_;
+ my ($crstype,$ltimenu,$menucoll,$menuref,$links_disabled,$links_target,$collapsible) = @_;
my (%menu,%ltiexc,%menuopts);
# each element of @primary contains following array:
# (link url, icon path, alt text, link text, condition, position)
@@ -275,6 +254,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 +281,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 +312,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 +322,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,9 +360,10 @@ 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/')) {
@@ -410,6 +406,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,6 +434,10 @@ sub primary_menu {
}
my @output = ('','');
if ($menu{'left'} ne '') {
+ if ($collapsible) {
+ $menu{'left'} = ($listclass?'
':'
').
+ '
'.$menu{'left'};
+ }
$output[0] = "$menu{'left'}";
}
if ($menu{'right'} ne '') {
@@ -452,10 +453,10 @@ sub primary_menu {
#
#TODO this should probably be moved somewhere more central
#since it can be used by different parts of the system
-sub getauthor{
+sub getauthor {
return unless $env{'request.role'}=~/^(ca|aa|au)/; #nothing to do if user isn't some kind of author
- #co- or assistent author?
+ #co- or assistant author?
my ($dom, $user) = ($env{'request.role'} =~ /^(?:ca|aa)\.\/($match_domain)\/($match_username)$/)
? ($1, $2) #domain, username of the parent author
: @env{ ('request.role.domain', 'user.name') }; #own domain, username
@@ -480,29 +481,38 @@ 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 ($is_author,$is_coauthor);
+ if ($author) {
+ if ($env{'request.role'} =~ /^au\./) {
+ $is_author = 1;
+ } elsif ($env{'request.role'} =~ /^ca\./) {
+ $is_coauthor = 1;
+ }
+ }
+
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'}) ||
@@ -555,15 +565,25 @@ sub secondary_menu {
$linkattr = 'aria-disabled="true"';
}
- my ($canmodifycoauthor);
+ my ($canlistcoauthors,$canmodifycoauthor);
if ($env{'request.role'} eq "au./$env{'user.domain'}/") {
my $extent = "$env{'user.domain'}/$env{'user.name'}";
if ((&Apache::lonnet::allowed('cca',$extent)) ||
(&Apache::lonnet::allowed('caa',$extent))) {
$canmodifycoauthor = 1;
}
+ } elsif ($env{'request.role'} =~ m{^(aa|ca)\./($match_domain/$match_username)$}) {
+ my ($role,$extent) = ($1,$2);
+ if (&Apache::lonnet::allowed('vca',$extent)) {
+ if ($env{"environment.internal.manager./$extent"}) {
+ $canmodifycoauthor = 1;
+ } else {
+ $canlistcoauthors = 1;
+ }
+ } elsif (&Apache::lonnet::allowed('vaa',$extent)) {
+ $canlistcoauthors = 1;
+ }
}
-
my ($roleswitcher_js,$roleswitcher_form);
if ($links_target ne '') {
$target = $links_target;
@@ -585,15 +605,16 @@ sub secondary_menu {
foreach my $menuitem (@secondary_menu) {
# evaluate conditions
next if ref($menuitem) ne 'ARRAY';
- next if $$menuitem[4] ne 'always'
- && ($$menuitem[4] ne 'author' && $$menuitem[4] ne 'cca')
+ next if (($crstype eq 'Placement') && ($$menuitem[3] ne 'Roles') && (!$env{'request.role.adv'}));
+ next if $$menuitem[4] ne 'always'
+ && $$menuitem[4] ne 'coauthor'
+ && $$menuitem[4] ne 'author'
+ && $$menuitem[4] ne 'authorspace'
+ && $$menuitem[4] ne 'vca'
+ && $$menuitem[4] ne 'mca'
&& !$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'
@@ -610,7 +631,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;
@@ -618,9 +639,17 @@ sub secondary_menu {
&& !$showfeeds;
next if $$menuitem[4] eq 'plc'
&& !$canplc;
- next if $$menuitem[4] eq 'author'
+ next if $$menuitem[4] eq 'authorspace'
&& !$author;
- next if $$menuitem[4] eq 'cca'
+ next if $$menuitem[4] eq 'author'
+ && !$is_author;
+ next if $$menuitem[4] eq 'coauthor'
+ && !$is_coauthor;
+ next if $$menuitem[4] eq 'vca'
+ && (!$canlistcoauthors || $canmodifycoauthor);
+ next if $$menuitem[4] eq 'vaa'
+ && (!$canlistcoauthors || $canmodifycoauthor);
+ next if $$menuitem[4] eq 'mca'
&& !$canmodifycoauthor;
next if $$menuitem[4] eq 'notltimapres'
&& $ltimapres;
@@ -633,9 +662,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]}));
}
}
@@ -658,8 +685,8 @@ 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 'author' && !$is_author);
+ next if ($item->[2] eq 'vca' && !$canlistcoauthors);
next if ($item->[2] eq 'lti' && !$lti);
if ($item->[2] =~ /^lti(portfolio|wishlist|blog)$/) {
my $tool = $1;
@@ -667,7 +694,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'}) {
@@ -689,14 +716,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];
@@ -742,11 +772,25 @@ sub secondary_menu {
}
$menu =~ s/\[url\]/$escurl/g;
$menu =~ s/\[symb\]/$escsymb/g;
+ } elsif (($menu =~ m{/adm/preferences\?}) && ($menu =~ /\[returnurl\]/)) {
+ my $returnurl = $ENV{'REQUEST_URI'};
+ if ($ENV{'REQUEST_URI'} =~ m{/adm/preferences\?action=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);
+ }
+ $menu =~ s/\[returnurl\]/$returnurl/;
}
$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;
}
@@ -785,7 +829,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 '';
}
@@ -818,11 +862,11 @@ sub build_submenu {
if (ref($href) eq 'ARRAY') {
$menu .= '