<?php
/**
 * 芋头CMS
 * ============================================================================
 * 版权所有 2016-2028 沅陵县乌托邦网络服务有限公司，并保留所有权利。
 * 网站地址: http://www.yutoucms.cn
 * ----------------------------------------------------------------------------
 * 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷。
 * ============================================================================
 * Author: 芋头 <mxgsf@qq.com>
 * Date: 2026-6-3
 */
if (!defined('ROOT_PATH')) exit;
$guestRows = $db->fetchAll("SELECT * FROM {$db->table('guestbook')} WHERE is_show=1 ORDER BY create_time DESC LIMIT 20");
$currentChannel = $db->fetch("SELECT * FROM {$db->table('channel')} WHERE channel_type=8 AND is_show=1 ORDER BY list_order ASC,id ASC LIMIT 1");
$bannerPic = !empty($slides[0]['slide_pic']) ? $slides[0]['slide_pic'] : (!empty($currentChannel['channel_thumb']) ? $currentChannel['channel_thumb'] : 'https://picsum.photos/1600/500?random=88');
$mobileBannerPic = !empty($slides[0]['slide_pic']) ? $slides[0]['slide_pic'] : (!empty($currentChannel['channel_thumb']) ? $currentChannel['channel_thumb'] : 'https://picsum.photos/1200/400?random=88');
?><!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no" />
    <title>在线留言-<?php echo htmlspecialchars($site['site_name']); ?></title>
    <link href="<?php echo $site['template_dir']; ?>css/style.css" rel="stylesheet" type="text/css" />
    <link href="<?php echo $site['template_dir']; ?>css/bootstrap.min.css" rel="stylesheet" type="text/css" />
    <script src="<?php echo $site['template_dir']; ?>js/jquery-1.8.3.min.js"></script>
</head>
<body>
<?php include dirname(__FILE__) . '/_header.php'; ?>

<div class="banner_n" style="background:url(<?php echo htmlspecialchars($bannerPic); ?>) no-repeat top center;background-size:cover;">
    <div class="capitalize">
        <div class="ad-tit">在线留言</div>
        <div class="ad-line"></div>
    </div>
</div>

<div class="mbanner">
    <img src="<?php echo htmlspecialchars($mobileBannerPic); ?>" width="100%" />
</div>

<div class="post">
    <div class="postcon clearfix">
        <div class="col-md-8 col-sm-12 col-xs-12 nabout_menu"><ul></ul></div>
        <div class="col-md-4 col-sm-12 col-xs-12 position hidden-s">
            <img src="<?php echo $site['template_dir']; ?>images/tb6.png" alt="当前位置" />
            <a href="<?php echo getUrl('home'); ?>">首页</a> >> <a href="<?php echo getUrl('guestbook'); ?>">在线留言</a>
        </div>
    </div>
</div>

<div class="ncontact cont">
    <div class="nmessagenr">
        <form action="/public/guestbook.php" class="my-4" method="post">
            <ul>
                <li><input type="text" name="name" id="name" class="intxt name" placeholder="请输入姓名"></li>
                <li><input type="text" name="phone" id="tel" class="intxt phone" placeholder="请输入手机号"></li>
                <li><input type="text" name="title" id="email" class="intxt email" placeholder="请输入标题" /></li>
                <li><textarea name="content" id="content" placeholder="请输入留言内容"></textarea></li>
            </ul>
            <div class="tjbtn"><button type="submit" class="coolbg" id="tj">提交</button></div>
        </form>
    </div>

    <?php if (!empty($guestRows)): ?>
    <div class="nmessagenr">
        <ul>
            <?php foreach ($guestRows as $g): ?>
            <li style="width:100%;margin:0 0 15px 0;float:none;background:#f7f7f7;padding:15px;border-radius:6px;">
                <strong><?php echo htmlspecialchars($g['name']); ?></strong>
                <div style="color:#999;margin:6px 0;">
                    <?php echo htmlspecialchars(is_numeric($g['create_time']) ? date('Y-m-d H:i', $g['create_time']) : $g['create_time']); ?>
                </div>
                <?php if (!empty($g['title'])): ?>
                <div style="font-size:13px;color:#666;margin-bottom:8px;">标题：<?php echo htmlspecialchars($g['title']); ?></div>
                <?php endif; ?>
                <div style="line-height:1.8;color:#333;"><?php echo nl2br(htmlspecialchars($g['content'])); ?></div>
                <?php if (!empty($g['reply'])): ?>
                <div style="margin-top:12px;padding:12px 14px;background:#f0fdf4;border:1px solid #bbf7d0;border-radius:6px;line-height:1.8;color:#166534;">
                    <div style="font-weight:700;margin-bottom:6px;">管理员回复</div>
                    <div><?php echo nl2br(htmlspecialchars($g['reply'])); ?></div>
                    <?php if (!empty($g['reply_time'])): ?>
                    <div style="margin-top:8px;font-size:12px;color:#16a34a;">回复时间：<?php echo date('Y-m-d H:i', $g['reply_time']); ?></div>
                    <?php endif; ?>
                </div>
                <?php endif; ?>
            </li>
            <?php endforeach; ?>
        </ul>
    </div>
    <?php endif; ?>
</div>

<script>
$(function(){
    $('#tj').click(function(){
        if($('#name').val() == ''){
            alert('请输入您的姓名！');
            $('#name').focus();
            return false;
        }
        if($('#tel').val() == ''){
            alert('请输入你的手机！');
            $('#tel').focus();
            return false;
        }
    });
});
</script>

<?php include dirname(__FILE__) . '/_footer.php'; ?>
</body>
</html>
