--- loncom/interface/lonnavmaps.pm 2002/12/02 14:19:38 1.119 +++ loncom/interface/lonnavmaps.pm 2003/03/20 22:30:38 1.129.2.3 @@ -2,7 +2,7 @@ # The LearningOnline Network with CAPA # Navigate Maps Handler # -# $Id: lonnavmaps.pm,v 1.119 2002/12/02 14:19:38 bowersj2 Exp $ +# $Id: lonnavmaps.pm,v 1.129.2.3 2003/03/20 22:30:38 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -96,6 +96,11 @@ sub real_handler { '')); $r->print(''); + $r->rflush(); + + # Now that we've displayed some stuff to the user, init the navmap + $navmap->init(); + $r->print(''); my $date=localtime; $r->print(''); @@ -178,9 +183,6 @@ sub real_handler { $r->print('
 '); $r->rflush(); - # Now that we've displayed some stuff to the user, init the navmap - $navmap->init(); - # Check that it's defined if (!($navmap->courseMapDefined())) { $r->print('Coursemap undefined.' . @@ -274,15 +276,13 @@ sub real_handler { my $foundJump = ($jumpType == $NOTHING); # look for jump point if we have one my $looped = 0; - $r->print($hereType); - # We only need to do this if we need to open the maps to show the # 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'}) { if ($curRes == $mapIterator->BEGIN_MAP()) { $depth++; } if ($curRes == $mapIterator->END_MAP()) { $depth--; } - $r->print($curRes . ' '); + if (ref($curRes) && !$ENV{'form.alreadyHere'} && ($hereType == $SYMB && $curRes->symb() eq $here) || (ref($curRes) && $hereType == $URL && $curRes->src() eq $here)) { @@ -403,13 +403,13 @@ sub real_handler { # just display first if (!$curRes->opendate("0")) { # no parts are open, display as one part - @parts = ("0"); + @parts = (); $condensed = 1; } else { # Otherwise, only display part 0 if we want to # attach feedback or email information to it if ($curRes->hasDiscussion() || $curRes->getFeedback()) { - shift @parts; + #shift @parts; } else { # Now, we decide whether to condense the # parts due to similarity @@ -441,23 +441,19 @@ sub real_handler { if (($statusAllSame && defined($condenseStatuses{$status})) || ($dueAllSame && $status == $curRes->OPEN && $statusAllSame)|| ($openAllSame && $status == $curRes->OPEN_LATER && $statusAllSame) ){ - @parts = ($parts[1]); + @parts = (); $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) == 1 ) { + if ( scalar(@parts) == 0 ) { $multipart = 0; } @@ -466,13 +462,16 @@ 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 = ("0"); + @parts = (); } # Step Two: Print the actual data. # 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 @@ -488,6 +487,10 @@ sub real_handler { '"'; my $title = $curRes->compTitle(); + if ($src=~/^\/uploaded\//) { + $nonLinkedText=$title; + $title=''; + } my $partLabel = ""; my $newBranchText = ""; @@ -503,7 +506,7 @@ sub real_handler { my $icon = "\"\""; if ($curRes->is_problem()) { - if ($part eq "0" || $condensed) { + if ($part eq "" || $condensed) { $icon = ''; } else { $icon = $indentString; @@ -580,11 +583,11 @@ sub real_handler { $displayedHereMarker = 1; } - if ($curRes->is_problem() && $part ne "0" && !$condensed) { + if ($curRes->is_problem() && $part ne "" && !$condensed) { $partLabel = " (Part $part)"; $title = ""; } - if ($multipart && $condensed) { + if ($condensed && $curRes->countParts() > 1) { $nonLinkedText .= ' (' . $curRes->countParts() . ' parts)'; } @@ -598,7 +601,7 @@ sub real_handler { $r->print("\n"); # SECOND COL: Is there text, feedback, errors?? - my $discussionHTML = ""; my $feedbackHTML = ""; + my $discussionHTML = ""; my $feedbackHTML = ""; my $errorHTML = ""; if ($curRes->hasDiscussion()) { $discussionHTML = $linkopen . @@ -618,7 +621,19 @@ sub real_handler { } } - $r->print(""); + if ($curRes->getErrors()) { + my $errors = $curRes->getErrors(); + foreach (split(/,/, $errors)) { + if ($_) { + $errorHTML .= ' ' + . ''; + } + } + } + + $r->print(""); # Is this the first displayed part of a multi-part problem # that has not been condensed, so we should suppress these two @@ -670,10 +685,10 @@ sub real_handler { $r->print(''); } - $r->print(""); - $navmap->untieHashes(); + $r->print(""); + return OK; } @@ -983,15 +998,11 @@ sub new { return undef; } - # Now copy the hashes for speed (?) - my %realnav; my %realparm; - foreach (%navmaphash) { $realnav{$_} = $navmaphash{$_}; } - foreach (%parmhash) { $realparm{$_} = $navmaphash{$_}; } - $self->{NAV_HASH} = \%realnav; - $self->{PARM_HASH} = \%realparm; + $self->{HASH_TIED} = 1; + $self->{NAV_HASH} = \%navmaphash; + $self->{PARM_HASH} = \%parmhash; bless($self); - $self->untieHashes(); return $self; } @@ -1062,7 +1073,7 @@ sub init { my %emailstatus = &Apache::lonnet::dump('email_status'); my $logoutTime = $emailstatus{'logout'}; my $courseLeaveTime = $emailstatus{'logout_'.$ENV{'request.course.id'}}; - $self->{LAST_CHECK} = ($courseLeaveTime > $logoutTime ? + $self->{LAST_CHECK} = ($courseLeaveTime < $logoutTime ? $courseLeaveTime : $logoutTime); my %discussiontime = &Apache::lonnet::dump('discussiontimes', $cdom, $cnum); @@ -1143,18 +1154,19 @@ sub DESTROY { $self->untieHashes(); } -# Private function: Does the given resource (as a symb string) have +# Private method: Does the given resource (as a symb string) have # current discussion? Returns 0 if chat/mail data not extracted. sub hasDiscussion { my $self = shift; my $symb = shift; if (!defined($self->{DISCUSSION_TIME})) { return 0; } + #return defined($self->{DISCUSSION_TIME}->{$symb}); return $self->{DISCUSSION_TIME}->{$symb} > $self->{LAST_CHECK}; } -# Private function: Does the given resource (as a symb string) have +# Private method: Does the given resource (as a symb string) have # current feedback? Returns the string in the feedback hash, which # will be false if it does not exist. sub getFeedback { @@ -1166,6 +1178,15 @@ sub getFeedback { return $self->{FEEDBACK}->{$symb}; } +# Private method: Get the errors for that resource (by source). +sub getErrors { + my $self = shift; + my $src = shift; + + if (!defined($self->{ERROR_MSG})) { return ""; } + return $self->{ERROR_MSG}->{$src}; +} + =pod =item * B(id): Based on the ID of the resource (1.1, 3.2, etc.), get a resource object for that resource. This method, or other methods that use it (as in the resource object) is the only proper way to obtain a resource object. @@ -1657,7 +1678,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(); } @@ -2231,7 +2252,16 @@ sub hasDiscussion { sub getFeedback { my $self = shift; - return $self->{NAV_MAP}->getFeedback($self->src()); + my $source = $self->src(); + if ($source =~ /^\/res\//) { $source = substr $source, 5; } + return $self->{NAV_MAP}->getFeedback($source); +} + +sub getErrors { + my $self = shift; + my $source = $self->src(); + if ($source =~ /^\/res\//) { $source = substr $source, 5; } + return $self->{NAV_MAP}->getErrors($source); } =pod @@ -2257,14 +2287,16 @@ 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; } - if (scalar(@{$parts}) < 2) { return 1;} - - return scalar(@{$parts}) - 1; + return scalar(@{$parts}) + $delta; } # Private function: Extracts the parts information and saves it @@ -2278,7 +2310,7 @@ sub extractParts { # Retrieve part count, if this is a problem if ($self->is_problem()) { - my $metadata = &Apache::lonnet::metadata($self->src(), 'allpossiblekeys'); + my $metadata = &Apache::lonnet::metadata($self->src(), 'packages'); if (!$metadata) { $self->{RESOURCE_ERROR} = 1; $self->{PARTS} = []; @@ -2286,7 +2318,7 @@ sub extractParts { } foreach (split(/\,/,$metadata)) { - if ($_ =~ /^parameter\_(.*)\_opendate$/) { + if ($_ =~ /^part_(.*)$/) { push @{$self->{PARTS}}, $1; } } @@ -2587,16 +2619,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; } @@ -2610,20 +2633,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
Key:  $discussionHTML$feedbackHTML $discussionHTML$feedbackHTML$errorHTML