--- loncom/interface/lonnavmaps.pm 2002/03/15 23:39:41 1.31
+++ loncom/interface/lonnavmaps.pm 2002/09/03 01:23:35 1.41.2.1
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Navigate Maps Handler
#
-# $Id: lonnavmaps.pm,v 1.31 2002/03/15 23:39:41 albertel Exp $
+# $Id: lonnavmaps.pm,v 1.41.2.1 2002/09/03 01:23:35 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -270,13 +270,11 @@ sub astatus {
sub addresource {
- my ($resource,$sofar,$rid,$showtypes)=@_;
- &Apache::lonxml::debug("Adding $resource allowing $showtypes");
+ my ($resource,$sofar,$rid,$showtypes,$indent,$linkid)=@_;
if ($showtypes eq 'problems') {
if ($resource!~/\.(problem|exam|quiz|assess|survey|form)$/) {
- &Apache::lonxml::debug("Returning early");
return;
- }
+ }
}
my $brepriv=&Apache::lonnet::allowed('bre',$resource);
if ($hash{'src_'.$rid}) {
@@ -285,17 +283,20 @@ sub addresource {
if ($resource=~/\.(problem|exam|quiz|assess|survey|form)$/) {
$pprefix=&astatus($rid);
}
- if (defined($rows[$sofar])) {
- $rows[$sofar].='&'.$pprefix.$rid;
+ $$sofar++;
+ if ($indent) { $pprefix='i'.$indent.','.$pprefix; }
+ if ($linkid) { $pprefix='l'.$linkid.','.$pprefix; }
+ if (defined($rows[$$sofar])) {
+ $rows[$$sofar].='&'.$pprefix.$rid;
} else {
- $rows[$sofar]=$pprefix.$rid;
+ $rows[$$sofar]=$pprefix.$rid;
}
}
}
}
sub followlinks () {
- my ($rid,$sofar,$beenhere,$further,$showtypes)=@_;
+ my ($rid,$sofar,$beenhere,$further,$showtypes,$indent,$linkid)=@_;
my $mincond=1;
my $next='';
foreach (split(/\,/,$hash{'to_'.$rid})) {
@@ -310,28 +311,38 @@ sub followlinks () {
if ($thiscond>$mincond) { $mincond=$thiscond; }
}
}
+ my $col=0;
+ &Apache::lonxml::debug("following links -$next-");
foreach (split(/\,/,$next)) {
- my ($linkid,$condval)=split(/\:/,$_);
+ my ($nextlinkid,$condval)=split(/\:/,$_);
if ($condval>=$mincond) {
- &Apache::lonxml::debug("following link $linkid");
- my $now=&tracetable($sofar,$hash{'goesto_'.$linkid},
- $beenhere,$showtypes);
- if ($now>$further) { $further=$now; }
+ my $now=&tracetable($sofar,$hash{'goesto_'.$nextlinkid},
+ $beenhere,$showtypes,$indent,$linkid);
+ if ($now>$further) {
+ if ($col>0) {
+ my $string;
+ for(my $i=0;$i<$col;$i++) { $string.='&'; }
+ for(my $i=$further+1;$now-1>$i;$i++) {
+ $rows[$i]=$string.$rows[$i];
+ }
+ }
+ $further=$now;
+ }
}
+ $col++;
}
return $further;
}
# ------------------------------------------------------------ Build page table
sub tracetable {
- my ($sofar,$rid,$beenhere,$showtypes)=@_;
+ my ($sofar,$rid,$beenhere,$showtypes,$indent,$linkid)=@_;
+ my $newshowtypes=$showtypes;
my $further=$sofar;
#$Apache::lonxml::debug=1;
- &Apache::lonxml::debug("$rid ; $sofar ; $beenhere");
- if ($beenhere=~/\&$rid\&/) {
- return $further;
- }
- $beenhere.=$rid.'&';
+ &Apache::lonxml::debug("$rid ; $linkid ; $sofar ; $beenhere ; ".$hash{'src_'.$rid});
+ if ($beenhere=~/\&$rid\&/) { return $further; }
+ $beenhere.=$rid.'&';
if (defined($hash{'is_map_'.$rid})) {
$sofar++;
@@ -341,8 +352,13 @@ sub tracetable {
$tprefix='h';
} elsif ($hash{'map_type_'.$hash{'map_pc_'.$hash{'src_'.$rid}}}
eq 'page') {
- $tprefix='i';
- $showtypes='problems';
+ $tprefix='j';
+ if ($indent) { $tprefix='i'.$indent.','.$tprefix; }
+ if ($linkid) { $tprefix='l'.$linkid.','.$tprefix; }
+ $newshowtypes='problems';
+ $indent++;
+ #if in a .page continue to link the encompising .page
+ if (!$linkid) { $linkid=$rid; }
}
if (defined($rows[$sofar])) {
$rows[$sofar].='&'.$tprefix.$rid;
@@ -352,20 +368,20 @@ sub tracetable {
if ((defined($hash{'map_start_'.$hash{'src_'.$rid}})) &&
(defined($hash{'map_finish_'.$hash{'src_'.$rid}}))) {
my $frid=$hash{'map_finish_'.$hash{'src_'.$rid}};
- $sofar=&tracetable($sofar,
- $hash{'map_start_'.$hash{'src_'.$rid}},
- '&'.$frid.'&',$showtypes);
- $sofar++;
- &addresource($hash{'src_'.$frid},$sofar,$frid,$showtypes);
- if ($tprefix eq 'i') { $showtypes=''; }
+ $sofar=&tracetable($sofar,$hash{'map_start_'.$hash{'src_'.$rid}},
+ '&'.$frid.'&',$newshowtypes,$indent,$linkid);
+ &addresource($hash{'src_'.$frid},\$sofar,$frid,$newshowtypes,
+ $indent,$linkid);
+ if ($tprefix =~ /j$/) { $indent--; $linkid=''; }
}
} else {
- $sofar++;
- &addresource($hash{'src_'.$rid},$sofar,$rid,$showtypes);
+ &addresource($hash{'src_'.$rid},\$sofar,$rid,$showtypes,
+ $indent,$linkid);
}
if (defined($hash{'to_'.$rid})) {
- $further=&followlinks($rid,$sofar,$beenhere,$further,$showtypes);
+ $further=&followlinks($rid,$sofar,$beenhere,$further,$showtypes,
+ $indent,$linkid);
}
return $further;
@@ -395,10 +411,10 @@ sub handler {
if ($ENV{'request.course.fn'}) {
$fn=$ENV{'request.course.fn'};
if (-e "$fn.db") {
- if ((tie(%hash,'GDBM_File',"$fn.db",&GDBM_READER,0640)) &&
+ if ((tie(%hash,'GDBM_File',"$fn.db",&GDBM_READER(),0640)) &&
(tie(%parmhash,'GDBM_File',
$ENV{'request.course.fn'}.'_parms.db',
- &GDBM_READER,0640))) {
+ &GDBM_READER(),0640))) {
$hashtied=1;
}
}
@@ -473,13 +489,7 @@ sub handler {
@rows=();
- &tracetable(0,$firstres,'&'.$lastres.'&');
- if ($hash{'src_'.$lastres}) {
- my $brepriv=&Apache::lonnet::allowed('bre',$hash{'src_'.$lastres});
- if (($brepriv eq '2') || ($brepriv eq 'F')) {
- $rows[$#rows+1]=''.$lastres;
- }
- }
+ &tracetable(0,$firstres,'&','',0);
# ------------------------------------------------------------------ Page parms
@@ -492,7 +502,7 @@ sub handler {
for ($i=0;$i<=$#rows;$i++) {
if ($rows[$i]) {
- &Apache::lonxml::debug($rows[$i]);
+ &Apache::lonxml::debug("Row $i is:".$rows[$i]);
$contents++;
my @colcont=split(/\&/,$rows[$i]);
$lcm*=($#colcont+1)/euclid($lcm,($#colcont+1));
@@ -559,8 +569,10 @@ sub handler {
}
$r->print('>'.
''.
- '