<?php
/**
 * 芋头CMS
 * ============================================================================
 * 版权所有 2016-2028 沅陵县乌托邦网络服务有限公司，并保留所有权利。
 * 网站地址: http://www.yutoucms.cn
 * ----------------------------------------------------------------------------
 * 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷。
 * ============================================================================
 * Author: 芋头 <mxgsf@qq.com>
 * Date: 2026-6-2
 */
if (!defined('ROOT_PATH')) exit;
$navChannels = $db->fetchAll("SELECT * FROM {$db->table('channel')} WHERE parent_id=0 AND is_show=1 ORDER BY list_order ASC,id ASC");
$currentChannelId = isset($currentChannel) && is_array($currentChannel) && isset($currentChannel['id']) ? intval($currentChannel['id']) : 0;
$currentParentId = isset($currentChannel) && is_array($currentChannel) && isset($currentChannel['parent_id']) ? intval($currentChannel['parent_id']) : 0;
function tpl_channel_url($ch){ return getUrl('channel', intval($ch['id']), isset($ch['channel_dir']) ? $ch['channel_dir'] : ''); }
?>
<div class="header">
  <div class="headernr hidden-s clearfix">
    <div class="logo left">
      <a href="<?php echo getUrl('home'); ?>">
        <?php if (!empty($site['site_logo'])) { ?>
        <img src="<?php echo htmlspecialchars($site['site_logo']); ?>" alt="<?php echo htmlspecialchars($site['site_name']); ?>" />
        <?php } else { ?>
        <span style="height:60px;line-height:60px;font-size:28px;font-weight:bold;color:#0068b4;display:inline-block;"> <?php echo htmlspecialchars($site['site_name']); ?> </span>
        <?php } ?>
      </a>
    </div>
    <div class="nav right">
      <ul id="menu3" class="menu">
        <li tabindex="0" class="<?php echo $module=='index' ? 'current' : ''; ?>"><a href="<?php echo getUrl('home'); ?>">网站首页</a></li>
        <?php foreach ($navChannels as $ch) { $sub = $db->fetchAll("SELECT * FROM {$db->table('channel')} WHERE parent_id=".intval($ch['id'])." AND is_show=1 ORDER BY list_order ASC,id ASC"); ?>
        <li tabindex="0" class="<?php echo ($currentChannelId === intval($ch['id']) || $currentParentId === intval($ch['id'])) ? 'current' : ''; ?>">
          <a href="<?php echo tpl_channel_url($ch); ?>"><?php echo htmlspecialchars($ch['channel_name']); ?></a>
          <?php if (!empty($sub)) { ?>
          <ul class="submenu shield">
            <?php foreach ($sub as $s) { ?>
            <li><a href="<?php echo tpl_channel_url($s); ?>"><?php echo htmlspecialchars($s['channel_name']); ?></a></li>
            <?php } ?>
          </ul>
          <?php } ?>
        </li>
        <?php } ?>
        <li tabindex="0" class="<?php echo $module=='guestbook' ? 'current' : ''; ?>"><a href="<?php echo getUrl('guestbook'); ?>">在线留言</a></li>
      </ul>
    </div>
  </div>
  <div class="mobile-header clearfix">
    <div class="logo left">
      <a href="<?php echo getUrl('home'); ?>">
        <?php if (!empty($site['site_logo'])) { ?>
        <img src="<?php echo htmlspecialchars($site['site_logo']); ?>" alt="<?php echo htmlspecialchars($site['site_name']); ?>" />
        <?php } else { ?>
        <span style="height:40px;line-height:40px;font-size:20px;font-weight:bold;color:#0068b4;margin-left:10px;display:inline-block;"> <?php echo htmlspecialchars($site['site_name']); ?> </span>
        <?php } ?>
      </a>
    </div>
    <div class="mobile-menu right">
      <a id="menu" href="javascript:void(0)"><span></span><span></span><span></span></a>
      <div id="sidenav">
        <a class="nav-close" href="javascript:void()"><span></span><span></span></a>
        <ul>
          <li><a href="<?php echo getUrl('home'); ?>">网站首页</a></li>
          <?php foreach ($navChannels as $ch) { ?>
          <li><a href="<?php echo tpl_channel_url($ch); ?>"><?php echo htmlspecialchars($ch['channel_name']); ?></a></li>
          <?php } ?>
          <li><a href="<?php echo getUrl('guestbook'); ?>">在线留言</a></li>
        </ul>
      </div>
    </div>
  </div>
</div>
<script>$(function(){$('#menu').click(function(){$(this).addClass('active');$(this).next().addClass('active');});$('.nav-close').click(function(){$(this).parent().removeClass('active');$(this).parent().prev().removeClass('active');});});</script>
