<?php
if (!defined('ROOT_PATH')) { exit('Access Denied'); }
require_once __DIR__ . '/_functions.php';
$route = isset($route) ? $route : 'article';
$item = tpl_detail($route, isset($id) ? $id : 0);
$channel = $item ? tpl_channel(isset($item['channel_id']) ? $item['channel_id'] : 0) : null;
$rootChannel = $channel ? tpl_root_for_channel($channel) : null;
$title = $route === 'product' ? '产品中心' : ($route === 'article' ? '新闻资讯' : ($channel ? $channel['channel_name'] : tpl_channel_title(1)));
$tplNavKey = $route === 'product' ? 'product' : ($route === 'article' ? 'news' : 'home');
if ($route === 'article' && $channel) {
    $newsRoot = tpl_root_channel(1);
    $children = $newsRoot ? tpl_channels($newsRoot['id']) : array();
    if (!empty($children[1]) && intval($channel['id']) === intval($children[1]['id'])) { $tplNavKey = 'technical'; }
}
$seoTitle = $item && !empty($item['seo_title']) ? $item['seo_title'] : ($item ? $item['title'] : '内容详情');
$seoKeywords = $item && !empty($item['seo_keywords']) ? $item['seo_keywords'] : '';
$seoDescription = $item && !empty($item['seo_description']) ? $item['seo_description'] : tpl_text($item ? (empty($item['summary']) ? $item['content'] : $item['summary']) : '', 120);
$bodyClass = 'k620-inner-page';
$formFeedback = tpl_handle_guestbook();
$pn = $item ? tpl_prev_next($route, $item) : array('prev' => null, 'next' => null);
$listUrl = $channel ? getUrl('channel', $channel['id'], $channel['channel_dir']) : getUrl($route);
require_once __DIR__ . '/_header.php';
tpl_inner_banner($title, $route);
?>

<?php if ($route === 'product' && $item): $pictures = tpl_product_pictures($item); ?>
<main class="NyProDetail"><div class="NyProDetail_Main"><div class="NyProDetail_Img prodetail_img">
    <div id="preview"><div class="jqzoom" id="spec-n1"><img src="<?php echo tpl_e($pictures[0]); ?>" alt="<?php echo tpl_e($item['title']); ?>"></div></div>
    <div id="spec-list"><ul><?php foreach ($pictures as $index => $picture): ?><li class="<?php echo $index === 0 ? 'on' : ''; ?>"><p><img src="<?php echo tpl_e($picture); ?>" alt="<?php echo tpl_e($item['title']); ?>"></p></li><?php endforeach; ?></ul></div>
</div><div class="NyProDetail_Text"><div class="NyProDetail_Name"><?php echo tpl_e($item['title']); ?></div>
    <h1 class="NyProDetail_Ms"><span><img src="<?php echo tpl_e(tpl_asset('skin/images/ico10.png')); ?>" alt="">产品简介</span><p><?php echo tpl_e(tpl_text(!empty($item['summary']) ? $item['summary'] : $item['content'], 260)); ?></p></h1>
    <div class="NyProDetail_Tags"><dl><dd><i></i>更新时间：<?php echo date('Y-m-d', tpl_row_time($item)); ?></dd><dd><i></i>访问量：<?php echo intval(isset($item['click']) ? $item['click'] : 0); ?></dd><div class="clear"></div></dl></div>
    <div class="NyProDetail_Btm"><a href="#cpzx" class="Btn01"><i><em></em></i><span>产品咨询</span></a><a href="tel:<?php echo tpl_e(tpl_phone()); ?>" class="Btn02"><i><em></em></i><span><?php echo tpl_e(tpl_phone()); ?></span></a><div class="clear"></div></div>
</div><div class="clear"></div></div>

