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

<SCRIPT>
function ZoomIn() {
		for(a=0;a<document.images.length;++a){
			if( (document.images[a].name=="pics") && (document.images[a].width+20 < 1000) )
				document.images[a].width+=20;
		}
}
function ZoomOut() {
		for(a=0;a<document.images.length;++a){
			if( (document.images[a].name=="pics") && (document.images[a].width-20 > 0) )
				document.images[a].width-=20;
		}
}
</SCRIPT>

<h2><strong><em>In situ search results.</em></strong></h2>

<!--Les Zooms etaient ici -->



<?php
	
	//connection
	//include("connection.php");
	
	//variables pour le systeme page suiv/prec
	if( isset($_GET["option"]) ) $option=$_GET["option"];
	if( isset($_GET["offset"]) ) $offset=$_GET["offset"];
	if( isset($_GET["nbMAX"])  ) $nbMAX=$_GET["nbMAX"];
	
	if(! isset($option)) $option= 1;
	if(! isset($offset)) $offset= 0;
	if(! isset($nbMAX)) $nbMAX= 20;
	
	
	/////////////////////////////////////////////////////////////////////////////////
	////////////////////////////////////requete//////////////////////////////////////
	/////////////////////////////////////////////////////////////////////////////////
	
	
	//recup species
	if(isset($_GET["species"]))
		$species = $_GET["species"];
	
	//recup regions	
	/*Test sur la selection d'une partie anatomique dans la page précédente*/
	if ($_GET["idanat"]=="undefined:") {print "<br><br><center><h2><strong>Error, please select an anatomical part.</strong></h2></center><br><br>"; include ("frames_footer.php");return;}

	if( (strlen($_GET["idanat"])>1)&&($_GET["fatemode"]==0) ){
		$sql_region='';
		$tabanat=split(":",$_GET["idanat"]);
		array_pop($tabanat);
		
		if($_GET["BOOLanat"]==1){//and
			//signifie que l'on cherche aussi les parents des anat fournis			if($_GET["xref"]==1)
			{
/* SIMULATION D'UNE REQUETE SUR HIERARCHIE PAR UNE PROCEDURE DE REQUETES RECURSIVES */
$IN1="";
function select_recursif_descendant_2($conn,$start,$res)
{
global $IN1;

if ($start!='')
$requete2="SELECT * FROM \"ANAT_ENTITY\" WHERE \"ANAT_ID\"= $start ";
else return;

$stmt2=pg_query($conn,$requete2);
while($row2=pg_fetch_array($stmt2))
	{
	$IN1.=$row2["ANAT_ID"].",";
	$res=select_recursif_descendant_2($conn,$row2["CHILD_OF"],$res);
	}
return $res;
}
/* FIN DE LA SIMULATION */

				for($a=0;$a<count($tabanat);++$a)
					{
					$IN1="";
					$res=select_recursif_descendant_2($c,$tabanat[$a],$res);
					//$IN1=substr($IN1,0,strlen($IN1)-1);
					$IN1.=$tabanat[$a];
					
					if ($IN1=="") $IN1="0";	/*Cas du IN vide*/
					$sql_region.="INTERSECT SELECT \"IN_SITU_ID\" FROM \"TARGET\" WHERE \"REGION_ID\" IN(".
					$IN1.") ";
					}
		/*IN1=SELECT ANAT_ID FROM CIONA_DESIGN.ANAT_ENTITY CONNECT BY ANAT_ID = PRIOR CHILD_OF START WITH ANAT_ID= $tabanat[$a] */
			
			}
			//signifie que l'on cherche aussi les enfants des anat fournis			else if($_GET["xref"]==2)
			{
/* SIMULATION D'UNE REQUETE SUR HIERARCHIE PAR UNE PROCEDURE DE REQUETES RECURSIVES */
$IN2="";
function select_recursif_descendant($conn,$start,$res)
{
global $IN2;

if ($start!='')
$requete2="SELECT * FROM \"ANAT_ENTITY\" WHERE \"CHILD_OF\"= $start ";
else return;

$stmt2=pg_query($conn,$requete2);
while($row2=pg_fetch_array($stmt2))
	{
	$IN2.=$row2["ANAT_ID"].",";
	$res=select_recursif_descendant($conn,$row2["ANAT_ID"],$res);
	}
return $res;
}
/* FIN DE LA SIMULATION */





				for($a=0;$a<count($tabanat);++$a)
					{
					$IN2="";
					$res=select_recursif_descendant($c,$tabanat[$a],$res);
					//$IN2=substr($IN2,0,strlen($IN2)-1);
					$IN2.=$tabanat[$a];
					if ($IN2=="") $IN2="0"; /*Cas du IN vide*/
					$sql_region.="INTERSECT SELECT \"IN_SITU_ID\" FROM \"TARGET\" WHERE \"REGION_ID\" IN(".$IN2.") ";
					}






/*SELECT ANAT_ID FROM CIONA_DESIGN.ANAT_ENTITY CONNECT BY  CHILD_OF = PRIOR ANAT_ID START WITH ANAT_ID= $tabanat[$a]*/

			}
			//signifie que l'on cherche le terme exact			else{
				for($a=0;$a<count($tabanat);++$a){
					$sql_region.="INTERSECT SELECT \"IN_SITU_ID\" FROM \"TARGET\" WHERE \"REGION_ID\" = $tabanat[$a]";
				}
			}
			
			if($_GET["only"]==1){  //gestion du only  //avec le and on veut autant de trucs marqu�que de trucs selectionn�mais pas plus.
			    /*$sql_region.=" intersect select \"IN_SITU_ID\" from (select \"TARGET.*, count(*) over (partition by in_situ_id) count from CIONA_DESIGN.TARGET) where count = ".(count($tabanat));*/
			}
			
		}else{//or
			$zz=join(",",$tabanat);
			//if($_GET["only"]==2)  //gestion de l'option "not stained"
			//    $sql_region="INTERSECT SELECT IN_SITU_ID FROM CIONA_DESIGN.TARGET WHERE NOT EXIST( REGION_ID IN(".$zz.") )";
		    //else
			
			$sql_region=" INTERSECT (SELECT \"IN_SITU_ID\" FROM \"TARGET\" WHERE \"REGION_ID\" IN (".$zz.") ";
			if($_POST["only"]==1){  //gestion du only  //avec le or on veut juste l'un des trucs selectionn�comme marqu�ou une combinaison mais pas plus.
			    $sql_region.=" EXCEPT SELECT \"IN_SITU_ID\" FROM \"TARGET\" WHERE \"REGION_ID\" NOT IN (".$zz.")";
			}
			$sql_region.=")";
			
			/*
			$sql_region="INTERSECT SELECT IN_SITU_ID FROM CIONA_DESIGN.TARGET WHERE ( REGION_ID IN(".$zz.") )";
			
			if($_GET["only"]==1){  //gestion du only  //avec le or on veut juste l'un des trucs selectionn�de marqu�mais pas plus.
			    $sql_region.=" intersect select IN_SITU_ID from (select CIONA_DESIGN.TARGET.*, count(*) over (partition by in_situ_id) count from CIONA_DESIGN.TARGET) where count = 1";
			}
			*/
		    
		}
		
	}

	
	
	// Les Fates
$sql_fate="";
$tabfate="";
if(isset($_POST["fate"]))
$tabfate=$_POST["fate"];

