[LON-CAPA-cvs] cvs: loncom /interface loncommon.pm londocs.pm lonextresedit.pm lonmenu.pm
raeburn
raeburn at source.lon-capa.org
Mon Nov 28 22:01:05 EST 2016
raeburn Tue Nov 29 03:01:05 2016 EDT
Modified files:
/loncom/interface loncommon.pm lonextresedit.pm lonmenu.pm
londocs.pm
Log:
Support case where custom role can access Course Editor, but adv priv
not set at system level for current role.
- Display of hidden status for folder takes into account parameters set at
Enclosing map/folder level for resource, and factors in whether resources
within sub-folders made visible by "no" for hiddenresource parameter make
higher-level folder(s) unhidden.
- Parameters: contents hidden and Parameters: URLs hidden shown between
DOCS breadcrumbs and DOCS inline menu influenced by both <param> tags in
a map, and hiddenresource or encrypturl parameter in resourcedata.db
-------------- next part --------------
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.1266 loncom/interface/loncommon.pm:1.1267
--- loncom/interface/loncommon.pm:1.1266 Sat Nov 26 19:40:44 2016
+++ loncom/interface/loncommon.pm Tue Nov 29 03:01:04 2016
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# a pile of common routines
#
-# $Id: loncommon.pm,v 1.1266 2016/11/26 19:40:44 raeburn Exp $
+# $Id: loncommon.pm,v 1.1267 2016/11/29 03:01:04 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -16960,8 +16960,8 @@
}
sub symb_to_docspath {
- my ($symb) = @_;
- return unless ($symb);
+ my ($symb,$navmapref) = @_;
+ return unless ($symb && ref($navmapref));
my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
if ($resurl=~/\.(sequence|page)$/) {
$mapurl=$resurl;
@@ -16969,9 +16969,11 @@
$mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
}
my $mapresobj;
- my $navmap = Apache::lonnavmaps::navmap->new();
- if (ref($navmap)) {
- $mapresobj = $navmap->getResourceByUrl($mapurl);
+ unless (ref($$navmapref)) {
+ $$navmapref = Apache::lonnavmaps::navmap->new();
+ }
+ if (ref($$navmapref)) {
+ $mapresobj = $$navmapref->getResourceByUrl($mapurl);
}
$mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
my $type=$2;
@@ -16981,7 +16983,7 @@
if ($pcslist ne '') {
foreach my $pc (split(/,/,$pcslist)) {
next if ($pc <= 1);
- my $res = $navmap->getByMapPc($pc);
+ my $res = $$navmapref->getByMapPc($pc);
if (ref($res)) {
my $thisurl = $res->src();
$thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
Index: loncom/interface/lonextresedit.pm
diff -u loncom/interface/lonextresedit.pm:1.11 loncom/interface/lonextresedit.pm:1.12
--- loncom/interface/lonextresedit.pm:1.11 Tue Nov 22 00:43:12 2016
+++ loncom/interface/lonextresedit.pm Tue Nov 29 03:01:04 2016
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Documents
#
-# $Id: lonextresedit.pm,v 1.11 2016/11/22 00:43:12 raeburn Exp $
+# $Id: lonextresedit.pm,v 1.12 2016/11/29 03:01:04 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -543,7 +543,7 @@
sub display_editor {
my ($url,$folderpath,$symb,$idx,$type,$cdom,$cnum) = @_;
- my ($residx,$supplementalflag,$title,$pathitem,$output,$js);
+ my ($residx,$supplementalflag,$title,$pathitem,$output,$js,$navmap);
if ($folderpath =~ /^supplemental/) {
$supplementalflag = 1;
$residx = $idx;
@@ -553,7 +553,7 @@
(my $map,$residx,my $res) =
&Apache::lonnet::decode_symb($symb);
$title = &Apache::lonnet::gettitle($symb);
- my $path = &Apache::loncommon::symb_to_docspath($symb);
+ my $path = &Apache::loncommon::symb_to_docspath($symb,\$navmap);
$pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($path,'<>&"').'" />';
}
my %ltitools;
Index: loncom/interface/lonmenu.pm
diff -u loncom/interface/lonmenu.pm:1.462 loncom/interface/lonmenu.pm:1.463
--- loncom/interface/lonmenu.pm:1.462 Tue Nov 22 00:43:12 2016
+++ loncom/interface/lonmenu.pm Tue Nov 29 03:01:04 2016
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Routines to control the menu
#
-# $Id: lonmenu.pm,v 1.462 2016/11/22 00:43:12 raeburn Exp $
+# $Id: lonmenu.pm,v 1.463 2016/11/29 03:01:04 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -1035,9 +1035,9 @@
my ($cfile,$home,$switchserver,$forceedit,$forceview,$forcereg) = @_;
my $jscall;
if (($forceview) && ($env{'form.todocs'})) {
- my ($folderpath,$command);
+ my ($folderpath,$command,$navmap);
if ($env{'request.symb'}) {
- $folderpath = &Apache::loncommon::symb_to_docspath($env{'request.symb'});
+ $folderpath = &Apache::loncommon::symb_to_docspath($env{'request.symb'},\$navmap);
} elsif ($env{'form.folderpath'} =~ /^supplemental/) {
$folderpath = $env{'form.folderpath'};
$command = '&forcesupplement=1';
Index: loncom/interface/londocs.pm
diff -u loncom/interface/londocs.pm:1.616 loncom/interface/londocs.pm:1.617
--- loncom/interface/londocs.pm:1.616 Sat Nov 26 19:40:44 2016
+++ loncom/interface/londocs.pm Tue Nov 29 03:01:04 2016
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Documents
#
-# $Id: londocs.pm,v 1.616 2016/11/26 19:40:44 raeburn Exp $
+# $Id: londocs.pm,v 1.617 2016/11/29 03:01:04 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -142,7 +142,43 @@
return $title;
}
-
+sub default_folderpath {
+ my ($coursenum,$coursedom,$navmapref) = @_;
+ return unless ($coursenum && $coursedom && ref($navmapref));
+# Check if entire course is hidden and/or encrypted
+ my ($hiddenmap,$encryptmap,$folderpath,$hiddentop);
+ my $toplevel = "uploaded/$coursedom/$coursenum/default.sequence";
+ unless (ref($$navmapref)) {
+ $$navmapref = Apache::lonnavmaps::navmap->new();
+ }
+ if (ref($$navmapref)) {
+ if (lc($$navmapref->get_mapparam(undef,$toplevel,"0.hiddenresource")) eq 'yes') {
+ my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
+ my @resources = $$navmapref->retrieveResources($toplevel,$filterFunc,1,1);
+ unless (@resources) {
+ $hiddenmap = 1;
+ unless ($env{'request.role.adv'}) {
+ $hiddentop = 1;
+ if ($env{'form.folder'}) {
+ undef($env{'form.folder'});
+ }
+ }
+ }
+ }
+ if (lc($$navmapref->get_mapparam(undef,$toplevel,"0.encrypturl")) eq 'yes') {
+ $encryptmap = 1;
+ }
+ }
+ unless ($hiddentop) {
+ $folderpath='default&'.&escape(&mt('Main Content')).
+ '::'.$hiddenmap.':'.$encryptmap.'::';
+ }
+ if (wantarray) {
+ return ($folderpath,$hiddentop);
+ } else {
+ return $folderpath;
+ }
+}
sub dumpcourse {
my ($r) = @_;
@@ -879,11 +915,12 @@
sub docs_change_log {
my ($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit)=@_;
my $supplementalflag=($env{'form.folderpath'}=~/^supplemental/);
+ my $navmap;
my $js = '<script type="text/javascript">'."\n".
'// <![CDATA['."\n".
&Apache::loncommon::display_filter_js('docslog')."\n".
&editing_js($env{'user.domain'},$env{'user.name'},$supplementalflag,
- $coursedom,$coursenum,'','',$canedit)."\n".
+ $coursedom,$coursenum,'','',$canedit,\$navmap)."\n".
&history_tab_js()."\n".
&Apache::lonratedt::editscript('simple')."\n".
'// ]]>'."\n".
@@ -899,8 +936,9 @@
}
my $folderpath=$env{'form.folderpath'};
if ($folderpath eq '') {
- $folderpath = 'default&'.&escape(&mt('Main Content').':::::');
+ $folderpath = &default_folderpath($coursenum,$coursedom,\$navmap);
}
+ undef($navmap);
$pathitem = '<input type="hidden" name="folderpath" value="'.
&HTML::Entities::encode($folderpath,'<>&"').'" />';
my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
@@ -3297,6 +3335,7 @@
if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
push(@allmapidx,$res);
}
+
$output .= &entryline($idx,$name,$url,$folder,$allowed,$res,
$coursenum,$coursedom,$crstype,
$pathitem,$supplementalflag,$container,
@@ -3930,7 +3969,7 @@
}
}
- my ($editlink,$extresform,$anchor);
+ my ($editlink,$extresform,$anchor,$hiddenres);
my $orig_url = $url;
$orig_url=~s{http(:|:)//https(:|:)//}{https$2//};
$url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
@@ -3964,7 +4003,18 @@
}
}
}
- $url.=(($url=~/\?/)?'&':'?').'symb='.&HTML::Entities::encode($shownsymb,'"<>&');
+ unless ($env{'request.role.adv'}) {
+ if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
+ $url = '';
+ }
+ if (&Apache::lonnet::EXT('resource.0.hiddenresource',$symb) =~ /^yes$/i) {
+ $url = '';
+ $hiddenres = 1;
+ }
+ }
+ if ($url ne '') {
+ $url.=(($url=~/\?/)?'&':'?').'symb='.&HTML::Entities::encode($shownsymb,'"<>&');
+ }
} elsif (!$env{'request.role.adv'}) {
my $checkencrypt;
if (((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) ||
@@ -4007,6 +4057,7 @@
}
}
my ($rand_pick_text,$rand_order_text,$hiddenfolder);
+ my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
if ($isfolder || $ispage || $extension eq 'sequence' || $extension eq 'page') {
my $foldername=&escape($foldertitle);
my $folderpath=$env{'form.folderpath'};
@@ -4015,39 +4066,44 @@
$folderpath.=$containerarg.'&'.$foldername;
$url.='folderpath='.&escape($folderpath);
} else {
-# Append randompick number, hidden, and encrypted with ":" to foldername,
-# so it gets transferred between levels
- $folderpath.=$containerarg.'&'.$foldername.
- ':'.(&LONCAPA::map::getparameter($orderidx,
- 'parameter_randompick'))[0]
- .':'.((&LONCAPA::map::getparameter($orderidx,
- 'parameter_hiddenresource'))[0]=~/^yes$/i)
- .':'.((&LONCAPA::map::getparameter($orderidx,
- 'parameter_encrypturl'))[0]=~/^yes$/i)
- .':'.((&LONCAPA::map::getparameter($orderidx,
- 'parameter_randomorder'))[0]=~/^yes$/i)
- .':'.$ispage;
- if (!$env{'request.role.adv'}) {
- if (lc((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]) eq 'yes') {
- $url = '';
- $hiddenfolder = 1;
- } else {
- unless (ref($$navmapref)) {
- $$navmapref = Apache::lonnavmaps::navmap->new();
- }
- if (ref($$navmapref)) {
- if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
- $url = '';
- $hiddenfolder = 1;
+ my $rpicknum = (&LONCAPA::map::getparameter($orderidx,
+ 'parameter_randompick'))[0];
+ my $randorder = ((&LONCAPA::map::getparameter($orderidx,
+ 'parameter_randomorder'))[0]=~/^yes$/i);
+ my $hiddenmap = ((&LONCAPA::map::getparameter($orderidx,
+ 'parameter_hiddenresource'))[0]=~/^yes$/i);
+ my $encryptmap = ((&LONCAPA::map::getparameter($orderidx,
+ 'parameter_encrypturl'))[0]=~/^yes$/i);
+ unless ($hiddenmap) {
+ unless (ref($$navmapref)) {
+ $$navmapref = Apache::lonnavmaps::navmap->new();
+ }
+ if (ref($$navmapref)) {
+ if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
+ my @resources = $$navmapref->retrieveResources($folderurl,$filterFunc,1,1);
+ unless (@resources) {
+ $hiddenmap = 1;
+ unless ($env{'request.role.adv'}) {
+ $url = '';
+ $hiddenfolder = 1;
+ }
}
}
}
}
+ unless ($encryptmap) {
+ if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.encrypturl")) eq 'yes') {
+ $encryptmap = 1;
+ }
+ }
+
+# Append randompick number, hidden, and encrypted with ":" to foldername,
+# so it gets transferred between levels
+ $folderpath.=$containerarg.'&'.$foldername.
+ ':'.$rpicknum.':'.$hiddenmap.':'.$encryptmap.':'.$randorder.':'.$ispage;
unless ($url eq '') {
$url.='folderpath='.&escape($folderpath);
}
- my $rpicknum = (&LONCAPA::map::getparameter($orderidx,
- 'parameter_randompick'))[0];
my $rpckchk;
if ($rpicknum) {
$rpckchk = ' checked="checked"';
@@ -4067,7 +4123,7 @@
$rand_pick_text .= '</span></span>'.
$form_end;
my $ro_set;
- if ((&LONCAPA::map::getparameter($orderidx,'parameter_randomorder'))[0]=~/^yes$/i) {
+ if ($randorder) {
$ro_set = 'checked="checked"';
if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
push(@{$filtersref->{'randomorder'}},$orderidx);
@@ -4167,7 +4223,7 @@
$line.=&Apache::loncommon::modal_link(&js_escape($url.(($url=~/\?/)?'&':'?').'inhibitmenu=yes'.
(($anchor ne '')?$anchor:'')),
$title,600,500);
- } elsif ($hiddenfolder) {
+ } elsif (($hiddenfolder) || ($hiddenres)) {
$line.=$title.' <span class="LC_warning LC_docs_reinit_warn">'.&mt('(Hidden)').'</span>';
} else {
$line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>';
@@ -5108,15 +5164,15 @@
my $containertag;
my $pathitem;
my %ltitools;
+ my $hiddentop;
my $navmap;
- my $hiddentop;
+ my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
# Do we directly jump somewhere?
-
if (($env{'form.command'} eq 'direct') || ($env{'form.command'} eq 'directnav')) {
if ($env{'form.symb'} ne '') {
$env{'form.folderpath'}=
- &Apache::loncommon::symb_to_docspath($env{'form.symb'});
+ &Apache::loncommon::symb_to_docspath($env{'form.symb'},\$navmap);
&Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
$env{'form.command'}.'_'.$env{'form.symb'}});
} elsif ($env{'form.supppath'} ne '') {
@@ -5125,12 +5181,10 @@
$env{'form.command'}.'_'.$env{'form.supppath'}});
}
} elsif ($env{'form.command'} eq 'editdocs') {
- $env{'form.folderpath'} = 'default&'.
- &escape(&mt('Main Content').':::::');
+ $env{'form.folderpath'} = &default_folderpath($coursenum,$coursedom,\$navmap);
&Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => $env{'form.command'}});
} elsif ($env{'form.command'} eq 'editsupp') {
- $env{'form.folderpath'} = 'supplemental&'.
- &escape('Supplemental Content');
+ $env{'form.folderpath'} = &supplemental_base();
&Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/supplemental'});
} elsif ($env{'form.command'} eq 'contents') {
&Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/navmaps'});
@@ -5178,22 +5232,27 @@
($env{'form.folderpath'} ne '') && (!$supplementalflag)) {
my $folderurl;
my @pathitems = split(/\&/,$env{'form.folderpath'});
- my $container = $pathitems[-2];
- if ($container ne '') {
- $folderurl = "uploaded/$coursedom/$coursenum/$container";
+ my $folder = $pathitems[-2];
+ if ($folder eq '') {
+ undef($env{'form.folderpath'});
+ } else {
+ $folderurl = "uploaded/$coursedom/$coursenum/$folder";
if ((split(/\:/,$pathitems[-1]))[4]) {
$folderurl .= '.page';
} else {
$folderurl .= '.sequence';
}
- $navmap = Apache::lonnavmaps::navmap->new();
+ unless (ref($navmap)) {
+ $navmap = Apache::lonnavmaps::navmap->new();
+ }
if (ref($navmap)) {
if (lc($navmap->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
- undef($env{'form.folderpath'});
+ my @resources = $navmap->retrieveResources($folderurl,$filterFunc,1,1);
+ unless (@resources) {
+ undef($env{'form.folderpath'});
+ }
}
}
- } else {
- undef($env{'form.folderpath'});
}
}
@@ -5202,29 +5261,11 @@
unless ($env{'form.folderpath'}) {
if ($supplementalflag) {
$env{'form.folderpath'}=&supplemental_base();
- } else {
- $env{'form.folderpath'}='default&'.&escape(&mt('Main Content').
- ':::::');
- if (($allowed) && (!$env{'request.role.adv'})) {
-# If allowed and user's role is not advanced check entire course is not hidden
- unless (ref($navmap)) {
- $navmap = Apache::lonnavmaps::navmap->new();
- }
- if (ref($navmap)) {
- if (lc($navmap->get_mapparam(undef,"uploaded/$coursedom/$coursenum/default.sequence",
- "0.hiddenresource")) eq 'yes') {
- undef($env{'form.folderpath'});
- $hiddentop = 1;
- if ($env{'form.folder'}) {
- undef($env{'form.folder'});
- }
- }
- }
- }
+ } elsif ($allowed) {
+ ($env{'form.folderpath'},$hiddentop) = &default_folderpath($coursenum,$coursedom,\$navmap);
}
}
-
# Store this
unless ($toolsflag) {
if (($allowed) && ($env{'form.folderpath'} ne '')) {
@@ -5245,8 +5286,12 @@
} else {
if ($env{'form.folder'} eq '' ||
$env{'form.folder'} eq 'supplemental') {
- $folderpath='default&'.
- &escape(&mt('Main Content').':::::');
+ if ($env{'form.folder'} eq 'supplemental') {
+ $folderpath=&supplemental_base();
+ } elsif (!$hiddentop) {
+ $folderpath='default&'.
+ &escape(&mt('Main Content').':::::');
+ }
}
}
$containertag = '<input type="hidden" name="folderpath" value="" />';
@@ -5299,7 +5344,7 @@
%ltitools = &Apache::lonnet::get_domain_ltitools($coursedom);
my $posslti = keys(%ltitools);
$script .= &editing_js($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
- $londocroot,$canedit).
+ $londocroot,$canedit,\$navmap).
&history_tab_js().
&inject_data_js().
&Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr,$tid).
@@ -5331,7 +5376,7 @@
{'force_register' => $showdoc,}));
} elsif ($toolsflag) {
my ($breadtext,$breadtitle);
- $breadtext = "$crstype Contents";
+ $breadtext = "$crstype Editor";
if ($canedit) {
$breadtitle = 'Editing '.$crstype.' Contents';
} else {
@@ -5351,7 +5396,7 @@
{'bread_crumbs' => $brcrum,}));
} else {
my ($breadtext,$breadtitle,$helpitem);
- $breadtext = "$crstype Contents";
+ $breadtext = "$crstype Editor";
if ($canedit) {
$breadtitle = 'Editing '.$crstype.' Contents';
$helpitem = 'Docs_Adding_Course_Doc';
@@ -6172,6 +6217,7 @@
my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
$supplementalflag,\%orderhash,$iconpath,$pathitem,
\%ltitools,$canedit,\$navmap,$hiddentop);
+ undef($navmap);
if ($error) {
$r->print('<p><span class="LC_error">'.$error.'</span></p>');
}
@@ -6319,7 +6365,7 @@
if ($supplementalflag) {
my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
$supplementalflag,\%suporderhash,$iconpath,$pathitem,
- \%ltitools,$canedit,\$navmap);
+ \%ltitools,$canedit);
if ($error) {
$r->print('<p><span class="LC_error">'.$error.'</span></p>');
} else {
@@ -6713,7 +6759,7 @@
}
sub editing_js {
- my ($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,$londocroot,$canedit) = @_;
+ my ($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,$londocroot,$canedit,$navmapref) = @_;
my %js_lt = &Apache::lonlocal::texthash(
p_mnf => 'Name of New Folder',
t_mnf => 'New Folder',
@@ -6766,11 +6812,10 @@
if (&HTML::Entities::decode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'}) =~ /\:1$/) {
$main_container_page = 1;
}
- my $toplevelmain =
- &escape(&mt('Main Content').':::::');
+ my $backtourl;
+ my $toplevelmain = &escape(&default_folderpath($coursenum,$coursedom,$navmapref));
my $toplevelsupp = &supplemental_base();
- my $backtourl;
if ($env{'docs.exit.'.$env{'request.course.id'}} =~ /^direct_(.+)$/) {
my $caller = $1;
if ($caller =~ /^supplemental/) {
More information about the LON-CAPA-cvs
mailing list