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


<?php

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

/*
$requete="SELECT \"MATRIX\" from \"MOTIF_REGUL\" where \"MOTIF_ID\"=$motif";
$stmt=pg_query($c,$requete);
if ($row=pg_fetch_array($stmt)) {
	$matrix = $row["MATRIX"];
	$size = $row["SIZE"];
}
*/
/*
$requete="SELECT \"SEQUENCE\", \"ORIENTATION\", \"UPDATE_MATRIX\" from \"MOTIF_COORD\" where \"MOTIF_ID\"=$motif AND \"PROMOTER_ID\"=$id AND \"BEGIN\"=$begin";
$stmt=pg_query($c,$requete);
if ($row=pg_fetch_array($stmt)) {
	$sequence = $row["SEQUENCE"];
	$orientation = $row["ORIENTATION"];	
	$update = $row["UPDATE_MATRIX"];		
}
*/

pg_query($c,"begin");

$requete = "DELETE FROM \"MOTIF_COORD_GENE\" WHERE \"MOTIF_COORD_ID\"=".$id;
pg_query($c, $requete) or die("<strong>ERROR </strong>".pg_last_error($c)); 

$requete="DELETE FROM \"MOTIF_COORD\" where \"MOTIF_COORD_ID\"='$id'";
pg_query($c,$requete) or die("<strong>Error</strong> ".pg_last_error($c));

$requete="DELETE FROM \"MOL_ENTITY\" where \"MOL_ID\"='$id'";
pg_query($c,$requete) or die("<strong>Error</strong> ".pg_last_error($c));

$requete="DELETE FROM \"BIO_ENTITY\" where \"BIO_ID\"='$id'";
pg_query($c,$requete) or die("<strong>Error</strong> ".pg_last_error($c));

/*
//if update_matrix='y' we need to update the matrix...
if($update=='y'){
  	//utils.php
	$reverseP = false;
	if($orientation=='-'){ $reverseP=true; }
	$matrix = update_matrix($matrix,$sequence,$reverseP,false);	
	$requete="UPDATE \"MOTIF_REGUL\" SET \"MATRIX\" = '$matrix' where \"MOTIF_ID\"=$motif_id";
	$stmt=pg_query($c,$requete);	
}
*/

		$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\"=".$regid;	  
		} else {
		    $khoueiry = "update \"ENTRY_ORIGIN\" set \"ANNOTATOR_ID\"=".$_SESSION['curationauthor'].", \"ANNOTATION_DATE\"=now() where \"BIO_ID\"=".$regid;		  
		}
		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));
		
		echo '<SCRIPT LANGUAGE="JavaScript"> javascript:opener.location.reload(); self.close(); </script>';

	include ("frames_footer.php"); 	
?>