<?
function is_active($url) {
	global $REDIRECT_URL, $PATH;
	$url=addcslashes(str_replace("{PATH}", $PATH, $url), "/");
	preg_match("/^($url).*/", $REDIRECT_URL, $array);
	return (isset($array[1]) ? $array[1] : "");
}

function get_menu($name) {
	global $PATH, $page;
	$menu = getConfig("common/".$name.".ru");
	$name=strtoupper($name);
	while (list($i,$item)=@each($menu)) {
		$active=is_active($item["self"][1]);
		$line=($item["self"][0]=="-");
		$page->addrow($name,array(
			"id"		=> $i,
			"title"		=> $item["self"][0],
			"href"		=> ((!$line and !$active) ? $item["self"][1] : ""),
			"active"	=> (!$line ? $active : ""),
			"line"		=> $line,
			"PATH"		=> $PATH,
		));
		if ($active) {
			for ($j=0; $j<count($item)-1; $j++) {
				$active=is_active($item[$j][1]);
				$line=($item[$j][0]=="-");
				$page->addrow("SUB_MENU",array(
					"id"		=> $i,
					"title"		=> $item[$j][0],
					"href"		=> ((!$line and !$active) ? $item[$j][1] : ""),
					"active"	=> (!$line ? $active : ""),
					"line"		=> $line,
					"PATH"		=> $PATH,
				));
			}
		}
	}
}
get_menu("menu");
?>