<?php
	include ("frames_header.php"); 
	print "<title>ANISEED CURATOR - Construct Edit</title>";

	include("connection.php");

	//CONSTRUCTION_ID
	$id = $_GET["constructid"];	
	
	$khoueiry = "SELECT * FROM \"CONSTRUCTION\" WHERE \"CONSTRUCTION_ID\"=".$id.";";		
	$stmt = pg_query($c,$khoueiry);
	if($row=pg_fetch_array($stmt)){
		$stable_id = $row["STABLE_ID"];
	    $name=$row["NAME"];
	    $comments=$row["COMMENTS"];
	    $promoter_id = $row["PROMOTER_ID"];
	    //$reporter = $row["REPORTER_ID"];
		$reporter = $row["REPORTER_GENE"];
	    $min_prom_id=$row["MIN_PROMOT_ID"];	
			    
	    $promoter_name = "Unable to determine";
		$khoueiry = "SELECT \"NAME\" FROM \"PROMOTER\" WHERE \"PROMOTER_ID\"=".$promoter_id.";";		
		$stmt = pg_query($c,$khoueiry);
		if($row=pg_fetch_array($stmt)){			  
			$promoter_name = $row["NAME"];
		}	    	    	    
	    
	    $min_prom_name = "Unable to determine";
	    if($promoter_id==$min_prom_id){
			$min_prom_name = "Endogenous Promoter";
		} else {
			$khoueiry = "SELECT \"NAME\" FROM \"PROMOTER\" WHERE \"PROMOTER_ID\"=".$min_prom_id.";";		
			$stmt = pg_query($c,$khoueiry);
			if($row=pg_fetch_array($stmt)){			  
				$min_prom_name = $row["NAME"];
			}
		}	    
	}
	
   
   
   print "<center><h3><a target=\"_BLANK\" href=\"createISH.php\">Create a new In-Situ Record</a><h3></center><br/>";
   
    print "<h2><strong><em>Construct ".$stable_id.": ".$name."</em></strong> <a href=\"insitu-result.php?target=".$stable_id."&MOLtype=1\" target=\"_blank\"> <img src=\"pictures/button-getPics.jpg\" border=\"0\" title=\"View Insitu data\"></a></h2> ";
    print "<strong>Regulatory Region:</strong><a target=\"_BLANK\" href=\"reg-region-edit.php?id=$promoter_id\">$promoter_name</a><br/><br/>";
    print "<u><strong><font size=\"+2\">Features:</font></strong></u><br><br>";
	print "<a target=\"_BLANK\" href=\"curator-mol-edit.php?type=construction&part=name&id=$id\"><img border=\"0\" src=\"pictures/button-cur-edit.gif\"></a><strong>Name: </strong>".$name."<br>";		
    print "<a target=\"_BLANK\" href=\"curator-mol-edit.php?type=construction&part=comments&id=$id\"><img border=\"0\" src=\"pictures/button-cur-edit.gif\"></a><strong>Comments:</strong>".$comments."<br/>";
    print "<a target=\"_BLANK\" href=\"construct-edit-minprom.php?id=$id&promid=$promoter_id\"><img border=\"0\" src=\"pictures/button-cur-edit.gif\"></a><strong>Minimal Promoter: </strong>";    
    if($promoter_id==$min_prom_id){
	     print "Endogenous Promoter<br/>"; 	  
	} else {
	     print "<a target=\"_BLANK\" href=\"reg-region-edit.php?id=$min_prom_id\">$min_prom_name</a><br/>"; 
	}
	
	if($reporter==""){ $reporter = "Unable to determine"; }
	
	print "<a target=\"_BLANK\" href=\"construct-edit-reporter.php?id=$id&promid=$promoter_id\"><img border=\"0\" src=\"pictures/button-cur-edit.gif\"></a><strong>Reporter:</strong>$reporter<br/>";
	/*
	$khoueiry = "SELECT \"NAME\" FROM \"MOLECULAR_TOOL\" WHERE \"MOLECULAR_TOOL_ID\"=$reporter;";
	$stmt = pg_query($c,$khoueiry);		
	if($row=pg_fetch_array($stmt)){ 
		print "<a target=\"_BLANK\" href=\"construct-edit-reporter.php?id=$id&reporter=$reporter&promid=$promoter_id\"><img border=\"0\" src=\"pictures/button-cur-edit.gif\"></a><strong>Reporter:</strong>".$row["NAME"]."<br/>";
	 
	} else {
		print "<a target=\"_BLANK\" href=\"construct-edit-reporter.php?id=$id&reporter=$reporter&promid=$promoter_id\"><img border=\"0\" src=\"pictures/button-cur-edit.gif\"></a><strong>Reporter:</strong>Unable to determine<br/>";
	}
	*/
			
	$khoueiry="select \"SEQUENCE\", \"LENGTH\", \"COMMENTS\", \"MOL_ID\" from \"SEQUENCE\" where \"MOL_ID\"=$id";
	$stmt = pg_query($c,$khoueiry);		
	$seq = "";
	if($row=pg_fetch_array($stmt)){
		$lob = $row["SEQUENCE"];

		pg_query ($c, "begin");		
		$handle_lo = pg_lo_open($c,$lob,"r");
		$seq=pg_lo_read($handle_lo);
		pg_query($c,"end");
					
		$seq=ereg_replace("\n","",$seq);
		$seq = chunk_split($seq, 70, "\n");
		
		print "<br/><a href=\"sequence-edit.php?id=$id\" target=\"_blank\"><img src=\"pictures/button-cur-edit.gif\" width=\"25\" border=\"0\" title=\"Edit\"></a><u><strong><font size=\"+2\">Sequence associated to this construction</font></strong></u><br/>";

		print "<strong>Length: </strong>".$row["LENGTH"]."<br/>";		
		print $row["COMMENTS"]."<br/>";		
		
		print "<pre><font face=\"Courier New, Courier, mono\" size=\"3\">".strtoupper($seq)."</font></pre>";
		
	}else{
		print "<br><br><a href=\"sequence-edit.php?id=$id\" target=\"_blank\"><img src=\"pictures/button-cur-edit.gif\" width=\"25\" border=\"0\" title=\"Edit\"></a><u><strong><font size=\"+2\">Sequence associated to this construction</font></strong></u><br></pre>";
	}
		
	include ("frames_footer.php"); 

?>