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


$id=$_POST["embryoid"];



if (strlen($_FILES['biomfile']['tmp_name'])==0)
	{
	print "<br><br><center>Please submit a file containing the distances data.</center>";
	include ("frames_footer.php");
	return;
	}

$requete="SELECT * from \"EMBRYO_BIOMETRY_SHAPE\" where \"EMBRYO_ID\"='$id'";
$stmt=pg_query($c,$requete);
if (pg_num_rows($stmt)==0) $INSERT=1; else $INSERT=0;


pg_query($c,"begin");


if ($INSERT==0)
{
$requete="DELETE FROM \"EMBRYO_BIOMETRY_SHAPE\" where \"EMBRYO_ID\"='$id'";
$stmt=pg_query($c,$requete) or die ("Error delete... please contact your administrator !");
}



$handle=fopen($_FILES['biomfile']['tmp_name'],"r");
while (!feof($handle))
{
$content=trim(fgets($handle,8192));
if (strlen($content)==0) continue;

if ($content{0}=="#") continue;


$tmp=explode("\t",$content);


$cell=$tmp[0];
$sphe=$tmp[1];
$elon=$tmp[2];
$flat=$tmp[3];
$occu=$tmp[4];
$entr=$tmp[5];
$sv=$tmp[6];
$conv=$tmp[7];
$vv=$tmp[8];

if ($cell=="default") continue;

$requete="INSERT INTO \"EMBRYO_BIOMETRY_SHAPE\" (\"EMBRYO_ID\",\"CELL\",\"SPHERICITY\",\"ELONGATION\",\"FLATNESS\",\"OCCUPENCY\",\"ENTROPY\",\"SV\",\"CONVEXITY\",\"VV\") values ('$id',(select \"ANAT_ID\" from \"ANAT_ENTITY\" where \"NAME\"='".$tmp[0]."' and \"DEV_STAGE_ID\"=(select \"DEV_STAGE_ID\" from \"EMBRYO\" where \"EMBRYO_ID\"='$id')),'$sphe','$elon','$flat','$occu','$entr','$sv','$conv','$vv')";


print $requete;

$stmt=pg_query($c,$requete) or die ("Error... please contact your administrator !");


}
fclose($handle);


pg_query($c,"end");






?>
<SCRIPT LANGUAGE="JavaScript"> javascript:opener.location.reload(); self.close(); </script>



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