<?

include ("connection.php");
include ("frames_header.php");

$id=$_GET["embryoid"];

$mode=$_GET["mode"];



$requete="SELECT \"NAME\",\"SPECIES\",\"WILD_TYPE\",\"COMMENTS\",\"DEV_STAGE_ID\",\"SOFTWARE\",\"OBJ_DATA\" from \"EMBRYO\" where \"EMBRYO_ID\"='$id'";
$stmt=pg_query($c,$requete);
$row=pg_fetch_array($stmt);

if (pg_num_rows($stmt)==0)
	{
	print "<center><br><br><font color=\"crimson\" size=\"2\"><b>The Embryo you have selected is not into the database, please try again with an other id</b></center>";
	include ("frames_footer.php");
	return;
	}

$name=$row["NAME"];
$species=$row["SPECIES"];
$wild=$row["WILD_TYPE"];
$comments=$row["COMMENTS"];
$devstageid=$row["DEV_STAGE_ID"];
$software=$row["SOFTWARE"];
if (strlen($row["OBJ_DATA"])>0) $is_obj="y"; else $is_obj="n";


$requete="SELECT \"NAME\" from \"DEV_STAGE\" where \"DEV_STAGE_ID\"='$devstageid'";
$stmt=pg_query($c,$requete);
$row=pg_fetch_array($stmt);
$devstagename=$row["NAME"];


$requete="SELECT \"AUTHOR_ID\",\"NAME\",\"SURNAME\",\"MAIL\" from \"AUTHOR\" where \"AUTHOR_ID\"=(
select \"AUTHOR_ID\" from \"ENTRY_ORIGIN\" where \"BIO_ID\"='$id'
)";
$stmt=pg_query($c,$requete);
$row=pg_fetch_array($stmt);

$author_id=$row["AUTHOR_ID"];
$author_name=$row["NAME"];
$author_surname=$row["SURNAME"];
$author_mail=$row["MAIL"];

$requete="SELECT \"ENTRY_DATE\" from \"ENTRY_ORIGIN\" where \"BIO_ID\"='$id'";
$stmt=pg_query($c,$requete);
$row=pg_fetch_array($stmt);
$date=$row["ENTRY_DATE"];

?>

<?
if (strlen($species)==0) $species=$_GET["species"];
?>


<center><font size="5" color="#486898"><b>Embryo Card <? if ($mode=="update") print "<font color=\"white\">(Edition Mode)</font>";?></b></font><br><br>

<form name="formulaire" action="update-embryo-card.php" method="POST" enctype="multipart/form-data">

<input type="hidden" name="ID" value="<?print $id;?>">

<!-- ---------------------------- SPECIES --------------------------------->
<font color="#486898" size="-1"><b>Species</b></font><br>
<select name="species" size="1" onChange="javascript: self.location.href = 'embryo-card.php?species='+ this.options[ this.selectedIndex ].value">
<option ></option>
<?
$requete="SELECT \"NAME\" from \"SPECIES\"";
$stmt=pg_query($c,$requete);
while ($row=pg_fetch_array($stmt))
{
$spe_name=$row["NAME"];
print "<option value=\"$spe_name\"";
if($species==$spe_name) print " selected";
print ">$spe_name</option>";
}

?>
</select>


<br><br>
<!-- ---------------------------- DEV_STAGE --------------------------------->
<font color="#486898" size="-1"><b>Developmental stage</b></font><br>
<select name="devstage" size="8" style="background-color:white;" onClick="window.document.formulaire.devname.value=this.options[ this.selectedIndex ].text;">
<?php

if (strlen($species)>0)
{

$requete="SELECT \"NAME\" from \"DEV_STAGE\" where \"SPECIES\"='$species' order by \"DEV_PERCENT\"";
$stmt=pg_query($c,$requete);
while($row=pg_fetch_array($stmt))
{

if ($row["NAME"]==$devstagename) print "<option value=\"".$row["DEV_STAGE_ID"]."\" selected>";
else print "<option value=\"".$row["DEV_STAGE_ID"]."\">";
print $row["NAME"]."</option>\n";
}

}
?>
</select>

<br><br>

<!-- ---------------------------- TRACABILITY ------------------------------>

<font color="#486898" size="-1"><b>Choose an author</b></font><br>
<select name="author" size="1" style="text-align:center;">
<option></option>
<?
$requete="SELECT \"AUTHOR_ID\",\"NAME\" from \"AUTHOR\" order by \"NAME\"";
$stmt=pg_query($c,$requete);

