--- loncom/interface/lonmenu.pm 2010/12/02 13:07:08 1.309.2.20
+++ loncom/interface/lonmenu.pm 2019/08/06 16:49:01 1.369.2.76
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Routines to control the menu
#
-# $Id: lonmenu.pm,v 1.309.2.20 2010/12/02 13:07:08 raeburn Exp $
+# $Id: lonmenu.pm,v 1.369.2.76 2019/08/06 16:49:01 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -26,10 +26,6 @@
# http://www.lon-capa.org/
#
#
-# There is one parameter controlling the action of this module:
-#
-# environment.remote - if this is 'on', the routines controll the remote
-# control, otherwise they render the main window controls;
=head1 NAME
@@ -37,33 +33,136 @@ Apache::lonmenu
=head1 SYNOPSIS
-Coordinates the response to clicking an image.
+Loads contents of /home/httpd/lonTabs/mydesk.tab,
+used to generate inline menu, and Main Menu page.
This is part of the LearningOnline Network with CAPA project
described at http://www.lon-capa.org.
-=head1 SUBROUTINES
+=head1 GLOBAL VARIABLES
=over
-Little texts
+=item @desklines
+
+Each element of this array contains a line of mydesk.tab that doesn't start with
+cat, prim or scnd.
+It gets filled in the BEGIN block of this module.
+
+=item %category_names
+
+The keys of this hash are the abbreviations used in mydesk.tab in those lines that
+start with cat, the values are strings representing titles.
+It gets filled in the BEGIN block of this module.
+
+=item %category_members
+
+TODO
+
+=item %category_positions
+
+The keys of this hash are the abbreviations used in mydesk.tab in those lines that
+start with cat, its values are position vectors (column, row).
+It gets filled in the BEGIN block of this module.
+
+=item $readdesk
+
+Indicates that mydesk.tab has been read.
+It is set to 'done' in the BEGIN block of this module.
+
+=item @primary_menu
+
+The elements of this array reference arrays that are made up of the components
+of those lines of mydesk.tab that start with prim:.
+It is used by primary_menu() to generate the corresponding menu.
+It gets filled in the BEGIN block of this module.
+
+=item %primary_sub_menu
+
+The keys of this hash reference are the names of items in the primary_menu array
+which have sub-menus. For each key, the corresponding value is a reference to
+an array containing components extracted from lines in mydesk.tab which begin
+with primsub:.
+This hash, which is used by primary_menu to generate sub-menus, is populated in
+the BEGIN block.
+
+=item @secondary_menu
-=item initlittle()
+The elements of this array reference arrays that are made up of the components
+of those lines of mydesk.tab that start with scnd.
+It is used by secondary_menu() to generate the corresponding menu.
+It gets filled in the BEGIN block of this module.
-=item menubuttons()
+=back
+
+=head1 SUBROUTINES
+
+=over
+
+=item prep_menuitems(\@menuitem)
-This gets called at the top of the body section
+This routine wraps a menuitem in proper HTML. It is used by primary_menu() and
+secondary_menu().
-=item show_return_link()
+=item primary_menu()
-=item registerurl()
+This routine evaluates @primary_menu and returns a two item array,
+with the array elements containing XHTML for the left and right sides of
+the menu that contains the following links: About, Message, Roles, Help, Logout
+@primary_menu is filled within the BEGIN block of this module with
+entries from mydesk.tab
+
+=item secondary_menu()
+
+Same as primary_menu() but operates on @secondary_menu.
+
+=item create_submenu()
+
+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
+(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
+ 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.
+
+ 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
+]
-This gets called in the header section
=item innerregister()
-This gets called in order to register a URL, both with the Remote
-and in the body of the document
+This gets called in order to register a URL in the body of the document
=item loadevents()
@@ -101,12 +200,11 @@ The javascript is usually similar to "go
=item rawconfig()
-=item close()
-
-=item footer()
-
=item utilityfunctions()
+Output from this routine is a number of javascript functions called by
+items in the inline menu, and in some cases items in the Main Menu page.
+
=item serverform()
=item constspaceform()
@@ -131,12 +229,13 @@ use Apache::lonhtmlcommon();
use Apache::loncommon();
use Apache::lonenc();
use Apache::lonlocal;
-use Apache::loncoursequeueadmin;
+use Apache::lonmsg();
use LONCAPA qw(:DEFAULT :match);
use HTML::Entities();
+use Apache::lonwishlist();
use vars qw(@desklines %category_names %category_members %category_positions
- $readdesk @primary_menu @secondary_menu);
+ $readdesk @primary_menu %primary_submenu @secondary_menu %secondary_submenu);
my @inlineremote;
@@ -151,23 +250,22 @@ sub prep_menuitem {
} else { # textual Link
$link = &mt($$menuitem[3]);
}
- if($$menuitem[4] eq 'newmsg'){ #special style for New Messages
- return ''.$link.'';
- }
- return ''.$link.'';
+ return '$link|;
}
-# primary_menu() evaluates @primary_menu and returns XHTML for the menu
-# that contains following links:
-# About, Message, Roles, Help, Logout
+# primary_menu() evaluates @primary_menu and returns a two item array,
+# with the array elements containing XHTML for the left and right sides of
+# the menu that contains the following links:
+# Personal, About, Message, Roles, Help, Logout
# @primary_menu is filled within the BEGIN block of this module with
# entries from mydesk.tab
sub primary_menu {
- my $menu;
- my $custommenu = &Apache::loncommon::needs_gci_custom();
- my $numdc = &Apache::loncommon::check_for_gci_dc();
+ my %menu;
# each element of @primary contains following array:
- # (link url, icon path, alt text, link text, condition)
+ # (link url, icon path, alt text, link text, condition, position)
my $public;
if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
|| (($env{'user.name'} eq '') && ($env{'user.domain'} eq ''))) {
@@ -180,30 +278,52 @@ sub primary_menu {
&& &Apache::lonmsg::mynewmail(); # whether a new msg
next if $$menuitem[4] eq 'newmsg' # arrived or not
&& !&Apache::lonmsg::mynewmail(); #
- next if $$menuitem[4] !~ /public/ ##we've a public user,
- && $public; ##who should not see all
+ next if $$menuitem[4] !~ /public/ ##we've a public user,
+ && $public; ##who should not see all
##links
next if $$menuitem[4] eq 'onlypublic'# hide links which are
&& !$public; # only visible to public
# users
- next if $$menuitem[4] eq 'gci'
- && (!$custommenu || $env{'request.role'} =~ m{^st\./gcitest/});
- next if $$menuitem[4] eq 'home'
- && (($custommenu) || ($env{'user.domain'} eq 'gcitest') ||
- (($env{'user.domain'} eq 'gci') && !$numdc));
- next if $$menuitem[4] eq 'gcitest'
- && (($env{'user.domain'} eq 'gci') || ($env{'request.role'} eq 'cm'));
- next if $$menuitem[4] eq 'roles' # hide links which are
- && $custommenu; # not visible when GCI
- next if $$menuitem[4] eq 'courses' # tabbed interface in use
- && $custommenu; #
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(); ##
-
- if ($$menuitem[3] eq 'Help') { # special treatment for helplink
+ my $title = $menuitem->[3];
+ my $position = $menuitem->[5];
+ if ($position eq '') {
+ $position = 'right';
+ }
+ if (defined($primary_submenu{$title})) {
+ my ($link,$target);
+ if ($menuitem->[0] ne '') {
+ $link = $menuitem->[0];
+ $target = '_top';
+ } else {
+ $link = '#';
+ }
+ 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')) &&
+ (!&Apache::lonnet::usertools_access('','',$item->[2],
+ undef,'tools')));
+ 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 {
+ $title = &mt($title);
+ }
+ $menu{$position} .= &create_submenu($link,$target,$title,\@primsub,1);
+ } elsif ($link) {
+ $menu{$position} .= ''.&mt($title).'';
+ }
+ }
+ } elsif ($$menuitem[3] eq 'Help') { # special treatment for helplink
if ($public) {
my $origmail = $Apache::lonnet::perlvar{'lonSupportEMail'};
my $defdom = &Apache::lonnet::default_login_domain();
@@ -211,86 +331,226 @@ sub primary_menu {
'helpdeskmail',
$defdom,$origmail);
if ($to ne '') {
- $menu .= &prep_menuitem($menuitem);
+ $menu{$position} .= &prep_menuitem($menuitem);
}
} else {
- $menu .= ''.&Apache::loncommon::top_nav_help('Help').'';
+ $menu{$position} .= ''.&Apache::loncommon::top_nav_help('Help').'';
}
} else {
- my @items = @{$menuitem};
- $items[0] = 'javascript:'.$menuitem->[0].';';
- $menu .= &prep_menuitem(\@items);
+ $menu{$position} .= prep_menuitem($menuitem);
}
}
-
- return "";
+ my @output = ('','');
+ if ($menu{'left'} ne '') {
+ $output[0] = "";
+ }
+ if ($menu{'right'} ne '') {
+ $output[1] = "";
+ }
+ return @output;
}
+#returns hashref {user=>'',dom=>''} containing:
+# own name, domain if user is au
+# name, domain of parent author if user is ca or aa
+#empty return if user is not an author or not on homeserver
+#
+#TODO this should probably be moved somewhere more central
+#since it can be used by different parts of the system
+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?
+ 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
+
+ # current server == home server?
+ my $home = &Apache::lonnet::homeserver($user,$dom);
+ foreach (&Apache::lonnet::current_machine_ids()){
+ return {user => $user, dom => $dom} if $_ eq $home;
+ }
+
+ # if wrong server
+ return;
+}
sub secondary_menu {
+ my ($httphost) = @_;
my $menu;
my $crstype = &Apache::loncommon::course_type();
- my $canedit = &Apache::lonnet::allowed('mdc', $env{'request.course.id'});
- my $canviewgrps = &Apache::lonnet::allowed('vcg', $env{'request.course.id'}
- . ($env{'request.course.sec'} ? "/$env{'request.course.sec'}"
- : ''));
- my $showlink = &show_return_link();
- my %groups = &Apache::lonnet::get_active_groups(
- $env{'user.domain'}, $env{'user.name'},
- $env{'course.' . $env{'request.course.id'} . '.domain'},
- $env{'course.' . $env{'request.course.id'} . '.num'});
- my $custommenu = &Apache::loncommon::needs_gci_custom();
- my $numdc = &Apache::loncommon::check_for_gci_dc();
- my $role = $env{'request.role'};
+ my $crs_sec = $env{'request.course.id'} . ($env{'request.course.sec'}
+ ? "/$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 $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 $canmodifyuser = &Apache::lonnet::allowed('cst', $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 $author = &getauthor();
+
+ my ($cdom,$cnum,$showsyllabus,$showfeeds,$showresv,$grouptools);
+ $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 (&Apache::lonnet::is_on_map("public/$cdom/$cnum/syllabus")) {
+ if (($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'}) ||
+ ($env{'course.'.$env{'request.course.id'}.'.uploadedsyllabus'}) ||
+ ($env{'course.'.$env{'request.course.id'}.'.updatedsyllabus'}) ||
+ ($env{'request.course.syllabustime'})) {
+ $showsyllabus = 1;
+ }
+ }
+ if ($env{'request.course.feeds'}) {
+ $showfeeds = 1;
+ }
+ }
+ unless ($canmgr || $canvgr) {
+ my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
+ if (keys(%slots) > 0) {
+ $showresv = 1;
+ }
+ }
+ 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) {
+ $grouptools ++;
+ }
+ }
+ }
+ }
+
+ 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)) ||
+ (&Apache::lonnet::allowed('caa',$extent))) {
+ $canmodifycoauthor = 1;
+ }
+ }
+
+ my ($roleswitcher_js,$roleswitcher_form);
+
foreach my $menuitem (@secondary_menu) {
# evaluate conditions
next if ref($menuitem) ne 'ARRAY';
- next if $$menuitem[4] eq 'showmenu'
- && ($custommenu || (!$numdc && $role eq 'cm'));
- next if $$menuitem[4] ne 'showmenu'
- && $$menuitem[4] ne 'author'
+ next if $$menuitem[4] ne 'always'
+ && ($$menuitem[4] ne 'author' && $$menuitem[4] ne 'cca')
&& !$env{'request.course.id'};
- next if $$menuitem[4] eq 'showreturn'
- && !$showlink
- && !($env{'request.state'} eq 'construct');
- next if $$menuitem[4] =~ /^mdc/
- && !$canedit;
- next if $$menuitem[4] eq 'mdcCourse'
- && $crstype eq 'Community';
- next if $$menuitem[4] eq 'mdcCommunity'
- && $crstype ne 'Community';
- next if $$menuitem[4] =~ /^remotenav/
- && $env{'environment.remotenavmap'} ne 'on';
- next if $$menuitem[4] =~ /noremotenav/
- && $env{'environment.remotenavmap'} eq 'on';
- next if $$menuitem[4] =~ /^(no|)remotenav$/
- && $crstype eq 'Community';
- next if $$menuitem[4] =~ /^(no|)remotenavCommunity$/
- && $crstype ne 'Community';
- next if $$menuitem[4] =~ /showgroups$/
- && !$canviewgrps
- && !%groups;
- next if $$menuitem[4] eq 'showroles'
- && ($custommenu || !$numdc || ($numdc && $env{'request.noversionuri'} eq '/adm/roles'));
- if ($$menuitem[3] eq 'Roles' && $env{'request.course.id'} && !$custommenu) {
- # special treatment for role selector
- my $roles_selector = &roles_selector(
- $env{'course.' . $env{'request.course.id'} . '.domain'},
- $env{'course.' . $env{'request.course.id'} . '.num'} );
-
- $menu .= $roles_selector ? "$roles_selector"
- : '';
- } elsif ($env{'environment.remotenavmap'} eq 'on') {
- # open link using javascript when remote navmap is activated
- my @items = @{$menuitem};
- if ($menuitem->[4] eq 'remotenav') {
- $items[0] = "javascript:gonav('$menuitem->[0]');";
+ 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;
+ next if $$menuitem[4] eq 'vgr'
+ && !$canvgr;
+ next if $$menuitem[4] eq 'viewusers'
+ && !$canmodifyuser && !$canviewusers;
+ next if $$menuitem[4] eq 'noviewusers'
+ && ($canmodifyuser || $canviewusers || !$canviewroster);
+ next if $$menuitem[4] eq 'mgr'
+ && !$canmgr;
+ next if $$menuitem[4] eq 'showresv'
+ && !$showresv;
+ next if $$menuitem[4] eq 'whn'
+ && !$canviewwnew;
+ next if $$menuitem[4] eq 'params'
+ && (!$canmodpara && !$canviewpara);
+ next if $$menuitem[4] eq 'nvcg'
+ && ($canviewgrps || !$grouptools);
+ next if $$menuitem[4] eq 'showsyllabus'
+ && !$showsyllabus;
+ next if $$menuitem[4] eq 'showfeeds'
+ && !$showfeeds;
+ next if $$menuitem[4] eq 'author'
+ && !$author;
+ next if $$menuitem[4] eq 'cca'
+ && !$canmodifycoauthor;
+
+ my $title = $menuitem->[3];
+ if (defined($secondary_submenu{$title})) {
+ my ($link,$target);
+ if ($menuitem->[0] ne '') {
+ $link = $menuitem->[0];
+ $target = '_top';
} else {
- $items[0] = "javascript:go('$menuitem->[0]');";
+ $link = '#';
+ }
+ my @scndsub;
+ if (ref($secondary_submenu{$title}) eq 'ARRAY') {
+ foreach my $item (@{$secondary_submenu{$title}}) {
+ if (ref($item) eq 'ARRAY') {
+ next if ($item->[2] eq 'vgr' && !$canvgr);
+ next if ($item->[2] eq 'opa' && !$canmodpara);
+ next if ($item->[2] eq 'vpa' && !$canviewpara);
+ next if ($item->[2] eq 'viewusers' && !($canmodifyuser || $canviewusers));
+ next if ($item->[2] eq 'mgr' && !$canmgr);
+ 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);
+ push(@scndsub,$item);
+ }
+ }
+ if (@scndsub > 0) {
+ $menu .= &create_submenu($link,$target,$title,\@scndsub,1);
+ } elsif ($link ne '#') {
+ $menu .= ''.&mt($title).'';
+ }
}
- $menu .= &prep_menuitem(\@items);
+ } elsif ($$menuitem[3] eq 'Roles' && $env{'request.course.id'}) {
+ # 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
+ );
+ $menu .= $switcher;
} else {
+ if ($$menuitem[3] eq 'Syllabus' && $env{'request.course.id'}) {
+ my $url = $$menuitem[0];
+ $url =~ s{\[cdom\]/\[cnum\]}{$cdom/$cnum};
+ if (&Apache::lonnet::is_on_map($url)) {
+ unless ($$menuitem[0] =~ /(\?|\&)register=1/) {
+ $$menuitem[0] .= (($$menuitem[0]=~/\?/)? '&' : '?').'register=1';
+ }
+ } else {
+ $$menuitem[0] =~ s{\&?register=1}{};
+ }
+ 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 ($$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);
}
}
@@ -305,288 +565,140 @@ sub secondary_menu {
and ( $env{'request.noversionuri'} eq ''
|| !defined($env{'request.noversionuri'})))
{
- ($escurl = $env{'request.filename'}) =~
- s{^/home/([^/]+)/public_html/(.*)$}{/priv/$1/$2};
-
+ my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
+ ($escurl = $env{'request.filename'}) =~ s{^\Q$londocroot\E}{};
$escurl = &escape($escurl);
- }
+ }
$menu =~ s/\[url\]/$escurl/g;
$menu =~ s/\[symb\]/$escsymb/g;
}
+ $menu =~ s/\[uname\]/$$author{user}/g;
+ $menu =~ s/\[udom\]/$$author{dom}/g;
+ if ($env{'request.course.id'}) {
+ $menu =~ s/\[cnum\]/$cnum/g;
+ $menu =~ s/\[cdom\]/$cdom/g;
+ }
+ if ($menu) {
+ $menu = "";
+ }
+ if ($roleswitcher_form) {
+ $menu .= "\n$roleswitcher_js\n$roleswitcher_form";
+ }
+ return $menu;
+}
+
+sub create_submenu {
+ my ($link,$target,$title,$submenu,$translate,$addclass) = @_;
+ return unless (ref($submenu) eq 'ARRAY');
+ my $disptarget;
+ if ($target ne '') {
+ $disptarget = ' target="'.$target.'"';
+ }
+ my $menu = ''.
+ ''.
+ ''.$title.
+ ''.
+ ' ▼'.
+ '';
+
+ # $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 .= '
';
+
+ return $menu;
+}
+
+# helper routine for 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) = @_;
+ unless (@{$submenu}) {
+ return '';
+ }
+
+ my $menu = '';
+ my $count = 0;
+ my $numsub = scalar(@{$submenu});
+ foreach my $item (@{$submenu}) {
+ $count ++;
+ if (ref($item) eq 'ARRAY') {
+ my $href = $item->[0];
+ my $bordertop;
+ my $borderbot;
+ my $title;
- return "";
-}
-
-sub gci_secondary_menu {
- my %courses = (
- 'review' => 'gci_9615072b469884921gcil1',
- 'submit' => 'gci_1H96711d710194bfegcil1',
- 'tutorial' => 'gci_5422913620b814c90gcil1',
- );
- my %linktext = (
- 'review' => 'Review Questions',
- 'submit' => 'Submit Questions',
- 'managetest' => 'Manage Tests',
- 'tutorial' => 'Tutorials',
- );
- my %links = (
- 'managetest' => '/adm/menu',
- );
- my $current = 'managetest';
- if ($env{'form.destinationurl'} eq '/adm/gci_info') {
- undef($current);
- }
- foreach my $key (keys(%courses)) {
- $links{$key} = "javascript:switchpage('$key');";
- if ($env{'request.course.id'} eq $courses{$key}) {
- if ($env{'environment.remotenavmap'} eq 'on') {
- $links{$key} = "javascript:gonav('/adm/navmaps')";
+ if ($translate) {
+ $title = &mt($item->[1]);
} else {
- $links{$key} = '/adm/navmaps';
+ $title = $item->[1];
}
- $current = $key;
- $links{'managetest'} = '/adm/roles?selectrole=1&cm=1&orgurl=%2fadm%2fmenu';
- }
- }
- my @menutabs = ('review','submit','managetest','tutorial');
- my $tabs;
- foreach my $item (@menutabs) {
- if ($item eq $current) {
- $tabs .= ''.
- $linktext{$item}.'';
- } else {
- $tabs .= ''.
- $linktext{$item}.'';
- }
- }
- return '
';
-}
-
-#
-# This routine returns a translated hash for the menu items in the top inline menu row
-# Probably should be in mydesk.tab
-
-#SD this sub is deprecated - don't use it
-sub initlittle {
- return &Apache::lonlocal::texthash('ret' => 'Return to Last Location',
- 'nav' => 'Course Contents',
- 'main' => 'Main Menu',
- 'roles' => (&Apache::loncommon::show_course()?
- 'Courses':'Roles'),
- 'other' => 'Other Roles',
- 'docs' => 'Edit Course',
- 'exit' => 'Logout',
- 'login' => 'Log In',
- 'launch' => 'Launch Remote Control',
- 'groups' => 'Groups',
- 'gdoc' => 'Community Documents',
- );
-}
-
-#SD this sub is deprecated - don't use it
-#SD functionality is covered by new loncommon::bodytag and primary_menu(), secondary_menu()
-sub menubuttons {
- my $forcereg=shift;
- my $titletable=shift;
-#
-# Early-out for pages that should not have a menu, triggered by query string "inhibitmenu=yes"
-#
- &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
- ['inhibitmenu']);
- if (($env{'form.inhibitmenu'} eq 'yes') ||
- ($ENV{'REQUEST_URI'} eq '/adm/logout')) { return ''; }
- if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
+ if ($count == 1 && !$first_level) {
+ $bordertop = 'border-top: 1px solid black;';
+ }
+ if ($count == $numsub) {
+ $borderbot = 'border-bottom: 1px solid black;';
+ }
- my %lt=&initlittle();
- my $navmaps='';
- my $reloadlink='';
- my $docs='';
- my $groups='';
- my $roles=''.$lt{'roles'}.'';
- my $role_selector;
- my $showgroups=0;
- my ($cnum,$cdom);
-#
-# if the URL is hidden, symbs and the non-versioned version of the URL would be encrypted
-#
- my $escurl=&escape(&Apache::lonenc::check_encrypt($env{'request.noversionuri'}));
- my $escsymb=&escape(&Apache::lonenc::check_encrypt($env{'request.symb'}));
-
- my $logo=&Apache::loncommon::lonhttpdurl("/adm/lonIcons/minilogo.gif");
- $logo = '';
+ # href is a reference to another submenu
+ if (ref($href) eq 'ARRAY') {
+ $menu .= '';
+ $menu .= '';
+ $menu .= '';
+ $menu .= &build_submenu($target, $href, $translate);
+ $menu .= '
';
+ $menu .= '';
+ } else { # href is the actual hyperlink and does not represent another submenu
+ # for the current menu title
+ if ($href =~ /(aboutme|rss\.html)$/) {
+ 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 ($env{'request.state'} eq 'construct') {
-#
-# We are in construction space
-#
- if (($env{'request.noversionuri'} eq '') || (!defined($env{'request.noversionuri'}))) {
- my $returnurl = $env{'request.filename'};
- $returnurl =~ s:^/home/([^/]+)/public_html/(.*)$:/priv/$1/$2:;
- $escurl = &escape($returnurl);
- }
- }
- if ($env{'request.course.id'}) {
-#
-# We are in a course
-#
- $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
- $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
- my %coursegroups;
- my $viewgrps_permission =
- &Apache::lonnet::allowed('vcg',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''));
- if (!$viewgrps_permission) {
- %coursegroups = &Apache::lonnet::get_active_groups($env{'user.domain'},$env{'user.name'},$cdom,$cnum);
- }
- if ((keys(%coursegroups) > 0) || ($viewgrps_permission)) {
- $showgroups = 1;
- }
- $role_selector = &roles_selector($cdom,$cnum);
- if ($role_selector) {
- $roles = ''.$role_selector.' '.$lt{'other'}.'';
+ $menu .= '';
+ $menu .= '' . $title . '';
+ $menu .= '';
+ }
}
}
-
- if ($env{'environment.remote'} eq 'off') {
-# Remote Control is switched off
-# figure out colors
- my %lt=&initlittle();
-
- my $domain=&Apache::loncommon::determinedomain();
- my $function=&Apache::loncommon::get_users_function();
- my $link=&Apache::loncommon::designparm($function.'.link',$domain);
- my $alink=&Apache::loncommon::designparm($function.'.alink',$domain);
- my $vlink=&Apache::loncommon::designparm($function.'.vlink',$domain);
- my $sidebg=&Apache::loncommon::designparm($function.'.sidebg',$domain);
-
- if ($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public') {
- return (<