<?php
////////////////////////////////////////////////////////////////////////
// Breeze Website Builder
// Copyright Silver Dolphin Solutions, LLC, Edward Lemmers, P.E.
// For licensing, see license.txt.
// Created: 12/17/2010	ELL
// Revised: 2/10/2012	ELL
// Added table prefix handling.
// Revised: 5/14/2013	ELL
// Added URL escaping and unescaping of URL itself.
// 
//
//

	include ("check_session.php");
	include("lib/unescape_url.php");

	$menu = $_POST['menu'];

	// Build item arrays from POST variables.
	$suffix = substr($menu, 4);
	$menu_items_table = "menu"  . $suffix . "_items";
	
	
	$ID = $_POST["ID"];
	$item_text = $_POST['item_text'];
	$item_text = trim(UnescapeURL($item_text));
	$level = $_POST["level"];
	$URL = $_POST["URL"];
	$URL = trim(UnescapeURL($URL));
	$target = $_POST["target"];
	$sort_order = $_POST["sort_order"];
		
	//Insert new data into table.
	$item_text = str_replace("'", "&#39;", $item_text);
	$item_text = str_replace("\"", "&quot;", $item_text);
	$level = addslashes($level);
	$URL = addslashes($URL);
	$target = addslashes($target);
		
	$query = "UPDATE " . BWB_TABLE_PREFIX . $menu_items_table . " SET item_text='" . $item_text . "', level='" . $level . "', URL='" . $URL . "', target ='" . $target . "', sort_order=" . $sort_order . " WHERE ID=" . $ID;
		$cnt = $bwb_dbh->exec($query);
	
	////////////////////////////////////////////////////////////
	// Re-write menu_items.js with new references.
	$query = "SELECT * FROM " . BWB_TABLE_PREFIX . "menus WHERE menu_name = '$menu'";
	$result = $bwb_dbh->query($query);
	$row = $row = $result->fetch(PDO::FETCH_ASSOC);
	$menu_type = $row['menu_type'];
	if ($menu_type == 1)
		include("save_menu_items_file.php");
	// Re-write sitemap.xml for web crawlers.
	include("generate_site_map.php");
	
	echo "Update complete";

?>
