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

function block_Latest_Ads_Browse(&$tpl, $args = ''){
global $db;

  $hw_num = isset($args['amount']) ? abs(intval($args['amount'])) : 10;
  $en_paging = ($args['paging'] && strtolower($args['paging'])!='off') ? TRUE : FALSE;
  $en_all_fld = ($args['all_fields'] && strtolower($args['all_fields'])!='false') ? TRUE : FALSE;
  $use_date_updated = ($args['use_date_updated'] && strtolower($args['use_date_updated'])=='true') ? TRUE : FALSE;

  $cid = 0;
  $reg_id = 0;
  if(defined('HW_MOD') && HW_MOD=='Regions') $reg_id = (int)$_REQUEST['cat'];
  else $reg_id = (int)$_GET['rid'];

  if($_GET['cid']) $cid = (int)$_GET['cid'];
  elseif($_GET['cat'] && !$reg_id) $cid = (int)$_GET['cat'];

  $sql = ' WHERE 1'.hwFilterGetSQL();
  if($cid) $sql.=' AND catid IN ('.get_daughter_cats($cid).')';
  
  if($reg_id && hwModGetState('Regions') == 'A'){ 
    $sql.=' AND hw_region_id IN ('.get_daughter_cats($reg_id, hwModTable('Regions','category')).')';
  }

  $var_off = 'off';
  if($en_paging){ 
    $numrows = $db->one_data('SELECT COUNT(*) FROM '.TBL_AD.
      (($cid && $db->version()>=40009) ? ' FORCE INDEX (catid) ' : '').
      $sql);
    
    $off = (ctype_digit($_GET[$var_off]) && $_SERVER['REQUEST_METHOD']=='GET') ? $_GET[$var_off] : 0;
  }
  else {
    $numrows = 1; // no need to know
    $off = 0;
  }

  if($numrows > 0){

    $sql = 'SELECT '.hwSQLFieldsGet($en_all_fld).',UNIX_TIMESTAMP('.($use_date_updated ? 'hw_updated' : 'hw_added').') AS ad_date,userid FROM '.TBL_AD.
           ($use_date_updated ? '' : ' USE INDEX (PRIMARY)').
           $sql.
           ' ORDER BY '.($use_date_updated ? 'hw_updated' : 'link_id').' DESC LIMIT '.($off*$hw_num).','.$hw_num;
    
    if(0){ // $off==0
      $cache = &Factory::singleton('Hw_Cache');
      $cache_id = 'b_Latest_Ads_Browse';
      $a_v = array('cid', 'reg_id', 'en_all_fld', 'use_date_updated', 'hw_num');
      foreach($a_v as $v){
        if($$v) $cache_id.='_'.$v[0].(int)$$v;
      }
      $cache_exp = $cache->getLifeTimeSec();
      $cache->setLifeTimeSec(600); // 10 minutes
      $a_v = $cache->get($cache_id, "\$GLOBALS['db']->select('$sql')", TRUE);
      $cache->setLifeTimeSec($cache_exp);
    }
    else{
      $a_v = $db->select($sql);
    }

    if($a_v) {
      
      if(EN_UF){ 
        $A_UID = array();
        foreach($a_v as $v) $A_UID[$v['userid']] = 1;
        reset($a_v);
        $A_UNAME = $db->two_col_assoc('SELECT id,username FROM '.TBL_USER.' WHERE id IN("'.implode('","',array_keys($A_UID)).'")');
      }
      global $DATE_FMT;
      $num = 1;
      $CP_BUF = array();
      foreach($a_v as $v) {
        $v['THUMB_WIDTH'] = (int)THUMB_WIDTH;
        $v['username'] = $A_UNAME[$v['userid']];
        $v['num'] = $num++;
        $v['ad_date'] = strftime($DATE_FMT,$v['ad_date']);
        if($en_all_fld){
          if(!$CP_BUF[$v['catid']]) $CP_BUF[$v['catid']] = GetCatPathCached($v['catid'],1);
          $v['cat_path'] = $CP_BUF[$v['catid']];
        }
        $tpl->AddCell('b_Latest_Ads_Browse', hwSQLRowGet($v));
      }
      
    }

    if($en_paging && $numrows>$hw_num){
      $v = array();
      $q_vars = preg_replace('/&'.$var_off.'=\d*/', '', strip_tags($_SERVER['QUERY_STRING']));
      if($q_vars){ 
        $q_vars = preg_replace('/&lang=\w*/','&lang='.$GLOBALS['HW_LANG'],$q_vars);
        $q_vars = '&'.$q_vars;
      }
      if(empty($_REQUEST['page']) && $GLOBALS['page']==IDX_PAGE && PHP_SELF_BASE=='index.php') $q_vars.='&page='.IDX_PAGE;
      $v['nav'] = GetNavigation($_SERVER['PHP_SELF'],$hw_num,10,$numrows,$off,$q_vars);
      $tpl->AddCell('b_Latest_Ads_Browse', $v, 'nav');
    }

  }

}

?>
Return current item: Esvon Personals