AIPT/cms_admin/contact-form.php

122 lines
5.7 KiB
PHP
Raw Permalink Normal View History

2024-10-29 11:42:53 +08:00
<?php
include('container/security.php');
// 处理删除请求
if (isset($_POST['delete_id'])) {
$delete_id = intval($_POST['delete_id']);
$delete_query = "DELETE FROM tools_submission WHERE id = $delete_id";
if (mysqli_query($conn, $delete_query)) {
echo json_encode(['status' => 'success']);
} else {
echo json_encode(['status' => 'error', 'message' => '删除失败']);
}
exit; // 终止脚本以避免输出额外内容
}
?>
<!DOCTYPE html>
<html lang="en" data-theme="light">
<head>
<?php include 'container/head_links.php'; ?>
</head>
<body>
<?php include 'container/side_bar.php'; ?>
<main class="dashboard-main">
<?php include 'container/header.php'; ?>
<div class="dashboard-main-body">
<div class="d-flex flex-wrap align-items-center justify-content-between gap-3 mb-24">
<h6 class="fw-semibold mb-0">AI Tool Submission Data</h6>
</div>
<div class="card basic-data-table">
<div class="card-header">
<h5 class="card-title mb-0">All Submitted AI Tools List</h5>
</div>
<div class="card-body">
<table class="table bordered-table mb-0" id="dataTable" data-page-length='10'>
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Domain</th>
<th scope="col">Logo</th>
<th scope="col">Product Name</th>
<th scope="col">Description</th>
<th scope="col">Submission Date</th>
<th scope="col">Language</th>
<th scope="col">IP Address</th>
<th scope="col">Actions</th>
</tr>
</thead>
<tbody>
<?php
$result = mysqli_query($conn, "SELECT id, product_name, domain, logo_url, description, submitted_at, language, submitted_ip FROM tools_submission ORDER BY submitted_at DESC");
$i = 1;
while ($row = mysqli_fetch_assoc($result)) {
$submission_id = $row['id'];
$product_name = htmlspecialchars($row['product_name']);
$domain = htmlspecialchars($row['domain']);
$logo_url = htmlspecialchars($row['logo_url']);
$description = htmlspecialchars($row['description']);
$submitted_at = htmlspecialchars($row['submitted_at']);
$language = htmlspecialchars($row['language']);
$submitted_ip = htmlspecialchars($row['submitted_ip']);
echo "
<tr id='row-$submission_id'>
<td>$i</td>
<td>$domain</td>
<td>
<img src='$logo_url' alt='Logo' class='thumbnail' style='max-width: 50px; max-height: 50px;'>
</td>
<td>$product_name</td>
<td><textarea readonly class='form-control' rows='2' style='width:200px;'>$description</textarea></td>
<td>$submitted_at</td>
<td>$language</td>
<td>$submitted_ip</td>
<td>
<a href='javascript:void(0);' class='delete-btn' data-id='$submission_id' title='Delete'>
<iconify-icon icon='mingcute:delete-2-line'></iconify-icon>
</a>
</td>
</tr>";
$i++;
}
mysqli_close($conn);
?>
</tbody>
</table>
</div>
</div>
</div>
<?php include 'container/footer.php'; ?>
</main>
<?php include 'container/footer_links.php'; ?>
<script>
let table = new DataTable('#dataTable');
// 删除功能
document.querySelectorAll('.delete-btn').forEach(button => {
button.addEventListener('click', function() {
let submissionId = this.getAttribute('data-id');
if (confirm("Are you sure you want to delete this submission?")) {
fetch('', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
body: new URLSearchParams({ 'delete_id': submissionId })
})
.then(response => response.json())
.then(data => {
if (data.status === 'success') {
document.getElementById('row-' + submissionId).remove();
} else {
alert(data.message || '删除失败');
}
});
}
});
});
</script>
</body>
</html>