<?
session_start();
require_once('../connect/connect.php'); 
include_once('../lib/lib.php');
require('pdk.php');

$base=dir_top();
$num_catalog=intval($_GET['num_catalog']);
if(!$num_catalog)
	{
	$buf="<?";
	$file1 = fopen ("../cashe_n/_menu2.php", "w");
	flock($file1, LOCK_EX);
	fputs($file1, $buf);
	fclose($file1);
	$buf='';
	}

$r=mysql_query("SELECT * FROM field WHERE id_catalog > ".$num_catalog." AND field_param_search = 1 ORDER BY id_catalog LIMIT 1");
$nc=mysql_num_rows($r);
if($nc)
	{
	$rr=mysql_fetch_array($r);
	$field=$rr['field_field'];
	$spisok=$rr['field_spisok'];
	$id_catalog=$rr['id_catalog'];
	echo $id_catalog;

	$r=mysql_query("SELECT COUNT(id) as cou, ".$field." FROM board WHERE id_catalog=".$id_catalog." GROUP BY ".$field);
	$nr=mysql_num_rows($r);
	if($nr)
		{
		$r1=mysql_query("SELECT * FROM catalog WHERE id_catalog=".$id_catalog);
		$rr1=mysql_fetch_array($r1);
		$parent=$rr1['parent_id'];
		$catalog=$rr1['catalog'];
		$url=$rr1['url'];
		include_once('../cashe_n/_svod_element_'.$spisok.'.php');
		$bu='';
		while($rr=mysql_fetch_array($r))
			{
			$bu .= '<a class=ww href="'.$base.'catalog/'.$url.'_'.$id_catalog.'/all_0/param_'.$field.'[1]='.$rr[1].'">'.$arr_element[$spisok][$rr[1]].'</a> ';
			}
		$buf = "\r\n".'$arr_menu['.$id_catalog.']=\''.$bu.'\';';
		$file1 = fopen ("../cashe_n/_menu2.php", "a");
		flock($file1, LOCK_EX);
		fputs($file1, $buf);
		fclose($file1);
		sleep(1);
		}
	echo "<HTML><HEAD><meta http-equiv='Refresh' charset='utf-8' content='0; URL=?num_catalog=".$id_catalog."'></HEAD></HTML>";
	}
else 
	{
	$buf="\r\n?>";
	$file1 = fopen ("../cashe_n/_menu2.php", "a");
	flock($file1, LOCK_EX);
	fputs($file1, $buf);
	fclose($file1);
	echo "<HTML><HEAD><meta http-equiv='Refresh' charset='utf-8' content='0; URL=_menu_cashe3.php'></HEAD></HTML>";
	}



?>
