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

<html>
<body bgcolor="#999966" text="#FFFFFF" link="#000000" vlink="#000000" alink="#000000">
<title>ANISEED</title>
<br>
 
<?php
    if ( (!isset($_SESSION["login"]))or(!isset($_SESSION["pass"])) ) {
	    print "<center><strong>you need to <a href=\"login.php\">login</a> as an authorised curator to proceed.</strong>";
	    print '</center></body></html>';
		return;
	}
?>



<?php


$id=$_GET["id"]; //insitu
$removed=$_GET["region"]; //la nouvelle region anatomique
$dev=$_GET["devid"]; //le nouveau id du stade de developpement

$oldfrom=$_GET["oldfrom"];
$oldremoved=$_GET["oldremoved"];

/*print "$id<br>";
print "$removed<br>";
print "$dev<br>";
print "<br>";
print ">$oldfrom<br>";
print ">$oldremoved";*/

$requete="SELECT \"CTRL_ISH_ID\" from \"EMBRYO_MANIP\" where \"IN_SITU_ID\"='$id' and \"STRUCTURE_ID\"='$oldremoved' and \"FROM_ID\"='$oldfrom'";
$stmt=pg_query($c,$requete);
$row=pg_fetch_array($stmt);
$ctrl=$row["CTRL_ISH_ID"];

pg_query($c,"begin");
$requete="DELETE from \"EMBRYO_MANIP\" where \"IN_SITU_ID\"='$id' and \"STRUCTURE_ID\"='$oldremoved' and \"FROM_ID\"='$oldfrom'";
pg_query($c,$requete);

if (strlen($ctrl)>0) $requete="INSERT INTO \"EMBRYO_MANIP\"(\"IN_SITU_ID\",\"STRUCTURE_ID\",\"FROM_ID\",\"CTRL_ISH_ID\") values ('$id','$removed','$dev','$ctrl')";
else $requete="INSERT INTO \"EMBRYO_MANIP\"(\"IN_SITU_ID\",\"STRUCTURE_ID\",\"FROM_ID\") values ('$id','$removed','$dev')";
pg_query($c,$requete);

pg_query($c,"commit");



print '<center><H1>Update done</H1></center>';
print ' <br><center> To see changes refresh the "IN SITU FULL REPORT" page</center><br>';

print '<br><center><input name="Exit" type="button" value="-= Close window =-" onClick="javascript:self.close();"></center>';
?>
<SCRIPT LANGUAGE="JavaScript"> javascript:opener.location.reload(); self.close(); </script>

</body>
</html>