<?php
////////////////////////////////////////////////////////////////////////
// Breeze Website Builder
// Copyright Silver Dolphin Solutions, LLC, Edward Lemmers, P.E.
// For licensing, see license.txt.
// Created: 10/12/2009
// Revined: 1/8/2011	ELL
// Added calls for adding and removing JavaScript menu code.
// Revised: 2/7/2012	ELL
// Added table prefix handling.
// Revised: 12/18/2013	ELL
// Added visual feedback for assigning menus.
// Fixed bug.
//
	
	include ("check_session.php");
	
	$border_area = $_REQUEST['border_area'];
	$menu_name = $_REQUEST['menu_name'];
	
	$query = "SELECT * FROM `" . BWB_TABLE_PREFIX . "menu_assignments` WHERE border_area = '$border_area'";
	$result = $bwb_dbh->query($query);
	if ($result->rowCount() == 0)
	{
		if ($menu_name != "-not assigned-")
		{
			$query2 = "INSERT INTO `" . BWB_TABLE_PREFIX . "menu_assignments` SET menu_name = '$menu_name', border_area = '$border_area'";
			$cnt = $bwb_dbh->exec($query2);
		}
	}
	else
	{
		if ($menu_name != "-not assigned-")
			$query2 = "UPDATE `" . BWB_TABLE_PREFIX . "menu_assignments` SET menu_name = '$menu_name' WHERE border_area = '$border_area'";
		else
			$query2 = "DELETE FROM `" . BWB_TABLE_PREFIX . "menu_assignments` WHERE border_area = '$border_area'";
		$cnt = $bwb_dbh->exec($query2);
	}

	header("Location: manage_menu.php?menu_name=$menu_name&border_area=$border_area");
?>