$tabfatelist="";
if(is_array($tabfate)){
$tabfatelist=join("','",$tabfate);
}else{
$tabfatelist=$tabfate;
//$tabfate=split("','",$tabfatelist);
}
//print $tabfate[0];
if((strlen($tabfatelist)>0)&&($_POST["fatemode"]==1))
{ 
$sql_fate="INTERSECT(SELECT \"IN_SITU_ID\" FROM \"TARGET\" WHERE \"REGION_ID\" in (select \"ANAT_ID\" from \"FATE\" where \"KEYWORDS\" in ('".$tabfatelist."')))";
}
	
	
	
	//get dev stage id
	//ne s'utilise qu'en l'absence d'anat_id
	//if( (strlen($_GET["selectediddev"])>1)&&((! strlen($sql_region)>0)||$_GET["only"]==2) ){
	if( (strlen($_GET["selectediddev"])>1)&&(! strlen($sql_region)>0) ){
		$tabdev=split(":",$_GET["selectediddev"]);
		array_pop($tabdev);
		$zz=join(",",$tabdev);
		
		$sql_dev_stage="INTERSECT SELECT \"IN_SITU_ID\" FROM \"IN_SITU\" WHERE ( \"DEV_STAGE_ID\" IN(".$zz.") )";
	}
	
	//check authors
	if( strlen($_GET["author"])>1 ){
                $author=eregi_replace(" : ",":",$_GET["author"]);
		$author=split(":",$author);
		$zz=join("','",$author);
		$zz=strtoupper($zz);
		
		$sql_author="INTERSECT SELECT \"IN_SITU_ID\" FROM \"IN_SITU\" WHERE \"IN_SITU_ID\" IN(  select \"BIO_ID\" from \"ENTRY_ORIGIN\" where \"AUTHOR_ID\" in (select \"AUTHOR_ID\" from \"AUTHOR\" where UPPER(\"NAME\") in ('".$zz."') ) ) ";
	
	}

	//check annotator

	if( strlen($_GET["annotator"])>1 ){
		$annotator=split(":",$_GET["annotator"]);
		$zz=join("','",$annotator);
		$zz=strtoupper($zz);
		
		$sql_annotator="INTERSECT SELECT \"IN_SITU_ID\" FROM \"IN_SITU\" WHERE \"IN_SITU_ID\" IN(  select \"BIO_ID\" from \"ENTRY_ORIGIN\" where \"ANNOTATOR_ID\" in (select \"AUTHOR_ID\" from \"AUTHOR\" where UPPER(\"NAME\") like ('%$zz%') ) ) ";
	}

	//check pmid

	if( strlen($_GET["pmid"])>1 ){
		$pmid=split(":",$_GET["pmid"]);
		$zz=join("','",$pmid);
		$zz=strtoupper($zz);
		
		$sql_pmid="INTERSECT SELECT \"BIO_ID\" AS \"IN_SITU_ID\" FROM \"REFERENCE\" where \"PUBMED_ID\"='$zz' ";
	}


	
	//AJOUT
	//Check date

	if (strlen($_GET["datefrom"])>0)
		{
		if (strlen($_GET["dateto"])>0)
			{
			$sql_date="INTERSECT SELECT \"IN_SITU_ID\" FROM \"IN_SITU\" WHERE \"IN_SITU_ID\" IN ( select \"BIO_ID\" from \"ENTRY_ORIGIN\" where \"ENTRY_DATE\" BETWEEN '".$_GET["datefrom"]."' and '".$_GET["dateto"]."') ";

			}
		}




	
	//get targets
	if(strlen($_GET["target"])>0){
	
		$targetTMP = split(":",strtoupper($_GET["target"]));
		
		if(count($targetTMP)>100){
		    print "<br><br><strong>ERROR:</strong> due to performance reasons, you cannot search for more than 100 molecules";
		    include ("frames_footer.php");
			return;
		}
		
		$sql_target='';
		if($_GET["BOOLtarg"]==1){//and

			if($_GET["MOLtype"]==2){ //si c un gene -> recup des clones correspondant
			/*
				for ($a=0; $a < count($targetTMP); ++$a){
                    $sql_target.=" INTERSECT SELECT IN_SITU_ID FROM CIONA_DESIGN.TARGET WHERE TARGET_ID IN ( select B.clone_id from ciona_design.clone_seq A, ciona_design.clone B where (A.clone_name=B.clone_name) and A.cluster_id=(select cluster_id from ciona_design.clustering where gene_id=(select gene_id from ciona_design.gene where name='$targetTMP[$a]')) ) OR TARGET_ID IN ( select clone_seq_id from ciona_design.clone_seq where cluster_id=(select cluster_id from ciona_design.clustering where gene_id=(select gene_id from ciona_design.gene where name='$targetTMP[$a]')) )";
				}
			*/
			
				////nouvelle version pour utiliser le clustering maison
				for ($a=0; $a < count($targetTMP); ++$a){
									
                    /*
					$sql_target.=" INTERSECT
					 SELECT IN_SITU_ID
					  FROM CIONA_DESIGN.TARGET
					   WHERE TARGET_ID IN (
					    select B.clone_id from ciona_design.clone_seq A, ciona_design.clone B where A.clone_name=B.clone_name and A.aniseed_cluster_id=(select gene_id from ciona_design.gene where upper(name)='$targetTMP[$a]') )
						 OR TARGET_ID IN ( select clone_seq_id from ciona_design.clone_seq where aniseed_cluster_id=(select gene_id from ciona_design.gene where upper(name)='$targetTMP[$a]'))
						  OR TARGET_ID IN (select gene_id from ciona_design.gene where upper(name)='$targetTMP[$a]')";
                    */
					
					$sql_target.=" INTERSECT
					 SELECT \"IN_SITU_ID\"
					  FROM \"TARGET\"
					   WHERE \"TARGET_ID\" IN ( 
					   select B.\"CLONE_ID\" from \"CLONE_SEQ\" A, \"CLONE\" B where A.\"CLONE_NAME\"=B.\"CLONE_NAME\" and A.\"ANISEED_CLUSTER_ID\"=(select \"GENE_ID\" from \"GENE\" where upper(\"NAME\")='$targetTMP[$a]') 
					   UNION select \"CLONE_SEQ_ID\" from \"CLONE_SEQ\" where \"ANISEED_CLUSTER_ID\"=(select \"GENE_ID\" from \"GENE\" where upper(\"NAME\")='$targetTMP[$a]')
					   UNION select \"GENE_ID\" from \"GENE\" where upper(\"NAME\")='$targetTMP[$a]')";

				}
			
			} else {
                //if is a clone or regulatory region construct... just do it!
				for ($a=0; $a < count($targetTMP); ++$a){
								
				
	 				$sql_target.=" INTERSECT SELECT \"IN_SITU_ID\" FROM \"TARGET\" WHERE \"TARGET_ID\" IN (SELECT \"MOL_ID\" FROM \"MOL_ENTITY\" WHERE (upper(\"NAME\")='$targetTMP[$a]' OR upper(\"FULL_NAME\")='$targetTMP[$a]'))";
					if($_GET["MOLtype"]==2){					  
					 	$sql_target.=" AND \"TYPE\"='construction')";
					} else {
						$sql_target.=")";  
					}
				}
			}
			
		}else{//or
			
			if($_GET["MOLtype"]==2){ //si c un gene -> recup des clones correspondant
				$name='';
			    /*	
				for ($a=0; $a < count($targetTMP); ++$a){
					if($a==0)
						$name.=" (TARGET_ID IN ( select B.clone_id from ciona_design.clone_seq A, ciona_design.clone B where (A.clone_name=B.clone_name) and A.cluster_id=(select cluster_id from ciona_design.clustering where gene_id=(select gene_id from ciona_design.gene where upper(name)='$targetTMP[$a]')) ) OR TARGET_ID IN ( select clone_seq_id from ciona_design.clone_seq where cluster_id=(select cluster_id from ciona_design.clustering where gene_id=(select gene_id from ciona_design.gene where upper(name)='$targetTMP[$a]')) )) ";
					else
						$name.=" OR (TARGET_ID IN ( select B.clone_id from ciona_design.clone_seq A, ciona_design.clone B where (A.clone_name=B.clone_name) and A.cluster_id=(select cluster_id from ciona_design.clustering where gene_id=(select gene_id from ciona_design.gene where upper(name)='$targetTMP[$a]')) ) OR TARGET_ID IN ( select clone_seq_id from ciona_design.clone_seq where cluster_id=(select cluster_id from ciona_design.clustering where gene_id=(select gene_id from ciona_design.gene where upper(name)='$targetTMP[$a]')) )) ";
				}
				$sql_target=" INTERSECT SELECT IN_SITU_ID FROM CIONA_DESIGN.TARGET WHERE ".$name;
				*/
				
				////nouvelle version pour utiliser le clustering maison
                for ($a=0; $a < count($targetTMP); ++$a){				
				
					if($a==0)
						$name.=" (\"TARGET_ID\" IN ( 
						select B.\"CLONE_ID\" from \"CLONE_SEQ\" A, \"CLONE\" B where A.\"CLONE_NAME\"=B.\"CLONE_NAME\" and A.\"ANISEED_CLUSTER_ID\"=(select \"GENE_ID\" from \"GENE\" where upper(\"NAME\")='$targetTMP[$a]')
						UNION select \"CLONE_SEQ_ID\" from \"CLONE_SEQ\" where \"ANISEED_CLUSTER_ID\"=(select \"GENE_ID\" from \"GENE\" where upper(\"NAME\")='$targetTMP[$a]')
						UNION select \"GENE_ID\" from \"GENE\" where upper(\"NAME\")='$targetTMP[$a]'
						";
						//$name.=" (TARGET_ID IN ( select B.clone_id from ciona_design.clone_seq A, ciona_design.clone B where A.clone_name=B.clone_name and A.aniseed_cluster_id=(select gene_id from ciona_design.gene where upper(name)='$targetTMP[$a]') ) OR TARGET_ID IN ( select clone_seq_id from ciona_design.clone_seq where aniseed_cluster_id=(select gene_id from ciona_design.gene where upper(name)='$targetTMP[$a]')) OR TARGET_ID IN (select gene_id from ciona_design.gene where upper(name)='$targetTMP[$a]') )";
					else
						$name.= "UNION select B.\"CLONE_ID\" from \"CLONE_SEQ\" A, \"CLONE\" B where A.\"CLONE_NAME\"=B.\"CLONE_NAME\" and A.\"ANISEED_CLUSTER_ID\"=(select \"GENE_ID\" from \"GENE\" where upper(\"NAME\")='$targetTMP[$a]') 
						UNION select \"CLONE_SEQ_ID\" from \"CLONE_SEQ\" where \"ANISEED_CLUSTER_ID\"=(select \"GENE_ID\" from \"GENE\" where upper(\"NAME\")='$targetTMP[$a]')
						UNION select \"GENE_ID\" from \"GENE\" where upper(\"NAME\")='$targetTMP[$a]'
						";
						//$name.=" OR (TARGET_ID IN ( select B.clone_id from ciona_design.clone_seq A, ciona_design.clone B where A.clone_name=B.clone_name and A.aniseed_cluster_id=(select gene_id from ciona_design.gene where upper(name)='$targetTMP[$a]') ) OR TARGET_ID IN ( select clone_seq_id from ciona_design.clone_seq where aniseed_cluster_id=(select gene_id from ciona_design.gene where upper(name)='$targetTMP[$a]')) OR TARGET_ID IN (select gene_id from ciona_design.gene where upper(name)='$targetTMP[$a]') )";
				
				}
				$sql_target=" INTERSECT SELECT \"IN_SITU_ID\" FROM \"TARGET\" WHERE ".$name."))";
                
			}else{
                //si c'est un clone
				$name='';
				for ($a=0; $a < count($targetTMP); ++$a){
								
					if($a==0){					  										  
						$name.=" (\"TARGET_ID\" IN (SELECT \"MOL_ID\" FROM \"MOL_ENTITY\" WHERE (upper(\"NAME\")='$targetTMP[$a]' OR upper(\"FULL_NAME\")='$targetTMP[$a]') ";						
						if($_GET["MOLtype"]==2){						  
					 		$name.=" AND \"TYPE\"='construction'))";
						} else {
							$name.="))";  
						}	

						
						//$name.=" ";  
					} else {					  
						$name.=" OR (\"TARGET_ID\" IN (SELECT \"MOL_ID\" FROM \"MOL_ENTITY\" WHERE (upper(\"NAME\")='$targetTMP[$a]' OR upper(\"FULL_NAME\")='$targetTMP[$a]') ";						
						if($_GET["MOLtype"]==2){						  
						 	$name.=" AND \"TYPE\"='construction'))";
						} else {
							$name.="))";  
						}
					}

///////////// BRICOLAGE STABLE_ID... 						
						$name.=" OR (\"TARGET_ID\" IN (SELECT \"CONSTRUCTION_ID\" FROM \"CONSTRUCTION\" WHERE upper(\"STABLE_ID\")='$targetTMP[$a]' )) ";	
						
///////////// BRICOLAGE STABLE_ID... 

				}
				$sql_target=" INTERSECT SELECT \"IN_SITU_ID\" FROM \"TARGET\" WHERE ".$name;
			}
			
		}
	}
	
	
	//recup des mutants
	if((strlen($_GET["mutant"])>0)&&($_GET["BOOLmut"]<2)){
		$mutantTMP = split(":",strtoupper($_GET["mutant"]));
		$sql_mutant='';
		if($_GET["BOOLmut"]==1){//and
			for ($a=0; $a < count($mutantTMP); ++$a){
				$sql_mutant.=" INTERSECT SELECT \"IN_SITU_ID\" FROM \"MUTANT\" WHERE \"BIO_ID\" IN (SELECT \"MOL_ID\" FROM \"MOL_ENTITY\" WHERE upper(\"NAME\")='$mutantTMP[$a]' OR upper(\"FULL_NAME\")='$mutantTMP[$a]')";
			}
		}else if($_GET["BOOLmut"]==0){//or
			$name='';
			for ($a=0; $a < count($mutantTMP); ++$a){
				if($a==0)
					$name.=" (\"BIO_ID\" IN (SELECT \"MOL_ID\" FROM \"MOL_ENTITY\" WHERE(upper(\"NAME\")='$mutantTMP[$a]' OR upper(\"FULL_NAME\")='$mutantTMP[$a]'))) ";
				else
					$name.=" OR (\"BIO_ID\" IN (SELECT \"MOL_ID\" FROM \"MOL_ENTITY\" WHERE(upper(\"NAME\")='$mutantTMP[$a]' OR upper(\"FULL_NAME\")='$mutantTMP[$a]'))) ";
			}
			$sql_mutant=" INTERSECT SELECT \"IN_SITU_ID\" FROM \"MUTANT\" WHERE ".$name;
		}
		
	}else if($_GET["BOOLmut"]==2){//any
		    //$sql_mutant=" INTERSECT select in_situ_id from ciona_design.in_situ where wild_type='n'";
			$sql_mutant=" INTERSECT select \"IN_SITU_ID\" from \"MUTANT\"";
	}else if($_GET["BOOLmut"]==3){//none
		    //$sql_mutant=" INTERSECT select in_situ_id from ciona_design.in_situ where wild_type='y'";
			$sql_mutant=" INTERSECT select \"IN_SITU_ID\" from \"IN_SITU\" where \"IN_SITU_ID\" not in (select \"IN_SITU_ID\" from \"MUTANT\")";
	}
	
	
	//recup des manip d'embryon
	$sql_manip='';
	if($_GET["BOOLmanip"]==1){
	    $sql_manip.=" INTERSECT select \"IN_SITU_ID\" from \"EMBRYO_MANIP\"";
	}else if($_GET["BOOLmanip"]==2){
		$sql_manip=" INTERSECT select \"IN_SITU_ID\" from \"IN_SITU\" where \"IN_SITU_ID\" not in (select \"IN_SITU_ID\" from \"EMBRYO_MANIP\")";
	}
	
	////////////////////////////////
	//MEGA requete //
	////////////////////////////////
	
	
	
	//$requete="SELECT IN_SITU_ID FROM CIONA_DESIGN.IN_SITU ";
	$requete="SELECT \"IN_SITU_ID\" FROM \"IN_SITU\" "; //WHERE (\"CHECKED\"='y') AND (\"PRIVATE\" = 'n') ";
	//$requete="SELECT \"IN_SITU_ID\" FROM \"IN_SITU\" WHERE (\"CHECKED\"='y') AND (\"PRIVATE\" = 'n') ";


	
