<?php
include("connection.php");
//Title before frames_header
print '<title>ANISEED - EST cluster</title>';

include("frames_header.php");
?>

<?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>';
	   include ("frames_footer.php");
		return;
	}
?>


<SCRIPT>
function CheckALL() {
		for(a=0; a<document.form.length; ++a){
			document.form[a].checked=!(document.form[a].checked);
		}
}
</SCRIPT>



<?php

	//connection
	

    $geneID=$_GET["name"];	
	
	$requete2="select count(*) AS compte from \"CLONE_SEQ\" where \"ANISEED_CLUSTER_ID\"='$geneID'";
	$stmt2 = pg_query($c,$requete2);
	if( $row2=pg_fetch_array($stmt2) ){
	    
    	print "<h2><strong><em>Cluster &nbsp;&nbsp;&nbsp;".$geneID."</em></strong></h2>";
    
    	print "<u><strong>Features</strong></u><br>";
        print "<table width=\"100%\"><tr valign=\"top\" align=\"left\"><td width=\"20%\"><strong>Name: </strong></td><td>".$geneID."</td></tr>";
        print "<tr valign=\"top\" align=\"left\"><td><strong>Composition: </strong></td><td>".$row2["compte"]." sequences</td></tr>";        


		$requete="SELECT \"NAME\" FROM \"GENE\" WHERE \"GENE_ID\"='$geneID'";
		$stmt = pg_query($c,$requete);
		
		if( $row=pg_fetch_array($stmt) ){
			print "<tr valign=\"top\" align=\"left\"><td><strong>Corresponding gene: </strong></td><td><a href=\"molecule-gene.php?name=".$row["NAME"]."\">".$row["NAME"]."</a></td></tr>";
        }
		
		$requete="SELECT \"SPECIES\" FROM \"MOL_ENTITY\" WHERE \"MOL_ID\"='$geneID'";
		$stmt = pg_query($c,$requete);
		
		if( $row=pg_fetch_array($stmt) ){
		    $species=$row["SPECIES"];
			print "<tr valign=\"top\" align=\"left\"><td><strong>Species: </strong></td><td>".$species."</td></tr>";
        }
		
		
		print "</table>";		
		
		
		print "<br><center><a href=\"est-expression.php?name=$geneID&species=$species\"><img src=\"pictures/button-library.jpg\" border=\"0\"></a></center>";
        print "<br><br><u><strong>Cluster composition</strong></u><br>";
		
	    $requete="select \"GENBANK_ID\", \"CLONE_NAME\", \"END\" from \"CLONE_SEQ\" where \"ANISEED_CLUSTER_ID\"='$geneID' order by \"CLONE_NAME\"";
	    $stmt = pg_query($c,$requete);
		
        print '<form name="form" action="AllClonesFASTA.php" target="_BLANK" method="POST"><table width="50%" border="0" cellspacing="0" cellpadding="0">';
        print '<tr align="center" valign="middle" bgcolor="#990000"><td>&nbsp;</td><td>Clone name</td><td>Genbank ID</td><td background="pictures/barre-red.jpg">End</td></tr>';
        $count=0;
		while($row=pg_fetch_array($stmt)){
		    ++$count;
	        print "<tr align=\"center\"><td><input name=\"id[]\" type=\"checkbox\" value=\"".$row["GENBANK_ID"]."\"></td><td width=\"33%\"><a href=\"molecule-clone.php?name=".$row["GENBANK_ID"]."\">".$row["CLONE_NAME"]."</a></td><td width=\"33%\"><a href=\"molecule-clone.php?name=".$row["GENBANK_ID"]."\">".$row["GENBANK_ID"]."</a></td><td width=\"33%\">".$row["END"]."</td></tr>";
			if($count>50){
			    //OCICancel($stmt);
				//pg_cancel_query($stmt);
		        break;
		    }
		}
	    print "</table></form>";
 	    
		if($count>50){
		    print "...<a href=\"AllClones.php?name=$geneID\">Get all clones</a><br><br>";
		}
		
		print "&nbsp;&nbsp;&nbsp;<img border=\"0\" src=\"pictures/button-selectALL.jpg\" onClick=\"CheckALL();\">";

		print "&nbsp;&nbsp;&nbsp;<img border=\"0\" src=\"pictures/button-download.jpg\" onClick=\"document.form.submit();\">";
		
		print '<br><br>&nbsp;&nbsp;&nbsp;
		<a href="ClusterFLATexport-molecule-clone.php?name='.$geneID.'">Get all clones in raw text format</a>';
		

	}else{ print "<br><br><center><h2><strong>No match</strong></h2></center><br><br>"; }

?>


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