<?php
/*
    ANISEED, NISEED System and Database
    Copyright (C) 2007 Olivier Tassy, Fabrice Daian, Patrick Lemaire

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.

*/
    include("connection.php");
//Title before frames_header
print '<title>ANISEED v3.0 - Position </title>';

    include("frames_header.php");
?>

<?php
    $id=$_GET["idanat"];
	
	if(! is_numeric($id)){
	    Print "Error: missing parameter";
		include("frames_footer.php");
		return;
	}

	$requete="SELECT \"DEV_STAGE_ID\",\"SPECIES\" from \"ANAT_ENTITY\" where \"ANAT_ID\"='$id'";
	$stmt=pg_query($c,$requete);
	$row=pg_fetch_array($stmt);
	$species=$row["SPECIES"];
	$stage=$row["DEV_STAGE_ID"]


	
?>
  <link rel="stylesheet" type="text/css" media="screen" href="ongletv1.css" title="Version 1" />
<!-- Header pour l'onglet -->
<div id="header">
  <ul>
    <li><a href="anatomy.php?species=<?print $species;?>&dev=<?print $stage;?>&region=<?print $id;?>">Anatomical dictionary</a></li>
    <li><a onclick="this.href='short_hierarchy.php?region=<? print $id;?>&dev=<?print $stage;?>'" href="">Anatomical territory summary card</a></li>
    <li><a onclick="this.href='insitu-result.php?BOOLanat=1&xref=2&idanat=<?print $id;?>:'" href="">In situ</a></li>
    <li><a href="fates.php?idanat=<?print $id;?>">Fate</a></li>

    <li><a href="lineage.php?idanat=<?print $id?>">Lineage</a></li>

    <!--<li><a onclick="this.href='insitu-result.php?BOOLanat=1&xref=2&idanat=<?print $id;?>:'" href="#">InSitu data</a></li>-->

    <li id="current"><a href="">Biometry</a></li>
    <li><a href="induction.php?idanat=<?print $id?>">Induction</a></li>

  </ul>
</div>
<!-- EOF Onglet -->
<br><br>

<?
    $dev="";

print "<center>";	
	
	$requete="select B.\"NAME\" as \"DEV\", A.\"NAME\", A.\"DEV_STAGE_ID\" from \"ANAT_ENTITY\" A, \"DEV_STAGE\" B where A.\"ANAT_ID\"='$id' and A.\"DEV_STAGE_ID\"=B.\"DEV_STAGE_ID\"";
    $stmt = pg_query($c,$requete);
	if ($row=pg_fetch_array($stmt)){
	    $dev=$row["DEV_STAGE_ID"];
	    print "<br><br><font color=\"#D64242\" size=\"3\"><b>".$row["NAME"]." &nbsp;(".$row["DEV"].")</b></font><br>";
	}
	

//////////////////////////////////////Vol & surface/////////////////////////////////////////////////
	print '<table width="80%" border="0" cellspacing="0" cellpadding="0">';
	print '<tr align="center"><td><font color="#456898" size="2"><b>Volume(&micro;3)</b></font></td><td><font color="#456898" size="2"><b>Surface(&micro;2)</b></font></td></tr>';
	$requete="select \"VOLUME\", \"SURFACE\" from \"BIOMETRY\" where \"CELL\"='$id'";
    $stmt = pg_query($c,$requete);
	$count=0;
	if ($row=pg_fetch_array($stmt)){
	    print "<tr align=\"center\"><td><font color=\"#656565\" size=\"-1\">".$row["VOLUME"]."</font></td><td><font color=\"#656565\" size=\"-1\">".$row["SURFACE"]."</font></td></tr>";
	     print "<tr align=\"center\"><td><hr size=\"1\"></td><td><hr size=\"1\"></td></tr>";
		++$count;
	}
	print '</table>';
	if($count==0)
	    print "<font color=\"#D64242\" size=\"2\"><b>No match</b></font>";
