226 lines
11 KiB
PHP
226 lines
11 KiB
PHP
<?php
|
|
session_start();
|
|
if (!isset($_SESSION['admin_logged_in'])) {
|
|
header('Location: login.php');
|
|
exit;
|
|
}
|
|
|
|
require_once __DIR__ . '/db/config.php';
|
|
$pdo = db();
|
|
|
|
// Get settings for favicon and logo
|
|
$stmt = $pdo->query("SELECT setting_key, setting_value FROM settings");
|
|
$settings = [];
|
|
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
|
|
$settings[$row['setting_key']] = $row['setting_value'];
|
|
}
|
|
$site_logo = $settings['site_logo'] ?? 'assets/pasted-20260207-134833-7329dc42.jpg';
|
|
|
|
$message = '';
|
|
$edit_day = isset($_GET['edit']) ? (int)$_GET['edit'] : 0;
|
|
|
|
// Handle Content Update
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['update_step'])) {
|
|
$day = (int)$_POST['day_number'];
|
|
$stmt = $pdo->prepare("UPDATE steps SET
|
|
title = ?, what_to_chat = ?, how_to_chat = ?, why_to_chat = ?,
|
|
correct_example = ?, wrong_example = ?, correct_explanation = ?,
|
|
wrong_explanation = ?, image_url = ?
|
|
WHERE day_number = ?");
|
|
|
|
$stmt->execute([
|
|
$_POST['title'], $_POST['what_to_chat'], $_POST['how_to_chat'], $_POST['why_to_chat'],
|
|
$_POST['correct_example'], $_POST['wrong_example'], $_POST['correct_explanation'],
|
|
$_POST['wrong_explanation'], $_POST['image_url'], $day
|
|
]);
|
|
$message = "第 {$day} 天的内容更新成功!";
|
|
$edit_day = 0;
|
|
}
|
|
|
|
// Fetch all steps
|
|
$steps = $pdo->query("SELECT * FROM steps ORDER BY day_number ASC")->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
// Fetch specific step for editing
|
|
$current_step = null;
|
|
if ($edit_day > 0) {
|
|
foreach ($steps as $s) {
|
|
if ($s['day_number'] == $edit_day) {
|
|
$current_step = $s;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="zh-CN">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>话术管理 - <?php echo htmlspecialchars($settings['site_title'] ?? '财神组聊天框架'); ?></title>
|
|
<link rel="icon" type="image/jpeg" href="<?php echo htmlspecialchars($site_logo); ?>">
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.1/font/bootstrap-icons.css">
|
|
<style>
|
|
:root { --admin-sidebar-width: 240px; }
|
|
body { background: #f8f9fa; }
|
|
.sidebar {
|
|
height: 100vh;
|
|
background: #212529;
|
|
color: #fff;
|
|
padding-top: 20px;
|
|
position: fixed;
|
|
width: var(--admin-sidebar-width);
|
|
z-index: 100;
|
|
}
|
|
.sidebar a { color: #adb5bd; text-decoration: none; padding: 12px 20px; display: block; transition: 0.2s; }
|
|
.sidebar a:hover, .sidebar a.active { background: #343a40; color: #fff; border-left: 4px solid #d4af37; }
|
|
.main-content {
|
|
margin-left: var(--admin-sidebar-width);
|
|
padding: 40px;
|
|
min-height: 100vh;
|
|
}
|
|
@media (max-width: 991px) {
|
|
.sidebar {
|
|
width: 100%;
|
|
height: auto;
|
|
position: fixed;
|
|
top: 0;
|
|
left: 0;
|
|
padding: 5px 0;
|
|
display: flex;
|
|
flex-wrap: nowrap;
|
|
overflow-x: auto;
|
|
justify-content: flex-start;
|
|
box-shadow: 0 2px 10px rgba(0,0,0,0.2);
|
|
}
|
|
.main-content {
|
|
margin-left: 0;
|
|
padding: 80px 15px 20px 15px;
|
|
}
|
|
.sidebar a {
|
|
padding: 10px 15px;
|
|
white-space: nowrap;
|
|
font-size: 0.85rem;
|
|
border-left: none !important;
|
|
border-bottom: 3px solid transparent;
|
|
}
|
|
.sidebar a.active {
|
|
border-bottom: 3px solid #d4af37;
|
|
}
|
|
.sidebar hr, .sidebar .text-center { display: none !important; }
|
|
}
|
|
.card-header { font-weight: bold; }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="sidebar">
|
|
<div class="text-center mb-4 px-3">
|
|
<?php if($site_logo): ?>
|
|
<img src="<?php echo htmlspecialchars($site_logo); ?>" alt="Logo" class="img-fluid mb-2" style="max-height: 60px; border-radius: 8px;">
|
|
<?php endif; ?>
|
|
<h5 class="text-warning">财神组管理</h5>
|
|
</div>
|
|
<a href="admin.php"><i class="bi bi-gear-fill me-2"></i> 系统设置</a>
|
|
<a href="admin_steps.php" class="active"><i class="bi bi-chat-dots-fill me-2"></i> 话术管理</a>
|
|
<a href="index.php" target="_blank"><i class="bi bi-eye me-2"></i> 查看前台</a>
|
|
<a href="logout.php"><i class="bi bi-box-arrow-right me-2"></i> 退出登录</a>
|
|
</div>
|
|
|
|
<div class="main-content">
|
|
<div class="container-fluid">
|
|
<div class="d-flex justify-content-between align-items-center mb-4">
|
|
<h3>话术管理</h3>
|
|
</div>
|
|
|
|
<?php if($message): ?>
|
|
<div class="alert alert-success"><?php echo $message; ?></div>
|
|
<?php endif; ?>
|
|
|
|
<?php if ($current_step): ?>
|
|
<div class="card shadow-sm mb-5">
|
|
<div class="card-header bg-dark text-white d-flex justify-content-between">
|
|
<span>正在编辑:第 <?php echo $current_step['day_number']; ?> 天</span>
|
|
<a href="admin_steps.php" class="text-white text-decoration-none"><i class="bi bi-x-lg"></i></a>
|
|
</div>
|
|
<div class="card-body p-4">
|
|
<form method="POST">
|
|
<input type="hidden" name="day_number" value="<?php echo $current_step['day_number']; ?>">
|
|
<div class="row g-3 mb-3">
|
|
<div class="col-md-6">
|
|
<label class="form-label fw-bold">步骤标题</label>
|
|
<input type="text" name="title" class="form-control" value="<?php echo htmlspecialchars($current_step['title']); ?>" required>
|
|
</div>
|
|
<div class="col-md-6">
|
|
<label class="form-label fw-bold">示例图片 URL</label>
|
|
<input type="text" name="image_url" class="form-control" value="<?php echo htmlspecialchars($current_step['image_url']); ?>" placeholder="https://...">
|
|
</div>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label class="form-label fw-bold">聊什么 (What)</label>
|
|
<textarea name="what_to_chat" class="form-control" rows="3"><?php echo htmlspecialchars($current_step['what_to_chat']); ?></textarea>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label class="form-label fw-bold">怎么去聊 (How)</label>
|
|
<textarea name="how_to_chat" class="form-control" rows="3"><?php echo htmlspecialchars($current_step['how_to_chat']); ?></textarea>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label class="form-label fw-bold">为什么要这样聊 (Why)</label>
|
|
<textarea name="why_to_chat" class="form-control" rows="3"><?php echo htmlspecialchars($current_step['why_to_chat']); ?></textarea>
|
|
</div>
|
|
<div class="row g-3 mb-4">
|
|
<div class="col-md-6">
|
|
<div class="p-3 border rounded bg-light">
|
|
<label class="form-label text-success fw-bold">正确做法示例</label>
|
|
<textarea name="correct_example" class="form-control mb-2" rows="4"><?php echo htmlspecialchars($current_step['correct_example']); ?></textarea>
|
|
<label class="form-label small fw-bold">正确做法解释</label>
|
|
<textarea name="correct_explanation" class="form-control" rows="2"><?php echo htmlspecialchars($current_step['correct_explanation']); ?></textarea>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-6">
|
|
<div class="p-3 border rounded bg-light">
|
|
<label class="form-label text-danger fw-bold">错误做法示例</label>
|
|
<textarea name="wrong_example" class="form-control mb-2" rows="4"><?php echo htmlspecialchars($current_step['wrong_example']); ?></textarea>
|
|
<label class="form-label small fw-bold">错误做法解释</label>
|
|
<textarea name="wrong_explanation" class="form-control" rows="2"><?php echo htmlspecialchars($current_step['wrong_explanation']); ?></textarea>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="d-flex gap-2">
|
|
<button type="submit" name="update_step" class="btn btn-warning px-5 fw-bold">更新内容</button>
|
|
<a href="admin_steps.php" class="btn btn-light px-4">取消</a>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<div class="table-responsive bg-white p-3 rounded shadow-sm">
|
|
<table class="table table-hover align-middle">
|
|
<thead class="table-light">
|
|
<tr>
|
|
<th width="80">天数</th>
|
|
<th>标题</th>
|
|
<th class="d-none d-md-table-cell">最后更新</th>
|
|
<th width="120">操作</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($steps as $s): ?>
|
|
<tr>
|
|
<td class="fw-bold">Day <?php echo $s['day_number']; ?></td>
|
|
<td><?php echo htmlspecialchars($s['title']); ?></td>
|
|
<td class="small text-muted d-none d-md-table-cell"><?php echo $s['updated_at']; ?></td>
|
|
<td>
|
|
<a href="admin_steps.php?edit=<?php echo $s['day_number']; ?>" class="btn btn-sm btn-outline-warning">
|
|
<i class="bi bi-pencil-square"></i> 编辑
|
|
</a>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</body>
|
|
</html>
|