<?
/*
    ANISEED, NISEED System and Database
    Copyright (C) 2007 Olivier Tassy, Fabrice Daian, Patrick Lemaire

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.

*/
include ("connection.php");
?>
<title>ANISEED v3.0 - Embryo view</title>
<?

include ("frames_header.php");


$species=$_GET["species"];
$dev=$_GET["dev"];


$requete="SELECT \"NAME\",\"SPECIES\" from \"DEV_STAGE\" where \"DEV_STAGE_ID\"='$dev'";
$stmt=pg_query($c,$requete);
$row=pg_fetch_array($stmt);

$name=$row["NAME"];
$devname=$row["NAME"];
$name=str_replace(" ","",$name);

?>
  <link rel="stylesheet" type="text/css" media="screen" href="ongletv1.css" title="Version 1" />
<!-- Header pour l'onglet -->
<div id="header">
  <ul>
    <!--<li><a href="anatomy.php?species=<? print $row["SPECIES"];?>&dev=<?print $dev;?>">Tree view</a></li>-->
    <li id="current"><a href="#">Anatomical dictionnary (Embryo view)</a></li>
  </ul>
</div>
<!-- EOF Onglet -->
<br><br>

<?

print "<br><br><font color=\"#D64242\" size=\"3\"><b>".$row["SPECIES"]."  (".$row["NAME"].")<br></b></font><br>";

//print "Click on an antomical part to display it.<br><br>";

print "
Click on individual cells to have access to a shortened anatomical tree, and to the fate, lineage, and biometry information on the selected cell.<br>
Up to the 110-cell stage, the whole embryo is represented by a vegetal and an animal scheme. Between the mid-gastrula and early tailbud, the scheme represents only the neural plate and its derivatives. Anterior is at the top on all schemes and pictures.<br>
Left image is based on <a href=\"http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?db=pubmed&cmd=Retrieve&dopt=AbstractPlus&list_uids=3197930&query_hl=1&itool=pubmed_docsum\">Nicol and Meinertzhagen</a> (1998) and <a href=\"http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?db=pubmed&cmd=Retrieve&dopt=AbstractPlus&list_uids=15223332&query_hl=3&itool=pubmed_docsum\">Cole and Meinertzhagen</a> (2004).<br><br><br>
";



//Traitement sur le stage de developpement
//print $devname;
//Stade inferieur a 110

$tmp=explode("-",$devname);
if (strlen($tmp[1])>0) 
	{
	//Stade inferieur ou egal a 110-cell stage
	$part=trim($tmp[0]);
	$tmp2=explode(" ",$part);
	if (strlen($tmp2[1])>0) //Early ou Late32
		{
		if ($tmp2[0]=="Early") $STADE="early".$tmp2[1];
		if ($tmp2[0]=="Late") $STADE="late".$tmp2[1];
		}
	else
		{
			//Tout le reste
		$STADE=trim($tmp2[0]);


		}

	}
else
	{
	//Stade superieur a 110-cell stage ou Zygot ou Unfertilized egg
	$STADE=str_replace(" ","",$devname);
	$STADE=strtolower($STADE);
	
	


	}




//include("embryos/".$STADE."c/index.html");

$page="";
$list=(array) null;
$listdev="";

$BOOL=false;

