--- loncom/interface/lonmenu.pm 2006/03/16 22:12:17 1.166
+++ loncom/interface/lonmenu.pm 2015/04/16 10:13:25 1.432
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Routines to control the menu
#
-# $Id: lonmenu.pm,v 1.166 2006/03/16 22:12:17 albertel Exp $
+# $Id: lonmenu.pm,v 1.432 2015/04/16 10:13:25 droeschl Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -26,804 +26,1136 @@
# http://www.lon-capa.org/
#
#
-# There are two parameters controlling the action of this module:
-#
-# browser.interface - if this is 'textual', it overrides the second parameter
-# and goes to screen reader PDA mode
-#
-# environment.remote - if this is 'on', the routines controll the remote
-# control, otherwise they render the main window controls; ignored it
-# browser.interface is 'textual'
-#
+
+=head1 NAME
+
+Apache::lonmenu
+
+=head1 SYNOPSIS
+
+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 GLOBAL VARIABLES
+
+=over
+
+=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
+
+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.
+
+=back
+
+=head1 SUBROUTINES
+
+=over
+
+=item prep_menuitems(\@menuitem)
+
+This routine wraps a menuitem in proper HTML. It is used by primary_menu() and
+secondary_menu().
+
+=item primary_menu()
+
+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: 4 - (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.
+
+ 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
+]
+
+=item innerregister()
+
+This gets called in order to register a URL in the body of the document
+
+=item clear()
+
+=item switch()
+
+Switch a button or create a link
+Switch acts on the javascript that is executed when a button is clicked.
+The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)".
+
+=item secondlevel()
+
+=item openmenu()
+
+=item inlinemenu()
+
+=item rawconfig()
+
+=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()
+
+=item get_nav_status()
+
+=item hidden_button_check()
+
+=item roles_selector()
+
+=item jump_to_role()
+
+=back
+
+=cut
package Apache::lonmenu;
use strict;
use Apache::lonnet;
-use Apache::Constants qw(:common);
use Apache::lonhtmlcommon();
use Apache::loncommon();
use Apache::lonenc();
use Apache::lonlocal;
+use Apache::lonmsg();
+use LONCAPA qw(:DEFAULT :match);
+use HTML::Entities();
+use Apache::lonwishlist();
-use vars qw(@desklines $readdesk);
-
+use vars qw(@desklines %category_names %category_members %category_positions
+ $readdesk @primary_menu %primary_submenu @secondary_menu);
my @inlineremote;
-my $font;
-my $tabbg;
-my $pgbg;
-
-# ================================================================ Little texts
-
-sub initlittle {
- return &Apache::lonlocal::texthash('ret' => 'Return to Last Location',
- 'nav' => 'Navigate Contents',
- 'main' => 'Main Menu',
- 'roles' => ($env{'user.adv'}?
- 'Roles':'Courses'),
- 'docs' => 'Course Documents',
- 'exit' => 'Exit',
- 'launch' => 'Launch Remote Control',
- 'groups' => 'Groups');
-}
-
-# ============================= This gets called at the top of the body section
-
-sub menubuttons {
- my $forcereg=shift;
- my $target =shift;
- my $registration=shift;
- my $titletable=shift;
- &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
- ['inhibitmenu']);
- if (($env{'form.inhibitmenu'} eq 'yes') ||
- ($ENV{'REQUEST_URI'} eq '/adm/logout')) { return ''; }
- my %lt=&initlittle();
- my $navmaps='';
- my $reloadlink='';
- my $docs='';
- my $groups='';
- my $showgroups=0;
- my $escurl=&Apache::lonnet::escape(&Apache::lonenc::check_encrypt($env{'request.noversionuri'}));
- my $escsymb=&Apache::lonnet::escape(&Apache::lonenc::check_encrypt($env{'request.symb'}));
- my $face= 'face="Arial,Helvetica,sans-serif"';
- if ($env{'request.state'} eq 'construct') {
- if (($env{'request.noversionuri'} eq '') || (!defined($env{'request.noversionuri'}))) {
- my $returnurl = $env{'request.filename'};
- $returnurl =~ s:^/home/([^/]+)/public_html/(.*)$:/priv/$1/$2:;
- $escurl = &Apache::lonnet::escape($returnurl);
+
+sub prep_menuitem {
+ my ($menuitem) = @_;
+ return '' unless(ref($menuitem) eq 'ARRAY');
+ my $link;
+ if ($$menuitem[1]) { # graphical Link
+ $link = "";
+ } else { # textual Link
+ $link = &mt($$menuitem[3]);
+ }
+ return '
|;
+}
+
+# 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);
+ # each element of @primary contains following array:
+ # (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 ''))) {
+ $public = 1;
+ }
+ foreach my $menuitem (@primary_menu) {
+ # evaluate conditions
+ next if ref($menuitem) ne 'ARRAY'; #
+ next if $$menuitem[4] eq 'nonewmsg' # show links depending on
+ && &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
+ ##links
+ next if $$menuitem[4] eq 'onlypublic'# hide links which are
+ && !$public; # only visible to public
+ # users
+ 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(); ##
+
+ 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} .= '
';
+
+ # $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) = @_;
+ if (!defined(@{$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;
+
+ if ($translate) {
+ $title = &mt($item->[1]);
+ } else {
+ $title = $item->[1];
+ }
-# ====================================== This gets called in the header section
+ if ($count == 1 && !$first_level) {
+ $bordertop = 'border-top: 1px solid black;';
+ }
+ if ($count == $numsub) {
+ $borderbot = 'border-bottom: 1px solid black;';
+ }
+
+ # href is a reference to another submenu
+ if (ref($href) eq 'ARRAY') {
+ $menu .= '
';
+ }
+ }
}
- return $result.$force_title;
+ return $menu;
}
-# =========== This gets called in order to register a URL, both with the Remote
-# =========== and in the body of the document
-
sub innerregister {
- my $forcereg=shift;
- my $target = shift;
- my $titletable = shift;
- my $result = '';
- my ($uname,$thisdisfn);
+ my ($forcereg,$bread_crumbs,$group) = @_;
my $const_space = ($env{'request.state'} eq 'construct');
my $is_const_dir = 0;
- if ($env{'request.noversionuri'} eq '/res/adm/pages/menu.html') { return ''; }
+ if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
- $Apache::lonxml::registered=1;
+ $env{'request.registered'} = 1;
- my $textinter=($env{'browser.interface'} eq 'textual');
- my $noremote=($env{'environment.remote'} eq 'off');
-
- my $textual=($textinter || $noremote);
+ undef(@inlineremote);
- @inlineremote=();
- undef @inlineremote;
+ my ($mapurl,$resurl);
- my $reopen=&Apache::lonmenu::reopenmenu();
+ if ($env{'request.course.id'}) {
+ if ($env{'request.symb'}) {
+ ($mapurl, my $rid, $resurl) = &Apache::lonnet::decode_symb(&Apache::lonnet::symbread());
+ my $coursetitle = $env{'course.'.$env{'request.course.id'}.'.description'};
- my $newmail='';
- if ($noremote) {
- $newmail='
';
- }
- if (($textual) && ($env{'request.symb'}) && ($env{'request.course.id'})) {
- my ($mapurl,$rid,$resurl)=
- &Apache::lonnet::decode_symb(&Apache::lonnet::symbread());
- $newmail.=$env{'course.'.$env{'request.course.id'}.'.description'};
- my $maptitle=&Apache::lonnet::gettitle($mapurl);
- my $restitle=&Apache::lonnet::gettitle(&Apache::lonnet::symbread());
- if ($maptitle && $maptitle ne 'default.sequence') {
- $newmail.=', '.$maptitle;
- }
- if ($restitle) {
- $newmail.=': '.$restitle;
- }
- $newmail.=' ';
- }
- if (&Apache::lonmsg::newmail()) {
- $newmail=($textual?
- 'You have new messages ':
- 'swmenu.setstatus("you have","messages");');
- }
- if ($env{'request.state'} eq 'construct') {
- $newmail = $titletable;
- } else {
- if ($noremote) {
- $newmail.='
';
- }
+ my $maptitle = &Apache::lonnet::gettitle($mapurl);
+ my $restitle = &Apache::lonnet::gettitle(&Apache::lonnet::symbread());
+
+#SD
+#course_type only Course and Community?
+#
+ my @crumbs;
+ unless (($forcereg) &&
+ ($env{'request.noversionuri'} eq '/adm/navmaps') &&
+ ($mapurl eq $env{'course.'.$env{'request.course.id'}.'.url'})) {
+ @crumbs = ({text => Apache::loncommon::course_type()
+ . ' Contents',
+ href => "Javascript:gopost('/adm/navmaps','')"});
+ }
+ if ($mapurl ne $env{'course.'.$env{'request.course.id'}.'.url'}) {
+ push(@crumbs, {text => '...',
+ no_mt => 1});
+ }
+
+ push @crumbs, {text => $maptitle, no_mt => 1} if ($maptitle
+ && $maptitle ne 'default.sequence'
+ && $maptitle ne $coursetitle);
+
+ push @crumbs, {text => $restitle, no_mt => 1} if $restitle;
+ &Apache::lonhtmlcommon::clear_breadcrumbs();
+ &Apache::lonhtmlcommon::add_breadcrumb(@crumbs);
+ } else {
+ $resurl = $env{'request.noversionuri'};
+ my $courseurl = &Apache::lonnet::courseid_to_courseurl($env{'request.course.id'});
+ my $crstype = &Apache::loncommon::course_type();
+ my $title = &mt('View Resource');
+ if ($resurl =~ m{^\Q/uploaded$courseurl/supplemental/\E(default|\d+)/}) {
+ &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['folderpath','title']);
+ &Apache::lonhtmlcommon::clear_breadcrumbs();
+ if ($env{'form.title'}) {
+ $title = $env{'form.title'};
+ }
+ my $trail;
+ if ($env{'form.folderpath'}) {
+ &prepare_functions($resurl,$forcereg,$group,undef,undef,1);
+ ($trail) =
+ &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
+ } else {
+ &Apache::lonhtmlcommon::add_breadcrumb(
+ {text => "Supplemental $crstype Content",
+ href => "javascript:gopost('/adm/supplemental','')"});
+ $title = &mt('View Resource');
+ ($trail) =
+ &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);
+ $title = &mt('Syllabus File');
+ my ($trail) =
+ &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
+ return $trail;
+ }
+ unless ($env{'request.state'} eq 'construct') {
+ &Apache::lonhtmlcommon::clear_breadcrumbs();
+ &Apache::lonhtmlcommon::add_breadcrumb({text => 'View Resource'});
+ }
+ }
+ } elsif (! $const_space){
+ #a situation when we're looking at a resource outside of context of a
+ #course or construction space (e.g. with cumulative rights)
+ &Apache::lonhtmlcommon::clear_breadcrumbs();
+ unless ($env{'request.noversionuri'} =~ m{^/adm/$match_domain/$match_username/aboutme$}) {
+ &Apache::lonhtmlcommon::add_breadcrumb({text => 'View Resource'});
+ }
}
- my $timesync=($textual?'':'swmenu.syncclock(1000*'.time.');');
- my $tablestart=($noremote?'