<?php
    include("connection.php");
print "<title>ANISEED CURATOR - Edit Article Anatomy</title>";
    include("frames_header.php");

$id=$_GET["id"];

?>

<script>
var selected_part=new Array();

function popup_anatomy_selector() {
  dev = "";
  names = "";
  for(a=0; a<window.document.formulaire.elements['devstage[]'].options.length; ++a){
  	if(window.document.formulaire.elements['devstage[]'].options[a].selected==true){
	  	dev  += window.document.formulaire.elements['devstage[]'].options[a].value+':'; // tab[a-1]+':';
		names+= window.document.formulaire.elements['devstage[]'].options[a].text+':';
	}
  }
  if(dev.length<=1){
  	alert("Select an Ascidian species and specific developmental stages first");
	return;
  }
  
  species=window.document.formulaire.species.options[window.document.formulaire.species.selectedIndex].text;

  if ((window.document.anat_keywords == null) || (window.document.anat_keywords.closed == true)) {
    window.document.anat_keywords = window.open("anatomyTreeLine.php?namedev="+names+"&iddev="+dev+"&species="+species,"anat_keywords","menubar=yes,toolbar=no,scrollbars=yes,resizable=yes,height=500,width=600");
  } else {
    window.document.anat_keywords.focus();
  }
}


function update(){
	window.document.formulaire.elements['region[]'].options.length = selected_part.length;
	//ids="";
	for(a=0; a<selected_part.length; ++a){
		window.document.formulaire.elements['region[]'].options[a].text  = selected_part[a][0];//+" ("+selected_part[a][1]+")";
		window.document.formulaire.elements['region[]'].options[a].value = selected_part[a][1];
		//ids+=selected_part[a][1]+":";
	}
	//window.document.formulaire.idanat.value=ids;
}

function addtoarray(name,value){
	selected_part[selected_part.length]=[name,value];
	update();
}

function retrenchtoarray(num){
	selected_part.splice(num,1);
	update();
}

function remove_structures(){
	
	for(a=0; a<selected_part.length; ++a){
		if(window.document.formulaire.elements['region[]'].options[a].selected == true){
			selected_part.splice(a,1);
			window.document.formulaire.elements['region[]'].options[a]=null;
			a-=1;
		}
	}
	update();
	//reloadit();
}

function reset_structures(){
	window.document.formulaire.elements['region[]'].options.length=0;
	selected_part=new Array();
	//window.document.formulaire.idanat.value='';
	//reloadit();
	update();
}


function selectanatomy(){
  for(a=0; a<window.document.formulaire.elements['region[]'].options.length; ++a){
 		window.document.formulaire.elements['region[]'].options[a].selected=true;
  }
}
</script>



<h2><strong><em>Add a Territory affected for Article <? print $id; ?></em></strong> </h2>
<center>

<form name="formulaire" action="edit-article-anatomy2.php" method="post">
            
	        <table width="99%" border="0" cellspacing="0" cellpadding="0">
			  
              <tr> 
                
				<td align="center" valign="top">
				    <strong>Species</strong>
					<br>
					<select name="species" size="1" onChange="javascript: document.forms[0].action='edit-article-anatomy.php?id=<?print $id;?>'; document.forms[0].target='_self'; submit();">
						<option></option>
						<?php
							$species="";
							if (isset($_POST["species"])) $species=$_POST["species"];

							$requete="Select \"NAME\" from \"SPECIES\" order by \"NAME\"";
							$stmt = pg_query($c,$requete);
							while( $row=pg_fetch_array($stmt) ){
								$name=$row["NAME"];
								print "<option";
								if($species==$name)
								    print " selected";
								print ">$name</option>";
							}
						?>
				    </select>&nbsp;
				</td>
                <td align="center" valign="top">
		            <strong>Developmental stage</strong><br>
                    <select name="devstage[]" size="10" multiple style="width:200">
                    
                    <?php
						
						if(strlen($species)>0){
							 $query="SELECT \"NAME\", \"DEV_STAGE_ID\" FROM \"DEV_STAGE\" WHERE \"SPECIES\"='$species' ORDER BY \"DEV_PERCENT\"";
							 $stmt = pg_query($c,$query);
	
							 while($row=pg_fetch_array($stmt)){
								print "<option value=\"".$row["DEV_STAGE_ID"]."\">";
								print $row["NAME"]."</option>\n";
								
							 }
						}
					 ?>
                  </select>
				</td>
				<td align="center" valign="top">
				    
				    <table width="100%" border="0" cellspacing="0" cellpadding="0">
					  <tr>
						<td align="center">
						    <strong>Anatomical part</strong><br>
						    <select name="region[]" size="10" multiple style="width:200">
						        
                            </select>
							<br>
							<img src="pictures/button-add.jpg" onClick="self.popup_anatomy_selector();" border="0">
							<img src="pictures/button-remove.jpg" onClick="self.remove_structures();" border="0">
							<img src="pictures/button-reset.jpg" onClick="self.reset_structures();" border="0">

					    </td>
						
					  </tr>
					</table>

				</td>
              </tr>
			  

<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>


<tr>
<td>&nbsp;</td>
<td align="center">
<h3>Choose a Transcript ID</h3>
<input style="text-align:center;" type="text" name="gene" value="">
<br><br>
</td>
<td>&nbsp;</td>
</tr>

<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
		  
              <tr>
                <td>&nbsp;</td>
				
                <td align="center">
				    <input name="submit" type="image" src="pictures/button-submit.jpg" onClick="self.selectanatomy(); submit">
					&nbsp;&nbsp;
				    <br>
				</td>
		<td>&nbsp;</td>
              </tr>
            </table>

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



<br><br>






</form>

</center>




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