Location: PHPKode > projects > Esvon Personals > esvon-personals/inc/pages/top.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/
//
// --------------------------------------------------------------------------

if(!defined('SITE_PATH')) die('Access Denied');

define('TOP_NUM',10);

$a_pg = array('new','rate','hit');
$pg = (string)$_GET['pg'];
if(!in_array($pg, $a_pg)) $pg = $a_pg[0];

ShowTopPage($pg);

function ShowTopPage($type) {
  global $db,$sort_title,$sort_by;

switch ($type) {
  case 'new':
    $sort_title = hwLng('date');
    $sort_by = 'hw_added';
    break;
  case 'rate':
    $sort_title = hwLng('rating');
    $sort_by = 'rating';
    break;
  case 'hit':
    $sort_title = hwLng('hits');
    $sort_by = 'hits';
    break;
  default :
  	die("Unknown sorting type");
}

  $sort_title = ucfirst($sort_title);

  $buf = '';

  $tpl = new HawkTpl;
  $tpl->BUF = ltrim(EvalAdvTpl(TPL_PATH.'top.htm','$TOP_NUM,$sort_title'));
  if($p = strpos($tpl->BUF, '<!-- TITLE:')){
    $buf = substr($tpl->BUF, 0, $p);
    $tpl->BUF = substr($tpl->BUF, $p);
  }

  $cache = &Factory::singleton('Hw_Cache');
  $a_v = $cache->get("p_top_$type", 'GetTopArray', TRUE);

  if($a_v) foreach($a_v as $v){
    // no listings ?
    if(empty($v[1])) continue;
    $tpl->InitArray('row');
    foreach($v[1] as $z){
      $tpl->AddCell('row',$z);
    }
    $buf.=$tpl->Parse('', array(
      'catname' => $v[0],
      'caturl' => $v[2],
      ));
  }
  echo $buf;

}

function GetTopArray(){
global $db;
  $a_v = array();
  $sql = hwGetCatSQL('c.id,c.name', ' AND c.pid=0 ORDER BY c.weight DESC,name', TBL_CAT);
  $res = $db->query($sql);
  while($v = mysql_fetch_assoc($res)){ 
    $a_v[] = array( $v['name'], GetCatTopArray($v['id']), hwGetCatURL($v['id']) );
  }
  return $a_v;
}

function GetCatTopArray($id){
global $db,$TITLE_FIELD,$DATE_FMT,$sort_by;

$ql = 'SELECT '.hwSQLFieldsGet().',';

if($sort_by=='hw_added') $ql.="UNIX_TIMESTAMP($sort_by)";
elseif($sort_by=='hits') $ql.=TBL_HITS.'.'.$sort_by;
else $ql.=$sort_by;

$ql.=' AS sort_by FROM '.TBL_AD;

if($sort_by=='hits') $ql.=' LEFT JOIN '.TBL_HITS.' ON '.TBL_AD.'.link_id='.TBL_HITS.'.lid';

$ql.=' WHERE catid IN ('.get_daughter_cats($id).')'.hwFilterGetSQL();
$ql.=' ORDER BY '.($sort_by=='hits' ? TBL_HITS.'.'.$sort_by : $sort_by).' DESC LIMIT '.TOP_NUM;

$res = $db->query($ql);

$a_v = array();
$num = 0;
while($v = mysql_fetch_assoc($res)){
  $v['num'] = ++$num;
  if($sort_by=='hw_added') $v['sort_by'] = strftime($DATE_FMT,$v['sort_by']);
  elseif($sort_by=='hits' && !isset($v['sort_by'])) $v['sort_by'] = 0;
  $a_v[] = hwSQLRowGet($v);
}

return $a_v;

}

?>
Return current item: Esvon Personals