Diff for /loncom/interface/lonnavmaps.pm between versions 1.129.2.3 and 1.130

version 1.129.2.3, 2003/03/20 22:30:38 version 1.130, 2003/01/14 18:47:50
Line 46  use Apache::Constants qw(:common :http); Line 46  use Apache::Constants qw(:common :http);
 use Apache::loncommon();  use Apache::loncommon();
 use POSIX qw (floor strftime);  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 {  sub handler {
     my $r = shift;      my $r = shift;
     real_handler($r);      real_handler($r);
Line 403  sub real_handler { Line 421  sub real_handler {
                     # just display first                      # just display first
                     if (!$curRes->opendate("0")) {                      if (!$curRes->opendate("0")) {
                         # no parts are open, display as one part                          # no parts are open, display as one part
                         @parts = ();                          @parts = ("0");
                         $condensed = 1;                          $condensed = 1;
                     } else {                      } else {
                         # Otherwise, only display part 0 if we want to                           # Otherwise, only display part 0 if we want to 
                         # attach feedback or email information to it                          # attach feedback or email information to it
                         if ($curRes->hasDiscussion() || $curRes->getFeedback()) {                          if ($curRes->hasDiscussion() || $curRes->getFeedback()) {
                             #shift @parts;                              shift @parts;
                         } else {                          } else {
                             # Now, we decide whether to condense the                              # Now, we decide whether to condense the
                             # parts due to similarity                              # parts due to similarity
Line 441  sub real_handler { Line 459  sub real_handler {
                             if (($statusAllSame && defined($condenseStatuses{$status})) ||                              if (($statusAllSame && defined($condenseStatuses{$status})) ||
                                 ($dueAllSame && $status == $curRes->OPEN && $statusAllSame)||                                  ($dueAllSame && $status == $curRes->OPEN && $statusAllSame)||
                                 ($openAllSame && $status == $curRes->OPEN_LATER && $statusAllSame) ){                                  ($openAllSame && $status == $curRes->OPEN_LATER && $statusAllSame) ){
                                 @parts = ();                                  @parts = ($parts[1]);
                                 $condensed = 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               # Is it a multipart problem with a single part, now in 
             # @parts with "0" filtered out? If so, 'forget' it's a multi-part              # @parts with "0" filtered out? If so, 'forget' it's a multi-part
             # problem and treat it like a single-part problem.              # problem and treat it like a single-part problem.
             if ( scalar(@parts) == 0 ) {              if ( scalar(@parts) == 1 ) {
                 $multipart = 0;                  $multipart = 0;
             }              }
   
Line 462  sub real_handler { Line 484  sub real_handler {
             # status, but if it's multipart, we're lost, since we can't              # status, but if it's multipart, we're lost, since we can't
             # retreive the metadata to count the parts              # retreive the metadata to count the parts
             if ($curRes->{RESOURCE_ERROR}) {              if ($curRes->{RESOURCE_ERROR}) {
                 @parts = ();                  @parts = ("0");
             }              }
   
             # Step Two: Print the actual data.              # Step Two: Print the actual data.
   
             # For each part we intend to display...              # For each part we intend to display...
             foreach my $part ('', @parts) {              foreach my $part (@parts) {
                 if ($part eq '0') {  
                     next;  
                 }  
   
                 my $nonLinkedText = ""; # unlinked stuff after title                  my $nonLinkedText = ""; # unlinked stuff after title
                                   
Line 506  sub real_handler { Line 525  sub real_handler {
   
                 my $icon = "<img src=\"/adm/lonIcons/html.gif\" alt=\"\" border=\"0\" />";                  my $icon = "<img src=\"/adm/lonIcons/html.gif\" alt=\"\" border=\"0\" />";
                 if ($curRes->is_problem()) {                   if ($curRes->is_problem()) { 
                     if ($part eq "" || $condensed) {                      if ($part eq "0" || $condensed) {
                         $icon = '<img src="/adm/lonIcons/problem.gif" alt="" border=\"0\" />';                           $icon = '<img src="/adm/lonIcons/problem.gif" alt="" border=\"0\" />'; 
                     } else {                      } else {
                         $icon = $indentString;                          $icon = $indentString;
Line 583  sub real_handler { Line 602  sub real_handler {
                     $displayedHereMarker = 1;                      $displayedHereMarker = 1;
                 }                  }
   
                 if ($curRes->is_problem() && $part ne "" && !$condensed) {                   if ($curRes->is_problem() && $part ne "0" && !$condensed) { 
                     $partLabel = " (Part $part)";                       $partLabel = " (Part $part)"; 
                     $title = "";                      $title = "";
                 }                  }
                 if ($condensed && $curRes->countParts() > 1) {                  if ($multipart && $condensed) {
                     $nonLinkedText .= ' (' . $curRes->countParts() . ' parts)';                      $nonLinkedText .= ' (' . $curRes->countParts() . ' parts)';
                 }                  }
   
Line 984  sub new { Line 1003  sub new {
     $self->{NETWORK_FAILURE} = 0;      $self->{NETWORK_FAILURE} = 0;
   
     # tie the nav hash      # tie the nav hash
     my %navmaphash;  
     if (!(tie(%navmaphash, 'GDBM_File', $self->{NAV_HASH_FILE},      if (!(tie(%navmaphash, 'GDBM_File', $self->{NAV_HASH_FILE},
               &GDBM_READER(), 0640))) {                &GDBM_READER(), 0640))) {
         return undef;          return undef;
     }      }
           
     my %parmhash;  
     if (!(tie(%parmhash, 'GDBM_File', $self->{PARM_HASH_FILE},      if (!(tie(%parmhash, 'GDBM_File', $self->{PARM_HASH_FILE},
               &GDBM_READER(), 0640)))                &GDBM_READER(), 0640)))
     {      {
Line 1678  sub next { Line 1696  sub next {
     # If this is a blank resource, don't actually return it.      # 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      # 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.      #  that you can use; other things depend on this behavior.
     if (!$self->{HERE}->src() || !$self->{HERE}->browsePriv()) {      if (!$self->{HERE}->src()) {
         return $self->next();          return $self->next();
     }      }
   
Line 2287  sub countParts { Line 2305  sub countParts {
     my $self = shift;      my $self = shift;
           
     my $parts = $self->parts();      my $parts = $self->parts();
     my $delta = 0;  
     for my $part (@$parts) {  
         if ($part eq '0') { $delta--; }  
     }  
   
     if ($self->{RESOURCE_ERROR}) {      if ($self->{RESOURCE_ERROR}) {
         return 0;          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  # Private function: Extracts the parts information and saves it
Line 2310  sub extractParts { Line 2326  sub extractParts {
   
     # Retrieve part count, if this is a problem      # Retrieve part count, if this is a problem
     if ($self->is_problem()) {      if ($self->is_problem()) {
         my $metadata = &Apache::lonnet::metadata($self->src(), 'packages');          my $metadata = &Apache::lonnet::metadata($self->src(), 'allpossiblekeys');
         if (!$metadata) {          if (!$metadata) {
             $self->{RESOURCE_ERROR} = 1;              $self->{RESOURCE_ERROR} = 1;
             $self->{PARTS} = [];              $self->{PARTS} = [];
Line 2318  sub extractParts { Line 2334  sub extractParts {
         }          }
                   
         foreach (split(/\,/,$metadata)) {          foreach (split(/\,/,$metadata)) {
             if ($_ =~ /^part_(.*)$/) {              if ($_ =~ /^parameter\_(.*)\_opendate$/) {
                 push @{$self->{PARTS}}, $1;                  push @{$self->{PARTS}}, $1;
             }              }
         }          }
Line 2619  sub getNext { Line 2635  sub getNext {
         my $next = $choice->goesto();          my $next = $choice->goesto();
         $next = $self->{NAV_MAP}->getById($next);          $next = $self->{NAV_MAP}->getById($next);
   
         push @branches, $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;
           }
     }      }
     return \@branches;      return \@branches;
 }  }
Line 2633  sub getPrevious { Line 2658  sub getPrevious {
         my $prev = $choice->comesfrom();          my $prev = $choice->comesfrom();
         $prev = $self->{NAV_MAP}->getById($prev);          $prev = $self->{NAV_MAP}->getById($prev);
   
         push @branches, $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;
           }
     }      }
     return \@branches;      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  =pod
   
 =back  =back

Removed from v.1.129.2.3  
changed lines
  Added in v.1.130


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>