Location: PHPKode > projects > Esvon Personals > esvon-personals/inc/blocks/block-Categories.php
<?php

// --------------------------------------------------------------------------
//
// Esvon Classifieds v.4.0
// Copyright(C), Esvon LTD, 2001-2010, All Rights Reserved.
// E-mail: hide@address.com
//
// All forms of reproduction, including, but not limited to, internet posting, 
// printing, e-mailing, faxing and recording are strictly prohibited.
// One license required per site running Esvon Classifieds. 
// To obtain a license for using Esvon Classifieds, please register at
// http://www.esvon.com/pg/products/p_classifieds/
//
// --------------------------------------------------------------------------

// Clickable categories navigation menu (left menu usually).
// Listings amount can be shown next to each category

function block_Categories(&$tpl, $args = ''){

  // set to 0 to display all categories
  $cat_limit = isset($args['cat_limit']) ? abs(intval($args['cat_limit'])) : 10;

  $cache_id = 'b_Categories';
  $cache_func = 'b_Categories_Get_Data';
  /*if($_GET['page']=='search' && $_GET['cid']){ 
    $cid = (int)$_GET['cid'];
    global $db;
    $has_child = $db->one_data('SELECT COUNT(*) FROM '.TBL_CAT.' WHERE pid='.$cid);
    if(!$has_child) $cid = $db->one_data('SELECT pid FROM '.TBL_CAT.' WHERE id='.$cid);
    if($cid){
      $cache_id.="_$cid";
      $cache_func.="($cid)";
    }
  }*/

  $cache = &Factory::singleton('Hw_Cache');
  $a_v = $cache->get($cache_id, $cache_func, TRUE);

  $f_all = 0;
  if($cat_limit>0 && count($a_v) > $cat_limit){
    $f_all = 1;
    $a_v = array_slice($a_v, 0, $cat_limit);
  }

  if($a_v) foreach($a_v as $v){
    $tpl->AddCell('b_Categories',$v,'row');
  }
  if($f_all) $tpl->AddCell('b_Categories','','all');

}

function b_Categories_Get_Data($pid = 0){
global $HW_LANG;

  include_once SITE_PATH.'inc/class.categ_tree.php';
  
  $o_cat = new HawkCategory(TBL_CAT,TBL_AD,'catid');
  $o_cat->CAT_F = 'fset'; // for drop-down menu usage
  $o_cat->CAT_ORDER = 'c.weight DESC,name';

  $o_cat->SQL_AMT = hwFilterGetSQL();
  if($pid) $o_cat->SQL_AMT.=' AND catid IN('.get_daughter_cats($pid).')';

  $o_cat->Fill_Cat_Tree($pid);
  $o_cat->Fill_Amount_Array();

  if(!EN_ZERO_CAT) $o_cat->Remove_Zero_Cats($o_cat->A_CAT_TREE);

  $a_v = array();

  $a_cats = $o_cat->GetTopCatIDArray(0);
  if(!$a_cats) return $a_v;

  $v = array();
  foreach($a_cats as $catid){
    $v['id'] = $catid;
    $v['name'] = $o_cat->A_CNAME[$catid];
    $v['l_num'] = $o_cat->AMT[$catid];
    if(!$v['l_num']) $v['l_num'] = 0;
    $v['href'] = hwGetCatURL($catid); // hwGetBrowseURL
    $a_v[] = $v;
  }

  return $a_v;

}
?>
Return current item: Esvon Personals