--- loncom/interface/lonnavmaps.pm 2002/03/15 23:39:41 1.31 +++ loncom/interface/lonnavmaps.pm 2002/03/16 08:56:53 1.32 @@ -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.32 2002/03/16 08:56:53 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,39 @@ 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 $newlinkid=$linkid; 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 +353,11 @@ 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; } + $newshowtypes='problems'; + $indent++; + $newlinkid=$rid; } if (defined($rows[$sofar])) { $rows[$sofar].='&'.$tprefix.$rid; @@ -352,20 +367,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,$newlinkid); + &addresource($hash{'src_'.$frid},\$sofar,$frid,$newshowtypes, + $indent,$newlinkid); + if ($tprefix =~ /j$/) { $indent--; } } } 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; @@ -473,7 +488,7 @@ sub handler { @rows=(); - &tracetable(0,$firstres,'&'.$lastres.'&'); + &tracetable(0,$firstres,'&'.$lastres.'&','',0); if ($hash{'src_'.$lastres}) { my $brepriv=&Apache::lonnet::allowed('bre',$hash{'src_'.$lastres}); if (($brepriv eq '2') || ($brepriv eq 'F')) { @@ -492,7 +507,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)); @@ -593,17 +608,21 @@ sub handler { my @colcont=split(/\&/,$rows[$i]); my $avespan=$lcm/($#colcont+1); for ($j=0;$j<=$#colcont;$j++) { + my $indent;my $indentstr; + my $linkid; my $rid=$colcont[$j]; - my $add='  '; + my $add=''; my $adde=''; my $hwk=''; my $hwke=''; + if ($rid=~/^l(\d+\.\d+),(.+)/) { $linkid=$1; $rid=$2; } + if ($rid=~/^i(\d+),(.+)/) { $indent=$1; $rid=$2; } if ($rid=~/^h(.+)/) { $rid=$1; $add=''; $adde=''; } - if ($rid=~/^i(.+)/) { $rid=$1; } + if ($rid=~/^j(.+)/) { $rid=$1; } if ($rid=~/^p(\d)(\d)\"([\w\: \(\)\/\,]*)\"(.+)/) { # sub astatus describes what code/tcode mean my $code=$1; @@ -679,8 +698,13 @@ sub handler { } } } - $r->print($add.''.$hwk. + if ($indent) { + my $is="  "; + for(my $i=-1;$i<$indent;$i++) { $indentstr.=$is; } + } + if (!$linkid) { $linkid=$rid; } + $r->print($add.$indentstr. + ''.$hwk. $hash{'title_'.$rid}.$hwke.''.$adde); } $r->print('');