<?php
/**
* 排名
* @author moufer<moufer@163.com>
* @package modoer
* @copyright Moufer Studio(www.modoer.com)
* @version $Id: top.php 4 2007-12-20 10:41 $
*/

define('SCRIPTNAV', 'top');
require_once './include/inc_common.php';

if(!$pcd) {
    $pcd = $_config['default_panel'];
}
$panelcfg = &$_panel_config[$pcd];
$review_item =& $panelcfg['review'];
$sort = !$sort ? 'all' : $sort;

$where = "classcode BETWEEN '{$pcd}00' AND '{$pcd}99' ";
$orderby = "sid DESC";
switch($sort) {
case 'sort1':
    $orderby="sumsort1 DESC";
    break;
case 'sort2':
    $orderby="sumsort2 DESC";
    break;
case 'sort3':
    $orderby="sumsort3 DESC";
    break;
case 'sort4':
    $orderby="sumsort4 DESC";
    break;
case 'sort5':
    $orderby="sumsort5 DESC";
    break;
case 'sort6':
    $orderby="sumsort6 DESC";
    break;
case 'sort7':
    $orderby="sumsort7 DESC";
    break;
case 'sort8':
    $orderby="sumsort8 DESC";
    break;
case 'addweek':
    $orderby="addtime DESC";
    $where .= "AND addtime>UNIX_TIMESTAMP((DATE_SUB(NOW(),INTERVAL 7 DAY)))";
    break;
case 'addmonth':
    $orderby = "addtime DESC";
    $where .= "AND addtime>UNIX_TIMESTAMP((DATE_SUB(NOW(),INTERVAL 30 DAY)))";
    break;
case 'add3month':
    $orderby = "addtime DESC";
    $where .= "AND addtime>UNIX_TIMESTAMP((DATE_SUB(NOW(),INTERVAL 90 DAY)))";
    break;
default:
    $orderby = "sumreview DESC";
}

$total = $db->get_value("SELECT COUNT(*) FROM {$dbpre}shops WHERE $where");
$total = min($total, 100);

if($total > 0) {
    $offset = 15;
    $limit = get_limit($page, $offset);
    $query = $db->query("SELECT a.* FROM {$dbpre}shops a WHERE $where ORDER BY $orderby LIMIT $limit");
    $i = 1;
    if(!function_exists('itemToArray')) {
        require_once(MUDDER_ROOT.'./'.$_modules['shop']['directory'].'/include/fun_item.php');
    }
    while($shop = $db->fetch_array($query)) {
        $shops[] = itemToArray($shop);
    }
    $multipage = multi($total,$offset,$page,"top.php?pcd=$pcd&sort=$sort");
}

$sorts = array('all'=>$_panels[$pcd]);
if(is_array($panelcfg['review'])) {
    foreach($panelcfg['review'] as $key => $val) {
        $sorts[$key] = $val;
    }
}

$adds = array(
    'addweek'=>'近一周加入',
    'addmonth'=>'近一个月加入',
    'add3month'=>'近三个月加入'
);

$subtitle = $adds[$sort].$sorts[$sort];
require_once MUDDER_ROOT.'header.php';
require_once template('shop_top');
footer();
?>
