236 lines
11 KiB
PHP
236 lines
11 KiB
PHP
<?php include('container/security.php');?>
|
|
<!DOCTYPE html>
|
|
<html lang="en" data-theme="light">
|
|
<head>
|
|
<!-- head links start -->
|
|
<?php include 'container/head_links.php';?>
|
|
<!-- head links start -->
|
|
<script src="https://cdn.ckeditor.com/4.22.1/standard/ckeditor.js"></script>
|
|
</head>
|
|
<body>
|
|
<!-- side_bar start -->
|
|
<?php include 'container/side_bar.php' ?>
|
|
<?php
|
|
|
|
|
|
|
|
$successcta='0';
|
|
if (isset($_POST['submit_CTA'])) {
|
|
// Collect form data and sanitize
|
|
$small_heading_EN = mysqli_real_escape_string($conn, $_POST['small_heading_CTA_EN']);
|
|
$small_heading_CN = mysqli_real_escape_string($conn, $_POST['small_heading_CTA_CN']);
|
|
$large_heading_EN = mysqli_real_escape_string($conn, $_POST['Large_heading_CTA_EN']);
|
|
$large_heading_CN = mysqli_real_escape_string($conn, $_POST['Large_heading_CTA_CN']);
|
|
$btn_text_EN = mysqli_real_escape_string($conn, $_POST['btn_text_cta_EN']);
|
|
$btn_text_CN = mysqli_real_escape_string($conn, $_POST['btn_text_cta_CN']);
|
|
$btn_link = mysqli_real_escape_string($conn, $_POST['btn_link']);
|
|
$long_description_EN = mysqli_real_escape_string($conn, $_POST['editor1_CTA_EN']);
|
|
$long_description_CN = mysqli_real_escape_string($conn, $_POST['editor1_CTA_CN']);
|
|
$addedby = mysqli_real_escape_string($conn, $_POST['addedby']);
|
|
|
|
// Check if data already exists (based on a unique identifier, e.g., ID or user-specific data)
|
|
$query = "SELECT id FROM cta_form_data LIMIT 1";
|
|
$result = mysqli_query($conn, $query);
|
|
|
|
if (mysqli_num_rows($result) > 0) {
|
|
// If the data already exists, update it
|
|
$row = mysqli_fetch_assoc($result);
|
|
$id = $row['id'];
|
|
|
|
$update_query = "UPDATE cta_form_data SET
|
|
small_heading_CTA_EN = '$small_heading_EN',
|
|
small_heading_CTA_CN = '$small_heading_CN',
|
|
Large_heading_CTA_EN = '$large_heading_EN',
|
|
Large_heading_CTA_CN = '$large_heading_CN',
|
|
btn_text_cta_EN = '$btn_text_EN',
|
|
btn_text_cta_CN = '$btn_text_CN',
|
|
btn_link = '$btn_link',
|
|
long_description_CTA_EN = '$long_description_EN',
|
|
long_description_CTA_CN = '$long_description_CN',
|
|
updated_at = NOW(),
|
|
status = 'active'
|
|
WHERE id = '$id'";
|
|
|
|
if (mysqli_query($conn, $update_query)) {
|
|
$successcta= "Data updated successfully.";
|
|
} else {
|
|
echo "Error updating data: " . mysqli_error($conn);
|
|
}
|
|
} else {
|
|
// If the data doesn't exist, insert a new record
|
|
$insert_query = "INSERT INTO cta_form_data
|
|
(small_heading_CTA_EN, small_heading_CTA_CN, Large_heading_CTA_EN, Large_heading_CTA_CN, btn_text_cta_EN, btn_text_cta_CN, btn_link, long_description_CTA_EN, long_description_CTA_CN, addedby, status, created_at)
|
|
VALUES
|
|
('$small_heading_EN', '$small_heading_CN', '$large_heading_EN', '$large_heading_CN', '$btn_text_EN', '$btn_text_CN', '$btn_link', '$long_description_EN', '$long_description_CN', '$addedby', 'active', NOW())";
|
|
|
|
if (mysqli_query($conn, $insert_query)) {
|
|
$successcta= "Data inserted successfully.";
|
|
} else {
|
|
echo "Error inserting data: " . mysqli_error($conn);
|
|
}
|
|
}
|
|
$_POST = [];
|
|
}
|
|
|
|
?>
|
|
|
|
|
|
<!-- side_bar end -->
|
|
<main class="dashboard-main">
|
|
<!-- Header start -->
|
|
<?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">Manage CTA Section</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>
|
|
Dashboard
|
|
</a>
|
|
</li>
|
|
<li>-</li>
|
|
<li class="fw-medium">Update CTA Section</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">Update CTA Section</h5>
|
|
</div>
|
|
<div class="card-body">
|
|
<?php if ($successcta != "0"): ?>
|
|
<div class="alert alert-success" role="alert">
|
|
<?php echo $successcta ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
<?php
|
|
// Initialize variables with default values
|
|
$small_heading_EN = '';
|
|
$small_heading_CN = '';
|
|
$large_heading_EN = '';
|
|
$large_heading_CN = '';
|
|
$btn_text_EN = '';
|
|
$btn_text_CN = '';
|
|
$btn_link = '';
|
|
$long_description_EN = '';
|
|
$long_description_CN = '';
|
|
|
|
// Fetch existing data if available
|
|
if (isset($_SESSION['user_id'])) {
|
|
$user_id = mysqli_real_escape_string($conn, $_SESSION['user_id']);
|
|
|
|
$query = "SELECT * FROM cta_form_data WHERE addedby = '$user_id' LIMIT 1";
|
|
$result = mysqli_query($conn, $query);
|
|
|
|
if (mysqli_num_rows($result) > 0) {
|
|
$row = mysqli_fetch_assoc($result);
|
|
// Assign fetched data to variables
|
|
$small_heading_EN = htmlspecialchars($row['small_heading_CTA_EN']);
|
|
$small_heading_CN = htmlspecialchars($row['small_heading_CTA_CN']);
|
|
$large_heading_EN = htmlspecialchars($row['Large_heading_CTA_EN']);
|
|
$large_heading_CN = htmlspecialchars($row['Large_heading_CTA_CN']);
|
|
$btn_text_EN = htmlspecialchars($row['btn_text_cta_EN']);
|
|
$btn_text_CN = htmlspecialchars($row['btn_text_cta_CN']);
|
|
$btn_link = htmlspecialchars($row['btn_link']);
|
|
$long_description_EN = htmlspecialchars($row['long_description_CTA_EN']);
|
|
$long_description_CN = htmlspecialchars($row['long_description_CTA_CN']);
|
|
}
|
|
}
|
|
?>
|
|
|
|
<!-- HTML form populated with PHP data -->
|
|
<!-- HTML form populated with PHP data -->
|
|
<form action="" method="POST" enctype="multipart/form-data">
|
|
<div class="row gy-3">
|
|
<div class="col-md-6 col-sm-12">
|
|
<label class="form-label">Small Heading EN</label>
|
|
<input type="text" name="small_heading_CTA_EN" class="form-control" required placeholder="Enter Small Heading EN" value="<?php echo $small_heading_EN; ?>">
|
|
</div>
|
|
<div class="col-md-6 col-sm-12">
|
|
<label class="form-label">Small Heading CN</label>
|
|
<input type="text" name="small_heading_CTA_CN" class="form-control" required placeholder="Enter Small Heading CN" value="<?php echo $small_heading_CN; ?>">
|
|
</div>
|
|
<div class="col-md-6 col-sm-12">
|
|
<label class="form-label">Large Heading EN</label>
|
|
<input type="text" name="Large_heading_CTA_EN" class="form-control" required placeholder="Enter Large Heading EN" value="<?php echo $large_heading_EN; ?>">
|
|
</div>
|
|
<div class="col-md-6 col-sm-12">
|
|
<label class="form-label">Large Heading CN</label>
|
|
<input type="text" name="Large_heading_CTA_CN" class="form-control" required placeholder="Enter Large Heading CN" value="<?php echo $large_heading_CN; ?>">
|
|
</div>
|
|
<div class="col-md-6 col-sm-12">
|
|
<label class="form-label">Button Text EN</label>
|
|
<input type="text" name="btn_text_cta_EN" class="form-control" required placeholder="Enter Button Text EN" value="<?php echo $btn_text_EN; ?>">
|
|
</div>
|
|
<div class="col-md-6 col-sm-12">
|
|
<label class="form-label">Button Text CN</label>
|
|
<input type="text" name="btn_text_cta_CN" class="form-control" required placeholder="Enter Button Text CN" value="<?php echo $btn_text_CN; ?>">
|
|
</div>
|
|
<div class="col-md-6 col-sm-12">
|
|
<label class="form-label">Button Link</label>
|
|
<input type="text" name="btn_link" class="form-control" required placeholder="Enter Button Link" value="<?php echo $btn_link; ?>">
|
|
</div>
|
|
<div class="col-12">
|
|
<label class="form-label">Long Description EN</label>
|
|
<textarea name="editor1_CTA_EN" id="editor3" required><?php echo $long_description_EN; ?></textarea>
|
|
</div>
|
|
<div class="col-12">
|
|
<label class="form-label">Long Description CN</label>
|
|
<textarea name="editor1_CTA_CN" id="editor4" required><?php echo $long_description_CN; ?></textarea>
|
|
</div>
|
|
<input type="hidden" value="<?php echo htmlspecialchars($_SESSION['user_id']); ?>" name="addedby">
|
|
<div class="col-12">
|
|
<button type="submit" name="submit_CTA" class="btn btn-primary mt-3">Submit</button>
|
|
</div>
|
|
</div>
|
|
</form>
|
|
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
|
|
<?php include 'container/footer.php' ?>
|
|
</main>
|
|
<!-- Footer Links Start -->
|
|
<?php include 'container/footer_links.php' ?>
|
|
<script>
|
|
// Replace textarea with CKEditor
|
|
CKEDITOR.replace('editor1');
|
|
CKEDITOR.replace('editor2'); CKEDITOR.replace('editor3');
|
|
CKEDITOR.replace('editor4');
|
|
</script>
|
|
<script>
|
|
// Function to perform the delayed click
|
|
function clickNotificationClose() {
|
|
setTimeout(function() {
|
|
var closeButton = document.querySelector('.cke_notification_close');
|
|
if (closeButton) {
|
|
closeButton.click();
|
|
} else {
|
|
console.log('Close button not found.');
|
|
}
|
|
}, 100); // Delay in milliseconds (e.g., 2000ms = 2 seconds)
|
|
}
|
|
|
|
// Call the function after the page has loaded
|
|
window.addEventListener('load', clickNotificationClose);
|
|
</script>
|
|
</body>
|
|
</html>
|
|
|
|
|
|
|
|
|
|
|