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

<html>
<body bgcolor="#999966" text="#FFFFFF" link="#000000" vlink="#000000" alink="#000000">
<title>ANISEED</title>
<br>
 
<?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>';
		return;
	}
?>


<form target="_self" action="editpartanat2.php" method="GET" name="formulaire">

<?php

	$insituid=$_GET["insituid"];
	$cloneid=$_GET["cloneid"];
	$anatid=$_GET["anatid"];
	$name=$_GET["name"];

	$typeMol=$_GET["type"];

$requete="SELECT \"DEV_STAGE_ID\",\"SPECIES\" from \"IN_SITU\" where \"IN_SITU_ID\"='$insituid'";
$stmt=pg_query($c,$requete);
$row=pg_fetch_array($stmt);
$species=$row["SPECIES"];
$devid=$row["DEV_STAGE_ID"];

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


 $requeteT="SELECT A.\"TARGET_ID\", A.\"SURE\", A.\"PART_OF\", A.\"REGION_ID\", A.\"SUBCELL_POS\", A.\"PROBE_ID\", A.\"METHOD\", A.\"INTENSITY\", A.\"SUBSTRATE\", B.\"NAME\", B.\"FULL_NAME\", B.\"TYPE\" FROM \"TARGET\" A, \"MOL_ENTITY\" B WHERE (A.\"IN_SITU_ID\"=$insituid) AND (A.\"TARGET_ID\"=B.\"MOL_ID\") AND (A.\"REGION_ID\"=$anatid)";

//print $requeteT;

$stmtT = pg_query($c,$requeteT);

$rowT=pg_fetch_array($stmtT);

$regionid=$rowT["REGION_ID"];
$sure=$rowT["SURE"];
$subcellpos=$rowT["SUBCELL_POS"];
$intensity=$rowT["INTENSITY"];
$name=$rowT["NAME"];
$method=$rowT["METHOD"];
$substrate=$rowT["SUBSTRATE"];
$type=$rowT["TYPE"];
$partof=$rowT["PART_OF"];
$target_id=$rowT["TARGET_ID"]; //D
     
				

//METHOD
$tabOption=(array) null;
$tabOption[0]="in situ hybridisation";
$tabOption[1]="immunohistochemestry";
$tabOption[2]="reporter gene lac Z ISH";
$tabOption[3]="reporter gene X gal";
$tabOption[4]="reporter gene lac Z immunohistochemestry";
$tabOption[5]="reporter gene GFP ISH";
$tabOption[6]="reporter gene GFP immunohistochemestry";
$tabOption[7]="reporter gene GFP fluorescence";
$tabOption[8]="other";

$option="<option selected>$method</option>";
for ($i=0;$i<count($tabOption);$i++)
{
if ($method!=$tabOption[$i])
	{
	$option.="<option>".$tabOption[$i]."</option>";
	}
}

//INTENSITY
$tabintens[0]="";
$tabintens[1]="+";
$tabintens[2]="++";
$tabintens[3]="+++";

$optionint="<option selected>$intensity</option>";
for ($i=0;$i<count($tabintens);$i++)
{
if ($intensity!=$tabintens[$i])
	{
	$optionint.="<option>".$tabintens[$i]."</option>";
	}
}

//SURE
if ($sure=="") $checksure="unchecked"; else $checksure="checked";

//PARTOF
if ($partof=="") $checkpart="unchecked"; else $checkpart="checked";


//SUBCELLULARPOS
$tabSub[0]="";
$tabSub[1]="membrane";
$tabSub[2]="nuclear";
$tabSub[3]="perinuclear";
$tabSub[4]="nucleoli";
$tabSub[5]="cytoplasmic";
$tabSub[6]="myoplasm";
$tabSub[7]="CAB";
$tabSub[8]="animal";
$tabSub[9]="vegetal";
$tabSub[10]="anterior";
$tabSub[11]="posterior";
$tabSub[12]="vesicule";
$tabSub[13]="mitochondria";
$tabSub[14]="endoplasmic reticulum";
$tabSub[15]="golgi";
$tabSub[16]="cilia";
$tabSub[17]="dendrite";
$tabSub[18]="axon";
$tabSub[19]="synapse";
$tabSub[20]="mitotic spindle";
$tabSub[21]="cytoskeleton";
$tabSub[22]="posterior cortex";
$tabSub[23]="pem-like distribution";

$optionsub="<option selected>$subcellpos</option>";

for ($i=0;$i<count($tabSub);$i++)
{
if ($subcellpos!=$tabSub[$i])
	{
	$optionsub.="<option>".$tabSub[$i]."</option>";
	}
}




