<?php
/**
 * 会员中心 - 单入口路由 + 公共布局 (PHP 5.4兼容)
 */
$mod = isset($_GET['mod']) ? $_GET['mod'] : 'login';
$mods = array('login', 'dashboard', 'posts', 'fav', 'profile', 'pay', 'messages', 'logout');

if (!in_array($mod, $mods)) {
    $mod = 'login';
}

require_once __DIR__ . '/config.php';

// 登录/退出页面不需要登录态
if ($mod == 'login') {
    require __DIR__ . '/page/login.php';
    exit;
}
if ($mod == 'logout') {
    require __DIR__ . '/page/logout.php';
    exit;
}

// 其他页面需要登录验证
$m = member();
if (!$m) {
    header('Location: index.php?mod=login');
    exit;
}

// 执行页面逻辑，捕获内容
ob_start();
require __DIR__ . '/page/' . $mod . '.php';
$content = ob_get_clean();
$pageTitle = isset($pageTitle) ? $pageTitle : '会员中心';
?><!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title><?php echo $pageTitle; ?> - <?php echo SITE_NAME; ?></title>
<style>
*{margin:0;padding:0;box-sizing:border-box}
body{background:#f0f2f5;font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,sans-serif;color:#333;font-size:14px}
a{text-decoration:none;color:#07c160}
.header{background:#fff;border-bottom:1px solid #eee;height:50px;position:fixed;top:0;left:0;right:0;z-index:100;display:flex;align-items:center;padding:0 15px}
.header .logo{font-size:16px;font-weight:700;color:#07c160}.header .logo span{color:#999;font-size:12px}
.header .r{margin-left:auto;display:flex;align-items:center;gap:10px;font-size:13px}
.header .r .cn{color:#07c160;font-weight:600}
.mb{display:none;background:none;border:none;font-size:20px;cursor:pointer;margin-right:10px;color:#333}
.sd{position:fixed;top:50px;left:0;bottom:0;width:170px;background:#fff;border-right:1px solid #eee;overflow-y:auto;z-index:99;transition:transform .3s}
.sd .g{padding:12px 16px 4px;font-size:11px;color:#bbb}
.sd a{display:block;padding:9px 16px;color:#555;font-size:13px}
.sd a:hover{background:#f0faf5;color:#07c160}
.sd a.act{background:#f0faf5;color:#07c160;font-weight:600;border-right:3px solid #07c160}
.main{margin-left:170px;margin-top:50px;padding:18px;min-height:calc(100vh - 50px)}
.main .pt{font-size:16px;font-weight:600;margin-bottom:12px;padding-bottom:8px;border-bottom:1px solid #eee}
.card{background:#fff;border-radius:6px;padding:16px;box-shadow:0 1px 3px rgba(0,0,0,.05);margin-bottom:12px}
.cg{background:linear-gradient(135deg,#07c160,#06ad56);border-radius:6px;padding:20px;color:#fff;margin-bottom:15px}
.cg .l{font-size:12px;opacity:.9}.cg .n{font-size:28px;font-weight:700;margin:4px 0}
.cg .a{margin-top:8px}.cg .a a{display:inline-block;padding:5px 14px;border:1px solid rgba(255,255,255,.3);border-radius:4px;color:#fff;font-size:12px;margin-right:6px}
.cg .a a:hover{background:rgba(255,255,255,.12)}
.gr{display:grid;grid-template-columns:repeat(auto-fit,minmax(120px,1fr));gap:10px;margin-bottom:12px}
.gr div{background:#fff;border-radius:6px;padding:14px;box-shadow:0 1px 3px rgba(0,0,0,.04)}
.gr div .n{font-size:22px;font-weight:700}.gr div .l{font-size:12px;color:#999;margin-top:2px}
.wrp{overflow-x:auto}
table{width:100%;border-collapse:collapse;font-size:13px}
table th{background:#f8f9fa;padding:9px 8px;text-align:left;font-weight:600;color:#555;border-bottom:1px solid #eee}
table td{padding:9px 8px;border-bottom:1px solid #f5f5f5}
table tr:hover td{background:#f8f9fa}
.btn{display:inline-block;padding:5px 12px;border:none;border-radius:4px;cursor:pointer;font-size:12px}
.bg{background:#07c160;color:#fff}.bg:hover{background:#06ad56}
.br{background:#ff4d4f;color:#fff}.br:hover{background:#e04345}
.bs{padding:3px 9px;font-size:11px}
.bw{background:#fff;color:#555;border:1px solid #ddd}
.pg{text-align:center;margin-top:10px;font-size:13px}
.pg a,.pg s{display:inline-block;margin:0 2px;padding:4px 9px;border:1px solid #ddd;border-radius:3px;color:#555}
.pg a:hover{border-color:#07c160;color:#07c160}
.pg s.curr{background:#07c160;color:#fff;border-color:#07c160}
.msg{padding:9px 12px;border-radius:4px;font-size:13px;margin-bottom:10px}
.msg.e{background:#fde8e8;color:#ff4d4f}.msg.s{background:#e8f8ee;color:#07c160}
.em{text-align:center;padding:35px;color:#ccc}.em p{font-size:13px;margin-top:5px}
.ov{display:none;position:fixed;top:0;left:0;right:0;bottom:0;background:rgba(0,0,0,.3);z-index:98}
@media(max-width:768px){.sd{transform:translateX(-100%)}.sd.sh{transform:translateX(0)}.mb{display:block}.main{margin-left:0;padding:12px}.gr{grid-template-columns:1fr 1fr}.ov.sh{display:block}}
</style>
</head>
<body>
<div class="header">
<button class="mb" onclick="tg()">☰</button>
<a href="?mod=dashboard" class="logo"><?php echo SITE_NAME; ?><span> · 会员中心</span></a>
<div class="r">
<span>👤 <?php echo $m['userid']; ?></span>
<span class="cn">🪙 <?php echo intval($m['money_own']); ?></span>
<a href="?mod=logout" style="color:#ff4d4f;font-size:12px">退出</a>
</div>
</div>
<div class="ov" id="ov" onclick="tg()"></div>
<div class="sd" id="sd">
<div class="g">管理</div>
<a href="?mod=dashboard" class="<?php echo $mod=='dashboard'?'act':''; ?>">📊 首页看板</a>
<a href="?mod=posts" class="<?php echo $mod=='posts'?'act':''; ?>">📋 信息管理</a>
<a href="?mod=fav" class="<?php echo $mod=='fav'?'act':''; ?>">⭐ 我的收藏</a>
<div class="g">账户</div>
<a href="?mod=pay" class="<?php echo $mod=='pay'?'act':''; ?>">💰 金币充值</a>
<a href="?mod=profile" class="<?php echo $mod=='profile'?'act':''; ?>">👤 个人资料</a>
<a href="?mod=messages" class="<?php echo $mod=='messages'?'act':''; ?>">✉️ 站内消息</a>
<div class="g">快捷</div>
<a href="/index.php?mod=post" target="_blank">📝 发布信息</a>
<a href="/" target="_blank">🏠 返回首页</a>
</div>
<div class="main"><?php echo $content; ?></div>
<script>
function tg(){document.getElementById('sd').classList.toggle('sh');document.getElementById('ov').classList.toggle('sh')}
</script>
</body>
</html>
