<?php
  $i=0;
  $categories_query = tep_db_query("select c.categories_id, cd.categories_name, c.parent_id from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.categories_id = cd.categories_id and cd.language_id='" . (int)$languages_id ."' order by sort_order, cd.categories_name");
  while ($categories = tep_db_fetch_array($categories_query))  {
    $tree1[$i][] = array('categories_name' => $categories['categories_name'],
                     'parent_id' => $categories['parent_id'],
                     'categories_id' => $categories['categories_id']);
    $tree2[$i][] = array('categories_name' => $categories['categories_name'],
                     'parent_id' => $categories['parent_id'],
                     'categories_id' => $categories['categories_id']);
    $tree3[$i][] = array('categories_name' => $categories['categories_name'],
                     'parent_id' => $categories['parent_id'],
                     'categories_id' => $categories['categories_id']);
	$i++;
	}

	
if(is_array($tree1)){foreach($tree1 as $key=>$value){
if($value[0]['parent_id']==0){ 	
?>  

<table width="550" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td>&#8226;<a href="./index.php?cPath=<? echo $value[0]['categories_id'];?>" class="cat_b"> <? echo $value[0]['categories_name'];?></a></td>
  </tr>
</table>
<table width="550" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
<?
	$allc_id="";
	getAllClassesIdByParentId($value[0]['categories_id']);
	if ($allc_id=="") 
		$allc_id=$value[0]['categories_id'];
	else
		$allc_id.=",".$value[0]['categories_id'];

//echo "sql=="."SELECT ptc.products_id, p.products_image, p.products_price, pd.products_name, p.products_tax_class_id FROM ".TABLE_PRODUCTS_TO_CATEGORIES." ptc LEFT JOIN " .TABLE_PRODUCTS." p ON ptc.products_id = p.products_id LEFT JOIN " .TABLE_PRODUCTS_DESCRIPTION. " pd ON p.products_id = pd.products_id WHERE p.products_status = 1 AND pd.language_id = '" . (int)$languages_id ."'  AND ptc.categories_id in (".$allc_id.") order by p.code";
	$c_products_query = tep_db_query("SELECT ptc.products_id, p.products_image, p.products_price, pd.products_name, p.products_tax_class_id FROM ".TABLE_PRODUCTS_TO_CATEGORIES." ptc LEFT JOIN " .TABLE_PRODUCTS." p ON ptc.products_id = p.products_id LEFT JOIN " .TABLE_PRODUCTS_DESCRIPTION. " pd ON p.products_id = pd.products_id WHERE p.products_status = 1 AND pd.language_id = '" . (int)$languages_id ."'  AND ptc.categories_id in (".$allc_id.") order by p.code");
	$j=0;
	while ($products = tep_db_fetch_array($c_products_query)) {
?>  
    <? $j++;
	if (($j % 2)==0) { ?>
	<td width="290"><a href="./product_info.php?cPath=<? echo $value[0]['categories_id'];?>&products_id=<? echo $products['products_id'];?>" class="bot"><? echo $products['products_name'];?></a> </td>
	<? }else{?>	
  </tr>
  <tr>
	<td width="290"><a href="./product_info.php?cPath=<? echo $value[0]['categories_id'];?>&products_id=<? echo $products['products_id'];?>" class="bot"><? echo $products['products_name'];?></a> </td>
	<? }?>
<?
}
?>
  </tr>
</table>
<?
}
}
}
?>