////////////////////////// AJOUT POUR QUE LE CURATOR NE LISE PAS LES ISHS PRIVEES /////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/*
$requete0="SELECT \"IS_CURATOR\",\"IS_ADMIN\" from \"AUTHOR\" where \"AUTHOR_ID\"='".$_SESSION["curationauthor"]."'";
$stmt0=pg_query($c,$requete0);
$row0=pg_fetch_array($stmt0);





*/
////// ENLEVE A CAUSE DU BUG POUR L'AFFICHAGE POUR LE CURATOR
/*
if (($row0["IS_CURATOR"]=="y") && ($row0["IS_ADMIN"]=="y"))
	{
	//$_GET["private"]=1;

		$sql_conf2="INTERSECT (SELECT \"BIO_ID\" from \"ENTRY_ORIGIN\" where \"AUTHOR_ID\"='".$_SESSION["curationauthor"]."' OR \"ANNOTATOR_ID\"='".$_SESSION["curationauthor"]."' OR \"CURATOR_ID\"='".$_SESSION["curationauthor"]."')";
		$requete.=$sql_conf2;
	
	}
*/
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


////// DU COUP le _GET private ne sert a rien en dessous si on est le curator !! //////////////////////////////////////////////////////////////////
	/*if($_GET["private"]==1)
	    $requete.=" WHERE \"PRIVATE\"='n' ";*/

	if($_GET["only_constructs"]==1)
	    $requete.=" INTERSECT (SELECT DISTINCT \"IN_SITU_ID\" FROM \"TARGET\", \"MOL_ENTITY\" WHERE \"TARGET_ID\"=\"MOL_ID\" AND \"MOL_ENTITY\".\"TYPE\"='construction')";

	if((strlen($_GET[idanat]==0))&&(strlen($species)>0))
		$requete.=" INTERSECT SELECT \"IN_SITU_ID\" FROM \"IN_SITU\" WHERE \"SPECIES\" = '$species' ";
