<?php
if (!isset($_SESSION['FirstName'])) {
	session_start();
}
include ('includes/db1config.php');
include ('../includes/mysql_connect.php');
include ('includes/admin-config.php');


if (!isset($_POST['recordKey']) || empty($_POST['recordKey'])) {
	die('Record key not set.');
}

$recordKey = $_POST['recordKey'];

if (isset($_POST['chkdelete']) && $_POST['chkdelete'] == 'true') {
	// delete record
	mysql_query("DELETE FROM menuCategory WHERE recordKey = '".mysql_real_escape_string($recordKey)."'") or die(mysql_error());
	die('1');
}

if (isset($_POST['action']) && $_POST['action'] == 'update-img') {
	// update header img
	if (!isset($_POST['newImage']) || empty($_POST['newImage'])) {
		die('New image not specified.');
	}

	$newHeaderImage = $_POST['newImage'];
	$sql = "UPDATE menuCategory SET headerImg = '".mysql_real_escape_string($newHeaderImage)."' WHERE recordKey = '".$recordKey."'";
	mysql_query($sql) or die(mysql_error());

	die('1');
}

// required fields for all
if (!isset($_POST['category']) || !isset($_POST['description'])) {
	die('Category or description not set.');
}

$alias = $_POST['alias'];
$categoryName = $_POST['category'];
$categoryDescription = $_POST['description'];
$categoryActive = ($_POST['chkactive'] == 'true') ? 1 : 0;
$categoryType = $_POST['cattype'];
//$str = print_r($_POST);
//mail("apicton@pilotwebsolutions.com", "updating cat settings - POST", $str);

$sql = "UPDATE menuCategory SET 
		categoryName = '".mysql_real_escape_string($categoryName)."',
		description = '".mysql_real_escape_string($categoryDescription)."',
		active = '".mysql_real_escape_string($categoryActive)."',
		category_type = '".mysql_real_escape_string($categoryType)."',
		alias = '".mysql_real_escape_string($alias)."'
		WHERE recordKey = '".mysql_real_escape_string($recordKey)."'";
		//die($sql);
		//mail("apicton@pilotwebsolutions.com", "updating cat settings", $sql);
		
mysql_query($sql) or die(mysql_error());
include "monitorchanges.php";
echo '1';
?>
