--- loncom/interface/lonmenu.pm 2009/07/09 08:53:39 1.272
+++ 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.272 2009/07/09 08:53:39 droeschl Exp $
+# $Id: lonmenu.pm,v 1.284 2009/10/06 14:06:12 droeschl Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -137,15 +137,140 @@ 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 = 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' => 'Navigate Contents',
+ 'nav' => 'Course Contents',
'main' => 'Main Menu',
'roles' => (&Apache::loncommon::show_course()?
'Courses':'Roles'),
@@ -159,10 +284,14 @@ 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 $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') ||
@@ -179,6 +308,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'}));
@@ -187,6 +319,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:;
@@ -194,6 +329,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;
@@ -272,24 +410,20 @@ 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
//
@@ -346,8 +480,14 @@ sub registerurl {
(!&Apache::lonnet::is_on_map(
&unescape($env{'request.noversionuri'})))) &&
(!$forcereg))) {
- return $result.
- ''.$force_title;
+ return
+ $result
+ .''
+ .$force_title;
}
# Graphical display after login only
if ($env{'request.registered'} && !$forcereg) { return ''; }
@@ -373,12 +513,13 @@ sub innerregister {
my $reopen=&Apache::lonmenu::reopenmenu();
my $newmail='';
- my $breadcrumb;
if (&Apache::lonmsg::newmail() && !$noremote) {
# We have new mail and remote is up
$newmail= 'swmenu.setstatus("you have","messages");';
}
+
+ my $breadcrumb;
if ($noremote
&& ($env{'request.symb'})
&& ($env{'request.course.id'})) {
@@ -453,6 +594,9 @@ sub innerregister {
}
if ($env{'user.author'}) {
if ($env{'request.role'}=~/^(aa|ca|au)/) {
+#
+# We have the role of an author
+#
# Set defaults for authors
my ($top,$bottom) = ('con-','struct');
my $action = "go('/priv/".$env{'user.name'}."');";
@@ -481,6 +625,11 @@ sub innerregister {
$noeditbutton = 0;
}
}
+#
+# We are an author for some stuff, but currently do not have the role of author.
+# Figure out if we have authoring privileges for the resource we are looking at.
+# This should maybe become a privilege check in lonnet
+#
##
## Determine if user can edit url.
##
@@ -539,6 +688,9 @@ sub innerregister {
# Prepare the rest of the buttons
my $menuitems;
if ($const_space) {
+#
+# We are in construction space
+#
my ($uname,$thisdisfn) =
($env{'request.filename'}=~m|^/home/([^/]+)/public_html/(.*)|);
my $currdir = '/priv/'.$uname.'/'.$thisdisfn;
@@ -548,6 +700,9 @@ sub innerregister {
$currdir =~ s|[^/]+$||;
my $cleandisfn = &Apache::loncommon::escape_single($thisdisfn);
my $esc_currdir = &Apache::loncommon::escape_single($currdir);
+#
+# Probably should be in mydesk.tab
+#
$menuitems=(< 0){
$menuitems.="&anno-[_1]&tations[_1]&annotate()&";
$menuitems.="Make notes and annotations about this resource&&1\n";
+ unless ($noremote) {
+ my $showreqcrs = &check_for_rcrs();
+ if ($showreqcrs) {
+ $menuitems.="s&8&1&rcrs.gif&request[_1]&course[_16]".
+ "&go('/adm/requestcourse')&Course requests\n";
+ }
+ }
unless ($env{'request.noversionuri'}=~/\/(bulletinboard|smppg|navmaps|syllabus|aboutme)(\?|$)/) {
if (!$env{'request.enc'}) {
$menuitems.=(<
+//
ENDREGTHIS
}
@@ -732,6 +900,7 @@ ENDDONOTREGTEXT
$result = (<
+//
ENDDONOTREGTHIS
}
@@ -826,6 +996,7 @@ sub startupremote {
my $message=&mt('"Waiting for Remote Control window to load: "+[_1]','waited');
return(<
+//
ENDREMOTESTARTUP
}
@@ -883,8 +1055,10 @@ ENDREMOTESTARTUP
sub setflags() {
return(<
+//
ENDSETFLAGS
}
@@ -893,7 +1067,9 @@ sub maincall() {
if ($env{'environment.remote'} eq 'off') { return ''; }
return(<
+//
ENDMAINCALL
}
@@ -935,7 +1111,12 @@ sub reopenmenu {
sub open {
my $returnval='';
if ($env{'environment.remote'} eq 'off') {
- return '';
+ return
+ '';
}
my $menuname = &get_menu_name();
@@ -948,11 +1129,13 @@ sub open {
#}
#ENDRESIZE
# }
- $returnval.=(<
ENDOPEN
return '';
}
@@ -963,6 +1146,7 @@ ENDOPEN
sub clear {
my ($row,$col)=@_;
unless ($env{'environment.remote'} eq 'off') {
+ if (($row<1) || ($row>13)) { return ''; }
return "\n".qq(window.status+='.';swmenu.clearbut($row,$col););
} else {
$inlineremote[10*$row+$col]='';
@@ -988,6 +1172,7 @@ sub switch {
$category_members{$cat}.=':'.$idx;
unless ($env{'environment.remote'} eq 'off') {
+ if (($row<1) || ($row>13)) { return ''; }
# Remote
return "\n".
qq(window.status+='.';swmenu.switchbutton($row,$col,"$img","$top","$bot","$act","$desc"););
@@ -1005,7 +1190,7 @@ sub switch {
&Apache::loncommon::lonhttpdurl('/res/adm/pages/'.$img).
'" align="'.($nobreak==3?'right':'left').'" class="LC_noBorder" />';
if ($env{'browser.interface'} eq 'faketextual') {
-# Accessibility
+# Main Menu
if ($nobreak==3) {
$inlineremote[$idx]="\n".
'