<?php
	/**
	 * Breed search wrapper (usually called from remote.php)  
	 * 
	 * @param $query string to search
	 * @link http://www.oldauntie.org
	 * @author Maggie Marple <oldauntie@oldauntie.org>
	 * @version 1.0
	 */
	function species_search( $query ){
		$sql = "SELECT 
					tsn, 
					completename as complete_name
				FROM ITIS_longnames
				WHERE 
					completename LIKE '%{$query}%'";
		
		$con = new Connection();
		
		$rv = $con->execute($sql);
		
		return $rv;
	}
	
	
	function species_list( $return_only_used = true ){
		$con = new Connection();
		
		$not_clause = "";
		if( $return_only_used == false ){
			$not_clause = "NOT";
		}
		
		$sql = "SELECT * 
					FROM species 
					WHERE tsn " . $not_clause ." IN (
						SELECT DISTINCT tsn FROM pets
						)";
		
		$species_list = $con->execute( $sql );
		
		return $species_list;
	}
	
