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

<?php
    $name=$_GET["name"];
	
	$requete="select A.*, B.\"SPECIES\" from \"PROMOTER\" A, \"MOL_ENTITY\" B where (A.\"NAME\"='$name')and(A.\"PROMOTER_ID\"=B.\"MOL_ID\")";
	$stmt = pg_query($c,$requete);
	if($row=pg_fetch_array($stmt)){
	    $species=$row["SPECIES"];
	    $id=$row["PROMOTER_ID"];
		
        print '<div align="right"><img src="pictures/button-cur-delete.gif" border="0" title="Delete" onClick="window.open(\'curator-mol-delete.php?id='.$id.'\')"></div>';
		
		print "<h2><strong><em>Promoter: ".$row["NAME"]." &nbsp;&nbsp;($species)</em></strong></h2>";
		
	    print "<u><strong><font size=\"+2\">Features</font></strong></u><br><br>";
		print "<a target=\"_BLANK\" href=\"curator-mol-edit.php?type=promoter&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=promoter&part=comments&id=$id\"><img border=\"0\" src=\"pictures/button-cur-edit.gif\"></a><strong>Comments:</strong><br>".$row["COMMENTS"]."<br>";
		
		
		print "<br><u><strong><font size=\"+2\">Constructions:</font></strong></u><br>";
		$requete="select \"NAME\" from \"CONSTRUCTION\" where \"PROMOTER_ID\"='$id'";
		$stmt = pg_query($c,$requete);
		$count=0;
		while($row=pg_fetch_array($stmt)){
		    ++$count;
		    print "<a href=\"molecule-construction.php?name=".$row["NAME"]."\">".$row["NAME"]."</a><br>";
		}
		if($count==0) print "No description";
		
		
		print "<br><u><strong><font size=\"+2\">Regulated genes:</font></strong></u><br>";
		$requete="select a.\"NAME\" from \"GENE\" a, \"GENE_REGULATION\" b where (b.\"PROMOTER_ID\"='$id') and (a.\"GENE_ID\"=b.\"GENE_ID\")";
		$stmt = pg_query($c,$requete);
		$count=0;
		while($row=pg_fetch_array($stmt)){
		    ++$count;
		    print "<a href=\"molecule-gene.php?name=".$row["NAME"]."\">".$row["NAME"]."</a><br>";
		}
		if($count==0) print "No description<br>";		
		
		
		print "<br><u><strong><font size=\"+2\">Regulatory motifs:</font></strong></u><br>";
		$requete="select A.\"SEQUENCE\", A.\"BEGIN\", A.\"STOP\", B.\"NAME\", B.\"COMMENTS\" from \"MOTIF_COORD\" A, \"MOTIF_REGUL\" B where (A.\"MOTIF_ID\"=B.\"MOTIF_ID\")and(A.\"PROMOTER_ID\"='$id')";
		$stmt = pg_query($c,$requete);
		$count=0;
		while($row=pg_fetch_array($stmt)){
		    ++$count;
		    print "<strong>Name: &nbsp;&nbsp;</strong> ".$row["NAME"]."<br>";
            print "<strong>Position: </strong> ".$row["BEGIN"]."-".$row["STOP"]."<br>";
			print "<strong>Sequence: </strong> ".$row["SEQUENCE"]."<br>";
			print "<strong>Comments: </strong> ".$row["COMMENTS"]."<br><br>";
		}
		if($count==0) print "No description<br>";
		
		
//////////////////////////////////////////SEQUENCE/////////////////////////////////////////////
	$requete="select \"SEQUENCE\", \"LENGTH\", \"COMMENTS\", \"MOL_ID\" from \"SEQUENCE\" where \"MOL_ID\"=$id";
		$stmt = pg_query($c,$requete);
		
		if($row=pg_fetch_array($stmt)){
		    $lob = $row["SEQUENCE"];

			/* DEBUT DE L'AFFICHAGE DU CLOB */

		pg_query ($c, "begin");	/*Debut de la transaction*/
		
		$handle_lo = pg_lo_open($c,$lob,"r");
		$seq=pg_lo_read($handle_lo);

		pg_query($c,"end"); /*fin de la Transaction*/

		/* FIN DE L'AFFICHAGE DU LOB */



			
			/*if( (! ereg("\n",$seq) )and(! ereg("<br>",$seq)) ){
				$seq = chunk_split($seq, 70, "\n");
			}*/
			$seq=ereg_replace("<br>","",$seq);
			$seq=ereg_replace("\n","",$seq);
			$seq = chunk_split($seq, 70, "\n");


		    print "<br><br><u><strong><font size=\"+2\">Sequence</font></strong></u><br><strong>Length: </strong>".$row["LENGTH"]."<br>".strtoupper($row["COMMENTS"])."<br><br><pre><font face=\"Courier New, Courier, mono\" size=\"3\">$seq</font></pre>";
		}
		
	}else{
		print "<br><br><center><h2><strong>No match</strong></h2></center><br><br>";
	}

?>

<?php
   	include("frames_footer.php");
?> 