<?php
include ("check_session.php");

$search_str = trim($_POST['search_str']);
$search_str = str_replace("SINGLEQUOTE", "'", $search_str);
$search_str = str_replace("AMPERSAND", "&", $search_str);
$search_str2 = str_replace("'", "&#39;", $search_str);
$search_str3 = str_replace("&amp;", "&", $search_str);
$search_str4 = str_replace("&", "&amp;", $search_str);
$search_str = addslashes($search_str);
$search_str3 = addslashes($search_str3);
$search_str4 = addslashes($search_str4);

$filter_city_location_search = $_POST['filter_city_location_search'];

if ((!isset($search_str)) || ($search_str == ""))
{
	echo "Location not found";
	exit;
}

if ($filter_city_location_search == "-not selected-")
	$query = "SELECT * FROM " . BWB_TABLE_PREFIX . "locations WHERE (`location_name` LIKE '%" . $search_str . "%' OR `address` LIKE '%" . $search_str . "%' OR `location_name` LIKE '%" . $search_str2 . "%' OR `address` LIKE '%" . $search_str2 . "%' OR `location_name` LIKE '%" . $search_str3 . "%' OR `address` LIKE '%" . $search_str3  . "%' OR `location_name` LIKE '%" . $search_str4 . "%' OR `address` LIKE '%" . $search_str4 . "%')";
else
	$query = "SELECT * FROM " . BWB_TABLE_PREFIX . "locations WHERE (`location_name` LIKE '%" . $search_str . "%' OR `address` LIKE '%" . $search_str . "%' OR `location_name` LIKE '%" . $search_str2 . "%' OR `address` LIKE '%" . $search_str2 . "%' OR `location_name` LIKE '%" . $search_str3 . "%' OR `address` LIKE '%" . $search_str3 . "%' OR `location_name` LIKE '%" . $search_str4 . "%' OR `address` LIKE '%" . $search_str4 . "%') AND (city = '" . $filter_city_location_search. "')";
	
//	echo $query;
	
$result = $bwb_dbh->query($query);
if ($result->rowCount() > 0)
{
	$location_name = "";
	$delim = "";
	while($row = $result->fetch(PDO::FETCH_ASSOC))
	{
		$location_name .= $delim . $row['location_name'];
		$delim = "::";
	}
	echo $location_name;
}
else
	echo "Location not found";
?>