<?
if(!$_SESSION['ID_Glob']) exit();
$out='';
ob_start();

function get_tree_map($parent_id) {
      global $out;
      global $i;
	  
	  $query = "SELECT id_catalog, catalog, url, path FROM catalog WHERE id_catalog > 0 AND parent_id = '".$parent_id."' ORDER BY num";
      $result = mysql_query($query);	
	  $nr = mysql_num_rows($result);  
	  
      while ($rr = mysql_fetch_array($result)) 
	  	{
		$path=explode(" ", trim($rr['path']));
		if(!$parent_id)
			{
			if($i)
			$out[] = "";
			$out[] = '<a class=ww href="'.dir_top().'catalog/'.$rr['url'].'_'.$rr['id_catalog'].'/all_0/">'.$rr['catalog'].'</a>'; 
			$i++;
			}
		elseif(count($path)<3)
		$out[] = '<a href="'.dir_top().'catalog/'.$rr['url'].'_'.$rr['id_catalog'].'/all_0/">'.$rr['catalog'].'</a>'; 

		get_tree_map($rr['id_catalog']);
      	}
      return $out;
} // end function

$i=0;
$out=array();
$aa = get_tree_map(0);

echo "<table cellpadding=3 cellspacing=3 width=100%><tr>";
if($aa)
	{
	$bb=count($aa);
	$b=ceil($bb/4);
	$i=0;
	foreach($aa as $a)
		{
		if(!$i) echo '<td valign=top>';
		if((!$i && $a) || $i)
			{
			echo $a.'<br>';
			$i++;
			}
		if($i==$b) $i=0;
		}
	}
echo "</table>";

$buf = ob_get_contents();
ob_end_clean();

file_put_contents("../cashe_n/_map.php", $buf);

if(file_exists('../cashe_n/_menu2.php'))
include_once('../cashe_n/_menu2.php');

$out='';
ob_start();
echo "<table>\n";

function get_tree_map2($parent_id, $prefix) {
      global $out;
      global $arr_menu;
	  $query = "SELECT * FROM catalog WHERE id_catalog > 0 AND parent_id = '".$parent_id."' ORDER BY num";
      $result = mysql_query($query);	
	  $nr = mysql_num_rows($result);  
	  
      while ($rr = mysql_fetch_array($result)) 
	  	{
		$out .= '<tr align=center>';
		$out .= '<td  align=left width="35%">';
		$out .= $prefix.'<img src="icon/folder.gif" border=0> <a href="catalog/'.$rr['url'].'_'.$rr['id_catalog'].'/all_0/">'.$rr['catalog'].'</a> '; 
		if($arr_menu[$rr['id_catalog']])
		$out .= '<br>'.$arr_menu[$rr['id_catalog']];
		get_tree_map2($rr['id_catalog'], $prefix."&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
      	}
      return $out;
} // end function

echo get_tree_map2(0, "");
echo "</table>";

$buf = ob_get_contents();
ob_end_clean();

file_put_contents("../cashe_n/_menu.php", $buf);

?>
