Location: PHPKode > scripts > Expandable Menu > expandable-menu/adv_expand_menu.php
<?php
session_start(); //	(Avram) now we use sessions to transfer informations :-)
include_once('db_connect.php');
class AdvExpMenu extends DbConnect {
	var $_MainMenuItems		=	array();
	var $_MenuItems			=	array();
	var $_SubMenuItems		=	array();
	var $cfg;
	var $_DirLevel;
	function AdvExpMenu() {
		$this->cfg = include('menu.config.inc.php');
		$this->StoreData();
	}
	function LoadMenuState($MenuName)
	{
		if(strtoupper($this->cfg['MenuType']) == "CSS") {
			return " onload=\"MenuState('$MenuName','On','$MenuName"."Arw')\"";
		} else {
			return " onload=\"MenuState('$MenuName','On')\"";
		}
	}
	function SetDirLevel($x)
	{
		$this->_DirLevel			= $x;
	}
	//functions added by Avram, Modified by Evil Wizard
	function StoreData()
	{
		$data = array();
		$data['MenuWidth']				=	$this->cfg['common']['MenuWidth'];
		$data['MenuItemHeight']			=	$this->cfg['common']['MenuItemHeight'];
		$data['MainMenuColor']			=	$this->cfg['common']['MainMenuColor'];
		$data['MainMenuHoverColor']		=	$this->cfg['common']['MainMenuHoverColor'];
		$data['SubMenuColor']			=	$this->cfg['common']['SubMenuColor'];
		$data['SubMenuHoverColor']		=	$this->cfg['common']['SubMenuHoverColor'];
		$data['MenuSeperatorColor']		=	$this->cfg['common']['MenuSeperatorColor'];
		$data['MenuFontMainColor']		=	$this->cfg['common']['MainMenuTextColor'];
		$data['MenuFontShadowColor']	=	$this->cfg['IMG']['MenuFontShadowColor'];
		$data['MenuFontSize']			=	$this->cfg['IMG']['MenuFontSize'];
		$_SESSION['MenuData']			=	$data;
	}
	//eo functions added by Avram
	function AddMainMenuItem($mnuName, $mnuText, $mnuType, $mnuHref, $mnuTitle, $mnuIndex, $mnuSubState='show')
	{
		if ($mnuName == "" || $mnuText == "" || $mnuType == "" || $mnuHref == "" || $mnuIndex == "") {
			return false;
		} else {
			$this->_MainMenuItems[] = array($mnuName, $mnuText, $mnuType, $mnuHref, $mnuTitle, $mnuIndex, $mnuSubState);
			return true;
		}
	}
	function AddSubMenuItem($mnuName, $mnuText, $mnuHref, $mnuTitle, $mnuParentName, $mnuIndex)
	{
		if($mnuParentName == "") {
			return false;
		} else {
			$this->_SubMenuItems[$mnuParentName][] = array($mnuName, $mnuText, $mnuHref, $mnuTitle, $mnuParentName, $mnuIndex);
			return true;
		}
	}
	function BuildMenu()
	{
		$MenuTags = $this->GetRequiredJS() . $this->GetMenuCSS();
		if(strtoupper($this->cfg['MenuType']) == "CSS") {
			$MenuTags .= $this->BuildCSSMenu();
		} else {
			$MenuTags .= $this->BuildIMGMenu();
		}
		return $MenuTags;
	}
	function BuildCSSMenu()
	{
		$mColor = $this->cfg['common']['MainMenuColor'];
		$mhColor = $this->cfg['common']['MainMenuHoverColor'];
		$mnuTags = "<table cellpadding=\"0\" cellspacing=\"0\" width=\"". $this->cfg['common']['MenuWidth'] ."\" style=\"border: 1px solid ". $this->cfg['CSS']['SeperatorColor'] ."; border-bottom-width: 0px;\">
";
		foreach($this->_MainMenuItems as $mnuItem) {
			if(strtoupper($mnuItem[2]) == "SUB") {
				$mnuTags .= $this->BuildCSSSubMenu($mnuItem);
			} else {
				$mnuTags .= "<tr bgcolor=\"$mColor\" onmouseover=\"PMenuHover('Row". $mnuItem[0] ."','$mhColor',1)\" onmouseout=\"PMenuHover('Row". $mnuItem[0] ."','$mColor',0)\" onclick=\"document.all.Menu". $mnuItem[0] .".click()\" id=\"Row". $mnuItem[0] ."\">
<td class=\"nav\" colspan=\"2\" height=\"20\">&nbsp;
<a href=\"". $this->_DirLevel . $mnuItem[3] ."\" title=\"". $mnuItem[4] ."\" class=\"mnuLnk\" name=\"Menu". $mnuItem[0] ."\">". $mnuItem[1] ."</a></td></tr>
<tr bgcolor=\"". $this->cfg['CSS']['SeperatorColor'] ."\"><td height=\"1\" colspan=\"2\"></td></tr>
";
			}
		}
		$mnuTags .= "</table>";
		return $mnuTags;
	}
	function BuildCSSSubMenu($mnuParent)
	{
		$mColor = $this->cfg['common']['MainMenuColor'];
		$mhColor = $this->cfg['common']['MainMenuHoverColor'];
		$smColor = $this->cfg['common']['SubMenuColor'];
		$smhColor = $this->cfg['common']['SubMenuHoverColor'];
		if($mnuParent[6] == "") {
			$mnuParent[6] = "show";
		}
		if(isset($this->_SubMenuItems[$mnuParent[0]])) {
			$arwsImg = ($mnuParent[6] == "show" ? "/arw_up.gif" : "/arw_down.gif");
			$mnuSubTags = "<tr bgcolor=\"$mColor\" onmouseover=\"PMenuHover('Row". $mnuParent[0] ."','$mhColor',1)\" onmouseout=\"PMenuHover('Row". $mnuParent[0] ."','$mColor',0)\" height=\"20\" onclick=\"document.all.Menu". $mnuParent[0] .".click()\" id=\"Row". $mnuParent[0] ."\">
<td class=\"nav\">&nbsp;
<a href=\"JavaScript:Sub_Menu('". $mnuParent[0] ."','". $mnuParent[0] ."Arw')\" title=\"". $mnuParent[4] ."\" class=\"mnuLnk\" name=\"Menu". $mnuParent[0] ."\">
". $mnuParent[1] ."</a></td>
<td align=\"right\">
<img src=\"". $this->_DirLevel . $this->cfg['CSS']['ImageBase'] . $arwsImg ."\" border=\"0\" align=\"right\" width=\"18\" height=\"18\" id=\"". $mnuParent[0] ."Arw\"></td></tr>
<tr bgcolor=\"". $this->cfg['CSS']['SeperatorColor'] ."\"><td height=\"1\" colspan=\"2\"></td></tr>
<tr bgcolor=\"$smColor\" id=\"". $mnuParent[0] ."\" style=\"display:". $mnuParent[6] ."\">
<td colspan=\"2\">
<table width=\"101%\" cellpadding=\"0\" cellspacing=\"0\">
";
			foreach($this->_SubMenuItems[$mnuParent[0]] as $mnuSubItem) {
				$mnuSubTags .= "<tr bgcolor=\"$smColor\" onmouseover=\"PMenuHover('Row". $mnuSubItem[0] ."','$smhColor',1)\" onmouseout=\"PMenuHover('Row". $mnuSubItem[0] ."','$smColor',0)\" height=\"20\" onclick=\"document.all.Sub". $mnuSubItem[0] .".click()\" id=\"Row". $mnuSubItem[0] ."\">
<td class=\"nav\" >
<a href=\"". $this->_DirLevel . $mnuSubItem[2] ."\" title=\"". $mnuSubItem[3] ."\" class=\"smnuLnk\" name=\"Sub". $mnuSubItem[0] ."\">
 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;". $mnuSubItem[1] ."</a></td></tr>
<tr bgcolor=\"". $this->cfg['CSS']['SeperatorColor'] ."\"><td height=\"1\"></td></tr>
";
			}
			$mnuSubTags .= "</table></td></tr>";
			return $mnuSubTags;
		} else {
			return false;
		}
	}
	function BuildIMGMenu($border = 0)
	{
		$mColor = $this->cfg['common']['MainMenuColor'];
		$mhColor = $this->cfg['common']['MainMenuHoverColor'];
		$mnuTags = "<table cellpadding=\"0\" border=\"$border\" cellspacing=\"0\"". $this->cfg['common']['MenuWidth'] .">
";
		foreach($this->_MainMenuItems as $mnuItem) {
			if(strtoupper($mnuItem[2]) == "SUB") {
				$mnuTags .= $this->BuildIMGSubMenu($mnuItem);
			} else {
				$mnuTags .= "<tr>
<td colspan=\"2\" height=\"". ($this->cfg['common']['MenuItemHeight'] +1) ."\" valign=\"middle\"><a href=\"". $this->_DirLevel . $mnuItem[3] ."\" title=\"". $mnuItem[4] ."\"><img src=\"". $this->cfg['IMG']['ButtonScriptFile'] ."?text=". $mnuItem[1] ."&typ=_std\" onmouseover='PMenuImageSwap(this,\"text=". $mnuItem[1] ."&typ=_hov\")' onmouseout='PMenuImageSwap(this,\"text=". $mnuItem[1] ."&typ=_std\")' border=\"0\" alt=\"". $mnuItem[4] ."\"></a></td></tr>
";
			}
		}
		$mnuTags .= "</table>";
		return $mnuTags;
	}
	function BuildIMGSubMenu($mnuParent)
	{
		$mColor = $this->cfg['common']['MainMenuColor'];
		$mhColor = $this->cfg['common']['MainMenuHoverColor'];
		$smColor = $this->cfg['common']['SubMenuColor'];
		$smhColor = $this->cfg['common']['SubMenuHoverColor'];
		if($mnuParent[6] == "") {
			$mnuParent[6] = "show";
		}
		if(isset($this->_SubMenuItems[$mnuParent[0]])) {
			$mnuSubTags = "<tr height=\"". ($this->cfg['common']['MenuItemHeight'] +1) ."\">
<td valign=\"middle\"><a href=\"JavaScript:Sub_Menu('". $mnuParent[0] ."')\" title=\"". $mnuParent[4] ."\" name=\"Menu". $mnuParent[0] ."\"><img alt=\"". $mnuItem[4] ."\" src=\"". $this->cfg['IMG']['ButtonScriptFile'] ."?text=". $mnuParent[1] ."&typ=_std&extra=par\" onmouseover=\"PMenuImageSwap(this,'text=". $mnuParent[1] ."&typ=_hov&extra=par')\" onmouseout=\"PMenuImageSwap(this,'text=". $mnuParent[1] ."&typ=_std&extra=par')\" border=\"0\"></a></td>

</tr>
<tr id=\"". $mnuParent[0] ."\" style=\"display:". $mnuParent[6] ."\">
<td colspan=\"2\">
<table width=\"101%\" cellpadding=\"0\" cellspacing=\"0\">
";
			foreach($this->_SubMenuItems[$mnuParent[0]] as $mnuSubItem) {
				$mnuSubTags .= "<tr>
<td height=\"". ($this->cfg['common']['MenuItemHeight'] +1) ."\" valign=\"middle\"><a href=\"". $this->_DirLevel . $mnuSubItem[2] ."\" title=\"". $mnuSubItem[3] ."\"><img src=\"". $this->cfg['IMG']['ButtonScriptFile'] ."?text=". $mnuSubItem[1] ."&typ=_std&extra=sub\" onmouseover=\"PMenuImageSwap(this,'text=". $mnuSubItem[1] ."&typ=_hov&extra=sub')\" onmouseout=\"PMenuImageSwap(this,'text=". $mnuSubItem[1] ."&typ=_std&extra=sub')\" border=\"0\"></a></td></tr>
";
			}
			$mnuSubTags .= "</table></td></tr>";
			return $mnuSubTags;
		} else {
			return false;
		}
	}
	function GetRequiredJs()
	{
		$Js = "<script language=\"Javascript\">
<!--
function GetObj(ObjName)
{
	if (document.getElementById)
	 	return document.getElementById(ObjName);
	else if (document.all)
	 	return document.all[ObjName];
	else
		return null;
}
";
		if(strtoupper($this->cfg['MenuType']) == "CSS") {
			$Js .= "function MenuState(eId, state, arw) {
	var x = GetObj(eId);
	var xI = GetObj(arw);
	if (state == 'On') {
		x.style.display = '';
		xI	.src = '". $this->_DirLevel . $this->cfg['CSS']['ImageBase'] ."/arw_up.gif';
	} else {
		x.style.display = 'none';
		xI.src = '". $this->_DirLevel . $this->cfg['CSS']['ImageBase'] ."/arw_down.gif';
	}
}
function Sub_Menu(ele, arw) {
	var x = GetObj(ele);
	var xI = GetObj(arw);
	xmenu = ele + 'Menu';
	if (x.style.display == 'none') {
		x.style.display = '';
		xI.src = '". $this->_DirLevel . $this->cfg['CSS']['ImageBase'] ."/arw_up.gif';
		document.cookie = xmenu + '=' + 'On';		
	} else {
		x.style.display = 'none';
		xI.src = '". $this->_DirLevel . $this->cfg['CSS']['ImageBase'] ."/arw_down.gif';
		document.cookie = xmenu + '=' + 'Off';		
	}
};
function PMenuHover(objName,lpBColorVal,lpCursor)
{
	var x = GetObj(objName);
		x.style.background = lpBColorVal;
	if (lpCursor == 1 ) {
		x.style.cursor = 'pointer';
	};
};
-->
</script>
";
		} else {
			$Js .= "function PMenuImageSwap(objName, queryString)
{
	objName.src = \"". $this->cfg['IMG']['ButtonScriptFile'] ."?\" + queryString;
};
function Sub_Menu(ele) {
	var x = GetObj(ele);
	xmenu = ele + 'Menu';
	if (x.style.display == 'none') {
		x.style.display = '';
		document.cookie = xmenu + '=' + 'On';		
	} else {
		x.style.display = 'none';
		document.cookie = xmenu + '=' + 'Off';		
	}
};
function MenuState(eId, state) {
	var x = GetObj(eId);
	if (state == 'On') {
		x.style.display = '';
	} else {
		x.style.display = 'none';
	}
}
-->
</script>
";
		}
		return $Js;
	}
	function GetMenuCSS()
	{
		if(strtoupper($this->cfg['CSS']['CssType']) == "EXTERNAL" && $this->cfg['CSS']['ExternalCssURL'] != "" && strtoupper($this->cfg['MenuType']) == "CSS") {
			$Css = "<link href=\"". $this->cfg['CSS']['ExternalCssURL'] ."\" rel=\"stylesheet\" type=\"text/css\">\n";
		} elseif(strtoupper($this->cfg['CSS']['CssType']) == "INTERNAL" && strtoupper($this->cfg['MenuType']) == "CSS") {
			$Css = "<style type=\"text/css\">
<!-- 
a.mnuLnk:link, a.mnuLnk:active, a.mnuLnk:visited
{
	font-size:10pt; font-family:Verdana, Arial, Helvetica, sans-serif; font-weight:bold; color:#2F3C71; text-decoration:none;
 }
a.mnuLnk:hover
{
	color:black; text-decoration:none;
 }
a.smnuLnk:link, a.smnuLnk:active, a.smnuLnk:visited
{
	font-size:10pt; font-family:Verdana, Arial, Helvetica, sans-serif; font-weight:bold; color:#2F4d82; text-decoration:none;
 }
a.smnuLnk:hover
{
	color:black; text-decoration:none;
 }
-->
</style>
";
		}
	return $Css;
	}
	function GetMenuList($tblName)
	{
		$this->Results = array();
		$this->SetDbTableName($tblName);
		$result = $this->GetResults();
		return $this->Results;
	}
}
?>
Return current item: Expandable Menu