<?php
	//connection
	include("connection.php");
    include("frames_header.php");
?>


<form action="lineage3.php" method="post" name="formu" target="_blank">

<?php


	$devstage="";
    if(isset($_POST["devstage"]))
		$devstage = $_POST["devstage"];
	
	
	if( count($devstage)<=1 ){
	    print "<center><h2></h2><br>Please select at least 2 developmental stages</center>";
		include("frames_footer.php");
	    return;
	}
    
	print '&nbsp;&nbsp;&nbsp;<input name="submit" type="image" src="pictures/button-submit.jpg" onClick="submit">';
//	print '&nbsp;&nbsp;&nbsp;<input name="submit" type="image" src="pictures/button-reset.jpg" onClick="javascript: window.location.reload()">';
	print '<table border="1" cellspacing="0" cellpadding="0"><tr>';
	
/*BOF SIMULATION*/

$nivo=0;
function select_recursif_descendant_2($conn,$start,$res,$nivo)
{
global $dev;
//global $level;
global $region;
global $fkw;
global $fates;
global $i;
//global $nivo;
/*ON ECRIT SA REQUETE*/

//print "la";
if ($start!='')
{
$requete="SELECT * FROM \"ANAT_ENTITY\" WHERE  \"DEV_STAGE_ID\"= ".$dev." and  \"CHILD_OF\"= $start ";
//print $start;
$level++;
}
else {
$requete="SELECT * FROM \"ANAT_ENTITY\" WHERE  \"DEV_STAGE_ID\"= ".$dev." and  \"CHILD_OF\" is null";
//$level=0;
}

$stmt=pg_query($conn,$requete) or die("<strong>Error</strong> ".pg_last_error($c));

//if (pg_num_rows($stmt2)==0) {$level--;}

if (pg_num_rows($stmt)!=0) $nivo++;//print "Nz";
if (pg_num_rows($stmt)==0) $nivo--;//print "Ze";

while($row=pg_fetch_array($stmt))
	{

			for($a=0;$a<$nivo-1;++$a){
				if( $nivo>1 )
					echo '&nbsp;&nbsp;<font color="#999999">|</font>&nbsp;&nbsp;';
			}
			
			if( $row["TYPE"]=='cell' )
				print "<img src=\"pictures/cell.gif\">";
			else if( $row["TYPE"]=='organism' )
				print "<img src=\"pictures/tetard.gif\">";
			else
				print "<img src=\"pictures/region.gif\">";
			


			echo $row["NAME"];
			//if((strlen($region)>0)){
			//	print "<input name=\"region\" type=\"radio\" value=\"".OCIResult($stmt, "ANAT_ID")."\">";
			//}else{
				print "<input name=\"region".$i."\" type=\"radio\" value=\"".$row["ANAT_ID"]."\">";
				//if(OCIResult($stmt, "LEVEL")==1)
				//	print "checked ";
				//print ">";//."<strong>".OCIResult($stmt, "ANAT_ID")."</strong>";
			//}



			print '<br>';
	$res=select_recursif_descendant_2($conn,$row["ANAT_ID"],$res,$nivo);

	
	}

return $res;
}



	
for($i=0; $i<count($devstage); ++$i){
	$dev=$devstage[count($devstage)-$i-1];
	print '<td valign="top">';

	$requete= "SELECT \"NAME\", \"SPECIES\" FROM \"DEV_STAGE\" WHERE \"DEV_STAGE_ID\"= $dev";
    $stmt = pg_query($c,$requete) or die("<strong>Error</strong> ".pg_last_error($c));
    if( $row=pg_fetch_array($stmt) ){
//		print "<center><h2><strong><em>".OCIResult($stmt, "SPECIES")."  (".OCIResult($stmt, "NAME").")<br>Anatomical tree</em></strong> </h2></center><br><br>";
//	    print "Select anatomical part below and click on buttons to access the relevant information.<br>";
//		print "\n&nbsp;&nbsp;<img src=\"pictures/button-getPics.jpg\" border=\"0\" onClick=\"self.location.href = 'insitu-result.php?BOOLanat=1&xref=2&idanat=' + self.getValue()+':'\">    &nbsp;<img src=\"pictures/button-lineage.jpg\" border=\"0\"onClick=\"self.location.href = 'lineage.php?idanat=' + self.getValue()\">    &nbsp;<img src=\"pictures/button-position.jpg\" border=\"0\" onClick=\"self.location.href = 'position.php?idanat=' + self.getValue()\">    &nbsp;<img src=\"pictures/button-fates.jpg\" border=\"0\" onClick=\"self.location.href = 'fates.php?idanat=' + self.getValue()\">\n<br><br><br>";		
	    print "<center>".$row["SPECIES"]."</center>";
	    print "&nbsp;<center><strong>".$row["NAME"]."</strong></center><br>";
		print '<center>___________________________________</center><br>';

	select_recursif_descendant_2($c,null,$res,$nivo);		

		print "</td>";
	
	}else{ print "<br><br><center><h2><strong>No match</strong></h2></center><br><br>"; }
	
}
	
	print "</tr></table>";
	print '<input type="hidden" name="count" value="'.$i.'">';
    print '<br>&nbsp;&nbsp;&nbsp;<input name="submit" type="image" src="pictures/button-submit.jpg" onClick="submit">';
?>
</form>




<?php
    include("frames_footer.php");
?>