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

<script language="JavaScript">
function getValue(){
    for(a=0; a< document.formu.length; a++){
        if(document.formu[a].checked==true){
			obj=document.formu[a];
            return obj.value;
        

    }
		
}        
}    
</script>

<form action="" method="get" name="formu">

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

	
	$requete= "SELECT \"NAME\", \"SPECIES\" FROM \"DEV_STAGE\" WHERE \"DEV_STAGE_ID\"= $dev";
    $stmt = pg_query($c,$requete);
    if( $row=pg_fetch_array($stmt)){
	
        print "<center><h2><strong><em>".$row["SPECIES"]."  (".$row["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 "&nbsp;&nbsp;<a href=\"anatomy.php?region=$region&dev=$dev#tag\"><img src=\"pictures/button-whole-tree.jpg\" border=\"0\"></a><br><br>";

/*
	    $requete= "SELECT NAME, LEVEL, ANAT_ID, TYPE, CHILD_OF FROM CIONA_DESIGN.ANAT_ENTITY  WHERE DEV_STAGE_ID= $dev  CONNECT BY ANAT_ID = PRIOR CHILD_OF START WITH ANAT_ID=$region ORDER BY LEVEL DESC";*/
        


	/* SIMULATION D'UNE REQUETE SUR HIERARCHIE PAR UNE PROCEDURE DE REQUETES RECURSIVES */

/* VARIANTE DANS LA REQUETE POUR LA CONNEXION ET LE RESULTAT DU SELECT */
$count=0;

function select_recursif_descendant($conn,$start,$res)
{
global $dev;
global $count;
/*ON ECRIT SA REQUETE*/

if ($start!='')
{
$requete="SELECT * FROM \"ANAT_ENTITY\" WHERE  \"DEV_STAGE_ID\"= ".$dev." and  \"ANAT_ID\"= $start ";
//$res=select_recursif_descendant($conn,$row["CHILD_OF"],$res);
}
else return;

$stmt=pg_query($conn,$requete);
while ($row=pg_fetch_array($stmt))
	{
	$res=select_recursif_descendant($conn,$row["CHILD_OF"],$res);
        ++$count;
//print "ici";
	        for($a=0;$a<$count-1;++$a){
		        echo '&nbsp;&nbsp;&nbsp;&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\">";
			
		
		    if($row["ANAT_ID"]==$region){
	  	        echo '<A NAME="tag"><font color="#FF9900"><strong>'.$row["NAME"]."</strong></font></A>"."<input name=\"region\" type=\"radio\" value=\"".$row["ANAT_ID"]."\" checked>";
		    }else{echo $row["NAME"]."<input name=\"region\" type=\"radio\" value=\"".$row["ANAT_ID"]."\">";}
		
		
		    print '<br>';

	

	//$res=select_recursif_descendant($conn,$row["CHILD_OF"],$res);
	}
return $res;
}

$res=select_recursif_descendant($c,$region,$res);



/* FIN DE LA SIMULATION */





////////////////////Recherche des enfants////////////////////////////////

	/* SIMULATION D'UNE REQUETE SUR HIERARCHIE PAR UNE PROCEDURE DE REQUETES RECURSIVES */

/* VARIANTE DANS LA REQUETE POUR LA CONNEXION ET LE RESULTAT DU SELECT */
//$level=0;


function select_recursif_descendant_2($conn,$start,$res)
{
global $dev;
global $count;
global $level;
/*ON ECRIT SA REQUETE*/
//print "la";
if ($start!='')
{
$requete="SELECT * FROM \"ANAT_ENTITY\" WHERE  \"DEV_STAGE_ID\"= ".$dev." and  \"CHILD_OF\"= $start ";
//$res=select_recursif_descendant_2($conn,$row["ANAT_ID"],$res);
//$level++;
}
else return;

$stmt=pg_query($conn,$requete);
while ($row=pg_fetch_array($stmt))
	{
$res=select_recursif_descendant_2($conn,$row["ANAT_ID"],$res);
	        for($a=0;$a<$count-1;++$a){
		        echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
		    }
		    echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
	        for($a=0;$a<$level-1;++$a){
		        if( $level>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"];
		    print "<input name=\"region\" type=\"radio\" value=\"".$row["ANAT_ID"]."\"><br>";
			
	

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

$res=select_recursif_descendant_2($c,$region,$res);



/* FIN DE LA SIMULATION */



	
        print "</form>";
	

        print "\n<br><br>&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()\"><br><br>";
	
	}else{ print "<br><br><center><h2><strong>No match</strong></h2></center><br><br>"; }
?>
<br>



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