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


<?


	
	$name=$_GET["name"];
	if(strlen($name)==0){
	    print '<center><h2><strong>Missing parameter: gene name.</strong></h2></center>';
		include("frames_footer.php");
		return;
	}
	
	$name=strtoupper($name);
	        $name=strtoupper($name);
        $name=ereg_replace("[^a-zA-Z0-9]"," ",$name);
		$name=ereg_replace("([a-zA-Z])([0-9])","\\1 \\2",$name);
		$name=ereg_replace("([0-9])([a-zA-Z])","\\1 \\2",$name);
		$name=ereg_replace(" +"," ",$name);
		$name=ereg_replace("^ ","",$name);
		$name=ereg_replace(" $","",$name);

	$species=$_GET["species"];
	


$requete="SELECT A.\"GENE_ID\", A.\"NAME\", B.\"SYNO\", B.\"ORIGIN\", C.\"SPECIES\" FROM \"GENE\" A, \"SYNO\" B, \"MOL_ENTITY\" C WHERE (B.\"SYNO_UPPER_CASE\" LIKE '%$name%') AND (B.\"GENE_ID\"=A.\"GENE_ID\") AND (B.\"GENE_ID\"=C.\"MOL_ID\") ";


	
			if( strlen($species)>1 ){
				$requete.=" AND (C.\"SPECIES\" ='$species') ";
			}
			$requete.="order by A.\"GENE_ID\"";
			
			$stmt = pg_query($c,$requete);
			
			print "<h2><strong><em>Matching records:</em></strong> </h2>";
			print '<table width="99%" border="0" cellspacing="0" cellpadding="0">';
			print '<tr align="center" valign="middle" bgcolor="#990000"><td>Gene ID</td><td>Gene name</td><td background="pictures/barre-red.jpg">Species</td></tr>';
			$count=0;
			$last="";
			while( $row=pg_fetch_array($stmt) ){
				
				$nname=$row["NAME"];
				$nspecies=$row["SPECIES"];
				if($last != $row["NAME"]){
					$last = $row["NAME"];
					++$count;
					print '<tr valign="top"><td><hr size="1"></td><td><hr size="1"></td><td><hr size="1"></td></tr>';
				}else{
					$nname="";
					$nspecies="";
				}
				
				print "<tr align=\"center\" valign=\"middle\" >"."<td><a href=\"go2.php?name=".$row["NAME"]."\">".$nname."</a></td><td><a href=\"go2.php?name=".$row["NAME"]."\">".$row["SYNO"]."</a>";
				if($row["ORIGIN"]=="user-JGI")
					print '*';
				print "</td><td>".$nspecies."</td></tr>";
				
				if($count>500){
					//OCICancel($stmt);
					pg_cancel_query($c);
					break;
				}
			}
			print '<tr valign="top"><td><hr size="1"></td><td><hr size="1"></td><td><hr size="1"></td></tr>';
			print '</table>';
			
			if($count==0){
				print "<br><br><center><h2><strong>No match</strong></h2></center><br><br>";
			}else{
				print "<br><center>$count result(s)</center><br>";
				print "</center><br><br>* Manual annotation<center>";
			}
			
			if($count>500){
				print "...<br>More than 500 results has been returned.<br>Please refine your query";
			}

?>


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


