<?php
	//connection
	include("connection.php");
	include ("frames_header.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;
	}

    $id=$_POST["id"];
	$mode=$_POST["mode"];

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

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

if(!isset($_POST["type"]) || $_POST["type"]!="reg"){
  $dataN = "IN_SITU";
} else {
  $dataN = "PROMOTER";
}

if($mode==1)//tag as public
	$requete = "update \"".$dataN."\" set \"PRIVATE\"='n' where \"".$dataN."_ID\"=$id";
if($mode==2)//tag as private
	$requete = "update \"".$dataN."\" set \"PRIVATE\"='y' where \"".$dataN."_ID\"=$id";
if($mode==3)//tag as not curated
	$requete = "update \"".$dataN."\" set \"CHECKED\"='n' where \"".$dataN."_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["login"]."'";
	$stest=pg_query($c,$test);
	$rtest=pg_fetch_array($stest);
	if ($rtest["IS_ADMIN"]=='y'){
		$khoueiry = "update \"ENTRY_ORIGIN\" set \"CURATOR_ID\"=".$_SESSION['curationauthor'].", \"CURATION_DATE\"=now() where \"BIO_ID\"='$id'";	  
	} else {
	    $khoueiry = "update \"ENTRY_ORIGIN\" set \"ANNOTATOR_ID\"=".$_SESSION['curationauthor'].", \"ANNOTATION_DATE\"=now() where \"BIO_ID\"=$id";		  
	}
	pg_query($c,$khoueiry) or die("<strong>ERROR </strong>".pg_last_error($c));
	  	  	
	pg_query($c, "COMMIT") or die("<strong>ERROR </strong>".pg_last_error($c));

    //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
		$khoueiry="INSERT INTO \"UPDATE_INTERACTIONS\" (\"ID\", \"ISH_ID\" ) values 
				( nextval('\"S_UPDATE_INTERACTION\"'),".$id.")";	  	
			pg_query($c,$khoueiry) or die ('<Strong>Error inserting UPDATE_INTERACTIONS: </Strong>'.pg_last_error($c));
		//update_evidence($c, $id);
	}	
	
	print '<SCRIPT LANGUAGE="JavaScript"> javascript:opener.location.reload(); self.close(); </script>';
      
	include ("frames_footer.php");
?> 
 
 
 