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

<html>
<body bgcolor="#999966" text="#FFFFFF" link="#000000" vlink="#000000" alink="#000000">
<title>ANISEED</title>


 <br>
 
<?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>';
		return;
	}
?>

<?php

    $id=$_POST["id"];

	if(strlen($id)<=0)
		return;


/*Debut de la transaction*/
pg_query($c,"begin");

	if((isset($_POST["type"]) && $_POST["type"]=="reg")){
		$requete = "update \"PROMOTER\" set \"BEING_CURATED\"='y' where \"PROMOTER_ID\"=$id";	  
	} else {
		$requete = "update \"IN_SITU\" set \"BEING_CURATED\"='y' where \"IN_SITU_ID\"=$id";	  
	}
	
	$resultset = pg_query($c,$requete) or die("<strong>ERROR </strong>".pg_last_error($c));

//Pour le curateur
	$requete = "update \"ENTRY_ORIGIN\" set \"CURATOR_ID\"=".$_SESSION['curationauthor'].", \"CURATION_DATE\"=current_date where \"BIO_ID\"=$id";
	$resultset = pg_query($c,$requete) or die("<strong>ERROR </strong>".pg_last_error($c));



$test="SELECT \"IS_ADMIN\" from \"AUTHOR\" where \"LOGIN\"='".$_SESSION["curationauthor"]."'";
$stest=pg_query($c,$test);
$rtest=pg_fetch_array($stest);
if ($rtest["IS_ADMIN"]!='y')
{
//Pour l'annotateur
/*
$requete = "update \"ENTRY_ORIGIN\" set \"CURATOR_ID\"=".$_SESSION['curationauthor'].", \"CURATION_DATE\"=current_date where \"BIO_ID\"=$id";
	$resultset = pg_query($c,$requete) or die("<strong>ERROR </strong>".pg_last_error($c));
*/
 
}
    // Validation de la transaction
   pg_query($c,"commit");

	//Automatic processing of networks
	
	//include("update-interactions.php");
	if((isset($_POST["type"]) && $_POST["type"]=="reg")){
   
		$test="SELECT \"IN_SITU_ID\" FROM \"TARGET\" WHERE \"TARGET_ID\" IN 
			(SELECT \"CONSTRUCTION_ID\" from \"CONSTRUCTION\" WHERE \"PROMOTER_ID\"=$id)";
		$stest=pg_query($c,$test);
		while ($rtest=pg_fetch_array($stest))
		{
			$khoueiry="INSERT INTO \"UPDATE_INTERACTIONS\" (\"ID\", \"ISH_ID\" ) values 
				( nextval('\"S_UPDATE_INTERACTION\"'),".$rtest["IN_SITU_ID"].")";	  	
			pg_query($c,$khoueiry) or die ('<Strong>Error inserting UPDATE_INTERACTIONS: </Strong>'.pg_last_error($c));
			//update_evidence($c, $rtest["IN_SITU_ID"]);
		}
	} else {
		//It is an ISH
		//update_evidence($c, $id);
		$khoueiry="INSERT INTO \"UPDATE_INTERACTIONS\" (\"ID\", \"ISH_ID\" ) values 
				( nextval('\"S_UPDATE_INTERACTION\"'),".$id["IN_SITU_ID"].")";	  	
		pg_query($c,$khoueiry) or die ('<Strong>Error inserting UPDATE_INTERACTIONS: </Strong>'.pg_last_error($c));
	}
 
 
    print '<table width="100%" border="0">';
	
    // Verification de la validation : si une erreur est survenue, afficher le message d'erreur
   
	    print '<tr><td align="center"><H1>Validation done</H1></td></tr>';
	    print '<tr><td align="center"><center><input name="Exit" type="button" value="-= Close window =-" onClick="javascript:self.close();"></center></td></tr>';
   
	//ocilogoff($connection);
	/* ??? pourquoi fermer la connexion ici ??? */
?>

 </table>


<SCRIPT LANGUAGE="JavaScript"> javascript:opener.location.reload(); self.close(); </script>
</body>
</html>
 
 
 
 