--- loncom/interface/lonmenu.pm 2009/09/27 11:05:06 1.282
+++ loncom/interface/lonmenu.pm 2009/10/06 14:06:12 1.284
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Routines to control the menu
#
-# $Id: lonmenu.pm,v 1.282 2009/09/27 11:05:06 amueller Exp $
+# $Id: lonmenu.pm,v 1.284 2009/10/06 14:06:12 droeschl Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -139,15 +139,135 @@ use Apache::lonlocal;
use LONCAPA qw(:DEFAULT :match);
use HTML::Entities();
-use vars qw(@desklines %category_names %category_members %category_positions $readdesk);
+use vars qw(@desklines %category_names %category_members %category_positions
+ $readdesk @primary_menu @secondary_menu);
my @inlineremote;
+sub prep_menuitem {
+ my $menuitem = shift;
+ return '' unless ref $menuitem eq 'ARRAY';
+ my $link;
+ if ($$menuitem[1]) { # graphical Link
+ $link = "";
+ } else { # textual Link
+ $link = mt($$menuitem[3]);
+ }
+ return "
$link";
+}
+
+# primary_menu() 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
+sub primary_menu {
+ my $menu;
+ # each element of @primary contains following array:
+ # (link url, icon path, alt text, link text, condition)
+ foreach my $menuitem (@primary_menu) {
+ # evaluate conditions
+ 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,
+ && $env{'user.name'} eq 'public' ##who should not see all
+ && $env{'user.domain'} eq 'public'; ##links
+ next if $$menuitem[4] eq 'onlypublic'# hide links which are
+ && $env{'user.name'} ne 'public' # only visible to public
+ && $env{'user.domain'} ne '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(); ##
+
+
+ if ($$menuitem[3] eq 'Help') { # special treatment for helplink
+ $menu .= ''.Apache::loncommon::top_nav_help('Help').'';
+ } else {
+ $menu .= prep_menuitem(\@$menuitem);
+ }
+ }
+
+ return "";
+}
+
+
+sub secondary_menu {
+ my $menu;
+
+ foreach my $menuitem (@secondary_menu) {
+ # evaluate conditions
+ next if $$menuitem[4] ne 'always'
+ && !$env{'request.course.id'};
+ next if $$menuitem[4] eq 'showreturn'
+ && !show_return_link()
+ && !($env{'request.state'} eq 'construct');
+ next if $$menuitem[4] =~ /^mdc/
+ && !Apache::lonnet::allowed('mdc', $env{'request.course.id'});
+ next if $$menuitem[4] =~ /nogrp$/
+ && Apache::loncommon::course_type() eq 'Group';
+ next if $$menuitem[4] =~ /group$/
+ && Apache::loncommon::course_type() ne 'Group';
+ next if $$menuitem[4] eq 'remotenav'
+ && $env{'environment.remotenavmap'} ne 'on';
+ next if $$menuitem[4] eq 'noremotenav'
+ && $env{'environment.remotenavmap'} eq 'on';
+ next if $$menuitem[4] =~ /showgroups$/
+ && !Apache::lonnet::allowed('vcg', $env{'request.course.id'}
+ . ($env{'request.course.sec'} ? "/$env{'request.course.sec'}"
+ : ''))
+ && !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'});
+
+
+ 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 ? "$roles_selector"
+ : '';
+ } else {
+ $menu .= prep_menuitem(\@$menuitem);
+ }
+ }
+ if ($menu =~ /\[url\].*\[symb\]/) {
+ my $escurl = escape( Apache::lonenc::check_encrypt(
+ $env{'request.noversionuri'}));
+
+ my $escsymb = escape( Apache::lonenc::check_encrypt(
+ $env{'request.symb'}));
+
+ if ( $env{'request.state'} eq 'construct'
+ and ( $env{'request.noversionuri'} eq ''
+ || !defined($env{'request.noversionuri'})))
+ {
+ ($escurl = $env{'request.filename'}) =~
+ s{^/home/([^/]+)/public_html/(.*)$}{/priv/$1/$2};
+
+ $escurl = escape($escurl);
+ }
+ $menu =~ s/\[url\]/$escurl/g;
+ $menu =~ s/\[symb\]/$escsymb/g;
+ }
+
+ 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',
@@ -164,6 +284,8 @@ sub initlittle {
);
}
+#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;
@@ -1867,34 +1989,34 @@ END
BEGIN {
if (! defined($readdesk)) {
- {
- my $tabfile = $Apache::lonnet::perlvar{'lonTabDir'}.'/mydesk.tab';
- if ( CORE::open( my $config,"<$tabfile") ) {
- while (my $configline=<$config>) {
- $configline=(split(/\#/,$configline))[0];
- $configline=~s/^\s+//;
- chomp($configline);
+ {
+ my $tabfile = $Apache::lonnet::perlvar{'lonTabDir'}.'/mydesk.tab';
+ if ( CORE::open( my $config,"<$tabfile") ) {
+ while (my $configline=<$config>) {
+ $configline=(split(/\#/,$configline))[0];
+ $configline=~s/^\s+//;
+ chomp($configline);
if ($configline=~/^cat\:/) {
- my @entries=split(/\:/,$configline);
- $category_positions{$entries[2]}=$entries[1];
- $category_names{$entries[2]}=$entries[3];
- } elsif ($configline) {
- push(@desklines,$configline);
- }
- }
- CORE::close($config);
- }
- }
- $readdesk='done';
+ my @entries=split(/\:/,$configline);
+ $category_positions{$entries[2]}=$entries[1];
+ $category_names{$entries[2]}=$entries[3];
+ } elsif ($configline=~/^prim\:/) {
+ my @entries = (split(/\:/, $configline))[1..5];
+ push @primary_menu, \@entries;
+ } elsif ($configline=~/^scnd\:/) {
+ my @entries = (split(/\:/, $configline))[1..5];
+ push @secondary_menu, \@entries;
+ } elsif ($configline) {
+ push(@desklines,$configline);
+ }
+ }
+ CORE::close($config);
+ }
+ }
+ $readdesk='done';
}
}
1;
__END__
-
-
-
-
-
-