源代码: admin-index2.php
<?php
file_put_contents("fail.json", "[]");
include __DIR__ . "/../password.php";
require_once __DIR__ . "/helpers.php";
function renderTableRow($item, $counter)
{
$itemId = htmlspecialchars($item["id"]);
$domain = htmlspecialchars($item["domain"]);
$description = htmlspecialchars($item["description"]);
$master = htmlspecialchars($item["master"]);
$email = htmlspecialchars($item["email"]);
// 向下兼容
$join_date = htmlspecialchars($item["join_date"] ?? '', ENT_QUOTES, 'UTF-8');
return <<<HTML
<tr id="item-$itemId">
<td>$counter</td>
<td>$itemId</td>
<td>$domain</td>
<td>$description</td>
<td>$master</td>
<td>$email</td>
<td>$join_date</td>
<td>
<button class="mdui-btn mdui-btn-raised mdui-ripple mdui-color-red" onclick="confirmDelete('$itemId')">删除</button>
</td>
</tr>
HTML;
}
if (!empty($_GET["password"]) && $_GET["password"] == $password) {
if (!empty($_POST["fail"])) {
header('Content-Type: application/json');
searchAndMoveValue(__DIR__ . "/../Assets/data/json/idinfo.json", "fail.json", "id", $_POST["fail"]);
searchAndMoveValue2(__DIR__ . "/../Assets/data/json/id.json", "fail.json", $_POST["fail"]);
echo json_encode(["status" => "success"]);
exit;
}
// Pagination setup
$data = json_decode(file_get_contents(__DIR__ . "/../Assets/data/json/idinfo.json"), true);
$totalItems = count($data);
$itemsPerPage = 10; // 每页显示的项目数量
$currentPage = isset($_GET['page']) ? (int)$_GET['page'] : 1;
$totalPages = ceil($totalItems / $itemsPerPage);
// 计算当前页显示的项目
$startIndex = ($currentPage - 1) * $itemsPerPage;
$currentPageData = array_slice($data, $startIndex, $itemsPerPage);
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>域名列表の后台</title>
<link rel="stylesheet" href="/Assets/css/mdui.min.css">
<link href="https://cdn.bootcdn.net/ajax/libs/nprogress/0.2.0/nprogress.min.css" rel="stylesheet">
<script src="https://cdn.bootcdn.net/ajax/libs/nprogress/0.2.0/nprogress.min.js"></script>
<script>
NProgress.configure({
minimum: 0.08,
showSpinner: true,
parent: '#item-list'
})
window.addEventListener('load', () => {
NProgress.done();
});
document.addEventListener('readystatechange', () => {
if (document.readyState === 'interactive') {
NProgress.start();
} else if (document.readyState === 'complete') {
NProgress.done();
}
});
</script>
</head>
<body>
<div class="mdui-container mdui-typo">
<h1 class="mdui-typo-display-1">
域名列表の后台
<a no-pjax href="index1.php?password=<?php echo htmlspecialchars($_GET["password"]); ?>">前往 - 等待审核列表</a>
|
<a no-pjax href="index3.php?password=<?php echo htmlspecialchars($_GET["password"]); ?>">前往 - 编辑公告</a>
</h1>
<div class="mdui-divider"></div>
<div id="item-list">
<?php
if (!empty($currentPageData)) {
echo <<<HTML
<div class="mdui-table-fluid">
<table class="mdui-table mdui-table-hoverable">
<thead>
<tr><th>#</th><th>ID</th><th>域名</th><th>介绍</th><th>站长</th><th>邮箱</th><th>加入时间</th><th>操作</th></tr>
</thead>
<tbody>
HTML;
$counter = $startIndex + 1;
foreach ($currentPageData as $item) {
echo renderTableRow($item, $counter);
$counter++;
}
echo '</tbody>';
echo '</table>';
echo '</div>';
// Pagination controls
echo '<div class="mdui-m-y-4 mdui-center">';
if ($currentPage > 1) {
$prevPage = $currentPage - 1;
echo "<a href=\"?page=$prevPage&password={$password}\" class=\"mdui-btn mdui-btn-raised mdui-ripple mdui-float-left\">上一页</a>";
}
if ($currentPage < $totalPages) {
$nextPage = $currentPage + 1;
echo "<a href=\"?page=$nextPage&password={$password}\" class=\"mdui-btn mdui-btn-raised mdui-ripple mdui-float-right\">下一页</a>";
}
echo '</div>';
echo '</div>';
} else {
echo '<div class="mdui-m-y-4 mdui-center">';
echo '<h3 class="mdui-typo-display-2 mdui-text-color-grey-500">暂无域名记录</h3>';
echo '</div>';
}
?>
</div>
</div>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery.pjax/2.0.1/jquery.pjax.min.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/mdui/1.0.2/js/mdui.min.js"></script>
<script>
function confirmDelete(id) {
if (confirm(`确认删除ID为:${id}?`)) {
deleteItem(id);
}
}
$(document).pjax('a:not(a[target="_blank"],a[no-pjax])', {
container: '#item-list',
fragment: '#item-list',
timeout: 20000
});
$(document).on('pjax:send', function() {
NProgress.start();
});
$(document).on('pjax:end', function() {
NProgress.done();
});
function deleteItem(id) {
$.ajax({
url: 'index2.php?password=<?php echo htmlspecialchars($_GET["password"]); ?>',
type: 'POST',
data: {
fail: id,
},
success: function(response) {
if (response.status === 'success') {
$('#item-' + id).fadeOut(500, function() {
$(this).remove();
});
mdui.snackbar({
message: `删除 ${id} 成功`,
position: 'left-bottom',
});
} else {
alert('操作失败: ' + response);
}
},
error: function() {
alert('请求失败,请稍后再试。');
}
});
}
</script>
</body>
</html>
<?php
} else {
http_response_code(404);
}
这个网站由wusheng233制作,生成了静态页面