<?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"ERROR: NO SPECIES ";
	include ("frames_footer.php");
	return;
}

if (isset($_GET["ordre"]))
	$order=$_GET["ordre"];
else 
{
	$order="";
	echo"ERROR: NO SPECIES ";
	include ("frames_footer.php");
	return;
}

if ($order=="")
{
	echo "<CENTER><strong>NO CHANGE FOR THE LIST</strong></CENTER>";
}
else
{
	//echo "<H3>TEST=$test  SPECIES=$species <br>ORDER=$order<br></H3>";
	$tab_order=explode("-",$order);
	$size_tab=count($tab_order);
	//echo"SIZE TAB ORDER = $size_tab <BR>";
	print_r($tab_order);
	for ($i=0; $i<$size_tab; $i++)
	{
		$pos=$i*4;
		//echo "<br>$pos<br>";
		$lib_id=$tab_order[$i];
		$requete="Update \"LIBRARY\" set \"ORDRE\"='$pos' where \"LIBRARY_ID\"='$lib_id' and \"SPECIES\"='$species'";
		if($test=="n")
        {
		pg_query($c,"begin");
        	$stmt = pg_query($c,$requete) or die("<strong>Error</strong> ".pg_last_error($c));
            	pg_query($c, "commit");
                //echo "<br>Commit for $requete<br>";
            
            //ocifreestatement($stmt);
		}
        else
        {
           echo "<H3>fake : $requete</H3>";
        }
		
	}
	echo "<H1>Update of the library hierarchie : DONE </H1> ";
	

}



?>


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