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


$id=$_POST["id"];
$gene=$_POST["gene"];
$type=$_POST["type"];
$update=$_POST["update"];

$oldname=$_POST["oldname"];
//$oldname=str_replace("aniseedV3_","cluster",$oldname);


$oldtype=$_POST["oldtype"];



$genecomp=$gene;

//$requete="SELECT \"GENE_CLUSTER_ID\" from \"GENE_CONCEPT\" where \"GENE_CLUSTER_ID\"='$genecomp'";
$requete="SELECT \"NAME\" from \"GENE\" where \"NAME\"='$genecomp'";
$stmt=pg_query($c,$requete);
if (pg_num_rows($stmt)==0)
	{

	print "<BR><BR><center>The Transcript ID you've entered is not in the database, please choose an other one</center>";
	include ("frames_footer.php");
	return;
	}

pg_query($c,"begin");


if ($update!="1") $requete="INSERT INTO \"ARTICLE_GENE\" (\"ARTICLE_ID\",\"TRANSCRIPT\",\"TYPE\") values ('$id','$genecomp','$type')";
else $requete="UPDATE \"ARTICLE_GENE\" set \"TRANSCRIPT\"='$genecomp',\"TYPE\"='$type' where \"ARTICLE_ID\"='$id' and \"TRANSCRIPT\"='$oldname' and \"TYPE\"='$oldtype'";

$stmt=pg_query($c,$requete) or die (pg_last_error($c));




pg_query($c,"commit");

if ($update!="1") print "<center><h3>Gene added !</h3></center><br>";
if ($update=="1") print "<center><h3>Gene Updated !</h3></center><br>";





include ("frames_footer.php");
?>

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