--- loncom/interface/lonmenu.pm 2003/03/03 13:03:58 1.45
+++ loncom/interface/lonmenu.pm 2012/05/29 16:25:53 1.380
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Routines to control the menu
#
-# $Id: lonmenu.pm,v 1.45 2003/03/03 13:03:58 www Exp $
+# $Id: lonmenu.pm,v 1.380 2012/05/29 16:25:53 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -25,420 +25,839 @@
#
# http://www.lon-capa.org/
#
-# (TeX Conversion Module
#
-# 05/29/00,05/30 Gerd Kortemeyer)
-#
-# 10/05,05/28,05/30,06/01,06/08,06/09,07/04,08/07 Gerd Kortemeyer
-# 02/15/02 Matthew Hall
+
+=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 XHTML for the menu
+that contains 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.
+
+=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::loncommon;
-use Apache::File;
-use vars qw(@desklines $readdesk);
-
-# ============================= This gets called at the top of the body section
-
-sub menubuttons {
- my $forcereg=shift;
- my $target =shift;
- my $registration=shift;
- unless ($ENV{'browser.interface'} eq 'textual') { return ''; }
-# Textual display only
- my $output=(<
-// BEGIN LON-CAPA Internal
-
-Main Menu
-
-ENDMAINMENU
- if ($registration) { $output.=&innerregister($forcereg,$target); }
- return $output."";
+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 %category_names %category_members %category_positions
+ $readdesk @primary_menu %primary_submenu @secondary_menu);
+
+my @inlineremote;
+
+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 XHTML for the menu
+# that contains following links:
+# About, Message, Personal, 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)
+ 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];
+ 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') &&
+ ((!&Apache::lonnet::allowed('bre',"/res/$env{'user.domain'}/")) &&
+ (!&Apache::lonnet::allowed('bro',"/res/$env{'user.domain'}/"))));
+ next if (($item->[2] eq 'reqcrs') && (!&check_for_rcrs()));
+ next if ((($item->[2] eq 'portfolio') ||
+ ($item->[2] eq 'blog')) &&
+ (!&Apache::lonnet::usertools_access('','',$item->[2],
+ undef,'tools')));
+ push(@primsub,$item);
+ }
+ if (@primsub > 0) {
+ $menu .= &create_submenu($link,$target,$title,\@primsub);
+ } elsif ($link) {
+ $menu .= '
';
+ }
+ }
+ } elsif ($$menuitem[3] eq 'Help') { # special treatment for helplink
+ if ($public) {
+ my $origmail = $Apache::lonnet::perlvar{'lonSupportEMail'};
+ my $defdom = &Apache::lonnet::default_login_domain();
+ my $to = &Apache::loncommon::build_recipient_list(undef,
+ 'helpdeskmail',
+ $defdom,$origmail);
+ if ($to ne '') {
+ $menu .= &prep_menuitem($menuitem);
+ }
+ } else {
+ $menu .= '
'.&Apache::loncommon::top_nav_help('Help').'
';
+ }
+ } else {
+ $menu .= prep_menuitem($menuitem);
+ }
+ }
+ $menu =~ s/\[domain\]/$env{'user.domain'}/g;
+ $menu =~ s/\[user\]/$env{'user.name'}/g;
+
+ return "$menu";
}
-# ====================================== This gets called in the header section
+#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;
+ }
-sub registerurl {
- my $forcereg=shift;
- my $target = shift;
- my $result = '';
-
- if ($target eq 'edit') {
- $result .="\n";
- }
- if (($ENV{'browser.interface'} eq 'textual') ||
- ((($ENV{'request.publicaccess'}) ||
- (!&Apache::lonnet::is_on_map($ENV{'REQUEST_URI'}))) &&
- (!$forcereg))) {
- return $result.
- '';
- }
-# Graphical display after login only
- if ($Apache::lonxml::registered && !$forcereg) { return ''; }
- $result.=&innerregister($forcereg,$target);
- return $result;
+ # if wrong server
+ return;
+}
+
+sub secondary_menu {
+ my $menu;
+
+ my $crstype = &Apache::loncommon::course_type();
+ 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 $canviewroster = $env{'course.'.$env{'request.course.id'}.'.student_classlist_view'};
+ my $canviewgrps = &Apache::lonnet::allowed('vcg', $crs_sec);
+ my $canmodifyuser = &Apache::lonnet::allowed('cst', $crs_sec);
+ my $canviewwnew = &Apache::lonnet::allowed('whn', $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 %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'});
+
+ foreach my $menuitem (@secondary_menu) {
+ # evaluate conditions
+ next if ref($menuitem) ne 'ARRAY';
+ next if $$menuitem[4] ne 'always'
+ && $$menuitem[4] ne 'author'
+ && !$env{'request.course.id'};
+ next if $$menuitem[4] =~ /^mdc/
+ && !$canedit;
+ next if $$menuitem[4] eq 'nvgr'
+ && $canvgr;
+ next if $$menuitem[4] eq 'vgr'
+ && !$canvgr;
+ next if $$menuitem[4] eq 'cst'
+ && !$canmodifyuser;
+ next if $$menuitem[4] eq 'ncst'
+ && ($canmodifyuser || !$canviewroster);
+ next if $$menuitem[4] eq 'mgr'
+ && !$canmgr;
+ next if $$menuitem[4] eq 'nmgr'
+ && $canmgr;
+ next if $$menuitem[4] eq 'whn'
+ && !$canviewwnew;
+ next if $$menuitem[4] eq 'opa'
+ && !$canmodpara;
+ next if $$menuitem[4] =~ /showgroups$/
+ && !$canviewgrps
+ && !%groups;
+ next if $$menuitem[4] eq 'author'
+ && !$author;
+
+ if ($$menuitem[3] eq 'Roles' && $env{'request.course.id'}) {
+ # 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 ? "
";
}
-# =========== This gets called in order to register a URL, both with the Remote
-# =========== and in the body of the document
+sub create_submenu {
+ my ($link,$target,$title,$submenu) = @_;
+ return unless (ref($submenu) eq 'ARRAY');
+ my $disptarget;
+ if ($target ne '') {
+ $disptarget = ' target="'.$target.'"';
+ }
+ my $menu = '