<?php
////////////////////////////////////////////////////////////////////////
// Breeze Website Builder
// Copyright Silver Dolphin Solutions, LLC, Edward Lemmers, P.E.
// For licensing, see license.txt.
// Created: 11/11/2009	ELL
// Revised: 11/11/2009	ELL
// Added menu item classes and styles for individual item control.
// Revised: 1/8/2011	ELL
// Added code to remove JavaScript from HTML record if necessary.
// Revised: 2/8/2012	ELL
// Added table prefix handling.
// Revised: 3/23/2015	ELL
// Added deletion of mobile menus.
// 
	include ("check_session.php");
	
	$menu = $_GET['menu'];
	
	if ($menu != "menu1")
	{
		$suffix = substr($menu, 4);
		
		/////// Look for JavaScript Menu and remove code if necessary. ///////////////
		$query = "SELECT * FROM `" . BWB_TABLE_PREFIX . "menus` WHERE `menu_name`='" . $menu . "'";
		$result = $bwb_dbh->query($query);
		$row = $result->fetch(PDO::FETCH_ASSOC);
		$menu_type = $row["menu_type"];
		
		$query = "SELECT * FROM `" . BWB_TABLE_PREFIX . "menus` WHERE `menu_name`='" . $menu . "_mobile'";
		$result = $bwb_dbh->query($query);
		if ($result->rowCount() > 0)	{
			$row = $result->fetch(PDO::FETCH_ASSOC);
			$menu_type_mobile = $row["menu_type"];
		}
		else
			$menu_type_mobile = 0;
			
		
		if (($menu_type == 1) || ($menu_type_mobile == 1))
		{
			$query = "SELECT * FROM `" . BWB_TABLE_PREFIX . "menu_assignments` WHERE `menu_name`='" . $menu . "'";
			$result = $bwb_dbh->query($query);
			$row = $result->fetch(PDO::FETCH_ASSOC);
			$border_area = $row["border_area"];
			include("remove_menu_code.php");
		}
		//////////////////////////////////////////////////////////////////////////////	
		$query = "DELETE FROM `" . BWB_TABLE_PREFIX . "menu_assignments` WHERE `menu_name`='" . $menu . "'";
		$cnt = $bwb_dbh->exec($query);

		$query = "DELETE FROM `" . BWB_TABLE_PREFIX . "menus` WHERE `menu_name`='" . $menu . "'";
		$cnt = $bwb_dbh->exec($query);
		$query = "DELETE FROM `" . BWB_TABLE_PREFIX . "menus` WHERE `menu_name`='" . $menu . "_mobile'";
		$cnt = $bwb_dbh->exec($query);
		
		$query = "DELETE FROM `" . BWB_TABLE_PREFIX . "style_sheets` WHERE `name`='" . $menu . "'";
		$cnt = $bwb_dbh->exec($query);
		$query = "DELETE FROM `" . BWB_TABLE_PREFIX . "style_sheets` WHERE `name`='" . $menu . "_mobile'";
		$cnt = $bwb_dbh->exec($query);
		
		$query = "DELETE FROM `" . BWB_TABLE_PREFIX . "style_sheets` WHERE `name`='" . $menu . "_item'";
		$cnt = $bwb_dbh->exec($query);
		$query = "DELETE FROM `" . BWB_TABLE_PREFIX . "style_sheets` WHERE `name`='" . $menu . "_mobile_item'";
		$cnt = $bwb_dbh->exec($query);
			
		$query = "DROP TABLE IF EXISTS " . BWB_TABLE_PREFIX . "menu"  . $suffix . "_classes";
		$cnt = $bwb_dbh->exec($query);
		$query = "DROP TABLE IF EXISTS " . BWB_TABLE_PREFIX . "menu"  . $suffix . "_mobile_classes";
		$cnt = $bwb_dbh->exec($query);
		
		$query = "DROP TABLE IF EXISTS " . BWB_TABLE_PREFIX . "menu" . $suffix . "_css";
		$cnt = $bwb_dbh->exec($query);
		$query = "DROP TABLE IF EXISTS " . BWB_TABLE_PREFIX . "menu" . $suffix . "_mobile_css";
		$cnt = $bwb_dbh->exec($query);
		
		$query = "DROP TABLE IF EXISTS " . BWB_TABLE_PREFIX . "menu" . $suffix . "_items";
		$cnt = $bwb_dbh->exec($query);
		$query = "DROP TABLE IF EXISTS " . BWB_TABLE_PREFIX . "menu" . $suffix . "_mobile_items";
		$cnt = $bwb_dbh->exec($query);
		
		$query = "DROP TABLE IF EXISTS " . BWB_TABLE_PREFIX . "menu"  . $suffix . "_item_classes";
		$cnt = $bwb_dbh->exec($query);
		$query = "DROP TABLE IF EXISTS " . BWB_TABLE_PREFIX . "menu"  . $suffix . "_mobile_item_classes";
		$cnt = $bwb_dbh->exec($query);
		
		$query = "DROP TABLE IF EXISTS " . BWB_TABLE_PREFIX . "menu" . $suffix . "_item_css";
		$cnt = $bwb_dbh->exec($query);
		$query = "DROP TABLE IF EXISTS " . BWB_TABLE_PREFIX . "menu" . $suffix . "_mobile_item_css";
		$cnt = $bwb_dbh->exec($query);
	}
	
	header("Location: manage_menu.php");
	
?>