//		$requete.=" WHERE SPECIES = '$species' ";
	
	
	if(strlen($sql_dev_stage)>0)
		$requete.= $sql_dev_stage;
	
	if(strlen($sql_region)>0)
		$requete .= $sql_region;
	
	if(strlen($sql_fate)>0)
	    $requete .= $sql_fate;

	if(strlen($sql_author)>0)
		$requete .= $sql_author;

	if (strlen($sql_annotator)>0)
		$requete .=$sql_annotator;
	
	if (strlen($sql_pmid)>0)
		$requete .=$sql_pmid;
//AJOUT
	if (strlen($sql_date)>0)
		$requete .= $sql_date;


	if(strlen($sql_target)>0)
		$requete.= $sql_target; 
		
	if(strlen($sql_mutant)>0)
		$requete.= $sql_mutant;
		
	if(strlen($sql_manip)>0)
		$requete .= $sql_manip;	
	

/////////// AJOUT POUR LA CONFIDENTIALITE DES DONNEES //////////

if (strlen($_SESSION["curationauthor"])==0)
	{
	print "<br><br><center>You have to be logged into the system ! Click on the \"Login\" menu on the left side of the page</center><br><br>";
	include ("frames_footer.php");
	return;
	}






/*
$requete0="SELECT \"IS_CURATOR\",\"IS_ADMIN\" from \"AUTHOR\" where \"AUTHOR_ID\"='".$_SESSION["curationauthor"]."'";
$stmt0=pg_query($c,$requete0);
$row0=pg_fetch_array($stmt0);

$sql_conf="";

if (($row0["IS_CURATOR"]=="y") && ($row0["IS_ADMIN"]=="n"))
	{
	//// It's an annotator !!

	$sql_conf="INTERSECT SELECT \"BIO_ID\" from \"ENTRY_ORIGIN\" where \"AUTHOR_ID\"='".$_SESSION["curationauthor"]."' OR \"ANNOTATOR_ID\"='".$_SESSION["curationauthor"]."'";

///// NOUVELLE MODIF POUR QUE LE LABO VOIT LES ISHS DONT l'AUTHOR EST DU LABO, OU L'ANNOTATOR EST DU LABO
	/*$sql_conf="INTERSECT SELECT \"BIO_ID\" from \"ENTRY_ORIGIN\" where \"AUTHOR_ID\"='".$_SESSION["curationauthor"]."' OR \"ANNOTATOR_ID\"='".$_SESSION["curationauthor"]."' 
	OR \"AUTHOR_ID\" in (select \"AUTHOR_ID\" from \"AUTHOR\" where \"TEAM\"=(select \"TEAM\" from \"AUTHOR\" where \"AUTHOR_ID\"='".$_SESSION["curationauthor"]."'))
	OR \"ANNOTATOR_ID\" in (select \"AUTHOR_ID\" from \"AUTHOR\" where \"TEAM\"=(select \"TEAM\" from \"AUTHOR\" where \"AUTHOR_ID\"='".$_SESSION["curationauthor"]."')
	)";
	$requete.=$sql_conf;

///// AJOUT /////

	//$requete.=" INTERSECT SELECT \"IN_SITU_ID\" from \"IN_SITU\" where \"PRIVATE\"='n' and \"CHECKED\"='y' ";

////////////////
	}
*/


/*
///// ENCORE UN AJOUT CAR LE CURATOR PEUT VOIR LES ISHS PRIVATE
if (($row0["IS_CURATOR"]=="y") && ($row0["IS_ADMIN"]=="y"))
	{
	$sql_conf="INTERSECT SELECT \"BIO_ID\" from \"ENTRY_ORIGIN\" where \"AUTHOR_ID\"='".$_SESSION["curationauthor"]."' OR \"ANNOTATOR_ID\"='".$_SESSION["curationauthor"]."' OR \"CURATOR_ID\"='".$_SESSION["curationauthor"]."'";
	//$sql_conf="INTERSECT SELECT \"BIO_ID\" from \"ENTRY_ORIGIN\" where \"AUTHOR_ID\"='".$_SESSION["curationauthor"]."' OR \"ANNOTATOR_ID\"='".$_SESSION["curationauthor"]."'";
	$requete.=$sql_conf;


	//$requete.=" INTERSECT SELECT \"IN_SITU_ID\" from \"IN_SITU\" where \"PRIVATE\"='n' and \"CHECKED\"='y' ";

	}
*/

//print $requete."<br>";

/////// TEST AJOUT /////////


	//$requete.="INTERSECT SELECT \"IN_SITU_ID\" FROM \"IN_SITU\" WHERE \"CHECKED\"='y' and \"PRIVATE\"='n'";

////////////////////////////////////////////////////////////////



	if($_GET["news"]==1)
	    $requete.=" INTERSECT SELECT \"IN_SITU_ID\" FROM \"IN_SITU\" WHERE \"CHECKED\"='n'";

	if ($_GET["being"]==1)
		$requete.=" INTERSECT SELECT \"IN_SITU_ID\" from \"IN_SITU\" where \"BEING_CURATED\"='y'";



$requete.=" INTERSECT (SELECT \"BIO_ID\" from \"ENTRY_ORIGIN\" where \"AUTHOR_ID\"='".$_SESSION["curationauthor"]."' OR \"ANNOTATOR_ID\"='".$_SESSION["curationauthor"]."' OR \"AUTHOR_ID\" in (select \"AUTHOR_ID\" from \"AUTHOR\" where \"TEAM\"=( select \"TEAM\" from \"AUTHOR\" where \"AUTHOR_ID\"='".$_SESSION["curationauthor"]."')) OR \"ANNOTATOR_ID\" in (select \"AUTHOR_ID\" from \"AUTHOR\" where \"TEAM\"=( select \"TEAM\" from \"AUTHOR\" where \"AUTHOR_ID\"='".$_SESSION["curationauthor"]."'))";





//// PEUT-ETRE A ENLEVER ----->

$requete0="SELECT \"IS_CURATOR\",\"IS_ADMIN\" from \"AUTHOR\" where \"AUTHOR_ID\"='".$_SESSION["curationauthor"]."'";
$stmt0=pg_query($c,$requete0);
$row0=pg_fetch_array($stmt0);

if ($row0["IS_ADMIN"]=="y") 
{
$requete.= "UNION SELECT \"IN_SITU_ID\" from \"IN_SITU\" where \"PRIVATE\"='n'"; 
}
else
{
$requete.=" UNION SELECT \"IN_SITU_ID\" from \"IN_SITU\" where \"PRIVATE\"='n' and \"CHECKED\"='y'";
}

//// <-----------


