Location: PHPKode > projects > Esvon Personals > esvon-personals/inc/blocks/block-Categories_Sel.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/
//
// --------------------------------------------------------------------------

// Categories drop-down menu for quick (keywords) search

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

  $depth_level = isset($args['depth_level']) ? (int)$args['depth_level'] : 1;

  if($_REQUEST['cid']) $cid = (int)$_REQUEST['cid'];
  elseif($_REQUEST['cat']) $cid = (int)$_REQUEST['cat'];
  elseif($_GET['page']=='out') $cid = (int)$GLOBALS['a_Ad']['catid'];
  else $cid = 0;

  global $db;
  $pid = $cid;
  // locate top cat_id
  while($pid){
    $pid = $db->one_data('SELECT pid FROM '.TBL_CAT.' WHERE id='.$cid);
    if($pid) $cid = $pid;
  }

  $cache = &Factory::singleton('Hw_Cache');
  
  $block_id = 'b_Categories_Sel';
  
  $data_func = $block_id.'_Get_Data';
  if($depth_level > 1) $data_func.='('.$depth_level.')';
  
  $a_v = $cache->get($block_id.$depth_level, $data_func, TRUE);

  if($a_v) foreach($a_v as $v){
    $v['sel'] = $v['id'] == $cid ? 'SELECTED' : '';
    $tpl->AddCell($block_id,$v);
  }

}

function b_Categories_Sel_Get_Data($max_depth = 1){

  if($max_depth>1){
    $a_v = array();
    if(preg_match_all('/<OPTION\s+.*?VALUE=(\d+)[^>]*>((?:[^>\n]+>){0,'.($max_depth-1).'}[^>\n]+)\n/i', ShowDropDownCategoryList(0), $m)){
      $max_i = count($m[0]);
      for($i=0;$i<$max_i;$i++){
        $a_v[] = array(
          'id' => $m[1][$i],
          'name' => $m[2][$i],
        );
      }
    }
    return $a_v;
  }

global $db,$HW_LANG;
  if($HW_LANG == 'en') $sql = 'SELECT id,name FROM '.TBL_CAT.' WHERE pid=0 ORDER BY weight DESC,name';
  else{ 
    $temp_tbl = '_block_cat_sel_'.$HW_LANG;
    $db->query('CREATE TEMPORARY TABLE IF NOT EXISTS '.$temp_tbl.
    ' SELECT id,name FROM '.hwModTable('Multi_Lang','category').' WHERE lang_id="'.$HW_LANG.'"');
    $sql = 'SELECT c.id,IF(m.name<>"",m.name,c.name) AS name FROM '.TBL_CAT.
  ' c LEFT JOIN '.$temp_tbl.' m ON c.id=m.id'.
  ' WHERE c.pid=0 ORDER BY c.weight DESC,name';
  }
  return $db->select($sql);
}

?>
Return current item: Esvon Personals