
<?php

/*
edit-author-result.php

AUTHOR: Daniel Sobral
12/01/2007

*/

	include ("frames_header.php"); 
	include ("connection.php");

	//Login Check
    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"];
	$author = $_POST["author"];
		
	$khoueiry = "SELECT * FROM \"ENTRY_ORIGIN\" WHERE \"BIO_ID\"=$id";
	$stmt = pg_query($c,$khoueiry);		
	if($row=pg_fetch_array($stmt)){
	
		$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 \"AUTHOR_ID\"=$author, \"CURATOR_ID\"=".$_SESSION['curationauthor'].", \"CURATION_DATE\"=now() where \"BIO_ID\"=".$id;	  
		} else {
		    $khoueiry = "update \"ENTRY_ORIGIN\" set \"AUTHOR_ID\"=$author, \"ANNOTATOR_ID\"=".$_SESSION['curationauthor'].", \"ANNOTATION_DATE\"=now() where \"BIO_ID\"=".$id;		  
		}
		pg_query($c,$khoueiry) or die("<strong>ERROR </strong>".pg_last_error($c));		
				
	} else {	  				  
		$khoueiry="INSERT INTO \"ENTRY_ORIGIN\" (\"AUTHOR_ID\",\"BIO_ID\",\"ENTRY_DATE\",\"ANNOTATOR_ID\",\"ANNOTATION_DATE\") values ('$author',$id,now(),".$_SESSION['curationauthor'].",now())";	  
	}

	pg_query($c,$khoueiry) or die ("<strong>Error </strong>".pg_last_error($c));
	
    echo "<SCRIPT LANGUAGE=\"JavaScript\"> javascript:opener.location.reload(); self.close(); </script>";

	include ("frames_footer.php"); 

?>
