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


<?

	$name=$_GET["name"];
	//$name=strtoupper($name);
	if(strlen($name)==0){
	    print '<center><h2><strong>Missing parameter: Gene Name </strong></h2></center>';
		include("frames_footer.php");
		return;
	}

	$syno=$_GET["syno"];
	
	
	$species=$_GET["species"];
	

	//Recup du mol_id etant donne le gene_id

	/*$requete="SELECT \"GENE_ID\" FROM \"GENE\" WHERE \"NAME\"='$name'";
	$stmt=pg_query($c,$requete);

	$row=pg_fetch_array($stmt);
	$molid=$row["GENE_ID"];
	*/

	//Insertion dans la base

		//Mis en conformite du syno a syno_upper_case

		$synoUP=strtoupper($syno);
	        $synoUP=strtoupper($synoUP);
        	$synoUP=ereg_replace("[^a-zA-Z0-9]"," ",$synoUP);
		$synoUP=ereg_replace("([a-zA-Z])([0-9])","\\1 \\2",$synoUP);
		$synoUP=ereg_replace("([0-9])([a-zA-Z])","\\1 \\2",$synoUP);
		$synoUP=ereg_replace(" +"," ",$synoUP);
		$synoUP=ereg_replace("^ ","",$synoUP);
		$synoUP=ereg_replace(" $","",$synoUP);


	pg_query($c,"begin");

	//$requete="INSERT into \"SYNO\" (\"GENE_ID\",\"SYNO\",\"SYNO_UPPER_CASE\",\"ORIGIN\") values ('$molid','$syno','$synoUP','user-JGI')";


	$requete="INSERT INTO \"GENE_CONCEPT_NAME\" (\"GENE_CLUSTER_ID\",\"GENE_CLUSTER_UPPER_NAME\",\"GENE_CLUSTER_NAME\",\"MANUAL\") values ('".str_replace("aniseedV3_","cluster","$name")."','$synoUP','$syno','y')";

	$stmt=pg_query($c,$requete);

	if (!$stmt)
		{
		print "Error: ".pg_last_error($c);
		pg_query($c,"rollback");
		include ("frames_footer.php");
		return;
		}


	pg_query($c,"commit");

	print "<center><strong> Synonym successfuly added </strong></center>";
	

	









?>


<?

include ("frames_footer.php");
?>