--- loncom/interface/lonmenu.pm 2010/03/29 14:50:46 1.324 +++ loncom/interface/lonmenu.pm 2010/08/13 13:13:26 1.332 @@ -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.332 2010/08/13 13:13:26 wenzelju Exp $ # # Copyright Michigan State University Board of Trustees # @@ -155,6 +155,7 @@ use Apache::lonhtmlcommon(); use Apache::loncommon(); use Apache::lonenc(); use Apache::lonlocal; +use Apache::lonwishlist(); use LONCAPA qw(:DEFAULT :match); use HTML::Entities(); @@ -177,7 +178,7 @@ sub prep_menuitem { return '
  • $link
  • |; + . qq| href="$$menuitem[0]" target="_top">$link|; } # primary_menu() evaluates @primary_menu and returns XHTML for the menu @@ -216,33 +217,65 @@ sub primary_menu { 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); + $menu .= prep_menuitem($menuitem); } } + $menu =~ s/\[domain\]/$env{'user.domain'}/g; + $menu =~ s/\[user\]/$env{'user.name'}/g; 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; 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 $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( $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 @@ -253,13 +286,17 @@ sub secondary_menu { && $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 'cst' + && !$canmodifyuser; + 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 @@ -292,6 +329,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 ""; } @@ -356,6 +395,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 @@ -445,6 +489,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)) { @@ -455,18 +501,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'}) { @@ -478,6 +526,12 @@ sub innerregister { if ($nocrsedit) { $editbutton=&clear(6,1); } else { + 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='.$env{'request.role'}.'&symb='.$env{'request.symb'}.'&origurl='.$resurl; + } + } $editbutton=&switch ('','',6,1,'pcstr.png','edit[_1]','resource[_2]', "go('".$cfile."');","Edit this resource"); @@ -551,8 +605,14 @@ c&6&3 c&8&1 c&8&2 s&8&3&prt.png&prepare[_1]&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document -s&9&1&sbkm.png&set[_1]&bookmark[_2]&set_bookmark()&Set a bookmark for this resource&&1 ENDMENUITEMS + if (&Apache::lonnet::allowed('bre', $env{'request.course.id'}) eq 'F' && $env{'request.uri'} =~ /^\/res/) { + # wishlist is only available for users with access to resource-pool + # and links can only be set for resources within the resource-pool + $menuitems .= (< 1}); + my $start_page_wishlistlink = + &Apache::loncommon::start_page('Set link to wishlist',undef, + {'only_body' => 1, + 'js_ready' => 1, + 'bgcolor' => '#FFFFFF',}); + + my $warningLink = &mt('You must insert a title!'); + + # HTML-Markup for 'Set a link for this resource to wishlist' + # this is written via JavaScript document.write (function set_wishlistlink) + # it is split into 3 parts and the inputfields for title and path are left out + # these fields are inserted later to set the values for title and path + # automatically via JavaScript (document.title and location.pathname) + my $in_page_wishlistlink1 = '

    '.&mt('Set a link to wishlist').'

    '. + '
    '. + &Apache::lonhtmlcommon::start_pick_box(). + &Apache::lonhtmlcommon::row_title(&mt('Link Title')); + + my $in_page_wishlistlink2 = &Apache::lonhtmlcommon::row_closure(). + &Apache::lonhtmlcommon::row_title(&mt('Path')); + + my $in_page_wishlistlink3 = &Apache::lonhtmlcommon::row_closure(). + &Apache::lonhtmlcommon::row_title(&mt('Note')). + ''. + &Apache::lonhtmlcommon::row_closure(1). + &Apache::lonhtmlcommon::end_pick_box(). + '

    '. + ''. + ''. + ''. + '
    '; + + # remove all \n for inserting on javascript document.write + $in_page_wishlistlink1 =~ s/\n//g; + $in_page_wishlistlink2 =~ s/\n//g; + $in_page_wishlistlink3 =~ s/\n//g; + + my $end_page_wishlistlink = + &Apache::loncommon::end_page({'js_ready' => 1}); + return (<' + +'function newlinksubmit(){' + +'var title = document.getElementsByName("title")[0].value;' + +'if (!title) {' + +'alert("$warningLink");' + +'return false;}' + +'return true;}' + +'<\/scr'+'ipt>' + +'$in_page_wishlistlink1' + +'' + +'$in_page_wishlistlink2' + +'' + +'$in_page_wishlistlink3' + +'$end_page_wishlistlink' ); + wishlistlink.document.close(); +} + ENDUTILITY }