<?php
	/**
	 * General 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 general_search( $query ){
		$pets 	= array();
		$owners = array();
		$visits	= array();
		
		
		$prefix = substr( $query, 0, strlen( _VISIT_ID_PREFIX ) );
		$number = substr( $query, strlen( _VISIT_ID_PREFIX ) );
		
		// query is a visit starting with the VISIT PREFIX (i.e. a capital V and Visit ID appears like V + numeric ID V1234567 )
		if ( $prefix === _VISIT_ID_PREFIX ){
			if ( is_int ( intval( $number ) ) == true ){
				// query is just the numeric ID as is in Database table (auto-increment) 
				$query = $number;
				
				$visits	= visit_search( $query );
				// $visits = Data::isNull ( $owners, array() );
			}
		}else{
			$pets = pet_search( $query );
			$pets = Data::isNull ( $pets, array() );
		
			$owners = owner_search( $query );
			$owners = Data::isNull ( $owners, array() );
		}
		
		
		$output = array_merge( $pets, $owners, $visits );
		
		return $output;
	}
