--- loncom/interface/lonmenu.pm 2017/02/18 23:39:16 1.467
+++ loncom/interface/lonmenu.pm 2017/10/07 22:20:19 1.482
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Routines to control the menu
#
-# $Id: lonmenu.pm,v 1.467 2017/02/18 23:39:16 raeburn Exp $
+# $Id: lonmenu.pm,v 1.482 2017/10/07 22:20:19 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -214,7 +214,7 @@ use HTML::Entities();
use Apache::lonwishlist();
use vars qw(@desklines %category_names %category_members %category_positions
- $readdesk @primary_menu %primary_submenu @secondary_menu);
+ $readdesk @primary_menu %primary_submenu @secondary_menu %secondary_submenu);
my @inlineremote;
@@ -401,10 +401,7 @@ sub secondary_menu {
if ($env{'request.course.id'}) {
$cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
$cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
- if ($canedit || $canvieweditor) {
- $showsyllabus = 1;
- $showfeeds = 1;
- } else {
+ 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'}) ||
@@ -471,9 +468,8 @@ sub secondary_menu {
&& !$canviewwnew;
next if $$menuitem[4] eq 'params'
&& (!$canmodpara && !$canviewpara);
- next if $$menuitem[4] =~ /showgroups$/
- && !$canviewgrps
- && !$grouptools;
+ next if $$menuitem[4] eq 'showgroups'
+ && ($canviewgrps || !$grouptools);
next if $$menuitem[4] eq 'showsyllabus'
&& !$showsyllabus;
next if $$menuitem[4] eq 'showfeeds'
@@ -483,7 +479,37 @@ sub secondary_menu {
next if $$menuitem[4] eq 'cca'
&& !$canmodifycoauthor;
- if ($$menuitem[3] eq 'Roles' && $env{'request.course.id'}) {
+ 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 'crsedit' && !$canedit && !$canvieweditor);
+ next if ($item->[2] eq 'params' && !$canmodpara && !$canviewpara);
+ 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'}) {
# special treatment for role selector
($roleswitcher_js,$roleswitcher_form,my $switcher) =
&roles_selector(
@@ -497,16 +523,23 @@ sub secondary_menu {
my $url = $$menuitem[0];
$url =~ s{\[cdom\]/\[cnum\]}{$cdom/$cnum};
if (&Apache::lonnet::is_on_map($url)) {
- unless ($$menuitem[0] =~ /\?register=1/) {
- $$menuitem[0] .= '?register=1';
+ unless ($$menuitem[0] =~ /(\?|\&)register=1/) {
+ $$menuitem[0] .= (($$menuitem[0]=~/\?/)? '&' : '?').'register=1';
}
} else {
- $$menuitem[0] =~ s{\?register=1}{};
+ $$menuitem[0] =~ s{\&?register=1}{};
}
- if (($ENV{'SERVER_PORT'} == 443) &&
- ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
- $$menuitem[0] .= ($$menuitem[0]=~/\?/) ? '&' : '?' . 'usehttp=1';
+ if ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://}) {
+ if (($ENV{'SERVER_PORT'} == 443) || ($env{'request.use_absolute'} =~ m{^https://})) {
+ unless ($$menuitem[0] =~ m{^https?://}) {
+ $$menuitem[0] = 'http://'.$ENV{'SERVER_NAME'}.$$menuitem[0];
+ }
+ unless ($$menuitem[0] =~ /(\&|\?)usehttp=1/) {
+ $$menuitem[0] .= (($$menuitem[0]=~/\?/) ? '&' : '?').'usehttp=1';
+ }
+ }
}
+ $$menuitem[0] = &HTML::Entities::encode($$menuitem[0],'&<>"');
}
$menu .= &prep_menuitem(\@$menuitem);
}
@@ -525,13 +558,13 @@ sub secondary_menu {
my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
($escurl = $env{'request.filename'}) =~ s{^\Q$londocroot\E}{};
$escurl = &escape($escurl);
- }
+ }
$menu =~ s/\[url\]/$escurl/g;
$menu =~ s/\[symb\]/$escsymb/g;
}
$menu =~ s/\[uname\]/$$author{user}/g;
$menu =~ s/\[udom\]/$$author{dom}/g;
- if ($showsyllabus || $showfeeds) {
+ if ($env{'request.course.id'}) {
$menu =~ s/\[cnum\]/$cnum/g;
$menu =~ s/\[cdom\]/$cdom/g;
}
@@ -629,7 +662,7 @@ sub build_submenu {
}
sub innerregister {
- my ($forcereg,$bread_crumbs,$group,$pagebuttonshide) = @_;
+ my ($forcereg,$bread_crumbs,$group,$pagebuttonshide,$hostname) = @_;
my $const_space = ($env{'request.state'} eq 'construct');
my $is_const_dir = 0;
@@ -639,7 +672,7 @@ sub innerregister {
undef(@inlineremote);
- my ($mapurl,$resurl,$crstype);
+ my ($mapurl,$resurl,$crstype,$navmap);
if ($env{'request.course.id'}) {
#
@@ -647,12 +680,24 @@ sub innerregister {
#
$crstype = &Apache::loncommon::course_type();
if ($env{'request.symb'}) {
- ($mapurl, my $rid, $resurl) = &Apache::lonnet::decode_symb(&Apache::lonnet::symbread());
+ my $ignorenull;
+ unless ($env{'request.noversionuri'} eq '/adm/navmaps') {
+ $ignorenull = 1;
+ }
+ my $symb = &Apache::lonnet::symbread('','',$ignorenull);
+ ($mapurl, my $rid, $resurl) = &Apache::lonnet::decode_symb($symb);
my $coursetitle = $env{'course.'.$env{'request.course.id'}.'.description'};
my $maptitle = &Apache::lonnet::gettitle($mapurl);
- my $restitle = &Apache::lonnet::gettitle(&Apache::lonnet::symbread());
- my @crumbs;
+ my $restitle = &Apache::lonnet::gettitle($symb);
+ my (@crumbs,@mapcrumbs);
+ if (($env{'request.noversionuri'} ne '/adm/navmaps') && ($mapurl ne '') &&
+ (!(($crstype eq 'Placement') && !$env{'request.role.adv'}))) {
+ $navmap = Apache::lonnavmaps::navmap->new();
+ if (ref($navmap)) {
+ @mapcrumbs = $navmap->recursed_crumbs($mapurl,$restitle);
+ }
+ }
unless (($forcereg) &&
($env{'request.noversionuri'} eq '/adm/navmaps') &&
($mapurl eq $env{'course.'.$env{'request.course.id'}.'.url'}) ||
@@ -661,17 +706,22 @@ sub innerregister {
href => "Javascript:gopost('/adm/navmaps','')"});
}
if ($mapurl ne $env{'course.'.$env{'request.course.id'}.'.url'}) {
- push(@crumbs, {text => '...',
- no_mt => 1});
+ if (@mapcrumbs) {
+ push(@crumbs,@mapcrumbs);
+ } elsif (!(($crstype eq 'Placement') && (!$env{'request.role.adv'}))) {
+ push(@crumbs, {text => '...',
+ no_mt => 1});
+ }
}
- unless (($crstype eq 'Placement') || (!$env{'request.role.adv'})) {
- push @crumbs, {text => $maptitle, no_mt => 1} if ($maptitle
- && $maptitle ne 'default.sequence'
- && $maptitle ne $coursetitle);
+ unless ((($crstype eq 'Placement') && (!$env{'request.role.adv'})) || (@mapcrumbs) ||
+ (!$maptitle) || ($maptitle eq 'default.sequence') ||
+ ($mapurl eq $env{'course.'.$env{'request.course.id'}.'.url'})) {
+ push @crumbs, {text => $maptitle, no_mt => 1, href => $mapurl};
+ }
+ if ($restitle && !@mapcrumbs) {
+ push(@crumbs,{text => $restitle, no_mt => 1});
}
-
- push @crumbs, {text => $restitle, no_mt => 1} if $restitle;
my @tools;
if ($env{'request.filename'} =~ /\.page$/) {
my %breadcrumb_tools = &Apache::lonhtmlcommon::current_breadcrumb_tools();
@@ -696,7 +746,7 @@ sub innerregister {
}
my $trail;
if ($env{'form.folderpath'}) {
- &prepare_functions($resurl,$forcereg,$group,undef,undef,1);
+ &prepare_functions($resurl,$forcereg,$group,undef,undef,1,$hostname);
($trail) =
&Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
} else {
@@ -711,10 +761,10 @@ sub innerregister {
} elsif ($resurl =~ m{^\Q/uploaded$courseurl/portfolio/syllabus/}) {
&Apache::lonhtmlcommon::clear_breadcrumbs();
&prepare_functions('/public'.$courseurl."/syllabus",
- $forcereg,$group,undef,undef,1);
+ $forcereg,$group,undef,undef,1,$hostname);
$title = &mt('Syllabus File');
my ($trail) =
- &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
+ &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1,$hostname);
return $trail;
}
unless ($env{'request.state'} eq 'construct') {
@@ -738,7 +788,7 @@ sub innerregister {
$forceview,$editbutton);
if (($resurl =~ m{^/?adm/($match_domain)/($match_username)/aboutme$}) ||
($env{'request.role'} !~/^(aa|ca|au)/)) {
- $editbutton = &prepare_functions($resurl,$forcereg,$group);
+ $editbutton = &prepare_functions($resurl,$forcereg,$group,'','','',$hostname);
}
if ($editbutton eq '') {
$editbutton = &clear(6,1);
@@ -912,7 +962,7 @@ if ($env{'browser.mobile'}) {
$is_mobile = 1;
}
- unless ($env{'request.noversionuri'}=~/\/(bulletinboard|smppg|navmaps|syllabus|aboutme|viewclasslist|portfolio|exttools?)(\?|$)/) {
+ unless ($env{'request.noversionuri'}=~/\/(bulletinboard|smppg|navmaps|syllabus|aboutme|viewclasslist|portfolio|ext\.tool)(\?|$)/) {
if ((!$env{'request.enc'}) && ($env{'request.noversionuri'} !~ m{^/adm/wrapper/ext/}) && ($env{'request.noversionuri'} !~ m{^/uploaded/$match_domain/$match_courseid/docs/})) {
$menuitems.=(<&"'));
+ my $link = '/adm/coursedocs?command=direct&forcesupplement=1&supppath='.
+ "$esc_path&anchor=$suppanchor";
+ if ($env{'request.use_absolute'} ne '') {
+ $link = $env{'request.use_absolute'}.$link;
+ }
&switch('','',7,4,'docs-22x22.png','Edit Folder','parms[_2]',
- "location.href='/adm/coursedocs?command=direct&forcesupplement=1&supppath=$esc_path&anchor=$suppanchor'",
- 'Folder/Page Content');
+ "location.href='$link'",'Folder/Page Content');
}
}
}
@@ -1234,7 +1326,7 @@ sub prepare_functions {
&advtools_crumbs(@inlineremote);
return $editbutton;
} elsif ($env{'request.registered'}) {
- return $editbutton;
+ return $editbutton || $viewsrcbutton;
} else {
if (ref($bread_crumbs) eq 'ARRAY') {
if (@inlineremote > 0) {
@@ -2041,6 +2133,12 @@ function open_StoredLinks_Import(rat) {
newWin.focus();
}
+function open_source() {
+ var url = escape(window.location.pathname);
+ sourcewin=window.open('/adm/source?inhibitmenu=yes&viewonly=1&filename='+url,'LONsource',
+ 'height=500,width=600,resizable=yes,location=no,menubar=no,toolbar=no,scrollbars=yes');
+}
+
(function (\$) {
\$(document).ready(function () {
\$.single=function(a){return function(b){a[0]=b;return a}}(\$([1]));
@@ -2114,11 +2212,11 @@ sub roles_selector {
}
my ($privref,$gotsymb,$destsymb);
my $destinationurl = $ENV{'REQUEST_URI'};
- if ($destinationurl =~ /\?symb=/) {
+ if ($destinationurl =~ /(\?|\&)symb=/) {
$gotsymb = 1;
} elsif ($destinationurl =~ m{^/enc/}) {
my $plainurl = &Apache::lonenc::unencrypted($destinationurl);
- if ($plainurl =~ /\?symb=/) {
+ if ($plainurl =~ /(\?|\&)symb=/) {
$gotsymb = 1;
}
}
@@ -2711,6 +2809,9 @@ BEGIN {
} elsif ($configline=~/^scnd\:/) {
my @entries = (split(/\:/, $configline))[1..5];
push(@secondary_menu,\@entries);
+ } elsif ($configline=~/^scndsub\:/) {
+ my ($parent,@entries) = (split(/\:/, $configline))[1..4];
+ push(@{$secondary_submenu{$parent}},\@entries);
} elsif ($configline) {
push(@desklines,$configline);
}