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



<?php
$species=$_POST["species"];
if(strlen($species)<=0){
    print "ERROR: please select a species.";
	include("frames_footer.php");
	return;
}

$requete="Select * from \"MOL_ENTITY\" where \"SPECIES\"='$species'";
$stmt01 = pg_query($c,$requete) or die("<strong>Error</strong> ".pg_last_error($c));
if(!$row01=pg_fetch_array($stmt01))
{
      $requete="Select * from \"IN_SITU\" where \"SPECIES\"='$species'";
      $stmt02 = pg_query($c,$requete) or die("<strong>Error</strong> ".pg_last_error($c));
      if(!$row02=pg_fetch_array($stmt02))
      {
            $requete="Select * from \"DEV_STAGE\" where \"SPECIES\"='$species'";
            $stmt03 = pg_query($c,$requete) or die("<strong>Error</strong> ".pg_last_error($c));
            if(!$row03=pg_fetch_array($stmt03))
            {
                  $requete="Select * from \"ANAT_ENTITY\" where \"SPECIES\"='$species'";
                  $stmt04 = pg_query($c,$requete) or die("<strong>Error</strong> ".pg_last_error($c));
                  if(!$row04=pg_fetch_array($stmt04))
                  {
			pg_query($c,"begin");
                        $requete="Delete from \"SPECIES\" where \"NAME\"='$species'";
                        $stmt05= pg_query($c,$requete) or die("<strong>Error</strong> ".pg_last_error($c));
                 	pg_query($c,"commit");
                           
                                    print "<br><center><H1>$species deleted.</H1></center>";
                                    print '<center><input name="Exit" type="button" value="-= Close window =-" onClick="javascript:self.close();"></center>';
                           
                        
                  }
                  else
                  {
                         print "<br><center><H1>Cannot Delete: an anatomical part refers to this species.</H1></center>";
                         print '<center><input name="Exit" type="button" value="-= Close window =-" onClick="javascript:self.close();"></center>';
                  }
            }
            else
            {
                  print "<br><center><H1>Cannot Delete: a developpement stage refers to this species.</H1></center>";
                  print '<center><input name="Exit" type="button" value="-= Close window =-" onClick="javascript:self.close();"></center>';
            }
      }
      else
      {
            print "<br><center><H1>Cannot Delete: an in situ refers to this species.</H1></center>";
            print '<center><input name="Exit" type="button" value="-= Close window =-" onClick="javascript:self.close();"></center>';
      }
}
else
{
      print "<br><center><H1>Cannot Delete: a molecular entity refers to this species.</H1></center>";
      print '<center><input name="Exit" type="button" value="-= Close window =-" onClick="javascript:self.close();"></center>';
}

?>


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