<?php

	/*
	*	Gekko - Open Source Web Development Framework
	*	------------------------------------------------------------------------
	*	Copyright (C) 2004-2005, J. Carlos Nieto <xiam@users.sourceforge.net>
	*	This program is Free Software.
	*
	*	@package	Gekko
	*	@license	http://www.gnu.org/copyleft/gpl.html GNU/GPL License 2.0
	*	@author		J. Carlos Nieto <xiam@users.sf.net>
	*	@version	CVS: $Id:$
	*	@link		http://gekkoware.sourceforge.net
	*/

	if (!defined("IN-BLOCK")) die();

	/*
	<%%>
	<?xml version="1.0" encoding="UTF-8"?>
	<blockscript>
		<info lang="en">
			<title>Menu loader</title>
			<description>Display the menu specified by it's ID</description>
			<author><![CDATA[xiam &lt;<a href="mailto:xiam@users.sourceforge.net">xiam@users.sourceforge.net</a>&gt;]]></author>
			<homepage><![CDATA[<a href="http://www.gekkoware.org">http://www.gekkoware.org</a>]]></homepage>
		</info>
		<info lang="es">
			<title>Muestra menu</title>
			<description><![CDATA[Carga menu]]></description>
		</info>
		<variable name="id">1</variable>
	</blockscript>
	<%%>
	*/

	$q = $GLOBALS["db"]->query("SELECT Title, Type, opt_noIcons
	FROM ".db_table("menu_block")." WHERE ID = '{$id}'",
	__FILE__, __LINE__, true);
	$parent = $GLOBALS["db"]->fetch_row($q);



	$block["Title"] = $parent["Title"];

	$q = $GLOBALS["db"]->query ("
		SELECT
			Type, Title, Link, Tooltip, Icon, auth_Access, Level
		FROM ".db_table("menu_link")."
		WHERE MenuLink = '{$id}' ORDER BY OrderID ASC
	", __FILE__, __LINE__, true);

	$return = Array();
	if ($GLOBALS["db"]->num_rows($q)) {
		while ($row = $GLOBALS["db"]->fetch_row($q)) {
			if (gauth($row["auth_Access"])) {

				$row["Icon"] = ($parent["opt_noIcons"] ? "" : mkIcon($row["Icon"], 16));

				switch ($parent["Type"]) {
					case 1:
						$return[] = "<a href=\"".$row["Link"]."\" title=\"{$row["Tooltip"]}\"><div class=\"link\" style=\"display: inline\">".$row["Icon"]." {$row["Title"]}</div></a>";
					break;
					default:
						$return[] = "<div class=\"link\" style=\"margin-left: ".($row["Level"]*8)."px;\">".$row["Icon"]." <a href=\"".$row["Link"]."\" title=\"{$row["Tooltip"]}\">{$row["Title"]}</a></div>\n";
					break;
				}
			}
		}
	}

	switch ($parent["Type"]) {
		case 1:
			// loading another skeleton (./$tpldir/blocks/*.block)
			$block["blockSkeleton"] = "contentonly.block";
			$return = implode("\n", $return);
		break;
		default:
			$return = implode("\n", $return);
		break;
	}
?>