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


$id=$_POST["id"];
$gene=$_POST["gene"];
$comments=$_POST["comments"];

$morpho=$_POST["morphoid"];

$name=$_POST["name"];

$devstage=$_POST["devstage"];



if (strlen($gene)==0) 
	{
	print "<center><br>Please choose a valid aniseed gene model ID</center>";
	include ("frames_footer.php");
	return;
	}

if (strlen($name)==0)
	{
	print "<center><br>Please choose one name for this morphogenetic process</center>";
	include ("frames_footer.php");
	return;
	}

//$requete="SELECT \"GENE_CLUSTER_ID\" from \"GENE_CONCEPT\" where \"GENE_CLUSTER_ID\"='".(str_replace("aniseedV3_","cluster",$gene))."'";

$requete="SELECT \"NAME\" from \"GENE\" where \"NAME\"='$gene'";
$stmt=pg_query($c,$requete);
if (pg_num_rows($stmt)==0) 
	{
	print "<center><br>Please choose a valid Transcript ID</center>";
	include ("frames_footer.php");
	return;
	}


if (strlen($morpho)==0)
{
if (strlen($comments)!=0) $requete="INSERT INTO \"ARTICLE_MORPHOGEN\" (\"MORPHOGEN_ID\",\"ARTICLE_ID\",\"TRANSCRIPT\",\"COMMENTS\",\"NAME\",\"DEV_STAGE_ID\") values (nextval('\"S_MORPHOGEN_ID\"'),'$id','$gene','$comments','$name','$devstage')";
else $requete="INSERT INTO \"ARTICLE_MORPHOGEN\" (\"MORPHOGEN_ID\",\"ARTICLE_ID\",\"TRANSCRIPT\",\"NAME\",\"DEV_STAGE_ID\") values (nextval('\"S_MORPHOGEN_ID\"'),'$id','$gene','$name','$devstage')";
}

else
{
$requete="UPDATE \"ARTICLE_MORPHOGEN\" SET \"TRANSCRIPT\"='$gene', \"NAME\"='$name', \"COMMENTS\"='$comments', \"DEV_STAGE_ID\"='$devstage' where \"MORPHOGEN_ID\"='$morpho'";
}


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


include ("frames_footer.php");


?>

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