--- loncom/interface/lonmenu.pm 2019/08/06 14:44:36 1.497
+++ loncom/interface/lonmenu.pm 2022/05/28 15:55:34 1.519
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Routines to control the menu
#
-# $Id: lonmenu.pm,v 1.497 2019/08/06 14:44:36 raeburn Exp $
+# $Id: lonmenu.pm,v 1.519 2022/05/28 15:55:34 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,$ltitarget)
+=item prep_menuitems(\@menuitem,$ltitarget,$deeplinktarget,$listclass,$linkattr)
This routine wraps a menuitem in proper HTML. It is used by primary_menu() and
secondary_menu().
@@ -220,7 +220,7 @@ use vars qw(@desklines %category_names %
my @inlineremote;
sub prep_menuitem {
- my ($menuitem,$ltitarget) = @_;
+ my ($menuitem,$ltitarget,$deeplinktarget,$listclass,$linkattr) = @_;
return '' unless(ref($menuitem) eq 'ARRAY');
my $link;
if ($$menuitem[1]) { # graphical Link
@@ -233,11 +233,13 @@ sub prep_menuitem {
my $target = ' target="_top"';
if ($ltitarget eq 'iframe') {
$target ='';
+ } elsif ($deeplinktarget eq '_self') {
+ $target = ' target="'.$deeplinktarget.'"';
}
- return '
':'').'$link |;
+ . qq| href="$$menuitem[0]"$target $linkattr>$link |;
}
# primary_menu() evaluates @primary_menu and returns a two item array,
@@ -247,8 +249,8 @@ sub prep_menuitem {
# @primary_menu is filled within the BEGIN block of this module with
# entries from mydesk.tab
sub primary_menu {
- my ($crstype,$ltimenu) = @_;
- my (%menu,%ltiexc);
+ my ($crstype,$ltimenu,$menucoll,$menuref,$links_disabled) = @_;
+ my (%menu,%ltiexc,%menuopts);
# each element of @primary contains following array:
# (link url, icon path, alt text, link text, condition, position)
my $public;
@@ -265,7 +267,7 @@ sub primary_menu {
my %roles_in_env;
$rolecount = &Apache::lonroles::roles_from_env(\%roles_in_env,$update);
}
- my ($lti,$ltitarget);
+ my ($lti,$ltitarget,$deeplinktarget);
if ($env{'request.lti.login'}) {
$lti = 1;
$ltitarget = $env{'request.lti.target'};
@@ -277,6 +279,12 @@ sub primary_menu {
}
}
}
+ if ($env{'request.deeplink.login'}) {
+ $deeplinktarget = $env{'request.deeplink.target'};
+ }
+ if (($menucoll) && (ref($menuref) eq 'HASH')) {
+ %menuopts = %{$menuref};
+ }
foreach my $menuitem (@primary_menu) {
# evaluate conditions
next if ref($menuitem) ne 'ARRAY'; #
@@ -292,10 +300,10 @@ sub primary_menu {
# users
next if $$menuitem[4] eq 'roles' ##show links depending on
&& (&Apache::loncommon::show_course() ##term 'Courses' or
- || $env{'request.lti.login'}); ##'Roles' wanted
+ || $lti); ##'Roles' wanted
next if $$menuitem[4] eq 'courses' ##and not LTI access
&& (!&Apache::loncommon::show_course()
- || !$env{'request.lti.login'});
+ || $lti);
next if $$menuitem[4] eq 'notlti'
&& $lti;
next if $$menuitem[4] eq 'ltiexc'
@@ -312,11 +320,33 @@ 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'} && !$ltiexc{'fullname'} &&
+ $env{'user.name'} && $env{'user.domain'}) {
+ $menu{$position} .= ''.
+ &Apache::loncommon::plainname($env{'user.name'},
+ $env{'user.domain'}).' ';
+ next;
+ } else {
+ next;
+ }
+ } else {
+ next;
+ }
+ }
+ }
+ my ($listclass,$linkattr);
+ if ($links_disabled) {
+ $listclass = 'LCisDisabled';
+ $linkattr = 'aria-disabled="true"';
+ }
if (defined($primary_submenu{$title})) {
my ($link,$target);
if ($menuitem->[0] ne '') {
$link = $menuitem->[0];
- unless ($ltitarget eq 'iframe') {
+ unless (($ltitarget eq 'iframe') || ($deeplinktarget eq '_self')) {
$target = '_top';
}
} else {
@@ -331,19 +361,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 ($title eq 'Personal' && $env{'user.name'} && $env{'user.domain'} ) {
- unless ($ltiexc{'fullname'}) {
- $title = &Apache::loncommon::plainname($env{'user.name'},$env{'user.domain'});
+ if ($title eq 'Personal') {
+ if ($env{'user.name'} && $env{'user.domain'} && !$ltiexc{'fullname'}) {
+ 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);
}
} else {
$title = &mt($title);
}
if (@primsub > 0) {
- $menu{$position} .= &create_submenu($link,$target,$title,\@primsub,1);
+ $menu{$position} .= &create_submenu($link,$target,$title,\@primsub,1,undef,$listclass,$linkattr);
} elsif ($link) {
- $menu{$position} .= ''.$title.' ';
+ $menu{$position} .= ($listclass?'':' ').
+ ''.$title.' ';
}
}
} elsif ($$menuitem[3] eq 'Help') { # special treatment for helplink
@@ -355,13 +396,22 @@ sub primary_menu {
'helpdeskmail',
$defdom,$origmail);
if ($to ne '') {
- $menu{$position} .= &prep_menuitem($menuitem,$ltitarget);
+ $menu{$position} .= &prep_menuitem($menuitem,$ltitarget,$deeplinktarget,$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,$ltitarget,$deeplinktarget,$listclass,$linkattr);
} else {
- $menu{$position} .= prep_menuitem($menuitem,$ltitarget);
+ $menu{$position} .= prep_menuitem($menuitem,$ltitarget,$deeplinktarget,$listclass,$linkattr);
}
}
my @output = ('','');
@@ -400,7 +450,7 @@ sub getauthor{
}
sub secondary_menu {
- my ($httphost,$ltiscope,$ltimenu,$noprimary) = @_;
+ my ($httphost,$ltiscope,$ltimenu,$noprimary,$menucoll,$menuref,$links_disabled) = @_;
my $menu;
my $crstype = &Apache::loncommon::course_type();
@@ -424,7 +474,8 @@ sub secondary_menu {
my $canplc = &Apache::lonnet::allowed('plc', $crs_sec);
my $author = &getauthor();
- my ($cdom,$cnum,$showsyllabus,$showfeeds,$showresv,$grouptools,$lti,$ltimapres,%ltiexc);
+ my ($cdom,$cnum,$showsyllabus,$showfeeds,$showresv,$grouptools,
+ $lti,$ltimapres,%ltiexc,%menuopts);
$grouptools = 0;
if ($env{'request.course.id'}) {
$cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
@@ -449,7 +500,8 @@ sub secondary_menu {
}
}
if ($env{'request.course.groups'} ne '') {
- foreach my $group (split(/:/,$env{'request.course.groups'}) {
+ foreach my $group (split(/:/,$env{'request.course.groups'})) {
+ next unless ($group =~ /^\w+$/);
my @privs = split(/:/,$env{"user.priv.$env{'request.role'}./$cdom/$cnum/$group"});
shift(@privs);
if (@privs) {
@@ -471,6 +523,15 @@ sub secondary_menu {
}
}
}
+ if (($menucoll) && (ref($menuref) eq 'HASH')) {
+ %menuopts = %{$menuref};
+ }
+
+ my ($listclass,$linkattr);
+ if ($links_disabled) {
+ $listclass = 'LCisDisabled';
+ $linkattr = 'aria-disabled="true"';
+ }
my ($canmodifycoauthor);
if ($env{'request.role'} eq "au./$env{'user.domain'}/") {
@@ -481,10 +542,13 @@ sub secondary_menu {
}
}
- my ($roleswitcher_js,$roleswitcher_form,$ltitarget);
+ my ($roleswitcher_js,$roleswitcher_form,$ltitarget,$deeplinktarget);
if ($env{'request.lti.login'}) {
$ltitarget = $env{'request.lti.target'};
}
+ if ($env{'request.deeplink.login'}) {
+ $deeplinktarget = $env{'request.deeplink.target'};
+ }
foreach my $menuitem (@secondary_menu) {
# evaluate conditions
@@ -533,11 +597,16 @@ sub secondary_menu {
&& $ltiexc{'logout'};
my $title = $menuitem->[3];
+ if ($env{'request.course.id'} && $menucoll) {
+ unless ($$menuitem[5] eq 'roles') {
+ next if (($$menuitem[5]) && (!$menuopts{$$menuitem[5]}));
+ }
+ }
if (defined($secondary_submenu{$title})) {
my ($link,$target);
if ($menuitem->[0] ne '') {
$link = $menuitem->[0];
- unless ($ltitarget eq 'iframe') {
+ unless (($ltitarget eq 'iframe') || ($deeplinktarget eq '_self')) {
$target = '_top';
}
} else {
@@ -567,25 +636,32 @@ sub secondary_menu {
push(@scndsub,$item);
}
}
- if ($title eq 'Personal' && $env{'user.name'} && $env{'user.domain'} ) {
+ if ($title eq 'Personal' && $env{'user.name'} && $env{'user.domain'}) {
unless ($ltiexc{'fullname'}) {
$title = &Apache::loncommon::plainname($env{'user.name'},$env{'user.domain'});
}
}
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,$ltitarget
+ $httphost,$menucoll,$menuref
);
+ if (($$menuitem[5]) && (!$menuopts{$$menuitem[5]})) {
+ next unless ($has_opa_priv);
+ }
$menu .= $switcher;
} elsif ($$menuitem[3] eq 'Help') { # special treatment for helplink
next if ($crstype eq 'Placement');
@@ -603,7 +679,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];
}
@@ -615,7 +691,7 @@ sub secondary_menu {
}
$$menuitem[0] = &HTML::Entities::encode($$menuitem[0],'&<>"');
}
- $menu .= &prep_menuitem(\@$menuitem,$ltitarget);
+ $menu .= &prep_menuitem(\@$menuitem,$ltitarget,$deeplinktarget,$listclass,$linkattr);
}
}
if ($menu =~ /\[url\].*\[symb\]/) {
@@ -653,7 +729,7 @@ 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 '') {
@@ -668,7 +744,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;
@@ -678,7 +754,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 '';
}
@@ -743,8 +819,10 @@ sub build_submenu {
}
}
- $menu .= '';
- $menu .= '' . $title . ' ';
+ $menu .= ' ';
+ $menu .= '' . $title . ' ';
$menu .= ' ';
}
}
@@ -986,6 +1064,13 @@ sub innerregister {
$currdir =~ s|[^/]+$||;
my $cleandisfn = &Apache::loncommon::escape_single($thisdisfn);
my $esc_currdir = &Apache::loncommon::escape_single($currdir);
+ my $pubfile = "/res/$udom/$uname/$thisdisfn";
+ my $candelete = 1;
+ if (-e $londocroot.$pubfile) {
+ unless (&Apache::lonnet::metadata($pubfile,'obsolete')) {
+ undef($candelete);
+ }
+ }
#
# Probably should be in mydesk.tab
#
@@ -993,7 +1078,18 @@ sub innerregister {
s&6&1&list.png&Directory&dir[_1]&golist('$esc_currdir')&List current directory
s&6&2&rtrv.png&Retrieve&version[_1]&gocstr('/adm/retrieve','/priv/$udom/$uname/$cleandisfn')&Retrieve old version
s&6&3&pub.png&Publish&resource[_3]&gocstr('/adm/publish','/priv/$udom/$uname/$cleandisfn')&Publish this resource
+s&7&3©.png&Copy&resource[_4]&gocstr('/adm/cfile?action=copy','/priv/$udom/$uname/$cleandisfn')&Copy this resource
+ENDMENUITEMS
+#
+# Rename and Delete only available if obsolete or unpublished
+#
+ if ($candelete) {
+ $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)) {
my @resources=();
if ($type eq 'map') {
my ($mapurl,$rid,$resurl)=&Apache::lonnet::decode_symb($env{'request.symb'});
- @resources=$navmap->retrieveResources($mapurl,sub { $_[0]->is_problem() });
+ if ($env{'request.symb'} =~ /\.page$/) {
+ @resources=$navmap->retrieveResources($resurl,sub { $_[0]->is_problem() });
+ } else {
+ @resources=$navmap->retrieveResources($mapurl,sub { $_[0]->is_problem() });
+ }
} else {
my $res = $navmap->getBySymb($env{'request.symb'});
if (ref($res)) {
@@ -1961,6 +2077,7 @@ sub done_button_js {
@@ -2042,6 +2159,7 @@ END
@@ -2121,13 +2239,17 @@ sub utilityfunctions {
my $esc_url=&escape($currenturl);
my $esc_symb=&escape($currentsymb);
+ my $newname = &mt('New Name');
my $countdown = &countdown_toggle_js();
- my $ltitarget;
+ my ($ltitarget,$deeplinktarget);
if ($env{'request.lti.login'}) {
$ltitarget = $env{'request.lti.target'};
}
+ if ($env{'request.deeplink.login'}) {
+ $deeplinktarget = $env{'request.deeplink.target'};
+ }
my $annotateurl = '/adm/annotation';
if ($httphost) {
@@ -2191,6 +2313,22 @@ function gocstr(url,filename) {
this.document.cstrdelete.submit();
return;
}
+ if ((url == '/adm/cfile?action=copy') || (url == '/adm/cfile?action=rename')) {
+ this.document.cstrcopy.filename.value = filename;
+ var oldname = filename.substring(filename.lastIndexOf("/") + 1);
+ var newname=prompt('$newname',oldname);
+ if (newname == "" || !newname || newname == oldname) {
+ return;
+ }
+ if (url == '/adm/cfile?action=rename') {
+ this.document.cstrcopy.action.value = 'rename';
+ } else {
+ this.document.cstrcopy.action.value = 'copy';
+ }
+ this.document.cstrcopy.newfilename.value = newname;
+ this.document.cstrcopy.submit();
+ return;
+ }
if (url == '/adm/printout') {
this.document.cstrprint.postdata.value = filename
this.document.cstrprint.curseed.value = 0;
@@ -2230,7 +2368,8 @@ function golist(url) {
currentSymb= null;
var lcHostname = setLCHost();
var ltitarget = '$ltitarget';
- if (ltitarget == 'iframe') {
+ var deeplinktarget = '$deeplinktarget';
+ if ((ltitarget == 'iframe') || (deeplinktarget == '_self')) {
document.location.href=lcHostname+url;
} else {
top.location.href=lcHostname+url;
@@ -2328,6 +2467,9 @@ sub serverform {
unless (($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) {
$target = ' target="_top"';
}
+ if (($env{'request.deeplink.login'}) && ($env{'request.deeplink.target'} eq '_self')) {
+ $target = ' target="_self"';
+ }
return(<
@@ -2339,10 +2481,17 @@ ENDSERVERFORM
}
sub constspaceform {
+ my ($frameset) = @_;
my ($target,$printtarget);
- unless (($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) {
- $target = ' target="_top"';
+ if ($frameset) {
+ $target = ' target="_parent"';
$printtarget = ' target="_parent"';
+ } else {
+ unless ((($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) ||
+ (($env{'request.deeplink.login'}) && ($env{'request.deeplink.target'} eq '_self'))) {
+ $target = ' target="_top"';
+ $printtarget = ' target="_parent"';
+ }
}
return(<
@@ -2357,6 +2506,11 @@ sub constspaceform {
+
ENDCONSTSPACEFORM
}
@@ -2372,12 +2526,12 @@ sub hidden_button_check {
}
sub roles_selector {
- my ($cdom,$cnum,$httphost,$ltitarget) = @_;
+ my ($cdom,$cnum,$httphost,$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';
@@ -2479,7 +2633,8 @@ sub roles_selector {
}
if ((keys(%seccount) > 1) || ($numdiffsec > 1)) {
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 =
'