Location: PHPKode > projects > Phparchive > phparchive.0.1.86.beta/includes/menubar.inc.php
<?php
/**
 *
 * @version $Id: menubar.inc.php,v 1.7 2003/12/27 12:09:14 freedev Exp $
 * @author Vincenzo D'Amore <hide@address.com>
 * @package wa_includes
 */

/**
 * Submit recursively all queries to build the menu tree
 */

function menu_load($iParent, $iIdGroup, &$aMenuConfiguration)
{
	$sUrl = "";
	if (!is_array($aMenuConfiguration))
		$aMenuConfiguration = array();

	$query = "SELECT tbmenu.WAIdMenu, tbmenu.WAMenu, tbmenu.WAIdParent, tbmenu.WAUrl, tbmenu.WASortValue, tbmenu.WAAbstract, tbmenu.WAIdForm, tbgroupsmenu.WAIdGroup ";
	// , tbforms.WADescr
	$query .= " FROM tbmenu INNER JOIN tbgroupsmenu ON tbmenu.WAIdMenu = tbgroupsmenu.WAIdMenu ";
//	$query .= " FROM (tbmenu LEFT JOIN tbforms ON tbmenu.WAIdMenu = tbforms.WAIdMenu) INNER JOIN tbgroupsmenu ON tbmenu.WAIdMenu = tbgroupsmenu.WAIdMenu ";
	$query .= " WHERE ";
//	$query .= " WAIdGroup = ".$iIdGroup;
	$query .= " WAIdGroup IN ( ".$iIdGroup;
	if (!empty($_SESSION["gsOtherGroups"]))
		$query .= ", ".$_SESSION["gsOtherGroups"];
	$query .= ") ORDER BY WAIdParent, WASortValue";

//	echo $query."<br>";
	
	$rec = new WARecordset(0);
	$rec->SetupFromGlobalCnn();
	$rec->WAOpenRecordset($query);
	while ($rec->WAFetchRow())
	{
		$IdMenu = $rec->WAResult("WAIdMenu");
		$a =  array("WAUrl"			=> $rec->WAResult("WAUrl"),
					"WAIdMenu"		=> $IdMenu,
					"WAIdParent"	=> $rec->WAResult("WAIdParent"),
					"WAIdForm"		=> $rec->WAResult("WAIdForm"),
					"WAAbstract"	=> $rec->WAResult("WAAbstract"),
					"WAMenu"		=> $rec->WAResult("WAMenu"));
		$aMenuConfiguration[$IdMenu] = $a;
	}
	$rec->WACloseRecordset();
}

