411 lines
21 KiB
PHP
411 lines
21 KiB
PHP
<?php include('include/headscript.php'); ?>
|
|
<!doctype html>
|
|
<html lang="en">
|
|
|
|
<head>
|
|
<!-- Required meta tags -->
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<!--favicon-->
|
|
<link rel="icon" href="assets/images/favicon-32x32.png" type="image/png" />
|
|
<?php include('cssinclude.php'); ?>
|
|
<title>Insert XLS Template <?= htmlspecialchars($titlewebsite, ENT_QUOTES, 'UTF-8'); ?></title>
|
|
</head>
|
|
|
|
<body>
|
|
<!--wrapper-->
|
|
<div class="wrapper">
|
|
<!--sidebar wrapper -->
|
|
<?php include('include/navbar.php'); ?>
|
|
<!--end sidebar wrapper -->
|
|
<!--start header -->
|
|
<?php include('include/topbar.php'); ?>
|
|
<!--end header -->
|
|
<!--start page wrapper -->
|
|
<div class="page-wrapper">
|
|
<div class="page-content">
|
|
<div class="row row-cols-1 row-cols-md-2 row-cols-xl-4">
|
|
<div class="col">
|
|
<div class="card radius-10 border-start border-0 border-4 border-info">
|
|
<div class="card-body">
|
|
<div class="d-flex align-items-center">
|
|
<div>
|
|
<p class="mb-0 text-secondary">Total Orders</p>
|
|
<h4 class="my-1 text-info">4805</h4>
|
|
<p class="mb-0 font-13">+2.5% from last week</p>
|
|
</div>
|
|
<div class="widgets-icons-2 rounded-circle bg-gradient-blues text-white ms-auto"><i class='bx bxs-cart'></i>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="col">
|
|
<div class="card radius-10 border-start border-0 border-4 border-danger">
|
|
<div class="card-body">
|
|
<div class="d-flex align-items-center">
|
|
<div>
|
|
<p class="mb-0 text-secondary">Total Revenue</p>
|
|
<h4 class="my-1 text-danger">$84,245</h4>
|
|
<p class="mb-0 font-13">+5.4% from last week</p>
|
|
</div>
|
|
<div class="widgets-icons-2 rounded-circle bg-gradient-burning text-white ms-auto"><i class='bx bxs-wallet'></i>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="col">
|
|
<div class="card radius-10 border-start border-0 border-4 border-success">
|
|
<div class="card-body">
|
|
<div class="d-flex align-items-center">
|
|
<div>
|
|
<p class="mb-0 text-secondary">Bounce Rate</p>
|
|
<h4 class="my-1 text-success">34.6%</h4>
|
|
<p class="mb-0 font-13">-4.5% from last week</p>
|
|
</div>
|
|
<div class="widgets-icons-2 rounded-circle bg-gradient-ohhappiness text-white ms-auto"><i class='bx bxs-bar-chart-alt-2'></i>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="col">
|
|
<div class="card radius-10 border-start border-0 border-4 border-warning">
|
|
<div class="card-body">
|
|
<div class="d-flex align-items-center">
|
|
<div>
|
|
<p class="mb-0 text-secondary">Total Customers</p>
|
|
<h4 class="my-1 text-warning">8.4K</h4>
|
|
<p class="mb-0 font-13">+8.4% from last week</p>
|
|
</div>
|
|
<div class="widgets-icons-2 rounded-circle bg-gradient-orange text-white ms-auto"><i class='bx bxs-group'></i>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div><!--end row-->
|
|
|
|
<div class="card radius-10">
|
|
<div class="card-header">
|
|
<div class="d-flex align-items-center">
|
|
<div>
|
|
<h6 class="mb-0">Insert New XLS Template</h6>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="card-body">
|
|
<div class="col-12">
|
|
<form id="insertTemplateForm" method="POST">
|
|
<div class="mb-3">
|
|
<label class="form-label"><?= htmlspecialchars($templatename, ENT_QUOTES, 'UTF-8'); ?> *</label>
|
|
<input type="text" name="name" class="form-control" required>
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<label class="form-label"><?= htmlspecialchars($rowheader, ENT_QUOTES, 'UTF-8'); ?> *</label>
|
|
<input type="number" name="header_row" class="form-control" required>
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<label class="form-label"><?= htmlspecialchars($columnheader, ENT_QUOTES, 'UTF-8'); ?> *</label>
|
|
<input type="text" name="start_column" class="form-control" required>
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<label class="form-label"><?= htmlspecialchars($desctemplate, ENT_QUOTES, 'UTF-8'); ?></label>
|
|
<textarea name="description" class="form-control"></textarea>
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<label class="form-label"><?= htmlspecialchars($desttable, ENT_QUOTES, 'UTF-8'); ?> *</label>
|
|
<input type="text" name="target_table" class="form-control" required>
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<label class="form-label">Button Size</label>
|
|
<select name="button_size" class="form-control">
|
|
<option value="small">Small</option>
|
|
<option value="medium" selected>Medium</option>
|
|
<option value="large">Large</option>
|
|
</select>
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<label class="form-label">Button Background Color</label>
|
|
<input type="color" name="button_bg_color" class="form-control" value="#007bff">
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<label class="form-label">Button Text Color</label>
|
|
<input type="color" name="button_text_color" class="form-control" value="#ffffff">
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<label class="form-label">Button Label</label>
|
|
<input type="text" name="button_label" class="form-control" value="Click Me">
|
|
</div>
|
|
|
|
<!-- Nuova sezione per i campi specifici del cliente -->
|
|
<div class="mb-3">
|
|
<label class="form-label">Client-Specific Fields</label>
|
|
<div id="clientSpecificFields">
|
|
<!-- Contenitore per i campi dinamici -->
|
|
<div class="client-field-row mb-2">
|
|
<div class="row">
|
|
<div class="col-md-3">
|
|
<input type="text" name="specific_fields[0][name]" class="form-control" placeholder="Field Name (e.g., SKU)">
|
|
</div>
|
|
<div class="col-md-2">
|
|
<select name="specific_fields[0][type]" class="form-control">
|
|
<option value="text">Text</option>
|
|
<option value="dropdown">Dropdown</option>
|
|
<option value="date">Date</option>
|
|
<option value="boolean">Yes/No</option>
|
|
</select>
|
|
</div>
|
|
<div class="col-md-2 d-none dropdown-values" style="display: none;">
|
|
<input type="text" name="specific_fields[0][possible_values]" class="form-control" placeholder="Values (e.g., Red, Blue, Green)">
|
|
</div>
|
|
<div class="col-md-1">
|
|
<select name="specific_fields[0][required]" class="form-control">
|
|
<option value="1">Yes</option>
|
|
<option value="0">No</option>
|
|
</select>
|
|
</div>
|
|
<div class="col-md-2">
|
|
<input type="text" name="specific_fields[0][export_column_name]" class="form-control" placeholder="Export Column Name (e.g., MONCLER_SKU)">
|
|
</div>
|
|
<div class="col-md-1">
|
|
<input type="text" name="specific_fields[0][default_value]" class="form-control" placeholder="Default Value (optional)">
|
|
</div>
|
|
<div class="col-md-1">
|
|
<button type="button" class="btn btn-danger remove-field">-</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<button type="button" class="btn btn-primary mt-2" id="addField">Add Field</button>
|
|
</div>
|
|
|
|
<br>
|
|
<button type="submit" class="btn btn-primary">Create Template</button>
|
|
<a href="templeates_dashboard.php" class="btn btn-secondary">Cancel</a>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
<!--end page wrapper -->
|
|
<!--start overlay-->
|
|
<div class="overlay toggle-icon"></div>
|
|
<!--end overlay-->
|
|
<!--Start Back To Top Button-->
|
|
<a href="javaScript:;" class="back-to-top"><i class='bx bxs-up-arrow-alt'></i></a>
|
|
<!--End Back To Top Button-->
|
|
<?php include('include/footer.php'); ?>
|
|
</div>
|
|
<!--end wrapper-->
|
|
|
|
<!-- search modal -->
|
|
<?php //include('include/searchmodal.php');
|
|
?>
|
|
<!-- end search modal -->
|
|
|
|
<!--start switcher-->
|
|
<?php //include('include/themeswitcher.php');
|
|
?>
|
|
<!--end switcher-->
|
|
<?php include('jsinclude.php'); ?>
|
|
<script>
|
|
// Debug iniziale
|
|
console.log("JavaScript is loaded and running!");
|
|
|
|
document.addEventListener("DOMContentLoaded", function() {
|
|
console.log("DOM is loaded");
|
|
|
|
const form = document.getElementById("insertTemplateForm");
|
|
const addFieldButton = document.getElementById("addField");
|
|
const container = document.getElementById("clientSpecificFields");
|
|
|
|
if (!form || !addFieldButton || !container) {
|
|
console.error("One or more DOM elements not found:", {
|
|
form,
|
|
addFieldButton,
|
|
container
|
|
});
|
|
return;
|
|
}
|
|
|
|
console.log("All DOM elements found");
|
|
|
|
// Gestione dinamica dei campi specifici
|
|
addFieldButton.addEventListener("click", function() {
|
|
console.log("Add Field button clicked");
|
|
const fieldCount = container.getElementsByClassName("client-field-row").length;
|
|
const newField = document.createElement("div");
|
|
newField.className = "client-field-row mb-2";
|
|
newField.innerHTML = `
|
|
<div class="row">
|
|
<div class="col-md-3">
|
|
<input type="text" name="specific_fields[${fieldCount}][name]" class="form-control" placeholder="Field Name (e.g., SKU)">
|
|
</div>
|
|
<div class="col-md-2">
|
|
<select name="specific_fields[${fieldCount}][type]" class="form-control" onchange="toggleDropdownValues(this)">
|
|
<option value="text">Text</option>
|
|
<option value="dropdown">Dropdown</option>
|
|
<option value="date">Date</option>
|
|
<option value="boolean">Yes/No</option>
|
|
</select>
|
|
</div>
|
|
<div class="col-md-2 d-none dropdown-values" style="display: none;">
|
|
<input type="text" name="specific_fields[${fieldCount}][possible_values]" class="form-control" placeholder="Values (e.g., Red, Blue, Green)">
|
|
</div>
|
|
<div class="col-md-1">
|
|
<select name="specific_fields[${fieldCount}][required]" class="form-control">
|
|
<option value="1">Yes</option>
|
|
<option value="0">No</option>
|
|
</select>
|
|
</div>
|
|
<div class="col-md-2">
|
|
<input type="text" name="specific_fields[${fieldCount}][export_column_name]" class="form-control" placeholder="Export Column Name (e.g., MONCLER_SKU)">
|
|
</div>
|
|
<div class="col-md-1">
|
|
<input type="text" name="specific_fields[${fieldCount}][default_value]" class="form-control" placeholder="Default Value (optional)">
|
|
</div>
|
|
<div class="col-md-1">
|
|
<button type="button" class="btn btn-danger remove-field">-</button>
|
|
</div>
|
|
</div>
|
|
`;
|
|
container.appendChild(newField);
|
|
|
|
newField.querySelector(".remove-field").addEventListener("click", function() {
|
|
console.log("Remove Field button clicked");
|
|
container.removeChild(newField);
|
|
updateFieldIndices();
|
|
});
|
|
});
|
|
|
|
window.toggleDropdownValues = function(selectElement) {
|
|
console.log("Toggling dropdown values for:", selectElement.value);
|
|
const row = selectElement.closest(".row");
|
|
const dropdownValues = row.querySelector(".dropdown-values");
|
|
if (selectElement.value === "dropdown") {
|
|
dropdownValues.style.display = "block";
|
|
} else {
|
|
dropdownValues.style.display = "none";
|
|
}
|
|
};
|
|
|
|
document.querySelectorAll(".remove-field").forEach(button => {
|
|
button.addEventListener("click", function() {
|
|
console.log("Existing remove button clicked");
|
|
const container = document.getElementById("clientSpecificFields");
|
|
container.removeChild(button.closest(".client-field-row"));
|
|
updateFieldIndices();
|
|
});
|
|
});
|
|
|
|
function updateFieldIndices() {
|
|
console.log("Updating field indices");
|
|
const rows = container.getElementsByClassName("client-field-row");
|
|
for (let i = 0; i < rows.length; i++) {
|
|
const inputs = rows[i].querySelectorAll("input, select");
|
|
inputs.forEach(input => {
|
|
const name = input.name.replace(/\[\d+\]/, `[${i}]`);
|
|
input.name = name;
|
|
});
|
|
}
|
|
}
|
|
|
|
form.addEventListener("submit", function(e) {
|
|
e.preventDefault();
|
|
console.log("Form submitted");
|
|
|
|
let formData = new FormData(this);
|
|
|
|
// Genera il JSON per client_specific_fields
|
|
let finalSpecificFields = {};
|
|
|
|
// Raccolta dei dati direttamente dal DOM
|
|
const fieldRows = container.getElementsByClassName("client-field-row");
|
|
for (let i = 0; i < fieldRows.length; i++) {
|
|
const row = fieldRows[i];
|
|
const inputs = row.querySelectorAll("input, select");
|
|
let fieldData = {};
|
|
|
|
inputs.forEach(input => {
|
|
const nameMatch = input.name.match(/specific_fields\[\d+\]\[(.*?)\]/);
|
|
if (nameMatch) {
|
|
const fieldName = nameMatch[1];
|
|
fieldData[fieldName] = input.value.trim();
|
|
}
|
|
});
|
|
|
|
if (fieldData.name) {
|
|
finalSpecificFields[fieldData.name] = {
|
|
type: fieldData.type || "text",
|
|
possible_values: (fieldData.possible_values && fieldData.type === "dropdown") ? fieldData.possible_values.split(",").map(v => v.trim()) : [],
|
|
is_required: fieldData.required === "1",
|
|
export_column_name: fieldData.export_column_name || "",
|
|
default_value: fieldData.default_value || ""
|
|
};
|
|
console.log(`Field ${fieldData.name}:`, finalSpecificFields[fieldData.name]);
|
|
}
|
|
}
|
|
|
|
console.log("Generated JSON for client_specific_fields:", JSON.stringify(finalSpecificFields));
|
|
|
|
// Aggiungi il JSON al FormData
|
|
formData.append("client_specific_fields", JSON.stringify(finalSpecificFields));
|
|
|
|
// Debug del FormData
|
|
console.log("FormData contents:");
|
|
for (let pair of formData.entries()) {
|
|
console.log(pair[0] + ': ' + pair[1]);
|
|
}
|
|
|
|
fetch("process_insert_template_xls.php", {
|
|
method: "POST",
|
|
body: formData
|
|
})
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
console.log("Fetch response:", data);
|
|
if (data.success) {
|
|
Swal.fire({
|
|
title: "Success!",
|
|
text: "Template created successfully!",
|
|
icon: "success",
|
|
confirmButtonText: "OK"
|
|
}).then(() => {
|
|
window.location.href = "templates_dashboard.php";
|
|
});
|
|
} else {
|
|
Swal.fire({
|
|
title: "Error!",
|
|
text: data.message,
|
|
icon: "error",
|
|
confirmButtonText: "OK"
|
|
});
|
|
}
|
|
})
|
|
.catch(error => {
|
|
console.error("Fetch error:", error);
|
|
Swal.fire({
|
|
title: "Error!",
|
|
text: "An unexpected error occurred.",
|
|
icon: "error",
|
|
confirmButtonText: "OK"
|
|
});
|
|
});
|
|
});
|
|
});
|
|
</script>
|
|
</body>
|
|
|
|
</html>
|