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

<html>
<!--<body bgcolor="#999966" text="#FFFFFF" link="#000000" vlink="#000000" alink="#000000">-->
<head>
<title>ANISEED CURATOR - Create Insitu</title>
<br>
 
<?
    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;
	}



//Calcul du nouvel IN_SITU_ID
/*On le fera a la fin*/


//Recup des parametres
$species=$_GET["species"];

if (strlen($species)==0) 
	{
	print "<center><strong>Please select a species</strong></center>";
	return;
	}

$devstage=$_GET["devstage"];

if (strlen($devstage)==0)
	{
	print "<center><strong>Please select a developmental stage before</strong></center>";
	return;
	}

$author=$_GET["author"];

if (strlen($author)==0)
	{
	print "<center><strong>Please select an author before</strong></center>";
	return;
	}


$ann="SELECT \"AUTHOR_ID\" from \"AUTHOR\" where \"LOGIN\"='".$_SESSION["login"]."'";
$sann=pg_query($c,$ann);
$rann=pg_fetch_array($sann);
$annotator_id=$rann["AUTHOR_ID"];


$wild=$_GET["wild"];


if ($wild=="yes") $wild="y"; else $wild="n";

//Pour la table ENTRY_ORIGIN

//recup de l'author_id
/*$requete="SELECT \"AUTHOR_ID\" from \"AUTHOR\" where \"NAME\"='".$_SESSION["login"]."'";
$stmt=pg_query($c,$requete);
$row=pg_fetch_array($stmt);
$author=$row["AUTHOR_ID"];*/





//On y va
pg_query($c,"begin");

//On commence par rentrer dans BIO_ID
$requete="INSERT INTO \"BIO_ENTITY\"(\"BIO_ID\",\"CURATED\") values (nextval('\"S_BIO_ID\"'),'n')";
pg_query($c,$requete);

//On passe dans IN_SITU
$requete="INSERT INTO \"IN_SITU\"(\"IN_SITU_ID\",\"DEV_STAGE_ID\",\"SPECIES\",\"WILD_TYPE\",\"CHECKED\",\"PRIVATE\") values(currval('\"S_BIO_ID\"'),'$devstage','$species','$wild','n','y')";

pg_query($c,$requete);

//On finit dans ENTRY_ORIGIN
$requete="INSERT INTO \"ENTRY_ORIGIN\"(\"AUTHOR_ID\",\"BIO_ID\",\"ENTRY_DATE\",\"ANNOTATOR_ID\",\"ANNOTATION_DATE\") values ('$author',currval('\"S_BIO_ID\"'),current_date,'$annotator_id',current_date)";
pg_query($c,$requete);


pg_query($c,"commit");

$requete="SELECT currval('\"S_BIO_ID\"')";
$stmt=pg_query($c,$requete);
$row=pg_fetch_array($stmt);


//print "<center><strong>In situ created !</strong></center><br><center>";

//print "<a target=\"_self\" href=\"insitu.php?id=".$row["currval"]."\">Go to In situ page to edit it </a></center>";

print "<meta http-equiv=\"refresh\" content=\"0; url=insitu.php?id=".$row["currval"]."\">";
print "</head>";


?>


</body>
</html>
