--- loncom/interface/lonnavmaps.pm 2003/03/20 20:40:42 1.129.2.2 +++ 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.129.2.2 2003/03/20 20:40:42 albertel 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); @@ -403,7 +421,7 @@ sub real_handler { # just display first if (!$curRes->opendate("0")) { # no parts are open, display as one part - @parts = (); + @parts = ("0"); $condensed = 1; } else { # Otherwise, only display part 0 if we want to @@ -441,19 +459,23 @@ sub real_handler { if (($statusAllSame && defined($condenseStatuses{$status})) || ($dueAllSame && $status == $curRes->OPEN && $statusAllSame)|| ($openAllSame && $status == $curRes->OPEN_LATER && $statusAllSame) ){ - @parts = (); + @parts = ($parts[1]); $condensed = 1; } } } } + } else { + $parts[0] = "0"; # this is to get past foreach loop below + # you can consider a non-problem resource as a resource + # with only one part without loss, and it simplifies the looping } # Is it a multipart problem with a single part, now in # @parts with "0" filtered out? If so, 'forget' it's a multi-part # problem and treat it like a single-part problem. - if ( scalar(@parts) == 0 ) { + if ( scalar(@parts) == 1 ) { $multipart = 0; } @@ -462,16 +484,13 @@ sub real_handler { # status, but if it's multipart, we're lost, since we can't # retreive the metadata to count the parts if ($curRes->{RESOURCE_ERROR}) { - @parts = (); + @parts = ("0"); } # Step Two: Print the actual data. # For each part we intend to display... - foreach my $part ('', @parts) { - if ($part eq '0') { - next; - } + foreach my $part (@parts) { my $nonLinkedText = ""; # unlinked stuff after title @@ -506,7 +525,7 @@ sub real_handler { my $icon = "\"\""; if ($curRes->is_problem()) { - if ($part eq "" || $condensed) { + if ($part eq "0" || $condensed) { $icon = ''; } else { $icon = $indentString; @@ -583,11 +602,11 @@ sub real_handler { $displayedHereMarker = 1; } - if ($curRes->is_problem() && $part ne "" && !$condensed) { + if ($curRes->is_problem() && $part ne "0" && !$condensed) { $partLabel = " (Part $part)"; $title = ""; } - if ($condensed && $curRes->countParts() > 1) { + if ($multipart && $condensed) { $nonLinkedText .= ' (' . $curRes->countParts() . ' parts)'; } @@ -984,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))) { @@ -2287,16 +2305,14 @@ sub countParts { my $self = shift; my $parts = $self->parts(); - my $delta = 0; - for my $part (@$parts) { - if ($part eq '0') { $delta--; } - } if ($self->{RESOURCE_ERROR}) { return 0; } - return scalar(@{$parts}) + $delta; + if (scalar(@{$parts}) < 2) { return 1;} + + return scalar(@{$parts}) - 1; } # Private function: Extracts the parts information and saves it @@ -2310,7 +2326,7 @@ sub extractParts { # Retrieve part count, if this is a problem if ($self->is_problem()) { - my $metadata = &Apache::lonnet::metadata($self->src(), 'packages'); + my $metadata = &Apache::lonnet::metadata($self->src(), 'allpossiblekeys'); if (!$metadata) { $self->{RESOURCE_ERROR} = 1; $self->{PARTS} = []; @@ -2318,7 +2334,7 @@ sub extractParts { } foreach (split(/\,/,$metadata)) { - if ($_ =~ /^part_(.*)$/) { + if ($_ =~ /^parameter\_(.*)\_opendate$/) { push @{$self->{PARTS}}, $1; } }