$requete.=") ";




	if(strlen($_GET["Order"])>0){
		if ($_GET["Order"]=="SPECIES")
		    $requete = "SELECT \"IN_SITU_ID\" FROM \"IN_SITU\" A, \"DEV_STAGE\" B  WHERE \"IN_SITU_ID\" IN ($requete) and (A.\"DEV_STAGE_ID\"=B.\"DEV_STAGE_ID\") ORDER BY B.\"SPECIES\", B.\"DEV_PERCENT\",ascii(chr(ascii(A.\"WILD_TYPE\")+145))";
			//$requete = "SELECT IN_SITU_ID FROM CIONA_DESIGN.IN_SITU WHERE IN_SITU_ID IN ($requete) ORDER BY SPECIES, DEV_STAGE_ID, IN_SITU_ID";
		else
		    $requete = "SELECT \"IN_SITU_ID\" FROM \"IN_SITU\" A, \"DEV_STAGE\" B WHERE \"IN_SITU_ID\" IN ($requete) and (A.\"DEV_STAGE_ID\"=B.\"DEV_STAGE_ID\") ORDER BY B.\"DEV_PERCENT\", ascii(chr(ascii(A.\"WILD_TYPE\")+145)) ,B.\"SPECIES\"";
			
	} 
//RAJOUT
	else {
$requete = "SELECT \"IN_SITU_ID\" FROM \"IN_SITU\" A, \"DEV_STAGE\" B WHERE \"IN_SITU_ID\" IN ($requete) and (A.\"DEV_STAGE_ID\"=B.\"DEV_STAGE_ID\") ORDER BY B.\"DEV_PERCENT\",ascii(chr(ascii(A.\"WILD_TYPE\")+145)) ,B.\"SPECIES\"";

}



	
	//echo "<br>".$requete;

	
	
	
	
	
	
	
	
	
	
	
	/////////////////////////////////////////////////////////////////////////////////
    /////////////////////////////lecture du resultat/////////////////////////////////
    /////////////////////////////////////////////////////////////////////////////////

//Calcul sur le nombre de pages et le nombre de résultat
print '<div align="right"><small>';
$stmt = pg_query($c,$requete);

$cpt=$offset+20; //Pour que le nombre de page commence a 1*/
$num_rows=pg_num_rows($stmt);
$number_of_pages=ceil($num_rows/20);
$current_page=$cpt/20;


/////////////////////////////////

//Affichage du nombre de resultats
if (pg_num_rows($stmt)<=1) print "Result 1 to $num_rows of $num_rows record ";
else {
$offset_plus_un=$offset+1;
	if ($cpt>$num_rows) print "Results $offset_plus_un to $num_rows of $num_rows records ";
	else print "Results $offset_plus_un to $cpt of $num_rows records ";
}
//Affichage du temps d'execution de la page

$execute = microtime();
print "(".number_format($execute,2);
echo "s)";
print "</small>";

print "</center></div>";


