644 lines
29 KiB
PHP
644 lines
29 KiB
PHP
<?php include('include/headscript.php');
|
|
|
|
// Check if a valid ID was provided
|
|
if (!isset($_GET['id']) || !is_numeric($_GET['id'])) {
|
|
header("Location: templates_dashboard.php?status=error&message=" . urlencode("Invalid ID"));
|
|
exit;
|
|
}
|
|
|
|
$id = intval($_GET['id']);
|
|
|
|
// Retrieve template from database
|
|
$db = DBHandlerSelect::getInstance();
|
|
$pdo = $db->getConnection();
|
|
|
|
$stmt = $pdo->prepare("SELECT * FROM excel_templates WHERE id = ?");
|
|
$stmt->execute([$id]);
|
|
$template = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
|
|
if (!$template) {
|
|
header("Location: templates_dashboard.php?status=error&message=" . urlencode("Template not found"));
|
|
exit;
|
|
}
|
|
|
|
// Retrieve all routines
|
|
$stmt = $pdo->prepare("SELECT * FROM routine");
|
|
$stmt->execute();
|
|
$routines = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
$buttonBgPalette = [
|
|
'#0d6efd' => 'Blue',
|
|
'#6610f2' => 'Indigo',
|
|
'#6f42c1' => 'Purple',
|
|
'#d63384' => 'Pink',
|
|
'#dc3545' => 'Red',
|
|
'#fd7e14' => 'Orange',
|
|
'#ffc107' => 'Yellow',
|
|
'#198754' => 'Green',
|
|
'#20c997' => 'Teal',
|
|
'#0dcaf0' => 'Cyan',
|
|
'#212529' => 'Dark',
|
|
'#6c757d' => 'Gray',
|
|
'#495057' => 'Slate',
|
|
'#795548' => 'Brown',
|
|
'#2f5d50' => 'Sage Green',
|
|
];
|
|
|
|
$buttonTextPalette = [
|
|
'#ffffff' => 'White',
|
|
'#6c757d' => 'Gray',
|
|
'#000000' => 'Black',
|
|
];
|
|
|
|
$currentButtonBgColor = strtolower($template['button_bg_color'] ?? '#007bff');
|
|
$currentButtonTextColor = strtolower($template['button_text_color'] ?? '#ffffff');
|
|
|
|
if (!array_key_exists($currentButtonBgColor, array_change_key_case($buttonBgPalette, CASE_LOWER))) {
|
|
$currentButtonBgColor = '#0d6efd';
|
|
}
|
|
|
|
if (!array_key_exists($currentButtonTextColor, array_change_key_case($buttonTextPalette, CASE_LOWER))) {
|
|
$currentButtonTextColor = '#ffffff';
|
|
}
|
|
?>
|
|
<!doctype html>
|
|
<html lang="en">
|
|
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<link rel="icon" href="assets/images/favicon-32x32.png" type="image/png" />
|
|
<link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css" rel="stylesheet" />
|
|
<?php include('cssinclude.php'); ?>
|
|
<style>
|
|
.color-palette {
|
|
display: flex;
|
|
flex-wrap: wrap;
|
|
gap: 10px;
|
|
margin-top: 8px;
|
|
}
|
|
|
|
.color-option {
|
|
position: relative;
|
|
cursor: pointer;
|
|
}
|
|
|
|
.color-option input {
|
|
position: absolute;
|
|
opacity: 0;
|
|
pointer-events: none;
|
|
}
|
|
|
|
.color-swatch {
|
|
width: 42px;
|
|
height: 42px;
|
|
border-radius: 10px;
|
|
border: 2px solid #d6dbe0;
|
|
display: inline-flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);
|
|
transition: all 0.18s ease;
|
|
}
|
|
|
|
.color-option input:checked+.color-swatch {
|
|
border: 3px solid #111827;
|
|
transform: scale(1.08);
|
|
box-shadow: 0 0 0 4px rgba(13, 110, 253, 0.18);
|
|
}
|
|
|
|
.color-swatch .check-mark {
|
|
display: none;
|
|
font-size: 18px;
|
|
font-weight: 700;
|
|
color: #ffffff;
|
|
text-shadow: 0 1px 3px rgba(0, 0, 0, 0.7);
|
|
}
|
|
|
|
.color-option input:checked+.color-swatch .check-mark {
|
|
display: inline-block;
|
|
}
|
|
|
|
.color-name {
|
|
display: block;
|
|
font-size: 11px;
|
|
text-align: center;
|
|
margin-top: 4px;
|
|
color: #555;
|
|
max-width: 55px;
|
|
}
|
|
</style>
|
|
<script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
|
|
<script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script>
|
|
<title>Edit Template <?= htmlspecialchars($titlewebsite, ENT_QUOTES, 'UTF-8'); ?></title>
|
|
</head>
|
|
|
|
<body>
|
|
<div class="wrapper">
|
|
<?php include('include/navbar.php'); ?>
|
|
<?php include('include/topbar.php'); ?>
|
|
|
|
<div class="page-wrapper">
|
|
<div class="page-content">
|
|
|
|
<div class="card mb-4">
|
|
<div class="card-header">
|
|
<h5 class="mb-0">Update Template</h5>
|
|
</div>
|
|
<div class="card-body">
|
|
<p class="mb-2">Edit the following form in order to update the selected import template</p>
|
|
<p class="mb-2">Mandatory Fields</p>
|
|
<ul class="mb-0">
|
|
<li>Template Name</li>
|
|
<li>Source Type</li>
|
|
<li>Schema and Client</li>
|
|
<li>Row Header and Column Header only for XLS templates</li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="card radius-10">
|
|
<div class="card-header">
|
|
<div class="d-flex align-items-center">
|
|
<div>
|
|
<h6 class="mb-0">Edit Template: <?php echo htmlspecialchars($template['name']); ?></h6>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="card-body">
|
|
<div class="col-12">
|
|
<form id="editTemplateForm" method="POST">
|
|
<input type="hidden" name="id" value="<?php echo (int)$template['id']; ?>">
|
|
|
|
<div class="mb-3">
|
|
<label class="form-label"><?= htmlspecialchars($templatename, ENT_QUOTES, 'UTF-8'); ?> *</label>
|
|
<input type="text" name="name" class="form-control" value="<?php echo htmlspecialchars($template['name'] ?? ''); ?>" required>
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<label class="form-label">Source Type *</label>
|
|
<select name="source_type" id="sourceType" class="form-control" required>
|
|
<option value="XLS" <?php echo (($template['source_type'] ?? 'XLS') === 'XLS') ? 'selected' : ''; ?>>XLS</option>
|
|
<option value="API" <?php echo (($template['source_type'] ?? 'XLS') === 'API') ? 'selected' : ''; ?>>API</option>
|
|
</select>
|
|
<small class="text-muted">Choose the source used by this template</small>
|
|
</div>
|
|
|
|
<div class="mb-3" id="headerRowWrapper">
|
|
<label class="form-label"><?= htmlspecialchars($rowheader, ENT_QUOTES, 'UTF-8'); ?> *</label>
|
|
<input type="number" name="header_row" id="headerRow" class="form-control" value="<?php echo htmlspecialchars($template['header_row'] ?? ''); ?>">
|
|
</div>
|
|
|
|
<div class="mb-3" id="startColumnWrapper">
|
|
<label class="form-label"><?= htmlspecialchars($columnheader, ENT_QUOTES, 'UTF-8'); ?> *</label>
|
|
<input type="text" name="start_column" id="startColumn" class="form-control" value="<?php echo htmlspecialchars($template['start_column'] ?? ''); ?>">
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<label class="form-label"><?= htmlspecialchars($desctemplate, ENT_QUOTES, 'UTF-8'); ?></label>
|
|
<textarea name="description" class="form-control"><?php echo htmlspecialchars($template['description'] ?? ''); ?></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" value="<?php echo htmlspecialchars($template['target_table'] ?? 'datadb'); ?>" readonly required>
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<label class="form-label">Button Size</label>
|
|
<select name="button_size" class="form-control">
|
|
<option value="small" <?php echo ($template['button_size'] ?? 'medium') === 'small' ? 'selected' : ''; ?>>Small</option>
|
|
<option value="medium" <?php echo ($template['button_size'] ?? 'medium') === 'medium' ? 'selected' : ''; ?>>Medium</option>
|
|
<option value="large" <?php echo ($template['button_size'] ?? 'medium') === 'large' ? 'selected' : ''; ?>>Large</option>
|
|
</select>
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<label class="form-label">Button Background Color</label>
|
|
|
|
<div class="color-palette">
|
|
<?php foreach ($buttonBgPalette as $colorValue => $colorLabel): ?>
|
|
<?php $isChecked = strtolower($colorValue) === $currentButtonBgColor; ?>
|
|
|
|
<label class="color-option" title="<?= htmlspecialchars($colorLabel, ENT_QUOTES, 'UTF-8'); ?>">
|
|
<input
|
|
type="radio"
|
|
name="button_bg_color"
|
|
value="<?= htmlspecialchars($colorValue, ENT_QUOTES, 'UTF-8'); ?>"
|
|
<?= $isChecked ? 'checked' : ''; ?>>
|
|
<span class="color-swatch" style="background-color: <?= htmlspecialchars($colorValue, ENT_QUOTES, 'UTF-8'); ?>;">
|
|
<span class="check-mark">✓</span>
|
|
</span>
|
|
<span class="color-name"><?= htmlspecialchars($colorLabel, ENT_QUOTES, 'UTF-8'); ?></span>
|
|
</label>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<label class="form-label">Button Text Color</label>
|
|
|
|
<div class="color-palette">
|
|
<?php foreach ($buttonTextPalette as $colorValue => $colorLabel): ?>
|
|
<?php $isChecked = strtolower($colorValue) === $currentButtonTextColor; ?>
|
|
|
|
<label class="color-option" title="<?= htmlspecialchars($colorLabel, ENT_QUOTES, 'UTF-8'); ?>">
|
|
<input
|
|
type="radio"
|
|
name="button_text_color"
|
|
value="<?= htmlspecialchars($colorValue, ENT_QUOTES, 'UTF-8'); ?>"
|
|
<?= $isChecked ? 'checked' : ''; ?>>
|
|
<span class="color-swatch" style="background-color: <?= htmlspecialchars($colorValue, ENT_QUOTES, 'UTF-8'); ?>;">
|
|
<span class="check-mark">✓</span>
|
|
</span>
|
|
<span class="color-name"><?= htmlspecialchars($colorLabel, ENT_QUOTES, 'UTF-8'); ?></span>
|
|
</label>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<label class="form-label">Button Label</label>
|
|
<input type="text" name="button_label" class="form-control" value="<?php echo htmlspecialchars($template['button_label'] ?? 'Click Me'); ?>">
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<label class="form-label">Select Client *</label>
|
|
<select name="client_id" id="clientSelect" class="form-control" required>
|
|
<option value="">Select a client...</option>
|
|
</select>
|
|
<span id="clientLoadingStatus" class="text-muted" style="margin-left: 10px; display: none;">Loading clients...</span>
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<label class="form-label">Select Schema *</label>
|
|
<select name="schema_id" id="schemaSelect" class="form-control" required>
|
|
<option value="">Select a schema...</option>
|
|
</select>
|
|
<span id="schemaLoadingStatus" class="text-muted" style="margin-left: 10px; display: none;">Loading schemas...</span>
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<label class="form-label">Select Routine</label>
|
|
<select name="idroutine" id="routineSelect" class="form-control">
|
|
<option value="">Select a routine...</option>
|
|
<?php foreach ($routines as $routine): ?>
|
|
<option value="<?php echo $routine['idroutine']; ?>" <?php echo (($template['idroutine'] ?? '') == $routine['idroutine']) ? 'selected' : ''; ?>>
|
|
<?php echo htmlspecialchars($routine['name']); ?>
|
|
</option>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
|
|
<div id="routineDetails" class="mt-2" style="display: none;">
|
|
<h6>Routine Details</h6>
|
|
<p><strong>Name:</strong> <span id="routineName"></span></p>
|
|
<p><strong>Description:</strong> <span id="routineDescription"></span></p>
|
|
<p><strong>Action 1:</strong> <span id="routineAction1"></span></p>
|
|
<p><strong>Action 2:</strong> <span id="routineAction2"></span></p>
|
|
<p><strong>Action 3:</strong> <span id="routineAction3"></span></p>
|
|
</div>
|
|
</div>
|
|
|
|
<br>
|
|
<button type="submit" class="btn btn-primary"><?= htmlspecialchars($savechanges, ENT_QUOTES, 'UTF-8'); ?></button>
|
|
<a href="templates_dashboard.php" class="btn btn-secondary">Cancel</a>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
|
|
<div class="overlay toggle-icon"></div>
|
|
<a href="javaScript:;" class="back-to-top"><i class='bx bxs-up-arrow-alt'></i></a>
|
|
<?php include('include/footer.php'); ?>
|
|
</div>
|
|
|
|
<script>
|
|
document.addEventListener("DOMContentLoaded", function() {
|
|
if (typeof jQuery === 'undefined') {
|
|
alert("Error: jQuery is not loaded.");
|
|
return;
|
|
}
|
|
|
|
const form = document.getElementById("editTemplateForm");
|
|
const clientLoadingStatus = document.getElementById("clientLoadingStatus");
|
|
const schemaLoadingStatus = document.getElementById("schemaLoadingStatus");
|
|
const routineSelect = document.getElementById("routineSelect");
|
|
const routineDetails = document.getElementById("routineDetails");
|
|
const routineName = document.getElementById("routineName");
|
|
const routineDescription = document.getElementById("routineDescription");
|
|
const routineAction1 = document.getElementById("routineAction1");
|
|
const routineAction2 = document.getElementById("routineAction2");
|
|
const routineAction3 = document.getElementById("routineAction3");
|
|
|
|
const sourceType = document.getElementById("sourceType");
|
|
const headerRowWrapper = document.getElementById("headerRowWrapper");
|
|
const startColumnWrapper = document.getElementById("startColumnWrapper");
|
|
const headerRow = document.getElementById("headerRow");
|
|
const startColumn = document.getElementById("startColumn");
|
|
|
|
const selectedClientId = <?php echo json_encode((int)($template['idclient'] ?? 0)); ?>;
|
|
const selectedSchemaId = <?php echo json_encode((int)($template['idschema'] ?? 0)); ?>;
|
|
|
|
$('#clientSelect').select2({
|
|
placeholder: "Search for a client...",
|
|
allowClear: true
|
|
});
|
|
|
|
$('#schemaSelect').select2({
|
|
placeholder: "Search for a schema...",
|
|
allowClear: true
|
|
});
|
|
|
|
$('#routineSelect').select2({
|
|
placeholder: "Select a routine...",
|
|
allowClear: true
|
|
});
|
|
|
|
function updateSourceFields() {
|
|
const selectedSource = sourceType.value;
|
|
|
|
if (selectedSource === 'API') {
|
|
headerRowWrapper.style.opacity = '0.6';
|
|
startColumnWrapper.style.opacity = '0.6';
|
|
|
|
headerRow.required = false;
|
|
startColumn.required = false;
|
|
|
|
headerRow.disabled = true;
|
|
startColumn.disabled = true;
|
|
} else {
|
|
headerRowWrapper.style.opacity = '1';
|
|
startColumnWrapper.style.opacity = '1';
|
|
|
|
headerRow.required = true;
|
|
startColumn.required = true;
|
|
|
|
headerRow.disabled = false;
|
|
startColumn.disabled = false;
|
|
}
|
|
}
|
|
|
|
sourceType.addEventListener('change', updateSourceFields);
|
|
updateSourceFields();
|
|
|
|
function formatClientLabel(client) {
|
|
const nome = client.Nominativo || "Name not available";
|
|
const id = client.IdCliente || "";
|
|
const codiceCliente = (client.CodiceCliente ?? client.codiceCliente ?? "").toString().trim();
|
|
const suffix = (codiceCliente.split("_")[1] || "").trim();
|
|
const shortCode = suffix || (codiceCliente ? codiceCliente.charAt(0) : "--");
|
|
|
|
return `${nome.trim()} - ${shortCode} (ID: ${id})`;
|
|
}
|
|
|
|
async function loadClients() {
|
|
try {
|
|
clientLoadingStatus.style.display = 'inline';
|
|
clientLoadingStatus.textContent = 'Loading clients...';
|
|
|
|
const response = await fetch("get_clienti.php", {
|
|
method: "GET",
|
|
headers: {
|
|
"Content-Type": "application/json"
|
|
}
|
|
});
|
|
|
|
const data = await response.json();
|
|
|
|
if (!response.ok) {
|
|
throw new Error(data.error || `HTTP error: ${response.status}`);
|
|
}
|
|
|
|
const select = document.getElementById("clientSelect");
|
|
select.innerHTML = '<option value="">Select a client...</option>';
|
|
|
|
data.value.forEach(client => {
|
|
const id = client.IdCliente || "";
|
|
const option = new Option(formatClientLabel(client), id);
|
|
|
|
if (parseInt(id) === parseInt(selectedClientId)) {
|
|
option.selected = true;
|
|
}
|
|
|
|
select.add(option);
|
|
});
|
|
|
|
$(select).trigger('change');
|
|
clientLoadingStatus.textContent = "Clients loaded.";
|
|
} catch (error) {
|
|
clientLoadingStatus.textContent = "Loading error.";
|
|
|
|
Swal.fire({
|
|
title: "Error!",
|
|
text: "Unable to load clients: " + error.message,
|
|
icon: "error",
|
|
confirmButtonText: "OK"
|
|
});
|
|
} finally {
|
|
setTimeout(() => clientLoadingStatus.style.display = 'none', 1500);
|
|
}
|
|
}
|
|
|
|
async function loadSchemas() {
|
|
try {
|
|
schemaLoadingStatus.style.display = 'inline';
|
|
schemaLoadingStatus.textContent = 'Loading schemas...';
|
|
|
|
const response = await fetch("get_schemi.php", {
|
|
method: "GET",
|
|
headers: {
|
|
"Content-Type": "application/json"
|
|
}
|
|
});
|
|
|
|
const data = await response.json();
|
|
|
|
if (!response.ok) {
|
|
throw new Error(data.error || `HTTP error: ${response.status}`);
|
|
}
|
|
|
|
const select = document.getElementById("schemaSelect");
|
|
select.innerHTML = '<option value="">Select a schema...</option>';
|
|
|
|
const sortedSchemas = [...data.value].sort((a, b) => {
|
|
const nomeA = (a.Nome || "").trim().toLowerCase();
|
|
const nomeB = (b.Nome || "").trim().toLowerCase();
|
|
return nomeA.localeCompare(nomeB, 'it', {
|
|
sensitivity: 'base'
|
|
});
|
|
});
|
|
|
|
sortedSchemas.forEach(schema => {
|
|
const nome = schema.Nome || "Name not available";
|
|
const id = schema.IdSchemaCustomFields || "";
|
|
const option = new Option(`${nome.trim()} (ID: ${id})`, id);
|
|
|
|
if (parseInt(id) === parseInt(selectedSchemaId)) {
|
|
option.selected = true;
|
|
}
|
|
|
|
select.add(option);
|
|
});
|
|
|
|
$(select).trigger('change');
|
|
schemaLoadingStatus.textContent = "Schemas loaded.";
|
|
} catch (error) {
|
|
schemaLoadingStatus.textContent = "Loading error.";
|
|
|
|
Swal.fire({
|
|
title: "Error!",
|
|
text: "Unable to load schemas: " + error.message,
|
|
icon: "error",
|
|
confirmButtonText: "OK"
|
|
});
|
|
} finally {
|
|
setTimeout(() => schemaLoadingStatus.style.display = 'none', 1500);
|
|
}
|
|
}
|
|
|
|
async function loadData() {
|
|
try {
|
|
await loadClients();
|
|
await loadSchemas();
|
|
} catch (error) {
|
|
Swal.fire({
|
|
title: "Error!",
|
|
text: "Error while loading data: " + error.message,
|
|
icon: "error",
|
|
confirmButtonText: "OK"
|
|
});
|
|
}
|
|
}
|
|
|
|
loadData();
|
|
|
|
const routines = <?php echo json_encode($routines); ?>;
|
|
|
|
function updateRoutineDetails() {
|
|
const selectedId = routineSelect.value;
|
|
routineDetails.style.display = selectedId ? 'block' : 'none';
|
|
|
|
if (selectedId) {
|
|
const routine = routines.find(r => r.idroutine == selectedId);
|
|
|
|
if (routine) {
|
|
routineName.textContent = routine.name || 'N/A';
|
|
routineDescription.textContent = routine.description || 'N/A';
|
|
routineAction1.textContent = routine.action1 || 'N/A';
|
|
routineAction2.textContent = routine.action2 || 'N/A';
|
|
routineAction3.textContent = routine.action3 || 'N/A';
|
|
} else {
|
|
routineName.textContent = 'N/A';
|
|
routineDescription.textContent = 'N/A';
|
|
routineAction1.textContent = 'N/A';
|
|
routineAction2.textContent = 'N/A';
|
|
routineAction3.textContent = 'N/A';
|
|
}
|
|
} else {
|
|
routineName.textContent = '';
|
|
routineDescription.textContent = '';
|
|
routineAction1.textContent = '';
|
|
routineAction2.textContent = '';
|
|
routineAction3.textContent = '';
|
|
}
|
|
}
|
|
|
|
routineSelect.addEventListener('change', updateRoutineDetails);
|
|
updateRoutineDetails();
|
|
|
|
form.addEventListener("submit", function(e) {
|
|
e.preventDefault();
|
|
|
|
let formData = new FormData(this);
|
|
|
|
const clientSelect = document.getElementById("clientSelect");
|
|
const clientId = clientSelect.value;
|
|
const selectedClientOption = clientSelect.options[clientSelect.selectedIndex];
|
|
|
|
if (!clientId) {
|
|
Swal.fire({
|
|
title: "Error!",
|
|
text: "Please select a client.",
|
|
icon: "error",
|
|
confirmButtonText: "OK"
|
|
});
|
|
return;
|
|
}
|
|
|
|
let clientName = "";
|
|
if (selectedClientOption) {
|
|
const optionText = selectedClientOption.text.trim();
|
|
const nameMatch = optionText.match(/^(.+?)(?:\s*\(ID:\s*\d+\))?$/);
|
|
clientName = nameMatch ? nameMatch[1].trim() : optionText;
|
|
}
|
|
formData.append("client_name", clientName);
|
|
|
|
const schemaSelect = document.getElementById("schemaSelect");
|
|
const schemaId = schemaSelect.value;
|
|
const selectedSchemaOption = schemaSelect.options[schemaSelect.selectedIndex];
|
|
|
|
if (!schemaId) {
|
|
Swal.fire({
|
|
title: "Error!",
|
|
text: "Please select a schema.",
|
|
icon: "error",
|
|
confirmButtonText: "OK"
|
|
});
|
|
return;
|
|
}
|
|
|
|
let schemaName = "";
|
|
if (selectedSchemaOption) {
|
|
const optionText = selectedSchemaOption.text.trim();
|
|
const nameMatch = optionText.match(/^(.+?)(?:\s*\(ID:\s*\d+\))?$/);
|
|
schemaName = nameMatch ? nameMatch[1].trim() : optionText;
|
|
}
|
|
|
|
formData.append("idschema", schemaId);
|
|
formData.append("schemaname", schemaName);
|
|
|
|
const routineId = routineSelect.value;
|
|
formData.append("idroutine", routineId);
|
|
|
|
fetch("process_edit_template_xls.php", {
|
|
method: "POST",
|
|
body: formData
|
|
})
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
if (data.success) {
|
|
Swal.fire({
|
|
title: "Success!",
|
|
text: "Template updated 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(() => {
|
|
Swal.fire({
|
|
title: "Error!",
|
|
text: "An unexpected error occurred.",
|
|
icon: "error",
|
|
confirmButtonText: "OK"
|
|
});
|
|
});
|
|
});
|
|
});
|
|
</script>
|
|
</body>
|
|
|
|
</html>
|