--- loncom/interface/lonmenu.pm 2010/05/30 18:30:52 1.328 +++ loncom/interface/lonmenu.pm 2010/06/06 11:56:12 1.329 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Routines to control the menu # -# $Id: lonmenu.pm,v 1.328 2010/05/30 18:30:52 droeschl Exp $ +# $Id: lonmenu.pm,v 1.329 2010/06/06 11:56:12 droeschl Exp $ # # Copyright Michigan State University Board of Trustees # @@ -225,6 +225,30 @@ sub primary_menu { return "
    $menu
"; } +#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; @@ -238,6 +262,7 @@ sub secondary_menu { 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 $author = getauthor(); my $showlink = &show_return_link(); my %groups = &Apache::lonnet::get_active_groups( @@ -249,6 +274,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 @@ -268,6 +294,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 @@ -300,6 +328,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 ""; }