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

<?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>';
	   include ("frames_footer.php");
		return;
	}
?>



<?

$id=$_GET["id"];
$idmutant=$_GET["idmutant"];

$TYPE=0;
//print ">>>".$idmutant;

//On va regarde en premier le type de mutation (MUTANT ou EMBRYO_MANIP)
$requete="SELECT distinct \"IN_SITU_ID\" from \"MUTANT\" where \"IN_SITU_ID\"='$idmutant'";
$stmt=pg_query($c,$requete);
if (pg_num_rows($stmt)==1) $TYPE+=1;

$requete="SELECT distinct \"IN_SITU_ID\" from \"EMBRYO_MANIP\" where \"IN_SITU_ID\"='$idmutant'";
$stmt=pg_query($c,$requete);
if (pg_num_rows($stmt)==1) $TYPE+=2;


if ($TYPE==0) {
print "Error daugette!";
return;
}

//BOF Transaction
pg_query($c,"begin");



if ($TYPE==1)
{
$requete="SELECT \"CTRL_ISH_ID\" from \"MUTANT\" where \"IN_SITU_ID\"='$id'";
$stmt=pg_query($c,$requete);
if (pg_num_rows($stmt)==0)
	{
	$requete="UPDATE \"MUTANT\" set \"CTRL_ISH_ID\"='$id' where \"IN_SITU_ID\"='$idmutant'";
	pg_query($c,$requete);
	}
}

if ($TYPE==2)
{
$requete="SELECT \"CTRL_ISH_ID\" from \"EMBRYO_MANIP\" where \"IN_SITU_ID\"='$id'";
$stmt=pg_query($c,$requete);
if (pg_num_rows($stmt)==0)
	{
	$requete="UPDATE \"EMBRYO_MANIP\" set \"CTRL_ISH_ID\"='$id' where \"IN_SITU_ID\"='$idmutant'";
	pg_query($c,$requete);
	}

}

if ($TYPE==3)
{

$requete="SELECT \"CTRL_ISH_ID\" from \"MUTANT\" where \"IN_SITU_ID\"='$id'";
$stmt=pg_query($c,$requete);
if (pg_num_rows($stmt)==0)
	{
	$requete="UPDATE \"MUTANT\" set \"CTRL_ISH_ID\"='$id' where \"IN_SITU_ID\"='$idmutant'";
	pg_query($c,$requete);
	}

$requete="SELECT \"CTRL_ISH_ID\" from \"EMBRYO_MANIP\" where \"IN_SITU_ID\"='$id'";
$stmt=pg_query($c,$requete);
if (pg_num_rows($stmt)==0)
	{
	$requete="UPDATE \"EMBRYO_MANIP\" set \"CTRL_ISH_ID\"='$id' where \"IN_SITU_ID\"='$idmutant'";
	pg_query($c,$requete);
	}

}



	print "<center><strong>UPDATE DONE</strong></center>";





//EOF Transaction
pg_query($c,"commit");
















include ("frames_footer.php");
?>