<?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_Featured_Matrix(&$tpl, $args = ''){
// featured ads amount (to be displayed)
$show_amt = isset($args['amount']) ? abs(intval($args['amount'])) : 12;
if($_GET['off'] || $show_amt<=0) return;
// columns amount
$show_cols = isset($args['cols']) ? abs(intval($args['cols'])) : 4;
$en_all_fld = ($args['all_fields'] && strtolower($args['all_fields'])!='false') ? TRUE : FALSE;
$cid = 0;
$reg_id = 0;
if(defined('HW_MOD') && HW_MOD=='Regions') $reg_id = (int)$_REQUEST['cat'];
else $reg_id = (int)$_GET['hw_region_id'];
if($_REQUEST['cid']) $cid = (int)$_REQUEST['cid'];
elseif($_REQUEST['cat'] && !$reg_id) $cid = (int)$_REQUEST['cat'];
// reinit fieldset if necessary
/*
if($cid){
$_GET['cid'] = $cid;
$fset_dir_tmp = GetCurFieldsSet();
global $FSET_DIR,$O_LFS;
if($fset_dir_tmp!=$FSET_DIR){
$FSET_DIR = $fset_dir_tmp;
$O_LFS->Init($FSET_DIR);
}
}
*/
/*
best known speed-up so far:
2 selects:
1/Get all IDs with hw_feat="1" AND catid into array
2/Get rnd by IDs AND FilterGet
*/
$cur_i = 0;
$ql = 'SELECT '.hwSQLFieldsGet($en_all_fld).' FROM '.TBL_AD.' WHERE hw_feat="1"'.hwFilterGetSQL();
if($cid) $ql.=' AND catid IN ('.get_daughter_cats($cid).')';
if($reg_id) $ql.=' AND hw_region_id IN ('.get_daughter_cats($reg_id, hwModTable('Regions','category')).')';
$ql.=' ORDER BY RAND() LIMIT 0,'.$show_amt;
$cell_id = 'b_Featured_Matrix';
$tpl->AddCell($cell_id, array('feat_cols'=>$show_cols), 'start');
$feat_w = intval(100/$show_cols);
global $db;
$a_v = $db->select($ql);
//if($a_v) $O_UFS = &Factory::singleton('FieldsSet', '{user_fields}');
//$A_USER = array();
foreach($a_v as $v){
$v['feat_w'] = $feat_w;
//$uid = $v['userid'];
$v = hwSQLRowGet($v);
/*if($uid){
if(!$A_USER[$uid]){
$A_USER[$uid] = $db->one_assoc('SELECT * FROM '.TBL_USER.' WHERE id='.$uid);
$A_USER[$uid] = $O_UFS->FillCustomFieldsArray($A_USER[$uid], true);
$O_UFS->AdjustCustomFields($A_USER[$uid]);
}
$v+= $A_USER[$uid];
}*/
$tpl->AddCell($cell_id, $v, 'item');
$cur_i++;
if($cur_i>=$show_cols){
$cur_i=0;
$tpl->AddCell($cell_id,'','new_row');
}
}
$v = compact('feat_w');
while($cur_i<$show_cols){
$tpl->AddCell($cell_id,$v,'no_item');
$cur_i++;
}
$tpl->AddCell($cell_id, '', 'end');
}
?>