607 行
24 KiB
PHP
607 行
24 KiB
PHP
<?php
|
|
// 启动会话
|
|
session_start();
|
|
|
|
// 引入必要的文件
|
|
require_once __DIR__ . '/../modules/user.php';
|
|
|
|
// 检查用户是否登录
|
|
if (!isLoggedIn()) {
|
|
header('Location: ../index.php');
|
|
exit;
|
|
}
|
|
|
|
// 检查用户是否是管理员
|
|
$currentUserId = $_SESSION['user_id'];
|
|
if (!isAdmin($currentUserId)) {
|
|
header('Location: ../index.php');
|
|
exit;
|
|
}
|
|
|
|
// 处理表单提交
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
if (isset($_POST['action'])) {
|
|
switch ($_POST['action']) {
|
|
case 'ban':
|
|
if (isset($_POST['user_id'])) {
|
|
banUser($_POST['user_id']);
|
|
}
|
|
break;
|
|
case 'unban':
|
|
if (isset($_POST['user_id'])) {
|
|
unbanUser($_POST['user_id']);
|
|
}
|
|
break;
|
|
case 'change_username':
|
|
if (isset($_POST['user_id']) && isset($_POST['new_username'])) {
|
|
$user = getUserById($_POST['user_id']);
|
|
if ($user) {
|
|
$user['username'] = $_POST['new_username'];
|
|
$db = Database::getInstance();
|
|
$db->execute("UPDATE users SET username = :username WHERE id = :id", [
|
|
'username' => $_POST['new_username'],
|
|
'id' => $_POST['user_id']
|
|
]);
|
|
}
|
|
}
|
|
break;
|
|
case 'change_password':
|
|
if (isset($_POST['user_id']) && isset($_POST['new_password'])) {
|
|
changeUserPassword($_POST['user_id'], $_POST['new_password']);
|
|
}
|
|
break;
|
|
case 'set_admin':
|
|
if (isset($_POST['user_id']) && isset($_POST['is_admin'])) {
|
|
setAdmin($_POST['user_id'], $_POST['is_admin'] === '1');
|
|
}
|
|
break;
|
|
case 'process_report':
|
|
if (isset($_POST['report_id']) && isset($_POST['action_type'])) {
|
|
require_once __DIR__ . '/../modules/message.php';
|
|
processReport($_POST['report_id'], $currentUserId, $_POST['action_type']);
|
|
}
|
|
break;
|
|
case 'publish_announcement':
|
|
if (isset($_POST['announcement_title']) && isset($_POST['announcement_content'])) {
|
|
require_once __DIR__ . '/../modules/message.php';
|
|
$title = $_POST['announcement_title'];
|
|
$content = $_POST['announcement_content'];
|
|
publishSystemAnnouncement($title, $content);
|
|
// 显示成功消息
|
|
echo '<script>alert("系统公告发布成功!"); window.location.href = "index.php";</script>';
|
|
exit;
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
// 获取所有用户
|
|
$users = getAllUsers();
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="zh-CN">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>管理员面板</title>
|
|
<link rel="stylesheet" href="../style.css">
|
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
|
|
<style>
|
|
:root {
|
|
--bg-primary: #f5f5f5;
|
|
--bg-secondary: #ffffff;
|
|
--bg-tertiary: #fafafa;
|
|
--bg-hover: #f5f5f5;
|
|
--bg-active: #e6f7ff;
|
|
--text-primary: #333333;
|
|
--text-secondary: #666666;
|
|
--text-tertiary: #999999;
|
|
--border-color: #e0e0e0;
|
|
--border-light: #e0e0e0;
|
|
--accent-color: #07c160;
|
|
--accent-hover: #00a86b;
|
|
--error-color: #ff4d4f;
|
|
--success-color: #52c41a;
|
|
--shadow-color: rgba(0, 0, 0, 0.1);
|
|
--shadow-hover: rgba(0, 0, 0, 0.15);
|
|
}
|
|
|
|
body.dark-mode {
|
|
--bg-primary: #1a1a1a;
|
|
--bg-secondary: #2d2d2d;
|
|
--bg-tertiary: #3d3d3d;
|
|
--bg-hover: #4d4d4d;
|
|
--bg-active: #1e3a5f;
|
|
--text-primary: #ffffff;
|
|
--text-secondary: #b8b8b8;
|
|
--text-tertiary: #888888;
|
|
--border-color: #3d3d3d;
|
|
--border-light: #4d4d4d;
|
|
--accent-color: #4caf50;
|
|
--accent-hover: #66bb6a;
|
|
--error-color: #ff7875;
|
|
--success-color: #73d13d;
|
|
--shadow-color: rgba(0, 0, 0, 0.3);
|
|
--shadow-hover: rgba(0, 0, 0, 0.4);
|
|
}
|
|
|
|
/* 管理员面板特定样式 */
|
|
body {
|
|
background-color: var(--bg-primary);
|
|
color: var(--text-primary);
|
|
transition: background-color 0.3s ease, color 0.3s ease;
|
|
}
|
|
|
|
.admin-container {
|
|
max-width: 1200px;
|
|
margin: 20px auto;
|
|
background-color: var(--bg-secondary);
|
|
border-radius: 10px;
|
|
box-shadow: 0 2px 10px var(--shadow-color);
|
|
overflow: hidden;
|
|
}
|
|
|
|
.admin-header {
|
|
background: var(--accent-color);
|
|
color: white;
|
|
padding: 20px;
|
|
text-align: center;
|
|
}
|
|
|
|
.admin-header h1 {
|
|
margin: 0;
|
|
font-size: 24px;
|
|
font-weight: bold;
|
|
}
|
|
|
|
.admin-body {
|
|
padding: 20px;
|
|
}
|
|
|
|
.admin-section {
|
|
margin-bottom: 30px;
|
|
}
|
|
|
|
.admin-section h2 {
|
|
color: var(--text-primary);
|
|
margin-bottom: 20px;
|
|
padding-bottom: 10px;
|
|
border-bottom: 1px solid var(--border-color);
|
|
font-size: 18px;
|
|
}
|
|
|
|
.user-table {
|
|
width: 100%;
|
|
border-collapse: collapse;
|
|
margin-top: 10px;
|
|
}
|
|
|
|
.user-table th,
|
|
.user-table td {
|
|
padding: 12px;
|
|
text-align: left;
|
|
border-bottom: 1px solid var(--border-color);
|
|
color: var(--text-primary);
|
|
}
|
|
|
|
.user-table th {
|
|
background-color: var(--bg-tertiary);
|
|
font-weight: bold;
|
|
color: var(--text-primary);
|
|
}
|
|
|
|
.user-table tr:hover {
|
|
background-color: var(--bg-hover);
|
|
}
|
|
|
|
.form-container {
|
|
margin-top: 20px;
|
|
padding: 20px;
|
|
border: 1px solid var(--border-color);
|
|
border-radius: 8px;
|
|
background: var(--bg-tertiary);
|
|
}
|
|
|
|
.form-group {
|
|
margin-bottom: 15px;
|
|
}
|
|
|
|
.form-group label {
|
|
display: block;
|
|
margin-bottom: 8px;
|
|
color: var(--text-primary);
|
|
font-weight: 500;
|
|
}
|
|
|
|
.form-group input,
|
|
.form-group select,
|
|
.form-group textarea {
|
|
width: 100%;
|
|
padding: 12px 15px;
|
|
border: 1px solid var(--border-color);
|
|
border-radius: 25px;
|
|
font-size: 14px;
|
|
background: var(--bg-secondary);
|
|
color: var(--text-primary);
|
|
box-sizing: border-box;
|
|
transition: all 0.3s ease;
|
|
}
|
|
|
|
.form-group input:focus,
|
|
.form-group select:focus,
|
|
.form-group textarea:focus {
|
|
outline: none;
|
|
border-color: var(--accent-color);
|
|
box-shadow: 0 0 0 2px rgba(7, 193, 96, 0.1);
|
|
}
|
|
|
|
.admin-actions {
|
|
margin-top: 20px;
|
|
display: flex;
|
|
gap: 10px;
|
|
}
|
|
|
|
.back-btn {
|
|
display: inline-block;
|
|
margin-top: 20px;
|
|
padding: 10px 20px;
|
|
background-color: #666;
|
|
color: white;
|
|
text-decoration: none;
|
|
border-radius: 5px;
|
|
transition: all 0.3s ease;
|
|
}
|
|
|
|
.back-btn:hover {
|
|
background-color: #555;
|
|
}
|
|
|
|
/* 状态徽章样式 */
|
|
.status-badge {
|
|
padding: 4px 10px;
|
|
border-radius: 12px;
|
|
font-size: 12px;
|
|
font-weight: bold;
|
|
}
|
|
|
|
.admin-badge {
|
|
background-color: var(--accent-color);
|
|
color: white;
|
|
}
|
|
|
|
.user-badge {
|
|
background-color: #1890ff;
|
|
color: white;
|
|
}
|
|
|
|
.banned-badge {
|
|
background-color: var(--error-color);
|
|
color: white;
|
|
}
|
|
|
|
.active-badge {
|
|
background-color: var(--success-color);
|
|
color: white;
|
|
}
|
|
|
|
/* 操作按钮样式 */
|
|
.ban-btn {
|
|
background-color: var(--error-color);
|
|
color: white;
|
|
}
|
|
|
|
.ban-btn:hover {
|
|
opacity: 0.8;
|
|
}
|
|
|
|
.unban-btn {
|
|
background-color: var(--success-color);
|
|
color: white;
|
|
}
|
|
|
|
.unban-btn:hover {
|
|
opacity: 0.8;
|
|
}
|
|
|
|
.edit-btn {
|
|
background-color: #1890ff;
|
|
color: white;
|
|
}
|
|
|
|
.edit-btn:hover {
|
|
opacity: 0.8;
|
|
}
|
|
|
|
.submit-btn {
|
|
padding: 10px 20px;
|
|
border: none;
|
|
border-radius: 5px;
|
|
font-size: 14px;
|
|
cursor: pointer;
|
|
transition: all 0.3s ease;
|
|
margin-right: 10px;
|
|
}
|
|
|
|
.submit-btn:hover {
|
|
opacity: 0.9;
|
|
}
|
|
|
|
/* 主题切换按钮 */
|
|
.theme-toggle-btn {
|
|
position: fixed;
|
|
top: 20px;
|
|
right: 20px;
|
|
width: 40px;
|
|
height: 40px;
|
|
border-radius: 50%;
|
|
background: var(--bg-secondary);
|
|
border: 1px solid var(--border-color);
|
|
color: var(--text-primary);
|
|
font-size: 18px;
|
|
cursor: pointer;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
box-shadow: 0 2px 8px var(--shadow-color);
|
|
transition: all 0.3s ease;
|
|
z-index: 1000;
|
|
}
|
|
|
|
.theme-toggle-btn:hover {
|
|
transform: scale(1.1);
|
|
box-shadow: 0 4px 12px var(--shadow-hover);
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<button class="theme-toggle-btn" id="theme-toggle-btn">
|
|
<i class="fas fa-moon"></i>
|
|
</button>
|
|
|
|
<div class="admin-container">
|
|
<div class="admin-header">
|
|
<h1>管理员面板</h1>
|
|
</div>
|
|
|
|
<div class="admin-body">
|
|
<div class="admin-section">
|
|
<h2>用户管理</h2>
|
|
<table class="user-table">
|
|
<thead>
|
|
<tr>
|
|
<th>ID</th>
|
|
<th>用户名</th>
|
|
<th>注册时间</th>
|
|
<th>最后登录</th>
|
|
<th>状态</th>
|
|
<th>角色</th>
|
|
<th>操作</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($users as $user): ?>
|
|
<tr>
|
|
<td><?php echo htmlspecialchars($user['id']); ?></td>
|
|
<td><?php echo htmlspecialchars($user['username']); ?></td>
|
|
<td><?php echo date('Y-m-d H:i:s', $user['created_at']); ?></td>
|
|
<td><?php echo date('Y-m-d H:i:s', $user['last_login']); ?></td>
|
|
<td>
|
|
<span class="status-badge <?php echo $user['is_banned'] ? 'banned-badge' : 'active-badge'; ?>">
|
|
<?php echo $user['is_banned'] ? '已封禁' : '活跃'; ?>
|
|
</span>
|
|
</td>
|
|
<td>
|
|
<span class="status-badge <?php echo $user['is_admin'] ? 'admin-badge' : 'user-badge'; ?>">
|
|
<?php echo $user['is_admin'] ? '管理员' : '用户'; ?>
|
|
</span>
|
|
</td>
|
|
<td>
|
|
<?php if (!$user['is_admin']): ?>
|
|
<?php if (!$user['is_banned']): ?>
|
|
<form method="post" style="display: inline;">
|
|
<input type="hidden" name="action" value="ban">
|
|
<input type="hidden" name="user_id" value="<?php echo $user['id']; ?>">
|
|
<button type="submit" class="btn btn-sm ban-btn" onclick="return confirm('确定要封禁该用户吗?');">封禁</button>
|
|
</form>
|
|
<?php else: ?>
|
|
<form method="post" style="display: inline;">
|
|
<input type="hidden" name="action" value="unban">
|
|
<input type="hidden" name="user_id" value="<?php echo $user['id']; ?>">
|
|
<button type="submit" class="btn btn-sm unban-btn" onclick="return confirm('确定要解除封禁该用户吗?');">解除封禁</button>
|
|
</form>
|
|
<?php endif; ?>
|
|
|
|
<button class="btn btn-sm edit-btn" onclick="showEditForm('<?php echo $user['id']; ?>', '<?php echo htmlspecialchars($user['username']); ?>', '<?php echo $user['is_admin']; ?>');">编辑</button>
|
|
<?php endif; ?>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
|
|
<!-- 编辑用户表单 -->
|
|
<div id="edit-form" class="form-container" style="display: none;">
|
|
<h3>编辑用户</h3>
|
|
<form method="post">
|
|
<input type="hidden" name="user_id" id="edit-user-id">
|
|
|
|
<div class="form-group">
|
|
<label for="new_username">新用户名</label>
|
|
<input type="text" name="new_username" id="new_username" required>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="new_password">新密码(留空则不修改)</label>
|
|
<input type="password" name="new_password" id="new_password">
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="is_admin">管理员权限</label>
|
|
<select name="is_admin" id="is_admin">
|
|
<option value="0">普通用户</option>
|
|
<option value="1">管理员</option>
|
|
</select>
|
|
</div>
|
|
|
|
<div class="admin-actions">
|
|
<button type="submit" name="action" value="change_username" class="btn btn-primary">修改用户名</button>
|
|
<button type="submit" name="action" value="change_password" class="btn btn-primary">修改密码</button>
|
|
<button type="submit" name="action" value="set_admin" class="btn btn-primary">设置权限</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="admin-section">
|
|
<h2>举报管理</h2>
|
|
<div class="report-list">
|
|
<table class="user-table">
|
|
<thead>
|
|
<tr>
|
|
<th>举报ID</th>
|
|
<th>被举报消息</th>
|
|
<th>举报人</th>
|
|
<th>举报原因</th>
|
|
<th>举报时间</th>
|
|
<th>状态</th>
|
|
<th>操作</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody id="report-list-body">
|
|
<!-- 举报列表将通过JavaScript动态加载 -->
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="admin-section">
|
|
<h2>系统公告</h2>
|
|
<div class="form-container">
|
|
<h3>发布平台通知</h3>
|
|
<form method="post">
|
|
<input type="hidden" name="action" value="publish_announcement">
|
|
|
|
<div class="form-group">
|
|
<label for="announcement_title">标题</label>
|
|
<input type="text" name="announcement_title" id="announcement_title" required>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="announcement_content">内容</label>
|
|
<textarea name="announcement_content" id="announcement_content" rows="6" style="width: 100%; padding: 12px 15px; border: 1px solid #ddd; border-radius: 25px; font-size: 14px; box-sizing: border-box; transition: all 0.3s ease; resize: vertical;"></textarea>
|
|
</div>
|
|
|
|
<div class="admin-actions">
|
|
<button type="submit" class="btn btn-primary" onclick="return confirm('确定要发布此系统公告吗?将发送给所有用户。');">发布公告</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
<a href="../index.php" class="btn btn-secondary">返回主页</a>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
function showEditForm(userId, username, isAdmin) {
|
|
document.getElementById('edit-user-id').value = userId;
|
|
document.getElementById('new_username').value = username;
|
|
document.getElementById('is_admin').value = isAdmin;
|
|
document.getElementById('edit-form').style.display = 'block';
|
|
}
|
|
|
|
// 加载举报列表
|
|
function loadReports() {
|
|
fetch('../api.php?action=getReports')
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
if (data.success) {
|
|
const reportListBody = document.getElementById('report-list-body');
|
|
reportListBody.innerHTML = '';
|
|
|
|
data.reports.forEach(item => {
|
|
const report = item.report;
|
|
const message = item.message;
|
|
const reporter = item.reporter;
|
|
|
|
const row = document.createElement('tr');
|
|
row.innerHTML = `
|
|
<td>${report.id}</td>
|
|
<td>
|
|
<div>${message ? message.content.substring(0, 50) + (message.content.length > 50 ? '...' : '') : '消息已删除'}</div>
|
|
<div style="font-size: 12px; color: #666;">发送者: ${message && message.sender_info ? message.sender_info.username : '未知'}</div>
|
|
</td>
|
|
<td>${reporter ? reporter.username : '未知'}</td>
|
|
<td>${report.reason || '无'}</td>
|
|
<td>${new Date(report.created_at * 1000).toLocaleString()}</td>
|
|
<td>
|
|
<span class="status-badge ${report.status === 'pending' ? 'active-badge' : report.status === 'deleted' ? 'banned-badge' : 'user-badge'}">
|
|
${report.status === 'pending' ? '待处理' : report.status === 'deleted' ? '已删除' : '已忽略'}
|
|
</span>
|
|
</td>
|
|
<td>
|
|
${report.status === 'pending' ? `
|
|
<form method="post" style="display: inline;">
|
|
<input type="hidden" name="action" value="process_report">
|
|
<input type="hidden" name="report_id" value="${report.id}">
|
|
<input type="hidden" name="action_type" value="deleted">
|
|
<button type="submit" class="btn btn-sm ban-btn" onclick="return confirm('确定要删除这条消息吗?');">删除消息</button>
|
|
</form>
|
|
<form method="post" style="display: inline;">
|
|
<input type="hidden" name="action" value="process_report">
|
|
<input type="hidden" name="report_id" value="${report.id}">
|
|
<input type="hidden" name="action_type" value="ignored">
|
|
<button type="submit" class="btn btn-sm edit-btn" onclick="return confirm('确定要忽略这个举报吗?');">忽略</button>
|
|
</form>
|
|
` : ''}
|
|
</td>
|
|
`;
|
|
reportListBody.appendChild(row);
|
|
});
|
|
}
|
|
})
|
|
.catch(error => {
|
|
console.error('加载举报列表失败:', error);
|
|
});
|
|
}
|
|
|
|
// 页面加载时加载举报列表
|
|
window.onload = function() {
|
|
loadReports();
|
|
initThemeToggle();
|
|
};
|
|
|
|
// 主题切换功能
|
|
function initThemeToggle() {
|
|
const themeToggleBtn = document.getElementById('theme-toggle-btn');
|
|
const themeIcon = themeToggleBtn.querySelector('i');
|
|
|
|
// 从localStorage读取主题设置
|
|
const savedTheme = localStorage.getItem('theme');
|
|
if (savedTheme === 'dark') {
|
|
document.body.classList.add('dark-mode');
|
|
themeIcon.classList.remove('fa-moon');
|
|
themeIcon.classList.add('fa-sun');
|
|
}
|
|
|
|
// 点击切换主题
|
|
themeToggleBtn.addEventListener('click', function() {
|
|
document.body.classList.toggle('dark-mode');
|
|
const isDark = document.body.classList.contains('dark-mode');
|
|
|
|
if (isDark) {
|
|
themeIcon.classList.remove('fa-moon');
|
|
themeIcon.classList.add('fa-sun');
|
|
localStorage.setItem('theme', 'dark');
|
|
} else {
|
|
themeIcon.classList.remove('fa-sun');
|
|
themeIcon.classList.add('fa-moon');
|
|
localStorage.setItem('theme', 'light');
|
|
}
|
|
});
|
|
}
|
|
</script>
|
|
</body>
|
|
</html>
|