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

<?php
$species = $_GET["species"];
$nomstade = $_GET["nomstade"];
$devid = $_GET["dev"];
//echo "$species ||||| $nomstade |||||| $devid";



$requete="select * from \"TARGET\" where \"TARGET_ID\" in (select \"ANAT_ID\" from \"ANAT_ENTITY\" where \"DEV_STAGE_ID\" ='$devid')";
$stmt00= pg_query($c,$requete) or die("<strong>Error</strong> ".pg_last_error($c));

if(!$row00=pg_fetch_array($stmt00))
{
      $requete="select \"ANAT_ID\" from \"ANAT_ENTITY\" where \"DEV_STAGE_ID\"='$devid' and \"SPECIES\"='$species'";
      $stmt01= pg_query($c,$requete) or die("<strong>Error</strong> ".pg_last_error($c));

/*Debut de la transaction*/
pg_query($c,"begin");

      while($row01=pg_fetch_array($stmt01))
      {
            $anatid=$row01["ANAT_ID"];
            $requete="delete from \"FATE\" where \"ANAT_ID\"='$anatid'";
            $stmt02= pg_query($c,$requete) or die("<strong>Error</strong> ".pg_last_error($c));
            
            $requete="delete from \"ANAT_ENTITY\"  where \"ANAT_ID\"='$anatid' and \"DEV_STAGE_ID\"='$devid' and \"SPECIES\"='$species'";
            $stmt03= pg_query($c,$requete) or die("<strong>Error</strong> ".pg_last_error($c));
            
                        
            $requete="delete from \"BIO_ENTITY\"  where \"BIO_ID\"='$anatid' ";
            $stmt04= pg_query($c,$requete) or die("<strong>Error</strong> ".pg_last_error($c));
                        
           
               
      }
      
      
      
      $requete="delete from \"DEV_STAGE\" where \"DEV_STAGE_ID\"='$devid' and \"SPECIES\"='$species' ";
      $stmt05= pg_query($c,$requete) or die("<strong>Error</strong> ".pg_last_error($c));
      
      
/*Commit de la transaction*/      
      
pg_query($c,"commit");
      
      // V�ification de la validation : si une erreur est survenue, afficher le message d'erreur

             print "<br><center><H1>Delete done for $nomstade ($species).</H1></center>";
             print '<center><input name="Exit" type="button" value="-= Close window =-" onClick="javascript:self.close();"></center>';
      
      
}
else
{
      print "<br><center><H1>This tree cannot be deleted: an in situ refers to it.</H1></center>";
      print '<center><input name="Exit" type="button" value="-= Close window =-" onClick="javascript:self.close();"></center>';

}





?>


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