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

<?php

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


if (isset($_GET["species"]))
	$species=$_GET["species"];
else 
{
	$species="";
	echo "<strong> You must specify a species for the library to add</strong> <br>";
	include("frames_footer.php");
	return;
}


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

if (isset($_GET["title"]))
	$title=$_GET["title"];
else 
{
	$title="";
	echo "<strong> You must specify a title for the library to add</strong> <br>";
	include("frames_footer.php");
	return;
}

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

if (isset($_GET["dev"]))
	$dev=$_GET["dev"];
else 
	$dev="";

$namestage=$dev;

if (isset($_GET["vector"]))
	$vector=$_GET["vector"];
else 
	$vector="";
	
if ($lib_id!="")
{
	$requete="SELECT \"LIBRARY_ID\" from \"LIBRARY\" where \"LIBRARY_ID\"='$lib_id'";
	$stmt = pg_query($c,$requete) or die("<strong>Error</strong> ".pg_last_error($c));
	if(!$row=pg_fetch_array($stmt))
	{
		$bool="true";
		//echo "THE ID FOR THE LIBRARY TO ADD IS: $lib_id<br>";
	}
	else
	{
		echo "<strong><center><H2>WARNING:</H2>THE LIBRARY ID ENTERED ALREADY EXIST. \"The system generate an other library id\"</center></strong><BR>";
		$bool="false";
		$lib_id="";
	}
	//ocifreestatement($stmt);
}

if ($lib_id=="")
{
	 $bool="false";
	 while ($bool!="true")
	 {
	 	srand();
	 	$lib_id=rand(0,99999);
		
		$requete="SELECT \"LIBRARY_ID\" from \"LIBRARY\" where \"LIBRARY_ID\"='$lib_id'";
		$stmt = pg_query($c,$requete) or die("<strong>Error</strong> ".pg_last_error($c));
		if(!$row=pg_fetch_array($stmt))
		{
			$bool="true";
			
		}
		else
			$bool="false";
		
		//ocifreestatement($stmt);
	
	 }
	 
}
/*
	$requete="SELECT NAME FROM CIONA_DESIGN.DEV_STAGE WHERE SPECIES='$species' and DEV_STAGE_ID='$dev'";
	$stmt = OCIParse($connection, $requete);
	OCIExecute($stmt);
	if (OCIFetch($stmt))
	{*/
	//	$namestage=OCIResult($stmt, "NAME");
	//}
	print '<table>';
	print "<tr><td align=\"center\"><strong>Are you sure you want to <font size=\"+2\" color=\"#CC0000\">INSERT </font> this new library</strong></td></tr>";
	print '</table>';	
	echo "<hr size=\"1\">";
	echo "<CENTER><H2>Description of this library :</H2>";
	
	echo "<table border=\"0\"  bgcolor=\"#999999\" background=\"pictures/barre.jpg\">";
	echo "<tr><td ALIGN=RIGHT>SPECIES :</td><td> $species</td></tr>";
	echo "<tr><td ALIGN=RIGHT>LIBRARY ID :</td><td> $lib_id</td></tr>";
	echo "<tr><td ALIGN=RIGHT>TITLE :</td><td>$title</td></tr>";
	echo "<tr><td ALIGN=RIGHT>TISSUE :</td><td> $tissue</td></tr>";
	echo "<tr><td ALIGN=RIGHT>DEVELOPMENTAL STAGE :</td><td>$namestage</td></tr>";
	echo "<tr><td ALIGN=RIGHT>VECTOR :</td><td> $vector</td></tr>";
	echo "</TABLE><br><br>";
	
	//arguments
	print'<form action="add-library-bis3.php" method="post" name="formulaire" target="_self">';
	print '<table>';
	print"<input name=\"test\" type=\"hidden\" value=\"$test\">";
	print "<input name=\"species\" type=\"hidden\" value=\"$species\">";
	print "<input name=\"lib_id\" type=\"hidden\" value=\"$lib_id\">";
	print"<input name=\"title\" type=\"hidden\" value=\"$title\">";
	print "<input name=\"tissue\" type=\"hidden\" value=\"$tissue\">";
	//print "<input name=\"dev\" type=\"hidden\" value=\"$dev\">";
	print "<input name=\"dev\" type=\"hidden\" value=\"$namestage\">";
	print "<input name=\"vector\" type=\"hidden\" value=\"$vector\">";
	
	
	print '<tr><td align="center"><center><input type="image" src="pictures/button-cur-delete.gif" title="Cancel"  onClick="javascript:self.close();">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
	print '<input type="image" src="pictures/button-cur-validate.gif" onClick="submit" title="Ok">';
	print '</table></center>';
	//ocifreestatement($stmt);
	
?>

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