--- loncom/interface/lonmenu.pm 2020/07/19 00:24:36 1.369.2.79.2.2 +++ loncom/interface/lonmenu.pm 2022/05/29 21:49:06 1.369.2.83.2.2 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Routines to control the menu # -# $Id: lonmenu.pm,v 1.369.2.79.2.2 2020/07/19 00:24:36 raeburn Exp $ +# $Id: lonmenu.pm,v 1.369.2.83.2.2 2022/05/29 21:49:06 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -99,7 +99,7 @@ It gets filled in the BEGIN block of thi =over -=item prep_menuitems(\@menuitem) +=item prep_menuitems(\@menuitem,$target,$listclass,$linkattr) This routine wraps a menuitem in proper HTML. It is used by primary_menu() and secondary_menu(). @@ -240,9 +240,9 @@ use vars qw(@desklines %category_names % my @inlineremote; sub prep_menuitem { - my ($menuitem) = @_; + my ($menuitem,$target,$listclass,$linkattr) = @_; return '' unless(ref($menuitem) eq 'ARRAY'); - my $link; + my ($link,$targetattr); if ($$menuitem[1]) { # graphical Link $link = "':'
  • ').'$link
  • |; + . qq| href="$$menuitem[0]"$targetattr $linkattr>$link|; } # primary_menu() evaluates @primary_menu and returns a two item array, @@ -263,7 +266,8 @@ 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 ($crstype,$ltimenu,$menucoll,$menuref,$links_disabled,$links_target) = @_; + my (%menu,%menuopts); # each element of @primary contains following array: # (link url, icon path, alt text, link text, condition, position) my $public; @@ -271,6 +275,27 @@ sub primary_menu { || (($env{'user.name'} eq '') && ($env{'user.domain'} eq ''))) { $public = 1; } + my ($listclass,$linkattr,$target); + if ($links_disabled) { + $listclass = 'LCisDisabled'; + $linkattr = 'aria-disabled="true"'; + } + if ($links_target ne '') { + $target = $links_target; + } else { + my $deeplinktarget; + if ($env{'request.deeplink.login'}) { + $deeplinktarget = $env{'request.deeplink.target'}; + } + if ($deeplinktarget eq '_self') { + $target = '_self'; + } else { + $target = '_top'; + } + } + if (($menucoll) && (ref($menuref) eq 'HASH')) { + %menuopts = %{$menuref}; + } foreach my $menuitem (@primary_menu) { # evaluate conditions next if ref($menuitem) ne 'ARRAY'; # @@ -294,11 +319,27 @@ sub primary_menu { if ($position eq '') { $position = 'right'; } + if ($env{'request.course.id'} && $menucoll) { + if (($menuitem->[6]) && (!$menuopts{$menuitem->[6]})) { + if ($menuitem->[6] eq 'pers') { + if ($menuopts{'name'} && + $env{'user.name'} && $env{'user.domain'}) { + $menu{$position} .= '
  • '. + &Apache::loncommon::plainname($env{'user.name'}, + $env{'user.domain'}).'
  • '; + next; + } else { + next; + } + } else { + next; + } + } + } if (defined($primary_submenu{$title})) { - my ($link,$target); + my $link; if ($menuitem->[0] ne '') { $link = $menuitem->[0]; - $target = '_top'; } else { $link = '#'; } @@ -310,17 +351,30 @@ sub primary_menu { ($item->[2] eq 'blog')) && (!&Apache::lonnet::usertools_access('','',$item->[2], undef,'tools'))); + if ($env{'request.course.id'} && $menucoll) { + next if ($item->[3]) && (!$menuopts{$item->[3]}); + } 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 { + if ($title eq 'Personal') { + if ($env{'user.name'} && $env{'user.domain'}) { + unless (($env{'request.course.id'}) && ($menucoll) && (!$menuopts{'name'})) { + $title = &Apache::loncommon::plainname($env{'user.name'},$env{'user.domain'}); + } + } + next if (($env{'request.course.id'}) && ($menucoll) && ($title eq 'Personal') && + (!@primsub)); + if ($title eq 'Personal') { $title = &mt($title); } - $menu{$position} .= &create_submenu($link,$target,$title,\@primsub,1); + } else { + $title = &mt($title); + } + if (@primsub > 0) { + $menu{$position} .= &create_submenu($link,$target,$title,\@primsub,1,undef,$listclass,$linkattr); } elsif ($link) { - $menu{$position} .= '
  • '.&mt($title).'
  • '; + $menu{$position} .= ($listclass?'
  • ':'
  • '). + ''.$title.'
  • '; } } } elsif ($$menuitem[3] eq 'Help') { # special treatment for helplink @@ -331,13 +385,22 @@ sub primary_menu { 'helpdeskmail', $defdom,$origmail); if ($to ne '') { - $menu{$position} .= &prep_menuitem($menuitem); + $menu{$position} .= &prep_menuitem($menuitem,$target,$listclass,$linkattr); } } else { - $menu{$position} .= '
  • '.&Apache::loncommon::top_nav_help('Help').'
  • '; + $menu{$position} .= ($listclass?'
  • ':'
  • '). + &Apache::loncommon::top_nav_help('Help',$linkattr). + '
  • '; } + } elsif ($$menuitem[3] eq 'Log In') { + if ($public) { + if (&Apache::lonnet::get_saml_landing()) { + $$menuitem[0] = '/adm/login'; + } + } + $menu{$position} .= prep_menuitem($menuitem,$target,$listclass,$linkattr); } else { - $menu{$position} .= prep_menuitem($menuitem); + $menu{$position} .= prep_menuitem($menuitem,$target,$listclass,$linkattr); } } my @output = ('',''); @@ -376,7 +439,8 @@ sub getauthor{ } sub secondary_menu { - my ($httphost) = @_; + my ($httphost,$ltiscope,$ltimenu,$noprimary,$menucoll,$menuref, + $links_disabled,$links_target) = @_; my $menu; my $crstype = &Apache::loncommon::course_type(); @@ -397,9 +461,10 @@ sub secondary_menu { 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 ($cdom,$cnum,$showsyllabus,$showfeeds,$showresv,$grouptools); + my ($cdom,$cnum,$showsyllabus,$showfeeds,$showresv,$grouptools,%menuopts); $grouptools = 0; if ($env{'request.course.id'}) { $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; @@ -434,6 +499,15 @@ sub secondary_menu { } } } + if (($menucoll) && (ref($menuref) eq 'HASH')) { + %menuopts = %{$menuref}; + } + + my ($listclass,$linkattr,$target); + if ($links_disabled) { + $listclass = 'LCisDisabled'; + $linkattr = 'aria-disabled="true"'; + } my ($canmodifycoauthor); if ($env{'request.role'} eq "au./$env{'user.domain'}/") { @@ -445,6 +519,19 @@ sub secondary_menu { } my ($roleswitcher_js,$roleswitcher_form); + if ($links_target ne '') { + $target = $links_target; + } else { + my $deeplinktarget + if ($env{'request.deeplink.login'}) { + $deeplinktarget = $env{'request.deeplink.target'}; + } + if ($deeplinktarget eq '_self') { + $target = '_self'; + } else { + $target = '_top'; + } + } foreach my $menuitem (@secondary_menu) { # evaluate conditions @@ -480,17 +567,25 @@ sub secondary_menu { && !$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; my $title = $menuitem->[3]; + if ($env{'request.course.id'} && $menucoll) { + if ($$menuitem[5] eq 'main') { + next if ($menuopts{$$menuitem[5]} eq 'n'); + } elsif ($$menuitem[5] ne 'roles') { + next if (($$menuitem[5]) && (!$menuopts{$$menuitem[5]})); + } + } if (defined($secondary_submenu{$title})) { - my ($link,$target); + my $link; if ($menuitem->[0] ne '') { $link = $menuitem->[0]; - $target = '_top'; } else { $link = '#'; } @@ -512,19 +607,26 @@ sub secondary_menu { } } if (@scndsub > 0) { - $menu .= &create_submenu($link,$target,$title,\@scndsub,1); + $menu .= &create_submenu($link,$target,&mt($title),\@scndsub,1,undef, + $listclass,$linkattr); } elsif ($link ne '#') { - $menu .= '
  • '.&mt($title).'
  • '; + $menu .= ($listclass?'
  • ':'
  • '). + ''. + &mt($title).'
  • '; } } } elsif ($$menuitem[3] eq 'Roles' && $env{'request.course.id'}) { # special treatment for role selector - ($roleswitcher_js,$roleswitcher_form,my $switcher) = + my ($switcher,$has_opa_priv); + ($roleswitcher_js,$roleswitcher_form,$switcher,$has_opa_priv) = &roles_selector( $env{'course.' . $env{'request.course.id'} . '.domain'}, $env{'course.' . $env{'request.course.id'} . '.num'}, - $httphost + $httphost,$target,$menucoll,$menuref ); + if (($$menuitem[5]) && (!$menuopts{$$menuitem[5]})) { + next unless ($has_opa_priv); + } $menu .= $switcher; } else { if ($$menuitem[3] eq 'Syllabus' && $env{'request.course.id'}) { @@ -539,7 +641,7 @@ sub secondary_menu { } if ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://}) { if (($ENV{'SERVER_PORT'} == 443) || ($env{'request.use_absolute'} =~ m{^https://})) { - unless (&Apache::lonnet::uses_sts()) { + unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl())) { unless ($$menuitem[0] =~ m{^https?://}) { $$menuitem[0] = 'http://'.$ENV{'SERVER_NAME'}.$$menuitem[0]; } @@ -551,7 +653,7 @@ sub secondary_menu { } $$menuitem[0] = &HTML::Entities::encode($$menuitem[0],'&<>"'); } - $menu .= &prep_menuitem(\@$menuitem); + $menu .= &prep_menuitem(\@$menuitem,$target,$listclass,$linkattr); } } if ($menu =~ /\[url\].*\[symb\]/) { @@ -574,6 +676,7 @@ sub secondary_menu { } $menu =~ s/\[uname\]/$$author{user}/g; $menu =~ s/\[udom\]/$$author{dom}/g; + $menu =~ s/\[javascript\]/javascript:/g; if ($env{'request.course.id'}) { $menu =~ s/\[cnum\]/$cnum/g; $menu =~ s/\[cdom\]/$cdom/g; @@ -588,14 +691,14 @@ sub secondary_menu { } sub create_submenu { - my ($link,$target,$title,$submenu,$translate,$addclass) = @_; + my ($link,$target,$title,$submenu,$translate,$addclass,$listclass,$linkattr) = @_; return unless (ref($submenu) eq 'ARRAY'); - my $disptarget; - if ($target ne '') { - $disptarget = ' target="'.$target.'"'; + my $targetattr; + if (($target ne '') && ($link ne '#')) { + $targetattr = ' target="'.$target.'"'; } my $menu = '
  • '. - ''. + ''. ''.$title. ''. ' ▼'. @@ -603,7 +706,7 @@ sub create_submenu { # $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 .= &build_submenu($target, $submenu, $translate, '1', $listclass, $linkattr); $menu .= '
  • '; return $menu; @@ -613,7 +716,7 @@ sub 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) = @_; + my ($target, $submenu, $translate, $first_level, $listclass, $linkattr) = @_; unless (@{$submenu}) { return ''; } @@ -672,12 +775,16 @@ sub build_submenu { } $href =~ s/\[returnurl\]/$returnurl/; } + my $targetattr; unless (($href eq '') || ($href =~ /^\#/)) { - $target = ' target="_top"'; + if ($target ne '') { + $targetattr = ' target="'.$target.'"'; } - $menu .= '
  • '; - $menu .= '' . $title . ''; + $menu .= '
  • '; + $menu .= '' . $title . ''; $menu .= '
  • '; } } @@ -1018,15 +1125,17 @@ if ($env{'browser.mobile'}) { $is_mobile = 1; } - unless ($env{'request.noversionuri'}=~/\/(bulletinboard|smppg|navmaps|syllabus|aboutme|viewclasslist|portfolio|ext\.tool)(\?|$)/) { + unless ($env{'request.noversionuri'}=~/\/(bulletinboard|smppg|navmaps|syllabus|aboutme|viewclasslist|portfolio)(\?|$)/) { if ((!$env{'request.enc'}) && ($env{'request.noversionuri'} !~ m{^/adm/wrapper/ext/}) && - ($env{'request.noversionuri'} !~ m{^/uploaded/$match_domain/$match_courseid/(docs/|default_\d+\.page$)})) { + ($env{'request.noversionuri'} !~ m{^/uploaded/$match_domain/$match_courseid/(docs/|default_\d+\.page$)}) && + ($env{'request.noversionuri'} !~ m{^/adm/.+/ext\.tool$})) { $menuitems.=(< 'Key:', nokey => 'A proctor key is required', ); + my $shownsymb = &HTML::Entities::encode(&Apache::lonenc::check_encrypt($env{'request.symb'})); my $navmap = Apache::lonnavmaps::navmap->new(); my ($missing,$tried) = (0,0); if (ref($navmap)) { @@ -2282,6 +2397,7 @@ sub done_button_js {
    +
    @@ -2363,6 +2479,7 @@ END
    +
    @@ -2445,6 +2562,11 @@ sub utilityfunctions { my $countdown = &countdown_toggle_js(); + my $deeplinktarget; + if ($env{'request.deeplink.login'}) { + $deeplinktarget = $env{'request.deeplink.target'}; + } + my $annotateurl = '/adm/annotation'; if ($httphost) { $annotateurl = '/adm/annotations'; @@ -2545,17 +2667,22 @@ function golist(url) { currentURL = null; currentSymb= null; var lcHostname = setLCHost(); - top.location.href=lcHostname+url; + var deeplinktarget = '$deeplinktarget'; + if (deeplinktarget == '_self') { + document.location.href=lcHostname+url; + } else { + top.location.href=lcHostname+url; + } } } -function catalog_info(isMobile) { +function catalog_info(url,isMobile) { if (isMobile == 1) { - openMyModal(window.location.pathname+'.meta?modal=1',500,400,'yes'); + openMyModal(url+'.meta?modal=1',500,400,'yes'); } else { - loncatinfo=window.open(window.location.pathname+'.meta',"LONcatInfo",'height=500,width=400,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no'); + loncatinfo=window.open(url+'.meta',"LONcatInfo",'height=500,width=400,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no'); } } @@ -2623,8 +2750,14 @@ ENDUTILITY } sub serverform { + my $target; + if (($env{'request.deeplink.login'}) && ($env{'request.deeplink.target'} eq '_self')) { + $target = ' target="_self"'; + } else { + $target = ' target="_top"'; + } return(< +
    @@ -2634,15 +2767,26 @@ ENDSERVERFORM } sub constspaceform { + my ($frameset) = @_; + my ($target,$printtarget); + if ($frameset) { + $target = ' target="_parent"'; + $printtarget = ' target="_parent"'; + } else { + unless (($env{'request.deeplink.login'}) && ($env{'request.deeplink.target'} eq '_self')) { + $target = ' target="_top"'; + $printtarget = ' target="_top"'; + } + } return(< + -
    +
    -
    + @@ -2672,12 +2816,12 @@ sub hidden_button_check { } sub roles_selector { - my ($cdom,$cnum,$httphost) = @_; + my ($cdom,$cnum,$httphost,$target,$menucoll,$menuref) = @_; my $crstype = &Apache::loncommon::course_type(); my $now = time; my (%courseroles,%seccount,%courseprivs,%roledesc); my $is_cc; - my ($js,$form,$switcher); + my ($js,$form,$switcher,$has_opa_priv); my $ccrole; if ($crstype eq 'Community') { $ccrole = 'co'; @@ -2778,10 +2922,15 @@ sub roles_selector { } } if ((keys(%seccount) > 1) || ($numdiffsec > 1)) { + my $targetattr; + if ($target ne '') { + $targetattr = ' target="'.$target.'"'; + } my @submenu; - $js = &jump_to_role($cdom,$cnum,\%seccount,\%courseroles,\%courseprivs,\%roledesc,$privref); + $js = &jump_to_role($cdom,$cnum,\%seccount,\%courseroles,\%courseprivs, + \%roledesc,$privref,$menucoll,$menuref); $form = - ''."\n". + ''."\n". ' '."\n". ' '."\n". @@ -2798,12 +2947,19 @@ sub roles_selector { if ($env{'request.role'} =~ m{^\Q$role\E}) { if ($seccount{$role} > 1) { $include = 1; + } else { + if ($env{'user.priv.'.$env{'request.role'}."./$cdom/$cnum"} =~/opa\&([^\:]*)/) { + $has_opa_priv = 1; + } } } else { $include = 1; } } if ($include) { + if ($env{"user.priv.$role./$cdom/$cnum./$cdom/$cnum"} =~/opa\&([^\:]*)/) { + $has_opa_priv = 1; + } push(@submenu,['javascript:adhocRole('."'$role'".')', &Apache::lonnet::plaintext($role,$crstype)]); } @@ -2828,16 +2984,19 @@ sub roles_selector { } else { $rolename = &Apache::lonnet::plaintext($role); } + if ($env{"user.priv.$role./$cdom/$cnum./$cdom/$cnum"} =~/opa\&([^\:]*)/) { + $has_opa_priv = 1; + } push(@submenu,['javascript:adhocRole('."'$role'".')', $rolename]); } } } if (@submenu > 0) { - $switcher = &create_submenu('','',&mt('Switch role'),\@submenu); + $switcher = &create_submenu('#',$target,&mt('Switch role'),\@submenu); } } - return ($js,$form,$switcher); + return ($js,$form,$switcher,$has_opa_priv); } sub get_all_courseroles { @@ -3004,7 +3163,8 @@ sub get_customadhoc_roles { } sub jump_to_role { - my ($cdom,$cnum,$seccount,$courseroles,$courseprivs,$roledesc,$privref) = @_; + my ($cdom,$cnum,$seccount,$courseroles,$courseprivs,$roledesc,$privref, + $menucoll,$menuref) = @_; my %lt = &Apache::lonlocal::texthash( this => 'This role has section(s) associated with it.', ente => 'Enter a specific section.', @@ -3015,6 +3175,7 @@ sub jump_to_role { role => 'The role you selected is not permitted to view the current page.', swit => 'Switch role, but display Main Menu page instead?', ); + &js_escape(\%lt); my $js; if (ref($courseroles) eq 'HASH') { $js = ' var secpick = new Array("'.$lt{'ente'}.'","'.$lt{'orlb'}.'");'."\n". @@ -3037,6 +3198,8 @@ sub jump_to_role { } } my $checkroles = 0; + my $fallback = '/adm/menu'; + my $displaymsg = $lt{'swit'}; if ((ref($privref) eq 'ARRAY') && (@{$privref} > 0) && (ref($courseprivs) eq 'HASH')) { my %disallowed; foreach my $role (sort(keys(%{$courseprivs}))) { @@ -3058,8 +3221,22 @@ sub jump_to_role { $checkroles = 1; $js .= " var disallow = new Array('".join("','",keys(%disallowed))."');\n". " var rolecheck = 1;\n"; + if ($menucoll) { + if (ref($menuref) eq 'HASH') { + if ($menuref->{'main'} eq 'n') { + $fallback = '/adm/navmaps'; + if (&Apache::loncommon::course_type() eq 'Community') { + $displaymsg = &mt('Switch role, but display Community Contents page instead?'); + } else { + $displaymsg = &mt('Switch role, but display Course Contents page instead?'); + } + &js_escape(\$displaymsg); + } + } + } } } + &js_escape(\$fallback); if (!$checkroles) { $js .= " var disallow = new Array();\n". " rolecheck = 0;\n"; @@ -3082,8 +3259,8 @@ function adhocRole(newrole) { if (rolecheck > 0) { for (var i=0; i