--- loncom/interface/lonnavmaps.pm 2003/01/13 22:41:20 1.126 +++ loncom/interface/lonnavmaps.pm 2003/01/28 22:25:54 1.131 @@ -2,7 +2,7 @@ # The LearningOnline Network with CAPA # Navigate Maps Handler # -# $Id: lonnavmaps.pm,v 1.126 2003/01/13 22:41:20 bowersj2 Exp $ +# $Id: lonnavmaps.pm,v 1.131 2003/01/28 22:25:54 bowersj2 Exp $ # # Copyright Michigan State University Board of Trustees # @@ -46,6 +46,24 @@ use Apache::Constants qw(:common :http); use Apache::loncommon(); use POSIX qw (floor strftime); +my %navmaphash; +my %parmhash; + +sub cleanup { + if (tied(%navmaphash)){ + &Apache::lonnet::logthis('Cleanup navmaps: navmaphash'); + unless (untie(%navmaphash)) { + &Apache::lonnet::logthis('Failed cleanup navmaps: navmaphash'); + } + } + if (tied(%parmhash)){ + &Apache::lonnet::logthis('Cleanup navmaps: parmhash'); + unless (untie(%parmhash)) { + &Apache::lonnet::logthis('Failed cleanup navmaps: parmhash'); + } + } +} + sub handler { my $r = shift; real_handler($r); @@ -273,12 +291,6 @@ sub real_handler { $mapIterator->next(); # discard the first BEGIN_MAP my $curRes = $mapIterator->next(); my $counter = 0; -<<<<<<< lonnavmaps.pm - - # We only need to do this if we need to open the maps to show the - # current position - while ($depth > 0 && !$ENV{'form.alreadyHere'}) { -======= my $foundJump = ($jumpType == $NOTHING); # look for jump point if we have one my $looped = 0; @@ -286,7 +298,6 @@ sub real_handler { # current position. This will change the counter so we can't count # for the jump marker with this loop. while ($depth > 0 && !$ENV{'form.alreadyHere'}) { ->>>>>>> 1.122 if ($curRes == $mapIterator->BEGIN_MAP()) { $depth++; } if ($curRes == $mapIterator->END_MAP()) { $depth--; } @@ -305,9 +316,6 @@ sub real_handler { } $ENV{'form.alreadyHere'} = 1; } -<<<<<<< lonnavmaps.pm - -======= $looped = 1; $curRes = $mapIterator->next(); @@ -337,7 +345,6 @@ sub real_handler { $foundJump = 1; } ->>>>>>> 1.122 $curRes = $mapIterator->next(); } @@ -699,7 +706,7 @@ sub real_handler { $navmap->untieHashes(); - $r->print("

Course Map Untied

"); + $r->print(""); return OK; } @@ -996,13 +1003,12 @@ sub new { $self->{NETWORK_FAILURE} = 0; # tie the nav hash - my %navmaphash; + if (!(tie(%navmaphash, 'GDBM_File', $self->{NAV_HASH_FILE}, &GDBM_READER(), 0640))) { return undef; } - my %parmhash; if (!(tie(%parmhash, 'GDBM_File', $self->{PARM_HASH_FILE}, &GDBM_READER(), 0640))) { @@ -1010,11 +1016,11 @@ sub new { return undef; } + $self->{HASH_TIED} = 1; $self->{NAV_HASH} = \%navmaphash; $self->{PARM_HASH} = \%parmhash; bless($self); - $self->untieHashes(); return $self; } @@ -1490,10 +1496,6 @@ sub new { if ($curRes == $iterator->END_MAP()) { $depth--; } if (ref($curRes)) { -<<<<<<< lonnavmaps.pm - # If there's only one resource, this will save it - $resource = $curRes; $resourceCount++; -======= # If there's only one resource, this will save it # we have to filter empty resources from consideration here, # or even "empty", redirecting maps have two (start & finish) @@ -1501,7 +1503,6 @@ sub new { if($direction == FORWARD && $curRes->src()) { $resource = $curRes; $resourceCount++; } ->>>>>>> 1.122 my $resultingVal = $curRes->{DATA}->{$valName}; my $nextResources = $curRes->$nextResourceMethod(); my $nextCount = scalar(@{$nextResources}); @@ -1695,7 +1696,7 @@ sub next { # If this is a blank resource, don't actually return it. # Should you ever find you need it, make sure to add an option to the code # that you can use; other things depend on this behavior. - if (!$self->{HERE}->src()) { + if (!$self->{HERE}->src() || !$self->{HERE}->browsePriv()) { return $self->next(); } @@ -2634,16 +2635,7 @@ sub getNext { my $next = $choice->goesto(); $next = $self->{NAV_MAP}->getById($next); - # Don't remember it if the student doesn't have browse priviledges - # future note: this may properly belong in the client of the resource - my $browsePriv = $self->{BROWSE_PRIV}; - if (!defined($browsePriv)) { - $browsePriv = &Apache::lonnet::allowed('bre', $self->src); - $self->{BROWSE_PRIV} = $browsePriv; - } - if (!($browsePriv ne '2' && $browsePriv ne 'F')) { - push @branches, $next; - } + push @branches, $next; } return \@branches; } @@ -2657,20 +2649,20 @@ sub getPrevious { my $prev = $choice->comesfrom(); $prev = $self->{NAV_MAP}->getById($prev); - # Don't remember it if the student doesn't have browse priviledges - # future note: this may properly belong in the client of the resource - my $browsePriv = $self->{BROWSE_PRIV}; - if (!defined($browsePriv)) { - $browsePriv = &Apache::lonnet::allowed('bre', $self->src); - $self->{BROWSE_PRIV} = $browsePriv; - } - if (!($browsePriv ne '2' && $browsePriv ne 'F')) { - push @branches, $prev; - } + push @branches, $prev; } return \@branches; } +sub browsePriv { + my $self = shift; + if (defined($self->{BROWSE_PRIV})) { + return $self->{BROWSE_PRIV}; + } + + $self->{BROWSE_PRIV} = &Apache::lonnet::allowed('bre', $self->src()); +} + =pod =back