function PrintMenu($elem, $iParent, $pos, $iMenuItem, $_SERVER)
{
//	echo "iMenuItem = ".$iMenuItem." iParent = ". $iParent. " elem[WAIdMenu]=".$elem["WAIdMenu"]." elem[WAIdParent] = ". $elem["WAIdParent"] . "<br>";
	if ((($iMenuItem > 0) && ($iMenuItem == $elem["WAIdMenu"])) ||
//	if (( ($iMenuItem == $elem["WAIdMenu"])) ||
		(($elem["WAIdParent"] == $iParent) && ($iMenuItem == 0)) )
	{
		if (empty($elem["WAUrl"]))
		{
			$sUrl = "menu.php" ; // $PHP_SELF;
			$sUrl .= "?IdMenu=".$elem["WAIdMenu"];
			$sUrl .= "&Depth=".($pos+1);
		}
		else
		{
			$sUrl = $elem["WAUrl"];
			$aUrlStriped = parse_url($elem["WAUrl"]);
			if (isset($aUrlStriped["query"]))
				$sUrl .= "&";
			else
				$sUrl .= "?";
			$sUrl .= "IdMenu=".$elem["WAIdMenu"];
			$sUrl .= "&Depth=".($pos+1);
		}
		if (!empty($elem["WAIdForm"]))
			$sUrl .= "&IdForm=".htmlentities(stripcslashes($elem["WAIdForm"]), ENT_QUOTES);
		if ($GLOBALS['WA_PRIVATE_SESSIONS'])
			$sUrl = AddSessionInUrl($sUrl);
		if ($_SESSION["giIdMenu"] == $iMenuItem)
		{
			echo "<td class='MenuCellSelectOver'>";
			echo "<a class='MenuCellSelectOver'";
		}
		elseif ($iMenuItem == 0)
		{
			echo "<td onmouseover=\"moverOnChildName(this, 'A', 'MenuCellOver');\" onmouseout=\"moutOnChildName(this, 'A', 'MenuCell');\" class='MenuCell'>";
			echo "<a onmouseover=\"moverOnParentName(this, 'TD', 'MenuCellOver');\" onmouseout=\"moutOnParentName(this, 'TD', 'MenuCell');\" class='MenuCell'";
		}
		else
		{
			echo "<td onmouseover=\"moverOnChildName(this, 'A', 'MenuCellSelectOver');\" onmouseout=\"moutOnChildName(this, 'A', 'MenuCellSelect');\" class='MenuCellSelect'>";
			echo "<a onmouseover=\"moverOnParentName(this, 'TD', 'MenuCellSelectOver');\" onmouseout=\"moutOnParentName(this, 'TD', 'MenuCellSelect');\" class='MenuCellSelect'";
		}
		echo " href='".$sUrl."' title='".htmlentities($elem["WAAbstract"], ENT_QUOTES)."'>";
		echo htmlentities($elem["WAMenu"], ENT_QUOTES);
		if ($iMenuItem == 0)
			echo "&nbsp;</a></td>\n";
//			echo "&nbsp;|&nbsp;</td>";
		else
			echo "&nbsp;&gt;&nbsp;</a></td>\n";
	}
}
?>
<script type="text/javascript" Language="JavaScript1.2" src="javascripts/handleform.js"></script>
<table width="100%" border="0" cellspacing="2" cellpadding="2" class="MenuTable">
<?php
	if (isset($_GET["IdMenu"]))
		$_SESSION["giIdMenu"] = $_GET["IdMenu"];
	elseif (isset($_POST["IdMenu"]))
		$_SESSION["giIdMenu"] = $_POST["IdMenu"];
	else
		$_SESSION["giIdMenu"] = 1;

	if (isset($_GET["Depth"]))
		$Depth = $_GET["Depth"];
	elseif (isset($_POST["Depth"]))
		$Depth = $_POST["Depth"];
	else
		$Depth = 1;

	if (isset($Depth))
	{
		if (($Depth <= count($_SESSION["gaMenuStatus"])) && (($Depth-1) >= 0))
			$_SESSION["gaMenuStatus"][$Depth-1] = $_SESSION["giIdMenu"];
		if ($Depth <= count($_SESSION["gaMenuStatus"]))
			$_SESSION["gaMenuStatus"][$Depth] = 0;
	}
//	echo "<pre>"; print_r($_SESSION["gaMenuStatus"]); echo "</pre>";
//	echo "<pre>"; print_r($_SESSION["gaMenuConfiguration"]); echo "</pre>";
	reset ($_SESSION["gaMenuStatus"]);
	$parent = 0;
	echo   "<tr><td nowrap >";
	if (count($_SESSION["gaMenuConfiguration"]) == 0)
	{
		$_SESSION["gaMenuConfiguration"] = array();
		menu_load(0, $_SESSION["giIdGroup"], $_SESSION["gaMenuConfiguration"] );
	}
	echo "<table border='0' cellspacing='1' cellpadding='1'><tr>\n";
	while (list ($chiave, $valore) = each ($_SESSION["gaMenuStatus"]))
	{
		reset($_SESSION["gaMenuConfiguration"]);
		foreach ($_SESSION["gaMenuConfiguration"] as $value)
		{
			PrintMenu($value, $parent, $chiave, $valore, $_SERVER);
		}
    	if ($valore == 0)
    		break;
    	$parent = $valore;
    }
	echo "<td></td></tr></table>\n";
	echo "</td></tr>";
?>
</table>

Return current item: Phparchive