<?php
////////////////////////////////////////////////////////////////////////
// Breeze Website Builder
// Copyright Silver Dolphin Solutions, LLC, Edward Lemmers, P.E.
// For licensing, see license.txt.
// Created: 10/24/2016	ELL
// Modified: 12/2/2016	ELL
// Consolidated all menu items tables into menu_items.
	
	include ("check_session.php");
		
	$menu = $_REQUEST['menu'];
	$menu_item = $_REQUEST['menu_item'];
	$page_name = $_REQUEST['page_name'];
	
	$query = "SELECT * FROM " . BWB_TABLE_PREFIX . "page_data_special WHERE page_name='" . $page_name . "'";
	$result = $bwb_dbh->query($query);
	if ($result->rowCount() > 0)	{
		echo "-page aleady exists-";
		exit;
	}
	
	$body_html = "\n<p>" . CREATE_PAGE_DEFAULT_CONTENT . "</p>\n";
	$today = date("Y-m-d H:i:s");
	$query = "INSERT INTO " . BWB_TABLE_PREFIX . "page_data_special SET page_name='" . $page_name . "', page_content='" . $body_html . "', revised='" . $today . "'";
	$cnt = $bwb_dbh->exec($query);
	// Copy page data to draft table.
	$query = "INSERT INTO " . BWB_TABLE_PREFIX . "page_data_draft SET page_name='" . $page_name . "', page_content='" . $body_html . "', revised='" . $today . "', `source`=1";
	$cnt = $cnt + $bwb_dbh->exec($query);
	
	$query = "UPDATE " . BWB_TABLE_PREFIX . "menu_items SET mega_menu = '" . $page_name . "' WHERE `menu`='" . $menu . "' AND item_text = '" . $menu_item . "'";
	$cnt = $cnt + $bwb_dbh->exec($query);
	
	echo $cnt . "@@@@@" . $page_name . "@@@@@" . $menu . "@@@@@" . $menu_item;
?>