--- loncom/interface/lonnavmaps.pm 2004/11/11 22:39:05 1.304
+++ loncom/interface/lonnavmaps.pm 2005/02/01 21:03:13 1.314
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Navigate Maps Handler
#
-# $Id: lonnavmaps.pm,v 1.304 2004/11/11 22:39:05 albertel Exp $
+# $Id: lonnavmaps.pm,v 1.314 2005/02/01 21:03:13 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -33,7 +33,9 @@ use strict;
use Apache::Constants qw(:common :http);
use Apache::loncommon();
use Apache::lonmenu();
+use Apache::lonenc();
use Apache::lonlocal;
+use Apache::lonnet;
use POSIX qw (floor strftime);
use Data::Dumper; # for debugging, not always
@@ -162,7 +164,7 @@ sub real_handler {
$r->send_http_header;
my %toplinkitems=();
-
+ &add_linkitem(\%toplinkitems,'blank','',"Select Action");
if ($ENV{QUERY_STRING} eq 'collapseExternal') {
&Apache::lonnet::put('environment',{'remotenavmap' => 'off'});
&Apache::lonnet::appenv('environment.remotenavmap' => 'off');
@@ -215,7 +217,7 @@ ENDSUBM
$r->print("
\n");
$r->print("".&mt('Navigate Course Contents')."");
# ------------------------------------------------------------ Get query string
- &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['register','sort','showOnlyHomework']);
+ &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['register','sort','showOnlyHomework','postsymb']);
# ----------------------------------------------------- Force menu registration
my $addentries='';
@@ -375,7 +377,7 @@ ENDSUBM
-
+
");
@@ -433,7 +435,6 @@ sub removeFromFilter {
# Convenience function: Given a stack returned from getStack on the iterator,
# return the correct src() value.
-# Later, this should add an anchor when we start putting anchors in pages.
sub getLinkForResource {
my $stack = shift;
my $res;
@@ -441,14 +442,18 @@ sub getLinkForResource {
# Check to see if there are any pages in the stack
foreach $res (@$stack) {
if (defined($res)) {
+ my $anchor;
if ($res->is_page()) {
- return $res->link();
+ foreach (@$stack) { if (defined($_)) { $anchor = $_; } }
+ $anchor=&Apache::lonnet::escape($anchor->shown_symb());
+ return ($res->link(),$res->shown_symb(),$anchor);
}
# in case folder was skipped over as "only sequence"
my ($map,$id,$src)=&Apache::lonnet::decode_symb($res->symb());
if ($map=~/\.page$/) {
- return &Apache::lonnet::clutter($map).'#'.
- &Apache::lonnet::escape(&Apache::lonnet::declutter($src));
+ my $url=&Apache::lonnet::clutter($map);
+ $anchor=&Apache::lonnet::escape($src->shown_symb());
+ return ($url,$res->shown_symb(),$anchor);
}
}
}
@@ -461,7 +466,7 @@ sub getLinkForResource {
if (defined($_)) { $res = $_; }
}
- return $res->link();
+ return ($res->link(),$res->shown_symb());
}
# Convenience function: This separates the logic of how to create
@@ -1009,6 +1014,15 @@ sub render_resource {
my $nonLinkedText = ''; # stuff after resource title not in link
my $link = $params->{"resourceLink"};
+
+ # The URL part is not escaped at this point, but the symb is...
+ # The stuff to the left of the ? must have ' replaced by \' since
+ # it will be quoted with ' in the href.
+
+ my ($left,$right) = split(/\?/, $link);
+ $left =~ s/'/\\'/g;
+ $link = $left.'?'.$right;
+
my $src = $resource->src();
my $it = $params->{"iterator"};
my $filter = $it->{FILTER};
@@ -1024,7 +1038,11 @@ sub render_resource {
}
# links to open and close the folder
+
+
my $linkopen = "";
+
+
my $linkclose = "";
# Default icon: unknown page
@@ -1065,6 +1083,7 @@ sub render_resource {
'&jump=' .
&Apache::lonnet::escape($resource->symb()) .
"&folderManip=1'>";
+
} else {
# Don't allow users to manipulate folder
$icon = "navmap.$folderType." . ($nowOpen ? 'closed' : 'open') .
@@ -1092,6 +1111,7 @@ sub render_resource {
}
# Decide what to display
+
$result .= "$newBranchText$linkopen$icon$linkclose";
my $curMarkerBegin = '';
@@ -1109,7 +1129,7 @@ sub render_resource {
!$params->{'condensed'}) {
my $displaypart=$resource->part_display($part);
$partLabel = " (Part: $displaypart)";
- $link.='#'.&Apache::lonnet::escape($part);
+ if ($link!~/\#/) { $link.='#'.&Apache::lonnet::escape($part); }
$title = "";
}
@@ -1829,7 +1849,26 @@ END
# Add part 0 so we display it correctly.
unshift @parts, '0';
}
-
+
+ {
+ my ($src,$symb,$anchor,$stack);
+ if ($args->{'sort'}) {
+ my $it = $navmap->getIterator(undef, undef, undef, 1);
+ while ( my $res=$it->next()) {
+ if (ref($res) &&
+ $res->symb() eq $curRes->symb()) { last; }
+ }
+ $stack=$it->getStack();
+ } else {
+ $stack=$it->getStack();
+ }
+ ($src,$symb,$anchor)=getLinkForResource($stack);
+ if (defined($anchor)) { $anchor='#'.$anchor; }
+ my $srcHasQuestion = $src =~ /\?/;
+ $args->{"resourceLink"} = $src.
+ ($srcHasQuestion?'&':'?') .
+ 'symb=' . &Apache::lonnet::escape($symb).$anchor;
+ }
# Now, we've decided what parts to show. Loop through them and
# show them.
foreach my $part (@parts) {
@@ -1840,22 +1879,6 @@ END
# Set up some data about the parts that the cols might want
my $filter = $it->{FILTER};
- my $src;
- if ($args->{'sort'}) {
- $src = $curRes->src(); # FIXME this is wrong for .pages
- } else {
- my $stack = $it->getStack();
- $src=getLinkForResource($stack);
- }
- my $anchor='';
- if ($src=~s/(\#.*)$//) {
- $anchor=$1;
- }
- my $srcHasQuestion = $src =~ /\?/;
- $args->{"resourceLink"} = $src.
- ($srcHasQuestion?'&':'?') .
- 'symb=' . &Apache::lonnet::escape($curRes->shown_symb()).
- $anchor;
# Now, display each column.
foreach my $col (@$cols) {
@@ -1933,8 +1956,8 @@ sub add_linkitem {
sub show_linkitems {
my ($linkitems)=@_;
- my @linkorder = ("launchnav","closenav","firsthomework","everything",
- "uncompleted","changefolder","clearbubbles");
+ my @linkorder = ("blank","launchnav","closenav","firsthomework",
+ "everything","uncompleted","changefolder","clearbubbles");
my $result .= (<
@@ -2234,7 +2257,8 @@ sub courseMapDefined {
sub getIterator {
my $self = shift;
my $iterator = Apache::lonnavmaps::iterator->new($self, shift, shift,
- shift, undef, shift);
+ shift, undef, shift,
+ shift, shift);
return $iterator;
}
@@ -2501,7 +2525,7 @@ you're not sure if $res is already an ob
resource appears multiple times in the course, only the first instance
will be returned. As a result, this is probably useful only for maps.
-=item * B(map, filterFunc, recursive, bailout):
+=item * B(map, filterFunc, recursive, bailout, showall):
The map is a specification of a map to retreive the resources from,
either as a url or as an object. The filterFunc is a reference to a
@@ -2509,13 +2533,14 @@ function that takes a resource object as
true if the resource should be included, or false if it should not
be. If recursive is true, the map will be recursively examined,
otherwise it will not be. If bailout is true, the function will return
-as soon as it finds a resource, if false it will finish. By default,
-the map is the top-level map of the course, filterFunc is a function
-that always returns 1, recursive is true, bailout is false. The
-resources will be returned in a list containing the resource objects
-for the corresponding resources, with B in
-the list; regardless of branching, recursion, etc., it will be a flat
-list.
+as soon as it finds a resource, if false it will finish. If showall is
+true it will not hide maps that contain nothing but one other map. By
+default, the map is the top-level map of the course, filterFunc is a
+function that always returns 1, recursive is true, bailout is false,
+showall is false. The resources will be returned in a list containing
+the resource objects for the corresponding resources, with B in the list; regardless of branching,
+recursion, etc., it will be a flat list.
Thus, this is suitable for cases where you don't want the structure,
just a list of all resources. It is also suitable for finding out how
@@ -2562,7 +2587,7 @@ sub retrieveResources {
if (!defined($recursive)) { $recursive = 1; }
my $bailout = shift;
if (!defined($bailout)) { $bailout = 0; }
-
+ my $showall = shift;
# Create the necessary iterator.
if (!ref($map)) { # assume it's a url of a map.
$map = $self->getResourceByUrl($map);
@@ -2581,7 +2606,7 @@ sub retrieveResources {
# Get an iterator.
my $it = $self->getIterator($map->map_start(), $map->map_finish(),
- undef, $recursive);
+ undef, $recursive, $showall);
my @resources = ();
@@ -2878,7 +2903,8 @@ sub new {
Apache::lonnavmaps::iterator->new($self->{NAV_MAP}, $firstResource,
$finishResource, $self->{FILTER},
$self->{ALREADY_SEEN},
- $self->{CONDITION}, 0);
+ $self->{CONDITION},
+ $self->{FORCE_TOP});
}
@@ -3041,7 +3067,9 @@ sub next {
$self->{RECURSIVE_ITERATOR} =
Apache::lonnavmaps::iterator->new($self->{NAV_MAP}, $firstResource,
$finishResource, $self->{FILTER},
- $self->{ALREADY_SEEN}, $self->{CONDITION});
+ $self->{ALREADY_SEEN},
+ $self->{CONDITION},
+ $self->{FORCE_TOP});
}
# If this is a blank resource, don't actually return it.
@@ -4702,7 +4730,8 @@ sub browsePriv {
return $self->{BROWSE_PRIV};
}
- $self->{BROWSE_PRIV} = &Apache::lonnet::allowed('bre', $self->src());
+ $self->{BROWSE_PRIV} = &Apache::lonnet::allowed('bre',$self->src(),
+ $self->symb());
}
=pod