--- loncom/interface/lonmenu.pm 2015/03/03 16:53:59 1.431.2.1 +++ loncom/interface/lonmenu.pm 2016/06/02 01:43:46 1.450 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Routines to control the menu # -# $Id: lonmenu.pm,v 1.431.2.1 2015/03/03 16:53:59 musolffc Exp $ +# $Id: lonmenu.pm,v 1.450 2016/06/02 01:43:46 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -124,9 +124,13 @@ dropdown list when mouse hovers over top (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. +Inputs: 6 - (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, + (e) boolean to indicate whether to call &mt() to translate + name of menu item, + (f) optional class for
  • element in primary menu, for which + sub menu is being generated. The underlying datastructure used in (d) contains data from mydesk.tab. It consists of an array which has an array for each item appearing in @@ -238,6 +242,7 @@ sub prep_menuitem { # @primary_menu is filled within the BEGIN block of this module with # entries from mydesk.tab sub primary_menu { + my ($crstype) = @_; my (%menu); # each element of @primary contains following array: # (link url, icon path, alt text, link text, condition, position) @@ -246,6 +251,15 @@ sub primary_menu { || (($env{'user.name'} eq '') && ($env{'user.domain'} eq ''))) { $public = 1; } + my $rolecount; + if (($crstype eq 'Placement') && (!$env{'request.role.adv'})) { + my $update=$env{'user.update.time'}; + if (!$update) { + $update = $env{'user.login.time'}; + } + my %roles_in_env; + $rolecount = &Apache::lonroles::roles_from_env(\%roles_in_env,$update); + } foreach my $menuitem (@primary_menu) { # evaluate conditions next if ref($menuitem) ne 'ARRAY'; # @@ -263,8 +277,14 @@ sub primary_menu { && &Apache::loncommon::show_course(); ##term 'Courses' or next if $$menuitem[4] eq 'courses' ##'Roles' wanted && !&Apache::loncommon::show_course(); ## - my $title = $menuitem->[3]; + if (($crstype eq 'Placement') && (!$env{'request.role.adv'})) { + if ($menuitem->[4] eq 'courses') { + next unless ($rolecount>1); + } else { + next unless (($title eq 'Personal') || ($title eq 'Logout')); + } + } my $position = $menuitem->[5]; if ($position eq '') { $position = 'right'; @@ -280,6 +300,7 @@ sub primary_menu { my @primsub; if (ref($primary_submenu{$title}) eq 'ARRAY') { foreach my $item (@{$primary_submenu{$title}}) { + next if (($crstype eq 'Placement') && (!$env{'request.role.adv'})); next if (($item->[2] eq 'wishlist') && (!$env{'user.adv'})); next if ((($item->[2] eq 'portfolio') || ($item->[2] eq 'blog')) && @@ -287,13 +308,19 @@ sub primary_menu { undef,'tools'))); push(@primsub,$item); } + if ($title eq 'Personal' && $env{'user.name'} && $env{'user.domain'} ) { + $title = &Apache::loncommon::plainname($env{'user.name'},$env{'user.domain'}); + } else { + $title = &mt($title); + } if (@primsub > 0) { $menu{$position} .= &create_submenu($link,$target,$title,\@primsub,1); } elsif ($link) { - $menu{$position} .= '
  • '.&mt($title).'
  • '; + $menu{$position} .= '
  • '.$title.'
  • '; } } } elsif ($$menuitem[3] eq 'Help') { # special treatment for helplink + next if ($crstype eq 'Placement'); if ($public) { my $origmail = $Apache::lonnet::perlvar{'lonSupportEMail'}; my $defdom = &Apache::lonnet::default_login_domain(); @@ -366,7 +393,8 @@ sub secondary_menu { my $canmgr = &Apache::lonnet::allowed('mgr', $crs_sec); my $author = &getauthor(); - my ($cdom,$cnum,$showsyllabus,$showfeeds,$showresv); + my ($cdom,$cnum,$showsyllabus,$showfeeds,$showresv,$grouptools); + $grouptools = 0; if ($env{'request.course.id'}) { $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; @@ -392,6 +420,17 @@ sub secondary_menu { $showresv = 1; } } + my %groups = &Apache::lonnet::get_active_groups( + $env{'user.domain'}, $env{'user.name'},$cdom,$cnum); + if (%groups) { + foreach my $group (keys(%groups)) { + my @privs = split(/:/,$env{"user.priv.$env{'request.role'}./$cdom/$cnum/$group"}); + shift(@privs); + if (@privs) { + $grouptools ++; + } + } + } } my ($canmodifycoauthor); @@ -402,17 +441,12 @@ sub secondary_menu { $canmodifycoauthor = 1; } } - - 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'}); - my ($roleswitcher_js,$roleswitcher_form); foreach my $menuitem (@secondary_menu) { # evaluate conditions next if ref($menuitem) ne 'ARRAY'; + next if (($crstype eq 'Placement') && ($$menuitem[3] ne 'Roles') && (!$env{'request.role.adv'})); next if $$menuitem[4] ne 'always' && ($$menuitem[4] ne 'author' && $$menuitem[4] ne 'cca') && !$env{'request.course.id'}; @@ -436,7 +470,7 @@ sub secondary_menu { && !$canmodpara; next if $$menuitem[4] =~ /showgroups$/ && !$canviewgrps - && !%groups; + && !$grouptools; next if $$menuitem[4] eq 'showsyllabus' && !$showsyllabus; next if $$menuitem[4] eq 'showfeeds' @@ -504,25 +538,15 @@ sub secondary_menu { } sub create_submenu { - my ($link,$target,$title,$submenu,$translate) = @_; + my ($link,$target,$title,$submenu,$translate,$addclass) = @_; return unless (ref($submenu) eq 'ARRAY'); my $disptarget; 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 = '
  • '. + my $menu = '
  • '. ''. - ''.$name. + ''.$title. ''. ' ▼'. '