[LON-CAPA-cvs] cvs: loncom /interface lonnavmaps.pm

albertel lon-capa-cvs@mail.lon-capa.org
Sat, 16 Mar 2002 08:56:53 -0000


albertel		Sat Mar 16 03:56:53 2002 EDT

  Modified files:              
    /loncom/interface	lonnavmaps.pm 
  Log:
  - .pages now show embedded resources if they are problems,
    - the link on the resource goes to the .page
    - the resources inside a .page are indented
    - .pages inside .pages indent more
  
  
Index: loncom/interface/lonnavmaps.pm
diff -u loncom/interface/lonnavmaps.pm:1.31 loncom/interface/lonnavmaps.pm:1.32
--- loncom/interface/lonnavmaps.pm:1.31	Fri Mar 15 18:39:41 2002
+++ loncom/interface/lonnavmaps.pm	Sat Mar 16 03:56:53 2002
@@ -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 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 @@
 	    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 @@
 	    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 @@
 	    $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 @@
 	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 @@
 
 	@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 @@
 
 	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 @@
 		    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='<td>&nbsp;&nbsp;';
+			my $add='<td>';
 			my $adde='</td>';
 			my $hwk='<font color="#223322">';
 			my $hwke='</font>';
+			if ($rid=~/^l(\d+\.\d+),(.+)/) { $linkid=$1; $rid=$2; }
+			if ($rid=~/^i(\d+),(.+)/) { $indent=$1; $rid=$2; }
 			if ($rid=~/^h(.+)/) {
 			    $rid=$1;
 			    $add='<th bgcolor="#AAFF55"><a name="'.$rid.'">';
 			    $adde='</th>';
 			}
-			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 @@
 				}
 			    }
 			}
-			$r->print($add.'<a href="'.$hash{'src_'.$rid}.
-				  '">'.$hwk.
+			if ($indent) {
+			    my $is="&nbsp;&nbsp;";
+			    for(my $i=-1;$i<$indent;$i++) { $indentstr.=$is; }
+			}
+			if (!$linkid) { $linkid=$rid; }
+			$r->print($add.$indentstr.
+				  '<a href="'.$hash{'src_'.$linkid}.'">'.$hwk.
 				  $hash{'title_'.$rid}.$hwke.'</a>'.$adde);
 		    }
 		    $r->print('</tr>');