--- loncom/interface/lonnavmaps.pm 2003/01/10 17:46:46 1.123 +++ 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.123 2003/01/10 17:46:46 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); @@ -96,6 +114,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 +201,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.' . @@ -600,7 +620,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 . @@ -620,7 +640,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 @@ -672,10 +704,10 @@ sub real_handler { $r->print(''); } - $r->print(""); - $navmap->untieHashes(); + $r->print(""); + return OK; } @@ -971,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))) { @@ -985,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; } @@ -1060,7 +1091,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); @@ -1141,18 +1172,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 { @@ -1164,6 +1196,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. @@ -1655,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(); } @@ -2229,7 +2270,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 @@ -2585,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; } @@ -2608,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
Key:  $discussionHTML$feedbackHTML $discussionHTML$feedbackHTML$errorHTML