<?php
session_start();
$servername = "localhost";
$username = "digimktgsolution_admin";
$password = "=ADP=OW?O3vl";
$database = "digimktgsolution_base";
// 创建数据库连接
$conn = new mysqli($servername, $username, $password, $database);
if ($conn->connect_error) {
die("连接失败: " . $conn->connect_error);
}
$conn->set_charset("utf8");
// 登录验证
$loginError = "";
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['login'])) {
$username = $_POST['username'];
$password = $_POST['password'];
$stmt = $conn->prepare("SELECT * FROM TMPinfobooth_Login WHERE UID = ? AND Password = ?");
$stmt->bind_param("ss", $username, $password);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows == 1) {
$_SESSION['loggedin'] = true;
} else {
$loginError = "用户名或密码不正确";
}
$stmt->close();
}
// 登出处理
if (isset($_GET['logout'])) {
session_destroy();
header("Location: " . $_SERVER['PHP_SELF']);
exit;
}
// 检查登录状态
if (!isset($_SESSION['loggedin']) || !$_SESSION['loggedin']) {
// 登录表单
?>
<!DOCTYPE html>
<html lang="zh-HK">
<head>
<meta charset="UTF-8">
<meta property="og:image" content="https://digimktgsolution.com/TMP_Infobooth/Sources/logo.jpg">
<meta property="og:image:type" content="image/jpg">
<meta property="og:image:width" content="510">
<meta property="og:image:height" content="510">
<meta property="og:title" content="TMP_Infobooth CMS" />
<meta property="og:description" content="TMP_Infobooth CMS" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CMS 登录</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
}
.login-container {
width: 300px;
padding: 20px;
background: white;
margin: 100px auto;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
border-radius: 5px;
}
input[type="text"],
input[type="password"] {
width: 100%;
padding: 10px;
margin: 8px 0;
border: 1px solid #ddd;
border-radius: 4px;
box-sizing: border-box;
}
input[type="submit"] {
width: 100%;
background: #009879;
color: white;
padding: 10px;
border: none;
border-radius: 4px;
cursor: pointer;
}
.error {
color: red;
}
</style>
</head>
<body>
<div class="login-container">
<h2>CMS 登录</h2>
<?php if ($loginError)
echo "<p class='error'>$loginError</p>"; ?>
<form method="post">
<input type="text" name="username" placeholder="用户名" required>
<input type="password" name="password" placeholder="密码" required>
<input type="submit" name="login" value="登录">
</form>
</div>
</body>
</html>
<?php
exit;
}
// 获取当前页面类型
$type = isset($_GET['type']) ? $_GET['type'] : 'main';
// 主菜单
if ($type == 'main') {
?>
<!DOCTYPE html>
<html lang="zh-HK">
<head>
<meta charset="UTF-8">
<meta property="og:image" content="https://digimktgsolution.com/TMP_Infobooth/Sources/logo.jpg">
<meta property="og:image:type" content="image/jpg">
<meta property="og:image:width" content="510">
<meta property="og:image:height" content="510">
<meta property="og:title" content="TMP_Infobooth CMS" />
<meta property="og:description" content="TMP_Infobooth CMS" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CMS 管理</title>
<style>
body {
font-family: Arial, sans-serif;
}
.container {
width: 80%;
margin: 20px auto;
}
.menu {
display: flex;
gap: 20px;
margin-bottom: 30px;
}
.menu-btn {
padding: 15px 30px;
background: #009879;
color: white;
text-decoration: none;
border-radius: 5px;
font-size: 18px;
}
.logout-btn {
padding: 8px 15px;
background: #f44336;
color: white;
text-decoration: none;
border-radius: 3px;
position: absolute;
top: 20px;
right: 20px;
}
</style>
</head>
<body>
<a href="?logout" class="logout-btn">登出</a>
<div class="container">
<h1>内容管理系统</h1>
<div class="menu">
<a href="?type=news" class="menu-btn">最新资讯管理</a>
<a href="?type=info" class="menu-btn">爬行动物资讯管理</a>
</div>
</div>
</body>
</html>
<?php
exit;
}
// 处理资讯操作
if ($type == 'news') {
// 处理新增
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['add_news'])) {
$newsTC = $_POST['news_tc'];
$newsENG = $_POST['news_eng'];
$newsSC = $_POST['news_sc'];
$stmt = $conn->prepare("INSERT INTO TMPinfobooth_News (NewsTC, NewsENG, NewsSC) VALUES (?, ?, ?)");
$stmt->bind_param("sss", $newsTC, $newsENG, $newsSC);
$stmt->execute();
$stmt->close();
header("Location: ?type=news");
exit;
}
// 处理更新
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['update_news'])) {
$id = $_POST['id'];
$newsTC = $_POST['news_tc'];
$newsENG = $_POST['news_eng'];
$newsSC = $_POST['news_sc'];
$stmt = $conn->prepare("UPDATE TMPinfobooth_News SET NewsTC=?, NewsENG=?, NewsSC=? WHERE ID=?");
$stmt->bind_param("sssi", $newsTC, $newsENG, $newsSC, $id);
$stmt->execute();
$stmt->close();
header("Location: ?type=news");
exit;
}
// 处理删除
if (isset($_GET['delete_news'])) {
$id = $_GET['delete_news'];
$stmt = $conn->prepare("DELETE FROM TMPinfobooth_News WHERE ID=?");
$stmt->bind_param("i", $id);
$stmt->execute();
$stmt->close();
header("Location: ?type=news");
exit;
}
// 获取所有资讯
$result = $conn->query("SELECT * FROM TMPinfobooth_News");
?>
<!DOCTYPE html>
<html lang="zh-HK">
<head>
<meta charset="UTF-8">
<link rel="shortcut icon" href="Sources/logo.jpg">
<meta property="og:image" content="https://digimktgsolution.com/TMP_Infobooth/Sources/logo.jpg">
<meta property="og:image:type" content="image/jpg">
<meta property="og:image:width" content="510">
<meta property="og:image:height" content="510">
<meta property="og:title" content="TMP_Infobooth CMS" />
<meta property="og:description" content="TMP_Infobooth CMS" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>最新资讯管理</title>
<style>
body {
font-family: Arial, sans-serif;
}
.container {
width: 90%;
margin: 20px auto;
}
table {
width: 100%;
border-collapse: collapse;
}
th,
td {
border: 1px solid #ddd;
padding: 8px;
text-align: left;
}
th {
background-color: #009879;
color: white;
}
tr:nth-child(even) {
background-color: #f2f2f2;
}
.btn {
padding: 5px 10px;
text-decoration: none;
border-radius: 3px;
cursor: pointer;
}
.edit-btn {
background: #4CAF50;
color: white;
}
.delete-btn {
background: #f44336;
color: white;
}
.add-btn {
background: #2196F3;
color: white;
padding: 10px 15px;
display: inline-block;
margin-bottom: 20px;
}
.modal {
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.5);
z-index: 1000;
}
.modal-content {
background: white;
margin: 10% auto;
padding: 20px;
width: 50%;
border-radius: 5px;
}
.form-group {
margin-bottom: 15px;
}
label {
display: block;
margin-bottom: 5px;
}
input[type="text"],
textarea {
width: 100%;
padding: 8px;
border: 1px solid #ddd;
border-radius: 4px;
}
</style>
</head>
<body>
<a href="?type=main" style="display:inline-block; margin:10px;">← 返回主菜单</a>
<div class="container">
<h1>最新资讯管理</h1>
<a href="#" class="add-btn" onclick="openAddModal()">新增资讯</a>
<table>
<tr>
<th>ID</th>
<th>中文资讯 (NewsTC)</th>
<th>英文资讯 (NewsENG)</th>
<th>简体资讯 (NewsSC)</th>
<th>更新时间</th>
<th>操作</th>
</tr>
<?php while ($row = $result->fetch_assoc()): ?>
<tr>
<td><?= htmlspecialchars($row['ID']) ?></td>
<td><?= htmlspecialchars($row['NewsTC']) ?></td>
<td><?= htmlspecialchars($row['NewsENG']) ?></td>
<td><?= htmlspecialchars($row['NewsSC']) ?></td>
<td><?= htmlspecialchars($row['UpdateTime']) ?></td>
<td>
<!-- 使用数据属性传递参数 -->
<button class="btn edit-btn"
data-id="<?= htmlspecialchars($row['ID']) ?>"
data-tc="<?= htmlspecialchars($row['NewsTC']) ?>"
data-eng="<?= htmlspecialchars($row['NewsENG']) ?>"
data-sc="<?= htmlspecialchars($row['NewsSC']) ?>"
>编辑</button>
<a href="?type=news&delete_news=<?= $row['ID'] ?>" class="btn delete-btn" onclick="return confirm('确定删除?')">删除</a>
</td>
</tr>
<?php endwhile; ?>
</table>
</div>
<!-- 编辑弹窗 -->
<div id="editModal" class="modal">
<div class="modal-content">
<span class="close" onclick="closeModal('editModal')">×</span>
<h2>编辑资讯</h2>
<form id="editForm" method="post">
<input type="hidden" name="id" id="editId">
<div class="form-group">
<label>中文资讯 (NewsTC):</label>
<textarea name="news_tc" id="editNewsTC" rows="3" required></textarea>
</div>
<div class="form-group">
<label>英文资讯 (NewsENG):</label>
<textarea name="news_eng" id="editNewsENG" rows="3" required></textarea>
</div>
<div class="form-group">
<label>简体资讯 (NewsSC):</label>
<textarea name="news_sc" id="editNewsSC" rows="3" required></textarea>
</div>
<div class="btn-container">
<button type="submit" name="update_news">更新</button>
<button type="button" onclick="closeModal('editModal')">取消</button>
</div>
</form>
</div>
</div>
<!-- 新增弹窗 -->
<div id="addModal" class="modal">
<div class="modal-content">
<span class="close" onclick="closeModal('addModal')">×</span>
<h2>新增资讯</h2>
<form method="post">
<div class="form-group">
<label>中文资讯 (NewsTC):</label>
<textarea name="news_tc" rows="3" required></textarea>
</div>
<div class="form-group">
<label>英文资讯 (NewsENG):</label>
<textarea name="news_eng" rows="3" required></textarea>
</div>
<div class="form-group">
<label>简体资讯 (NewsSC):</label>
<textarea name="news_sc" rows="3" required></textarea>
</div>
<div class="btn-container">
<button type="submit" name="add_news">添加</button>
<button type="button" onclick="closeModal('addModal')">取消</button>
</div>
</form>
</div>
</div>
<script>
// 为所有编辑按钮添加事件监听器
document.querySelectorAll('.edit-btn').forEach(button => {
button.addEventListener('click', function() {
// 从数据属性获取参数
const id = this.getAttribute('data-id');
const tc = this.getAttribute('data-tc');
const eng = this.getAttribute('data-eng');
const sc = this.getAttribute('data-sc');
// 打开编辑模态框
openEditModal(id, tc, eng, sc);
});
});
function openEditModal(id, newsTC, newsENG, newsSC) {
document.getElementById('editId').value = id;
document.getElementById('editNewsTC').value = newsTC;
document.getElementById('editNewsENG').value = newsENG;
document.getElementById('editNewsSC').value = newsSC;
document.getElementById('editModal').style.display = 'block';
}
function openAddModal() {
document.getElementById('addModal').style.display = 'block';
}
function closeModal(modalId) {
document.getElementById(modalId).style.display = 'none';
}
// 点击模态框外部关闭
window.onclick = function(event) {
if (event.target.className === 'modal') {
closeModal(event.target.id);
}
}
// 为关闭按钮添加事件
document.querySelectorAll('.close').forEach(closeBtn => {
closeBtn.addEventListener('click', function() {
const modal = this.closest('.modal');
closeModal(modal.id);
});
});
</script>
</body>
</html>
<?php
exit;
}
// 爬行动物资讯管理
// 爬行动物资讯管理
if ($type == 'info') {
// 处理图片上传
function handleFileUpload($file, $prefix)
{
if (!$file || !isset($file['name']) || $file['error'] != UPLOAD_ERR_OK) {
return '';
}
$targetDir = $_SERVER['DOCUMENT_ROOT'] . "/TMP_Infobooth/Sources/InformationCard/";
$fileName = $prefix . '_' . time() . '_' . basename($file['name']);
$targetFile = $targetDir . $fileName;
if (move_uploaded_file($file['tmp_name'], $targetFile)) {
return "https://digimktgsolution.com/TMP_Infobooth/Sources/InformationCard/" . $fileName;
}
return '';
}
// 处理新增
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['add_info'])) {
$type = $_POST['type'];
$tcName = $_POST['tc_name'];
$scName = $_POST['sc_name'];
$engName = $_POST['eng_name'];
$tcUrl = handleFileUpload($_FILES['tc_url'], "tc");
$scUrl = handleFileUpload($_FILES['sc_url'], "sc");
$engUrl = handleFileUpload($_FILES['eng_url'], "eng");
$stmt = $conn->prepare("INSERT INTO TMPinfobooth_InformationCard
(Type, TCName, TCUrl, SCName, SCUrl, ENGName, ENGUrl)
VALUES (?, ?, ?, ?, ?, ?, ?)");
$stmt->bind_param("sssssss", $type, $tcName, $tcUrl, $scName, $scUrl, $engName, $engUrl);
$stmt->execute();
$stmt->close();
header("Location: ?type=info");
exit;
}
// 处理更新
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['update_info'])) {
$id = $_POST['id'];
$type = $_POST['type'];
$tcName = $_POST['tc_name'];
$scName = $_POST['sc_name'];
$engName = $_POST['eng_name'];
// 获取当前数据
$current = $conn->query("SELECT * FROM TMPinfobooth_InformationCard WHERE ID = $id")->fetch_assoc();
// 处理文件上传,保留现有URL如果没有新文件上传
$tcUrl = !empty($_FILES['tc_url']['name']) ? handleFileUpload($_FILES['tc_url'], "tc") : $current['TCUrl'];
$scUrl = !empty($_FILES['sc_url']['name']) ? handleFileUpload($_FILES['sc_url'], "sc") : $current['SCUrl'];
$engUrl = !empty($_FILES['eng_url']['name']) ? handleFileUpload($_FILES['eng_url'], "eng") : $current['ENGUrl'];
$stmt = $conn->prepare("UPDATE TMPinfobooth_InformationCard
SET Type=?, TCName=?, TCUrl=?, SCName=?, SCUrl=?, ENGName=?, ENGUrl=?
WHERE ID=?");
$stmt->bind_param("sssssssi", $type, $tcName, $tcUrl, $scName, $scUrl, $engName, $engUrl, $id);
$stmt->execute();
$stmt->close();
header("Location: ?type=info");
exit;
}
// 处理删除
if (isset($_GET['delete_info'])) {
$id = $_GET['delete_info'];
$stmt = $conn->prepare("DELETE FROM TMPinfobooth_InformationCard WHERE ID=?");
$stmt->bind_param("i", $id);
$stmt->execute();
$stmt->close();
header("Location: ?type=info");
exit;
}
// 获取所有资讯并按OrderNum排序
$result = $conn->query("SELECT * FROM TMPinfobooth_InformationCard ORDER BY OrderNum ASC");
?>
<!DOCTYPE html>
<html lang="zh-HK">
<head>
<meta charset="UTF-8">
<meta property="og:image" content="https://digimktgsolution.com/TMP_Infobooth/Sources/logo.jpg">
<meta property="og:image:type" content="image/jpg">
<meta property="og:image:width" content="510">
<meta property="og:image:height" content="510">
<meta property="og:title" content="TMP_Infobooth CMS" />
<meta property="og:description" content="TMP_Infobooth CMS" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>爬行动物资讯管理</title>
<style>
body {
font-family: Arial, sans-serif;
}
.container {
width: 95%;
margin: 20px auto;
}
table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
}
th,
td {
border: 1px solid #ddd;
padding: 8px;
text-align: left;
}
th {
background-color: #009879;
color: white;
}
tr:nth-child(even) {
background-color: #f2f2f2;
}
.image-preview {
max-width: 100px;
max-height: 100px;
}
.btn {
padding: 5px 10px;
text-decoration: none;
border-radius: 3px;
cursor: pointer;
border: none;
}
.edit-btn {
background: #4CAF50;
color: white;
}
.delete-btn {
background: #f44336;
color: white;
}
.add-btn {
background: #2196F3;
color: white;
padding: 10px 15px;
display: inline-block;
margin-bottom: 20px;
text-decoration: none;
}
.modal {
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.5);
z-index: 1000;
overflow: auto;
}
.modal-content {
background: white;
margin: 5% auto;
padding: 20px;
width: 80%;
max-width: 700px;
border-radius: 5px;
position: relative;
}
.close {
position: absolute;
top: 10px;
right: 15px;
font-size: 24px;
cursor: pointer;
}
.form-group {
margin-bottom: 15px;
}
label {
display: block;
margin-bottom: 5px;
font-weight: bold;
}
input[type="text"],
select {
width: 100%;
padding: 8px;
border: 1px solid #ddd;
border-radius: 4px;
box-sizing: border-box;
}
.form-row {
display: flex;
gap: 15px;
margin-bottom: 15px;
}
.form-col {
flex: 1;
}
.image-upload {
border: 1px dashed #ccc;
padding: 10px;
text-align: center;
margin-top: 5px;
}
.current-image {
max-width: 100px;
max-height: 100px;
margin-top: 10px;
}
.btn-container {
display: flex;
gap: 10px;
margin-top: 20px;
}
.btn-container button {
padding: 8px 15px;
cursor: pointer;
}
</style>
</head>
<body>
<a href="?type=main" style="display:inline-block; margin:10px;">← 返回主菜单</a>
<div class="container">
<h1>爬行动物资讯管理</h1>
<a href="#" class="add-btn" onclick="openAddModal()">新增资讯</a>
<table>
<tr>
<th>ID</th>
<th>类型 (Type)</th>
<th>繁体名称 (TCName)</th>
<th>繁体图片 (TCUrl)</th>
<th>简体名称 (SCName)</th>
<th>简体图片 (SCUrl)</th>
<th>英文名称 (ENGName)</th>
<th>英文图片 (ENGUrl)</th>
<th>更新时间</th>
<th>操作</th>
</tr>
<?php while ($row = $result->fetch_assoc()): ?>
<tr>
<td><?= htmlspecialchars($row['ID']) ?></td>
<td><?= htmlspecialchars($row['Type']) ?></td>
<td><?= htmlspecialchars($row['TCName']) ?></td>
<td>
<?php if (!empty($row['TCUrl'])): ?>
<img src="<?= htmlspecialchars($row['TCUrl']) ?>" class="image-preview">
<?php else: ?>
-
<?php endif; ?>
</td>
<td><?= htmlspecialchars($row['SCName']) ?></td>
<td>
<?php if (!empty($row['SCUrl'])): ?>
<img src="<?= htmlspecialchars($row['SCUrl']) ?>" class="image-preview">
<?php else: ?>
-
<?php endif; ?>
</td>
<td><?= htmlspecialchars($row['ENGName']) ?></td>
<td>
<?php if (!empty($row['ENGUrl'])): ?>
<img src="<?= htmlspecialchars($row['ENGUrl']) ?>" class="image-preview">
<?php else: ?>
-
<?php endif; ?>
</td>
<td><?= htmlspecialchars($row['UpdateTime']) ?></td>
<td>
<button class="btn edit-btn" onclick="openEditModal(
<?= $row['ID'] ?>,
'<?= addslashes($row['Type']) ?>',
'<?= addslashes($row['TCName']) ?>',
'<?= addslashes($row['TCUrl']) ?>',
'<?= addslashes($row['SCName']) ?>',
'<?= addslashes($row['SCUrl']) ?>',
'<?= addslashes($row['ENGName']) ?>',
'<?= addslashes($row['ENGUrl']) ?>'
)">编辑</button>
<a href="?type=info&delete_info=<?= $row['ID'] ?>" class="btn delete-btn"
onclick="return confirm('确定删除?')">删除</a>
</td>
</tr>
<?php endwhile; ?>
</table>
</div>
<!-- 编辑弹窗 -->
<div id="editModal" class="modal">
<div class="modal-content">
<span class="close" onclick="closeModal('editModal')">×</span>
<h2>编辑资讯</h2>
<form id="editForm" method="post" enctype="multipart/form-data">
<input type="hidden" name="id" id="editId">
<div class="form-row">
<div class="form-col">
<div class="form-group">
<label>类型 (Type):</label>
<input type="text" name="type" id="editType" required>
</div>
</div>
</div>
<div class="form-row">
<div class="form-col">
<div class="form-group">
<label>繁体名称 (TCName):</label>
<input type="text" name="tc_name" id="editTCName" required>
</div>
</div>
<div class="form-col">
<div class="form-group">
<label>简体名称 (SCName):</label>
<input type="text" name="sc_name" id="editSCName" required>
</div>
</div>
<div class="form-col">
<div class="form-group">
<label>英文名称 (ENGName):</label>
<input type="text" name="eng_name" id="editENGName" required>
</div>
</div>
</div>
<div class="form-row">
<div class="form-col">
<div class="form-group">
<label>繁体图片 (TCUrl):</label>
<div class="image-upload">
<input type="file" name="tc_url" accept="image/*">
<div id="editTCImagePreview"></div>
</div>
</div>
</div>
<div class="form-col">
<div class="form-group">
<label>简体图片 (SCUrl):</label>
<div class="image-upload">
<input type="file" name="sc_url" accept="image/*">
<div id="editSCImagePreview"></div>
</div>
</div>
</div>
<div class="form-col">
<div class="form-group">
<label>英文图片 (ENGUrl):</label>
<div class="image-upload">
<input type="file" name="eng_url" accept="image/*">
<div id="editENGImagePreview"></div>
</div>
</div>
</div>
</div>
<div class="btn-container">
<button type="submit" name="update_info">更新</button>
<button type="button" onclick="closeModal('editModal')">取消</button>
</div>
</form>
</div>
</div>
<!-- 新增弹窗 -->
<div id="addModal" class="modal">
<div class="modal-content">
<span class="close" onclick="closeModal('addModal')">×</span>
<h2>新增资讯</h2>
<form method="post" enctype="multipart/form-data">
<div class="form-row">
<div class="form-col">
<div class="form-group">
<label>类型 (Type):</label>
<input type="text" name="type" required>
</div>
</div>
</div>
<div class="form-row">
<div class="form-col">
<div class="form-group">
<label>繁体名称 (TCName):</label>
<input type="text" name="tc_name" required>
</div>
</div>
<div class="form-col">
<div class="form-group">
<label>简体名称 (SCName):</label>
<input type="text" name="sc_name" required>
</div>
</div>
<div class="form-col">
<div class="form-group">
<label>英文名称 (ENGName):</label>
<input type="text" name="eng_name" required>
</div>
</div>
</div>
<div class="form-row">
<div class="form-col">
<div class="form-group">
<label>繁体图片 (TCUrl):</label>
<div class="image-upload">
<input type="file" name="tc_url" accept="image/*" required>
</div>
</div>
</div>
<div class="form-col">
<div class="form-group">
<label>简体图片 (SCUrl):</label>
<div class="image-upload">
<input type="file" name="sc_url" accept="image/*" required>
</div>
</div>
</div>
<div class="form-col">
<div class="form-group">
<label>英文图片 (ENGUrl):</label>
<div class="image-upload">
<input type="file" name="eng_url" accept="image/*" required>
</div>
</div>
</div>
</div>
<div class="btn-container">
<button type="submit" name="add_info">添加</button>
<button type="button" onclick="closeModal('addModal')">取消</button>
</div>
</form>
</div>
</div>
<script>
function openEditModal(id, type, tcName, tcUrl, scName, scUrl, engName, engUrl) {
document.getElementById('editId').value = id;
document.getElementById('editType').value = type;
document.getElementById('editTCName').value = tcName;
document.getElementById('editSCName').value = scName;
document.getElementById('editENGName').value = engName;
// 显示预览图
document.getElementById('editTCImagePreview').innerHTML = tcUrl ?
`<p>当前图片:</p><img src="${tcUrl}" class="current-image">` :
'<p>无图片</p>';
document.getElementById('editSCImagePreview').innerHTML = scUrl ?
`<p>当前图片:</p><img src="${scUrl}" class="current-image">` :
'<p>无图片</p>';
document.getElementById('editENGImagePreview').innerHTML = engUrl ?
`<p>当前图片:</p><img src="${engUrl}" class="current-image">` :
'<p>无图片</p>';
document.getElementById('editModal').style.display = 'block';
}
function openAddModal() {
document.getElementById('addModal').style.display = 'block';
}
function closeModal(modalId) {
document.getElementById(modalId).style.display = 'none';
}
// 点击模态框外部关闭
window.onclick = function (event) {
if (event.target.className === 'modal') {
closeModal(event.target.id);
}
}
// 点击关闭按钮
document.querySelectorAll('.close').forEach(closeBtn => {
closeBtn.addEventListener('click', function () {
const modal = this.closest('.modal');
modal.style.display = 'none';
});
});
</script>
</body>
</html>
<?php
exit;
}
?>
使用以上代碼,在最新资讯管理新增和編輯裏面的輸入框,要驗證輸入的是不是分別是繁體,英文和簡體在指定輸入框