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

<h2><strong><em>Competence description.</em></strong> </h2><br>
<center>
<form action="competence3.php" method="post" name="formu" target="_blank">

<?php


	$dev="";
    if(isset($_POST["devstage"]))
		$dev = $_POST["devstage"];
	
	
	if( strlen($dev)<=0 ){
	    print "<center><h2></h2><br>Please select a developmental stage</center>";
		include("frames_footer.php");
	    return;
	}
    


	print '<table border="1" cellspacing="0" cellpadding="0"><tr>';
	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"]."&nbsp;-&nbsp;".$row["NAME"]."</center><br>";
			
		print '<center>___________________________________</center><br>';

/*SIMULATION BOF*/
$nivo=0;
function select_recursif_descendant_2($conn,$start,$res,$nivo)
{
global $dev;

/*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"];
			print "<input name=\"region\" type=\"radio\" value=\"".$row["ANAT_ID"]."\">";

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

	
	}

return $res;
}




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 '<td align="center" valign="top" colspan="2">';
		
		$flist="";
		$requete2="select \"KEYWORDS\" from \"FATE_KW\"";
		$stmt = pg_query($c,$requete2) or die("<strong>Error</strong> ".pg_last_error($c));
		while($row=pg_fetch_array($stmt)){
		    $flist .= '<option>'.$row["KEYWORDS"].'</option>';
		}
		print '<br><strong>Competence</strong><br>________________________<br> <select name="comp[]" size="20" multiple>'.$flist.'</select>';
        print '<br><input name="submit" type="image" src="pictures/button-submit.jpg" onClick="submit">';

		print '</td></tr></table>';

?>
</form>
</center>



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