<?php
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;
	}

$region = $_GET["region"];
$devid = $_GET["devid"];
$cloneid=$_GET["cloneid"];
$substrate=$_GET["substrate"];
$species=$_GET["species"];
$insituid=$_GET["insituid"];
$sure=$_GET["sure"];
$partof=$_GET["partof"];
$subcellpos=$_GET["subcellpos"];
$intensity=$_GET["intensity"];
$method=$_GET["method"];
$anatid=$_GET["anatid"];


$typeMol=$_GET["typeMol"];


$requete0="SELECT \"TYPE\" from \"MOL_ENTITY\" where \"NAME\"='$cloneid'";
$stmt0=pg_query($c,$requete0);
$typeMol="";
while ($row0=pg_fetch_array($stmt0))
{
if ($row0["TYPE"]=="clone")
	{
	$typeMol=$row0["TYPE"];
	break;
	}
else $typeMol=$row0["TYPE"];
}


//print ">>>".$subcellpos;

//print "$cloneid";

//Daniel Sobral 6 October 2006
//added exception so it won't include regulatory regions... (see addmultpartanat.php for more info)
$requete= "select * from \"MOL_ENTITY\" where \"NAME\"='$cloneid' and \"TYPE\"='$typeMol' and \"TYPE\"!='regulatory_region'";
$stmt = pg_query($c,$requete);
print $requete;

$found = FALSE;

//print $requete."<br>";
while($row=pg_fetch_array($stmt))
{
	//if it is a construction we do not control for species...
	if($row["TYPE"]=='construction' || $row["SPECIES"]==$species){
		$id=$row["MOL_ID"];
		$found = TRUE;  
	}	
}
	
if($found){

pg_query($c,"begin");

/* 
	$requete=" delete from \"TARGET\" where \"IN_SITU_ID\"='$insituid' and \"TARGET_ID\"='$id' and \"REGION_ID\"='$anatid'";
	pg_query($c,$requete)or die ("<strong>Error </strong>".pg_last_error($c));


$requete= "insert into \"TARGET\" (\"TARGET_ID\", \"IN_SITU_ID\", \"REGION_ID\", \"METHOD\", \"INTENSITY\", \"SUBSTRATE\", \"SUBCELL_POS\", \"NAME\", \"SURE\", \"PART_OF\") values ('$id','$insituid','$region', '$method', '$intensity', '$substrate', '$subcellpos','$cloneid','$sure', '$partof')";

*/

$requete="UPDATE \"TARGET\" set \"TARGET_ID\"='$id', \"REGION_ID\"='$region', \"METHOD\"='$method', \"INTENSITY\"='$intensity', \"SUBCELL_POS\"='$subcellpos', \"SUBSTRATE\"='$substrate', \"NAME\"='$cloneid',\"SURE\"='$sure',\"PART_OF\"='$partof' where \"IN_SITU_ID\"='$insituid' and \"REGION_ID\"='$anatid'";

//print $requete;

	$stmt1 = pg_query($c,$requete) or die ("<strong>Error </strong>".pg_last_error($c));

/*$requete = "update \"ENTRY_ORIGIN\" set \"ANNOTATOR_ID\"=".$_SESSION['curationauthor'].", \"ANNOTATION_DATE\"=current_date where \"BIO_ID\"=$id";
		$resultset = pg_query($c,$requete) or die("<strong>ERROR </strong>".pg_last_error($c));	*/

	
		print '<center><H1>Update done for '.$cloneid.'</H1></center>';
		print ' <br><center> To see changes refresh the "IN SITU FULL REPORT" page</center><br>';
pg_query($c,"commit");

print '<SCRIPT LANGUAGE="JavaScript"> javascript:opener.location.reload(); self.close(); </script>';
}
else 
{
 echo "<center><strong><br>\"WARNING\" &nbsp;----> &nbsp;Clone name not found in ANISEED database<br> </strong><center>";
 echo"<br><center><strong> ERROR : Update NOT done for $cloneid </strong></center><br>";
}

print '<br><center><input name="Exit" type="button" value="-= Close window =-" onClick="javascript:self.close();"></center>';


?>



