--- loncom/interface/lonmenu.pm 2010/05/26 19:50:46 1.315.2.1
+++ loncom/interface/lonmenu.pm 2012/03/03 01:01:33 1.315.2.15.2.2
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Routines to control the menu
#
-# $Id: lonmenu.pm,v 1.315.2.1 2010/05/26 19:50:46 raeburn Exp $
+# $Id: lonmenu.pm,v 1.315.2.15.2.2 2012/03/03 01:01:33 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -205,10 +205,10 @@ sub prep_menuitem {
} else { # textual Link
$link = &mt($$menuitem[3]);
}
- if($$menuitem[4] eq 'newmsg'){ #special style for New Messages
- return '
'.$link.'';
- }
- return ''.$link.'';
+ return '$link|;
}
# primary_menu() evaluates @primary_menu and returns XHTML for the menu
@@ -245,26 +245,63 @@ sub primary_menu {
if ($$menuitem[3] eq 'Help') { # special treatment for helplink
- $menu .= ''.&Apache::loncommon::top_nav_help('Help').'';
+ 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);
}
}
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 $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 $canviewgrps = &Apache::lonnet::allowed('vcg', $crs_sec);
+ my $author = getauthor();
+
my $showlink = &show_return_link();
my %groups = &Apache::lonnet::get_active_groups(
$env{'user.domain'}, $env{'user.name'},
@@ -274,6 +311,7 @@ sub 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
@@ -295,6 +333,8 @@ sub secondary_menu {
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
@@ -336,6 +376,8 @@ sub secondary_menu {
$menu =~ s/\[url\]/$escurl/g;
$menu =~ s/\[symb\]/$escsymb/g;
}
+ $menu =~ s/\[uname\]/$$author{user}/g;
+ $menu =~ s/\[udom\]/$$author{dom}/g;
return "";
}
@@ -411,12 +453,12 @@ sub innerregister {
$newmail= 'swmenu.setstatus("you have","messages");';
}
- my ($breadcrumb,$separator);
+ my ($breadcrumb,$separator,$resurl);
if ($noremote
&& ($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);
@@ -430,8 +472,12 @@ sub innerregister {
my @crumbs;
unless (($forcereg) && ($env{'request.noversionuri'} eq '/adm/navmaps')
&& ($mapurl eq $env{'course.'.$env{'request.course.id'}.'.url'})) {
+ my $navhref = "javascript:gopost('/adm/navmaps','')";
+ if ($env{'environment.remotenavmap'} eq 'on') {
+ $navhref = "javascript:gonav('/adm/navmaps');";
+ }
@crumbs = ({text => $contentstext,
- href => "Javascript:gopost('/adm/navmaps','')"});
+ href => $navhref});
}
if ($mapurl ne $env{'course.'.$env{'request.course.id'}.'.url'}) {
push(@crumbs, {text => '...',
@@ -446,6 +492,7 @@ sub innerregister {
&Apache::lonhtmlcommon::clear_breadcrumbs();
&Apache::lonhtmlcommon::add_breadcrumb(@crumbs);
+
#$breadcrumb .= &Apache::lonhtmlcommon::breadcrumbs(undef,undef,0);
unless (($env{'request.state'} eq 'edit') || ($newmail) ||
($env{'request.state'} eq 'construct') ||
@@ -453,6 +500,11 @@ sub innerregister {
$separator = &Apache::loncommon::head_subbox();
}
#
+ } 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'});
}
if ($env{'request.state'} eq 'construct') {
$newmail = $titletable;
@@ -546,6 +598,8 @@ 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)) {
@@ -556,18 +610,20 @@ sub innerregister {
# Check that the user has permission to edit this resource
($cfuname,$cfudom)=&Apache::loncacc::constructaccess($file,$1);
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'}) {
@@ -579,9 +635,19 @@ sub innerregister {
if ($nocrsedit) {
$editbutton=&clear(6,1);
} else {
+ my $bot = "go('$cfile')";
+ if ($switchserver) {
+ if ( $env{'request.symb'} && $env{'request.course.id'} ) {
+ my ($mapurl,$rid,$resurl) = &Apache::lonnet::decode_symb(&Apache::lonnet::symbread());
+ $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.gif','edit[_1]','resource[_2]',
- "go('".$cfile."');","Edit this resource");
+ $bot,"Edit this resource");
$noeditbutton = 0;
}
} elsif ($editbutton eq '') {
@@ -604,6 +670,18 @@ 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
@@ -646,6 +724,18 @@ ENDMENUITEMS
# We are in a course and looking at a registred URL
# Should probably be in mydesk.tab
#
+
+ my %icon_text;
+ if ($noremote) {
+ %icon_text = &Apache::lonlocal::texthash (
+ annotate => 'Notes',
+ bookmark => 'Bookmark',
+ catalog => 'Info',
+ evaluate => 'Evaluate',
+ feedback => 'Communicate',
+ printout => 'Print',
+ );
+ }
$menuitems=(< 0){
$menuitems.="anot.gif";
}
$menuitems.="&anno-[_1]&tations[_1]&annotate()&";
-$menuitems.="Make notes and annotations about this resource&&1\n";
+$menuitems.="Make notes and annotations about this resource&&1&$icon_text{'annotate'}\n";
unless ($noremote) {
my $showreqcrs = &check_for_rcrs();
@@ -678,21 +771,29 @@ $menuitems.="Make notes and annotations
}
unless ($env{'request.noversionuri'}=~/\/(bulletinboard|smppg|navmaps|syllabus|aboutme|viewclasslist|portfolio)(\?|$)/) {
if ((!$env{'request.enc'}) && ($env{'request.noversionuri'} !~ m{^/adm/wrapper/ext/})) {
+ my $tail;
+ unless ($env{'request.state'} eq 'construct') {
+ $tail = '&&&'.$icon_text{'catalog'};
+ }
$menuitems.=(<13)) { return ''; }
@@ -1170,9 +1273,13 @@ sub switch {
if ($env{'environment.icons'} eq 'iconsonly') {
$inlineremote[$idx]=''.$pic.'';
} else {
+ my $icon_text = $desc;
+ if ($inlinetools) {
+ $icon_text = $inlinetools.' ';
+ }
$inlineremote[$idx]=
'';
+ '';
}
}
}
@@ -1272,6 +1379,13 @@ sub rawconfig {
my ($row,$col,$pro,$prt,$img,$top,$bot,$act,$desc,$cat)=split(/\:/,$line);
$prt=~s/\$uname/$uname/g;
$prt=~s/\$udom/$udom/g;
+ if ($env{'environment.remotenavmap'} eq 'on') {
+ unless ($env{'environment.remote'} eq 'on') {
+ if ($img eq 'nav.gif') {
+ $act = "gonav('/adm/navmaps','')";
+ }
+ }
+ }
if ($prt =~ /\$crs/) {
next unless ($env{'request.course.id'});
next if ($crstype eq 'Community');
@@ -1568,6 +1682,9 @@ sub utilityfunctions {
my $end_page_bookmark =
&Apache::loncommon::end_page({'js_ready' => 1});
+ my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
+ &mt('Switch server?');
+
return (<{$destination})) {
+ $priv = $reqprivs->{$destination};
+ }
+ }
if ($env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum}) {
my ($start,$end) = split(/\./,$env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum});
@@ -1798,7 +1928,7 @@ sub roles_selector {
}
}
if ($is_cc) {
- &get_all_courseroles($cdom,$cnum,\%courseroles,\%seccount);
+ &get_all_courseroles($cdom,$cnum,\%courseroles,\%seccount,\%courseprivs,$priv);
} else {
my %gotnosection;
foreach my $item (keys(%env)) {
@@ -1814,6 +1944,18 @@ sub roles_selector {
$gotnosection{$role} = 1;
}
}
+ if ($priv ne '') {
+ my $cnumsec = $cnum;
+ if ($sec ne '') {
+ $cnumsec .= "/$sec";
+ }
+ $courseprivs{"$role./$cdom/$cnumsec./"} =
+ $env{"user.priv.$role./$cdom/$cnumsec./"};
+ $courseprivs{"$role./$cdom/$cnumsec./$cdom/"} =
+ $env{"user.priv.$role./$cdom/$cnumsec./$cdom/"};
+ $courseprivs{"$role./$cdom/$cnumsec./$cdom/$cnumsec"} =
+ $env{"user.priv.$role./$cdom/$cnumsec./$cdom/$cnumsec"};
+ }
if (ref($courseroles{$role}) eq 'ARRAY') {
if ($sec ne '') {
if (!grep(/^\Q$sec\E$/,@{$courseroles{$role}})) {
@@ -1839,7 +1981,7 @@ sub roles_selector {
}
my @roles_order = ($ccrole,'in','ta','ep','ad','st');
if (keys(%courseroles) > 1) {
- $role_selector = &jump_to_role($cdom,$cnum,\%seccount,\%courseroles);
+ $role_selector = &jump_to_role($cdom,$cnum,\%seccount,\%courseroles,\%courseprivs,$priv);
$role_selector .= '