<?php

	include ("frames_header.php"); 
	include ("connection.php");
	
    if ( (!isset($_SESSION["login"]))or(!isset($_SESSION["pass"])) ) {
	    print "<strong>you need to <a href=\"login.php\">login</a> as an authorised curator to proceed.</strong>";
		include ("frames_footer.php"); 
		return;
	}

	$id = $_POST["id"];
	$type = $_POST["type"];
	$species = $_POST["species"];
	if($type=="Artificial"){
		$is_natural = 'n';
	} else {
		$is_natural = 'y';
	}
		
	pg_query($c,"begin") or die ("<strong>Error: </strong>".pg_last_error($c));

	if($type!="Artificial"){
		$khoueiry="UPDATE \"MOL_ENTITY\" SET \"SPECIES\"='$species' WHERE \"MOL_ID\"=$id";	  
	  	pg_query($c,$khoueiry) or die ("<strong>Error: </strong>".pg_last_error($c));
	}

  	$khoueiry="UPDATE \"PROMOTER\" SET \"IS_NATURAL\"='$is_natural' WHERE \"PROMOTER_ID\"=$id";	  

  	pg_query($c,$khoueiry) 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,"end") or die ("<strong>Error: </strong>".pg_last_error($c));	  
	
	echo '<SCRIPT LANGUAGE="JavaScript"> javascript:opener.location.reload(); self.close(); </script>';

	include ("frames_footer.php"); 

?>