<div class="NyProDetail_Content"><aside class="NyProDetail_Left"><?php tpl_product_sidebar($channel); ?></aside><div class="NyProDetail_Right">
    <div class="NyProDetail_Con"><div class="NyProDetail_Tit"><span>详细介绍</span><a href="#cpzx">在线留言</a><div class="clear"></div></div><div class="ProDetailText ab_img ueditor-content"><?php echo !empty($item['content']) ? $item['content'] : (!empty($item['summary']) ? '<p>' . tpl_e($item['summary']) . '</p>' : ''); ?></div></div>
    <div class="NyPro_PrevNext"><p class="NyProPrev"><img src="<?php echo tpl_e(tpl_asset('skin/images/jt11.png')); ?>" alt="">上一个：<?php if ($pn['prev']): ?><a href="<?php echo tpl_e(tpl_item_url($route, $pn['prev'])); ?>"><?php echo tpl_e($pn['prev']['title']); ?></a><?php else: ?>没有了！<?php endif; ?></p><a href="<?php echo tpl_e($listUrl); ?>" class="NyProAll"><img src="<?php echo tpl_e(tpl_asset('skin/images/proall.png')); ?>" alt="">返回列表</a><p class="NyProNext">下一个：<?php if ($pn['next']): ?><a href="<?php echo tpl_e(tpl_item_url($route, $pn['next'])); ?>"><?php echo tpl_e($pn['next']['title']); ?></a><?php else: ?>没有了！<?php endif; ?><img src="<?php echo tpl_e(tpl_asset('skin/images/jt0.png')); ?>" alt=""></p><div class="clear"></div></div>
    <div id="cpzx"></div><div class="NyProOrder_Main"><div class="ab_Title1"><p>在线留言</p><span><i></i></span></div><?php $formAction = tpl_item_url('product', $item); require __DIR__ . '/_message_form.php'; ?></div>
</div><div class="clear"></div></div></main>

<?php elseif ($item): ?>
<main class="NyNewDetail"><div class="NyNewDetail_Main"><h1 class="NyNewDetail_Name"><?php echo tpl_e($item['title']); ?></h1><div class="NyNewDetail_Tips"><span>更新时间：<?php echo date('Y-m-d', tpl_row_time($item)); ?></span><span>点击次数：<?php echo intval(isset($item['click']) ? $item['click'] : (isset($item['view']) ? $item['view'] : 0)); ?></span></div>
    <div class="NyNewDetail_Content ab_img ueditor-content">
        <?php if ($route === 'image'): ?><p style="text-align:center"><img class="cms-detail-media" src="<?php echo tpl_e(tpl_img($item)); ?>" alt="<?php echo tpl_e($item['title']); ?>"></p><?php endif; ?>
        <?php if ($route === 'video' && !empty($item['video_path'])): ?><video class="cms-detail-media" controls preload="metadata" poster="<?php echo tpl_e(tpl_img($item)); ?>" src="<?php echo tpl_e(tpl_normalize_url($item['video_path'])); ?>"></video><?php endif; ?>
        <?php if ($route === 'recruit'): ?><div class="cms-job-meta"><span>部门：<?php echo tpl_e(isset($item['department']) ? $item['department'] : ''); ?></span><span>地区：<?php echo tpl_e(isset($item['region']) ? $item['region'] : ''); ?></span><span>薪资：<?php echo tpl_e(isset($item['salary']) ? $item['salary'] : ''); ?></span></div><?php endif; ?>
        <?php echo !empty($item['content']) ? $item['content'] : (!empty($item['summary']) ? '<p>' . tpl_e($item['summary']) . '</p>' : ''); ?>
        <?php $downloadUrl = !empty($item['file_path']) ? $item['file_path'] : (!empty($item['download_url']) ? $item['download_url'] : ''); if ($route === 'download' && $downloadUrl !== ''): ?><p><a class="cms-download-button" href="<?php echo tpl_e(tpl_normalize_url($downloadUrl)); ?>" download>下载文件</a></p><?php endif; ?>
    </div>
</div><div class="NyPrevNext"><ul><li><i>上一条</i><?php if ($pn['prev']): ?><a href="<?php echo tpl_e(tpl_item_url($route, $pn['prev'])); ?>"><?php echo tpl_e($pn['prev']['title']); ?></a><?php else: ?><span>没有了！</span><?php endif; ?></li><li><i>下一条</i><?php if ($pn['next']): ?><a href="<?php echo tpl_e(tpl_item_url($route, $pn['next'])); ?>"><?php echo tpl_e($pn['next']['title']); ?></a><?php else: ?><span>没有了！</span><?php endif; ?></li></ul></div></main>

<?php else: ?>
<main class="NyNewDetail"><div class="NyNewDetail_Main"><h1 class="NyNewDetail_Name">内容不存在</h1><div class="NyNewDetail_Content"><p>该内容可能已被删除或下线。</p></div></div></main>
<?php endif; ?>

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