while ($row=pg_fetch_array($stmt))
{
//print $row["NAME"]."<br>";
if ($row["NAME"]==$author_name) print "<option value=\"".$row["AUTHOR_ID"]."\" selected>".$row["NAME"]."</option>";
else print "<option value=\"".$row["AUTHOR_ID"]."\">".$row["NAME"]."</option>";

}

?>
</select>
<br><br>

<!-- ---------------------------- WILD TYPE ----------------------------->

<font color="#486898" size="-1"><b>Wild Type</b></font><br>
<select name="wt" size="1">

<?
if ($wild=="Yes") {print "<option selected>Yes</option>";print "<option>No</option>";}
else {print "<option>Yes</option>";print "<option selected>No</option>";}
?>

</select>


<!-- ---------------------------- NAME --------------------------------->
<br><br>
<font color="#486898" size="-1"><b>Name</b></font><br>

<?

$tname=explode("@",$name);

$_evol=trim($tname[0]);
$_devname=trim($tname[1]);

$_devname=str_replace("_"," ",$_devname);

$_soft=trim($tname[2]);
$_resolution=trim($tname[3]);
$_complements=trim($tname[4]);


?>


<table>
<tr>
<td align="center"><font color="black" size="-1"><i>Part of stage</i></font></td>
<td align="center"><font color="black" size="-1"><i>Developmental stage</i></font></td>
<td align="center"><font color="black" size="-1">&nbsp;</font></td>
<td align="center"><font color="black" size="-1"><i>Software</i></font></td>
<td align="center"><font color="black" size="-1">&nbsp;</font></td>
<td align="center"><font color="black" size="-1"><i>Resolution</i></font></td>
<td align="center"><font color="black" size="-1">&nbsp;</font></td>
<td align="center"><font color="black" size="-1"><i>Complements</i></font></td>
</tr>



<tr>
<td align="center">
<select name="evol" size="1">
<option></option>

<?
if ($_evol=="Initial") print "<option selected>Initial</option>"; else print "<option>Initial</option>";
if ($_evol=="Very-Early") print "<option selected>Very-Early</option>"; else print "<option>Very-Early</option>";
if ($_evol=="Early") print "<option selected>Early</option>"; else print "<option>Early</option>";
if ($_evol=="Mid") print "<option selected>Mid</option>"; else print "<option>Mid</option>";
if ($_evol=="Late") print "<option selected>Late</option>"; else print "<option>Late</option>";
if ($_evol=="Very-Late") print "<option selected>Very-Late</option>"; else print "<option>Very-Late</option>";
?>

</select>
</td>

<td align="center">
<input type="text" name="devname" style="text-align:center;color:#486898;font-weight:bold;" value="<? print $_devname; ?>">

</td>

<td align="center">
-
</td>

<td align="center">
<input type="text" name="software" size="10" value="<? if (strlen($_soft)==0) print "Amira"; else print $_soft; ?>" style="color:crimson;text-align:center;font-weight:bold;">
</td>

<td align="center">
-
</td>

<td align="center">
<select name="resolution" size="1">
<option></option>
<?
if ($_resolution=="Low-Resolution") print "<option selected>Low-Resolution</option>"; else print "<option>Low-Resolution</option>";
if ($_resolution=="High-Resolution") print "<option selected>High-Resolution</option>"; else print "<option>High-Resolution</option>";
?>
</select>
</td>

<td align="center">
-
</td>

<td align="center">
<input type="text" name="complements" size="50" style="text-align:center;font-weight:bold;" value="<? if (strlen($_complements)!=0) print $_complements;?>">
</td>


</tr>
</table>


<br><br>
<?
if ($is_obj=="y") print "<img src=\"pictures/yes.gif\"> An Obj File has already been entered.<br>";
else print "<img src=\"pictures/no.gif\"> No Obj File are stored for this embryo into the database<br>";
?>
<font color="#486898" size="-1"><b>Wavefront Object (*.obj)</b></font><br>
<input type="file" size="50" name="objfile" style="text-align:center;">

<br><br>

<!--
<font color="#486898" size="-1"><b>VRML 2.0 (*.wrl)</b></font><br>
<input type="file" size="50" name="vrmlfile" style="text-align:center;">

<br><br>

<font color="#486898" size="-1"><b>LSM Confocal Stack (*.lsm)</b></font><br>
<input type="file" size="50" name="lsmfile" style="text-align:center;">

<br><br>398
-->

<font color="#486898" size="-1"><b>Comments</b></font><br>
<textarea name="comments" rows="5" cols="80">
<? print $comments; ?>
</textarea>

<br><br>

<?
if ($mode=="update") print "<input type=\"submit\" value=\"Update Embryo\">";
?>


</form>


</center>






<?

include ("frames_footer.php");
?> 