//Le Zoom a été déplacé ici au lieu du début
print "
<img src=\"pictures/zoom-in.gif\" onClick=\"ZoomIn()\" border=\"0\">
<img src=\"pictures/zoom-out.gif\" onClick=\"ZoomOut()\" border=\"0\">
";

	
   // Start of table and column headings (ID and Name)
   print "<center><TABLE CELLSPACING=\"0\" BORDER=\"0\" WIDTH=\"99%\">\n";
   
   // Loop through results
   $count=0;
   while( ($row=pg_fetch_array($stmt)) && ($count < $offset+$nbMAX) )
   {  
	  if($count++ >= $offset){
   	    print "  <TR><TD>\n";
		$id=$row["IN_SITU_ID"];
	    
		$requete = "SELECT C.\"LOGO\",A.\"BEING_CURATED\",A.\"PRIVATE\", A.\"WILD_TYPE\", A.\"CHECKED\", A.\"IM_COMMENTS\", B.\"NAME\" AS \"DEV\", A.\"SPECIES\" FROM \"IN_SITU\" A, \"DEV_STAGE\" B, \"AUTHOR\" C, \"ENTRY_ORIGIN\" D where (D.\"BIO_ID\"=$id) AND (D.\"AUTHOR_ID\"=C.\"AUTHOR_ID\") AND (A.\"IN_SITU_ID\" = $id) AND (A.\"DEV_STAGE_ID\"=B.\"DEV_STAGE_ID\")";
		//print $requete;
		$resultset = pg_query($c,$requete);
		$row2=pg_fetch_array($resultset);
		
		//couleur en fonction de wild type ou non
		$wild=$row2["WILD_TYPE"];
		if($wild=='n'){$color='#CCCC99';}else{$color='#FFFFCC';}
		
		//espece & stade de devt. & logo
		print "<TABLE CELLSPACING=\"0\" BORDER=\"0\" bgcolor=\"$color\" WIDTH=\"100%\" style=\"color:black\"><TR>\n";		
		print '<td><table width="100%" border="0" cellspacing="0" cellpadding="0" style="color:black">'
		  .'<tr>'
		  ."<td align=\"left\" >";
		if(strlen($row2["LOGO"])>0)
			print "<img align=\"absmiddle\" src=\"pictures/".$row2["LOGO"]."\">&nbsp;&nbsp;";
		
	if($row2["PRIVATE"]=='y') print "&nbsp;&nbsp;<strong><font color=\"#990000\">PRIVATE</font></strong>&nbsp;&nbsp;";
		else if($row2["CHECKED"]=='y')
			//print "&nbsp;&nbsp;<strong><font color=\"#505F70\">PUBLIC</font></strong>&nbsp;&nbsp;";
			print "&nbsp;&nbsp;<strong><font color=\"#505F70\">AVAILABLE ON PUBLIC WEBSITE</font></strong>&nbsp;&nbsp;";
		else if ($row2["CHECKED"]='n')
			print "&nbsp;&nbsp;<strong><font color=\"PURPLE\">DESTINED TO BE PUBLISHED</font></strong>&nbsp;&nbsp;";

		print "<a href=\"insitu.php?id=$id\"><img src=\"pictures/button-more.jpg\" border=\"1\"></a>";

		if ($row2["BEING_CURATED"]=='y')
			print "&nbsp;&nbsp;<font size=\"1\" color=\"orange\">This entry is  <strong> being manually curated</font></strong>&nbsp;&nbsp;</td>";



		print "<td align=\"right\" valign=\"top\"><strong>".$row2["SPECIES"]."&nbsp;&nbsp;&nbsp;&nbsp;".$row2["DEV"]."</strong></td>"
		  .'</tr></table></td></tr>';

		
		//picture
		$requete="SELECT \"PICTURE_ID\", \"PATH\" FROM \"PICTURE\" WHERE \"IN_SITU_ID\" = $id and \"CONTROL\" IS NULL";
		$stmtpic = pg_query($c,$requete);
		print "<TR><TD><TABLE><tr align=\"top\"><td>";
		while($row3=pg_fetch_array($stmtpic)){
			$idpicture=$row3["PICTURE_ID"];
			if(strlen($row3["PATH"])>0)
			    {
			    if (!preg_match("/mix/",$row3["PATH"]))
			    echo '<a href="insitu.php?id='.$id.'"><img src="picturesDB/'.$row3["PATH"].'" border=1 width="100" name="pics"></a> ';
			    }
			else
			    echo "<a href=\"insitu.php?id=$id\"><img src=\"picture-mini.php?id=$idpicture\" border=1 width=\"100\" name=\"pics\"></a> ";
		}
		print "</td><td width=\"45%\"><font size=\"-1\" color=\"#000000\">".(str_replace("<br>"," ",$row2[ "IM_COMMENTS"]))."</font></td></tr>";
		print "</TABLE></TD></TR>\n";
		
		
		print "<TABLE cellpadding=\"0\" CELLSPACING=\"0\" BORDER=\"0\" bgcolor=\"$color\" WIDTH=\"100%\" style=\"color:black\">\n";
			//recherche des cibles
			$requete = "SELECT distinct B.\"SURE\", B.\"PART_OF\", A.\"MOL_ID\", A.\"NAME\", A.\"TYPE\", C.\"NAME\" AS \"REGION\", C.\"ANAT_ID\", C.\"DEV_STAGE_ID\" FROM \"MOL_ENTITY\" A, \"TARGET\" B, \"ANAT_ENTITY\" C where (B.\"IN_SITU_ID\"=$id) AND (B.\"TARGET_ID\"=A.\"MOL_ID\") AND (B.\"REGION_ID\"=C.\"ANAT_ID\")";
			$resultset = pg_query($c,$requete);
			$str='';
			$str2='';
			$mol=null; $typemol=null;//sert a retrouver le gene correspondant

			$isin=(array) null; //avoid doublon

			while( $row2=pg_fetch_array($resultset) ){
				if(substr_count (  $str, $row2["NAME"] )==0){
					if( $row2["TYPE"]=="clone" )
					    $str.="<a href=\"molecule-clone2.php?name=";
					else if( $row2["TYPE"]=="clone_sequence" )
					    $str.="<a href=\"molecule-clone.php?name=";
					else if( $row2["TYPE"]=="gene" )
					    $str.="<a href=\"molecule-gene.php?name=";
					else if( $row2["TYPE"]=="construction" )
					    $str.="<a href=\"construct-edit.php?constructid=".$row2["MOL_ID"]."\">".$row2["NAME"]."</a> - ";
					else
					    $str.="<a href=\"\" name=\"";
					
					if( $row2["TYPE"]!="construction" ){					
						$str.=$row2["NAME"]."\">".$row2["NAME"]."</a> - ";
					}
				    
					$mol[$row2["MOL_ID"]]=$row2["NAME"];
					$typemol[$row2["MOL_ID"]]=$row2["TYPE"];
				}
				//anotation sup sur les "stained anatomy part"
				$partof="";$sure="";
				if($row2["PART_OF"]=="X") $partof="Part of ";  else $partof="";
				if($row2["SURE"]=="X") $sure="?"; else $sure="";
					
				if (!in_array($row2["REGION"],$isin))
				{
				$str2.="<a href=\"short_hierarchy.php?region=".$row2["ANAT_ID"]."&dev=".$row2["DEV_STAGE_ID"]."\">$partof".$row2["REGION"]."$sure</a> - ";
				
				$isin[count($isin)]=$row2["REGION"];
				
				}

			}
			
			print "<TR valign=\"top\"><TD width=\"250\"><strong>Stained molecule: - </strong>$str</TD>\n";
			
			//region
			print "<TD><strong>Stained region: - </strong>$str2</TD></TR>\n";
			
			
			
///////////////////////
            //recherche des genes correspondants aux cibles
//AJOUT POUR LA COMPATIBILITE AVEC LA CREATION DES INSITU VIDES
if ($mol!=null)
{

			while (list($key, $value) = each($mol)) {
			      $count2=0;
			      $geneidlist="";
				  if( $typemol[$key]=="clone" ){
					  $requete="SELECT distinct \"ANISEED_CLUSTER_ID\" from \"CLONE_SEQ\" where \"CLONE_NAME\"='$value'";
					  $resultset = pg_query($c,$requete);
					  while($row2=pg_fetch_array($resultset)){
						   $geneidlist[$count2++]=$row2["ANISEED_CLUSTER_ID"]; //+ieur genes poss si les est d'un meme clone correspondent a des modeles differents
					  }
				  }
				  else if( $typemol[$key]=="clone_sequence" ){
					  $requete="SELECT \"ANISEED_CLUSTER_ID\" from \"CLONE_SEQ\" where \"CLONE_SEQ_ID\"=$key";
					  $resultset = pg_query($c,$requete);
					  while($row2=pg_fetch_array($resultset)){
						   $geneidlist[$count2++]=$row2["ANISEED_CLUSTER_ID"];
					  }
				  }
				  else if( $typemol[$key]=="gene" ){
					  $geneidlist[$count2++]=$key;
				  }
				  
				  //recherche des noms possibles pour le gene correspondant				  if(count($geneidlist)>1)
				      $geneidlist=array_unique($geneidlist);
				  for($a=0; $a<count($geneidlist); ++$a){
					if(strlen($geneidlist[$a])>0){
					  $requete="SELECT distinct A.\"NAME\", B.\"SYNO\", B.\"ORIGIN\" from \"GENE\" A, \"SYNO\" B where A.\"GENE_ID\"=B.\"GENE_ID\" and B.\"GENE_ID\"=".$geneidlist[$a]."order by B.\"ORIGIN\" DESC";
					  $resultset = pg_query($c,$requete);
					  $syno=""; $aaa=0;
					  while($row2=pg_fetch_array($resultset)){
					      $genename=$row2["NAME"];
						  if($row2["SYNO"]==$row2["NAME"])
							  continue;
						  if(++$aaa>1)
						      $syno.=' <strong><font color="#990000">/</font></strong> ';
						  $syno.=$row2["SYNO"];
						  if($row2["ORIGIN"]=="user-JGI")
							  $syno.="*";
							  
						  if( strlen($syno)-(($aaa-1)*48) > 100 ){
							  $syno.=" <strong><font color=\"#990000\">/</font></strong>...";
							  break;
						  }
					  }
						if($aaa==0){
							$requete="select \"DESCRIPTION\", \"EVALUE\" from \"BLAST\" where \"MOL_ID\"='".$geneidlist[$a]."' and \"SCORE\"=(select max(\"SCORE\") from \"BLAST\" where \"MOL_ID\"='".$geneidlist[$a]."')";
							//$requete2="select max(score), description, evalue from ciona_design.blast where mol_id=$id";
							$resultset = pg_query($c,$requete);
							if($row2=pg_fetch_array($resultset)){
								$eval = $row2["EVALUE"];
								if( $eval <= 1e-10)
									$syno.= "HIGHLY ";
								else if( ($eval >= 1e-4) and ($eval <= 1e-3) )
									$syno.= "WEAKLY ";
								if($eval <= 1e-3)
									$syno.= "SIMILAR TO ".$row2["DESCRIPTION"]." (Eval: $eval)";
							}
						}
					  
					  print "<tr valign=\"top\"><td><hr color=\"#505F70\" size=\"1\"><font size=\"-1\">Predicted gene for ".$value.": <a href=\"molecule-gene.php?name=".$genename."\">".$genename."</a></font></td><td><hr color=\"#505F70\" size=\"1\"><font size=\"-1\">".$syno."</font></td></tr>";
					}
				  }
			}
//////////////////////////////////
}


            //description des manipulations d'embryon
			if($wild=='n'){
				//recherche des mutants
                $requete = "SELECT \"NAME\", \"BIO_ID\" FROM \"MUTANT\" where \"IN_SITU_ID\"=$id";
				$resultset = pg_query($c,$requete);
				$str='';
				$a=0; $geneidlist="";//sert ensuite a retouver les noms des genes
				while( $row2=pg_fetch_array($resultset) ){
				    $geneidlist[$a++]=$row2["BIO_ID"];
					$str.="<a href=\"molecule-gene.php?name=".$row2["NAME"]."\">".$row2["FULL_NAME"]." ".$row2["NAME"]."</a> - ";
				}
				print "<TR valign=\"top\"><TD><hr color=\"#505F70\" size=\"1\"><strong>Deregulated molecule: - </strong>$str</TD>\n";
				
				//recherche des amputations
				$requete = "SELECT A.\"DEV_STAGE_ID\", A.\"ANAT_ID\", A.\"NAME\" FROM \"ANAT_ENTITY\" A, \"EMBRYO_MANIP\" B WHERE (B.\"IN_SITU_ID\"=$id) AND (B.\"STRUCTURE_ID\"=A.\"ANAT_ID\")";
				$resultset = pg_query($c,$requete);
				$str='';
				while( $row2=pg_fetch_array($resultset) ){
					$str.="<a href=\"short_hierarchy.php?region=".$row2["ANAT_ID"]."&dev=".$row2["DEV_STAGE_ID"]."\">".$row2["NAME"]."</a> - ";
				}
			    print "<TD><hr color=\"#505F70\" size=\"1\"><strong>Embryo manipulation: - </strong>$str</TD></TR>\n";
			

//On va tenter d'introduire la description des conditions experimentales
if ($wild=='n')
{
//Requete pour recuperer le commentaire 
$r="SELECT \"EXP_COMMENTS\" from \"IN_SITU\" where \"IN_SITU_ID\"='$id'";
$st=pg_query($c,$r);
if (pg_num_rows($st)>0)
{
	$rro=pg_fetch_array($st);
	$comment=$rro["EXP_COMMENTS"];
print "<TR valign=\"top\"><TD><hr color=\"#505F70\" size=\"1\"><strong>Experimental conditions:<strong></TD>\n";
	print "<TD><hr color=\"#505F70\" size=\"1\"><font size=\"2\"><em> $comment</em></font></TD></TR>\n";
}

}			
			
				//recherche des noms possibles pour le gene correspondant				if(count($geneidlist)>1)
				    $geneidlist=array_unique($geneidlist);
				for($a=0; $a<count($geneidlist); ++$a){
					if(strlen($geneidlist[$a])>0){
						  $requete="SELECT distinct A.\"NAME\", B.\"SYNO\", B.\"ORIGIN\" from \"GENE\" A, \"SYNO\" B where A.\"GENE_ID\"=B.\"GENE_ID\" and B.\"GENE_ID\"=".$geneidlist[$a]."order by B.\"ORIGIN\" DESC";
						  $resultset = pg_query($c,$requete);
						  $syno=""; $aaa=0;
						  while($row2=pg_fetch_array($resultset)){
						      $genename=$row2["NAME"];
							  if($row2["SYNO"]==$row2["NAME"])
								  continue;
							  if(++$aaa>1)
								  $syno.=' <strong><font color="#990000">/</font></strong> ';
							  $syno.=$row2["SYNO"];
							  if($row2["ORIGIN"]=="user-JGI")
								  $syno.="*";
							  if( strlen($syno)-(($aaa-1)*48) > 100 ){
								  $syno.=" <strong><font color=\"#990000\">/</font></strong>...";
								  break;
							  }
						  }
							if($aaa==0){
								$requete="select \"DESCRIPTION\", \"EVALUE\" from \"BLAST\" where \"MOL_ID\"='".$geneidlist[$a]."' and \"SCORE\"=(select max(\"SCORE\") from \"BLAST\" where \"MOL_ID\"='".$geneidlist[$a]."')";
								//$requete2="select max(score), description, evalue from ciona_design.blast where mol_id=$id";
								$resultset = pg_query($c,$requete);
								if($row2=pg_fetch_array($resultset)){
									$eval = $row2["EVALUE"];
									if( $eval < 1e-10)
										$syno.= "HIGHLY ";
									else if( $eval > 1e-4) 
										$syno.= "WEAKLY ";
									$syno.= "SIMILAR TO ".$row2["DESCRIPTION"]." (Eval: $eval)";
								}
							}
						  
						  //print the corresponding gene model and its biological names.
						  if(strlen($syno)>0)
						      print "<tr valign=\"top\"><td><hr color=\"#505F70\" size=\"1\"><font size=\"-1\">Possible names for <a href=\"molecule-gene.php?name=".$genename."\">".$genename.": </a></font></td><td><hr color=\"#505F70\" size=\"1\"><font size=\"-1\">".$syno."</font></td></tr>";					}
				}
			    $geneidlist=null;
		
		
		
		}
		print "</TABLE><br>";

	  }
   }

   print "</TD></TR></TABLE></center>\n";


   if($count==0){
	   print "<br><br><center><h2><strong>No match</strong></h2></center><br><br>";
   }


   print '<img src="pictures/zoom-in.gif" onClick="ZoomIn()" border="0"><img src="pictures/zoom-out.gif" onClick="ZoomOut()" border="0"><br><br>';
   
   //navigation dans les pages (prec suivant)
    echo "<font SIZE=2><center>";

