first commit
This commit is contained in:
249
cms_admin/product_add.php
Normal file
249
cms_admin/product_add.php
Normal file
@@ -0,0 +1,249 @@
|
||||
<?php include('container/security.php'); ?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en" data-theme="light">
|
||||
<head>
|
||||
<!-- 头部链接开始 -->
|
||||
<?php include 'container/head_links.php'; ?>
|
||||
<!-- 头部链接结束 -->
|
||||
|
||||
<!-- TinyMCE脚本 -->
|
||||
<script src="https://cdn.tiny.cloud/1/lm04pa5dnd1x7omv4il6r3yz8vf0rxprjp20od48no7sk2wz/tinymce/7/tinymce.min.js" referrerpolicy="origin"></script>
|
||||
<script>
|
||||
// TinyMCE初始化
|
||||
tinymce.init({
|
||||
selector: '#long_description, #cn_long_description',
|
||||
language: 'zh_CN', // 设置语言为简体中文
|
||||
plugins: [
|
||||
'anchor', 'autolink', 'charmap', 'codesample', 'emoticons', 'image', 'link', 'lists', 'media',
|
||||
'searchreplace', 'table', 'visualblocks', 'wordcount', 'checklist', 'mediaembed', 'casechange',
|
||||
'export', 'formatpainter', 'pageembed', 'a11ychecker', 'tinymcespellchecker', 'permanentpen',
|
||||
'powerpaste', 'advtable', 'advcode', 'editimage', 'advtemplate', 'mentions', 'tinycomments',
|
||||
'tableofcontents', 'footnotes', 'mergetags', 'autocorrect', 'typography', 'inlinecss', 'markdown'
|
||||
],
|
||||
toolbar: 'undo redo | blocks fontfamily fontsize | bold italic underline strikethrough | link image media table mergetags | addcomment showcomments | spellcheckdialog a11ycheck typography | align lineheight | checklist numlist bullist indent outdent | emoticons charmap | code',
|
||||
tinycomments_mode: 'embedded',
|
||||
tinycomments_author: 'Author name',
|
||||
mergetags_list: [
|
||||
{ value: 'First.Name', title: 'First Name' },
|
||||
{ value: 'Email', title: 'Email' }
|
||||
],
|
||||
images_upload_url: 'upload.php',
|
||||
automatic_uploads: true,
|
||||
images_reuse_filename: true,
|
||||
file_picker_callback: function (callback, value, meta) {
|
||||
if (meta.filetype === 'image') {
|
||||
let input = document.createElement('input');
|
||||
input.setAttribute('type', 'file');
|
||||
input.setAttribute('accept', 'image/*');
|
||||
input.onchange = function () {
|
||||
let file = this.files[0];
|
||||
let formData = new FormData();
|
||||
formData.append('file', file);
|
||||
|
||||
fetch('upload.php', {
|
||||
method: 'POST',
|
||||
body: formData
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
callback(data.filePath, { alt: file.name });
|
||||
} else {
|
||||
alert('文件上传失败: ' + data.message);
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('错误:', error);
|
||||
alert('上传文件出错。');
|
||||
});
|
||||
};
|
||||
input.click();
|
||||
}
|
||||
},
|
||||
images_upload_handler: function (blobInfo, success, failure) {
|
||||
let formData = new FormData();
|
||||
formData.append('file', blobInfo.blob(), blobInfo.filename());
|
||||
|
||||
fetch('upload.php', {
|
||||
method: 'POST',
|
||||
body: formData
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
success(data.filePath);
|
||||
} else {
|
||||
failure('文件上传失败: ' + data.message);
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('错误:', error);
|
||||
failure('上传文件出错。');
|
||||
});
|
||||
},
|
||||
content_style: "body { font-family: Arial, 'Microsoft YaHei', sans-serif; font-size: 14px; }"
|
||||
});
|
||||
</script>
|
||||
</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工具产品</h6>
|
||||
<ul class="d-flex align-items-center gap-2">
|
||||
<li class="fw-medium">
|
||||
<a href="index-2.html" class="d-flex align-items-center gap-1 hover-text-primary">
|
||||
<iconify-icon icon="solar:home-smile-angle-outline" class="icon text-lg"></iconify-icon>
|
||||
仪表盘
|
||||
</a>
|
||||
</li>
|
||||
<li>-</li>
|
||||
<li class="fw-medium">添加产品</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="row gy-4">
|
||||
<div class="col-md-12">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h5 class="card-title mb-0">添加新产品</h5>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<form action="" method="POST">
|
||||
<div class="row gy-3">
|
||||
<div class="col-6">
|
||||
<label class="form-label">选择分类</label>
|
||||
<select name="category_id" class="form-control" required>
|
||||
<option value="">-请选择-</option>
|
||||
<?php
|
||||
$result = mysqli_query($conn, "SELECT id, c_name, cn_name FROM categories");
|
||||
while ($row = mysqli_fetch_assoc($result)) {
|
||||
echo "<option value='{$row['id']}'>{$row['c_name']} - {$row['cn_name']}</option>";
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-6">
|
||||
<label class="form-label">跟踪链接</label>
|
||||
<input type="url" name="tracking_link" class="form-control" required placeholder="输入跟踪链接">
|
||||
</div>
|
||||
<!-- 产品图标 -->
|
||||
<div class="col-6">
|
||||
<label class="form-label">产品图标</label>
|
||||
<input type="file" id="icon" class="form-control" accept="image/*" required onchange="uploadFile('icon')">
|
||||
<input type="hidden" name="icon_link" id="icon_link">
|
||||
<div id="icon_preview" style="margin-top: 10px;"></div>
|
||||
</div>
|
||||
<!-- 产品图片(可选) -->
|
||||
<div class="col-6">
|
||||
<label class="form-label">产品图片(可选)</label>
|
||||
<input type="file" id="image" class="form-control" accept="image/*" onchange="uploadFile('image')">
|
||||
<input type="hidden" name="image_link" id="image_link">
|
||||
<div id="image_preview" style="margin-top: 10px;"></div>
|
||||
</div>
|
||||
<div class="col-6">
|
||||
<label class="form-label">产品英文标题</label>
|
||||
<input type="text" name="title" class="form-control" required placeholder="输入产品英文标题">
|
||||
</div>
|
||||
<div class="col-6">
|
||||
<label class="form-label">产品中文标题</label>
|
||||
<input type="text" name="cn_title" class="form-control" required placeholder="输入产品中文标题">
|
||||
</div>
|
||||
<div class="col-6">
|
||||
<label class="form-label">英文简短描述</label>
|
||||
<textarea name="short_description" class="form-control" rows="3" maxlength="200" placeholder="编写英文描述" required></textarea>
|
||||
</div>
|
||||
<div class="col-6">
|
||||
<label class="form-label">中文简短描述</label>
|
||||
<textarea name="cn_short_description" class="form-control" rows="3" maxlength="200" placeholder="编写中文描述" required></textarea>
|
||||
</div>
|
||||
<div class="col-6">
|
||||
<label class="form-label">英文长描述(可选)</label>
|
||||
<textarea name="long_description" id="long_description" class="form-control" rows="7" placeholder="编写英文详细描述"></textarea>
|
||||
</div>
|
||||
<div class="col-6">
|
||||
<label class="form-label">中文长描述(可选)</label>
|
||||
<textarea name="cn_long_description" id="cn_long_description" class="form-control" rows="7" placeholder="编写中文详细描述"></textarea>
|
||||
</div>
|
||||
<div class="col-12">
|
||||
<button type="submit" class="btn btn-primary mt-3">添加产品</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php include 'container/footer.php' ?>
|
||||
</main>
|
||||
<?php include 'container/footer_links.php' ?>
|
||||
<script>
|
||||
// 文件上传处理函数
|
||||
function uploadFile(inputId) {
|
||||
const fileInput = document.getElementById(inputId);
|
||||
const file = fileInput.files[0];
|
||||
|
||||
if (file) {
|
||||
let formData = new FormData();
|
||||
formData.append('file', file);
|
||||
|
||||
fetch('upload.php', {
|
||||
method: 'POST',
|
||||
body: formData
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
document.getElementById(inputId + '_link').value = data.filePath;
|
||||
|
||||
const previewDiv = document.getElementById(inputId + '_preview');
|
||||
previewDiv.innerHTML = `<img src="${data.filePath}" alt="上传后的图片" style="max-width: 100px;">`;
|
||||
|
||||
alert('文件上传成功!');
|
||||
} else {
|
||||
alert('文件上传失败: ' + data.message);
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('错误:', error);
|
||||
alert('上传文件出错。');
|
||||
});
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
<?php
|
||||
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
||||
// 获取表单数据
|
||||
$category_id = intval($_POST['category_id']);
|
||||
$title = mysqli_real_escape_string($conn, $_POST['title']);
|
||||
$cn_title = mysqli_real_escape_string($conn, $_POST['cn_title']);
|
||||
$tracking_link = mysqli_real_escape_string($conn, $_POST['tracking_link']);
|
||||
$short_description = mysqli_real_escape_string($conn, $_POST['short_description']);
|
||||
$cn_short_description = mysqli_real_escape_string($conn, $_POST['cn_short_description']);
|
||||
$long_description = isset($_POST['long_description']) ? mysqli_real_escape_string($conn, $_POST['long_description']) : '';
|
||||
$cn_long_description = isset($_POST['cn_long_description']) ? mysqli_real_escape_string($conn, $_POST['cn_long_description']) : '';
|
||||
|
||||
// 获取上传的文件路径
|
||||
$icon_path = mysqli_real_escape_string($conn, $_POST['icon_link']);
|
||||
$image_path = isset($_POST['image_link']) ? mysqli_real_escape_string($conn, $_POST['image_link']) : '';
|
||||
|
||||
// 插入数据库的SQL语句
|
||||
$sql = "INSERT INTO products (category_id, title, cn_title, icon, image, tracking_link, short_description, cn_short_description, long_description, cn_long_description)
|
||||
VALUES ('$category_id', '$title', '$cn_title', '$icon_path', '$image_path', '$tracking_link', '$short_description', '$cn_short_description', '$long_description', '$cn_long_description')";
|
||||
|
||||
// 执行SQL语句
|
||||
if (mysqli_query($conn, $sql)) {
|
||||
echo "<script>alert('产品添加成功。'); window.location.href = 'product_view.php';</script>";
|
||||
} else {
|
||||
echo "<script>alert('错误: " . mysqli_error($conn) . "'); window.location.href = 'product_add.php';</script>";
|
||||
}
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user