<?php
////////////////////////////////////////////////////////////////////////
// Breeze Website Builder
// Copyright Copyright Silver Dolphin Solutions, LLC, Edward Lemmers, P.E.
// For licensing, see license.txt.
// 
// Revised: 9/30/2011	ELL
// Added building of download files for open-source customers who purchase templates.
// Mode will switch based on whether or not wizard is enabled in options_selected table.
// If wizard is enabled, setup_site.php copies files to perspective folders and runs
// SQL directly on tables just as originally designed.  If wizard is not enabled,
// setup_site.php creates SQL file from all of the SQL commands, copies all of the
// other necessary files to a temp location, zips these files into a single file, and
// initiates download of zip file to customer.  Open-source customers will then upload
// this zip file into their Breeze Website Builder which will then unpack the files and
// apply template to their site automatically by running the SQL commands in the SQL file
// and copying the perspective files to the correct locations.
// Revised: 2/10/2012	ELL
// Added table prefix handling.
// Revised: 12/7/2016	ELL
// Modified for consolidated menu items tables.
//
//

function AddMenuItem($menu, $menu_item, $item_text, $dbh, $wiz_mode, $menu_cnt, $table_prefix)
{
	if ($wiz_mode == 1)
	{
		$query = "SELECT MAX(sort_order) FROM " . $table_prefix . "menu_items WHERE menu = '" . $menu . "'";
		$result = $dbh->query($query);
		$row = $result->fetch(PDO::FETCH_ASSOC);
		$new_sort_order = $row[0] + 1;
	}
	else
		$new_sort_order = $menu_cnt;
	
	$item_text = str_replace("'", "&#39;", $item_text);
	if ($menu_item == "Cart")
		$url = "/shoppingcart/";
	else
		$url = $menu_item . ".php";

	$query = "INSERT INTO " . $table_prefix . "menu_items (menu, item_text, level, URL, target, sort_order) VALUES('$menu', '$item_text', 0, '$url', '_self', $new_sort_order)";
	if ($wiz_mode == 1)
		$cnt = $dbh->exec($query);
	else
		$query .= ";\n";
	return($query);
}
?>
