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


<html>
<body bgcolor="#999966" text="#FFFFFF" link="#000000" vlink="#000000" alink="#000000">
<title>ANISEED CURATOR - Edit InSitu Comments</title>

<?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

    $part = $_POST["part"];
    $id = $_POST["id"];
    $text = $_POST["text"];
    $text = ereg_replace( "'", "&apos;", $text);
	$text = stripslashes($text);
	
	
    if( ($part=="IM_COMMENTS")or($part=="EXP_COMMENTS") ){
pg_query($c,"begin");
		
		$part="\"".$part."\"";

	    $requete="update \"IN_SITU\" set $part = '".$text."' where \"IN_SITU_ID\"=$id";
		$resultset = pg_query($c,$requete) or die("<strong>ERROR </strong>".pg_last_error($c));
		
	
		/*$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 if this ish is already annotated by an annotator
		$requete="SELECT \"ANNOTATOR_ID\" from \"ENTRY_ORIGIN\" where \"BIO_ID\"='$id'";
		$stmt=pg_query($c,$requete);
		$row=pg_fetch_array($stmt);
		
		if (strlen($row["ANNOTATOR_ID"])==0)
		{
		$requete = "update \"ENTRY_ORIGIN\" set \"ANNOTATOR_ID\"=".$_SESSION['curationauthor'].", \"ANNOTATION_DATE\"=current_date where \"BIO_ID\"=$id";
		$resultset = pg_query($c,$requete) or die("<strong>ERROR </strong>".pg_last_error($c));	
		}
		else
		{
		$requete="SELECT \"IS_ADMIN\" from \"AUTHOR\" where \"AUTHOR_ID\"='".$_SESSION['curationauthor']."'";
		$stmt=pg_query($c,$requete);
		$row=pg_fetch_array($stmt);
		if ($row["IS_ADMIN"]!="y")
			{
			$requete = "update \"ENTRY_ORIGIN\" set \"ANNOTATOR_ID\"=".$_SESSION['curationauthor'].", \"ANNOTATION_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");
	
		// Verification de la validation : si une erreur est survenue, afficher le message d'erreur
			print '<center><H1>Update done</H1><br>';
			print '<input name="Exit" type="button" value="-= Close window =-" onClick="javascript:opener.location.reload();self.close();"></center>';
		
		
	}else{
	    print "error.";
	}


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