if (is_file("embryos/".$STADE."/index.html")) //Stade superieur a 110
	{
$BOOL=true;
////////////////////////////////////////////////////////
$handle=fopen("embryos/".$STADE."/index.html","r");
while (!feof($handle))
{
$text0=fgets($handle,8192);
$text.=$text0;

$tmp0=ereg("region=[0-9]*",$text0,$tab0);
$tab0[0]=str_replace("region=","",$tab0[0]);

$tmp2=ereg("dev=[0-9]*",$text0,$tab2);
$listdev=trim($tab2[0]);
$listdev=str_replace("dev=","",$listdev);


$text0=str_replace("\"right\"","\"right \"",$text0);
$text0=str_replace("right\"","*\"",$text0);

$tmp=ereg("alt=\"[A-Z]*[a-z]*[0-9]*.[0-9]*[\*]*\"",$text0,$tab);


//print_r($tab);

$tab[0]=str_replace("alt=\"","",$tab[0]);
$tab[0]=trim(str_replace("\"","",$tab[0]));

if (strlen($tab[0])==0) continue;
if (strlen($list[$tab[0]])==0) $list[$tab[0]]=$tab0[0];


}
fclose($handle);
//print_r($list);




$text=str_replace("<img src=\"original.jpg\"","<img src=\"embryos/$STADE/original.jpg\"",$text);

$text=str_replace("<img name=\"img\" src=\"original.jpg\"","<img name=\"img\" src=\"embryos/$STADE/original.jpg\"",$text);

//Stade MidNeurula
$text=str_replace("<img name=\"img1\" src=\"MN_3F/original.jpg\"","<img name=\"img1\" src=\"embryos/$STADE/MN_3F/original.jpg\"",$text);
$text=str_replace("<img name=\"img2\" src=\"MN_3H/original.jpg\"","<img name=\"img2\" src=\"embryos/$STADE/MN_3H/original.jpg\"",$text);

$text=str_replace("<img src=\"originalreal.jpg\"","<img src=\"embryos/$STADE/originalreal.jpg\"",$text);

$text=str_replace("http://crfb.univ-mrs.fr/aniseed/","",$text);
$text=str_replace("['img'].src='","['img'].src='embryos/".$STADE."/",$text);
$text=str_replace("['img1'].src='","['img1'].src='embryos/".$STADE."/",$text);
$text=str_replace("['img2'].src='","['img2'].src='embryos/".$STADE."/",$text);





//AJOUT POUR LE TARGET _blank

$text=str_replace("href=","target=\'_blank\' href=",$text);





print "<center>".$text."</center>";	
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


	}


if (((!is_file("embryos/".$STADE."c/index.html"))) && ($BOOL==false))
	{
	print "<br><br><center><strong>No embryo scheme available for this stage</strong></center>";
	include ("frames_footer.php");
	return;
	}
else if ($BOOL==false)
{

$handle=fopen("embryos/".$STADE."c/index.html","r");
while (!feof($handle))
{
$text0=fgets($handle,8192);
$text.=$text0;

$tmp0=ereg("region=[0-9]*",$text0,$tab0);
$tab0[0]=str_replace("region=","",$tab0[0]);

$tmp2=ereg("dev=[0-9]*",$text0,$tab2);
$listdev=trim($tab2[0]);
$listdev=str_replace("dev=","",$listdev);

$tmp=ereg("alt=\"[A-Z]*[a-z]*[0-9]*.[0-9]*[\*]*\"",$text0,$tab);

$tab[0]=str_replace("alt=\"","",$tab[0]);
$tab[0]=trim(str_replace("\"","",$tab[0]));

if (strlen($tab[0])==0) continue;
if (strlen($list[$tab[0]])==0) $list[$tab[0]]=$tab0[0];


}
fclose($handle);
//print_r($list);


$text=str_replace("<IMG SRC=\"".$STADE."anim.gif","<IMG SRC=\"embryos/".$STADE."c/".$STADE."anim.gif",$text);
$text=str_replace("<IMG SRC=\"".$STADE."vege.gif","<IMG SRC=\"embryos/".$STADE."c/".$STADE."vege.gif",$text);
$text=str_replace("http://crfb.univ-mrs.fr/aniseed/","",$text);
$text=str_replace("['img'].src='","['img'].src='embryos/".$STADE."c/",$text);
$text=str_replace("['img2'].src='","['img2'].src='embryos/".$STADE."c/",$text);

//AJOUT POUR LE TARGET _blank

$text=str_replace("href=","target=\"_blank\" href=",$text);



//PANSEMENT TEMPORAIRE POUR LES BONS IDANAT SUR LA NOUVELLE BASE

foreach ($list as $key => $val)
{
$requete="SELECT \"ANAT_ID\",\"DEV_STAGE_ID\" from \"ANAT_ENTITY\" where \"NAME\"='$key' and \"DEV_STAGE_ID\"=(
select \"DEV_STAGE_ID\" from \"DEV_STAGE\" where \"NAME\"='";

if ($STADE=="late32") $requete.="Late 32-cell stage";
else if ($STADE=="early32") $requete.="Early 32-cell stage";
else $requete.=$STADE."-cell stage";

$requete.="' and \"SPECIES\"='Ciona intestinalis') and \"SPECIES\"='Ciona intestinalis'";

$stmt=pg_query($c,$requete);


$row=pg_fetch_array($stmt);

$region=$row["ANAT_ID"];
$devstage=$row["DEV_STAGE_ID"];


$text=str_replace("?region=".$list[$key],"?region=$region",$text);
$text=str_replace("&dev=$listdev","&dev=$devstage",$text);


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

}

print $text;
}



?>







<?

include ("frames_footer.php");
?>

