feat(公告管理): 添加公告删除功能并优化公告显示
- 新增delete_announcement.php实现公告删除功能 - 在公告管理页面添加删除按钮和确认对话框 - 在首页公告显示中添加发布时间 - 更新config.php中的数据库和SMTP配置 - 优化公告管理页面的导航栏和提示样式
This commit is contained in:
@@ -63,6 +63,8 @@ $result = $conn->query($sql);
|
||||
<title>公告管理 - <?php echo APP_STORE_NAME; ?></title>
|
||||
<!-- Bootstrap CSS -->
|
||||
<link href="../css/bootstrap.min.css" rel="stylesheet">
|
||||
<!-- SweetAlert2 CSS -->
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/sweetalert2@11/dist/sweetalert2.min.css">
|
||||
<!-- 自定义CSS -->
|
||||
<link rel="stylesheet" href="../styles.css">
|
||||
<!-- Fluent Design 模糊效果 -->
|
||||
@@ -99,7 +101,7 @@ $result = $conn->query($sql);
|
||||
<a class="nav-link" href="system_info.php">系统信息</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="announcements.php">公告管理</a>
|
||||
<a class="nav-link active" aria-current="page" href="announcements.php">公告管理</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="#" onclick="confirmLogout()">退出登录</a>
|
||||
@@ -110,7 +112,6 @@ $result = $conn->query($sql);
|
||||
</nav>
|
||||
|
||||
<div class="container mt-4">
|
||||
<script src="/js/sweetalert.js"></script>
|
||||
<script>
|
||||
function confirmLogout() {
|
||||
Swal.fire({
|
||||
@@ -125,22 +126,38 @@ $result = $conn->query($sql);
|
||||
}
|
||||
});
|
||||
}
|
||||
function confirmDelete(id) {
|
||||
Swal.fire({
|
||||
title: '确定要删除这条公告吗?',
|
||||
icon: 'warning',
|
||||
showCancelButton: true,
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消'
|
||||
}).then((result) => {
|
||||
if (result.isConfirmed) {
|
||||
window.location.href = 'delete_announcement.php?id=' + id;
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
<?php if (isset($_GET['success'])): ?>
|
||||
<script>
|
||||
Swal.fire({
|
||||
icon: "success",
|
||||
title: "成功",
|
||||
text: "<?php echo addslashes($_GET['success']); ?>",
|
||||
});
|
||||
</script>
|
||||
<?php endif; ?>
|
||||
<?php if (isset($error)): ?>
|
||||
<script>
|
||||
Swal.fire({
|
||||
icon: "error",
|
||||
title: "错误",
|
||||
text: "<?php echo addslashes($error); ?>",
|
||||
});
|
||||
</script>
|
||||
<?php endif; ?>
|
||||
</script>
|
||||
|
||||
<h2>发布公告</h2>
|
||||
<form method="post">
|
||||
@@ -163,6 +180,7 @@ $result = $conn->query($sql);
|
||||
<th>标题</th>
|
||||
<th>发布者</th>
|
||||
<th>发布时间</th>
|
||||
<th>操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@@ -172,6 +190,9 @@ $result = $conn->query($sql);
|
||||
<td><?php echo htmlspecialchars($row['title']); ?></td>
|
||||
<td><?php echo htmlspecialchars($row['username']); ?></td>
|
||||
<td><?php echo $row['created_at']; ?></td>
|
||||
<td>
|
||||
<button class="btn btn-danger btn-sm" onclick="confirmDelete(<?php echo $row['id']; ?>)">删除</button>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endwhile; ?>
|
||||
</tbody>
|
||||
@@ -180,6 +201,8 @@ $result = $conn->query($sql);
|
||||
|
||||
<!-- Bootstrap JS Bundle with Popper -->
|
||||
<script src="/js/bootstrap.bundle.js"></script>
|
||||
<!-- SweetAlert2 JS -->
|
||||
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11/dist/sweetalert2.all.min.js"></script>
|
||||
<script>
|
||||
// 导航栏滚动效果
|
||||
window.addEventListener('scroll', function() {
|
||||
|
||||
41
admin/delete_announcement.php
Normal file
41
admin/delete_announcement.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
require_once '../config.php';
|
||||
session_start();
|
||||
|
||||
// 检查管理员登录状态
|
||||
if (!isset($_SESSION['admin']) || !isset($_SESSION['admin']['id'])) {
|
||||
header('Location: login.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
// 检查权限 - 只允许all权限
|
||||
if ($_SESSION['admin']['permission'] !== 'all') {
|
||||
header('Location: announcements.php?error=没有删除公告的权限');
|
||||
exit();
|
||||
}
|
||||
|
||||
// 验证公告ID
|
||||
if (!isset($_GET['id']) || !is_numeric($_GET['id'])) {
|
||||
header('Location: announcements.php?error=无效的公告ID');
|
||||
exit();
|
||||
}
|
||||
|
||||
$announcement_id = intval($_GET['id']);
|
||||
|
||||
// 执行删除操作
|
||||
$stmt = $conn->prepare('DELETE FROM announcements WHERE id = ?');
|
||||
$stmt->bind_param('i', $announcement_id);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
$success = '公告已成功删除';
|
||||
} else {
|
||||
$error = '删除公告失败: ' . $conn->error;
|
||||
}
|
||||
|
||||
$stmt->close();
|
||||
$conn->close();
|
||||
|
||||
// 重定向回公告管理页面并显示结果
|
||||
$redirect = 'announcements.php?' . ($success ? 'success=' . urlencode($success) : 'error=' . urlencode($error));
|
||||
header('Location: ' . $redirect);
|
||||
exit;
|
||||
@@ -92,7 +92,7 @@ if (!isset($conn) || !$conn instanceof mysqli) {
|
||||
|
||||
<?php
|
||||
// 获取最新公告
|
||||
$announcementQuery = "SELECT title, content FROM announcements ORDER BY created_at DESC LIMIT 1";
|
||||
$announcementQuery = "SELECT title, content, created_at FROM announcements ORDER BY created_at DESC LIMIT 1";
|
||||
$announcementResult = $conn->query($announcementQuery);
|
||||
$announcement = $announcementResult && $announcementResult->num_rows > 0 ? $announcementResult->fetch_assoc() : null;
|
||||
?>
|
||||
@@ -100,6 +100,7 @@ $announcement = $announcementResult && $announcementResult->num_rows > 0 ? $anno
|
||||
<div class="container mt-3">
|
||||
<div class="alert alert-info blur-bg">
|
||||
<h4 class="alert-heading"><?php echo htmlspecialchars($announcement['title']); ?></h4>
|
||||
<p class="text-muted small">发布时间: <?php echo date('Y-m-d H:i', strtotime($announcement['created_at'])); ?></p>
|
||||
<p><?php echo nl2br(htmlspecialchars($announcement['content'])); ?></p>
|
||||
<p class="mt-2"><a href="history_announcements.php" class="alert-link">查看所有历史公告</a></p>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user