<?php
/*
* @package LabCMS
* @copyright (c) 2006 Alexander Levin aka Loki (loki_angel@mail.ru)
* @support http://labcms.ru
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*/
	
	$mod_template="menu.tpl";
	if (LabCMS::i()->is_cached($mod_template, -1, LabCMS::i()->id)) return;
	
	$first_point_id=LabConfig::$mcfg['start_id']; //id корня всего дерева
	$deep_level=LabConfig::$mcfg['deep_level']; //глубина построения
	
	function menu_tree($first_point_id, $level=0)
	{
		global $deep_level;
		if (!$deep_level || $deep_level>$level)
		{
			$result=Db::i()->select("SELECT t.tree_id, parent_id, tree_name, path FROM ?_tree t WHERE menu=1 AND parent_id=? ORDER BY pos", $first_point_id);
			if (count($result))
			{
				foreach($result as $key=>$tmp)
				{
					$tree[$key]=array(
					'tree_id'=>$tmp['tree_id'],
					'name'=>$tmp['tree_name'],
					'path'=>$tmp['path'],
					'subtree'=>menu_tree($tmp['tree_id'], $level+1));
					if (in_array($tmp['tree_id'],LabCMS::i()->parents)) $tree[$key]['active']=1;
					if ($tmp['tree_id']==LabCMS::i()->id) $tree[$key]['current']=1;
					if (!is_array($tree[$key]['subtree'])) unset($tree[$key]['subtree']);
				}
				return $tree;
			}
			else
			{
				return false;
			}
		}
		else
		{
			return false;
		}
	}
	$tree=menu_tree($first_point_id);
	Tpl::i()->assign('tree', $tree);
