<?php
/////////////////////////////////////////////
// Add Menu Code /////
////////////////////////////////////////////////////////////////////////
// Breeze Website Builder
// Copyright EB Dynamics, Inc., Edward Lemmers, P.E.
// For licensing, see license.txt.
// Revised: 11/13/2009	ELL
// Added code to ensure menu code exists only once and in only one border area.
// Revised to run from multi-menu-type menu assignment console.
// Revised: 2/7/2012	ELL
// Added table prefix handling.  Added reference to script folder constant.
// 
//
	include ("check_session.php");
	
	$today = addslashes(date("m/d/Y  H:m:s"));
	
	if (BWB_WEBPAGE_DIR == "")
		$rel_path = "";
	else
		$rel_path = "../";
	
	// Add code to selected border area.
	$query = "SELECT page_content FROM " . BWB_TABLE_PREFIX . "page_data_special WHERE page_name = '$border_area'";
	$result = mysql_query($query, $bwb_link);
	$row = mysql_fetch_array($result);
	$page_content = $row["page_content"];
	
	$searchStr= "new menu (MENU" . $suffix  . "_ITEMS, MENU" . $suffix  . "_POS);";
	$pos = strrpos($page_content, $searchStr);
	if ($pos === false)
	{
		$page_content .= "\n\n<script language=\"JavaScript\"> new menu (MENU" . $suffix  . "_ITEMS, MENU" . $suffix  . "_POS); </script>\n";
	
		$page_content = addslashes($page_content);
		$query = "UPDATE " . BWB_TABLE_PREFIX . "page_data_special SET page_content='$page_content', revised='$today' WHERE page_name='$border_area'";
		$result = mysql_query($query, $bwb_link);
	}
//	else
//		echo "<br>Note: Menu code already exists in this border area.<br>";
	
	// Add code to all head content.
	$query = "SELECT * FROM `" . BWB_TABLE_PREFIX . "head`";
	$result = mysql_query($query, $bwb_link);
	while ($row = mysql_fetch_array($result))
	{
		$head_content  = $row["head_content"];
		$head_name = $row["head_name"]; 
		
		$searchStr = "<script language='JavaScript' src='" . $rel_path . BWB_SCRIPTS_DIR . "/menu.js'></script>";
		$pos = strrpos($head_content , $searchStr);
		if ($pos === false)
		{
			$head_content .= "\n\n<script language='JavaScript' src='" . $rel_path . BWB_SCRIPTS_DIR . "/menu.js'></script>\n";
    	}
		
		$searchStr = "<script language='JavaScript' src='" . $rel_path . BWB_SCRIPTS_DIR . "/menu" . $suffix . "_items.js'></script>";
		$pos = strrpos($head_content , $searchStr);
		if ($pos === false)
		{
			$head_content .= "\n<script language='JavaScript' src='" . $rel_path . BWB_SCRIPTS_DIR . "/menu" . $suffix . "_items.js'></script>\n";
    	}
		
		$searchStr = "<script language='JavaScript' src='" . $rel_path . BWB_SCRIPTS_DIR . "/menu" . $suffix . "_tpl.js'></script>";
		$pos = strrpos($head_content , $searchStr);
		if ($pos === false)
		{
			$head_content .= "\n<script language='JavaScript' src='" . $rel_path . BWB_SCRIPTS_DIR . "/menu" . $suffix . "_tpl.js'></script>\n";
    	}
		
		$head_content = addslashes($head_content);
		$query2 = "UPDATE `" . BWB_TABLE_PREFIX . "head` SET `head_content`='$head_content', `revised`='$today' WHERE `head_name`='$head_name'";
		$result2 = mysql_query($query2, $bwb_link);
    }

?>