AIPT/en/contact.php

399 lines
19 KiB
PHP
Raw Normal View History

2024-10-29 11:42:53 +08:00
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<?php
// Set SEO information for the Join Us page
$title = "Submit Your AI Tool - AI Tool Path";
$description = "Join us in advancing and innovating AI tools. Submit your AI tool to help more users discover and utilize your products.";
$keywords = "Join us, AI tools, artificial intelligence, AI development, AI innovation, AI industry trends, AI Tool Path";
include('container/links.php');
?>
<?php
// Check if form is submitted
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
// Check if required fields are set and not empty
if (
isset($_POST['product_name'], $_POST['domain'], $_POST['keywords'], $_POST['description'], $_POST['ai_description']) &&
!empty($_POST['product_name']) && !empty($_POST['domain']) && !empty($_POST['keywords']) &&
!empty($_POST['description']) && !empty($_POST['ai_description'])
) {
// Database connection setup (ensure $conn is defined)
// $conn = new mysqli('host', 'username', 'password', 'database');
// Get form inputs with strict filtering
$product_name = htmlspecialchars(mysqli_real_escape_string($conn, $_POST['product_name']), ENT_QUOTES, 'UTF-8');
$domain = filter_var(mysqli_real_escape_string($conn, $_POST['domain']), FILTER_SANITIZE_URL);
$logo_url = isset($_POST['logo_url']) ? htmlspecialchars(mysqli_real_escape_string($conn, $_POST['logo_url']), ENT_QUOTES, 'UTF-8') : null;
$screenshot_url = isset($_POST['screenshot_url']) ? htmlspecialchars(mysqli_real_escape_string($conn, $_POST['screenshot_url']), ENT_QUOTES, 'UTF-8') : null;
$keywords = htmlspecialchars(mysqli_real_escape_string($conn, $_POST['keywords']), ENT_QUOTES, 'UTF-8');
$description = htmlspecialchars(mysqli_real_escape_string($conn, $_POST['description']), ENT_QUOTES, 'UTF-8');
$ai_description = htmlspecialchars(mysqli_real_escape_string($conn, $_POST['ai_description']), ENT_QUOTES, 'UTF-8');
// Get user's IP address
$submitted_ip = $_SERVER['REMOTE_ADDR'];
$language = 'en'; // Specify the language as English ('en')
// Check for existing submission with the same domain or IP address
$parsed_domain = parse_url($domain, PHP_URL_HOST);
$check_query = "SELECT * FROM tools_submission WHERE domain LIKE '%$parsed_domain%' OR submitted_ip = '$submitted_ip'";
$check_result = mysqli_query($conn, $check_query);
if (mysqli_num_rows($check_result) > 0) {
// Set custom header to indicate duplicate submission
header("X-Response-Status: duplicate");
echo "<script>layui.layer.msg('You have already submitted this domain or IP address. Please do not submit again.', {icon: 5});</script>";
} else {
// Insert query
$qry = "INSERT INTO tools_submission (product_name, domain, logo_url, screenshot_url, keywords, description, features_description, submitted_ip, language) VALUES ('$product_name', '$domain', '$logo_url', '$screenshot_url', '$keywords', '$description', '$ai_description', '$submitted_ip', '$language')";
// Execute the query
$run = mysqli_query($conn, $qry);
if ($run) {
// Set custom header to indicate successful submission
header("X-Response-Status: success");
echo "<script>layui.layer.msg('Submission successful. It will be displayed after approval.', {icon: 1});</script>";
echo "<script>window.location.reload();</script>"; // Reload page after submission
} else {
// Set custom header to indicate submission failure
header("X-Response-Status: error");
echo "<script>layui.layer.msg('Form submission failed. Error message: " . addslashes($conn->error) . "', {icon: 5});</script>";
}
}
} else {
// Set custom header to indicate missing fields
header("X-Response-Status: missing_fields");
echo "<script>layui.layer.msg('Please fill in all required fields.', {icon: 5});</script>";
}
}
?>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/layui-src/dist/layui.all.js"></script> <!-- Load layui.js -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/layui-src/dist/css/layui.css" /> <!-- Load layui.css -->
<style>
body {
color: var(--thm-gray) !important;
}
.loading-mask {
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.5);
z-index: 9999;
text-align: center;
}
.loading-mask .loading-text {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
color: #fff;
font-size: 1.5em;
}
.thumbnail {
max-width: 120px;
margin-top: 10px;
}
.contact-one__form-box {
max-width: 800px; /* Control form size */
margin: 0 auto; /* Center form */
}
.form-group {
margin-bottom: 20px;
}
textarea {
max-height: 200px;
overflow: auto; /* Allow scrolling when content overflows */
resize: vertical; /* Allow users to resize vertically */
}
.file-input {
display: none; /* Hide file input button */
}
</style>
</head>
<body class="body-bg-color">
<!-- Header -->
<?php include 'container/header.php' ?>
<!-- Page Title Start -->
<section class="page-title">
<div class="container">
<div class="page-title__inner">
<div class="page-title__shape-1" style="background-image: url(images/shapes/page-title-shape-1.png);"></div>
<div class="page-title__title-box">
<p class="page-title__sub-title">Submit Your AI Tool</p>
<h3 class="page-title__title">Submit your AI tool and let more users discover and use it.</h3>
</div>
<p class="page-title__text">Master the art of AI tools: unleash the power of automation and creativity with AI Tool Path</p>
<p class="page-title__text">Business cooperation: admin@aitoolpath.com</p>
<p class="page-title__text">Tool review: a1726850085@outlook.com</p>
</div>
</div>
</section>
<!-- Page Title End -->
<!-- Contact One Start -->
<section class="contact-one">
<div class="container">
<div class="row">
<div class="col-xl-12 col-lg-12">
<div class="contact-one__right">
<div class="contact-one__form-box">
<h3 class="contact-one__form-title">Submit Your AI Tool</h3>
<form method="POST" action="" id="tool-form">
<div class="form-group">
<p class="contact-one__form-label">Product Name *</p>
<input type="text" name="product_name" id="product_name" placeholder="Product Name" maxlength="20" required="">
</div>
<div class="form-group">
<p class="contact-one__form-label">Domain *</p>
<input type="text" name="domain" id="domain" placeholder=" https://www.aitoolpath.com" maxlength="30" required="">
</div>
<div class="form-group">
<button type="button" class="thm-btn" id="ai-fill-button">Auto Fill with AI</button>
</div>
<div class="form-group">
<p class="contact-one__form-label">Logo URL</p>
<input type="text" name="logo_url" id="logo_url" maxlength="300">
<input type="file" id="logo_file" class="file-input">
<button type="button" class="thm-btn" id="upload-logo">Upload Logo</button>
<img id="logo_thumbnail" class="thumbnail" style="display:none;">
</div>
<div class="form-group">
<p class="contact-one__form-label">Screenshot URL</p>
<input type="text" name="screenshot_url" id="screenshot_url" maxlength="300">
<input type="file" id="screenshot_file" class="file-input">
<button type="button" class="thm-btn" id="upload-screenshot">Upload Screenshot</button>
<img id="screenshot_thumbnail" class="thumbnail" style="display:none;">
</div>
<div class="form-group">
<p class="contact-one__form-label">Keywords *</p>
<input type="text" name="keywords" placeholder='AI video, AI chat' id="keywords" maxlength="120" required="">
</div>
<div class="form-group text-message-box">
<p class="contact-one__form-label">Description *</p>
<textarea name="description" id="description" placeholder='One-sentence introduction' maxlength="160" required=""></textarea>
</div>
<div class="form-group text-message-box">
<p class="contact-one__form-label">Feature Description *</p>
<textarea name="ai_description" id="ai_description" placeholder='Introduce the features, the more detailed the better' maxlength="1000" required=""></textarea>
</div>
<div class="form-group">
<div class="button-box">
<button type="submit" class="thm-btn contact-one__btn" data-loading-text="Please wait...">Submit Tool</button>
</div>
</div>
</form>
<p class="ajax-response mb-0"></p>
</div>
</div>
</div>
</div>
</div>
</section>
<!-- Contact One End -->
<!-- Loading Mask -->
<div class="loading-mask" id="loading-mask">
<div class="loading-text">Processing, please wait...</div>
</div>
<!-- Free Trial Start -->
<?php include 'container/free_trail.php' ?>
<!-- Free Trial End -->
<!-- Main Footer Start -->
<?php include 'container/footer.php' ?>
<!-- Main Footer End -->
<?php include 'container/footer_links.php' ?>
<script>
// Form submission handling
$('#tool-form').on('submit', function(e) {
e.preventDefault(); // Prevent default form submission
// Check if required fields are filled
if (!$('#product_name').val() || !$('#domain').val() || !$('#keywords').val() || !$('#description').val() || !$('#ai_description').val()) {
layui.layer.msg("Please fill in all required fields.", { icon: 5 });
return;
}
// Check if domain format is correct
var domain = $('#domain').val();
var domainRegex = /^(https?:\/\/)?([\w-]+\.)+[\w-]+(\/[\w-]*)*$/; // Simple domain validation regex
if (!domainRegex.test(domain)) {
layui.layer.msg("Please enter a valid domain, e.g. https://www.example.com", { icon: 5 });
return;
}
// Show loading mask and disable button
$('#loading-mask').show();
$('.contact-one__btn').attr('disabled', true);
// Submit the form
$.ajax({
url: '', // Current page, submitted to PHP processing
type: 'POST',
data: $(this).serialize(),
success: function(response, textStatus, request) {
$('#loading-mask').hide();
$('.contact-one__btn').attr('disabled', false);
// Display different messages based on the response header X-Response-Status
var responseStatus = request.getResponseHeader('X-Response-Status');
switch (responseStatus) {
case 'success':
layui.layer.msg('Submission successful. It will be displayed after approval.', { icon: 1 }, function() {
// Redirect to the specified page after the success message
window.location.href = 'contact';
});
break;
case 'duplicate':
layui.layer.msg('You have already submitted this domain or IP address. Please do not submit again.', { icon: 5 });
break;
case 'error':
layui.layer.msg('Form submission failed. Please try again.', { icon: 5 });
break;
case 'missing_fields':
layui.layer.msg('Please fill in all required fields.', { icon: 5 });
break;
default:
layui.layer.msg('An unknown error occurred. Please try again.', { icon: 5 });
}
},
error: function(xhr, status, error) {
$('#loading-mask').hide();
$('.contact-one__btn').attr('disabled', false);
layui.layer.msg('Request failed. Please try again.', { icon: 5 });
}
});
});
</script>
<script>
// AI Fill button click event
$('#ai-fill-button').click(function() {
var domain = $('#domain').val();
var productName = $('#product_name').val();
var language = '英文'; // Default language is English
if (!domain || !productName) {
layui.layer.msg("Please enter both the product name and domain.", {icon: 5});
return;
}
// Show loading mask and disable button
$('#loading-mask').show();
$('#ai-fill-button').attr('disabled', true);
$.ajax({
url: 'https://api.aitoolpath.com/fetch_website_info',
method: 'POST',
contentType: 'application/json',
data: JSON.stringify({ domain: domain, language: language }),
success: function(data) {
// Hide loading mask and enable button
$('#loading-mask').hide();
$('#ai-fill-button').attr('disabled', false);
console.log('API response:', data); // Log the API response
if (data.code === 200) {
var responseData = data.data;
$('#logo_url').val(responseData.logo_filename || "Fetch failed, please enter manually");
$('#logo_thumbnail').attr('src', responseData.logo_filename).toggle(!!responseData.logo_filename);
$('#screenshot_url').val(responseData.screenshot_filename || "Fetch failed, please enter manually");
$('#screenshot_thumbnail').attr('src', responseData.screenshot_filename).toggle(!!responseData.screenshot_filename);
$('#keywords').val(responseData.keywords || "Fetch failed, please enter manually");
$('#description').val(responseData.description || "Fetch failed, please enter manually");
$('#ai_description').val(responseData.ai_description || "Fetch failed, please enter manually");
layui.layer.msg('AI Fill completed', {icon: 1});
} else {
layui.layer.msg(data.message, {icon: 5});
}
},
error: function(xhr, status, error) {
// Hide loading mask and enable button
$('#loading-mask').hide();
$('#ai-fill-button').attr('disabled', false);
console.error('Request error:', error);
layui.layer.msg('Request failed. Please try again.', {icon: 5});
}
});
});
// Upload LOGO
$('#upload-logo').click(function() {
$('#logo_file').click();
});
$('#logo_file').change(function() {
var formData = new FormData();
formData.append('file', $('#logo_file')[0].files[0]);
$.ajax({
url: 'https://api.aitoolpath.com/upload_image', // Replace with your upload API
type: 'POST',
data: formData,
processData: false,
contentType: false,
success: function(data) {
if (data.code === 200) {
console.log(data.data.file_url); // Log uploaded image URL
$('#logo_url').val(data.data.file_url);
$('#logo_thumbnail').attr('src', data.data.file_url).show();
layui.layer.msg('Logo uploaded successfully', {icon: 1});
} else {
layui.layer.msg('Logo upload failed. Please try again.', {icon: 5});
}
},
error: function(xhr, status, error) {
layui.layer.msg('Logo upload failed. Please try again.', {icon: 5});
}
});
});
// Upload Screenshot
$('#upload-screenshot').click(function() {
$('#screenshot_file').click();
});
$('#screenshot_file').change(function() {
var formData = new FormData();
formData.append('file', $('#screenshot_file')[0].files[0]);
$.ajax({
url: 'https://api.aitoolpath.com/upload_image', // Replace with your upload API
type: 'POST',
data: formData,
processData: false,
contentType: false,
success: function(data) {
if (data.code === 200) {
console.log(data.data.file_url);
$('#screenshot_url').val(data.data.file_url);
$('#screenshot_thumbnail').attr('src', data.data.file_url).show();
layui.layer.msg('Screenshot uploaded successfully', {icon: 1});
} else {
layui.layer.msg('Screenshot upload failed. Please try again.', {icon: 5});
}
},
error: function(xhr, status, error) {
layui.layer.msg('Screenshot upload failed. Please try again.', {icon: 5});
}
});
});
</script>
</body>
</html>