Initial commit: Flutter 无书应用项目
This commit is contained in:
276
ht/admin/index.php
Normal file
276
ht/admin/index.php
Normal file
@@ -0,0 +1,276 @@
|
||||
<?php
|
||||
|
||||
// 引入必要文件
|
||||
require_once '../inc/pubs.php';
|
||||
require_once '../inc/sqls.php';
|
||||
|
||||
// 验证管理员权限
|
||||
if (!checkAdmin()) {
|
||||
header('Location: ../login.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
// 获取当前用户
|
||||
$user = $_SESSION['user'];
|
||||
|
||||
// 实例化数据库操作类
|
||||
$db = new DB();
|
||||
|
||||
// 统计数据
|
||||
// 1. 用户总数
|
||||
$totalUsers = $db->count('users');
|
||||
// 2. 投票主题总数
|
||||
$totalTopics = $db->count('vote');
|
||||
// 3. 进行中的投票数
|
||||
$now = date('Y-m-d H:i:s');
|
||||
$activeTopics = $db->count('vote', "status = 1 AND statime <= '$now' AND endtime >= '$now'");
|
||||
// 4. 总投票记录数
|
||||
$totalVotes = $db->count('recs');
|
||||
|
||||
// 最近投票记录
|
||||
$recentVotes = [];
|
||||
$sql = "SELECT r.*, u.username, v.title
|
||||
FROM " . $db->table('recs') . " r
|
||||
LEFT JOIN " . $db->table('users') . " u ON r.user_id = u.id
|
||||
LEFT JOIN " . $db->table('vote') . " v ON r.topic_id = v.id
|
||||
ORDER BY r.vote_time DESC LIMIT 10";
|
||||
$result = $db->query($sql);
|
||||
if ($result) {
|
||||
while ($row = $result->fetch_assoc()) {
|
||||
$recentVotes[] = $row;
|
||||
}
|
||||
}
|
||||
|
||||
// 最近操作日志
|
||||
$recentLogs = [];
|
||||
$sql = "SELECT l.*, u.username
|
||||
FROM " . $db->table('logs') . " l
|
||||
LEFT JOIN " . $db->table('users') . " u ON l.user_id = u.id
|
||||
ORDER BY l.logtime DESC LIMIT 10";
|
||||
$result = $db->query($sql);
|
||||
if ($result) {
|
||||
while ($row = $result->fetch_assoc()) {
|
||||
$recentLogs[] = $row;
|
||||
}
|
||||
}
|
||||
|
||||
// 页面标题
|
||||
$pageTitle = "管理后台";
|
||||
?>
|
||||
<!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 $pageTitle; ?> - <?php echo getSiteTitle(); ?></title>
|
||||
<link rel="stylesheet" href="../inc/css.css">
|
||||
<style>
|
||||
.admin-container {
|
||||
display: flex;
|
||||
min-height: calc(100vh - 60px);
|
||||
}
|
||||
|
||||
.admin-sidebar {
|
||||
width: 200px;
|
||||
background-color: #2c3e50;
|
||||
color: #fff;
|
||||
padding-top: 20px;
|
||||
}
|
||||
|
||||
.admin-menu {
|
||||
list-style: none;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.admin-menu-item {
|
||||
padding: 12px 20px;
|
||||
border-bottom: 1px solid #34495e;
|
||||
}
|
||||
|
||||
.admin-menu-item a {
|
||||
color: #fff;
|
||||
text-decoration: none;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.admin-menu-item:hover {
|
||||
background-color: #34495e;
|
||||
}
|
||||
|
||||
.admin-menu-item.active {
|
||||
background-color: #3498db;
|
||||
}
|
||||
|
||||
.admin-content {
|
||||
flex: 1;
|
||||
padding: 20px;
|
||||
background-color: #f5f5f5;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.admin-header {
|
||||
margin-bottom: 20px;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.stats-container {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
|
||||
gap: 20px;
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
|
||||
.stat-card {
|
||||
background-color: #fff;
|
||||
border-radius: 5px;
|
||||
padding: 20px;
|
||||
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.stat-value {
|
||||
font-size: 36px;
|
||||
font-weight: bold;
|
||||
color: #3498db;
|
||||
margin: 10px 0;
|
||||
}
|
||||
|
||||
.stat-label {
|
||||
color: #7f8c8d;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.table-container {
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<!-- 顶部导航 -->
|
||||
<header class="header">
|
||||
<div class="header-container">
|
||||
<div class="logo"><?php echo getSiteTitle(); ?> - 管理后台</div>
|
||||
<nav class="nav">
|
||||
<a href="../index.php" class="nav-item">前台首页</a>
|
||||
<a href="../api/user.php?act=logout" class="nav-item">退出登录</a>
|
||||
</nav>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<!-- 管理内容 -->
|
||||
<div class="admin-container">
|
||||
<!-- 侧边栏 -->
|
||||
<div class="admin-sidebar">
|
||||
<ul class="admin-menu">
|
||||
<li class="admin-menu-item active"><a href="index.php">系统概况</a></li>
|
||||
<li class="admin-menu-item"><a href="topic.php">投票管理</a></li>
|
||||
<li class="admin-menu-item"><a href="user.php">用户管理</a></li>
|
||||
<li class="admin-menu-item"><a href="stat.php">数据统计</a></li>
|
||||
<li class="admin-menu-item"><a href="logs.php">系统日志</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<!-- 主体内容 -->
|
||||
<div class="admin-content">
|
||||
<div class="admin-header">
|
||||
<h2>系统概况</h2>
|
||||
<div>
|
||||
<span>欢迎您,<?php echo htmlspecialchars($user['username']); ?></span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 统计卡片 -->
|
||||
<div class="stats-container">
|
||||
<div class="stat-card">
|
||||
<div class="stat-value"><?php echo $totalUsers; ?></div>
|
||||
<div class="stat-label">用户总数</div>
|
||||
</div>
|
||||
|
||||
<div class="stat-card">
|
||||
<div class="stat-value"><?php echo $totalTopics; ?></div>
|
||||
<div class="stat-label">投票主题总数</div>
|
||||
</div>
|
||||
|
||||
<div class="stat-card">
|
||||
<div class="stat-value"><?php echo $activeTopics; ?></div>
|
||||
<div class="stat-label">进行中的投票</div>
|
||||
</div>
|
||||
|
||||
<div class="stat-card">
|
||||
<div class="stat-value"><?php echo $totalVotes; ?></div>
|
||||
<div class="stat-label">总投票记录数</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 最近投票记录 -->
|
||||
<div class="table-container">
|
||||
<h3>最近投票记录</h3>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>用户</th>
|
||||
<th>投票主题</th>
|
||||
<th>投票时间</th>
|
||||
<th>IP地址</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php if (!empty($recentVotes)): ?>
|
||||
<?php foreach ($recentVotes as $vote): ?>
|
||||
<tr>
|
||||
<td><?php echo htmlspecialchars($vote['username']); ?></td>
|
||||
<td><?php echo htmlspecialchars($vote['title']); ?></td>
|
||||
<td><?php echo date('Y-m-d H:i:s', strtotime($vote['vote_time'])); ?></td>
|
||||
<td><?php echo htmlspecialchars($vote['ip']); ?></td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
<?php else: ?>
|
||||
<tr>
|
||||
<td colspan="4" style="text-align: center;">暂无投票记录</td>
|
||||
</tr>
|
||||
<?php endif; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<!-- 最近操作日志 -->
|
||||
<div class="table-container">
|
||||
<h3>最近操作日志</h3>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>用户</th>
|
||||
<th>操作类型</th>
|
||||
<th>操作内容</th>
|
||||
<th>IP地址</th>
|
||||
<th>时间</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php if (!empty($recentLogs)): ?>
|
||||
<?php foreach ($recentLogs as $log): ?>
|
||||
<tr>
|
||||
<td><?php echo htmlspecialchars($log['username']); ?></td>
|
||||
<td><?php echo htmlspecialchars($log['action']); ?></td>
|
||||
<td><?php echo htmlspecialchars($log['idesc']); ?></td>
|
||||
<td><?php echo htmlspecialchars($log['ip']); ?></td>
|
||||
<td><?php echo date('Y-m-d H:i:s', strtotime($log['logtime'])); ?></td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
<?php else: ?>
|
||||
<tr>
|
||||
<td colspan="5" style="text-align: center;">暂无操作日志</td>
|
||||
</tr>
|
||||
<?php endif; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="../inc/js.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
360
ht/admin/logs.php
Normal file
360
ht/admin/logs.php
Normal file
@@ -0,0 +1,360 @@
|
||||
<?php
|
||||
|
||||
// 引入必要文件
|
||||
require_once '../inc/pubs.php';
|
||||
require_once '../inc/sqls.php';
|
||||
|
||||
// 验证管理员权限
|
||||
if (!checkAdmin()) {
|
||||
header('Location: ../login.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
// 获取当前用户
|
||||
$user = $_SESSION['user'];
|
||||
|
||||
// 实例化数据库操作类
|
||||
$db = new DB();
|
||||
|
||||
// 获取所有用户,用于筛选
|
||||
$users = $db->getAll('users', '', 'id, username', 'id ASC');
|
||||
|
||||
// 获取所有操作类型,用于筛选
|
||||
$sql = "SELECT DISTINCT action FROM " . $db->table('logs');
|
||||
$result = $db->query($sql);
|
||||
$actionTypes = [];
|
||||
|
||||
if ($result) {
|
||||
while ($row = $result->fetch_assoc()) {
|
||||
$actionTypes[] = $row['action'];
|
||||
}
|
||||
}
|
||||
|
||||
// 页面标题
|
||||
$pageTitle = "系统日志";
|
||||
?>
|
||||
<!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 $pageTitle; ?> - <?php echo getSiteTitle(); ?></title>
|
||||
<link rel="stylesheet" href="../inc/css.css">
|
||||
<style>
|
||||
.admin-container {
|
||||
display: flex;
|
||||
min-height: calc(100vh - 60px);
|
||||
}
|
||||
|
||||
.admin-sidebar {
|
||||
width: 200px;
|
||||
background-color: #2c3e50;
|
||||
color: #fff;
|
||||
padding-top: 20px;
|
||||
}
|
||||
|
||||
.admin-menu {
|
||||
list-style: none;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.admin-menu-item {
|
||||
padding: 12px 20px;
|
||||
border-bottom: 1px solid #34495e;
|
||||
}
|
||||
|
||||
.admin-menu-item a {
|
||||
color: #fff;
|
||||
text-decoration: none;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.admin-menu-item:hover {
|
||||
background-color: #34495e;
|
||||
}
|
||||
|
||||
.admin-menu-item.active {
|
||||
background-color: #3498db;
|
||||
}
|
||||
|
||||
.admin-content {
|
||||
flex: 1;
|
||||
padding: 20px;
|
||||
background-color: #f5f5f5;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.admin-header {
|
||||
margin-bottom: 20px;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.filter-form {
|
||||
margin-bottom: 20px;
|
||||
padding: 15px;
|
||||
background-color: #fff;
|
||||
border-radius: 5px;
|
||||
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.logs-container {
|
||||
background-color: #fff;
|
||||
border-radius: 5px;
|
||||
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
|
||||
padding: 20px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.export-btn {
|
||||
margin-left: 10px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<!-- 顶部导航 -->
|
||||
<header class="header">
|
||||
<div class="header-container">
|
||||
<div class="logo"><?php echo getSiteTitle(); ?> - 管理后台</div>
|
||||
<nav class="nav">
|
||||
<a href="../index.php" class="nav-item">前台首页</a>
|
||||
<a href="../api/user.php?act=logout" class="nav-item">退出登录</a>
|
||||
</nav>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<!-- 管理内容 -->
|
||||
<div class="admin-container">
|
||||
<!-- 侧边栏 -->
|
||||
<div class="admin-sidebar">
|
||||
<ul class="admin-menu">
|
||||
<li class="admin-menu-item"><a href="index.php">系统概况</a></li>
|
||||
<li class="admin-menu-item"><a href="topic.php">投票管理</a></li>
|
||||
<li class="admin-menu-item"><a href="user.php">用户管理</a></li>
|
||||
<li class="admin-menu-item"><a href="stat.php">数据统计</a></li>
|
||||
<li class="admin-menu-item active"><a href="logs.php">系统日志</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<!-- 主体内容 -->
|
||||
<div class="admin-content">
|
||||
<div class="admin-header">
|
||||
<h2>系统日志</h2>
|
||||
<div>
|
||||
<button class="btn btn-blue" id="exportBtn">导出日志</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 筛选表单 -->
|
||||
<div class="filter-form">
|
||||
<form id="filterForm">
|
||||
<div style="display: flex; gap: 15px; flex-wrap: wrap; align-items: flex-end;">
|
||||
<div>
|
||||
<label for="user_id">用户:</label>
|
||||
<select id="user_id" name="user_id" class="form-control">
|
||||
<option value="0">全部用户</option>
|
||||
<?php foreach ($users as $userData): ?>
|
||||
<option value="<?php echo $userData['id']; ?>"><?php echo htmlspecialchars($userData['username']); ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label for="action">操作类型:</label>
|
||||
<select id="action" name="action" class="form-control">
|
||||
<option value="">全部操作</option>
|
||||
<?php foreach ($actionTypes as $actionType): ?>
|
||||
<option value="<?php echo $actionType; ?>"><?php echo htmlspecialchars($actionType); ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label for="start_date">开始日期:</label>
|
||||
<input type="date" id="start_date" name="start_date" class="form-control">
|
||||
</div>
|
||||
<div>
|
||||
<label for="end_date">结束日期:</label>
|
||||
<input type="date" id="end_date" name="end_date" class="form-control">
|
||||
</div>
|
||||
<div>
|
||||
<button type="button" id="searchBtn" class="btn btn-blue">搜索</button>
|
||||
<button type="button" id="resetBtn" class="btn btn-gray">重置</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<!-- 日志列表 -->
|
||||
<div class="logs-container">
|
||||
<div id="logsTable" class="table-container">
|
||||
<div style="text-align: center; padding: 20px;">加载中...</div>
|
||||
</div>
|
||||
|
||||
<!-- 分页 -->
|
||||
<div class="pagination" id="pagination"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="../inc/js.js"></script>
|
||||
<script>
|
||||
// 当前页码
|
||||
var currentPage = 1;
|
||||
|
||||
// 页面加载完成后加载日志
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
loadLogs(1);
|
||||
});
|
||||
|
||||
// 搜索按钮点击事件
|
||||
document.getElementById('searchBtn').addEventListener('click', function() {
|
||||
loadLogs(1);
|
||||
});
|
||||
|
||||
// 重置按钮点击事件
|
||||
document.getElementById('resetBtn').addEventListener('click', function() {
|
||||
document.getElementById('filterForm').reset();
|
||||
loadLogs(1);
|
||||
});
|
||||
|
||||
// 导出按钮点击事件
|
||||
document.getElementById('exportBtn').addEventListener('click', function() {
|
||||
exportLogs();
|
||||
});
|
||||
|
||||
// 加载日志数据
|
||||
function loadLogs(page) {
|
||||
currentPage = page;
|
||||
|
||||
// 获取筛选参数
|
||||
var userId = document.getElementById('user_id').value;
|
||||
var action = document.getElementById('action').value;
|
||||
var startDate = document.getElementById('start_date').value;
|
||||
var endDate = document.getElementById('end_date').value;
|
||||
|
||||
// 显示加载中
|
||||
document.getElementById('logsTable').innerHTML = '<div style="text-align: center; padding: 20px;">加载中...</div>';
|
||||
|
||||
// 发送请求获取日志数据
|
||||
ajaxRequest('../api/admin.php', {
|
||||
act: 'getLogs',
|
||||
page: page,
|
||||
page_size: 20,
|
||||
user_id: userId,
|
||||
action: action,
|
||||
start_date: startDate,
|
||||
end_date: endDate
|
||||
}, function(response) {
|
||||
if (response.code === 0) {
|
||||
displayLogs(response.data);
|
||||
} else {
|
||||
document.getElementById('logsTable').innerHTML = '<div style="text-align: center; padding: 20px; color: #e74c3c;">加载失败:' + (response.msg || '未知错误') + '</div>';
|
||||
document.getElementById('pagination').innerHTML = '';
|
||||
}
|
||||
}, function(error) {
|
||||
document.getElementById('logsTable').innerHTML = '<div style="text-align: center; padding: 20px; color: #e74c3c;">网络错误,请稍后重试</div>';
|
||||
document.getElementById('pagination').innerHTML = '';
|
||||
});
|
||||
}
|
||||
|
||||
// 显示日志列表
|
||||
function displayLogs(data) {
|
||||
var logs = data.logs;
|
||||
var pagination = data.pagination;
|
||||
|
||||
// 如果没有日志
|
||||
if (logs.length === 0) {
|
||||
document.getElementById('logsTable').innerHTML = '<div style="text-align: center; padding: 20px;">暂无日志数据</div>';
|
||||
document.getElementById('pagination').innerHTML = '';
|
||||
return;
|
||||
}
|
||||
|
||||
// 构建表格HTML
|
||||
var tableHtml = `
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th>用户</th>
|
||||
<th>操作类型</th>
|
||||
<th>操作内容</th>
|
||||
<th>IP地址</th>
|
||||
<th>时间</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
`;
|
||||
|
||||
// 遍历日志数据
|
||||
logs.forEach(function(log) {
|
||||
var logTime = new Date(log.logtime);
|
||||
|
||||
tableHtml += `
|
||||
<tr>
|
||||
<td>${log.id}</td>
|
||||
<td>${log.username || '未知用户'}</td>
|
||||
<td>${log.action}</td>
|
||||
<td>${log.idesc || ''}</td>
|
||||
<td>${log.ip}</td>
|
||||
<td>${formatDateTime(logTime)}</td>
|
||||
</tr>
|
||||
`;
|
||||
});
|
||||
|
||||
tableHtml += `
|
||||
</tbody>
|
||||
</table>
|
||||
`;
|
||||
|
||||
// 更新DOM
|
||||
document.getElementById('logsTable').innerHTML = tableHtml;
|
||||
|
||||
// 初始化分页
|
||||
if (typeof pagination === 'function' && pagination.page !== undefined && pagination.totalPage !== undefined) {
|
||||
pagination('pagination', pagination.page, pagination.totalPage, function(page) {
|
||||
loadLogs(page);
|
||||
});
|
||||
} else {
|
||||
console.error('Pagination data error:', pagination);
|
||||
document.getElementById('pagination').innerHTML = '';
|
||||
}
|
||||
}
|
||||
|
||||
// 导出日志
|
||||
function exportLogs() {
|
||||
// 获取筛选参数
|
||||
var userId = document.getElementById('user_id').value;
|
||||
var action = document.getElementById('action').value;
|
||||
var startDate = document.getElementById('start_date').value;
|
||||
var endDate = document.getElementById('end_date').value;
|
||||
|
||||
// 构建导出URL
|
||||
var exportUrl = '../api/admin.php?act=exportLogs';
|
||||
|
||||
if (userId) exportUrl += '&user_id=' + userId;
|
||||
if (action) exportUrl += '&action=' + encodeURIComponent(action);
|
||||
if (startDate) exportUrl += '&start_date=' + startDate;
|
||||
if (endDate) exportUrl += '&end_date=' + endDate;
|
||||
|
||||
// 跳转到导出URL
|
||||
window.location.href = exportUrl;
|
||||
}
|
||||
|
||||
// 格式化日期时间
|
||||
function formatDateTime(date) {
|
||||
return date.getFullYear() + '-' +
|
||||
padZero(date.getMonth() + 1) + '-' +
|
||||
padZero(date.getDate()) + ' ' +
|
||||
padZero(date.getHours()) + ':' +
|
||||
padZero(date.getMinutes()) + ':' +
|
||||
padZero(date.getSeconds());
|
||||
}
|
||||
|
||||
// 数字补零
|
||||
function padZero(num) {
|
||||
return num < 10 ? '0' + num : num;
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
499
ht/admin/stat.php
Normal file
499
ht/admin/stat.php
Normal file
@@ -0,0 +1,499 @@
|
||||
<?php
|
||||
|
||||
// 引入必要文件
|
||||
require_once '../inc/pubs.php';
|
||||
require_once '../inc/sqls.php';
|
||||
|
||||
// 验证管理员权限
|
||||
if (!checkAdmin()) {
|
||||
header('Location: ../login.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
// 获取当前用户
|
||||
$user = $_SESSION['user'];
|
||||
|
||||
// 实例化数据库操作类
|
||||
$db = new DB();
|
||||
|
||||
// 获取所有投票主题
|
||||
$topics = $db->getAll('vote', '', 'id, title', 'addtime DESC');
|
||||
|
||||
// 页面标题
|
||||
$pageTitle = "数据统计";
|
||||
?>
|
||||
<!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 $pageTitle; ?> - <?php echo getSiteTitle(); ?></title>
|
||||
<link rel="stylesheet" href="../inc/css.css">
|
||||
<style>
|
||||
.admin-container {
|
||||
display: flex;
|
||||
min-height: calc(100vh - 60px);
|
||||
}
|
||||
|
||||
.admin-sidebar {
|
||||
width: 200px;
|
||||
background-color: #2c3e50;
|
||||
color: #fff;
|
||||
padding-top: 20px;
|
||||
}
|
||||
|
||||
.admin-menu {
|
||||
list-style: none;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.admin-menu-item {
|
||||
padding: 12px 20px;
|
||||
border-bottom: 1px solid #34495e;
|
||||
}
|
||||
|
||||
.admin-menu-item a {
|
||||
color: #fff;
|
||||
text-decoration: none;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.admin-menu-item:hover {
|
||||
background-color: #34495e;
|
||||
}
|
||||
|
||||
.admin-menu-item.active {
|
||||
background-color: #3498db;
|
||||
}
|
||||
|
||||
.admin-content {
|
||||
flex: 1;
|
||||
padding: 20px;
|
||||
background-color: #f5f5f5;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.admin-header {
|
||||
margin-bottom: 20px;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.stats-container {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
|
||||
gap: 20px;
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
|
||||
.stat-card {
|
||||
background-color: #fff;
|
||||
border-radius: 5px;
|
||||
padding: 20px;
|
||||
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.stat-value {
|
||||
font-size: 36px;
|
||||
font-weight: bold;
|
||||
color: #3498db;
|
||||
margin: 10px 0;
|
||||
}
|
||||
|
||||
.stat-label {
|
||||
color: #7f8c8d;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.filter-form {
|
||||
margin-bottom: 20px;
|
||||
padding: 15px;
|
||||
background-color: #fff;
|
||||
border-radius: 5px;
|
||||
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.chart-container {
|
||||
background-color: #fff;
|
||||
border-radius: 5px;
|
||||
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
|
||||
padding: 20px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.chart-title {
|
||||
margin-top: 0;
|
||||
margin-bottom: 20px;
|
||||
padding-bottom: 10px;
|
||||
border-bottom: 1px solid #eee;
|
||||
}
|
||||
|
||||
.vote-bar {
|
||||
height: 30px;
|
||||
background-color: #eee;
|
||||
border-radius: 15px;
|
||||
overflow: hidden;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
.vote-bar-fill {
|
||||
height: 100%;
|
||||
background-color: #3498db;
|
||||
border-radius: 15px;
|
||||
}
|
||||
|
||||
.vote-option-row {
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.vote-option-label {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
.vote-option-name {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.participants-container {
|
||||
max-height: 300px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<!-- 顶部导航 -->
|
||||
<header class="header">
|
||||
<div class="header-container">
|
||||
<div class="logo"><?php echo getSiteTitle(); ?> - 管理后台</div>
|
||||
<nav class="nav">
|
||||
<a href="../index.php" class="nav-item">前台首页</a>
|
||||
<a href="../api/user.php?act=logout" class="nav-item">退出登录</a>
|
||||
</nav>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<!-- 管理内容 -->
|
||||
<div class="admin-container">
|
||||
<!-- 侧边栏 -->
|
||||
<div class="admin-sidebar">
|
||||
<ul class="admin-menu">
|
||||
<li class="admin-menu-item"><a href="index.php">系统概况</a></li>
|
||||
<li class="admin-menu-item"><a href="topic.php">投票管理</a></li>
|
||||
<li class="admin-menu-item"><a href="user.php">用户管理</a></li>
|
||||
<li class="admin-menu-item active"><a href="stat.php">数据统计</a></li>
|
||||
<li class="admin-menu-item"><a href="logs.php">系统日志</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<!-- 主体内容 -->
|
||||
<div class="admin-content">
|
||||
<div class="admin-header">
|
||||
<h2>数据统计</h2>
|
||||
</div>
|
||||
|
||||
<!-- 筛选表单 -->
|
||||
<div class="filter-form">
|
||||
<div style="display: flex; gap: 15px; flex-wrap: wrap; align-items: flex-end;">
|
||||
<div>
|
||||
<label for="topic_id">选择投票:</label>
|
||||
<select id="topic_id" class="form-control" style="min-width: 200px;">
|
||||
<option value="0">-- 显示所有投票统计 --</option>
|
||||
<?php foreach ($topics as $topic): ?>
|
||||
<option value="<?php echo $topic['id']; ?>"><?php echo htmlspecialchars($topic['title']); ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<button type="button" id="loadStatsBtn" class="btn btn-blue">加载统计</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 总体统计 -->
|
||||
<div id="overall-stats" class="stats-container">
|
||||
<!-- 由JavaScript填充 -->
|
||||
</div>
|
||||
|
||||
<!-- 详细统计 -->
|
||||
<div id="detailed-stats">
|
||||
<!-- 由JavaScript填充 -->
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="../inc/js.js"></script>
|
||||
<script>
|
||||
// 页面加载完成后加载所有投票统计
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
loadStatistics(0);
|
||||
});
|
||||
|
||||
// 加载统计按钮点击事件
|
||||
document.getElementById('loadStatsBtn').addEventListener('click', function() {
|
||||
var topicId = document.getElementById('topic_id').value;
|
||||
loadStatistics(topicId);
|
||||
});
|
||||
|
||||
// 加载统计数据
|
||||
function loadStatistics(topicId) {
|
||||
// 显示加载中
|
||||
document.getElementById('overall-stats').innerHTML = '<div style="grid-column: 1 / -1; text-align: center; padding: 20px;">加载中...</div>';
|
||||
document.getElementById('detailed-stats').innerHTML = '';
|
||||
|
||||
// 发送请求获取统计数据
|
||||
ajaxRequest('../api/admin.php', {
|
||||
act: 'getVoteStats',
|
||||
topic_id: topicId
|
||||
}, function(response) {
|
||||
if (response.code === 0) {
|
||||
if (topicId > 0) {
|
||||
// 显示单个投票的详细统计
|
||||
displaySingleVoteStats(response.data);
|
||||
} else {
|
||||
// 显示所有投票的总体统计
|
||||
displayOverallStats(response.data);
|
||||
}
|
||||
} else {
|
||||
document.getElementById('overall-stats').innerHTML = '<div style="grid-column: 1 / -1; text-align: center; padding: 20px; color: #e74c3c;">加载失败:' + (response.msg || '未知错误') + '</div>';
|
||||
}
|
||||
}, function(error) {
|
||||
document.getElementById('overall-stats').innerHTML = '<div style="grid-column: 1 / -1; text-align: center; padding: 20px; color: #e74c3c;">网络错误,请稍后重试</div>';
|
||||
});
|
||||
}
|
||||
|
||||
// 显示所有投票的总体统计
|
||||
function displayOverallStats(data) {
|
||||
var voteStats = data.voteStats;
|
||||
var overallStatsHtml = '';
|
||||
var detailedStatsHtml = '';
|
||||
|
||||
// 计算总数据
|
||||
var totalVotes = 0;
|
||||
var totalUsers = 0;
|
||||
var totalViews = 0;
|
||||
var activeVotes = 0;
|
||||
|
||||
voteStats.forEach(function(stat) {
|
||||
totalVotes += parseInt(stat.total_votes);
|
||||
totalUsers += parseInt(stat.user_count);
|
||||
totalViews += parseInt(stat.view_count);
|
||||
|
||||
// 检查投票是否进行中
|
||||
var now = new Date();
|
||||
var startTime = new Date(stat.start_time);
|
||||
var endTime = new Date(stat.end_time);
|
||||
|
||||
if (now >= startTime && now <= endTime) {
|
||||
activeVotes++;
|
||||
}
|
||||
});
|
||||
|
||||
// 总体统计卡片
|
||||
overallStatsHtml += `
|
||||
<div class="stat-card">
|
||||
<div class="stat-value">${voteStats.length}</div>
|
||||
<div class="stat-label">投票总数</div>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<div class="stat-value">${activeVotes}</div>
|
||||
<div class="stat-label">进行中的投票</div>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<div class="stat-value">${totalVotes}</div>
|
||||
<div class="stat-label">总投票数</div>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<div class="stat-value">${totalUsers}</div>
|
||||
<div class="stat-label">参与用户数</div>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<div class="stat-value">${totalViews}</div>
|
||||
<div class="stat-label">总浏览量</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
// 每个投票的统计表格
|
||||
detailedStatsHtml += `
|
||||
<div class="chart-container">
|
||||
<h3 class="chart-title">投票统计列表</h3>
|
||||
<div class="table-container">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th>投票标题</th>
|
||||
<th>开始时间</th>
|
||||
<th>结束时间</th>
|
||||
<th>总票数</th>
|
||||
<th>参与人数</th>
|
||||
<th>浏览量</th>
|
||||
<th>操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
`;
|
||||
|
||||
voteStats.forEach(function(stat) {
|
||||
var startTime = new Date(stat.start_time);
|
||||
var endTime = new Date(stat.end_time);
|
||||
|
||||
detailedStatsHtml += `
|
||||
<tr>
|
||||
<td>${stat.id}</td>
|
||||
<td>${stat.title}</td>
|
||||
<td>${formatDateTime(startTime)}</td>
|
||||
<td>${formatDateTime(endTime)}</td>
|
||||
<td>${stat.total_votes}</td>
|
||||
<td>${stat.user_count}</td>
|
||||
<td>${stat.view_count}</td>
|
||||
<td>
|
||||
<button class="btn btn-blue btn-sm" onclick="loadStatistics(${stat.id})">详细统计</button>
|
||||
<a href="../vote.php?id=${stat.id}" target="_blank" class="btn btn-green btn-sm">查看投票</a>
|
||||
</td>
|
||||
</tr>
|
||||
`;
|
||||
});
|
||||
|
||||
detailedStatsHtml += `
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
// 更新DOM
|
||||
document.getElementById('overall-stats').innerHTML = overallStatsHtml;
|
||||
document.getElementById('detailed-stats').innerHTML = detailedStatsHtml;
|
||||
}
|
||||
|
||||
// 显示单个投票的详细统计
|
||||
function displaySingleVoteStats(data) {
|
||||
var vote = data.vote;
|
||||
var options = data.options;
|
||||
var totalVotes = data.totalVotes;
|
||||
var participants = data.participants;
|
||||
|
||||
var overallStatsHtml = '';
|
||||
var detailedStatsHtml = '';
|
||||
|
||||
// 总体统计卡片
|
||||
overallStatsHtml += `
|
||||
<div class="stat-card">
|
||||
<div class="stat-value">${totalVotes}</div>
|
||||
<div class="stat-label">总投票数</div>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<div class="stat-value">${participants.length}</div>
|
||||
<div class="stat-label">参与用户数</div>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<div class="stat-value">${vote.iview}</div>
|
||||
<div class="stat-label">浏览量</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
// 投票信息
|
||||
detailedStatsHtml += `
|
||||
<div class="chart-container">
|
||||
<h3 class="chart-title">投票信息</h3>
|
||||
<div>
|
||||
<p><strong>投票标题:</strong>${vote.title}</p>
|
||||
<p><strong>投票描述:</strong>${vote.idesc}</p>
|
||||
<p><strong>投票类型:</strong>${vote.itype == 0 ? '单选' : '多选(最多选' + vote.maxtime + '项)'}</p>
|
||||
<p><strong>开始时间:</strong>${formatDateTime(new Date(vote.statime))}</p>
|
||||
<p><strong>结束时间:</strong>${formatDateTime(new Date(vote.endtime))}</p>
|
||||
<p><strong>状态:</strong>${vote.status == 1 ? '正常' : '禁用'}</p>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
// 选项统计
|
||||
detailedStatsHtml += `
|
||||
<div class="chart-container">
|
||||
<h3 class="chart-title">选项统计</h3>
|
||||
<div id="options-chart">
|
||||
`;
|
||||
|
||||
options.forEach(function(option) {
|
||||
detailedStatsHtml += `
|
||||
<div class="vote-option-row">
|
||||
<div class="vote-option-label">
|
||||
<span class="vote-option-name">${option.name}</span>
|
||||
<span>${option.count}票 (${option.percentage}%)</span>
|
||||
</div>
|
||||
<div class="vote-bar">
|
||||
<div class="vote-bar-fill" style="width: ${option.percentage}%"></div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
});
|
||||
|
||||
detailedStatsHtml += `
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
// 参与用户
|
||||
detailedStatsHtml += `
|
||||
<div class="chart-container">
|
||||
<h3 class="chart-title">参与用户(${participants.length}人)</h3>
|
||||
<div class="participants-container">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>用户名</th>
|
||||
<th>投票时间</th>
|
||||
<th>IP地址</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
`;
|
||||
|
||||
participants.forEach(function(participant) {
|
||||
detailedStatsHtml += `
|
||||
<tr>
|
||||
<td>${participant.username}</td>
|
||||
<td>${formatDateTime(new Date(participant.vote_time))}</td>
|
||||
<td>${participant.ip}</td>
|
||||
</tr>
|
||||
`;
|
||||
});
|
||||
|
||||
detailedStatsHtml += `
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div style="margin-top: 20px; text-align: center;">
|
||||
<button class="btn btn-gray btn-lg" onclick="loadStatistics(0)">返回总体统计</button>
|
||||
<a href="../vote.php?id=${vote.id}" target="_blank" class="btn btn-blue btn-lg">查看投票页面</a>
|
||||
</div>
|
||||
`;
|
||||
|
||||
// 更新DOM
|
||||
document.getElementById('overall-stats').innerHTML = overallStatsHtml;
|
||||
document.getElementById('detailed-stats').innerHTML = detailedStatsHtml;
|
||||
}
|
||||
|
||||
// 格式化日期时间
|
||||
function formatDateTime(date) {
|
||||
return date.getFullYear() + '-' +
|
||||
padZero(date.getMonth() + 1) + '-' +
|
||||
padZero(date.getDate()) + ' ' +
|
||||
padZero(date.getHours()) + ':' +
|
||||
padZero(date.getMinutes());
|
||||
}
|
||||
|
||||
// 数字补零
|
||||
function padZero(num) {
|
||||
return num < 10 ? '0' + num : num;
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
420
ht/admin/topic.php
Normal file
420
ht/admin/topic.php
Normal file
@@ -0,0 +1,420 @@
|
||||
<?php
|
||||
|
||||
// 引入必要文件
|
||||
require_once '../inc/pubs.php';
|
||||
require_once '../inc/sqls.php';
|
||||
|
||||
// 验证管理员权限
|
||||
if (!checkAdmin()) {
|
||||
header('Location: ../login.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
// 获取当前用户
|
||||
$user = $_SESSION['user'];
|
||||
|
||||
// 实例化数据库操作类
|
||||
$db = new DB();
|
||||
|
||||
// 获取操作类型
|
||||
$action = isset($_GET['act']) ? $_GET['act'] : 'list';
|
||||
|
||||
// 根据操作类型显示不同页面
|
||||
switch ($action) {
|
||||
// 添加投票页面
|
||||
case 'add':
|
||||
$pageTitle = "添加投票";
|
||||
include 'topic_form.php';
|
||||
break;
|
||||
|
||||
// 编辑投票页面
|
||||
case 'edit':
|
||||
$pageTitle = "编辑投票";
|
||||
$id = isset($_GET['id']) ? intval($_GET['id']) : 0;
|
||||
|
||||
if (!$id) {
|
||||
header('Location: topic.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
// 获取投票信息
|
||||
$vote = $db->getOne('vote', "id = $id");
|
||||
if (!$vote) {
|
||||
header('Location: topic.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
include 'topic_form.php';
|
||||
break;
|
||||
|
||||
// 管理选项页面
|
||||
case 'options':
|
||||
$pageTitle = "管理选项";
|
||||
$id = isset($_GET['id']) ? intval($_GET['id']) : 0;
|
||||
|
||||
if (!$id) {
|
||||
header('Location: topic.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
// 获取投票信息
|
||||
$vote = $db->getOne('vote', "id = $id");
|
||||
if (!$vote) {
|
||||
header('Location: topic.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
// 获取选项列表
|
||||
$options = $db->getAll('xuan', "topic_id = $id", '*', 'sort ASC, id ASC');
|
||||
|
||||
include 'topic_options.php';
|
||||
break;
|
||||
|
||||
// 投票列表页面(默认)
|
||||
default:
|
||||
$pageTitle = "投票管理";
|
||||
|
||||
// 获取分页参数
|
||||
$page = isset($_GET['page']) ? intval($_GET['page']) : 1;
|
||||
$pageSize = 10;
|
||||
|
||||
// 获取筛选参数
|
||||
$status = isset($_GET['status']) ? intval($_GET['status']) : -1;
|
||||
$type = isset($_GET['type']) ? intval($_GET['type']) : -1;
|
||||
$keyword = isset($_GET['keyword']) ? safeFilter($_GET['keyword']) : '';
|
||||
|
||||
// 构建查询条件
|
||||
$whereConditions = [];
|
||||
if ($status >= 0) {
|
||||
$whereConditions[] = "status = $status";
|
||||
}
|
||||
if ($type >= 0) {
|
||||
$whereConditions[] = "itype = $type";
|
||||
}
|
||||
if ($keyword) {
|
||||
$whereConditions[] = "(title LIKE '%$keyword%' OR idesc LIKE '%$keyword%')";
|
||||
}
|
||||
|
||||
$whereStr = !empty($whereConditions) ? implode(' AND ', $whereConditions) : '';
|
||||
|
||||
// 获取总记录数
|
||||
$total = $db->count('vote', $whereStr);
|
||||
|
||||
// 计算分页信息
|
||||
$pagination = getPagination($total, $page, $pageSize);
|
||||
|
||||
// 获取投票列表
|
||||
$orderBy = "addtime DESC";
|
||||
$limit = "{$pagination['offset']}, {$pagination['pageSize']}";
|
||||
$voteList = $db->getAll('vote', $whereStr, '*', $orderBy, $limit);
|
||||
|
||||
// 页面标题
|
||||
$pageTitle = "投票管理";
|
||||
?>
|
||||
<!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 $pageTitle; ?> - <?php echo getSiteTitle(); ?></title>
|
||||
<link rel="stylesheet" href="../inc/css.css">
|
||||
<style>
|
||||
.admin-container {
|
||||
display: flex;
|
||||
min-height: calc(100vh - 60px);
|
||||
}
|
||||
|
||||
.admin-sidebar {
|
||||
width: 200px;
|
||||
background-color: #2c3e50;
|
||||
color: #fff;
|
||||
padding-top: 20px;
|
||||
}
|
||||
|
||||
.admin-menu {
|
||||
list-style: none;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.admin-menu-item {
|
||||
padding: 12px 20px;
|
||||
border-bottom: 1px solid #34495e;
|
||||
}
|
||||
|
||||
.admin-menu-item a {
|
||||
color: #fff;
|
||||
text-decoration: none;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.admin-menu-item:hover {
|
||||
background-color: #34495e;
|
||||
}
|
||||
|
||||
.admin-menu-item.active {
|
||||
background-color: #3498db;
|
||||
}
|
||||
|
||||
.admin-content {
|
||||
flex: 1;
|
||||
padding: 20px;
|
||||
background-color: #f5f5f5;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.admin-header {
|
||||
margin-bottom: 20px;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.filter-form {
|
||||
margin-bottom: 20px;
|
||||
padding: 15px;
|
||||
background-color: #fff;
|
||||
border-radius: 5px;
|
||||
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.operation-btns {
|
||||
display: flex;
|
||||
gap: 5px;
|
||||
}
|
||||
|
||||
.vote-status {
|
||||
display: inline-block;
|
||||
padding: 3px 8px;
|
||||
border-radius: 3px;
|
||||
color: #fff;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.vote-status-active {
|
||||
background-color: #2ecc71;
|
||||
}
|
||||
|
||||
.vote-status-pending {
|
||||
background-color: #f39c12;
|
||||
}
|
||||
|
||||
.vote-status-ended {
|
||||
background-color: #95a5a6;
|
||||
}
|
||||
|
||||
.vote-status-disabled {
|
||||
background-color: #e74c3c;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<!-- 顶部导航 -->
|
||||
<header class="header">
|
||||
<div class="header-container">
|
||||
<div class="logo"><?php echo getSiteTitle(); ?> - 管理后台</div>
|
||||
<nav class="nav">
|
||||
<a href="../index.php" class="nav-item">前台首页</a>
|
||||
<a href="../api/user.php?act=logout" class="nav-item">退出登录</a>
|
||||
</nav>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<!-- 管理内容 -->
|
||||
<div class="admin-container">
|
||||
<!-- 侧边栏 -->
|
||||
<div class="admin-sidebar">
|
||||
<ul class="admin-menu">
|
||||
<li class="admin-menu-item"><a href="index.php">系统概况</a></li>
|
||||
<li class="admin-menu-item active"><a href="topic.php">投票管理</a></li>
|
||||
<li class="admin-menu-item"><a href="user.php">用户管理</a></li>
|
||||
<li class="admin-menu-item"><a href="stat.php">数据统计</a></li>
|
||||
<li class="admin-menu-item"><a href="logs.php">系统日志</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<!-- 主体内容 -->
|
||||
<div class="admin-content">
|
||||
<div class="admin-header" style="height:40px;">
|
||||
</div>
|
||||
|
||||
<!-- 筛选表单 -->
|
||||
<div class="filter-form">
|
||||
<form action="topic.php" method="get">
|
||||
<div style="display: flex; gap: 15px; flex-wrap: wrap; align-items: flex-end;">
|
||||
<div>
|
||||
<label for="keyword">关键词:</label>
|
||||
<input type="text" name="keyword" id="keyword" class="form-control" value="<?php echo htmlspecialchars($keyword); ?>" placeholder="标题或描述">
|
||||
</div>
|
||||
<div>
|
||||
<label for="status">状态:</label>
|
||||
<select name="status" id="status" class="form-control">
|
||||
<option value="-1">全部</option>
|
||||
<option value="1" <?php echo $status == 1 ? 'selected' : ''; ?>>正常</option>
|
||||
<option value="0" <?php echo $status === 0 ? 'selected' : ''; ?>>禁用</option>
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label for="type">类型:</label>
|
||||
<select name="type" id="type" class="form-control">
|
||||
<option value="-1">全部</option>
|
||||
<option value="0" <?php echo $type === 0 ? 'selected' : ''; ?>>单选</option>
|
||||
<option value="1" <?php echo $type == 1 ? 'selected' : ''; ?>>多选</option>
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<button type="submit" class="btn btn-blue">搜索</button>
|
||||
<a href="topic.php" class="btn btn-gray">重置</a>
|
||||
<a href="topic.php?act=add" class="btn btn-green">添加投票</a>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<!-- 投票列表 -->
|
||||
<div class="table-container">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th>标题</th>
|
||||
<th>类型</th>
|
||||
<th>开始时间</th>
|
||||
<th>结束时间</th>
|
||||
<th>状态</th>
|
||||
<th>浏览量</th>
|
||||
<th>创建时间</th>
|
||||
<th>操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php if (!empty($voteList)): ?>
|
||||
<?php foreach ($voteList as $vote):
|
||||
// 确定投票状态
|
||||
$now = date('Y-m-d H:i:s');
|
||||
$voteStatus = '';
|
||||
$statusClass = '';
|
||||
|
||||
if ($vote['status'] == 0) {
|
||||
$voteStatus = '已禁用';
|
||||
$statusClass = 'vote-status-disabled';
|
||||
} else {
|
||||
if ($vote['statime'] > $now) {
|
||||
$voteStatus = '未开始';
|
||||
$statusClass = 'vote-status-pending';
|
||||
} elseif ($vote['endtime'] < $now) {
|
||||
$voteStatus = '已结束';
|
||||
$statusClass = 'vote-status-ended';
|
||||
} else {
|
||||
$voteStatus = '进行中';
|
||||
$statusClass = 'vote-status-active';
|
||||
}
|
||||
}
|
||||
?>
|
||||
<tr>
|
||||
<td><?php echo $vote['id']; ?></td>
|
||||
<td><?php echo htmlspecialchars($vote['title']); ?></td>
|
||||
<td><?php echo $vote['itype'] == 0 ? '单选' : "多选({$vote['maxtime']}项)"; ?></td>
|
||||
<td><?php echo date('Y-m-d H:i', strtotime($vote['statime'])); ?></td>
|
||||
<td><?php echo date('Y-m-d H:i', strtotime($vote['endtime'])); ?></td>
|
||||
<td><span class="vote-status <?php echo $statusClass; ?>"><?php echo $voteStatus; ?></span></td>
|
||||
<td><?php echo $vote['iview']; ?></td>
|
||||
<td><?php echo date('Y-m-d H:i', strtotime($vote['addtime'])); ?></td>
|
||||
<td class="operation-btns">
|
||||
<a href="../vote.php?id=<?php echo $vote['id']; ?>" class="btn btn-blue btn-sm" target="_blank">查看</a>
|
||||
<a href="topic.php?act=options&id=<?php echo $vote['id']; ?>" class="btn btn-green btn-sm">选项</a>
|
||||
<a href="topic.php?act=edit&id=<?php echo $vote['id']; ?>" class="btn btn-gray btn-sm">编辑</a>
|
||||
<button class="btn btn-red btn-sm" onclick="deleteTopic(<?php echo $vote['id']; ?>, '<?php echo htmlspecialchars(addslashes($vote['title'])); ?>')">删除</button>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
<?php else: ?>
|
||||
<tr>
|
||||
<td colspan="9" style="text-align: center;">暂无投票数据</td>
|
||||
</tr>
|
||||
<?php endif; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<!-- 分页 -->
|
||||
<div class="pagination" id="pagination"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="../inc/js.js"></script>
|
||||
<script>
|
||||
// 初始化分页
|
||||
pagination('pagination', <?php echo $pagination['page']; ?>, <?php echo $pagination['totalPage']; ?>, function(page) {
|
||||
// 构建URL参数
|
||||
var params = new URLSearchParams(window.location.search);
|
||||
params.delete('act');
|
||||
params.set('page', page);
|
||||
|
||||
// 跳转到新页面
|
||||
window.location.href = 'topic.php?' + params.toString();
|
||||
});
|
||||
|
||||
// 删除投票
|
||||
function deleteTopic(id, title) {
|
||||
showMask('确认删除', '确定要删除投票 "' + title + '" 吗?<br><span style="color: #e74c3c;">注意:删除后将同时删除该投票的所有选项和投票记录,且不可恢复!</span>', [
|
||||
{
|
||||
text: '取消',
|
||||
class: 'btn-default',
|
||||
callback: function() {
|
||||
closeMask();
|
||||
}
|
||||
},
|
||||
{
|
||||
text: '确定删除',
|
||||
class: 'btn-danger',
|
||||
callback: function() {
|
||||
// 发送删除请求
|
||||
ajaxRequest('../api/topic.php', {
|
||||
act: 'delete',
|
||||
id: id
|
||||
}, function(response) {
|
||||
if (response.code === 0) {
|
||||
// 删除成功,刷新页面
|
||||
showMask('操作成功', '投票删除成功', [
|
||||
{
|
||||
text: '确定',
|
||||
class: 'btn-primary',
|
||||
callback: function() {
|
||||
window.location.reload();
|
||||
}
|
||||
}
|
||||
]);
|
||||
} else {
|
||||
// 显示错误信息
|
||||
showMask('操作失败', response.msg || '删除失败,请稍后重试', [
|
||||
{
|
||||
text: '确定',
|
||||
class: 'btn-primary',
|
||||
callback: function() {
|
||||
closeMask();
|
||||
}
|
||||
}
|
||||
]);
|
||||
}
|
||||
}, function(error) {
|
||||
showMask('请求失败', '网络错误,请稍后重试', [
|
||||
{
|
||||
text: '确定',
|
||||
class: 'btn-primary',
|
||||
callback: function() {
|
||||
closeMask();
|
||||
}
|
||||
}
|
||||
]);
|
||||
});
|
||||
}
|
||||
}
|
||||
]);
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
<?php
|
||||
break;
|
||||
}
|
||||
354
ht/admin/topic_form.php
Normal file
354
ht/admin/topic_form.php
Normal file
@@ -0,0 +1,354 @@
|
||||
<?php
|
||||
|
||||
// 检查是否已经引入必要文件
|
||||
if (!isset($db) || !isset($user) || !isset($action)) {
|
||||
header('Location: topic.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
// 初始化表单数据
|
||||
$formData = [
|
||||
'id' => 0,
|
||||
'title' => '',
|
||||
'idesc' => '',
|
||||
'statime' => date('Y-m-d H:i:s', strtotime('+1 hour')),
|
||||
'endtime' => date('Y-m-d H:i:s', strtotime('+7 days')),
|
||||
'itype' => 0,
|
||||
'maxtime' => 1,
|
||||
'status' => 1
|
||||
];
|
||||
|
||||
// 如果是编辑模式,加载现有数据
|
||||
if ($action == 'edit' && isset($vote)) {
|
||||
$formData = array_merge($formData, $vote);
|
||||
}
|
||||
?>
|
||||
<!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 $pageTitle; ?> - <?php echo getSiteTitle(); ?></title>
|
||||
<link rel="stylesheet" href="../inc/css.css">
|
||||
<style>
|
||||
.admin-container {
|
||||
display: flex;
|
||||
min-height: calc(100vh - 60px);
|
||||
}
|
||||
|
||||
.admin-sidebar {
|
||||
width: 200px;
|
||||
background-color: #2c3e50;
|
||||
color: #fff;
|
||||
padding-top: 20px;
|
||||
}
|
||||
|
||||
.admin-menu {
|
||||
list-style: none;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.admin-menu-item {
|
||||
padding: 12px 20px;
|
||||
border-bottom: 1px solid #34495e;
|
||||
}
|
||||
|
||||
.admin-menu-item a {
|
||||
color: #fff;
|
||||
text-decoration: none;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.admin-menu-item:hover {
|
||||
background-color: #34495e;
|
||||
}
|
||||
|
||||
.admin-menu-item.active {
|
||||
background-color: #3498db;
|
||||
}
|
||||
|
||||
.admin-content {
|
||||
flex: 1;
|
||||
padding: 20px;
|
||||
background-color: #f5f5f5;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.admin-header {
|
||||
margin-bottom: 20px;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.form-card {
|
||||
background-color: #fff;
|
||||
border-radius: 5px;
|
||||
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
|
||||
padding: 20px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.form-actions {
|
||||
margin-top: 20px;
|
||||
text-align: center;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<!-- 顶部导航 -->
|
||||
<header class="header">
|
||||
<div class="header-container">
|
||||
<div class="logo"><?php echo getSiteTitle(); ?> - 管理后台</div>
|
||||
<nav class="nav">
|
||||
<a href="../index.php" class="nav-item">前台首页</a>
|
||||
<a href="../api/user.php?act=logout" class="nav-item">退出登录</a>
|
||||
</nav>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<!-- 管理内容 -->
|
||||
<div class="admin-container">
|
||||
<!-- 侧边栏 -->
|
||||
<div class="admin-sidebar">
|
||||
<ul class="admin-menu">
|
||||
<li class="admin-menu-item"><a href="index.php">系统概况</a></li>
|
||||
<li class="admin-menu-item active"><a href="topic.php">投票管理</a></li>
|
||||
<li class="admin-menu-item"><a href="user.php">用户管理</a></li>
|
||||
<li class="admin-menu-item"><a href="stat.php">数据统计</a></li>
|
||||
<li class="admin-menu-item"><a href="logs.php">系统日志</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<!-- 主体内容 -->
|
||||
<div class="admin-content">
|
||||
<div class="admin-header">
|
||||
<h2><?php echo $pageTitle; ?></h2>
|
||||
<div>
|
||||
<a href="topic.php" class="btn btn-gray">返回列表</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 表单卡片 -->
|
||||
<div class="form-card">
|
||||
<form id="topicForm">
|
||||
<?php if ($action == 'edit'): ?>
|
||||
<input type="hidden" name="id" value="<?php echo $formData['id']; ?>">
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="title" class="form-label">投票标题</label>
|
||||
<input type="text" id="title" name="title" class="form-control" value="<?php echo htmlspecialchars($formData['title']); ?>" required>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="desc" class="form-label">投票描述</label>
|
||||
<textarea id="desc" name="desc" class="form-control" rows="5"><?php echo htmlspecialchars($formData['idesc']); ?></textarea>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="type" class="form-label">投票类型</label>
|
||||
<select id="type" name="type" class="form-control">
|
||||
<option value="0" <?php echo $formData['itype'] == 0 ? 'selected' : ''; ?>>单选</option>
|
||||
<option value="1" <?php echo $formData['itype'] == 1 ? 'selected' : ''; ?>>多选</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="form-group" id="maxOptionsGroup" style="<?php echo $formData['itype'] == 0 ? 'display:none;' : ''; ?>">
|
||||
<label for="maxtime" class="form-label">最多可选项数</label>
|
||||
<input type="number" id="maxtime" name="maxtime" class="form-control" min="1" value="<?php echo $formData['maxtime']; ?>" <?php echo $formData['itype'] == 0 ? '' : 'required'; ?>>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="statime" class="form-label">开始时间</label>
|
||||
<input type="datetime-local" id="statime" name="statime" class="form-control" value="<?php echo date('Y-m-d\TH:i', strtotime($formData['statime'])); ?>" required>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="endtime" class="form-label">结束时间</label>
|
||||
<input type="datetime-local" id="endtime" name="endtime" class="form-control" value="<?php echo date('Y-m-d\TH:i', strtotime($formData['endtime'])); ?>" required>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="status" class="form-label">状态</label>
|
||||
<select id="status" name="status" class="form-control">
|
||||
<option value="1" <?php echo $formData['status'] == 1 ? 'selected' : ''; ?>>正常</option>
|
||||
<option value="0" <?php echo $formData['status'] == 0 ? 'selected' : ''; ?>>禁用</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="form-actions">
|
||||
<button type="submit" class="btn btn-blue btn-lg">保存</button>
|
||||
<a href="topic.php" class="btn btn-gray btn-lg">取消</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="../inc/js.js"></script>
|
||||
<script>
|
||||
// 监听投票类型变化,控制最多可选项数显示
|
||||
document.getElementById('type').addEventListener('change', function() {
|
||||
var maxOptionsGroup = document.getElementById('maxOptionsGroup');
|
||||
if (this.value == '1') {
|
||||
maxOptionsGroup.style.display = 'block';
|
||||
} else {
|
||||
maxOptionsGroup.style.display = 'none';
|
||||
}
|
||||
});
|
||||
|
||||
// 表单提交
|
||||
document.getElementById('topicForm').addEventListener('submit', function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
// 获取表单数据
|
||||
var form = this;
|
||||
var title = form.elements['title'].value.trim();
|
||||
var desc = form.elements['desc'].value.trim();
|
||||
var type = form.elements['type'].value;
|
||||
var maxtime = form.elements['maxtime'].value;
|
||||
var statime = form.elements['statime'].value;
|
||||
var endtime = form.elements['endtime'].value;
|
||||
var status = form.elements['status'].value;
|
||||
|
||||
// 验证表单
|
||||
if (!title) {
|
||||
showMask('提示', '请输入投票标题', [
|
||||
{
|
||||
text: '确定',
|
||||
class: 'btn-primary',
|
||||
callback: function() {
|
||||
closeMask();
|
||||
form.elements['title'].focus();
|
||||
}
|
||||
}
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!statime || !endtime) {
|
||||
showMask('提示', '请选择开始和结束时间', [
|
||||
{
|
||||
text: '确定',
|
||||
class: 'btn-primary',
|
||||
callback: function() {
|
||||
closeMask();
|
||||
}
|
||||
}
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
if (new Date(statime) >= new Date(endtime)) {
|
||||
showMask('提示', '结束时间必须晚于开始时间', [
|
||||
{
|
||||
text: '确定',
|
||||
class: 'btn-primary',
|
||||
callback: function() {
|
||||
closeMask();
|
||||
form.elements['endtime'].focus();
|
||||
}
|
||||
}
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
if (type == 1 && maxtime < 2) {
|
||||
showMask('提示', '多选投票最少可选2项', [
|
||||
{
|
||||
text: '确定',
|
||||
class: 'btn-primary',
|
||||
callback: function() {
|
||||
closeMask();
|
||||
form.elements['maxtime'].focus();
|
||||
}
|
||||
}
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
// 准备提交数据
|
||||
var postData = {
|
||||
title: title,
|
||||
desc: desc,
|
||||
type: type,
|
||||
maxtime: maxtime,
|
||||
statime: statime.replace('T', ' '),
|
||||
endtime: endtime.replace('T', ' '),
|
||||
status: status
|
||||
};
|
||||
|
||||
// 如果是编辑模式,添加ID
|
||||
<?php if ($action == 'edit'): ?>
|
||||
postData.id = <?php echo $formData['id']; ?>;
|
||||
postData.act = 'update';
|
||||
<?php else: ?>
|
||||
postData.act = 'add';
|
||||
<?php endif; ?>
|
||||
|
||||
// 发送请求
|
||||
ajaxRequest('../api/topic.php', postData, function(response) {
|
||||
if (response.code === 0) {
|
||||
<?php if ($action == 'edit'): ?>
|
||||
showMask('成功', '投票更新成功', [
|
||||
{
|
||||
text: '返回列表',
|
||||
class: 'btn-primary',
|
||||
callback: function() {
|
||||
window.location.href = 'topic.php';
|
||||
}
|
||||
},
|
||||
{
|
||||
text: '管理选项',
|
||||
class: 'btn-blue',
|
||||
callback: function() {
|
||||
window.location.href = 'topic.php?act=options&id=<?php echo $formData['id']; ?>';
|
||||
}
|
||||
}
|
||||
]);
|
||||
<?php else: ?>
|
||||
showMask('成功', '投票创建成功', [
|
||||
{
|
||||
text: '返回列表',
|
||||
class: 'btn-default',
|
||||
callback: function() {
|
||||
window.location.href = 'topic.php';
|
||||
}
|
||||
},
|
||||
{
|
||||
text: '管理选项',
|
||||
class: 'btn-primary',
|
||||
callback: function() {
|
||||
window.location.href = 'topic.php?act=options&id=' + response.data.id;
|
||||
}
|
||||
}
|
||||
]);
|
||||
<?php endif; ?>
|
||||
} else {
|
||||
showMask('错误', response.msg || '操作失败,请稍后重试', [
|
||||
{
|
||||
text: '确定',
|
||||
class: 'btn-primary',
|
||||
callback: function() {
|
||||
closeMask();
|
||||
}
|
||||
}
|
||||
]);
|
||||
}
|
||||
}, function(error) {
|
||||
showMask('错误', '网络错误,请稍后重试', [
|
||||
{
|
||||
text: '确定',
|
||||
class: 'btn-primary',
|
||||
callback: function() {
|
||||
closeMask();
|
||||
}
|
||||
}
|
||||
]);
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
569
ht/admin/topic_options.php
Normal file
569
ht/admin/topic_options.php
Normal file
@@ -0,0 +1,569 @@
|
||||
<?php
|
||||
|
||||
// 检查是否已经引入必要文件
|
||||
if (!isset($db) || !isset($user) || !isset($vote) || !isset($options)) {
|
||||
header('Location: topic.php');
|
||||
exit;
|
||||
}
|
||||
?>
|
||||
<!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 $pageTitle; ?> - <?php echo getSiteTitle(); ?></title>
|
||||
<link rel="stylesheet" href="../inc/css.css">
|
||||
<style>
|
||||
.admin-container {
|
||||
display: flex;
|
||||
min-height: calc(100vh - 60px);
|
||||
}
|
||||
|
||||
.admin-sidebar {
|
||||
width: 200px;
|
||||
background-color: #2c3e50;
|
||||
color: #fff;
|
||||
padding-top: 20px;
|
||||
}
|
||||
|
||||
.admin-menu {
|
||||
list-style: none;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.admin-menu-item {
|
||||
padding: 12px 20px;
|
||||
border-bottom: 1px solid #34495e;
|
||||
}
|
||||
|
||||
.admin-menu-item a {
|
||||
color: #fff;
|
||||
text-decoration: none;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.admin-menu-item:hover {
|
||||
background-color: #34495e;
|
||||
}
|
||||
|
||||
.admin-menu-item.active {
|
||||
background-color: #3498db;
|
||||
}
|
||||
|
||||
.admin-content {
|
||||
flex: 1;
|
||||
padding: 20px;
|
||||
background-color: #f5f5f5;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.admin-header {
|
||||
margin-bottom: 20px;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.form-card {
|
||||
background-color: #fff;
|
||||
border-radius: 5px;
|
||||
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
|
||||
padding: 20px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.options-list {
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
|
||||
.option-item {
|
||||
background-color: #fff;
|
||||
border-radius: 5px;
|
||||
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
|
||||
padding: 15px;
|
||||
margin-bottom: 15px;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.option-actions {
|
||||
position: absolute;
|
||||
top: 15px;
|
||||
right: 15px;
|
||||
}
|
||||
|
||||
.option-image {
|
||||
max-width: 100px;
|
||||
max-height: 100px;
|
||||
margin-top: 10px;
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
.operation-btns {
|
||||
display: flex;
|
||||
gap: 5px;
|
||||
}
|
||||
|
||||
.vote-info {
|
||||
margin-bottom: 20px;
|
||||
background-color: #f8f9fa;
|
||||
padding: 15px;
|
||||
border-radius: 5px;
|
||||
border-left: 4px solid #3498db;
|
||||
}
|
||||
|
||||
.progress-bar {
|
||||
height: 20px;
|
||||
background-color: #f0f0f0;
|
||||
border-radius: 4px;
|
||||
overflow: hidden;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
.progress-fill {
|
||||
height: 100%;
|
||||
background-color: #4CAF50;
|
||||
transition: width 0.3s ease;
|
||||
}
|
||||
|
||||
.progress-text {
|
||||
font-size: 14px;
|
||||
color: #555;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<!-- 顶部导航 -->
|
||||
<header class="header">
|
||||
<div class="header-container">
|
||||
<div class="logo"><?php echo getSiteTitle(); ?> - 管理后台</div>
|
||||
<nav class="nav">
|
||||
<a href="../index.php" class="nav-item">前台首页</a>
|
||||
<a href="../api/user.php?act=logout" class="nav-item">退出登录</a>
|
||||
</nav>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<!-- 管理内容 -->
|
||||
<div class="admin-container">
|
||||
<!-- 侧边栏 -->
|
||||
<div class="admin-sidebar">
|
||||
<ul class="admin-menu">
|
||||
<li class="admin-menu-item"><a href="index.php">系统概况</a></li>
|
||||
<li class="admin-menu-item active"><a href="topic.php">投票管理</a></li>
|
||||
<li class="admin-menu-item"><a href="user.php">用户管理</a></li>
|
||||
<li class="admin-menu-item"><a href="stat.php">数据统计</a></li>
|
||||
<li class="admin-menu-item"><a href="logs.php">系统日志</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<!-- 主体内容 -->
|
||||
<div class="admin-content">
|
||||
<div class="admin-header">
|
||||
<h2>管理投票选项</h2>
|
||||
<div>
|
||||
<a href="topic.php" class="btn btn-gray">返回列表</a>
|
||||
<a href="topic.php?act=edit&id=<?php echo $vote['id']; ?>" class="btn btn-blue">编辑投票</a>
|
||||
<a href="../vote.php?id=<?php echo $vote['id']; ?>" class="btn btn-green" target="_blank">查看投票</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 投票信息 -->
|
||||
<div class="vote-info">
|
||||
<h3><?php echo htmlspecialchars($vote['title']); ?></h3>
|
||||
<p><strong>类型:</strong><?php echo $vote['itype'] == 0 ? '单选' : "多选(最多选{$vote['maxtime']}项)"; ?></p>
|
||||
<p><strong>时间:</strong><?php echo date('Y-m-d H:i', strtotime($vote['statime'])); ?> 至 <?php echo date('Y-m-d H:i', strtotime($vote['endtime'])); ?></p>
|
||||
<p><strong>状态:</strong><?php echo $vote['status'] == 1 ? '正常' : '禁用'; ?></p>
|
||||
</div>
|
||||
|
||||
<!-- 选项列表 -->
|
||||
<div class="options-list">
|
||||
<h3>现有选项(<?php echo count($options); ?>)</h3>
|
||||
|
||||
<?php if (!empty($options)): ?>
|
||||
<?php foreach ($options as $option): ?>
|
||||
<div class="option-item">
|
||||
<div class="option-actions">
|
||||
<button class="btn btn-blue btn-sm" onclick="editOption(<?php echo $option['id']; ?>)">编辑</button>
|
||||
<button class="btn btn-red btn-sm" onclick="deleteOption(<?php echo $option['id']; ?>, '<?php echo htmlspecialchars(addslashes($option['name'])); ?>')">删除</button>
|
||||
</div>
|
||||
|
||||
<h4><?php echo htmlspecialchars($option['name']); ?></h4>
|
||||
|
||||
<?php if (!empty($option['imgs'])): ?>
|
||||
<div><img src="<?php echo htmlspecialchars($option['imgs']); ?>" alt="<?php echo htmlspecialchars($option['name']); ?>" class="option-image"></div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if (!empty($option['idesc'])): ?>
|
||||
<p><?php echo nl2br(htmlspecialchars($option['idesc'])); ?></p>
|
||||
<?php endif; ?>
|
||||
|
||||
<p><small>排序:<?php echo $option['sort']; ?></small></p>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
<?php else: ?>
|
||||
<div class="card">
|
||||
<div class="card-body" style="text-align: center; padding: 30px;">
|
||||
<p>暂无选项数据</p>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
<!-- 添加选项表单 -->
|
||||
<div class="form-card">
|
||||
<h3 id="formTitle">添加新选项</h3>
|
||||
<form id="optionForm">
|
||||
<input type="hidden" id="optionId" name="id" value="0">
|
||||
<input type="hidden" name="topic_id" value="<?php echo $vote['id']; ?>">
|
||||
|
||||
<div class="form-group">
|
||||
<label for="name" class="form-label">选项名称</label>
|
||||
<input type="text" id="name" name="name" class="form-control" required>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="imgs" class="form-label">选项图片URL(可选)</label>
|
||||
<div style="display: flex; gap: 10px;">
|
||||
<input type="text" id="imgs" name="imgs" class="form-control" placeholder="选项图片相对路径">
|
||||
<button type="button" id="uploadImgBtn" class="btn btn-green">传图</button>
|
||||
</div>
|
||||
<input type="file" id="imgUploader" style="display: none;" accept="image/*">
|
||||
<div id="uploadProgress" style="display: none; margin-top: 10px;">
|
||||
<div class="progress-bar">
|
||||
<div class="progress-fill" style="width: 0%;"></div>
|
||||
</div>
|
||||
<div class="progress-text">上传中 0%</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="desc" class="form-label">选项描述(可选)</label>
|
||||
<textarea id="desc" name="desc" class="form-control" rows="3"></textarea>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="sort" class="form-label">排序(数字越小越靠前)</label>
|
||||
<input type="number" id="sort" name="sort" class="form-control" value="0">
|
||||
</div>
|
||||
|
||||
<div style="margin-top: 20px; text-align: center;">
|
||||
<button type="submit" class="btn btn-blue btn-lg" id="submitBtn">添加选项</button>
|
||||
<button type="button" class="btn btn-gray btn-lg" id="resetBtn" style="display: none;">取消编辑</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="../inc/js.js"></script>
|
||||
<script>
|
||||
|
||||
// 图片上传相关
|
||||
document.getElementById('uploadImgBtn').addEventListener('click', function() {
|
||||
document.getElementById('imgUploader').click();
|
||||
});
|
||||
|
||||
document.getElementById('imgUploader').addEventListener('change', function(e) {
|
||||
if (this.files.length === 0) return;
|
||||
|
||||
var file = this.files[0];
|
||||
if (!file.type.match('image.*')) {
|
||||
showMask('错误', '请选择图片文件', [{ text: '确定', class: 'btn-blue' }]);
|
||||
return;
|
||||
}
|
||||
|
||||
// 显示上传进度条
|
||||
var progressBar = document.getElementById('uploadProgress');
|
||||
var progressFill = progressBar.querySelector('.progress-fill');
|
||||
var progressText = progressBar.querySelector('.progress-text');
|
||||
progressBar.style.display = 'block';
|
||||
progressFill.style.width = '0%';
|
||||
progressText.textContent = '上传中 0%';
|
||||
|
||||
// 如果图片较大,先在客户端进行预处理
|
||||
var reader = new FileReader();
|
||||
reader.onload = function(e) {
|
||||
var img = new Image();
|
||||
img.onload = function() {
|
||||
// 检查图片尺寸,如果宽度大于1280,则调整为1024宽度
|
||||
var canvas = document.createElement('canvas');
|
||||
var ctx = canvas.getContext('2d');
|
||||
var width = img.width;
|
||||
var height = img.height;
|
||||
|
||||
if (width > 1280) {
|
||||
height = Math.round(height * (1024 / width));
|
||||
width = 1024;
|
||||
}
|
||||
|
||||
canvas.width = width;
|
||||
canvas.height = height;
|
||||
ctx.drawImage(img, 0, 0, width, height);
|
||||
|
||||
// 转换为Blob格式
|
||||
canvas.toBlob(function(blob) {
|
||||
// 创建FormData对象上传文件
|
||||
var formData = new FormData();
|
||||
formData.append('image', blob, file.name);
|
||||
|
||||
// 创建XMLHttpRequest对象
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open('POST', '../api/upload.php', true);
|
||||
|
||||
// 上传进度
|
||||
xhr.upload.onprogress = function(e) {
|
||||
if (e.lengthComputable) {
|
||||
var percentage = Math.round((e.loaded / e.total) * 100);
|
||||
progressFill.style.width = percentage + '%';
|
||||
progressText.textContent = '上传中 ' + percentage + '%';
|
||||
}
|
||||
};
|
||||
|
||||
// 上传完成
|
||||
xhr.onload = function() {
|
||||
progressBar.style.display = 'none';
|
||||
|
||||
if (xhr.status === 200) {
|
||||
try {
|
||||
var response = JSON.parse(xhr.responseText);
|
||||
if (response.code === 0) {
|
||||
// 上传成功,将图片URL填入输入框
|
||||
document.getElementById('imgs').value = response.data.url;
|
||||
showMask('成功', '图片上传成功', [{ text: '确定', class: 'btn-blue' }]);
|
||||
} else {
|
||||
showMask('错误', '上传失败: ' + response.msg, [{ text: '确定', class: 'btn-blue' }]);
|
||||
}
|
||||
} catch (e) {
|
||||
showMask('错误', '服务器返回异常', [{ text: '确定', class: 'btn-blue' }]);
|
||||
}
|
||||
} else {
|
||||
showMask('错误', '上传失败,服务器返回状态码: ' + xhr.status, [{ text: '确定', class: 'btn-blue' }]);
|
||||
}
|
||||
};
|
||||
|
||||
// 上传错误
|
||||
xhr.onerror = function() {
|
||||
progressBar.style.display = 'none';
|
||||
showMask('错误', '网络错误,上传失败', [{ text: '确定', class: 'btn-blue' }]);
|
||||
};
|
||||
|
||||
// 发送请求
|
||||
xhr.send(formData);
|
||||
}, 'image/jpeg', 0.92);
|
||||
};
|
||||
img.src = e.target.result;
|
||||
};
|
||||
reader.readAsDataURL(file);
|
||||
});
|
||||
// 表单提交
|
||||
document.getElementById('optionForm').addEventListener('submit', function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
// 获取表单数据
|
||||
var form = this;
|
||||
var optionId = form.elements['id'].value;
|
||||
var topicId = form.elements['topic_id'].value;
|
||||
var name = form.elements['name'].value.trim();
|
||||
var imgs = form.elements['imgs'].value.trim();
|
||||
var desc = form.elements['desc'].value.trim();
|
||||
var sort = form.elements['sort'].value;
|
||||
|
||||
// 验证表单
|
||||
if (!name) {
|
||||
showMask('提示', '请输入选项名称', [
|
||||
{
|
||||
text: '确定',
|
||||
class: 'btn-primary',
|
||||
callback: function() {
|
||||
closeMask();
|
||||
form.elements['name'].focus();
|
||||
}
|
||||
}
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
// 准备提交数据
|
||||
var postData = {
|
||||
topic_id: topicId,
|
||||
name: name,
|
||||
imgs: imgs,
|
||||
desc: desc,
|
||||
sort: sort
|
||||
};
|
||||
|
||||
// 根据是新增还是编辑,设置不同的请求参数
|
||||
if (optionId > 0) {
|
||||
postData.act = 'updateOption';
|
||||
postData.id = optionId;
|
||||
} else {
|
||||
postData.act = 'addOption';
|
||||
}
|
||||
|
||||
// 发送请求
|
||||
ajaxRequest('../api/topic.php', postData, function(response) {
|
||||
if (response.code === 0) {
|
||||
showMask('成功', optionId > 0 ? '选项更新成功' : '选项添加成功', [
|
||||
{
|
||||
text: '确定',
|
||||
class: 'btn-primary',
|
||||
callback: function() {
|
||||
window.location.reload();
|
||||
}
|
||||
}
|
||||
]);
|
||||
} else {
|
||||
showMask('错误', response.msg || '操作失败,请稍后重试', [
|
||||
{
|
||||
text: '确定',
|
||||
class: 'btn-primary',
|
||||
callback: function() {
|
||||
closeMask();
|
||||
}
|
||||
}
|
||||
]);
|
||||
}
|
||||
}, function(error) {
|
||||
showMask('错误', '网络错误,请稍后重试', [
|
||||
{
|
||||
text: '确定',
|
||||
class: 'btn-primary',
|
||||
callback: function() {
|
||||
closeMask();
|
||||
}
|
||||
}
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
// 重置表单按钮点击事件
|
||||
document.getElementById('resetBtn').addEventListener('click', function() {
|
||||
resetForm();
|
||||
});
|
||||
|
||||
// 重置表单
|
||||
function resetForm() {
|
||||
var form = document.getElementById('optionForm');
|
||||
form.reset();
|
||||
form.elements['id'].value = 0;
|
||||
|
||||
document.getElementById('formTitle').textContent = '添加新选项';
|
||||
document.getElementById('submitBtn').textContent = '添加选项';
|
||||
document.getElementById('resetBtn').style.display = 'none';
|
||||
}
|
||||
|
||||
// 编辑选项
|
||||
function editOption(id) {
|
||||
// 发送请求获取选项详情
|
||||
ajaxRequest('../api/topic.php', {
|
||||
act: 'getOptions',
|
||||
topic_id: <?php echo $vote['id']; ?>
|
||||
}, function(response) {
|
||||
if (response.code === 0) {
|
||||
var options = response.data;
|
||||
var option = options.find(function(item) {
|
||||
return item.id == id;
|
||||
});
|
||||
|
||||
if (option) {
|
||||
// 填充表单
|
||||
var form = document.getElementById('optionForm');
|
||||
form.elements['id'].value = option.id;
|
||||
form.elements['name'].value = option.name;
|
||||
form.elements['imgs'].value = option.imgs;
|
||||
form.elements['desc'].value = option.idesc;
|
||||
form.elements['sort'].value = option.sort;
|
||||
|
||||
// 更新UI
|
||||
document.getElementById('formTitle').textContent = '编辑选项';
|
||||
document.getElementById('submitBtn').textContent = '更新选项';
|
||||
document.getElementById('resetBtn').style.display = 'inline-block';
|
||||
|
||||
// 滚动到表单位置
|
||||
document.querySelector('.form-card').scrollIntoView({ behavior: 'smooth' });
|
||||
}
|
||||
} else {
|
||||
showMask('错误', response.msg || '获取选项信息失败', [
|
||||
{
|
||||
text: '确定',
|
||||
class: 'btn-primary',
|
||||
callback: function() {
|
||||
closeMask();
|
||||
}
|
||||
}
|
||||
]);
|
||||
}
|
||||
}, function(error) {
|
||||
showMask('错误', '网络错误,请稍后重试', [
|
||||
{
|
||||
text: '确定',
|
||||
class: 'btn-primary',
|
||||
callback: function() {
|
||||
closeMask();
|
||||
}
|
||||
}
|
||||
]);
|
||||
});
|
||||
}
|
||||
|
||||
// 删除选项
|
||||
function deleteOption(id, name) {
|
||||
showMask('确认删除', '确定要删除选项 "' + name + '" 吗?<br><span style="color: #e74c3c;">注意:删除后该选项相关的投票记录也将被删除,且不可恢复!</span>', [
|
||||
{
|
||||
text: '取消',
|
||||
class: 'btn-default',
|
||||
callback: function() {
|
||||
closeMask();
|
||||
}
|
||||
},
|
||||
{
|
||||
text: '确定删除',
|
||||
class: 'btn-danger',
|
||||
callback: function() {
|
||||
// 发送删除请求
|
||||
ajaxRequest('../api/topic.php', {
|
||||
act: 'deleteOption',
|
||||
id: id
|
||||
}, function(response) {
|
||||
if (response.code === 0) {
|
||||
// 删除成功,刷新页面
|
||||
showMask('操作成功', '选项删除成功', [
|
||||
{
|
||||
text: '确定',
|
||||
class: 'btn-primary',
|
||||
callback: function() {
|
||||
window.location.reload();
|
||||
}
|
||||
}
|
||||
]);
|
||||
} else {
|
||||
// 显示错误信息
|
||||
showMask('操作失败', response.msg || '删除失败,请稍后重试', [
|
||||
{
|
||||
text: '确定',
|
||||
class: 'btn-primary',
|
||||
callback: function() {
|
||||
closeMask();
|
||||
}
|
||||
}
|
||||
]);
|
||||
}
|
||||
}, function(error) {
|
||||
showMask('请求失败', '网络错误,请稍后重试', [
|
||||
{
|
||||
text: '确定',
|
||||
class: 'btn-primary',
|
||||
callback: function() {
|
||||
closeMask();
|
||||
}
|
||||
}
|
||||
]);
|
||||
});
|
||||
}
|
||||
}
|
||||
]);
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
698
ht/admin/user.php
Normal file
698
ht/admin/user.php
Normal file
@@ -0,0 +1,698 @@
|
||||
<?php
|
||||
|
||||
// 引入必要文件
|
||||
require_once '../inc/pubs.php';
|
||||
require_once '../inc/sqls.php';
|
||||
|
||||
// 验证管理员权限
|
||||
if (!checkAdmin()) {
|
||||
header('Location: ../login.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
// 获取当前用户
|
||||
$user = $_SESSION['user'];
|
||||
|
||||
// 实例化数据库操作类
|
||||
$db = new DB();
|
||||
|
||||
// 获取分页参数
|
||||
$page = isset($_GET['page']) ? intval($_GET['page']) : 1;
|
||||
$pageSize = 20;
|
||||
|
||||
// 获取筛选参数
|
||||
$status = isset($_GET['status']) ? intval($_GET['status']) : -1;
|
||||
$role = isset($_GET['role']) ? intval($_GET['role']) : -1;
|
||||
$keyword = isset($_GET['keyword']) ? safeFilter($_GET['keyword']) : '';
|
||||
|
||||
// 构建查询条件
|
||||
$whereConditions = [];
|
||||
if ($status >= 0) {
|
||||
$whereConditions[] = "status = $status";
|
||||
}
|
||||
if ($role >= 0) {
|
||||
$whereConditions[] = "irole = $role";
|
||||
}
|
||||
if ($keyword) {
|
||||
$whereConditions[] = "username LIKE '%$keyword%'";
|
||||
}
|
||||
|
||||
$whereStr = !empty($whereConditions) ? implode(' AND ', $whereConditions) : '';
|
||||
|
||||
// 获取总记录数
|
||||
$total = $db->count('users', $whereStr);
|
||||
|
||||
// 计算分页信息
|
||||
$pagination = getPagination($total, $page, $pageSize);
|
||||
|
||||
// 获取用户列表
|
||||
$orderBy = "id ASC";
|
||||
$limit = "{$pagination['offset']}, {$pagination['pageSize']}";
|
||||
$userList = $db->getAll('users', $whereStr, '*', $orderBy, $limit);
|
||||
|
||||
// 页面标题
|
||||
$pageTitle = "用户管理";
|
||||
?>
|
||||
<!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 $pageTitle; ?> - <?php echo getSiteTitle(); ?></title>
|
||||
<link rel="stylesheet" href="../inc/css.css">
|
||||
<style>
|
||||
.admin-container {
|
||||
display: flex;
|
||||
min-height: calc(100vh - 60px);
|
||||
}
|
||||
|
||||
.admin-sidebar {
|
||||
width: 200px;
|
||||
background-color: #2c3e50;
|
||||
color: #fff;
|
||||
padding-top: 20px;
|
||||
}
|
||||
|
||||
.admin-menu {
|
||||
list-style: none;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.admin-menu-item {
|
||||
padding: 12px 20px;
|
||||
border-bottom: 1px solid #34495e;
|
||||
}
|
||||
|
||||
.admin-menu-item a {
|
||||
color: #fff;
|
||||
text-decoration: none;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.admin-menu-item:hover {
|
||||
background-color: #34495e;
|
||||
}
|
||||
|
||||
.admin-menu-item.active {
|
||||
background-color: #3498db;
|
||||
}
|
||||
|
||||
.admin-content {
|
||||
flex: 1;
|
||||
padding: 20px;
|
||||
background-color: #f5f5f5;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.admin-header {
|
||||
margin-bottom: 20px;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.filter-form {
|
||||
margin-bottom: 20px;
|
||||
padding: 15px;
|
||||
background-color: #fff;
|
||||
border-radius: 5px;
|
||||
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.operation-btns {
|
||||
display: flex;
|
||||
gap: 5px;
|
||||
}
|
||||
|
||||
.user-role, .user-status {
|
||||
display: inline-block;
|
||||
padding: 3px 8px;
|
||||
border-radius: 3px;
|
||||
color: #fff;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.user-role-admin {
|
||||
background-color: #e74c3c;
|
||||
}
|
||||
|
||||
.user-role-user {
|
||||
background-color: #3498db;
|
||||
}
|
||||
|
||||
.user-status-enabled {
|
||||
background-color: #2ecc71;
|
||||
}
|
||||
|
||||
.user-status-disabled {
|
||||
background-color: #95a5a6;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<!-- 顶部导航 -->
|
||||
<header class="header">
|
||||
<div class="header-container">
|
||||
<div class="logo"><?php echo getSiteTitle(); ?> - 管理后台</div>
|
||||
<nav class="nav">
|
||||
<a href="../index.php" class="nav-item">前台首页</a>
|
||||
<a href="../api/user.php?act=logout" class="nav-item">退出登录</a>
|
||||
</nav>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<!-- 管理内容 -->
|
||||
<div class="admin-container">
|
||||
<!-- 侧边栏 -->
|
||||
<div class="admin-sidebar">
|
||||
<ul class="admin-menu">
|
||||
<li class="admin-menu-item"><a href="index.php">系统概况</a></li>
|
||||
<li class="admin-menu-item"><a href="topic.php">投票管理</a></li>
|
||||
<li class="admin-menu-item active"><a href="user.php">用户管理</a></li>
|
||||
<li class="admin-menu-item"><a href="stat.php">数据统计</a></li>
|
||||
<li class="admin-menu-item"><a href="logs.php">系统日志</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<!-- 主体内容 -->
|
||||
<div class="admin-content">
|
||||
<div class="admin-header">
|
||||
<h2>用户管理</h2>
|
||||
<div>
|
||||
<button class="btn btn-green" onclick="showAddUserForm()">添加用户</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 筛选表单 -->
|
||||
<div class="filter-form">
|
||||
<form action="user.php" method="get">
|
||||
<div style="display: flex; gap: 15px; flex-wrap: wrap; align-items: flex-end;">
|
||||
<div>
|
||||
<label for="keyword">用户名:</label>
|
||||
<input type="text" name="keyword" id="keyword" class="form-control" value="<?php echo htmlspecialchars($keyword); ?>" placeholder="搜索用户名">
|
||||
</div>
|
||||
<div>
|
||||
<label for="status">状态:</label>
|
||||
<select name="status" id="status" class="form-control">
|
||||
<option value="-1">全部</option>
|
||||
<option value="1" <?php echo $status == 1 ? 'selected' : ''; ?>>正常</option>
|
||||
<option value="0" <?php echo $status === 0 ? 'selected' : ''; ?>>禁用</option>
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label for="role">角色:</label>
|
||||
<select name="role" id="role" class="form-control">
|
||||
<option value="-1">全部</option>
|
||||
<option value="0" <?php echo $role === 0 ? 'selected' : ''; ?>>普通用户</option>
|
||||
<option value="1" <?php echo $role == 1 ? 'selected' : ''; ?>>管理员</option>
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<button type="submit" class="btn btn-blue">搜索</button>
|
||||
<a href="user.php" class="btn btn-gray">重置</a>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<!-- 用户列表 -->
|
||||
<div class="table-container">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th>用户名</th>
|
||||
<th>角色</th>
|
||||
<th>状态</th>
|
||||
<th>注册时间</th>
|
||||
<th>最后登录</th>
|
||||
<th>操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php if (!empty($userList)): ?>
|
||||
<?php foreach ($userList as $userData): ?>
|
||||
<tr>
|
||||
<td><?php echo $userData['id']; ?></td>
|
||||
<td><?php echo htmlspecialchars($userData['username']); ?></td>
|
||||
<td>
|
||||
<?php if ($userData['irole'] == 1): ?>
|
||||
<span class="user-role user-role-admin">管理员</span>
|
||||
<?php else: ?>
|
||||
<span class="user-role user-role-user">普通用户</span>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
<td>
|
||||
<?php if ($userData['status'] == 1): ?>
|
||||
<span class="user-status user-status-enabled">正常</span>
|
||||
<?php else: ?>
|
||||
<span class="user-status user-status-disabled">禁用</span>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
<td><?php echo date('Y-m-d H:i', strtotime($userData['regtime'])); ?></td>
|
||||
<td><?php echo $userData['logtime'] ? date('Y-m-d H:i', strtotime($userData['logtime'])) : '从未登录'; ?></td>
|
||||
<td class="operation-btns">
|
||||
<button class="btn btn-blue btn-sm" onclick="editUser(<?php echo $userData['id']; ?>, '<?php echo htmlspecialchars(addslashes($userData['username'])); ?>', <?php echo $userData['irole']; ?>, <?php echo $userData['status']; ?>)">编辑</button>
|
||||
<button class="btn btn-gray btn-sm" onclick="resetPassword(<?php echo $userData['id']; ?>, '<?php echo htmlspecialchars(addslashes($userData['username'])); ?>')">重置密码</button>
|
||||
|
||||
<?php if ($userData['id'] != $user['id']): // 不能删除自己 ?>
|
||||
<?php if ($userData['status'] == 1): ?>
|
||||
<button class="btn btn-red btn-sm" onclick="changeUserStatus(<?php echo $userData['id']; ?>, '<?php echo htmlspecialchars(addslashes($userData['username'])); ?>', 0)">禁用</button>
|
||||
<?php else: ?>
|
||||
<button class="btn btn-green btn-sm" onclick="changeUserStatus(<?php echo $userData['id']; ?>, '<?php echo htmlspecialchars(addslashes($userData['username'])); ?>', 1)">启用</button>
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
<?php else: ?>
|
||||
<tr>
|
||||
<td colspan="7" style="text-align: center;">暂无用户数据</td>
|
||||
</tr>
|
||||
<?php endif; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<!-- 分页 -->
|
||||
<div class="pagination" id="pagination"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="../inc/js.js"></script>
|
||||
<script>
|
||||
// 初始化分页
|
||||
pagination('pagination', <?php echo $pagination['page']; ?>, <?php echo $pagination['totalPage']; ?>, function(page) {
|
||||
// 构建URL参数
|
||||
var params = new URLSearchParams(window.location.search);
|
||||
params.set('page', page);
|
||||
|
||||
// 跳转到新页面
|
||||
window.location.href = 'user.php?' + params.toString();
|
||||
});
|
||||
|
||||
// 显示添加用户表单
|
||||
function showAddUserForm() {
|
||||
var content = `
|
||||
<form id="addUserForm">
|
||||
<div class="form-group">
|
||||
<label for="username" class="form-label">用户名(手机号)</label>
|
||||
<input type="text" id="username" name="username" class="form-control" required>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="password" class="form-label">密码</label>
|
||||
<input type="password" id="password" name="password" class="form-control" required>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="confirm_password" class="form-label">确认密码</label>
|
||||
<input type="password" id="confirm_password" name="confirm_password" class="form-control" required>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="role" class="form-label">角色</label>
|
||||
<select id="role" name="role" class="form-control">
|
||||
<option value="0">普通用户</option>
|
||||
<option value="1">管理员</option>
|
||||
</select>
|
||||
</div>
|
||||
</form>
|
||||
`;
|
||||
|
||||
showMask('添加用户', content, [
|
||||
{
|
||||
text: '取消',
|
||||
class: 'btn-default',
|
||||
callback: function() {
|
||||
closeMask();
|
||||
}
|
||||
},
|
||||
{
|
||||
text: '确定添加',
|
||||
class: 'btn-primary',
|
||||
callback: function() {
|
||||
var form = document.getElementById('addUserForm');
|
||||
var username = form.elements['username'].value.trim();
|
||||
var password = form.elements['password'].value;
|
||||
var confirmPassword = form.elements['confirm_password'].value;
|
||||
var role = form.elements['role'].value;
|
||||
|
||||
// 验证手机号格式
|
||||
var phoneRegex = /^1[3456789]\d{9}$/;
|
||||
if (!phoneRegex.test(username)) {
|
||||
showMask('提示', '请输入正确的手机号码', [
|
||||
{
|
||||
text: '确定',
|
||||
class: 'btn-primary',
|
||||
callback: function() {
|
||||
showAddUserForm();
|
||||
}
|
||||
}
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
// 验证密码
|
||||
if (password.length < 6) {
|
||||
showMask('提示', '密码长度不能少于6位', [
|
||||
{
|
||||
text: '确定',
|
||||
class: 'btn-primary',
|
||||
callback: function() {
|
||||
showAddUserForm();
|
||||
}
|
||||
}
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
if (password !== confirmPassword) {
|
||||
showMask('提示', '两次输入的密码不一致', [
|
||||
{
|
||||
text: '确定',
|
||||
class: 'btn-primary',
|
||||
callback: function() {
|
||||
showAddUserForm();
|
||||
}
|
||||
}
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
// 发送添加用户的请求
|
||||
ajaxRequest('../api/admin.php', {
|
||||
act: 'addUser',
|
||||
username: username,
|
||||
password: password,
|
||||
role: role
|
||||
}, function(response) {
|
||||
if (response.code === 0) {
|
||||
showMask('成功', '用户添加成功', [
|
||||
{
|
||||
text: '确定',
|
||||
class: 'btn-primary',
|
||||
callback: function() {
|
||||
window.location.reload();
|
||||
}
|
||||
}
|
||||
]);
|
||||
} else {
|
||||
showMask('错误', response.msg || '添加失败,请稍后重试', [
|
||||
{
|
||||
text: '确定',
|
||||
class: 'btn-primary',
|
||||
callback: function() {
|
||||
showAddUserForm();
|
||||
}
|
||||
}
|
||||
]);
|
||||
}
|
||||
}, function(error) {
|
||||
showMask('错误', '网络错误,请稍后重试', [
|
||||
{
|
||||
text: '确定',
|
||||
class: 'btn-primary',
|
||||
callback: function() {
|
||||
closeMask();
|
||||
}
|
||||
}
|
||||
]);
|
||||
});
|
||||
}
|
||||
}
|
||||
]);
|
||||
}
|
||||
|
||||
// 编辑用户
|
||||
function editUser(id, username, role, status) {
|
||||
var content = `
|
||||
<form id="editUserForm">
|
||||
<input type="hidden" name="id" value="${id}">
|
||||
|
||||
<div class="form-group">
|
||||
<label class="form-label">用户名</label>
|
||||
<div>${username}</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="role" class="form-label">角色</label>
|
||||
<select id="role" name="role" class="form-control">
|
||||
<option value="0" ${role == 0 ? 'selected' : ''}>普通用户</option>
|
||||
<option value="1" ${role == 1 ? 'selected' : ''}>管理员</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="status" class="form-label">状态</label>
|
||||
<select id="status" name="status" class="form-control">
|
||||
<option value="1" ${status == 1 ? 'selected' : ''}>正常</option>
|
||||
<option value="0" ${status == 0 ? 'selected' : ''}>禁用</option>
|
||||
</select>
|
||||
</div>
|
||||
</form>
|
||||
`;
|
||||
|
||||
showMask('编辑用户', content, [
|
||||
{
|
||||
text: '取消',
|
||||
class: 'btn-default',
|
||||
callback: function() {
|
||||
closeMask();
|
||||
}
|
||||
},
|
||||
{
|
||||
text: '保存',
|
||||
class: 'btn-primary',
|
||||
callback: function() {
|
||||
var form = document.getElementById('editUserForm');
|
||||
var userId = form.elements['id'].value;
|
||||
var userRole = form.elements['role'].value;
|
||||
var userStatus = form.elements['status'].value;
|
||||
|
||||
// 不能禁用自己
|
||||
if (userId == <?php echo $user['id']; ?> && userStatus == 0) {
|
||||
showMask('提示', '不能禁用当前登录的账号', [
|
||||
{
|
||||
text: '确定',
|
||||
class: 'btn-primary',
|
||||
callback: function() {
|
||||
editUser(id, username, role, status);
|
||||
}
|
||||
}
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
// 发送更新用户的请求
|
||||
ajaxRequest('../api/admin.php', {
|
||||
act: 'updateUser',
|
||||
id: userId,
|
||||
role: userRole,
|
||||
status: userStatus
|
||||
}, function(response) {
|
||||
if (response.code === 0) {
|
||||
showMask('成功', '用户信息更新成功', [
|
||||
{
|
||||
text: '确定',
|
||||
class: 'btn-primary',
|
||||
callback: function() {
|
||||
window.location.reload();
|
||||
}
|
||||
}
|
||||
]);
|
||||
} else {
|
||||
showMask('错误', response.msg || '更新失败,请稍后重试', [
|
||||
{
|
||||
text: '确定',
|
||||
class: 'btn-primary',
|
||||
callback: function() {
|
||||
closeMask();
|
||||
}
|
||||
}
|
||||
]);
|
||||
}
|
||||
}, function(error) {
|
||||
showMask('错误', '网络错误,请稍后重试', [
|
||||
{
|
||||
text: '确定',
|
||||
class: 'btn-primary',
|
||||
callback: function() {
|
||||
closeMask();
|
||||
}
|
||||
}
|
||||
]);
|
||||
});
|
||||
}
|
||||
}
|
||||
]);
|
||||
}
|
||||
|
||||
// 重置密码
|
||||
function resetPassword(id, username) {
|
||||
var content = `
|
||||
<form id="resetPasswordForm">
|
||||
<input type="hidden" name="id" value="${id}">
|
||||
<p>您将重置用户 <strong>${username}</strong> 的密码。</p>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="new_password" class="form-label">新密码</label>
|
||||
<input type="password" id="new_password" name="new_password" class="form-control" required>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="confirm_password" class="form-label">确认密码</label>
|
||||
<input type="password" id="confirm_password" name="confirm_password" class="form-control" required>
|
||||
</div>
|
||||
</form>
|
||||
`;
|
||||
|
||||
showMask('重置密码', content, [
|
||||
{
|
||||
text: '取消',
|
||||
class: 'btn-default',
|
||||
callback: function() {
|
||||
closeMask();
|
||||
}
|
||||
},
|
||||
{
|
||||
text: '确定重置',
|
||||
class: 'btn-primary',
|
||||
callback: function() {
|
||||
var form = document.getElementById('resetPasswordForm');
|
||||
var userId = form.elements['id'].value;
|
||||
var newPassword = form.elements['new_password'].value;
|
||||
var confirmPassword = form.elements['confirm_password'].value;
|
||||
|
||||
// 验证密码
|
||||
if (newPassword.length < 6) {
|
||||
showMask('提示', '密码长度不能少于6位', [
|
||||
{
|
||||
text: '确定',
|
||||
class: 'btn-primary',
|
||||
callback: function() {
|
||||
resetPassword(id, username);
|
||||
}
|
||||
}
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
if (newPassword !== confirmPassword) {
|
||||
showMask('提示', '两次输入的密码不一致', [
|
||||
{
|
||||
text: '确定',
|
||||
class: 'btn-primary',
|
||||
callback: function() {
|
||||
resetPassword(id, username);
|
||||
}
|
||||
}
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
// 发送重置密码的请求
|
||||
ajaxRequest('../api/admin.php', {
|
||||
act: 'resetPassword',
|
||||
id: userId,
|
||||
password: newPassword
|
||||
}, function(response) {
|
||||
if (response.code === 0) {
|
||||
showMask('成功', '密码重置成功', [
|
||||
{
|
||||
text: '确定',
|
||||
class: 'btn-primary',
|
||||
callback: function() {
|
||||
closeMask();
|
||||
}
|
||||
}
|
||||
]);
|
||||
} else {
|
||||
showMask('错误', response.msg || '重置失败,请稍后重试', [
|
||||
{
|
||||
text: '确定',
|
||||
class: 'btn-primary',
|
||||
callback: function() {
|
||||
closeMask();
|
||||
}
|
||||
}
|
||||
]);
|
||||
}
|
||||
}, function(error) {
|
||||
showMask('错误', '网络错误,请稍后重试', [
|
||||
{
|
||||
text: '确定',
|
||||
class: 'btn-primary',
|
||||
callback: function() {
|
||||
closeMask();
|
||||
}
|
||||
}
|
||||
]);
|
||||
});
|
||||
}
|
||||
}
|
||||
]);
|
||||
}
|
||||
|
||||
// 更改用户状态
|
||||
function changeUserStatus(id, username, status) {
|
||||
var statusText = status == 1 ? '启用' : '禁用';
|
||||
|
||||
showMask('确认操作', `确定要${statusText}用户 "${username}" 吗?`, [
|
||||
{
|
||||
text: '取消',
|
||||
class: 'btn-default',
|
||||
callback: function() {
|
||||
closeMask();
|
||||
}
|
||||
},
|
||||
{
|
||||
text: '确定',
|
||||
class: status == 1 ? 'btn-green' : 'btn-red',
|
||||
callback: function() {
|
||||
// 发送更改状态的请求
|
||||
ajaxRequest('../api/admin.php', {
|
||||
act: 'updateUser',
|
||||
id: id,
|
||||
status: status
|
||||
}, function(response) {
|
||||
if (response.code === 0) {
|
||||
showMask('成功', `用户已${statusText}`, [
|
||||
{
|
||||
text: '确定',
|
||||
class: 'btn-primary',
|
||||
callback: function() {
|
||||
window.location.reload();
|
||||
}
|
||||
}
|
||||
]);
|
||||
} else {
|
||||
showMask('错误', response.msg || '操作失败,请稍后重试', [
|
||||
{
|
||||
text: '确定',
|
||||
class: 'btn-primary',
|
||||
callback: function() {
|
||||
closeMask();
|
||||
}
|
||||
}
|
||||
]);
|
||||
}
|
||||
}, function(error) {
|
||||
showMask('错误', '网络错误,请稍后重试', [
|
||||
{
|
||||
text: '确定',
|
||||
class: 'btn-primary',
|
||||
callback: function() {
|
||||
closeMask();
|
||||
}
|
||||
}
|
||||
]);
|
||||
});
|
||||
}
|
||||
}
|
||||
]);
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user