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


<?php
$region = $_GET["region"];
$dev = $_GET["dev"];


if( (strlen($dev)<=0)or(ereg("___",$dev)) )
{
	print "<center><h2><strong>No match</strong></h2><br>please select a developmental stage</center>";
	include("frames_footer.php");
	return;
}
	
	

	

$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) )
{
	$species=$row["SPECIES"];
	$nomstade=$row["NAME"];
	$stadedev=$dev;
	
	print "<center><h2><strong><em>".$row["SPECIES"]."  (".$row["NAME"].")<br>Anatomical tree</em></strong> </h2></center><br><br>";
	echo "<TABLE>";
/*HIERACHIE*/


$nivo=0;
function select_recursif_descendant_2($conn,$start,$res,$nivo)
{
global $dev;
global $type;
global $species;
global $nomstade;
global $stadedev;
//global $level;

//global $nivo;
/*ON ECRIT SA REQUETE*/

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


$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))
	{
		echo"<tr><td>";
		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\">";
			
			$type=$row["TYPE"];
			echo " - ".$row["ANAT_ID"]." __&nbsp;&nbsp; ";
			echo $row["NAME"];
			echo "</td><td>";
			if ($row["NAME"]!="No expression")
			{
			   echo'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="addpartanat.php?name='.$row["NAME"].'&anatid='.$row["ANAT_ID"].'&type='.$type.'&species='.$species.'&nomstade='.$nomstade.'&stadedev='.$stadedev.'&childof='.$row["CHILD_OF"].'" target="_blank">ADD</a></TD>';
			   echo'<TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="deletepartanat.php?name='.$row["NAME"].'&anatid='.$row["ANAT_ID"].'&type='.$type.'&species='.$species.'&nomstade='.$nomstade.'&stadedev='.$stadedev.'&childof='.$row["CHILD_OF"].'" target="_blank">DELETE</a></TD>';
			   echo'<TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="renamepartanat.php?name='.$row["NAME"].'&anatid='.$row["ANAT_ID"].'&type='.$type.'&species='.$species.'&nomstade='.$nomstade.'&stadedev='.$stadedev.'&childof='.$row["CHILD_OF"].'" target="_blank">EDIT</a></TD></tr>';
			}
		}
		else
		{ 
			if( $row["TYPE"]=='organism' )
			{
			   
			      $type=$row["TYPE"];
				print "<img src=\"pictures/tetard.gif\">";
				echo " - ".$row["ANAT_ID"]." __&nbsp;&nbsp; ";
				echo $row["NAME"];
				echo "</td><td>";
                        if ($row["NAME"]!="No expression")
                        {
                              echo'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="addpartanat.php?name='.$row["NAME"].'&anatid='.$row["ANAT_ID"].'&type='.$type.'&species='.$species.'&nomstade='.$nomstade.'&stadedev='.$stadedev.'&childof='.$row["CHILD_OF"].'" target="_blank">ADD</a></TD>';
		//	            echo'<TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="deletepartanat.php?name='.OCIResult($stmt, "NAME").'&anatid='.OCIResult($stmt, "ANAT_ID").'&type='.$type.'&species='.$species.'&nomstade='.$nomstade.'&stadedev='.$stadedev.'&childof='.OCIResult($stmt, "CHILD_OF").'" target="_blank">DELETE</a></TD>';
                              echo'<TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="renamepartanat.php?name='.$row["NAME"].'&anatid='.$row["ANAT_ID"].'&type='.$type.'&species='.$species.'&nomstade='.$nomstade.'&stadedev='.$stadedev.'&childof='.$row["CHILD_OF"].'" target="_blank">EDIT</a></TD></tr>';
		    	      }
			}
			else
			{
				print "<img src=\"pictures/region.gif\">";
				
				$type=$row["TYPE"];
				echo " - ".$row["ANAT_ID"]." __&nbsp;&nbsp; ";
				echo $row["NAME"];
				echo "</td><td>";
				if ($row["NAME"]!="No expression")
                        {
				        echo'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="addpartanat.php?name='.$row["NAME"].'&anatid='.$row["ANAT_ID"].'&type='.$type.'&species='.$species.'&nomstade='.$nomstade.'&stadedev='.$stadedev.'&childof='.$row["CHILD_OF"].'" target="_blank">ADD</a></TD>';
				        echo'<TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="deletepartanat.php?name='.$row["NAME"].'&anatid='.$row["ANAT_ID"].'&type='.$type.'&species='.$species.'&nomstade='.$nomstade.'&stadedev='.$stadedev.'&childof='.$row["CHILD_OF"].'" target="_blank">DELETE</a></TD>';
				        echo'<TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="renamepartanat.php?name='.$row["NAME"].'&anatid='.$row["ANAT_ID"].'&type='.$type.'&species='.$species.'&nomstade='.$nomstade.'&stadedev='.$stadedev.'&childof='.$row["CHILD_OF"].'" target="_blank">EDIT</a></TD></tr>';
				}
			}
		}	



	$res=select_recursif_descendant_2($conn,$row["ANAT_ID"],$res,$nivo);
	
	}

return $res;
}


	select_recursif_descendant_2($c,null,$res,$nivo);
	
        echo"</table>";
	
}
else
{ 
	print "<br><br><center><h2><strong>No match</strong></h2></center><br><br>"; 
}
?>





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

