<?php
////////////////////////////////////////////////////////////////////////
// Breeze Website Builder
// Copyright Silver Dolphin Solutions, LLC, Edward Lemmers, P.E.
// For licensing, see license.txt.
// Created: 2/21/2014
//
include ("check_session.php");

$location_name = $_POST['location_name'];
if ($location_name != "-all locations-")	{
	$location_name = str_replace("SINGLEQUOTE", "'", $location_name);
	$location_name = str_replace("AMPERSAND", "&", $location_name);
	$location_name_2 = str_replace("'", "&#39;", $location_name);
	$location_name_3 = str_replace("&amp;", "&", $location_name);
	$location_name_4 = str_replace("&", "&amp;", $location_name);
}

if ($location_name == "-all locations-")	{
	$query = "SELECT DISTINCT city FROM " . BWB_TABLE_PREFIX . "locations ORDER BY city";
	$stmt = $bwb_dbh->prepare($query);
	$stmt->execute();
}
else	{
		$query = "SELECT DISTINCT city FROM `" . BWB_TABLE_PREFIX . "locations` WHERE `location_name` = :location_name OR `location_name` = :location_name_2 OR `location_name` = :location_name_3 OR `location_name` = :location_name_4";
	$stmt = $bwb_dbh->prepare($query);
	$stmt->execute(array(':location_name' => $location_name, ':location_name_2' => $location_name_2, ':location_name_3' => $location_name_3, ':location_name_4' => $location_name_4));
}

if ($stmt->rowCount() > 0)
{
	$cities = array();
	$i = 0;
	while ($row = $stmt->fetch(PDO::FETCH_ASSOC, PDO::FETCH_ORI_NEXT))
	{
		$cities[$i] = $row['city'];
		$i++;
	}
	print json_encode($cities);
}
else
	echo "-no data-";
?>