///////////////////////////////////////////////////////////////////////////////////////	
	
	
////////////////////////////////Shape descriptors//////////////////////////////////////
	print '<br><br><table width="80%" border="0" cellspacing="0" cellpadding="0">';
    print '<tr><td>&nbsp;</td><td><font color="#456898" size="2"><b>Shape descriptors</b></font></td></tr>';
	print '<tr><td>&nbsp;</td><td>&nbsp;</td></tr>';
	$requete="select * from \"BIOMETRY_SHAPE\" where \"CELL\"='$id'";
    $stmt = pg_query($c,$requete);
	$count=0;
	while ($row=pg_fetch_array($stmt)){
	    ++$count;
		
		$av=$row["AV"];
		
		
		$val=$row["ENTROPY"];
		print "<tr><td><font color=\"#656565\" size=\"-1\">Entropy: </font></td><td>";
		for($l=0; $l<=$val; ++$l)
			print '<img src="pictures/stat1.jpg">';
		for($l=0; $l<=(100-$val); ++$l)
			print '<img src="pictures/stat0.jpg">';
		print "&nbsp;&nbsp;<font color=\"#656565\" size=\"-1\">$val%</font></td></tr>";
		
		$val=$row["OCCUPENCY"];
		print "<tr><td><font color=\"#656565\" size=\"-1\">Squarness: </font></td><td>";
		for($l=0; $l<=$val; ++$l)
			print '<img src="pictures/stat1.jpg">';
		for($l=0; $l<=(100-$val); ++$l)
			print '<img src="pictures/stat0.jpg">';
		print "&nbsp;&nbsp;<font color=\"#656565\" size=\"-1\">$val%</font></td></tr>";
		
		$val=$row["SPHERICITY"];
		print "<tr><td><font color=\"#656565\" size=\"-1\">Sphericity: </font></td><td>";
		for($l=0; $l<=$val; ++$l)
			print '<img src="pictures/stat1.jpg">';
		for($l=0; $l<=(100-$val); ++$l)
			print '<img src="pictures/stat0.jpg">';
		print "&nbsp;&nbsp;<font color=\"#656565\" size=\"-1\">$val%</font></td></tr>";
		/*
		$val=$row["CYLINDRICITY"];
		print "<tr><td>Cylindricity: </td><td>";
		for($l=0; $l<=$val; ++$l)
			print '<img src="pictures/stat1.jpg">';
		for($l=0; $l<=(100-$val); ++$l)
			print '<img src="pictures/stat0.jpg">';
		print "&nbsp;&nbsp;$val%</td></tr>";
		*/
		$val=$row["ELONGATION"];
		print "<tr><td><font color=\"#656565\" size=\"-1\">Elongation: </font></td><td>";
		for($l=0; $l<=$val; ++$l)
			print '<img src="pictures/stat1.jpg">';
		for($l=0; $l<=(100-$val); ++$l)
			print '<img src="pictures/stat0.jpg">';
		print "&nbsp;&nbsp;<font color=\"#656565\" size=\"-1\">$val%</font></td></tr>";
		
		$val=$row["FLATNESS"];
		print "<tr><td><font color=\"#656565\" size=\"-1\">Flatness: </font></td><td>";
		for($l=0; $l<=$val; ++$l)
			print '<img src="pictures/stat1.jpg">';
		for($l=0; $l<=(100-$val); ++$l)
			print '<img src="pictures/stat0.jpg">';
		print "&nbsp;&nbsp;<font color=\"#656565\" size=\"-1\">$val%</font></td></tr>";
		/*
		$val=$row["COMPLEXITY"];
		print "<tr><td>Complexity: </td><td>";
		for($l=0; $l<=$val; ++$l)
			print '<img src="pictures/stat1.jpg">';
		for($l=0; $l<=(100-$val); ++$l)
			print '<img src="pictures/stat0.jpg">';
		print "&nbsp;&nbsp;$val%</td></tr>";
		*/
		$val=$row["SV"];
		print "<tr><td><font color=\"#656565\" size=\"-1\">Surface/Volume: </font></td><td>";
		for($l=0; $l<=$val; ++$l)
			print '<img src="pictures/stat1.jpg">';
		for($l=0; $l<=(100-$val); ++$l)
			print '<img src="pictures/stat0.jpg">';
		print "&nbsp;&nbsp;<font color=\"#656565\" size=\"-1\">$val%</font></td></tr>";


		$val=$row["CONVEXITY"];
		print "<tr><td><font color=\"#656565\" size=\"-1\">Convexity: </font></td><td>";
		for($l=0; $l<=$val; ++$l)
			print '<img src="pictures/stat1.jpg">';
		for($l=0; $l<=(100-$val); ++$l)
			print '<img src="pictures/stat0.jpg">';
		print "&nbsp;&nbsp;<font color=\"#656565\" size=\"-1\">$val%</font></td></tr>";


		$val=$row["VV"];
		print "<tr><td><font color=\"#656565\" size=\"-1\">Cell Volume/Embryo volume </font></td><td>";
		for($l=0; $l<=$val; ++$l)
			print '<img src="pictures/stat1.jpg">';
		for($l=0; $l<=(100-$val); ++$l)
			print '<img src="pictures/stat0.jpg">';
		print "&nbsp;&nbsp;<font color=\"#656565\" size=\"-1\">$val%</font></td></tr>";


		
	}
	if($count>0)
		print '<tr><td>&nbsp;</td><td align=\"right\"><font size="-2">Measures based on '.$av.' model(s).</font></td></tr>';
	
	print '</table>';
	
	if($count==0)
	    print "<font color=\"#D64242\" size=\"2\"><b>No match</b></font>";