echo "<br>";


print "Page: $current_page / $number_of_pages<br>";	



	if($offset>0){
		echo "<a href=\"".$_SERVER["PHP_SELF"].
			 "?private=".$_GET["private"]."&option=$option"."&only_constructs=".$_GET["only_constructs"].
			 "&offset=".($offset-$nbMAX).
			 "&species=$species&selectediddev=".$_GET["selectediddev"]."&dateto=".$_GET["dateto"]."&datefrom=".$_GET["datefrom"]."&mutant=".$_GET["mutant"]."&target=".$_GET["target"]."&amputation=".$_GET["amputation"]."&idanat=".$_GET["idanat"]."&Order=".$_GET["Order"]."&BOOLmut=".$_GET["BOOLmut"]."&BOOLtarg=".$_GET["BOOLtarg"]."&BOOLanat=".$_GET["BOOLanat"]."&xref=".$_GET["xref"]."&MOLtype=".$_GET["MOLtype"]."&being=".$_GET["being"]."&pmid=".$_GET["pmid"]."&annotator=".$_GET["annotator"]."&author=".$_GET["author"]."&only=".$_GET["only"]."&news=".$_GET["news"]."&BOOLmanip=".$_GET["BOOLmanip"]."&fate=".$_GET["fate"]."&fatemode=".$_GET["fatemode"].//"&fateonly=".$_GET["fateonly"].
			 "&nbMAX=$nbMAX\"><img src=\"pictures/previous.jpg\" border=\"0\"></a>";
	}


	
	echo "&nbsp;&nbsp;&nbsp;";

/*NAVIGATION ICI*/
if ($number_of_pages<=10)
	{
		for ($i=1;$i<=$number_of_pages;$i++)
		{
		if ($i!=$current_page)
		{
		$link_to_page="<a href=\"".$_SERVER["PHP_SELF"].
			 "?private=".$_GET["private"]."&option=$option"."&only_constructs=".$_GET["only_constructs"].
			 "&offset=".((($i-1)*$nbMAX)).
			 "&species=$species&selectediddev=".$_GET["selectediddev"]."&dateto=".$_GET["dateto"]."&datefrom=".$_GET["datefrom"]."&mutant=".$_GET["mutant"]."&target=".$_GET["target"]."&amputation=".$_GET["amputation"]."&idanat=".$_GET["idanat"]."&Order=".$_GET["Order"]."&BOOLmut=".$_GET["BOOLmut"]."&BOOLtarg=".$_GET["BOOLtarg"]."&BOOLanat=".$_GET["BOOLanat"]."&xref=".$_GET["xref"]."&MOLtype=".$_GET["MOLtype"]."&being=".$_GET["being"]."&pmid=".$_GET["pmid"]."&annotator=".$_GET["annotator"]."&author=".$_GET["author"]."&only=".$_GET["only"]."&news=".$_GET["news"]."&BOOLmanip=".$_GET["BOOLmanip"]."&fate=".$_GET["fate"]."&fatemode=".$_GET["fatemode"].//"&fateonly=".$_GET["fateonly"].
			 "&nbMAX=$nbMAX\">";
		
		print "$link_to_page $i </a>&nbsp;&nbsp;";
		}
	
		else print "$i &nbsp;&nbsp;";
		}


	}
	else
	{

//Les 5 premiers
	for ($i=$current_page-5;$i<$current_page;$i++)
		{
			if ($i>=1) 
			{
			if ($i!=$current_page)
			{
			$link_to_page="<a href=\"".$_SERVER["PHP_SELF"].
			 "?private=".$_GET["private"]."&option=$option"."&only_constructs=".$_GET["only_constructs"].
			 "&offset=".(($i-1)*$nbMAX).
			 "&species=$species&selectediddev=".$_GET["selectediddev"]."&dateto=".$_GET["dateto"]."&datefrom=".$_GET["datefrom"]."&mutant=".$_GET["mutant"]."&target=".$_GET["target"]."&amputation=".$_GET["amputation"]."&idanat=".$_GET["idanat"]."&Order=".$_GET["Order"]."&BOOLmut=".$_GET["BOOLmut"]."&BOOLtarg=".$_GET["BOOLtarg"]."&BOOLanat=".$_GET["BOOLanat"]."&xref=".$_GET["xref"]."&MOLtype=".$_GET["MOLtype"]."&being=".$_GET["being"]."&pmid=".$_GET["pmid"]."&annotator=".$_GET["annotator"]."&author=".$_GET["author"]."&only=".$_GET["only"]."&news=".$_GET["news"]."&BOOLmanip=".$_GET["BOOLmanip"]."&fate=".$_GET["fate"]."&fatemode=".$_GET["fatemode"].//"&fateonly=".$_GET["fateonly"].
			 "&nbMAX=$nbMAX\">";
			
			print "$link_to_page ".$i." </a>&nbsp;&nbsp;";			
			}
			}	
		}


	//La page courante
	print "&nbsp;$current_page&nbsp;&nbsp;";

	//Les 5 derniers
	for ($i=$current_page;($i<=$current_page+5);$i++)
			{
			if ($i<=$number_of_pages)
			{
			if ($i!=$current_page)
			{
			$link_to_page="<a href=\"".$_SERVER["PHP_SELF"].
			 "?private=".$_GET["private"]."&option=$option"."&only_constructs=".$_GET["only_constructs"].
			 "&offset=".(($i-1)*$nbMAX).
			 "&species=$species&selectediddev=".$_GET["selectediddev"]."&dateto=".$_GET["dateto"]."&datefrom=".$_GET["datefrom"]."&mutant=".$_GET["mutant"]."&target=".$_GET["target"]."&amputation=".$_GET["amputation"]."&idanat=".$_GET["idanat"]."&Order=".$_GET["Order"]."&BOOLmut=".$_GET["BOOLmut"]."&BOOLtarg=".$_GET["BOOLtarg"]."&BOOLanat=".$_GET["BOOLanat"]."&xref=".$_GET["xref"]."&MOLtype=".$_GET["MOLtype"]."&being=".$_GET["being"]."&pmid=".$_GET["pmid"]."&annotator=".$_GET["annotator"]."&author=".$_GET["author"]."&only=".$_GET["only"]."&news=".$_GET["news"]."&BOOLmanip=".$_GET["BOOLmanip"]."&fate=".$_GET["fate"]."&fatemode=".$_GET["fatemode"].//"&fateonly=".$_GET["fateonly"].
			 "&nbMAX=$nbMAX\">";
			
			print "$link_to_page ".$i." </a>&nbsp;&nbsp;";			
			}
			}

			}
	}

