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

$location_id = $_POST['location_id'];
$location_name = addslashes($_POST['location_name']);
$location_name = str_replace("AMPERSAND", "&", $location_name);
$address = addslashes($_POST['address']);
$address2 = addslashes($_POST['address2']);
$city = addslashes($_POST['city']);
$state = $_POST['state'];
$country = $_POST['country'];
$postal_code = $_POST['postal_code'];
$phone = $_POST['phone'];
$phone2 = $_POST['phone2'];
$fax = $_POST['fax'];
$website = addslashes($_POST['website']);
if (stripos($website, "http", 0) === false)
	$website = "http://" . $website;
$web_link_text = addslashes($_POST['web_link_text']);
$email = addslashes($_POST['email']);
$location_description = addslashes($_POST['location_description']);
$location_description = str_replace("AMPERSAND", "&", $location_description);
$location_categories = $_POST['location_categories'];
$location_status = $_POST['location_status'];
if (isset($_REQUEST["location_owner"]) && ($_REQUEST["location_owner"] != ""))
		$location_owner = $_REQUEST["location_owner"];
	else
		$location_owner = "";
$location_active = $_REQUEST["location_active"];
		
$today = date("Y-m-d H:i:s");

	$query = "SELECT * FROM " . BWB_TABLE_PREFIX . "locations WHERE location_id='$location_id'";
	$result = $bwb_dbh->query($query);
	if ($result->rowCount() > 0)	{
		$query = "UPDATE " . BWB_TABLE_PREFIX . "locations SET location_name = '$location_name', address = '$address', address2 = '$address2', city = '$city', state = '$state', country = '$country', postal_code = '$postal_code', phone = '$phone', phone2 = '$phone2', fax = '$fax', website = '$website', web_link_text = '$web_link_text', email = '$email', location_description = '$location_description', location_categories = '$location_categories', location_status = $location_status, location_active = $location_active WHERE location_id = $location_id";
		$action = "Update event ID $location_id: ";
	}
	else	{
		$query = "INSERT INTO " . BWB_TABLE_PREFIX . "locations SET location_name = '$location_name', address = '$address', address2 = '$address2', city = '$city', state = '$state', country = '$country', postal_code = '$postal_code', phone = '$phone', phone2 = '$phone2', fax = '$fax', website = '$website', web_link_text = '$web_link_text', email = '$email', location_description = '$location_description', location_categories = '$location_categories', location_status = $location_status, location_active = $location_active, location_owner = '$location_owner', `created` = '$today'";
		$action = "Insert: ";
	}
//	echo $query . "<br><br>\n\n";
	$result = $bwb_dbh->exec($query);
	
	if (strpos($action, "Insert") > -1)
		$location_id = $bwb_dbh->lastInsertId();
	echo $location_id;
?>