Location: PHPKode > projects > Esvon Personals > esvon-personals/modules/Reviews/addons/blocks/block-Latest_Reviews_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_Reviews_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;

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

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

  $sql = '';
  
  if($cid) $sql.=' AND l.catid IN ('.get_daughter_cats($cid).')';
  
  if($reg_id && hwModGetState('Regions') == 'A'){ 
    $sql.=' AND l.hw_region_id IN ('.get_daughter_cats($reg_id, hwModTable('Regions','category')).')';
  }
  
  if($sql) $sql = ','.TBL_AD.' l WHERE r.link_id=l.link_id '.$sql.' AND ';
  else $sql = ' WHERE ';
  
  $sql.= ' r.approved="1"';

  $var_off = 'rev_off';
  $tbl = hwModTable('Reviews','data').' r';
  
  if($en_paging){ 
    $numrows = $db->one_data('SELECT COUNT(*) FROM '.$tbl.
      //(($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 r.id AS rev_id, r.review AS rev_txt, r.caption AS rev_title, r.username AS rev_username,'.
           'UNIX_TIMESTAMP(r.date) AS rev_date,r.images FROM '.$tbl.//' USE INDEX (PRIMARY)'.
           $sql.
           ' ORDER by r.id DESC LIMIT '.($off*$hw_num).','.$hw_num;
    
    $res = $db->query($sql);

    if(mysql_num_rows($res) > 0) {
      
      global $DATE_FMT;
      $num = 1;
      while($v = mysql_fetch_assoc($res)) {
        $v['THUMB_WIDTH'] = (int)THUMB_WIDTH;
        if($v['images']) list($v['images']) = explode("\n",$v['images']); 
        $v['num'] = $num++;
        $v['rev_date'] = strftime($DATE_FMT,$v['rev_date']);
        $tpl->AddCell('b_Latest_Reviews_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,$var_off.'='.$off,$q_vars);
      $tpl->AddCell('b_Latest_Reviews_Browse', $v, 'nav');
    }

  }

}

?>
Return current item: Esvon Personals