--- loncom/interface/lonnavmaps.pm 2004/10/27 18:15:31 1.301 +++ loncom/interface/lonnavmaps.pm 2004/12/12 21:17:04 1.309 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Navigate Maps Handler # -# $Id: lonnavmaps.pm,v 1.301 2004/10/27 18:15:31 albertel Exp $ +# $Id: lonnavmaps.pm,v 1.309 2004/12/12 21:17:04 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 @@ -119,23 +121,6 @@ window.status='Done.'; ENDCLOSE } -sub nav_control_js { - my $nav=($ENV{'environment.remotenavmap'} eq 'on'); - return (<".&mt('Default')." - + "); @@ -450,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; @@ -458,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->src(); + 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); } } } @@ -478,7 +466,7 @@ sub getLinkForResource { if (defined($_)) { $res = $_; } } - return $res->src(); + return ($res->link(),$res->shown_symb()); } # Convenience function: This separates the logic of how to create @@ -1026,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}; @@ -1041,7 +1038,11 @@ sub render_resource { } # links to open and close the folder + + my $linkopen = ""; + + my $linkclose = ""; # Default icon: unknown page @@ -1082,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') . @@ -1109,6 +1111,7 @@ sub render_resource { } # Decide what to display + $result .= "$newBranchText$linkopen$icon$linkclose"; my $curMarkerBegin = ''; @@ -1126,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 = ""; } @@ -1417,7 +1420,7 @@ sub render { # Determine where the "here" marker is and where the screen jumps to. if ($ENV{'form.postsymb'}) { - $here = $jump = $ENV{'form.postsymb'}; + $here = $jump = &Apache::lonnet::symbclean($ENV{'form.postsymb'}); } elsif ($ENV{'form.postdata'}) { # couldn't find a symb, is there a URL? my $currenturl = $ENV{'form.postdata'}; @@ -1857,22 +1860,19 @@ END # Set up some data about the parts that the cols might want my $filter = $it->{FILTER}; - my $src; + my ($src,$symb,$anchor); if ($args->{'sort'}) { $src = $curRes->src(); # FIXME this is wrong for .pages + $symb = $curRes->symb(); # FIXME this is wrong for .pages } else { my $stack = $it->getStack(); - $src=getLinkForResource($stack); - } - my $anchor=''; - if ($src=~s/(\#.*)$//) { - $anchor=$1; + ($src,$symb,$anchor)=getLinkForResource($stack); } + if (defined($anchor)) { $anchor='#'.$anchor; } my $srcHasQuestion = $src =~ /\?/; $args->{"resourceLink"} = $src. ($srcHasQuestion?'&':'?') . - 'symb=' . &Apache::lonnet::escape($curRes->symb()). - $anchor; + 'symb=' . &Apache::lonnet::escape($symb).$anchor; # Now, display each column. foreach my $col (@$cols) { @@ -3463,6 +3463,7 @@ Returns the title of the resource. # These info functions can be used directly, as they don't return # resource information. sub comesfrom { my $self=shift; return $self->navHash("comesfrom_", 1); } +sub encrypted { my $self=shift; return $self->navHash("encrypted_", 1); } sub ext { my $self=shift; return $self->navHash("ext_", 1) eq 'true:'; } sub from { my $self=shift; return $self->navHash("from_", 1); } # considered private and undocumented @@ -3474,10 +3475,20 @@ sub randompick { return $self->{NAV_MAP}->{PARM_HASH}->{$self->symb . '.0.parameter_randompick'}; } +sub link { + my $self=shift; + if ($self->encrypted()) { return &Apache::lonenc::encrypted($self->src); } + return $self->src; +} sub src { my $self=shift; return $self->navHash("src_", 1); } +sub shown_symb { + my $self=shift; + if ($self->encrypted()) {return &Apache::lonenc::encrypted($self->symb());} + return $self->symb(); +} sub symb { my $self=shift; (my $first, my $second) = $self->{ID} =~ /(\d+).(\d+)/;