--- loncom/interface/lonmenu.pm 2009/05/26 20:30:28 1.268
+++ loncom/interface/lonmenu.pm 2009/12/07 20:04:18 1.309.2.1
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Routines to control the menu
#
-# $Id: lonmenu.pm,v 1.268 2009/05/26 20:30:28 droeschl Exp $
+# $Id: lonmenu.pm,v 1.309.2.1 2009/12/07 20:04:18 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -26,15 +26,10 @@
# 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
+# 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; ignored it
-# browser.interface is 'textual'
-#
+# control, otherwise they render the main window controls;
=head1 NAME
@@ -118,11 +113,6 @@ The javascript is usually similar to "go
=item get_nav_status()
-=item convert_menu_function()
-
-FIXME this needs to move into mydesktab and the other locations
-the text is generated
-
=item hidden_button_check()
=item roles_selector()
@@ -142,15 +132,212 @@ use Apache::loncommon();
use Apache::lonenc();
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) = @_;
+ 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;
+ my $custommenu = &Apache::loncommon::needs_gci_custom();
+ # 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 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,
+ && $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' # 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
+ $menu .= ''.&Apache::loncommon::top_nav_help('Help').'';
+ } else {
+ my @items = @{$menuitem};
+ $items[0] = 'javascript:'.$menuitem->[0].';';
+ $menu .= &prep_menuitem(\@items);
+ }
+ }
+
+ return "";
+}
+
+
+sub secondary_menu {
+ 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'});
+ foreach my $menuitem (@secondary_menu) {
+ # evaluate conditions
+ next if ref($menuitem) ne 'ARRAY';
+ next if $$menuitem[4] ne 'always'
+ && !$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;
+
+ 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"
+ : '';
+ } 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]');";
+ } else {
+ $items[0] = "javascript:go('$menuitem->[0]');";
+ }
+ $menu .= &prep_menuitem(\@items);
+ } 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 "";
+}
+
+sub gci_secondary_menu {
+ my %courses = (
+ 'review' => 'gci_9615072b469884921gcil1',
+ 'submit' => 'gci_1H96711d710194bfegcil1',
+ );
+ my %linktext = (
+ 'review' => 'Review Questions',
+ 'submit' => 'Submit Questions',
+ 'createtest' => 'Create a Test',
+ );
+ my (%links,$current);
+ foreach my $key (keys(%courses)) {
+ $links{$key} = "javascript:switchpage('$key');";
+ if ($env{'request.course.id'} eq $courses{$key}) {
+ $links{$key} = '/adm/navmaps';
+ $current = $key;
+ }
+ }
+ $links{'createtest'} = "javascript:switchpage('createtest');";
+ if (($ENV{'REQUEST_URI'} eq '/adm/requestcourse') ||
+ ($env{'form.orgurl'} eq '/adm/requestcourse')) {
+ $current = 'createtest';
+ }
+ my @menutabs = ('review','submit','createtest');
+ if ($env{'user.adv'}) {
+ my $key = 'managetest';
+ push(@menutabs,$key);
+ $linktext{$key} = 'Manage Tests';
+ $links{$key} = "javascript:switchpage('$key');";
+ if (($current eq '') && (($ENV{'REQUEST_URI'} eq '/adm/menu') ||
+ ($env{'form.orgurl'} eq '/adm/menu'))) {
+ $current = $key;
+ }
+ }
+ 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' => 'Navigate Contents',
+ 'nav' => 'Course Contents',
'main' => 'Main Menu',
'roles' => (&Apache::loncommon::show_course()?
'Courses':'Roles'),
@@ -160,14 +347,18 @@ sub initlittle {
'login' => 'Log In',
'launch' => 'Launch Remote Control',
'groups' => 'Groups',
- 'gdoc' => 'Group Documents',
+ '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 $registration=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') ||
@@ -184,6 +375,9 @@ sub menubuttons {
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'}));
@@ -192,6 +386,9 @@ sub menubuttons {
$logo.'" alt="LON-CAPA Logo" class="LC_noBorder" />';
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:;
@@ -199,6 +396,9 @@ sub menubuttons {
}
}
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;
@@ -222,7 +422,7 @@ sub menubuttons {
my %lt=&initlittle();
my $domain=&Apache::loncommon::determinedomain();
- my $function =&Apache::loncommon::get_users_function();
+ 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);
@@ -230,15 +430,11 @@ sub menubuttons {
if ($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public') {
return (<
-
- $logo |
- |
-
- $lt{'login'}
- |
-
-
+
+
ENDINLINEMENU
}
$roles = ''.$lt{'roles'}.'';
@@ -252,9 +448,10 @@ ENDINLINEMENU
$navmaps=(<$lt{'nav'}
ENDNAV
- my $is_group = (&Apache::loncommon::course_type() eq 'Group');
+ my $is_community =
+ (&Apache::loncommon::course_type() eq 'Community');
if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
- my $text = ($is_group) ? $lt{'gdoc'} : $lt{'docs'};
+ my $text = ($is_community) ? $lt{'gdoc'} : $lt{'docs'};
$docs=(<$text
ENDDOCS
@@ -281,35 +478,31 @@ ENDRELOAD
$lt{'ret'}
ENDCRELOAD
}
- my $reg='';
- if ($registration) {
- $reg=&innerregister($forcereg,$titletable);
- }
- my $form=&serverform();
- my $utility=&utilityfunctions();
-
- my $messagelink = "";
- if(&Apache::lonmsg::mynewmail()){
- $messagelink = 'Message(new)'
- }else{
- $messagelink = 'Message'
- }
- my $helplink=&Apache::loncommon::top_nav_help('Help');
+ my $reg = $forcereg ? &innerregister($forcereg,$titletable) : '';
+ my $form = &serverform();
+ my $utility = &utilityfunctions();
+
+ #Prepare the message link that indicates the arrival of new mail
+ my $messagelink = &Apache::lonmsg::mynewmail() ? "Message (new)" : "Message";
+ $messagelink = ''
+ . mt($messagelink) .'';
+
+ my $helplink = &Apache::loncommon::top_nav_help('Help');
return (<
-// BEGIN LON-CAPA Internal
//
-