/*Fin Navigation*/
echo "&nbsp;&nbsp;&nbsp";

	if( ($count%$nbMAX==0)&&($count>0)&&($count>$offset) ){
		echo "<a href=\"".$_SERVER["PHP_SELF"].
			 "?private=".$_GET["private"]."&option=$option"."&only_constructs=".$_GET["only_constructs"].
			 "&offset=".($offset+$nbMAX).
			 "&species=$species&selectediddev=".$_GET["selectediddev"]."&dateto=".$_GET["dateto"]."&datefrom=".$_GET["datefrom"]."&mutant=".$_GET["mutant"]."&target=".$_GET["target"]."&amputation=".$_GET["amputation"]."&idanat=".$_GET["idanat"]."&Order=".$_GET["Order"]."&BOOLmut=".$_GET["BOOLmut"]."&BOOLtarg=".$_GET["BOOLtarg"]."&BOOLanat=".$_GET["BOOLanat"]."&xref=".$_GET["xref"]."&MOLtype=".$_GET["MOLtype"]."&being=".$_GET["being"]."&pmid=".$_GET["pmid"]."&annotator=".$_GET["annotator"]."&author=".$_GET["author"]."&only=".$_GET["only"]."&news=".$_GET["news"]."&BOOLmanip=".$_GET["BOOLmanip"]."&fate=".$_GET["fate"]."&fatemode=".$_GET["fatemode"].//"&fateonly=".$_GET["fateonly"].
			 "&nbMAX=$nbMAX\"><img src=\"pictures/next.jpg\" border=\"0\"></a>";
	}


/*Premier type de navigation: on deplace de 10 a droite et de 1 a gauche en suivant les fleches de navigations */
/*
		//Retour gauche
		if ($current_page!=1)
		{
		print "<a href=\"".$_SERVER["PHP_SELF"].
			 "?private=".$_GET["private"]."&option=$option".
			 "&offset=".(($current_page-2)*$nbMAX).
			 "&species=$species&selectediddev=".$_GET["selectediddev"]."&mutant=".$_GET["mutant"]."&target=".$_GET["target"]."&amputation=".$_GET["amputation"]."&idanat=".$_GET["idanat"]."&Order=".$_GET["Order"]."&BOOLmut=".$_GET["BOOLmut"]."&BOOLtarg=".$_GET["BOOLtarg"]."&BOOLanat=".$_GET["BOOLanat"]."&xref=".$_GET["xref"]."&MOLtype=".$_GET["MOLtype"]."&author=".$_GET["author"]."&only=".$_GET["only"]."&news=".$_GET["news"]."&BOOLmanip=".$_GET["BOOLmanip"]."&fate=".$_GET["fate"]."&fatemode=".$_GET["fatemode"].//"&fateonly=".$_GET["fateonly"].
			 "&nbMAX=$nbMAX\"> <<  </a> &nbsp;&nbsp;";
		}


		for ($i=$current_page;($i<=$current_page+10);$i++)
			{
			if ($i>$number_of_pages) break;
			if ($i!=$current_page)
			{
			$link_to_page="<a href=\"".$_SERVER["PHP_SELF"].
			 "?private=".$_GET["private"]."&option=$option".
			 "&offset=".(($i-1)*$nbMAX).
			 "&species=$species&selectediddev=".$_GET["selectediddev"]."&mutant=".$_GET["mutant"]."&target=".$_GET["target"]."&amputation=".$_GET["amputation"]."&idanat=".$_GET["idanat"]."&Order=".$_GET["Order"]."&BOOLmut=".$_GET["BOOLmut"]."&BOOLtarg=".$_GET["BOOLtarg"]."&BOOLanat=".$_GET["BOOLanat"]."&xref=".$_GET["xref"]."&MOLtype=".$_GET["MOLtype"]."&author=".$_GET["author"]."&only=".$_GET["only"]."&news=".$_GET["news"]."&BOOLmanip=".$_GET["BOOLmanip"]."&fate=".$_GET["fate"]."&fatemode=".$_GET["fatemode"].//"&fateonly=".$_GET["fateonly"].
			 "&nbMAX=$nbMAX\">";
			
			print "$link_to_page ".$i." </a>&nbsp;&nbsp;";			
			}
			

			}

		//Avance droit
		if ($i<=$number_of_pages)
		{
		print "<a href=\"".$_SERVER["PHP_SELF"].
		 "?private=".$_GET["private"]."&option=$option".
		 "&offset=".(($i-1)*$nbMAX).
		 "&species=$species&selectediddev=".$_GET["selectediddev"]."&mutant=".$_GET["mutant"]."&target=".$_GET["target"]."&amputation=".$_GET["amputation"]."&idanat=".$_GET["idanat"]."&Order=".$_GET["Order"]."&BOOLmut=".$_GET["BOOLmut"]."&BOOLtarg=".$_GET["BOOLtarg"]."&BOOLanat=".$_GET["BOOLanat"]."&xref=".$_GET["xref"]."&MOLtype=".$_GET["MOLtype"]."&author=".$_GET["author"]."&only=".$_GET["only"]."&news=".$_GET["news"]."&BOOLmanip=".$_GET["BOOLmanip"]."&fate=".$_GET["fate"]."&fatemode=".$_GET["fatemode"].//"&fateonly=".$_GET["fateonly"].
		 "&nbMAX=$nbMAX\"> >> </a>";
		}
	*/



	
/*Second type de navigation on centre la page courante, on prend les 5 pages autour et on a supprimé les fleches de navigation
	"Google Like"  */
	//Les 5 premiers
/*	for ($i=$current_page-5;$i<$current_page;$i++)
		{
			if ($i>=1) 
			{
			if ($i!=$current_page)
			{
			$link_to_page="<a href=\"".$_SERVER["PHP_SELF"].
			 "?private=".$_GET["private"]."&option=$option".
			 "&offset=".(($i-1)*$nbMAX).
			 "&species=$species&selectediddev=".$_GET["selectediddev"]."&mutant=".$_GET["mutant"]."&target=".$_GET["target"]."&amputation=".$_GET["amputation"]."