#!/usr/bin/perl

use lib '..';
use CGI;
use CGI::Carp qw(fatalsToBrowser);
use DATobj;
use HTMLfile;
use BN2 qw(safe_param);
use LOCALprofile;
use strict;

my $query = new CGI;
my $latin = $query->param("latin");

my ($s, $m, %species);
my %name = ( "bird"		=> "bird",
							"but"			=> "butterfly",
							"drag"		=> "dragonfly",
							"invert"	=> "invertebrate",
							"mam"			=> "mammal",
							"moth"		=> "moth",
							"plant"		=> "plant" );
							
print $query->header();

foreach $s (qw(bird but drag invert mam moth plant)) {
	my $dat = DATobj->new($s . "bap.txt");
	$dat->order_by("sort") unless $latin;
	$dat->order_by("Latin-Name") if $latin;
	my @matches = $dat->select();
	my $sname = $name{$s};
	$species{$s} .= qq{<option value="">Choose a $sname...};
	foreach $m (@matches) {
		my $n = $m->{"Name"};
		my $d = $n;
		
		if ($latin and $m->{"Latin-Name"}) {
			$d = $m->{"Latin-Name"};
			$n = ".$d";
		}
		
		$species{$s} .= qq{<option value="$n">$d
		} if $n;
	}
}


print HTMLtemplate("templ/choose-species.html",
	\%species );

exit;
