<?php

	require_once '../auth.php';
	require_once 'menustring.php';

	$phplm_www = '';
	$phplm_dir = '';

	require_once ($phplm_dir . "lib/layersmenu-common.inc.php");
	require_once ($phplm_dir . "lib/layersmenu-process.inc.php");
	$mid = new ProcessLayersMenu();
	$mid->setMenuStructureString($menuString);
	$mid->parseStructureForMenu('treemenu1');
	$tmpTable = "t".date('YmdHis');
	$mid->setTableName($tmpTable);
	$sqlDump = $mid->getSQLDump('treemenu1');

	$sqlCreate = "CREATE TEMPORARY TABLE ".$tmpTable." ( ".
	" ".implode(" varchar(255), ", $mid->tableFields)." varchar(255) ".
	" )";

	//$adodb->debug = 1;
	$adodb->Execute($sqlCreate);
	$pie = explode(";", $sqlDump);
	foreach ($pie as $k => $v) $adodb->Execute($v);

	if (isset($_GET['id'])) {
		$rs = $adodb->Execute("SELECT * FROM ".$tmpTable.
		" WHERE parent_id = ? ", array($_GET['id']));
		header("Content-Type: text/xml");
		header("Cache-Control: no-cache");
		echo "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n";

		echo "<tree>\n";
		while (!$rs->EOF) {
			$rs2 = $adodb->Execute("SELECT COUNT(*) as cnt FROM ".$tmpTable.
			" WHERE parent_id = ? ", array($rs->fields['id']));
			echo "<tree ".
			" text=\"".htmlspecialchars($rs->fields['text'])."\" ";

			if ($rs2->fields['cnt']>0) {
				echo " src=\"".htmlspecialchars($_SERVER['PHP_SELF']."?id=".$rs->fields['id'])."\" ";
			}

			echo " action=\"".htmlspecialchars($rs->fields['href'])."\" ".
			" target=\"".htmlspecialchars($rs->fields['target'])."\" ".
			" />\n";
			$rs->MoveNext();
		}
		echo "</tree>\n";
		exit;
	}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html>
<head>
<title>XLoadTree Demo (WebFX)</title>
<script type="text/javascript" src="xloadtree/xtree.js"></script>
<script type="text/javascript" src="xloadtree/xmlextras.js"></script>
<script type="text/javascript" src="xloadtree/xloadtree.js"></script>
<link type="text/css" rel="stylesheet" href="xloadtree/xtree.css" />

<style type="text/css">

body {
	background:	white;
	color:		black;
}

</style>
</head>
<body>

<script type="text/javascript">

/// XP Look
webFXTreeConfig.rootIcon		= "xloadtree/images/xp/folder.png";
webFXTreeConfig.openRootIcon		= "xloadtree/images/xp/openfolder.png";
webFXTreeConfig.folderIcon		= "xloadtree/images/xp/folder.png";
webFXTreeConfig.openFolderIcon		= "xloadtree/images/xp/openfolder.png";
webFXTreeConfig.fileIcon		= "xloadtree/images/xp/file.png";
webFXTreeConfig.lMinusIcon		= "xloadtree/images/xp/Lminus.png";
webFXTreeConfig.lPlusIcon		= "xloadtree/images/xp/Lplus.png";
webFXTreeConfig.tMinusIcon		= "xloadtree/images/xp/Tminus.png";
webFXTreeConfig.tPlusIcon		= "xloadtree/images/xp/Tplus.png";
webFXTreeConfig.iIcon			= "xloadtree/images/xp/I.png";
webFXTreeConfig.lIcon			= "xloadtree/images/xp/L.png";
webFXTreeConfig.tIcon			= "xloadtree/images/xp/T.png";
webFXTreeConfig.errorLoadingText 	= "Error Loading";

//var tree = new WebFXLoadTree("Root", "<?=$_SERVER['PHP_SELF']?>?id=1");
var tree = new WebFXLoadTree("<?=__('Tree Menu', 'Root', 'MAIN MENU');?>", "<?=$_SERVER['PHP_SELF']?>?id=1");
//tree.setBehavior("classic");

document.write(tree);

</script>

</body>
</html>