--- loncom/interface/lonmenu.pm 2010/01/18 21:35:55 1.244.2.12
+++ loncom/interface/lonmenu.pm 2018/12/30 19:47:02 1.495
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Routines to control the menu
#
-# $Id: lonmenu.pm,v 1.244.2.12 2010/01/18 21:35:55 raeburn Exp $
+# $Id: lonmenu.pm,v 1.495 2018/12/30 19:47:02 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -26,15 +26,6 @@
# http://www.lon-capa.org/
#
#
-# There are two parameters controlling the action of this module:
-#
-# browser.interface - if this is 'textual', it overrides the second parameter
-# and goes to screen reader PDA mode
-#
-# environment.remote - if this is 'on', the routines controll the remote
-# control, otherwise they render the main window controls; ignored it
-# browser.interface is 'textual'
-#
=head1 NAME
@@ -42,55 +33,135 @@ Apache::lonmenu
=head1 SYNOPSIS
-Coordinates the response to clicking an image.
+Loads contents of /home/httpd/lonTabs/mydesk.tab,
+used to generate inline menu, and Main Menu page.
This is part of the LearningOnline Network with CAPA project
described at http://www.lon-capa.org.
-=head1 SUBROUTINES
+=head1 GLOBAL VARIABLES
=over
-=item show_course()
+=item @desklines
-Little texts
+Each element of this array contains a line of mydesk.tab that doesn't start with
+cat, prim or scnd.
+It gets filled in the BEGIN block of this module.
-=item initlittle()
+=item %category_names
-=item menubuttons()
+The keys of this hash are the abbreviations used in mydesk.tab in those lines that
+start with cat, the values are strings representing titles.
+It gets filled in the BEGIN block of this module.
-This gets called at the top of the body section
+=item %category_members
-=item show_return_link()
+TODO
-=item registerurl()
+=item %category_positions
-This gets called in the header section
+The keys of this hash are the abbreviations used in mydesk.tab in those lines that
+start with cat, its values are position vectors (column, row).
+It gets filled in the BEGIN block of this module.
-=item innerregister()
+=item $readdesk
+
+Indicates that mydesk.tab has been read.
+It is set to 'done' in the BEGIN block of this module.
+
+=item @primary_menu
+
+The elements of this array reference arrays that are made up of the components
+of those lines of mydesk.tab that start with prim:.
+It is used by primary_menu() to generate the corresponding menu.
+It gets filled in the BEGIN block of this module.
+
+=item %primary_sub_menu
-This gets called in order to register a URL, both with the Remote
-and in the body of the document
+The keys of this hash reference are the names of items in the primary_menu array
+which have sub-menus. For each key, the corresponding value is a reference to
+an array containing components extracted from lines in mydesk.tab which begin
+with primsub:.
+This hash, which is used by primary_menu to generate sub-menus, is populated in
+the BEGIN block.
-=item loadevents()
+=item @secondary_menu
-=item unloadevents()
+The elements of this array reference arrays that are made up of the components
+of those lines of mydesk.tab that start with scnd.
+It is used by secondary_menu() to generate the corresponding menu.
+It gets filled in the BEGIN block of this module.
-=item startupremote()
+=back
-=item setflags()
+=head1 SUBROUTINES
-=item maincall()
+=over
-=item load_remote_msg()
+=item prep_menuitems(\@menuitem,$ltitarget)
-=item get_menu_name()
+This routine wraps a menuitem in proper HTML. It is used by primary_menu() and
+secondary_menu().
-=item reopenmenu()
+=item primary_menu()
-=item open()
+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
+
+=item secondary_menu()
+
+Same as primary_menu() but operates on @secondary_menu.
+
+=item create_submenu()
+
+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
+(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,
+ (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.
+
+ 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
+]
+
+=item innerregister()
-Open the menu
+This gets called in order to register a URL in the body of the document
=item clear()
@@ -108,12 +179,11 @@ The javascript is usually similar to "go
=item rawconfig()
-=item close()
-
-=item footer()
-
=item utilityfunctions()
+Output from this routine is a number of javascript functions called by
+items in the inline menu, and in some cases items in the Main Menu page.
+
=item serverform()
=item constspaceform()
@@ -138,291 +208,554 @@ use Apache::lonhtmlcommon();
use Apache::loncommon();
use Apache::lonenc();
use Apache::lonlocal;
+use Apache::lonmsg();
use LONCAPA qw(:DEFAULT :match);
+use LONCAPA::ltiutils;
use HTML::Entities();
+use Apache::lonwishlist();
-use vars qw(@desklines %category_names %category_members %category_positions $readdesk);
-
+use vars qw(@desklines %category_names %category_members %category_positions
+ $readdesk @primary_menu %primary_submenu @secondary_menu %secondary_submenu);
my @inlineremote;
+sub prep_menuitem {
+ my ($menuitem,$ltitarget) = @_;
+ return '' unless(ref($menuitem) eq 'ARRAY');
+ my $link;
+ if ($$menuitem[1]) { # graphical Link
+ $link = "";
+ } else { # textual Link
+ $link = &mt($$menuitem[3]);
+ }
+ my $target = ' target="_top"';
+ if ($ltitarget eq 'iframe') {
+ $target ='';
+ }
+ return '
';
+ }
+ }
+ } 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();
+ my $to = &Apache::loncommon::build_recipient_list(undef,
+ 'helpdeskmail',
+ $defdom,$origmail);
+ if ($to ne '') {
+ $menu{$position} .= &prep_menuitem($menuitem,$ltitarget);
+ }
+ } else {
+ $menu{$position} .= '
'.&Apache::loncommon::top_nav_help('Help').'
';
+ }
+ } else {
+ $menu{$position} .= prep_menuitem($menuitem,$ltitarget);
+ }
+ }
+ my @output = ('','');
+ if ($menu{'left'} ne '') {
+ $output[0] = "$menu{'left'}";
+ }
+ if ($menu{'right'} ne '') {
+ $output[1] = "$menu{'right'}";
+ }
+ return @output;
+}
-
-sub show_course {
- my $course = !$env{'user.adv'};
- if (!$env{'user.adv'}) {
- foreach my $env (keys(%env)) {
- next if ($env !~ m/^user\.priv\./);
- if ($env !~ m/^user\.priv\.(?:st|cm)/) {
- $course = 0;
- last;
- }
- }
+#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;
}
- return $course;
+
+ # if wrong server
+ return;
}
-sub initlittle {
- return &Apache::lonlocal::texthash('ret' => 'Return to Last Location',
- 'nav' => 'Navigate Contents',
- 'main' => 'Main Menu',
- 'roles' => (&Apache::loncommon::show_course()?
- 'Courses':'Roles'),
- 'other' => 'Other Roles',
- 'docs' => 'Edit Course',
- 'exit' => 'Logout',
- 'login' => 'Log In',
- 'launch' => 'Launch Remote Control',
- 'groups' => 'Groups',
- 'gdoc' => 'Community Documents',
- );
-}
-
-sub menubuttons {
- my $forcereg=shift;
- my $registration=shift;
- my $titletable=shift;
- &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
- ['inhibitmenu']);
- if (($env{'form.inhibitmenu'} eq 'yes') ||
- ($ENV{'REQUEST_URI'} eq '/adm/logout')) { return ''; }
+sub secondary_menu {
+ my ($httphost,$ltiscope,$ltimenu,$noprimary) = @_;
+ my $menu;
- if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
+ my $crstype = &Apache::loncommon::course_type();
+ 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 $canvieweditor = &Apache::lonnet::allowed('cev', $env{'request.course.id'});
+ my $canviewroster = $env{'course.'.$env{'request.course.id'}.'.student_classlist_view'};
+ 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 $canmodpara = &Apache::lonnet::allowed('opa', $crs_sec);
+ my $canvgr = &Apache::lonnet::allowed('vgr', $crs_sec);
+ my $canmgr = &Apache::lonnet::allowed('mgr', $crs_sec);
+ my $canplc = &Apache::lonnet::allowed('plc', $crs_sec);
+ my $author = &getauthor();
- my %lt=&initlittle();
- my $navmaps='';
- my $reloadlink='';
- my $docs='';
- my $groups='';
- my $roles=''.$lt{'roles'}.'';
- my $role_selector;
- my $showgroups=0;
- my ($cnum,$cdom);
- my $escurl=&escape(&Apache::lonenc::check_encrypt($env{'request.noversionuri'}));
- my $escsymb=&escape(&Apache::lonenc::check_encrypt($env{'request.symb'}));
-
- my $logo=&Apache::loncommon::lonhttpdurl("/adm/lonIcons/minilogo.gif");
- $logo = '
';
-
- if ($env{'request.state'} eq 'construct') {
- if (($env{'request.noversionuri'} eq '') || (!defined($env{'request.noversionuri'}))) {
- my $returnurl = $env{'request.filename'};
- $returnurl =~ s:^/home/([^/]+)/public_html/(.*)$:/priv/$1/$2:;
- $escurl = &escape($returnurl);
- }
- }
+ my ($cdom,$cnum,$showsyllabus,$showfeeds,$showresv,$grouptools,$lti,$ltimapres,%ltiexc);
+ $grouptools = 0;
if ($env{'request.course.id'}) {
- $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
$cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
- my %coursegroups;
- my $viewgrps_permission =
- &Apache::lonnet::allowed('vcg',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''));
- if (!$viewgrps_permission) {
- %coursegroups = &Apache::lonnet::get_active_groups($env{'user.domain'},$env{'user.name'},$cdom,$cnum);
- }
- if ((keys(%coursegroups) > 0) || ($viewgrps_permission)) {
- $showgroups = 1;
+ $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
+ unless ($canedit || $canvieweditor) {
+ 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;
+ }
+ }
+ unless ($canmgr || $canvgr) {
+ my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
+ if (keys(%slots) > 0) {
+ $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 ++;
+ }
+ }
}
- $role_selector = &roles_selector($cdom,$cnum);
- if ($role_selector) {
- $roles = ''.$role_selector.' '.$lt{'other'}.'';
+ if ($env{'request.lti.login'}) {
+ $lti = 1;
+ if (ref($ltimenu) eq 'HASH') {
+ foreach my $item ('fullname','coursetitle','role','logout','grades') {
+ unless ($ltimenu->{$item}) {
+ $ltiexc{$item} = 1;
+ }
+ }
+ }
+ if (($ltiscope eq 'map') || ($ltiscope eq 'resource')) {
+ $ltimapres = 1;
+ }
}
}
- if ($env{'browser.interface'} eq 'textual') {
-# Textual display only
- if ($env{'request.course.id'}) {
- $navmaps=(<$lt{'nav'}
-ENDNAV
- if (&show_return_link()) {
- my $escreload=&escape('return:');
- $reloadlink=(<$lt{'ret'}
-ENDRELOAD
- }
- my $is_community =
- (&Apache::loncommon::course_type() eq 'Community');
- if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
- my $text = ($is_community) ? $lt{'gdoc'} : $lt{'docs'};
- $docs=(<$text
-ENDDOCS
- }
- if ($showgroups) {
- $groups =(<$lt{'groups'}
-ENDGROUPS
+ 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)) ||
+ (&Apache::lonnet::allowed('caa',$extent))) {
+ $canmodifycoauthor = 1;
+ }
+ }
+
+ my ($roleswitcher_js,$roleswitcher_form,$ltitarget);
+ if ($env{'request.lti.login'}) {
+ $ltitarget = $env{'request.lti.target'};
+ }
+
+ 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'};
+ next if $$menuitem[4] =~ /^crsedit/
+ && (!$canedit && !$canvieweditor);
+ next if $$menuitem[4] eq 'nvgr'
+ && ($canvgr || $ltiexc{'grades'});
+ 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 '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 'showgroups'
+ && ($canviewgrps || !$grouptools);
+ next if $$menuitem[4] eq 'showsyllabus'
+ && !$showsyllabus;
+ next if $$menuitem[4] eq 'showfeeds'
+ && !$showfeeds;
+ next if $$menuitem[4] eq 'plc'
+ && !$canplc;
+ next if $$menuitem[4] eq 'author'
+ && !$author;
+ next if $$menuitem[4] eq 'cca'
+ && !$canmodifycoauthor;
+ next if $$menuitem[4] eq 'notltimapres'
+ && $ltimapres;
+ next if $$menuitem[4] eq 'notlti'
+ && $lti;
+ next if $$menuitem[4] eq 'lti'
+ && (!$lti || !$noprimary);
+ next if $$menuitem[3] eq 'Logout'
+ && $ltiexc{'logout'};
+
+ my $title = $menuitem->[3];
+ if (defined($secondary_submenu{$title})) {
+ my ($link,$target);
+ if ($menuitem->[0] ne '') {
+ $link = $menuitem->[0];
+ unless ($ltitarget eq 'iframe') {
+ $target = '_top';
+ }
+ } else {
+ $link = '#';
}
- }
- my $form=&serverform();
- my $utility=&utilityfunctions();
- my $output=(<
-// BEGIN LON-CAPA Internal
-$utility
-
-
';
+
+ # $link and $title are only used in the initial string written in $menu
+ # as seen above, not needed for nested submenus
+ $menu .= &build_submenu($target, $submenu, $translate, '1');
+ $menu .= '
';
+
+ return $menu;
+}
+
+# helper routine for create_submenu
+# build the dropdown (and nested submenus) recursively
+# see perldoc create_submenu documentation for further information
+sub build_submenu {
+ my ($target, $submenu, $translate, $first_level) = @_;
+ unless (@{$submenu}) {
+ return '';
+ }
+
+ my $menu = '';
+ my $count = 0;
+ my $numsub = scalar(@{$submenu});
+ foreach my $item (@{$submenu}) {
+ $count ++;
+ if (ref($item) eq 'ARRAY') {
+ my $href = $item->[0];
+ my $bordertop;
+ my $borderbot;
+ my $title;
-sub show_return_link {
- return (($env{'request.noversionuri'}=~m{^/(res|public)/} &&
- $env{'request.symb'} eq '')
- ||
- ($env{'request.noversionuri'}=~ m{^/cgi-bin/printout.pl})
- ||
- (($env{'request.noversionuri'}=~/^\/adm\//) &&
- ($env{'request.noversionuri'}!~/^\/adm\/wrapper\//) &&
- ($env{'request.noversionuri'}!~
- m[^/adm/.*/(smppg|bulletinboard|aboutme)($|\?)])
- ));
-}
+ if ($translate) {
+ $title = &mt($item->[1]);
+ } else {
+ $title = $item->[1];
+ }
+ if ($count == 1 && !$first_level) {
+ $bordertop = 'border-top: 1px solid black;';
+ }
+ if ($count == $numsub) {
+ $borderbot = 'border-bottom: 1px solid black;';
+ }
-sub registerurl {
- my ($forcereg) = @_;
- my $result = '';
- if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
- my $force_title='';
- if ($env{'request.state'} eq 'construct') {
- $force_title=&Apache::lonxml::display_title();
- }
- if (($env{'browser.interface'} eq 'textual') ||
- ($env{'environment.remote'} eq 'off') ||
- ((($env{'request.publicaccess'}) ||
- (!&Apache::lonnet::is_on_map(
- &unescape($env{'request.noversionuri'})))) &&
- (!$forcereg))) {
- return $result.
- ''.$force_title;
- }
-# Graphical display after login only
- if ($env{'request.registered'} && !$forcereg) { return ''; }
- $result.=&innerregister($forcereg);
- return $result.$force_title;
+ # href is a reference to another submenu
+ if (ref($href) eq 'ARRAY') {
+ $menu .= '