<?php
/**
* 点评对象列表
* @author moufer<moufer@163.com>
* @package modoer
* @copyright: Moufer Studio(www.modoer.com)
* @version $Id: cate.php 5 2007-12-14 10:26 $
*/
require_once './include/inc_common.php';

if($classcode && array_key_exists($classcode, $_classcodes) && !$keyword && !$areacode && $page <= 1) {
   location('cate.php?cd='.$classcode);
} elseif(array_key_exists($classcode, $_classcodes)) {
    $cd = $classcode;
}
$cd = empty($cd) ? $_config['default_panel'] : $cd;
$classcode = $cd;
$panelcode = $pcd = substr($classcode,0,2);
define('SCRIPTNAV', "shop-cate-$pcd");
$urlparam = 'cate.php?cd='.$cd;
$panelcfg = $_panel_config[$pcd];
if(empty($panelcfg)) {
    header("Location:cate.php?cp=".$_config['default_panel']);
}
$reviewsorts = $panelcfg['review'];
// URL参数
$multiurl[] = "cd=".$cd;
$areacode && $multiurl[] = "areacode=".$areacode;
$streetcode && $multiurl[] = "streetcode=".$streetcode;
$orderurl = 'cate.php?'.implode('&',$multiurl);
$order && $multiurl[] = "order=".$order;

// 老模板参数兼容
if($_config['compatible']) {
    $review_item = &$panelcfg;
}

// 搜索条件
$params = array();
$params['classcode'] = $classcode;
if(preg_match("/[0-9]{6}/",$streetcode)) {
    $params['streetcode'] = $streetcode;
} elseif(preg_match("/[0-9]{4}/",$areacode)) {
    $params['areacode'] = $areacode;
}
$keyword && $params['keyword'] = $keyword;
$keyword = html_special_chars_ex($keyword);
// 排序
// 排序参数
$order_arr  = array(    
    'finer' => 's.finer DESC',
    'sumreview' => 'sumreview DESC',
    'sort1' => 'sumsort1 DESC',
    'sort2' => 'sumsort2 DESC',
    'sort3' => 'sumsort3 DESC',
    'sort4' => 'sumsort4 DESC',
    'sort5' => 'sumsort5 DESC',
    'sort6' => 'sumsort6 DESC',
    'sort7' => 'sumsort7 DESC',
    'sort8' => 'sumsort8 DESC',
    'reviews' => 'reviews DESC',
    'enjoy' => 'sumenjoy DESC',
    'price' => 'avgprice DESC',
    'price_s' => 'avgprice',
    'picture' => 'pictures DESC',
    'picture_s' => 'pictures',
    'addtime' => 's.addtime DESC',
    'pageviews' => 'pageviews DESC',
    'effect1' => 'effect1 DESC',
    'effect2' => 'effect2 DESC',
);
$order = empty($order) ? (empty($panelcfg['listorder']) ? 'finer' : $panelcfg['listorder']) : $order;
if(!array_key_exists($order, $order_arr)) {
    $order = 'finer';
}
$params['orderby'] = $order_arr[$order];
// 返回数量
$params['limit'] = get_limit($page, $_config['dpshopnumber']);
// 显示参数配置
$params['showbase'] = $params['showtotal'] = $params['showpoint'] = $params['showinfo'] = 
$params['showcard'] = $params['showmember'] = 1;
// 参数加载，返回搜索结果 array(total,result)
$total = 0;
$shops = array();
list($total,$shops) = searchItem($params);
if($total > 0) {
    $multiurl = 'cate.php?'.implode('&',$multiurl);
    $multipage = multi($total, $_config['dpshopnumber'], $page, $multiurl);
}
// 排序数组
$orderlist = array (
    'finer' => '推荐度',
    'effect1' => '去过最多',
    'effect2' => '最想去',
    'reviews' => '点评数量',
    'enjoy' => '喜欢程度',
    'addtime' => '登记时间',
    'pageviews' => '浏览量',
    'price' => '人均消费',
    'picture' => '图片数量',
    'sumreview' => '综合点评',
);
/*
foreach($panelcfg['review'] as $key => $val) {
    $orderlist[$key] = $val;
}
unset($key,$val);
*/

$subtitle = ($_areacodes[$areacode] ? $_areacodes[$areacode] : '全部地区').'&nbsp;-&nbsp;';
$subtitle .= $_areacodes[$streetcode] ? $_areacodes[$streetcode].'&nbsp;-&nbsp;' : '';
$subtitle .= $_classcodes[$cd] ? $_classcodes[$cd]['classname'] : '全部分类';
$meta_keywords = $panelcfg['meta_keywords'];
$meta_description = $panelcfg['meta_description'];
unset($cate_class);
$tplname = $panelcfg['tplname_list'] ? $panelcfg['tplname_list'] : 'shop_cate';

require_once MUDDER_ROOT.'header.php';
require_once template($tplname);
footer();
?>