--- loncom/interface/lonmenu.pm 2013/05/05 00:15:02 1.412 +++ loncom/interface/lonmenu.pm 2013/06/26 04:25:41 1.416 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Routines to control the menu # -# $Id: lonmenu.pm,v 1.412 2013/05/05 00:15:02 raeburn Exp $ +# $Id: lonmenu.pm,v 1.416 2013/06/26 04:25:41 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -106,10 +106,11 @@ secondary_menu(). =item primary_menu() -This routine evaluates @primary_menu and returns XHTML for the menu -that contains following links: About, Message, Roles, Help, Logout +This routine evaluates @primary_menu and returns a two item array, +with the array elements containing XHTML for the left and right sides of +the menu that contains the following links: About, Message, Roles, Help, Logout @primary_menu is filled within the BEGIN block of this module with -entries from mydesk.tab +entries from mydesk.tab =item secondary_menu() @@ -203,15 +204,16 @@ sub prep_menuitem { . qq| href="$$menuitem[0]" target="_top">$link|; } -# primary_menu() evaluates @primary_menu and returns XHTML for the menu -# that contains following links: -# About, Message, Personal, Roles, Help, Logout +# primary_menu() evaluates @primary_menu and returns a two item array, +# with the array elements containing XHTML for the left and right sides of +# the menu that contains the following links: +# Personal, 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; + my (%menu); # each element of @primary contains following array: - # (link url, icon path, alt text, link text, condition) + # (link url, icon path, alt text, link text, condition, position) my $public; if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')) || (($env{'user.name'} eq '') && ($env{'user.domain'} eq ''))) { @@ -236,6 +238,10 @@ sub primary_menu { && !&Apache::loncommon::show_course(); ## my $title = $menuitem->[3]; + my $position = $menuitem->[5]; + if ($position eq '') { + $position = 'right'; + } if (defined($primary_submenu{$title})) { my ($link,$target); if ($menuitem->[0] ne '') { @@ -255,9 +261,9 @@ sub primary_menu { push(@primsub,$item); } if (@primsub > 0) { - $menu .= &create_submenu($link,$target,$title,\@primsub); + $menu{$position} .= &create_submenu($link,$target,$title,\@primsub); } elsif ($link) { - $menu .= '
  • '.&mt($title).'
  • '; + $menu{$position} .= '
  • '.&mt($title).'
  • '; } } } elsif ($$menuitem[3] eq 'Help') { # special treatment for helplink @@ -268,19 +274,17 @@ sub primary_menu { 'helpdeskmail', $defdom,$origmail); if ($to ne '') { - $menu .= &prep_menuitem($menuitem); + $menu{$position} .= &prep_menuitem($menuitem); } } else { - $menu .= '
  • '.&Apache::loncommon::top_nav_help('Help').'
  • '; + $menu{$position} .= '
  • '.&Apache::loncommon::top_nav_help('Help').'
  • '; } } else { - $menu .= prep_menuitem($menuitem); + $menu{$position} .= prep_menuitem($menuitem); } } - $menu =~ s/\[domain\]/$env{'user.domain'}/g; - $menu =~ s/\[user\]/$env{'user.name'}/g; - - return "
      $menu
    "; + return ("
      $menu{'left'}
    ", + "
      $menu{'right'}
    "); } #returns hashref {user=>'',dom=>''} containing: @@ -325,6 +329,28 @@ sub secondary_menu { my $canmgr = &Apache::lonnet::allowed('mgr', $crs_sec); my $author = &getauthor(); + my ($cdom,$cnum,$showsyllabus,$showfeeds); + if ($env{'request.course.id'}) { + $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; + $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; + if ($canedit) { + $showsyllabus = 1; + $showfeeds = 1; + } else { + unless (&Apache::lonnet::is_on_map("public/$cdom/$cnum/syllabus")) { + if (($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'}) || + ($env{'course.'.$env{'request.course.id'}.'.uploadedsyllabus'}) || + ($env{'course.'.$env{'request.course.id'}.'.updatedsyllabus'}) || + ($env{'request.course.syllabustime'})) { + $showsyllabus = 1; + } + } + if ($env{'request.course.feeds'}) { + $showfeeds = 1; + } + } + } + my ($canmodifycoauthor); if ($env{'request.role'} eq "au./$env{'user.domain'}/") { my $extent = "$env{'user.domain'}/$env{'user.name'}"; @@ -368,6 +394,10 @@ sub secondary_menu { next if $$menuitem[4] =~ /showgroups$/ && !$canviewgrps && !%groups; + next if $$menuitem[4] eq 'showsyllabus' + && !$showsyllabus; + next if $$menuitem[4] eq 'showfeeds' + && !$showfeeds; next if $$menuitem[4] eq 'author' && !$author; next if $$menuitem[4] eq 'cca' @@ -382,6 +412,17 @@ sub secondary_menu { ); $menu .= $switcher; } else { + if ($$menuitem[3] eq 'Syllabus' && $env{'request.course.id'}) { + my $url = $$menuitem[0]; + $url =~ s{\[cdom\]/\[cnum\]}{$cdom/$cnum}; + if (&Apache::lonnet::is_on_map($url)) { + unless ($$menuitem[0] =~ /\?register=1/) { + $$menuitem[0] .= '?register=1'; + } + } else { + $$menuitem[0] =~ s{\?register=1}{}; + } + } $menu .= &prep_menuitem(\@$menuitem); } } @@ -405,6 +446,10 @@ sub secondary_menu { } $menu =~ s/\[uname\]/$$author{user}/g; $menu =~ s/\[udom\]/$$author{dom}/g; + if ($showsyllabus || $showfeeds) { + $menu =~ s/\[cnum\]/$cnum/g; + $menu =~ s/\[cdom\]/$cdom/g; + } if ($menu) { $menu = ""; } @@ -421,9 +466,19 @@ sub create_submenu { if ($target ne '') { $disptarget = ' target="'.$target.'"'; } + my $name; + if ($title eq 'Personal') { + if ($env{'user.name'} && $env{'user.domain'}) { + $name = &Apache::loncommon::plainname($env{'user.name'},$env{'user.domain'}); + } else { + $name = &mt($title); + } + } else { + $name = &mt($title); + } my $menu = '
  • '. ''. - ''.&mt($title). + ''.$name. ''. ' ▼'. '