print "<center><h2><strong><em>$species($devname)<br>Anatomical tree</em></strong> </h2></center><br><br>";
		print '<center><TABLE >
				<tr><td>Clone name :</td><td> <input type="text" VALUE= "'.$name.'" size="20" name="cloneid"></td> 
				<td>Method : </td><td><select name=method size="1">
						'.$option.'
						</select></td></tr>
				<tr><td>Substrate :</td><td> <input type=text VALUE= "'.$substrate.'" size=20 name=substrate></td>
				<td>Intensity: </td><td><select name=intensity size="1">
											'.$optionint.'
											</select></td></tr>
				<tr><td> Not sure :</td><td> 
				<input type="checkbox" name="sure" value="X" '.$checksure.'></td>
				<td> Part of :</td><td> 
				<input type="checkbox" name="partof" value="X" '.$checkpart.'></td></tr>
				<tr><td> Subcellular position:</td><td> <select name=subcellpos size="1">
				        '.$optionsub.'
						</select></td>

				</TABLE></center>'
				;
		print "<input name=\"insituid\" type=\"hidden\" value=\"$insituid\">";
		print "<input name=\"species\" type=\"hidden\" value=\"$species\">";
		print "<input name=\"dev\" type=\"hidden\" value=\"$dev\">";
		//Le type de molecule (clone, cloneseq, gene, ....)	
		print "<input name=\"typeMol\" type=\"hidden\" value=\"$typeMol\">";


//ARBRE ANATOMIQUE

print "<br><br>";

$nivo=0;


function select_recursif_descendant_2($conn,$start,$res,$nivo)
{
global $devid;
//global $level;
global $anatid;
//global $nivo;
/*ON ECRIT SA REQUETE*/

//print "la";
if ($start!='')
{
$requete2="SELECT * FROM \"ANAT_ENTITY\" WHERE  \"DEV_STAGE_ID\"= ".$devid." and  \"CHILD_OF\"= $start ";
//print $start;
$level++;
}
else {
$requete2="SELECT * FROM \"ANAT_ENTITY\" WHERE  \"DEV_STAGE_ID\"= ".$devid." and  \"CHILD_OF\" is null";
//$level=0;
}

$stmt2=pg_query($conn,$requete2);

//if (pg_num_rows($stmt2)==0) {$level--;}

if (pg_num_rows($stmt2)!=0) $nivo++;//print "Nz";
if (pg_num_rows($stmt2)==0) $nivo--;//print "Ze";

while($row2=pg_fetch_array($stmt2))
	{
for($a=0;$a<$nivo-1;++$a){
				if( $nivo>1 )
					echo '&nbsp;&nbsp;<font color="#999999">|</font>&nbsp;&nbsp;';
			}
			
			if( $row2["TYPE"]=='cell' )
				print "<img src=\"pictures/cell.gif\">";
			else if( $row2["TYPE"]=='organism' )
				print "<img src=\"pictures/tetard.gif\">";
			else
				print "<img src=\"pictures/region.gif\">";
			
			
			if($row2["ANAT_ID"]==$anatid){
				echo '<A NAME="tag"> <font color="#FF9900"><strong>'.$row2["NAME"]."</strong></font> </A>";//.OCIResult($stmt, "ANAT_ID");
				print "<input name=\"region\" type=\"radio\" value=\"".$row2["ANAT_ID"]."\" ";
			    //if($nivo==1)
				    print "checked ";
				print ">";
			}else{
				echo $row2["NAME"];
				if((strlen($anatid)>0)){
					print "<input name=\"region\" type=\"radio\" value=\"".$row2["ANAT_ID"]."\">";//.OCIResult($stmt, "ANAT_ID");
				}else{
					print "<input name=\"region\" type=\"radio\" value=\"".$row2["ANAT_ID"]."\"";//.OCIResult($stmt, "ANAT_ID");
			        if($nivo==1)
					    print "checked ";
					print ">";
				}
			}
				print '<br>';
	
	$res=select_recursif_descendant_2($conn,$row2["ANAT_ID"],$res,$nivo);

	
	}

return $res;
}

$res=select_recursif_descendant_2($c,null,$res,$nivo);



//print '<input type="hidden" name="anatid" value="'.$anatid.'">';
print '<input type="hidden" name="devid" value="'.$devid.'">';
//print '<input type="hidden" name="cloneid" value="'.$cloneid.'">';
//print '<input type="hidden" name="substrate" value="'.$substrate.'">';
print '<input type="hidden" name="species" value="'.$species.'">';
print '<input type="hidden" name="insituid" value="'.$insituid.'">';
print '<input type="hidden" name="anatid" value="'.$anatid.'">';
//print '<input type="hidden" name="sure" value="'.$sure.'">';
//print '<input type="hidden" name="partof" value="'.$partof.'">';
//print '<input type="hidden" name="subcellpos" value="'.$subcellpos.'">';
//print '<input type="hidden" name="intensity" value="'.$intensity.'">';
//print '<input type="hidden" name="method" value="'.$method.'">';


?>
&nbsp;<br>&nbsp;<br>&nbsp;<br>

<center><input name="submit" type="image" src="pictures/button-submit.jpg" onClick="submit"></center>                                          
</form>




</body>
</html>