<?php
////////////////////////////////////////////////////////////////////////
// Breeze Website Builder
// Copyright Silver Dolphin Solutions, LLC, Edward Lemmers, P.E.
// For licensing, see license.txt.
// Created: 2/18/2018	ELL
// Revised: 2/26/2018	ELL
// Added 3rd menu category for systems that ane not mobile (cell phones) but have touchscreens.
// 
// 
	include ("check_session.php");
	
	$source_menu = $_POST['source_menu'];
	$destination_menu_type = $_POST['destination_menu_type'];
	$menu_parts = explode("_", $source_menu);
	$menu_prefix = $menu_parts[0];
	
	$suffix = substr($menu_name, strlen("menu"));
	if ($destination_menu_type != "desktop")
		$menu_mobile_touchscreen = $menu_prefix . "_" . $destination_menu_type;
	else
		$menu_mobile_touchscreen = $menu_prefix;
	
	$sql = "DELETE FROM `" . BWB_TABLE_PREFIX . "menu_items` WHERE `menu` = '" . $menu_mobile_touchscreen . "'";
	$cnt = $bwb_dbh->exec($sql);
	
	$query = "SELECT * FROM `" . BWB_TABLE_PREFIX . "menu_items` WHERE `menu` = '" . $source_menu . "'";
	$result = $bwb_dbh->query($query);
	if ($result->rowCount() > 0)
	{
		while ($row = $result->fetch(PDO::FETCH_ASSOC))
		{
			$sql = "INSERT INTO `" . BWB_TABLE_PREFIX . "menu_items` SET `menu` = '" . $menu_mobile_touchscreen . "'";
			foreach($row as $key => $val)
			{
				if (($key != 'menu') && ($key != 'ID'))
					$sql .= ", `" . $key . "` = '" . $val . "'";
			}
			$cnt = $bwb_dbh->exec($sql);
		}
	}

	header("Location: manage_menu.php");
?>