<?php
////////////////////////////////////////////////////////////////////////
// Breeze Website Builder
// Copyright Silver Dolphin Solutions, LLC, Edward Lemmers, P.E.
// For licensing, see license.txt.
// Created: 1/20/2018	ELL

	include ("check_session.php");
	
	$nCount = $_POST['nCount'];
	
	$id = array();
	$category = array();
	$category_string = array();
	$event_type = array();
	$location_type = array();
	$sort_order = array();
	
	for ($i = 0; $i < $nCount; $i++)
	{
		$id_str = "id" . $i;
		$category_str = "category" . $i;
		$category_string_str = "category_string" . $i;
		$event_type_str = "event_type" . $i;
		$location_type_str = "location_type" . $i;
		
		$id[$i] = $_POST[$id_str];
		$category[$i] = $_POST[$category_str];
		$category_string[$i] = $_POST[$category_string_str];
		if (isset($_REQUEST[$event_type_str]) && ($_REQUEST[$event_type_str] == 1))
			$event_type[$i] = 1;
		else
			$event_type[$i] = 0;
		if (isset($_REQUEST[$location_type_str]) && ($_REQUEST[$location_type_str] == 1))
			$location_type[$i] = 1;
		else
			$location_type[$i] = 0;
		$sort_order[$i] = 10 * ($i + 1);
	}
	
	for ($j = 0; $j < $nCount; $j++)
	{
		$query = "SELECT * FROM `" . BWB_TABLE_PREFIX . "event_location_categories` WHERE `id` = '" . $id[$j] . "'";
		$result = $bwb_dbh->query($query);
		if ($result->rowCount() > 0)
			$query = "UPDATE " . BWB_TABLE_PREFIX . "event_location_categories SET category = '" . $category[$j] . "', category_string = '" . $category_string[$j] . "', event_type = '" . $event_type[$j] . "', location_type = '" . $location_type[$j] . "', sort_order = '" . $sort_order[$j] . "' WHERE id = '" . $id[$j] . "'";
		else
			$query = "INSERT INTO " . BWB_TABLE_PREFIX . "event_location_categories SET category = '" . $category[$j] . "', category_string = '" . $category_string[$j] . "', event_type = '" . $event_type[$j] . "', location_type = '" . $location_type[$j] . "', sort_order = '" . $sort_order[$j] . "'";
		$cnt = $bwb_dbh->exec($query);
	}
	
	echo 1;
?>