--- loncom/interface/lonnavmaps.pm 2003/02/27 02:45:32 1.147
+++ loncom/interface/lonnavmaps.pm 2003/03/21 22:41:12 1.165
@@ -2,7 +2,7 @@
# The LearningOnline Network with CAPA
# Navigate Maps Handler
#
-# $Id: lonnavmaps.pm,v 1.147 2003/02/27 02:45:32 bowersj2 Exp $
+# $Id: lonnavmaps.pm,v 1.165 2003/03/21 22:41:12 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -38,16 +38,21 @@
# YEAR=2002
# 1/1 Gerd Kortemeyer
# Oct-Nov Jeremy Bowers
+# YEAR=2003
+# Jeremy Bowers ... lots of days
package Apache::lonnavmaps;
+use vars qw($test @refsToUntie);
use strict;
use Apache::Constants qw(:common :http);
use Apache::loncommon();
+use Apache::lonmenu();
use POSIX qw (floor strftime);
my %navmaphash;
my %parmhash;
+@refsToUntie;
# symbolic constants
sub SYMB { return 1; }
@@ -95,8 +100,12 @@ my %colormap =
# And a special case in the nav map; what to do when the assignment
# is not yet done and due in less then 24 hours
my $hurryUpColor = "#FF0000";
-
+$test = 'abc';
sub cleanup {
+ &Apache::lonnet::logthis("Cleanup called.");
+ &Apache::lonnet::logthis("refs size".scalar(@refsToUntie));
+ &Apache::lonnet::logthis("test is ".$test);
+ $test = '467';
if (tied(%navmaphash)){
&Apache::lonnet::logthis('Cleanup navmaps: navmaphash');
unless (untie(%navmaphash)) {
@@ -109,6 +118,14 @@ sub cleanup {
&Apache::lonnet::logthis('Failed cleanup navmaps: parmhash');
}
}
+ # Apparently, if you take a reference to a tied hash, both the
+ # original hash and the tied hash must be untied. Bleh.
+ for my $ref (@refsToUntie) {
+ &Apache::lonnet::logthis('Cleanup navmaps: reference');
+ unless (untie($ref)) {
+ &Apache::lonnet::logthis('Failed cleanup navmaps: reference');
+ }
+ }
}
sub handler {
@@ -140,7 +157,7 @@ sub real_handler {
$r->send_http_header;
# Create the nav map
- my $navmap = Apache::lonnavmaps::navmap->new(
+ my $navmap = Apache::lonnavmaps::navmap->new($r,
$ENV{"request.course.fn"}.".db",
$ENV{"request.course.fn"}."_parms.db", 1, 1);
@@ -152,11 +169,22 @@ sub real_handler {
}
$r->print("
\n");
- $r->print("Navigate Course Contents");
+ $r->print("Navigate Course Contents");
+# ------------------------------------------------------------ Get query string
+ &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['register']);
+
+# ----------------------------------------------------- Force menu registration
+ my $addentries='';
+ if ($ENV{'form.register'}) {
+ $addentries=' onLoad="'.&Apache::lonmenu::loadevents().
+ '" onUnload="'.&Apache::lonmenu::unloadevents().'"';
+ $r->print(&Apache::lonmenu::registerurl(1));
+ }
# Header
- $r->print(&Apache::loncommon::bodytag('Navigate Course Contents','',
- ''));
+ $r->print(''.
+ &Apache::loncommon::bodytag('Navigate Course Contents','',
+ $addentries,'','',$ENV{'form.register'}));
$r->print('');
$r->rflush();
@@ -164,7 +192,6 @@ sub real_handler {
# Now that we've displayed some stuff to the user, init the navmap
$navmap->init();
-
$r->print('
');
$r->rflush();
@@ -175,13 +202,51 @@ sub real_handler {
return OK;
}
+ # See if there's only one map in the top-level... if so,
+ # automatically display it
+ my $iterator = $navmap->getIterator(undef, undef, undef, 0);
+ my $depth = 1;
+ $iterator->next();
+ my $curRes = $iterator->next();
+ my $sequenceCount = 0;
+ my $sequenceId;
+ while ($depth > 0) {
+ if ($curRes == $iterator->BEGIN_MAP()) { $depth++; }
+ if ($curRes == $iterator->END_MAP()) { $depth--; }
+
+ if (ref($curRes) && $curRes->is_sequence()) {
+ $sequenceCount++;
+ $sequenceId = $curRes->map_pc();
+ }
+
+ $curRes = $iterator->next();
+ }
+
+ if ($sequenceCount == 1) {
+ # The automatic iterator creation in the render call
+ # will pick this up.
+ $ENV{'form.filter'} = "$sequenceId";
+ }
+
# renderer call
my $render = render({ 'cols' => [0,1,2,3],
'url' => '/adm/navmaps',
- 'printKey' => 1,
+ 'suppressNavmap' => 1,
'r' => $r});
- $navmap->untieHashes();
+ #$navmap->untieHashes();
+
+ if (tied(%navmaphash)) {
+ $r->print("Dang it.");
+ } else {
+ $r->print("It's out.");
+ }
+
+ if (tied(%parmhash)) {
+ $r->print("Dang it.");
+ } else {
+ $r->print("It's out.");
+ }
$r->print("