//////////////////////////////////////////////////////////////////////////////////////
	
	
//////////////////////////////neighbouring cells//////////////////////////////////////	
	print '<br><br><table width="80%" border="0" cellspacing="0" cellpadding="0">';
	print '<tr align="center"><td><font color="#456898" size="2"><b>Neighbouring cell (<5&micro;)</b></font></td><td><font color="#456898" size="2"><b>Distance(&micro;)</b></font></td><td><font color="#456898" size="2"><b>Contact(&micro;2)</b></font></td><td><font color="#456898" size="2"><b>Volume(&micro;3)</b></font></td><td><font color="#456898" size="2"><b>Surface(&micro;2)</b></font></td></tr>';
	$requete="select \"CELL_A\", \"CELL_B\", \"DISTANCE\", \"CONTACT\" from \"NEIGHBOR\" where (\"CELL_A\"='$id' or \"CELL_B\"='$id') and \"DISTANCE\"<=5";
    $stmt = pg_query($c,$requete);
	$count=0;
	while ($row=pg_fetch_array($stmt)){
	    $ncell="";
		$nidcell="";
	    if($row["CELL_A"]==$id)
		    $nidcell=$row["CELL_B"];
		else
		    $nidcell=$row["CELL_A"];
	    
		$requete="select \"NAME\" from \"ANAT_ENTITY\" where \"ANAT_ID\"='$nidcell'";
		$stmt2 = pg_query($c,$requete);
		if ($row2=pg_fetch_array($stmt2)){
	        $ncell=$row2["NAME"];
	        print "<tr align=\"center\"><td><a href=\"short_hierarchy.php?region=$nidcell&dev=$dev\">".$ncell."</a></td><td>".$row["DISTANCE"]."</td><td>".$row["CONTACT"]."</td>";
		}else
		    print "<tr align=\"center\"><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>";
		
		//volume & surface
		$requete="select \"VOLUME\", \"SURFACE\" from \"BIOMETRY\" where \"CELL\"='$nidcell'";
		$stmt2 = pg_query($c,$requete);
		$count=0;
		if ($row2=pg_fetch_array($stmt2))
			print "<td>".$row2["VOLUME"]."</td><td>".$row2["SURFACE"]."</td></tr>";
		else
		    print "<td>&nbsp;</td><td>&nbsp;</td></tr>";
			
		print "<tr align=\"center\"><td><hr size=\"1\"></td><td><hr size=\"1\"></td><td><hr size=\"1\"></td><td><hr size=\"1\"></td><td><hr size=\"1\"></td>";
		
		++$count;
	}
	print '</table>';
	if($count==0)
	    print "<br><font color=\"#D64242\" size=\"2\"><b>No match</b></font>";
	
	
	
	print "<center>";
	
?>

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