<?php
if (!defined('ROOT_PATH')) { exit('Access Denied'); }
require_once __DIR__ . '/../_functions.php';
$module = isset($module) ? trim((string) $module) : 'channel';
$typeMap = array('article' => 1, 'product' => 2, 'page' => 3, 'image' => 4, 'download' => 5, 'video' => 7, 'recruit' => 9);
$channel = !empty($id) ? tpl_channel($id) : (isset($typeMap[$module]) ? tpl_root_channel($typeMap[$module]) : null);
$route = $channel ? tpl_content_route($channel['channel_type']) : (isset($typeMap[$module]) ? $module : 'article');
$title = $channel ? $channel['channel_name'] : tpl_channel_title(isset($typeMap[$route]) ? $typeMap[$route] : 1);
if ($route === 'product' && (!$channel || intval($channel['parent_id']) === 0)) { $title = '产品中心'; }
if ($route === 'article' && (!$channel || intval($channel['parent_id']) === 0)) { $title = '新闻资讯'; }
$tplNavKey = $route === 'product' ? 'product' : ($route === 'article' ? 'news' : 'home');
if ($route === 'article' && $channel) {
    $newsRoot = tpl_root_channel(1);
    $newsChildren = $newsRoot ? tpl_channels($newsRoot['id']) : array();
    if (!empty($newsChildren[1]) && intval($channel['id']) === intval($newsChildren[1]['id'])) { $tplNavKey = 'technical'; }
}
$pageSize = $route === 'article' ? 6 : ($route === 'product' ? 12 : 9);
$result = tpl_query_items($route, $channel ? $channel['id'] : 0, $pageSize, null, isset($_GET['keyword']) ? $_GET['keyword'] : '');
$baseUrl = $channel ? getUrl('channel', $channel['id'], $channel['channel_dir']) : getUrl($route);
$seoTitle = $title;
$seoKeywords = $channel && !empty($channel['seo_keywords']) ? $channel['seo_keywords'] : '';
$seoDescription = $channel && !empty($channel['seo_description']) ? $channel['seo_description'] : '';
$bodyClass = 'k620-inner-page';
require_once __DIR__ . '/../_header.php';
tpl_inner_banner($title, $route);
?>

<?php if ($route === 'product'): ?>
<main class="NyProducts"><aside class="NyPro_Left"><?php tpl_product_sidebar($channel); ?></aside><div class="NyPro_Right"><div class="abNyPro_list"><ul>
    <?php foreach ($result['items'] as $item): ?><li><div class="abIdxPro_Img"><a href="<?php echo tpl_e(tpl_item_url('product', $item)); ?>"><img src="<?php echo tpl_e(tpl_img($item)); ?>" alt="<?php echo tpl_e($item['title']); ?>"></a></div><div class="abIdxPro_Name"><a href="<?php echo tpl_e(tpl_item_url('product', $item)); ?>"><?php echo tpl_e($item['title']); ?></a></div></li><?php endforeach; ?>
    <?php if (!$result['items']): ?><li class="cms-empty">暂无产品内容</li><?php endif; ?>
</ul><div class="clear"></div></div><?php echo tpl_pagination($result, $baseUrl); ?></div><div class="clear"></div></main>

<?php elseif ($route === 'article'): ?>
<main class="NyNews"><div class="NyNews_Main"><div class="NyNews_List"><ul class="newul">
    <?php foreach ($result['items'] as $item): ?><li><div class="new_box"><p><a href="<?php echo tpl_e(tpl_item_url('article', $item)); ?>"><?php echo tpl_e($item['title']); ?></a></p><em><?php echo date('Y-m-d', tpl_row_time($item)); ?></em><span><?php echo tpl_e(tpl_text(!empty($item['summary']) ? $item['summary'] : $item['content'], 190)); ?></span></div></li><?php endforeach; ?>
    <?php if (!$result['items']): ?><li class="cms-empty">暂无资讯内容</li><?php endif; ?>
</ul></div><div class="clear"></div><?php echo tpl_pagination($result, $baseUrl); ?></div></main>

<?php else: ?>
<main class="cms-generic-list"><div class="cms-generic-grid">
    <?php foreach ($result['items'] as $item): ?><article class="cms-generic-card"><a class="cover" href="<?php echo tpl_e(tpl_item_url($route, $item)); ?>"><img src="<?php echo tpl_e(tpl_img($item)); ?>" alt="<?php echo tpl_e($item['title']); ?>"></a><h2><a href="<?php echo tpl_e(tpl_item_url($route, $item)); ?>"><?php echo tpl_e($item['title']); ?></a></h2><time><?php echo date('Y-m-d', tpl_row_time($item)); ?></time><p><?php echo tpl_e(tpl_text(isset($item['summary']) && $item['summary'] !== '' ? $item['summary'] : (isset($item['content']) ? $item['content'] : ''), 100)); ?></p></article><?php endforeach; ?>
    <?php if (!$result['items']): ?><div class="cms-empty">暂无相关内容</div><?php endif; ?>
</div><?php echo tpl_pagination($result, $baseUrl); ?></main>
<?php endif; ?>

<?php require_once __DIR__ . '/../_footer.php'; ?>
