--- loncom/interface/lonmenu.pm 2010/03/29 14:50:46 1.324
+++ loncom/interface/lonmenu.pm 2012/08/03 01:23:38 1.383
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Routines to control the menu
#
-# $Id: lonmenu.pm,v 1.324 2010/03/29 14:50:46 raeburn Exp $
+# $Id: lonmenu.pm,v 1.383 2012/08/03 01:23:38 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -26,8 +26,6 @@
# http://www.lon-capa.org/
#
#
-# There is one parameter controlling the action of this module:
-#
=head1 NAME
@@ -35,7 +33,8 @@ Apache::lonmenu
=head1 SYNOPSIS
-Coordinates the response to clicking an image.
+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.
@@ -74,10 +73,19 @@ It is set to 'done' in the BEGIN block o
=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.
+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
@@ -107,7 +115,17 @@ entries from mydesk.tab
Same as primary_menu() but operates on @secondary_menu.
-=item show_return_link()
+=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()
@@ -131,6 +149,9 @@ The javascript is usually similar to "go
=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()
@@ -155,11 +176,13 @@ 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 @secondary_menu);
+ $readdesk @primary_menu %primary_submenu @secondary_menu);
my @inlineremote;
@@ -177,12 +200,12 @@ sub prep_menuitem {
return '$link|;
+ . qq| href="$$menuitem[0]" target="_top">$link|;
}
# primary_menu() evaluates @primary_menu and returns XHTML for the menu
# that contains following links:
-# About, Message, Roles, Help, Logout
+# 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 {
@@ -212,54 +235,131 @@ sub primary_menu {
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').'';
+ 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') && (!$env{'user.adv'}));
+ 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 .= ''.&mt($title).'';
+ }
+ }
+ } 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 {
- my @items = @{$menuitem};
- $items[0] = 'javascript:'.$menuitem->[0].';';
- $menu .= &prep_menuitem(\@items);
+ $menu .= prep_menuitem($menuitem);
}
}
+ $menu =~ s/\[domain\]/$env{'user.domain'}/g;
+ $menu =~ s/\[user\]/$env{'user.name'}/g;
return "";
}
+#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;
+ }
+
+ # if wrong server
+ 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 $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] 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] =~ /^Course$/
- && $crstype eq 'Community';
- next if $$menuitem[4] =~ /^Community$/
- && $crstype ne 'Community';
+ 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
@@ -284,34 +384,48 @@ sub secondary_menu {
and ( $env{'request.noversionuri'} eq ''
|| !defined($env{'request.noversionuri'})))
{
- ($escurl = $env{'request.filename'}) =~
- s{^/home/([^/]+)/public_html/(.*)$}{/priv/$1/$2};
-
+ my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
+ ($escurl = $env{'request.filename'}) =~ s{^\Q$londocroot\E}{};
$escurl = &escape($escurl);
}
$menu =~ s/\[url\]/$escurl/g;
$menu =~ s/\[symb\]/$escsymb/g;
}
+ $menu =~ s/\[uname\]/$$author{user}/g;
+ $menu =~ s/\[udom\]/$$author{dom}/g;
return "";
}
-sub show_return_link {
- if (($env{'request.noversionuri'} =~ m{^/adm/(viewclasslist|navmaps)($|\?)})
- || ($env{'request.noversionuri'} =~ m{^/adm/.*/aboutme($|\?)})) {
-
- return if ($env{'form.register'});
- }
- return (($env{'request.noversionuri'}=~m{^/(res|public)/} &&
- $env{'request.symb'} eq '')
- ||
- ($env{'request.noversionuri'}=~ m{^/cgi-bin/printout.pl})
- ||
- (($env{'request.noversionuri'}=~/^\/adm\//) &&
- ($env{'request.noversionuri'}!~/^\/adm\/wrapper\//) &&
- ($env{'request.noversionuri'}!~
- m{^/adm/.*/(smppg|bulletinboard)($|\?)})
- ));
+sub create_submenu {
+ my ($link,$target,$title,$submenu) = @_;
+ return unless (ref($submenu) eq 'ARRAY');
+ my $disptarget;
+ if ($target ne '') {
+ $disptarget = ' target="'.$target.'"';
+ }
+ my $menu = ''.
+ ''.
+ ''.&mt($title).
+ ''.
+ ' ▼'.
+ '';
+ my $count = 0;
+ my $numsub = scalar(@{$submenu});
+ foreach my $item (@{$submenu}) {
+ $count ++;
+ if (ref($item) eq 'ARRAY') {
+ my $borderbot;
+ if ($count == $numsub) {
+ $borderbot = 'border-bottom:1px solid black;';
+ }
+ $menu .= '- '.
+ &mt($item->[1]).'
';
+ }
+ }
+ $menu .= '
';
+ return $menu;
}
sub innerregister {
@@ -325,9 +439,10 @@ sub innerregister {
undef(@inlineremote);
+ my $resurl;
if ( $env{'request.symb'} && $env{'request.course.id'} ) {
- my ($mapurl,$rid,$resurl) = &Apache::lonnet::decode_symb(&Apache::lonnet::symbread());
+ (my $mapurl, my $rid, $resurl) = &Apache::lonnet::decode_symb(&Apache::lonnet::symbread());
my $coursetitle = $env{'course.'.$env{'request.course.id'}.'.description'};
my $maptitle = &Apache::lonnet::gettitle($mapurl);
@@ -356,6 +471,11 @@ sub innerregister {
&Apache::lonhtmlcommon::clear_breadcrumbs();
&Apache::lonhtmlcommon::add_breadcrumb(@crumbs);
+ }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();
+ &Apache::lonhtmlcommon::add_breadcrumb({text => 'View Resource'});
}
# =============================================================================
# ============================ This is for URLs that actually can be registered
@@ -371,23 +491,29 @@ sub innerregister {
my $hwkadd='';
if ($env{'request.symb'} ne '' &&
- $env{'request.filename'}=~/\.(problem|exam|quiz|assess|survey|form|task)$/) {
+ $env{'request.filename'}=~/$LONCAPA::assess_re/) {
if (&Apache::lonnet::allowed('mgr',$crs)) {
- $hwkadd.=&switch('','',7,2,'pgrd.png','problem[_1]','grades[_4]',
+ $hwkadd.=&switch('','',7,2,'pgrd.png','Content Grades','grades[_4]',
"gocmd('/adm/grades','gradingmenu')",
- 'Modify user grades for this assessment resource');
+ 'Content Grades');
} elsif (&Apache::lonnet::allowed('vgr',$crs)) {
- $hwkadd.=&switch('','',7,2,'subm.png','view sub-[_1]','missions[_1]',
+ $hwkadd.=&switch('','',7,2,'subm.png','Content Submissions','missions[_1]',
"gocmd('/adm/grades','submission')",
- 'View user submissions for this assessment resource');
+ 'Content Submissions');
}
}
if ($env{'request.symb'} ne '' &&
&Apache::lonnet::allowed('opa',$crs)) {
- $hwkadd.=&switch('','',7,3,'pparm.png','problem[_2]','parms[_2]',
+ $hwkadd.=&switch('','',7,3,'pparm.png','Content Settings','parms[_2]',
"gocmd('/adm/parmset','set')",
- 'Modify parameter settings for this resource');
+ 'Content Settings');
}
+ if ($env{'request.symb'}=~/^uploaded/ &&
+ &Apache::lonnet::allowed('mdc',$crs)) {
+ $hwkadd.=&switch('','',7,4,'docs.png','Folder/Page Content','parms[_2]',
+ "gocmd('/adm/coursedocs','direct')",
+ 'Folder/Page Content');
+ }
# -- End Homework
###
### Determine whether or not to display the 'cstr' button for this
@@ -407,7 +533,7 @@ sub innerregister {
#
# Set defaults for authors
my ($top,$bottom) = ('con-','struct');
- my $action = "go('/priv/".$env{'user.name'}."');";
+ my $action = "go('/priv/".$env{'user.domain'}.'/'.$env{'user.name'}."');";
my $cadom = $env{'request.role.domain'};
my $caname = $env{'user.name'};
my $desc = "Enter my construction space";
@@ -415,12 +541,12 @@ sub innerregister {
if ($env{'request.role'} =~ /^ca/) {
($cadom,$caname)=($env{'request.role'}=~/($match_domain)\/($match_username)$/);
($top,$bottom) = ('co con-','struct');
- $action = "go('/priv/".$caname."');";
+ $action = "go('/priv/".$cadom.'/'.$caname."');";
$desc = "Enter construction space as co-author";
} elsif ($env{'request.role'} =~ /^aa/) {
($cadom,$caname)=($env{'request.role'}=~/($match_domain)\/($match_username)$/);
($top,$bottom) = ('co con-','struct');
- $action = "go('/priv/".$caname."');";
+ $action = "go('/priv/".$cadom.'/'.$caname."');";
$desc = "Enter construction space as assistant co-author";
}
# Check that we are on the correct machine
@@ -445,28 +571,36 @@ sub innerregister {
my $cfuname='';
my $cfudom='';
my $uploaded;
+ my $switchserver='';
+ my $home;
if ($env{'request.filename'}) {
my $file=&Apache::lonnet::declutter($env{'request.filename'});
if (defined($cnum) && defined($cdom)) {
$uploaded = &is_course_upload($file,$cnum,$cdom);
}
if (!$uploaded) {
- $file=~s/^($match_domain)\/($match_username)/\/priv\/$2/;
+
+ $file=~s{^(priv/$match_domain/$match_username)}{/$1};
+ $file=~s{^($match_domain/$match_username)}{/priv/$1};
+
# Check that the user has permission to edit this resource
- ($cfuname,$cfudom)=&Apache::loncacc::constructaccess($file,$1);
+ my $setpriv = 1;
+ ($cfuname,$cfudom)=&Apache::loncacc::constructaccess($file,$setpriv);
if (defined($cfudom)) {
- my $home=&Apache::lonnet::homeserver($cfuname,$cfudom);
+ $home=&Apache::lonnet::homeserver($cfuname,$cfudom);
my $allowed=0;
my @ids=&Apache::lonnet::current_machine_ids();
foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
if ($allowed) {
$cfile=$file;
+ } else {
+ $switchserver=$file;
}
}
}
}
# Finally, turn the button on or off
- if ($cfile && !$const_space) {
+ if (($cfile || $switchserver) && !$const_space) {
my $nocrsedit;
# Suppress display where CC has switched to student role.
if ($env{'request.course.id'}) {
@@ -478,9 +612,18 @@ sub innerregister {
if ($nocrsedit) {
$editbutton=&clear(6,1);
} else {
+ my $bot = "go('$cfile')";
+ if ($switchserver) {
+ if ( $env{'request.symb'} && $env{'request.course.id'} ) {
+ $cfile = '/adm/switchserver?otherserver='.$home.'&role='.
+ &HTML::Entities::encode($env{'request.role'},'"<>&').'&symb='.
+ &HTML::Entities::encode($env{'request.symb'},'"<>&');
+ $bot = "need_switchserver('$cfile');";
+ }
+ }
$editbutton=&switch
- ('','',6,1,'pcstr.png','edit[_1]','resource[_2]',
- "go('".$cfile."');","Edit this resource");
+ ('','',6,1,'pcstr.png','Edit','resource[_2]',
+ $bot,"Edit this resource");
$noeditbutton = 0;
}
} elsif ($editbutton eq '') {
@@ -495,7 +638,7 @@ sub innerregister {
my $cfile = &edit_course_upload($file,$cnum,$cdom);
if ($cfile) {
$editbutton=&switch
- ('','',6,1,'pcstr.png','edit[_1]',
+ ('','',6,1,'pcstr.png','Edit',
'resource[_2]',"go('".$cfile."');",
'Edit this resource');
}
@@ -503,17 +646,31 @@ sub innerregister {
}
}
}
+ if ($env{'request.course.id'}) {
+ if ($resurl eq "public/$cdom/$cnum/syllabus") {
+ if ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ /\w/) {
+ if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
+ $editbutton=&switch('','',6,1,'pcstr.png','Edit',
+ 'resource[_2]',
+ "go('/adm/courseprefs?phase=display&actions=courseinfo')",
+ 'Edit this resource');
+ }
+ }
+ }
+ }
###
###
# Prepare the rest of the buttons
- my $menuitems;
+ my ($menuitems,$got_prt,$got_wishlist);
if ($const_space) {
#
# We are in construction space
#
- my ($uname,$thisdisfn) =
- ($env{'request.filename'}=~m|^/home/([^/]+)/public_html/(.*)|);
- my $currdir = '/priv/'.$uname.'/'.$thisdisfn;
+
+ my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
+ my ($udom,$uname,$thisdisfn) =
+ ($env{'request.filename'}=~m{^\Q$londocroot/priv/\E([^/]+)/([^/]+)/(.*)$});
+ my $currdir = '/priv/'.$udom.'/'.$uname.'/'.$thisdisfn;
if ($currdir =~ m-/$-) {
$is_const_dir = 1;
} else {
@@ -524,11 +681,11 @@ sub innerregister {
# Probably should be in mydesk.tab
#
$menuitems=(< 0){
}else{
$menuitems.="anot.png";
}
-$menuitems.="&anno-[_1]&tations[_1]&annotate()&";
+$menuitems.="&Notes&&annotate()&";
$menuitems.="Make notes and annotations about this resource&&1\n";
unless ($env{'request.noversionuri'}=~/\/(bulletinboard|smppg|navmaps|syllabus|aboutme|viewclasslist|portfolio)(\?|$)/) {
- if ((!$env{'request.enc'}) && ($env{'request.noversionuri'} !~ m{^/adm/wrapper/ext/})) {
+ if ((!$env{'request.enc'}) && ($env{'request.noversionuri'} !~ m{^/adm/wrapper/ext/}) && ($env{'request.noversionuri'} !~ m{^/uploaded/$match_domain/$match_courseid/docs/})) {
$menuitems.=(<