124 lines
4.7 KiB
PHP
124 lines
4.7 KiB
PHP
<?php
|
|
require_once __DIR__ . '/db/config.php';
|
|
|
|
// Simple password protection
|
|
define('ADMIN_PASSWORD', '888888'); // You can change this
|
|
session_start();
|
|
|
|
if (isset($_GET['logout'])) {
|
|
session_destroy();
|
|
header("Location: admin.php");
|
|
exit;
|
|
}
|
|
|
|
if (isset($_POST['password'])) {
|
|
if ($_POST['password'] === ADMIN_PASSWORD) {
|
|
$_SESSION['admin_logged_in'] = true;
|
|
} else {
|
|
$error = "密码错误";
|
|
}
|
|
}
|
|
|
|
if (!isset($_SESSION['admin_logged_in'])) {
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="zh">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<title>后台登录 - 财神组</title>
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<style>
|
|
body { background: #B71C1C; display: flex; align-items: center; justify-content: center; height: 100vh; font-family: 'Inter', sans-serif; }
|
|
.login-card { background: #fff; padding: 2rem; border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,0.3); width: 100%; max-width: 400px; }
|
|
.btn-primary { background: #D4AF37; border: none; }
|
|
.btn-primary:hover { background: #B8860B; }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="login-card">
|
|
<h3 class="text-center mb-4" style="color: #B71C1C;">财神组内部管理</h3>
|
|
<?php if (isset($error)) echo "<div class='alert alert-danger'>$error</div>"; ?>
|
|
<form method="POST">
|
|
<div class="mb-3">
|
|
<label class="form-label">管理员密码</label>
|
|
<input type="password" name="password" class="form-control" required>
|
|
</div>
|
|
<button type="submit" class="btn btn-primary w-100">登录</button>
|
|
</form>
|
|
</div>
|
|
</body>
|
|
</html>
|
|
<?php
|
|
exit;
|
|
}
|
|
|
|
$db = db();
|
|
|
|
// Save content
|
|
if (isset($_POST['save'])) {
|
|
$id = $_POST['id'];
|
|
$title = $_POST['title'];
|
|
$content = $_POST['content'];
|
|
|
|
$stmt = $db->prepare("UPDATE site_content SET title = :title, content = :content WHERE id = :id");
|
|
$stmt->execute(['title' => $title, 'content' => $content, 'id' => $id]);
|
|
$success = "内容更新成功!";
|
|
}
|
|
|
|
$contents = $db->query("SELECT * FROM site_content ORDER BY id ASC")->fetchAll();
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="zh">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<title>内容管理后台 - 财神组</title>
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<style>
|
|
:root { --primary-red: #B71C1C; --gold: #D4AF37; }
|
|
body { background: #f8f9fa; }
|
|
.navbar { background: var(--primary-red); }
|
|
.card-header { background: var(--gold); color: white; font-weight: bold; }
|
|
.btn-gold { background: var(--gold); color: white; border: none; }
|
|
.btn-gold:hover { background: #B8860B; color: white; }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<nav class="navbar navbar-dark mb-4">
|
|
<div class="container">
|
|
<a class="navbar-brand" href="#">财神组内容管理系统</a>
|
|
<a href="?logout=1" class="btn btn-outline-light btn-sm">退出登录</a>
|
|
</div>
|
|
</nav>
|
|
|
|
<div class="container mb-5">
|
|
<?php if (isset($success)) echo "<div class='alert alert-success'>$success</div>"; ?>
|
|
|
|
<div class="row">
|
|
<div class="col-12">
|
|
<?php foreach ($contents as $c): ?>
|
|
<div class="card mb-4 shadow-sm">
|
|
<div class="card-header d-flex justify-content-between align-items-center">
|
|
<span><?php echo htmlspecialchars($c['title']); ?> (<?php echo $c['section_key']; ?>)</span>
|
|
</div>
|
|
<div class="card-body">
|
|
<form method="POST">
|
|
<input type="hidden" name="id" value="<?php echo $c['id']; ?>">
|
|
<div class="mb-3">
|
|
<label class="form-label">页面标题</label>
|
|
<input type="text" name="title" class="form-control" value="<?php echo htmlspecialchars($c['title']); ?>">
|
|
</div>
|
|
<div class="mb-3">
|
|
<label class="form-label">页面内容 (支持 HTML)</label>
|
|
<textarea name="content" class="form-control" rows="10"><?php echo htmlspecialchars($c['content']); ?></textarea>
|
|
</div>
|
|
<button type="submit" name="save" class="btn btn-gold">保存修改</button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</body>
|
|
</html>
|