<?php

/**
 * ECSHOP 文章分类
 * ============================================================================
 * 版权所有 (C) 2005-2007 北京亿商互动科技发展有限公司，并保留所有权利。
 * 网站地址: http://www.ecshop.com
 * ----------------------------------------------------------------------------
 * 这是一个免费开源的软件；这意味着您可以在不用于商业目的的前提下对程序代码
 * 进行修改、使用和再发布。
 * ============================================================================
 * @author:     Weber Liu <weberliu@hotmail.com>
 * @version:    v2.1
 * ---------------------------------------------
 * $Author: paulgao $
 * $Date: 2007-04-19 18:11:35 +0800 (星期四, 19 四月 2007) $
 * $Id: article_cat.php 8272 2007-04-19 10:11:35Z paulgao $
*/

define('IN_ECS', true);

require('./includes/init.php');

if ((DEBUG_MODE & 2) != 2)
{
    $smarty->caching = true;
}

/*------------------------------------------------------ */
//-- INPUT
/*------------------------------------------------------ */

/* 获得指定的分类ID */
if (!empty($_GET['id']))
{
    $cat_id = intval($_GET['id']);
}
elseif (!empty($_GET['category']))
{
    $cat_id = intval($_GET['category']);
}
else
{
    header("Location: ./\n");

    exit;
}

/* 获得当前页码 */
$page = !empty($_REQUEST['page']) ? intval($_REQUEST['page']) : 1;

/*------------------------------------------------------ */
//-- PROCESSOR
/*------------------------------------------------------ */

/* 获得页面的缓存ID */
$cache_id = sprintf('%X', crc32($cat_id . '-' . $page . '-' . $_CFG['lang']));

if (!$smarty->is_cached('article_cat.dwt', $cache_id))
{
    /* 如果页面没有被缓存则重新获得页面的内容 */
    $smarty->assign('nav_list',        get_navigator());        // 导航栏

    assign_template();
    $position = assign_ur_here($cat_id);
    $smarty->assign('page_title',      $position['title']);     // 页面标题
    $smarty->assign('ur_here',         $position['ur_here']);   // 当前位置

    $smarty->assign('categories',      get_categories_tree(0)); // 分类树
    $smarty->assign('helps',            get_shop_help());        // 网店帮助
    $smarty->assign('top_goods',       get_top10());            // 销售排行

    $smarty->assign('best_goods',      get_recommend_goods('best'));
    $smarty->assign('new_goods',       get_recommend_goods('new'));
    $smarty->assign('hot_goods',       get_recommend_goods('hot'));
    $smarty->assign('promotion_goods', get_recommend_goods('promote'));

    /* Meta */
    $meta = $db->getRow("SELECT keywords, cat_desc FROM " . $ecs->table('article_cat') . " WHERE cat_id = '$cat_id'");

    if ($meta === false || empty($meta))
    {
        /* 如果没有找到任何记录则返回首页 */
        header("Location: ./\n");
        exit;
    }

    $smarty->assign('keywords',    htmlspecialchars($meta['keywords']));
    $smarty->assign('description', htmlspecialchars($meta['cat_desc']));

    /* 获得文章总数 */
    $size = isset($_CFG['page_size']) && intval($_CFG['page_size']) > 0 ? intval($_CFG['page_size']) : 20;
    $count = $db->getOne("SELECT COUNT(*) FROM " . $ecs->table('article') . " WHERE cat_id = '$cat_id' AND is_open = 1");
    $max_page = ($count > 0) ? ceil($count / $size) : 1;
    if ($page > $max_page)
    {
        $page = $max_page;
    }

    /* 获得文章列表 */
    $smarty->assign('artciles_list', get_cat_articles($cat_id, $page, $size));

    /* 分页 */
    assign_pager('article_cat', $cat_id, $count, $size, '', '', $page);
    assign_dynamic('article_cat');
}

$smarty->display('article_cat.dwt', $cache_id);

?>