<?php

class menu
{
var $tpl = 'design.menu.tpl';
var $icons = true;
var $file;
var $menu_arr = array();
var $menu = array();
private $values = array();


function menu($menu_name)
{
$this->file=H.'/sys/ini/menu.'.$menu_name.'.ini';
if ($menu_arr=@parse_ini_file($this->file, true))
{
$this->menu_arr=$menu_arr;
}
else $this->menu_arr=array('Ошибка загрузки меню '.$menu_name=>array('icon'=>'err.png'));


}

private function processing()
{
global $user,$dcms;
foreach ($this->menu_arr as $key=>$value) {
if ($user->group >= @$value['group'] && (empty($value['for_vip']) || $user->is_vip) && (empty($value['license']) || $dcms -> license -> status))
{
$this->menu[]=array(
'razdel'=>@$value['razdel'],
'name'=>$key,
'url'=>@$this->value($value['url']),
'icon'=>($this->icons && !empty($value['icon']))?'/sys/images/icons/'.$value['icon']:false
);
}

}
//print_r($this->menu_arr);
}


private function value($str)
{
if (!$this->values)return $str;
return preg_replace('#\{\$(.+?)\}#e', '$this->values[\\1]', $str);
}



function display()
{
global $user,$dcms;
$this->processing();
$tpl = new design();
$tpl->assign('menu',$this->menu);
$tpl->display($this->tpl);
}

function value_add($name,$value)
{
$this->values[$name]=$value;

}

}

?>