166 lines
5.7 KiB
PHP
166 lines
5.7 KiB
PHP
<?php
|
|
/**
|
|
* 班级操行分管理系统 - 管理端历史记录
|
|
*
|
|
* 开发者: Canglan
|
|
* 联系方式: admin@sea-studio.top
|
|
* 版权归属: Sea Network Technology Studio
|
|
* 许可证: MIT License
|
|
*
|
|
* 版权所有 © Sea Network Technology Studio
|
|
*/
|
|
|
|
require_once __DIR__ . '/../config.php';
|
|
|
|
if (!isset($_SESSION['user_id']) || $_SESSION['user_type'] !== 'admin') {
|
|
header('Location: /index.php');
|
|
exit();
|
|
}
|
|
|
|
$page_title = '历史记录';
|
|
$role = $_SESSION['role'] ?? '';
|
|
include __DIR__ . '/../includes/header.php';
|
|
?>
|
|
|
|
<div class="nav">
|
|
<a href="/admin/dashboard.php" class="nav-item">首页</a>
|
|
<a href="/admin/students.php" class="nav-item">学生管理</a>
|
|
<?php if ($role === '班主任' || $role === '班长'): ?>
|
|
<a href="/admin/conduct.php" class="nav-item">操行分管理</a>
|
|
<?php endif; ?>
|
|
<?php if ($role === '班主任' || $role === '科代表'): ?>
|
|
<a href="/admin/homework.php" class="nav-item">作业管理</a>
|
|
<?php endif; ?>
|
|
<?php if ($role === '班主任' || $role === '考勤委员'): ?>
|
|
<a href="/admin/attendance.php" class="nav-item">考勤管理</a>
|
|
<?php endif; ?>
|
|
<?php if ($role === '班主任'): ?>
|
|
<a href="/admin/subjects.php" class="nav-item">科目管理</a>
|
|
<a href="/admin/admins.php" class="nav-item">管理员管理</a>
|
|
<?php endif; ?>
|
|
<a href="/admin/history.php" class="nav-item active">历史记录</a>
|
|
<a href="/admin/password.php" class="nav-item">修改密码</a>
|
|
</div>
|
|
|
|
<div class="container">
|
|
<div class="card">
|
|
<div class="filter-bar">
|
|
<div class="filter-group">
|
|
<label>开始日期</label>
|
|
<input type="date" id="historyStartDate">
|
|
</div>
|
|
<div class="filter-group">
|
|
<label>结束日期</label>
|
|
<input type="date" id="historyEndDate">
|
|
</div>
|
|
<div class="filter-group">
|
|
<label>学生</label>
|
|
<select id="historyStudentId">
|
|
<option value="">全部</option>
|
|
</select>
|
|
</div>
|
|
<button class="btn btn-primary" onclick="loadHistory(1)">查询</button>
|
|
</div>
|
|
|
|
<div class="table-wrapper">
|
|
<table class="table">
|
|
<thead>
|
|
<tr>
|
|
<th>时间</th>
|
|
<th>学生</th>
|
|
<th>分数变动</th>
|
|
<th>原因</th>
|
|
<th>操作人</th>
|
|
<?php if ($role === '班主任' || $role === '班长'): ?>
|
|
<th>操作</th>
|
|
<?php endif; ?>
|
|
</tr>
|
|
</thead>
|
|
<tbody id="historyList"></tbody>
|
|
</table>
|
|
</div>
|
|
<div class="pagination" id="historyPagination"></div>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
let currentHistoryPage = 1;
|
|
let totalHistoryPages = 1;
|
|
|
|
async function loadStudentsForSelect() {
|
|
const res = await apiGet('/api/admin/students');
|
|
if (res && res.success) {
|
|
let html = '<option value="">全部</option>';
|
|
res.data.students.forEach(s => {
|
|
html += `<option value="${s.student_id}">${escapeHtml(s.student_no)} - ${escapeHtml(s.name)}</option>`;
|
|
});
|
|
document.getElementById('historyStudentId').innerHTML = html;
|
|
}
|
|
}
|
|
|
|
async function loadHistory(page = 1) {
|
|
currentHistoryPage = page;
|
|
const startDate = document.getElementById('historyStartDate').value;
|
|
const endDate = document.getElementById('historyEndDate').value;
|
|
const studentId = document.getElementById('historyStudentId').value;
|
|
|
|
const res = await apiGet('/api/admin/conduct/history', {
|
|
page, page_size: 20,
|
|
start_date: startDate,
|
|
end_date: endDate,
|
|
student_id: studentId
|
|
});
|
|
|
|
if (res && res.success) {
|
|
let html = '';
|
|
res.data.records.forEach(record => {
|
|
const pointsClass = record.points_change > 0 ? 'plus' : 'minus';
|
|
html += `<tr>
|
|
<td>${formatDateTime(record.created_at)}</td>
|
|
<td>${escapeHtml(record.student_name)}</td>
|
|
<td class="${pointsClass}">${record.points_change > 0 ? '+' : ''}${record.points_change}</td>
|
|
<td>${escapeHtml(record.reason)}</td>
|
|
<td>${escapeHtml(record.recorder_name)}</td>`;
|
|
<?php if ($role === '班主任' || $role === '班长'): ?>
|
|
html += `<td><button class="btn btn-sm btn-danger" onclick="revokeRecord(${record.record_id})">撤销</button></td>`;
|
|
<?php endif; ?>
|
|
html += `</tr>`;
|
|
});
|
|
|
|
if (res.data.records.length === 0) {
|
|
const colSpan = <?php echo ($role === '班主任' || $role === '班长') ? '6' : '5'; ?>;
|
|
html = `<tr><td colspan="${colSpan}" style="text-align:center;">暂无记录</td></tr>`;
|
|
}
|
|
|
|
document.getElementById('historyList').innerHTML = html;
|
|
|
|
totalHistoryPages = res.data.total_pages || 1;
|
|
renderHistoryPagination();
|
|
}
|
|
}
|
|
|
|
function renderHistoryPagination() {
|
|
const container = document.getElementById('historyPagination');
|
|
if (!container) return;
|
|
if (totalHistoryPages <= 1) {
|
|
container.innerHTML = '';
|
|
return;
|
|
}
|
|
|
|
let html = '';
|
|
for (let i = 1; i <= totalHistoryPages; i++) {
|
|
if (i === currentHistoryPage) {
|
|
html += `<span class="active">${i}</span>`;
|
|
} else {
|
|
html += `<a href="#" onclick="loadHistory(${i}); return false;">${i}</a>`;
|
|
}
|
|
}
|
|
container.innerHTML = html;
|
|
}
|
|
|
|
loadStudentsForSelect();
|
|
loadHistory();
|
|
</script>
|
|
<script src="/assets/js/admin.js"></script>
|
|
|
|
<?php include __DIR__ . '/../includes/footer.php'; ?>
|