--- loncom/interface/lonmenu.pm 2016/11/09 23:21:08 1.369.2.65 +++ loncom/interface/lonmenu.pm 2015/01/19 15:36:01 1.431 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Routines to control the menu # -# $Id: lonmenu.pm,v 1.369.2.65 2016/11/09 23:21:08 raeburn Exp $ +# $Id: lonmenu.pm,v 1.431 2015/01/19 15:36:01 goltermann Exp $ # # Copyright Michigan State University Board of Trustees # @@ -118,72 +118,47 @@ Same as primary_menu() but operates on @ =item create_submenu() -Creates XHTML for unordered list of sub-menu items which belong to a +Creates XHTML for unordered list of sub-menu items which belong to a particular top-level menu item. Uses hover pseudo class in css to display -dropdown list when mouse hovers over top-level item. Support for IE6 +dropdown list when mouse hovers over top-level item. Support for IE6 (no hover psuedo class) via LC_hoverable class for
  • tag for top- level item, which employs jQuery to handle behavior on mouseover. -Inputs: 6 - (a) link and (b) target for anchor href in top level item, +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. - (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 -the menu (e.g. [["link", "title", "condition"]] for a single-item menu). -create_submenu() supports also the creation of XHTML for nested dropdown -menus represented by unordered lists. This is done by replacing the -scalar used for the link with an arrayreference containing the menuitems -for the nested menu. This can be done recursively so that the next menu -may also contain nested submenus. + + 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 + the menu (e.g. [["link", "title", "condition"]] for a single-item menu). + create_submenu() supports also the creation of XHTML for nested dropdown + menus represented by unordered lists. This is done by replacing the + scalar used for the link with an arrayreference containing the menuitems + for the nested menu. This can be done recursively so that the next menu + may also contain nested submenus. Example: - [ # begin of datastructure - ["/home/", "Home", "condition1"], # 1st item of the 1st layer menu - [ # 2nd item of the 1st layer menu - [ # anon. array for nested menu - ["/path1", "Path1", undef], # 1st item of the 2nd layer menu - ["/path2", "Path2", undef], # 2nd item of the 2nd layer menu - [ # 3rd item of the 2nd layer menu - [[...], [...], ..., [...]], # containing another menu layer - "Sub-Sub-Menu", # title for this container - undef - ] - ], # end of array/nested menu - "Sub-Menu", # title for the container item - undef - ] # end of 2nd item of the 1st layer menu + [ # begin of datastructure + ["/home/", "Home", "condition1"], # 1st item of the 1st layer menu + [ # 2nd item of the 1st layer menu + [ # anon. array for nested menu + ["/path1", "Path1", undef], # 1st item of the 2nd layer menu + ["/path2", "Path2", undef], # 2nd item of the 2nd layer menu + [ # 3rd item of the 2nd layer menu + [[...], [...], ..., [...]], # containing another menu layer + "Sub-Sub-Menu", # title for this container + undef + ] + ], # end of array/nested menu + "Sub-Menu", # title for the container item + undef + ] # end of 2nd item of the 1st layer menu ] - =item innerregister() This gets called in order to register a URL in the body of the document -=item loadevents() - -=item unloadevents() - -=item startupremote() - -=item setflags() - -=item maincall() - -=item load_remote_msg() - -=item get_menu_name() - -=item reopenmenu() - -=item open() - -Open the menu - =item clear() =item switch() @@ -235,7 +210,7 @@ use HTML::Entities(); use Apache::lonwishlist(); use vars qw(@desklines %category_names %category_members %category_positions - $readdesk @primary_menu %primary_submenu @secondary_menu %secondary_submenu); + $readdesk @primary_menu %primary_submenu @secondary_menu); my @inlineremote; @@ -263,7 +238,7 @@ sub prep_menuitem { # @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, position) my $public; @@ -305,19 +280,14 @@ sub primary_menu { my @primsub; if (ref($primary_submenu{$title}) eq 'ARRAY') { foreach my $item (@{$primary_submenu{$title}}) { - next if (($item->[2] eq 'wishlist') && (!$env{'user.adv'})); - next if ((($item->[2] eq 'portfolio') || - ($item->[2] eq 'blog')) && + next if (($item->[2] eq 'wishlist') && (!$env{'user.adv'})); + next if ((($item->[2] eq 'portfolio') || + ($item->[2] eq 'blog')) && (!&Apache::lonnet::usertools_access('','',$item->[2], undef,'tools'))); push(@primsub,$item); } if (@primsub > 0) { - if ($title eq 'Personal' && $env{'user.name'} && $env{'user.domain'} ) { - $title = &Apache::loncommon::plainname($env{'user.name'},$env{'user.domain'}); - } else { - $title = &mt($title); - } $menu{$position} .= &create_submenu($link,$target,$title,\@primsub,1); } elsif ($link) { $menu{$position} .= '
  • '.&mt($title).'
  • '; @@ -388,21 +358,22 @@ sub secondary_menu { if ($canviewroster eq 'disabled') { undef($canviewroster); } - my $canviewgrps = &Apache::lonnet::allowed('vcg', $crs_sec); - my $canmodifyuser = &Apache::lonnet::allowed('cst', $crs_sec); - my $canviewusers = &Apache::lonnet::allowed('vcl', $crs_sec); - my $canviewwnew = &Apache::lonnet::allowed('whn', $crs_sec); - my $canviewpara = &Apache::lonnet::allowed('vpa', $crs_sec); + 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 $canvgr = &Apache::lonnet::allowed('vgr', $crs_sec); - my $canmgr = &Apache::lonnet::allowed('mgr', $crs_sec); + my $canmgr = &Apache::lonnet::allowed('mgr', $crs_sec); my $author = &getauthor(); my ($cdom,$cnum,$showsyllabus,$showfeeds,$showresv); if ($env{'request.course.id'}) { $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; - unless ($canedit) { + 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'}) || @@ -415,7 +386,7 @@ sub secondary_menu { $showfeeds = 1; } } - unless (($canmgr) || ($canvgr)) { + unless ($canmgr) { my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom); if (keys(%slots) > 0) { $showresv = 1; @@ -423,7 +394,7 @@ sub secondary_menu { } } - my ($canmodifycoauthor); + my ($canmodifycoauthor); if ($env{'request.role'} eq "au./$env{'user.domain'}/") { my $extent = "$env{'user.domain'}/$env{'user.name'}"; if ((&Apache::lonnet::allowed('cca',$extent)) || @@ -443,32 +414,29 @@ sub secondary_menu { # evaluate conditions next if ref($menuitem) ne 'ARRAY'; next if $$menuitem[4] ne 'always' - && ($$menuitem[4] ne 'author' && $$menuitem[4] ne 'cca') + && ($$menuitem[4] ne 'author' && $$menuitem[4] ne 'cca') && !$env{'request.course.id'}; next if $$menuitem[4] =~ /^mdc/ && !$canedit; - next if $$menuitem[4] eq 'mdcCourse' - && ($crstype eq 'Community'); - next if $$menuitem[4] eq 'mdcCommunity' - && ($crstype eq 'Course'); next if $$menuitem[4] eq 'nvgr' && $canvgr; next if $$menuitem[4] eq 'vgr' && !$canvgr; - next if $$menuitem[4] eq 'viewusers' - && !$canmodifyuser && !$canviewusers; - next if $$menuitem[4] eq 'noviewusers' - && ($canmodifyuser || $canviewusers || !$canviewroster); + next if $$menuitem[4] eq 'cst' + && !$canmodifyuser; + next if $$menuitem[4] eq 'ncst' + && ($canmodifyuser || !$canviewroster); next if $$menuitem[4] eq 'mgr' && !$canmgr; next if $$menuitem[4] eq 'showresv' && !$showresv; next if $$menuitem[4] eq 'whn' && !$canviewwnew; - next if $$menuitem[4] eq 'params' - && (!$canmodpara && !$canviewpara); - next if $$menuitem[4] eq 'nvcg' - && ($canviewgrps || !%groups); + next if $$menuitem[4] eq 'opa' + && !$canmodpara; + next if $$menuitem[4] =~ /showgroups$/ + && !$canviewgrps + && !%groups; next if $$menuitem[4] eq 'showsyllabus' && !$showsyllabus; next if $$menuitem[4] eq 'showfeeds' @@ -478,36 +446,7 @@ sub secondary_menu { next if $$menuitem[4] eq 'cca' && !$canmodifycoauthor; - my $title = $menuitem->[3]; - if (defined($secondary_submenu{$title})) { - my ($link,$target); - if ($menuitem->[0] ne '') { - $link = $menuitem->[0]; - $target = '_top'; - } else { - $link = '#'; - } - my @scndsub; - if (ref($secondary_submenu{$title}) eq 'ARRAY') { - foreach my $item (@{$secondary_submenu{$title}}) { - if (ref($item) eq 'ARRAY') { - next if ($item->[2] eq 'vgr' && !$canvgr); - next if ($item->[2] eq 'opa' && !$canmodpara); - next if ($item->[2] eq 'vpa' && !$canviewpara); - next if ($item->[2] eq 'viewusers' && !($canmodifyuser || $canviewusers)); - next if ($item->[2] eq 'mgr' && !$canmgr); - next if ($item->[2] eq 'vcg' && !$canviewgrps); - next if ($item->[2] eq 'mdc' && !$canedit); - push(@scndsub,$item); - } - } - if (@scndsub > 0) { - $menu .= &create_submenu($link,$target,$title,\@scndsub,1); - } elsif ($link ne '#') { - $menu .= '
  • '.&mt($title).'
  • '; - } - } - } elsif ($$menuitem[3] eq 'Roles' && $env{'request.course.id'}) { + if ($$menuitem[3] eq 'Roles' && $env{'request.course.id'}) { # special treatment for role selector ($roleswitcher_js,$roleswitcher_form,my $switcher) = &roles_selector( @@ -551,7 +490,7 @@ sub secondary_menu { } $menu =~ s/\[uname\]/$$author{user}/g; $menu =~ s/\[udom\]/$$author{dom}/g; - if ($env{'request.course.id'}) { + if ($showsyllabus || $showfeeds) { $menu =~ s/\[cnum\]/$cnum/g; $menu =~ s/\[cdom\]/$cdom/g; } @@ -565,15 +504,25 @@ sub secondary_menu { } sub create_submenu { - my ($link,$target,$title,$submenu,$translate,$addclass) = @_; + my ($link,$target,$title,$submenu,$translate) = @_; return unless (ref($submenu) eq 'ARRAY'); my $disptarget; if ($target ne '') { $disptarget = ' target="'.$target.'"'; } - my $menu = '
  • '. + 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 = '
  • '. ''. - ''.$title. + ''.$name. ''. ' ▼'. '