38271-vm/admin_steps.php
Flatlogic Bot 7174e34e88 财神
2026-02-07 13:55:25 +00:00

179 lines
9.7 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">
<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>
.sidebar { height: 100vh; background: #212529; color: #fff; padding-top: 20px; position: fixed; width: 16.666667%; }
.sidebar a { color: #adb5bd; text-decoration: none; padding: 10px 20px; display: block; }
.sidebar a:hover { background: #343a40; color: #fff; }
.sidebar a.active { background: #343a40; color: #fff; border-left: 4px solid #d4af37; }
.main-content { padding: 30px; background: #f8f9fa; min-height: 100vh; margin-left: 16.666667%; }
</style>
</head>
<body>
<div class="container-fluid">
<div class="row">
<div class="col-md-2 sidebar px-0">
<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>
<hr>
<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="col-md-10 main-content">
<div class="d-flex justify-content-between align-items-center mb-4">
<h3>话术管理 (1-7天步骤)</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">
<form method="POST">
<input type="hidden" name="day_number" value="<?php echo $current_step['day_number']; ?>">
<div class="row mb-3">
<div class="col-md-6">
<label class="form-label">步骤标题</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">示例图片 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">聊什么 (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">怎么去聊 (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">为什么要这样聊 (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 mb-3">
<div class="col-md-6">
<label class="form-label text-success">正确做法示例</label>
<textarea name="correct_example" class="form-control" rows="4"><?php echo htmlspecialchars($current_step['correct_example']); ?></textarea>
<label class="form-label mt-2">正确做法解释</label>
<textarea name="correct_explanation" class="form-control" rows="2"><?php echo htmlspecialchars($current_step['correct_explanation']); ?></textarea>
</div>
<div class="col-md-6">
<label class="form-label text-danger">错误做法示例</label>
<textarea name="wrong_example" class="form-control" rows="4"><?php echo htmlspecialchars($current_step['wrong_example']); ?></textarea>
<label class="form-label mt-2">错误做法解释</label>
<textarea name="wrong_explanation" class="form-control" rows="2"><?php echo htmlspecialchars($current_step['wrong_explanation']); ?></textarea>
</div>
</div>
<div class="d-flex gap-2">
<button type="submit" name="update_step" class="btn btn-warning px-5">更新内容</button>
<a href="admin_steps.php" class="btn btn-light">取消</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>最后更新</th>
<th width="150">操作</th>
</tr>
</thead>
<tbody>
<?php foreach ($steps as $s): ?>
<tr>
<td>Day <?php echo $s['day_number']; ?></td>
<td><?php echo htmlspecialchars($s['title']); ?></td>
<td class="small text-muted"><?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>
</div>
</body>
</html>