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

<?php

if (isset($_POST["test"]))
	$test=$_POST["test"];
else 
$test="n";


if (isset($_POST["species"]))
	$species=$_POST["species"];
else 
{
	$species="";
	echo "<strong> ERROR: please select a species</strong> <br>";
	include("frames_footer.php");
	return;
}


if (isset($_POST["lib_id"]))
	$lib_id=$_POST["lib_id"];
else 
$lib_id="";

if (isset($_POST["title"]))
	$title=$_POST["title"];
else 
{
	$title="";
	echo "<strong>ERROR: please choose a title</strong> <br>";
	include("frames_footer.php");
	return;
}

if (isset($_POST["tissue"]))
	$tissue=$_POST["tissue"];
else 
	$tissue="";

if (isset($_POST["dev"]))
	$dev=$_POST["dev"];
else 
	$dev="";
	
if (isset($_POST["vector"]))
	$vector=$_POST["vector"];
else 
	$vector="";
	
	
	
	
$requete="SELECT \"LIBRARY_ID\" FROM \"LIBRARY\" where \"LIBRARY_ID\"='$id' and \"SPECIES\"= '$species'";
$stmt = pg_query($c,$requete) or die("<strong>Error</strong> ".pg_last_error($c));
if(!$row=pg_fetch_array($stmt))
{

	$requete = "INSERT INTO \"LIBRARY\" (\"LIBRARY_ID\", \"TITLE\", \"TISSUE\", \"DEV_STAGE\", \"VECTOR\", \"SPECIES\") values ($lib_id, '$title', '$tissue', '$dev', '$vector', '$species')";
	if($test=="n")
	{
		pg_query($c,"begin");
		$stmt1 = pg_query($c,$requete) or die("<strong>Error</strong> ".pg_last_error($c));
		pg_query($c,"commit");
		//ocifreestatement($stmt1);
	}
	else
	{
		echo "<H3>OK</H3>";
	}
				
}
else
{
	echo "ERROR : a library with the same ID already exists<br>";
	include ("frames_footer.php");
	return;
}
	
	
	
	
?>

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