Merge branch 'features/routine'
This commit is contained in:
commit
b39d601ec9
12
.gitignore
vendored
12
.gitignore
vendored
@ -51,4 +51,16 @@ public/userarea/class/curl_request_debug.log
|
|||||||
# Ignora cartella photostrf in public/userarea
|
# Ignora cartella photostrf in public/userarea
|
||||||
/public/userarea/photostrf/
|
/public/userarea/photostrf/
|
||||||
public/userarea/customfield_values_response.json
|
public/userarea/customfield_values_response.json
|
||||||
|
/public/userarea/logaspi/
|
||||||
|
|
||||||
|
public/userarea/logsapi/campione_762_1.json
|
||||||
|
public/userarea/logsapi/campione_763_1.json
|
||||||
|
public/userarea/logsapi/campione_762_2.json
|
||||||
|
public/userarea/logsapi/campione_763_2.json
|
||||||
|
public/userarea/logsapi/commessaweb_create_762.json
|
||||||
|
public/userarea/logsapi/commessaweb_create_763.json
|
||||||
|
public/userarea/logsapi/commessaweb_customfields_762.json
|
||||||
|
public/userarea/logsapi/commessaweb_customfields_763.json
|
||||||
|
public/userarea/logsapi/commessaweb_invia_762.json
|
||||||
|
public/userarea/logsapi/commessaweb_invia_763.json
|
||||||
|
public/userarea/logsapi/last_auth_url.txt
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@ -20,17 +20,10 @@ if (!$template) {
|
|||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Debug del JSON
|
// Recupera tutte le routine dal database
|
||||||
$clientSpecificFieldsJson = $template['client_specific_fields'] ?? '{}';
|
$stmt = $pdo->prepare("SELECT * FROM routine");
|
||||||
error_log("Raw client_specific_fields JSON: " . $clientSpecificFieldsJson);
|
$stmt->execute();
|
||||||
|
$routines = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
$clientSpecificFields = json_decode($clientSpecificFieldsJson, true);
|
|
||||||
if (json_last_error() !== JSON_ERROR_NONE) {
|
|
||||||
error_log("JSON decode error: " . json_last_error_msg());
|
|
||||||
$clientSpecificFields = [];
|
|
||||||
} else {
|
|
||||||
error_log("Decoded client_specific_fields: " . print_r($clientSpecificFields, true));
|
|
||||||
}
|
|
||||||
?>
|
?>
|
||||||
<!doctype html>
|
<!doctype html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
@ -41,28 +34,9 @@ if (json_last_error() !== JSON_ERROR_NONE) {
|
|||||||
<link rel="icon" href="assets/images/favicon-32x32.png" type="image/png" />
|
<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" />
|
<link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css" rel="stylesheet" />
|
||||||
<?php include('cssinclude.php'); ?>
|
<?php include('cssinclude.php'); ?>
|
||||||
<style>
|
<!-- Include jQuery prima di Select2 -->
|
||||||
.client-field-row .row {
|
<script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
|
||||||
margin-bottom: 0 !important;
|
<script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script>
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
.client-field-row .col-md-1,
|
|
||||||
.client-field-row .col-md-2,
|
|
||||||
.client-field-row .col-md-3 {
|
|
||||||
padding: 0 5px;
|
|
||||||
overflow: hidden;
|
|
||||||
max-width: 100%;
|
|
||||||
flex: 0 0 auto;
|
|
||||||
}
|
|
||||||
|
|
||||||
.client-field-row input,
|
|
||||||
.client-field-row select {
|
|
||||||
width: 100%;
|
|
||||||
box-sizing: border-box;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
<title>Edit Template <?= htmlspecialchars($titlewebsite, ENT_QUOTES, 'UTF-8'); ?></title>
|
<title>Edit Template <?= htmlspecialchars($titlewebsite, ENT_QUOTES, 'UTF-8'); ?></title>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
@ -82,7 +56,7 @@ if (json_last_error() !== JSON_ERROR_NONE) {
|
|||||||
<ul class="mb-0">
|
<ul class="mb-0">
|
||||||
<li>Template Name</li>
|
<li>Template Name</li>
|
||||||
<li>Row Header and Column Header: where the title of the excel starts</li>
|
<li>Row Header and Column Header: where the title of the excel starts</li>
|
||||||
<li>Cheme</li>
|
<li>Schema</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -124,95 +98,42 @@ if (json_last_error() !== JSON_ERROR_NONE) {
|
|||||||
<label class="form-label"><?= htmlspecialchars($desttable, ENT_QUOTES, 'UTF-8'); ?>*</label>
|
<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']); ?>" readonly required>
|
<input type="text" name="target_table" class="form-control" value="<?php echo htmlspecialchars($template['target_table']); ?>" readonly required>
|
||||||
</div>
|
</div>
|
||||||
<!-- Aggiungi il campo per selezionare il cliente -->
|
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label class="form-label">Select Client *</label>
|
<label class="form-label">Select Client *</label>
|
||||||
<select name="client_id" id="clientSelect" class="form-control" required>
|
<select name="client_id" id="clientSelect" class="form-control" required>
|
||||||
<option value="">Select a client...</option>
|
<option value="">Select a client...</option>
|
||||||
<!-- Le opzioni verranno popolate tramite JavaScript -->
|
|
||||||
</select>
|
</select>
|
||||||
<span id="clientLoadingStatus" class="text-muted" style="margin-left: 10px; display: none;">Recupero clienti in corso...</span>
|
<span id="clientLoadingStatus" class="text-muted" style="margin-left: 10px; display: none;">Recupero clienti in corso...</span>
|
||||||
</div>
|
</div>
|
||||||
<!-- Aggiungi il campo per selezionare lo schema -->
|
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label class="form-label">Select Schema *</label>
|
<label class="form-label">Select Schema *</label>
|
||||||
<select name="schema_id" id="schemaSelect" class="form-control" required>
|
<select name="schema_id" id="schemaSelect" class="form-control" required>
|
||||||
<option value="">Select a schema...</option>
|
<option value="">Select a schema...</option>
|
||||||
<!-- Le opzioni verranno popolate tramite JavaScript -->
|
|
||||||
</select>
|
</select>
|
||||||
<span id="schemaLoadingStatus" class="text-muted" style="margin-left: 10px; display: none;">Caricamento schemi in corso...</span>
|
<span id="schemaLoadingStatus" class="text-muted" style="margin-left: 10px; display: none;">Caricamento schemi in corso...</span>
|
||||||
</div>
|
</div>
|
||||||
<!-- Sezione per i campi specifici del cliente -->
|
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label class="form-label">Client-Specific Fields</label>
|
<label class="form-label">Select Routine</label>
|
||||||
|
<select name="idroutine" id="routineSelect" class="form-control">
|
||||||
<!-- Intestazioni colonne -->
|
<option value="">Select a routine...</option>
|
||||||
<div class="row fw-bold text-secondary mb-1">
|
<?php foreach ($routines as $routine): ?>
|
||||||
<div class="col-md-3">Field Name</div>
|
<option value="<?php echo $routine['idroutine']; ?>" <?php echo ($template['idroutine'] ?? '') == $routine['idroutine'] ? 'selected' : ''; ?>>
|
||||||
<div class="col-md-2">Type</div>
|
<?php echo htmlspecialchars($routine['name']); ?>
|
||||||
<div class="col-md-2">Possible Values</div>
|
</option>
|
||||||
<div class="col-md-1">Required</div>
|
<?php endforeach; ?>
|
||||||
<div class="col-md-2">Export Column Name</div>
|
|
||||||
<div class="col-md-1">Default Value</div>
|
|
||||||
<div class="col-md-1">Actions</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="clientSpecificFields">
|
|
||||||
<?php
|
|
||||||
$index = 0;
|
|
||||||
if (!empty($clientSpecificFields) && is_array($clientSpecificFields)) {
|
|
||||||
foreach ($clientSpecificFields as $fieldName => $fieldData) {
|
|
||||||
if (is_array($fieldData)) {
|
|
||||||
$type = $fieldData['type'] ?? 'text';
|
|
||||||
$possibleValues = implode(', ', $fieldData['possible_values'] ?? []);
|
|
||||||
$isRequired = isset($fieldData['is_required']) && $fieldData['is_required'] ? '1' : '0';
|
|
||||||
$exportColumnName = $fieldData['export_column_name'] ?? '';
|
|
||||||
$defaultValue = $fieldData['default_value'] ?? '';
|
|
||||||
?>
|
|
||||||
<div class="client-field-row mb-2">
|
|
||||||
<div class="row align-items-center">
|
|
||||||
<div class="col-md-3">
|
|
||||||
<input type="text" name="specific_fields[<?php echo $index; ?>][name]" class="form-control" value="<?php echo htmlspecialchars($fieldName); ?>" placeholder="Field Name (e.g., SKU)">
|
|
||||||
</div>
|
|
||||||
<div class="col-md-2">
|
|
||||||
<select name="specific_fields[<?php echo $index; ?>][type]" class="form-control" onchange="toggleDropdownValues(this)">
|
|
||||||
<option value="text" <?php echo $type === 'text' ? 'selected' : ''; ?>>Text</option>
|
|
||||||
<option value="dropdown" <?php echo $type === 'dropdown' ? 'selected' : ''; ?>>Dropdown</option>
|
|
||||||
<option value="date" <?php echo $type === 'date' ? 'selected' : ''; ?>>Date</option>
|
|
||||||
<option value="boolean" <?php echo $type === 'boolean' ? 'selected' : ''; ?>>Yes/No</option>
|
|
||||||
</select>
|
</select>
|
||||||
</div>
|
<div id="routineDetails" class="mt-2" style="display: none;">
|
||||||
<div class="col-md-2 dropdown-values" style="<?php echo $type === 'dropdown' ? 'visibility: visible;' : 'visibility: hidden;'; ?>">
|
<h6>Routine Details</h6>
|
||||||
<input type="text" name="specific_fields[<?php echo $index; ?>][possible_values]" class="form-control" value="<?php echo htmlspecialchars($possibleValues); ?>" placeholder="Values (e.g., Red, Blue, Green)">
|
<p><strong>Name:</strong> <span id="routineName"></span></p>
|
||||||
</div>
|
<p><strong>Description:</strong> <span id="routineDescription"></span></p>
|
||||||
<div class="col-md-1">
|
<p><strong>Action 1:</strong> <span id="routineAction1"></span></p>
|
||||||
<select name="specific_fields[<?php echo $index; ?>][required]" class="form-control">
|
<p><strong>Action 2:</strong> <span id="routineAction2"></span></p>
|
||||||
<option value="1" <?php echo $isRequired === '1' ? 'selected' : ''; ?>>Yes</option>
|
<p><strong>Action 3:</strong> <span id="routineAction3"></span></p>
|
||||||
<option value="0" <?php echo $isRequired === '0' ? 'selected' : ''; ?>>No</option>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
<div class="col-md-2">
|
|
||||||
<input type="text" name="specific_fields[<?php echo $index; ?>][export_column_name]" class="form-control" value="<?php echo htmlspecialchars($exportColumnName); ?>" placeholder="Export Column Name (e.g., MONCLER_SKU)">
|
|
||||||
</div>
|
|
||||||
<div class="col-md-1">
|
|
||||||
<input type="text" name="specific_fields[<?php echo $index; ?>][default_value]" class="form-control" value="<?php echo htmlspecialchars($defaultValue); ?>" placeholder="Default Value (optional)">
|
|
||||||
</div>
|
|
||||||
<div class="col-md-1">
|
|
||||||
<button type="button" class="btn btn-danger remove-field">-</button>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
<?php
|
|
||||||
$index++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<button type="button" class="btn btn-primary mt-2" id="addField">Add Field</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
<br>
|
<br>
|
||||||
<button type="submit" class="btn btn-primary"><?= htmlspecialchars($savechanges, ENT_QUOTES, 'UTF-8'); ?></button>
|
<button type="submit" class="btn btn-primary"><?= htmlspecialchars($savechanges, ENT_QUOTES, 'UTF-8'); ?></button>
|
||||||
@ -223,132 +144,78 @@ if (json_last_error() !== JSON_ERROR_NONE) {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<!--end page wrapper -->
|
|
||||||
<!--start overlay-->
|
|
||||||
<div class="overlay toggle-icon"></div>
|
<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>
|
<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'); ?>
|
<?php include('include/footer.php'); ?>
|
||||||
</div>
|
</div>
|
||||||
<!--end wrapper-->
|
|
||||||
|
|
||||||
<!-- search modal -->
|
|
||||||
<?php //include('include/searchmodal.php');
|
|
||||||
?>
|
|
||||||
<!-- end search modal -->
|
|
||||||
|
|
||||||
<!--start switcher-->
|
|
||||||
<?php //include('include/themeswitcher.php');
|
|
||||||
?>
|
|
||||||
<!--end switcher-->
|
|
||||||
<!-- Temporaneamente disabilitato jsinclude.php per test -->
|
|
||||||
<!-- <?php include('jsinclude.php'); ?> -->
|
|
||||||
<!-- Includi jQuery e Select2 -->
|
|
||||||
<script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
// Dati del cliente e dello schema associati al template
|
|
||||||
const templateClientId = <?php echo json_encode($template['idclient'] ?? 0); ?>;
|
|
||||||
const templateSchemaId = <?php echo json_encode($template['idschema'] ?? 0); ?>;
|
|
||||||
const templateSchemaName = "<?php echo htmlspecialchars($template['schemaname'] ?? ''); ?>";
|
|
||||||
</script>
|
|
||||||
<script>
|
<script>
|
||||||
document.addEventListener("DOMContentLoaded", function() {
|
document.addEventListener("DOMContentLoaded", function() {
|
||||||
|
// Verifica che jQuery sia caricato
|
||||||
|
if (typeof jQuery === 'undefined') {
|
||||||
|
alert("Errore: jQuery non è caricato. Contatta l'amministratore.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const form = document.getElementById("editTemplateForm");
|
const form = document.getElementById("editTemplateForm");
|
||||||
const addFieldButton = document.getElementById("addField");
|
|
||||||
const container = document.getElementById("clientSpecificFields");
|
|
||||||
const clientLoadingStatus = document.getElementById("clientLoadingStatus");
|
const clientLoadingStatus = document.getElementById("clientLoadingStatus");
|
||||||
const schemaLoadingStatus = document.getElementById("schemaLoadingStatus");
|
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");
|
||||||
|
|
||||||
if (!form || !addFieldButton || !container || !clientLoadingStatus || !schemaLoadingStatus) {
|
if (!form || !clientLoadingStatus || !schemaLoadingStatus || !routineSelect || !routineDetails) {
|
||||||
console.error("One or more DOM elements not found:", {
|
alert("Errore: Uno o più elementi della pagina non sono stati trovati. Contatta l'amministratore.");
|
||||||
form,
|
|
||||||
addFieldButton,
|
|
||||||
container,
|
|
||||||
clientLoadingStatus,
|
|
||||||
schemaLoadingStatus
|
|
||||||
});
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("All DOM elements found");
|
// Inizializza Select2
|
||||||
|
|
||||||
// Controllo che jQuery sia caricato
|
|
||||||
if (typeof jQuery === 'undefined') {
|
|
||||||
console.error("jQuery non è caricato!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Inizializza Select2 sulla tendina dei clienti
|
|
||||||
$('#clientSelect').select2({
|
$('#clientSelect').select2({
|
||||||
placeholder: "Search for a client...",
|
placeholder: "Search for a client...",
|
||||||
allowClear: true
|
allowClear: true
|
||||||
}).on('select2:open', function() {
|
|
||||||
console.log("Select2 initialized successfully for clientSelect");
|
|
||||||
}).on('select2:select', function(e) {
|
|
||||||
console.log("Client selected:", e.params.data.id, e.params.data.text);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Inizializza Select2 sulla tendina degli schemi
|
|
||||||
$('#schemaSelect').select2({
|
$('#schemaSelect').select2({
|
||||||
placeholder: "Search for a schema...",
|
placeholder: "Search for a schema...",
|
||||||
allowClear: true
|
allowClear: true
|
||||||
}).on('select2:open', function() {
|
|
||||||
console.log("Select2 initialized successfully for schemaSelect");
|
|
||||||
}).on('select2:select', function(e) {
|
|
||||||
console.log("Schema selected:", e.params.data.id, e.params.data.text);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Carica i clienti al caricamento della pagina
|
$('#routineSelect').select2({
|
||||||
|
placeholder: "Select a routine...",
|
||||||
|
allowClear: true
|
||||||
|
});
|
||||||
|
|
||||||
|
// Carica i clienti
|
||||||
async function loadClients() {
|
async function loadClients() {
|
||||||
try {
|
try {
|
||||||
clientLoadingStatus.style.display = 'inline';
|
clientLoadingStatus.style.display = 'inline';
|
||||||
clientLoadingStatus.textContent = 'Recupero clienti in corso...';
|
clientLoadingStatus.textContent = 'Recupero clienti in corso...';
|
||||||
|
|
||||||
const response = await fetch("get_clienti.php", {
|
const response = await fetch("get_clienti.php", {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json"
|
"Content-Type": "application/json"
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
const data = await response.json();
|
||||||
const text = await response.text();
|
if (!response.ok) throw new Error(data.error || `Errore HTTP: ${response.status}`);
|
||||||
console.log("Risposta raw (clienti):", text);
|
|
||||||
const data = JSON.parse(text);
|
|
||||||
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error(data.error || `Errore HTTP: ${response.status}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (data.value && Array.isArray(data.value)) {
|
|
||||||
const select = document.getElementById("clientSelect");
|
const select = document.getElementById("clientSelect");
|
||||||
select.innerHTML = '<option value="">Select a client...</option>';
|
select.innerHTML = '<option value="">Select a client...</option>';
|
||||||
data.value.forEach(client => {
|
data.value.forEach(client => {
|
||||||
const nome = client.Nominativo || "Nome non disponibile";
|
const nome = client.Nominativo || "Nome non disponibile";
|
||||||
const id = client.IdCliente || "ID non disponibile";
|
const id = client.IdCliente || "ID non disponibile";
|
||||||
const option = new Option(`${nome.trim()} (ID: ${id})`, id);
|
const option = new Option(`${nome.trim()} (ID: ${id})`, id);
|
||||||
if (parseInt(id) === parseInt(templateClientId)) {
|
if (parseInt(id) === parseInt(<?php echo json_encode($template['idclient'] ?? 0); ?>)) {
|
||||||
option.selected = true;
|
option.selected = true;
|
||||||
}
|
}
|
||||||
select.add(option);
|
select.add(option);
|
||||||
});
|
});
|
||||||
$(select).trigger('change');
|
$(select).trigger('change');
|
||||||
console.log("Clienti caricati con successo.");
|
|
||||||
clientLoadingStatus.textContent = "Clienti caricati.";
|
clientLoadingStatus.textContent = "Clienti caricati.";
|
||||||
} else {
|
|
||||||
console.error("Nessun cliente trovato o formato dati non valido.", data);
|
|
||||||
clientLoadingStatus.textContent = "Nessun cliente trovato.";
|
|
||||||
Swal.fire({
|
|
||||||
title: "Errore!",
|
|
||||||
text: "Nessun cliente trovato o formato dati non valido.",
|
|
||||||
icon: "error",
|
|
||||||
confirmButtonText: "OK"
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Errore nel caricamento dei clienti:", error);
|
|
||||||
clientLoadingStatus.textContent = "Errore nel caricamento.";
|
clientLoadingStatus.textContent = "Errore nel caricamento.";
|
||||||
Swal.fire({
|
Swal.fire({
|
||||||
title: "Errore!",
|
title: "Errore!",
|
||||||
@ -357,50 +224,37 @@ if (json_last_error() !== JSON_ERROR_NONE) {
|
|||||||
confirmButtonText: "OK"
|
confirmButtonText: "OK"
|
||||||
});
|
});
|
||||||
} finally {
|
} finally {
|
||||||
setTimeout(() => {
|
setTimeout(() => clientLoadingStatus.style.display = 'none', 2000);
|
||||||
clientLoadingStatus.style.display = 'none';
|
|
||||||
}, 2000);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Carica gli schemi al caricamento della pagina
|
// Carica gli schemi
|
||||||
async function loadSchemas() {
|
async function loadSchemas() {
|
||||||
try {
|
try {
|
||||||
schemaLoadingStatus.style.display = 'inline';
|
schemaLoadingStatus.style.display = 'inline';
|
||||||
schemaLoadingStatus.textContent = 'Caricamento schemi in corso...';
|
schemaLoadingStatus.textContent = 'Caricamento schemi in corso...';
|
||||||
|
|
||||||
const response = await fetch("get_schemi.php", {
|
const response = await fetch("get_schemi.php", {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json"
|
"Content-Type": "application/json"
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
const data = await response.json();
|
||||||
const text = await response.text();
|
if (!response.ok) throw new Error(data.error || `Errore HTTP: ${response.status}`);
|
||||||
console.log("Risposta raw (schemi):", text);
|
|
||||||
const data = JSON.parse(text);
|
|
||||||
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error(data.error || `Errore HTTP: ${response.status}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
const select = document.getElementById("schemaSelect");
|
const select = document.getElementById("schemaSelect");
|
||||||
select.innerHTML = '<option value="">Select a schema...</option>';
|
select.innerHTML = '<option value="">Select a schema...</option>';
|
||||||
data.value.forEach(schema => {
|
data.value.forEach(schema => {
|
||||||
const nome = schema.Nome || "Nome non disponibile";
|
const nome = schema.Nome || "Nome non disponibile";
|
||||||
const id = schema.IdSchemaCustomFields || "ID non disponibile";
|
const id = schema.IdSchemaCustomFields || "ID non disponibile";
|
||||||
const optionText = `${nome.trim()} (ID: ${id})`;
|
const option = new Option(`${nome.trim()} (ID: ${id})`, id);
|
||||||
const option = new Option(optionText, id);
|
if (parseInt(id) === parseInt(<?php echo json_encode($template['idschema'] ?? 0); ?>)) {
|
||||||
if (parseInt(id) === parseInt(templateSchemaId)) {
|
|
||||||
option.selected = true;
|
option.selected = true;
|
||||||
}
|
}
|
||||||
select.add(option);
|
select.add(option);
|
||||||
});
|
});
|
||||||
$(select).trigger('change');
|
$(select).trigger('change');
|
||||||
console.log("Schemi caricati con successo.");
|
|
||||||
schemaLoadingStatus.textContent = "Schemi caricati.";
|
schemaLoadingStatus.textContent = "Schemi caricati.";
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Errore nel caricamento degli schemi:", error);
|
|
||||||
schemaLoadingStatus.textContent = "Errore nel caricamento.";
|
schemaLoadingStatus.textContent = "Errore nel caricamento.";
|
||||||
Swal.fire({
|
Swal.fire({
|
||||||
title: "Errore!",
|
title: "Errore!",
|
||||||
@ -409,169 +263,68 @@ if (json_last_error() !== JSON_ERROR_NONE) {
|
|||||||
confirmButtonText: "OK"
|
confirmButtonText: "OK"
|
||||||
});
|
});
|
||||||
} finally {
|
} finally {
|
||||||
setTimeout(() => {
|
setTimeout(() => schemaLoadingStatus.style.display = 'none', 2000);
|
||||||
schemaLoadingStatus.style.display = 'none';
|
|
||||||
}, 2000);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Carica i dati in sequenza
|
// Carica i dati
|
||||||
async function loadData() {
|
async function loadData() {
|
||||||
try {
|
try {
|
||||||
await loadClients();
|
await loadClients();
|
||||||
await loadSchemas();
|
await loadSchemas();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Errore nel caricamento dei dati:", error);
|
Swal.fire({
|
||||||
|
title: "Errore!",
|
||||||
|
text: "Errore nel caricamento dei dati: " + error.message,
|
||||||
|
icon: "error",
|
||||||
|
confirmButtonText: "OK"
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
loadData();
|
loadData();
|
||||||
|
|
||||||
// Debug iniziale del DOM
|
// Routine dettagli
|
||||||
const debugDom = () => {
|
const routines = <?php echo json_encode($routines); ?>;
|
||||||
const initialRows = container.getElementsByClassName("client-field-row");
|
|
||||||
console.log("Initial number of rows:", initialRows.length);
|
|
||||||
for (let i = 0; i < initialRows.length; i++) {
|
|
||||||
const inputs = initialRows[i].querySelectorAll("input, select");
|
|
||||||
const buttons = initialRows[i].querySelectorAll("button");
|
|
||||||
console.log(`Row ${i + 1} - Total inputs: ${inputs.length}, Total buttons: ${buttons.length}`);
|
|
||||||
inputs.forEach(input => console.log(`Input name: ${input.name}, value: ${input.value}, placeholder: ${input.placeholder}`));
|
|
||||||
buttons.forEach(button => console.log(`Button type: ${button.type}`));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
debugDom();
|
function updateRoutineDetails() {
|
||||||
|
const selectedId = routineSelect.value;
|
||||||
// Pulizia del DOM da input extra
|
routineDetails.style.display = selectedId ? 'block' : 'none';
|
||||||
const cleanDom = () => {
|
if (selectedId) {
|
||||||
const rows = container.getElementsByClassName("client-field-row");
|
const routine = routines.find(r => r.idroutine == selectedId);
|
||||||
for (let i = 0; i < rows.length; i++) {
|
if (routine) {
|
||||||
const inputs = rows[i].querySelectorAll("input, select");
|
routineName.textContent = routine.name || 'N/A';
|
||||||
if (inputs.length > 6) { // 6 input/select attesi
|
routineDescription.textContent = routine.description || 'N/A';
|
||||||
console.warn(`Row ${i + 1}: Extra inputs detected, removing excess...`);
|
routineAction1.textContent = routine.action1 || 'N/A';
|
||||||
inputs.forEach((input, index) => {
|
routineAction2.textContent = routine.action2 || 'N/A';
|
||||||
if (index >= 6) {
|
routineAction3.textContent = routine.action3 || 'N/A';
|
||||||
console.log(`Removing extra input: ${input.name}`);
|
|
||||||
input.remove();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
cleanDom();
|
|
||||||
|
|
||||||
// Osservatore del DOM per rilevare modifiche
|
|
||||||
const observer = new MutationObserver((mutations) => {
|
|
||||||
mutations.forEach(mutation => {
|
|
||||||
if (mutation.addedNodes.length) {
|
|
||||||
console.log("DOM modified: New nodes added", mutation.addedNodes);
|
|
||||||
cleanDom(); // Pulisce il DOM ogni volta che viene modificato
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
observer.observe(container, {
|
|
||||||
childList: true,
|
|
||||||
subtree: true
|
|
||||||
});
|
|
||||||
|
|
||||||
// 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 align-items-center">
|
|
||||||
<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 dropdown-values" style="visibility: hidden;">
|
|
||||||
<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();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// Funzione per mostrare/nascondere il campo dei valori possibili per i dropdown
|
|
||||||
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.visibility = "visible";
|
|
||||||
} else {
|
} else {
|
||||||
dropdownValues.style.visibility = "hidden";
|
routineName.textContent = 'N/A';
|
||||||
|
routineDescription.textContent = 'N/A';
|
||||||
|
routineAction1.textContent = 'N/A';
|
||||||
|
routineAction2.textContent = 'N/A';
|
||||||
|
routineAction3.textContent = 'N/A';
|
||||||
}
|
}
|
||||||
};
|
} else {
|
||||||
|
routineName.textContent = '';
|
||||||
// Event listener per i pulsanti di rimozione esistenti
|
routineDescription.textContent = '';
|
||||||
document.querySelectorAll(".remove-field").forEach(button => {
|
routineAction1.textContent = '';
|
||||||
button.addEventListener("click", function() {
|
routineAction2.textContent = '';
|
||||||
console.log("Existing remove button clicked");
|
routineAction3.textContent = '';
|
||||||
const container = document.getElementById("clientSpecificFields");
|
|
||||||
container.removeChild(button.closest(".client-field-row"));
|
|
||||||
updateFieldIndices();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// Funzione per aggiornare gli indici dei campi
|
|
||||||
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;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
routineSelect.addEventListener('change', updateRoutineDetails);
|
||||||
|
updateRoutineDetails(); // Inizializza dettagli se una routine è preselezionata
|
||||||
|
|
||||||
// Submit del form
|
// Submit del form
|
||||||
form.addEventListener("submit", function(e) {
|
form.addEventListener("submit", function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
console.log("Form submitted");
|
|
||||||
|
|
||||||
let formData = new FormData(this);
|
let formData = new FormData(this);
|
||||||
|
|
||||||
// Aggiungi il nome del cliente selezionato a FormData
|
|
||||||
const clientSelect = document.getElementById("clientSelect");
|
const clientSelect = document.getElementById("clientSelect");
|
||||||
const clientId = clientSelect.value;
|
const clientId = clientSelect.value;
|
||||||
const selectedClientOption = clientSelect.options[clientSelect.selectedIndex];
|
const selectedClientOption = clientSelect.options[clientSelect.selectedIndex];
|
||||||
|
|
||||||
// Validazione: assicurati che un cliente sia selezionato
|
|
||||||
if (!clientId) {
|
if (!clientId) {
|
||||||
Swal.fire({
|
Swal.fire({
|
||||||
title: "Errore!",
|
title: "Errore!",
|
||||||
@ -582,22 +335,18 @@ if (json_last_error() !== JSON_ERROR_NONE) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Estrai il nome del cliente in modo più robusto
|
|
||||||
let clientName = "";
|
let clientName = "";
|
||||||
if (selectedClientOption) {
|
if (selectedClientOption) {
|
||||||
const optionText = selectedClientOption.text.trim();
|
const optionText = selectedClientOption.text.trim();
|
||||||
const nameMatch = optionText.match(/^(.+?)(?:\s*\(ID:\s*\d+\))?$/);
|
const nameMatch = optionText.match(/^(.+?)(?:\s*\(ID:\s*\d+\))?$/);
|
||||||
clientName = nameMatch ? nameMatch[1].trim() : optionText;
|
clientName = nameMatch ? nameMatch[1].trim() : optionText;
|
||||||
}
|
}
|
||||||
|
|
||||||
formData.append("client_name", clientName);
|
formData.append("client_name", clientName);
|
||||||
|
|
||||||
// Aggiungi l'ID e il nome dello schema selezionato a FormData
|
|
||||||
const schemaSelect = document.getElementById("schemaSelect");
|
const schemaSelect = document.getElementById("schemaSelect");
|
||||||
const schemaId = schemaSelect.value;
|
const schemaId = schemaSelect.value;
|
||||||
const selectedSchemaOption = schemaSelect.options[schemaSelect.selectedIndex];
|
const selectedSchemaOption = schemaSelect.options[schemaSelect.selectedIndex];
|
||||||
|
|
||||||
// Validazione: assicurati che uno schema sia selezionato
|
|
||||||
if (!schemaId) {
|
if (!schemaId) {
|
||||||
Swal.fire({
|
Swal.fire({
|
||||||
title: "Errore!",
|
title: "Errore!",
|
||||||
@ -608,63 +357,18 @@ if (json_last_error() !== JSON_ERROR_NONE) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Estrai il nome dello schema in modo più robusto
|
|
||||||
let schemaName = "";
|
let schemaName = "";
|
||||||
if (selectedSchemaOption) {
|
if (selectedSchemaOption) {
|
||||||
const optionText = selectedSchemaOption.text.trim();
|
const optionText = selectedSchemaOption.text.trim();
|
||||||
const nameMatch = optionText.match(/^(.+?)(?:\s*\(ID:\s*\d+\))?$/);
|
const nameMatch = optionText.match(/^(.+?)(?:\s*\(ID:\s*\d+\))?$/);
|
||||||
schemaName = nameMatch ? nameMatch[1].trim() : optionText;
|
schemaName = nameMatch ? nameMatch[1].trim() : optionText;
|
||||||
}
|
}
|
||||||
|
|
||||||
formData.append("idschema", schemaId);
|
formData.append("idschema", schemaId);
|
||||||
formData.append("schemamaname", schemaName);
|
formData.append("schemaname", schemaName);
|
||||||
|
|
||||||
// Log per debug
|
// Aggiungi idroutine
|
||||||
console.log("Client ID:", clientId);
|
const routineId = routineSelect.value;
|
||||||
console.log("Client Name:", clientName);
|
formData.append("idroutine", routineId);
|
||||||
console.log("Schema ID:", schemaId);
|
|
||||||
console.log("Schema Name:", schemaName);
|
|
||||||
|
|
||||||
// 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_edit_template_xls.php", {
|
fetch("process_edit_template_xls.php", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
@ -672,7 +376,6 @@ if (json_last_error() !== JSON_ERROR_NONE) {
|
|||||||
})
|
})
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(data => {
|
.then(data => {
|
||||||
console.log("Fetch response:", data);
|
|
||||||
if (data.success) {
|
if (data.success) {
|
||||||
Swal.fire({
|
Swal.fire({
|
||||||
title: "Successo!",
|
title: "Successo!",
|
||||||
@ -692,7 +395,6 @@ if (json_last_error() !== JSON_ERROR_NONE) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
console.error("Errore Fetch:", error);
|
|
||||||
Swal.fire({
|
Swal.fire({
|
||||||
title: "Errore!",
|
title: "Errore!",
|
||||||
text: "Si è verificato un errore imprevisto.",
|
text: "Si è verificato un errore imprevisto.",
|
||||||
|
|||||||
239
public/userarea/export_to_lims.js
Normal file
239
public/userarea/export_to_lims.js
Normal file
@ -0,0 +1,239 @@
|
|||||||
|
document.addEventListener("DOMContentLoaded", () => {
|
||||||
|
console.log("export_to_lims.js loaded");
|
||||||
|
|
||||||
|
// Debug: verifica che i pulsanti siano trovati
|
||||||
|
const exportButtons = document.querySelectorAll(".export-lims-btn");
|
||||||
|
console.log(`Found ${exportButtons.length} export-lims-btn buttons`);
|
||||||
|
|
||||||
|
if (exportButtons.length === 0) {
|
||||||
|
console.warn("No .export-lims-btn buttons found in the DOM");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
exportButtons.forEach((btn) => {
|
||||||
|
btn.addEventListener("click", (e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
const rowIndex = btn.dataset.row;
|
||||||
|
const iddatadb = btn.dataset.iddatadb;
|
||||||
|
console.log(
|
||||||
|
`Export to LIMS clicked for row ${rowIndex}, iddatadb: ${iddatadb}`,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Mostra il modale di conferma
|
||||||
|
const confirmModalElement =
|
||||||
|
document.getElementById("exportConfirmModal");
|
||||||
|
if (!confirmModalElement) {
|
||||||
|
console.error("exportConfirmModal not found in the DOM");
|
||||||
|
alert("Errore: Modale di conferma non trovato");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const confirmModal = new bootstrap.Modal(confirmModalElement, {
|
||||||
|
keyboard: false,
|
||||||
|
});
|
||||||
|
document.getElementById("exportIddatadb").textContent = iddatadb;
|
||||||
|
confirmModal.show();
|
||||||
|
|
||||||
|
// Gestisci il click su "Conferma"
|
||||||
|
const confirmBtn = document.getElementById("exportConfirmBtn");
|
||||||
|
if (!confirmBtn) {
|
||||||
|
console.error("exportConfirmBtn not found in the DOM");
|
||||||
|
confirmModal.hide();
|
||||||
|
alert("Errore: Pulsante di conferma non trovato");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const confirmHandler = async () => {
|
||||||
|
console.log(`Confirmed export for iddatadb: ${iddatadb}`);
|
||||||
|
confirmModal.hide();
|
||||||
|
|
||||||
|
const formData = new FormData();
|
||||||
|
formData.append("iddatadb", iddatadb);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await fetch("export_to_lims.php", {
|
||||||
|
method: "POST",
|
||||||
|
body: formData,
|
||||||
|
});
|
||||||
|
if (!response.ok)
|
||||||
|
throw new Error(
|
||||||
|
`HTTP error! status: ${response.status}`,
|
||||||
|
);
|
||||||
|
const data = await response.json();
|
||||||
|
|
||||||
|
console.log("Export response:", data);
|
||||||
|
|
||||||
|
// Mostra il modale di risposta
|
||||||
|
const responseModalElement = document.getElementById(
|
||||||
|
"exportResponseModal",
|
||||||
|
);
|
||||||
|
if (!responseModalElement) {
|
||||||
|
console.error(
|
||||||
|
"exportResponseModal not found in the DOM",
|
||||||
|
);
|
||||||
|
alert("Errore: Modale di risposta non trovato");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const responseModal = new bootstrap.Modal(
|
||||||
|
responseModalElement,
|
||||||
|
{
|
||||||
|
keyboard: false,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
const responseMessage = document.getElementById(
|
||||||
|
"exportResponseMessage",
|
||||||
|
);
|
||||||
|
if (data.success) {
|
||||||
|
responseMessage.innerHTML = `${data.message.replace(/\n/g, "<br>")}<br>ID CommessaWeb: ${data.idcommessaweb}`;
|
||||||
|
document.getElementById(
|
||||||
|
"exportResponseModalLabel",
|
||||||
|
).textContent = "Esportazione Completata";
|
||||||
|
responseModal.show();
|
||||||
|
|
||||||
|
// Aggiorna la UI per riflettere lo stato 'To LIMS'
|
||||||
|
const statusCell = btn
|
||||||
|
.closest(".grid-row")
|
||||||
|
.querySelector(
|
||||||
|
'.grid-cell[data-col="status"] .status-badge',
|
||||||
|
);
|
||||||
|
if (statusCell) {
|
||||||
|
statusCell.classList.remove("status-i", "status-P");
|
||||||
|
statusCell.classList.add("status-l");
|
||||||
|
statusCell.textContent = "To LIMS";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Gestisci la chiusura del modale di risposta
|
||||||
|
responseModalElement.addEventListener(
|
||||||
|
"hidden.bs.modal",
|
||||||
|
() => {
|
||||||
|
console.log(
|
||||||
|
"exportResponseModal closed, cleaning up",
|
||||||
|
);
|
||||||
|
// Rimuovi tutti i backdrop residui
|
||||||
|
document
|
||||||
|
.querySelectorAll(".modal-backdrop")
|
||||||
|
.forEach((backdrop) => {
|
||||||
|
console.log(
|
||||||
|
"Removing backdrop:",
|
||||||
|
backdrop,
|
||||||
|
);
|
||||||
|
backdrop.remove();
|
||||||
|
});
|
||||||
|
// Ripristina il body
|
||||||
|
document.body.classList.remove("modal-open");
|
||||||
|
document.body.style.paddingRight = "";
|
||||||
|
// Nascondi l'overlay
|
||||||
|
const overlay = document.querySelector(
|
||||||
|
".overlay.toggle-icon",
|
||||||
|
);
|
||||||
|
if (overlay) {
|
||||||
|
overlay.style.display = "none";
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{ once: true },
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
responseMessage.textContent = `Errore durante la generazione dei payload: ${data.message}`;
|
||||||
|
document.getElementById(
|
||||||
|
"exportResponseModalLabel",
|
||||||
|
).textContent = "Errore Esportazione";
|
||||||
|
responseModal.show();
|
||||||
|
|
||||||
|
// Gestisci la chiusura del modale di risposta anche in caso di errore
|
||||||
|
responseModalElement.addEventListener(
|
||||||
|
"hidden.bs.modal",
|
||||||
|
() => {
|
||||||
|
console.log(
|
||||||
|
"exportResponseModal closed, cleaning up",
|
||||||
|
);
|
||||||
|
// Rimuovi tutti i backdrop residui
|
||||||
|
document
|
||||||
|
.querySelectorAll(".modal-backdrop")
|
||||||
|
.forEach((backdrop) => {
|
||||||
|
console.log(
|
||||||
|
"Removing backdrop:",
|
||||||
|
backdrop,
|
||||||
|
);
|
||||||
|
backdrop.remove();
|
||||||
|
});
|
||||||
|
// Ripristina il body
|
||||||
|
document.body.classList.remove("modal-open");
|
||||||
|
document.body.style.paddingRight = "";
|
||||||
|
// Nascondi l'overlay
|
||||||
|
const overlay = document.querySelector(
|
||||||
|
".overlay.toggle-icon",
|
||||||
|
);
|
||||||
|
if (overlay) {
|
||||||
|
overlay.style.display = "none";
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{ once: true },
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Export error:", error);
|
||||||
|
const responseModalElement = document.getElementById(
|
||||||
|
"exportResponseModal",
|
||||||
|
);
|
||||||
|
if (!responseModalElement) {
|
||||||
|
console.error(
|
||||||
|
"exportResponseModal not found in the DOM",
|
||||||
|
);
|
||||||
|
alert("Errore: Modale di risposta non trovato");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const responseModal = new bootstrap.Modal(
|
||||||
|
responseModalElement,
|
||||||
|
{
|
||||||
|
keyboard: false,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
document.getElementById(
|
||||||
|
"exportResponseMessage",
|
||||||
|
).textContent =
|
||||||
|
`Errore durante la generazione dei payload: ${error.message}`;
|
||||||
|
document.getElementById(
|
||||||
|
"exportResponseModalLabel",
|
||||||
|
).textContent = "Errore Esportazione";
|
||||||
|
responseModal.show();
|
||||||
|
|
||||||
|
// Gestisci la chiusura del modale di risposta in caso di errore
|
||||||
|
responseModalElement.addEventListener(
|
||||||
|
"hidden.bs.modal",
|
||||||
|
() => {
|
||||||
|
console.log(
|
||||||
|
"exportResponseModal closed, cleaning up",
|
||||||
|
);
|
||||||
|
// Rimuovi tutti i backdrop residui
|
||||||
|
document
|
||||||
|
.querySelectorAll(".modal-backdrop")
|
||||||
|
.forEach((backdrop) => {
|
||||||
|
console.log("Removing backdrop:", backdrop);
|
||||||
|
backdrop.remove();
|
||||||
|
});
|
||||||
|
// Ripristina il body
|
||||||
|
document.body.classList.remove("modal-open");
|
||||||
|
document.body.style.paddingRight = "";
|
||||||
|
// Nascondi l'overlay
|
||||||
|
const overlay = document.querySelector(
|
||||||
|
".overlay.toggle-icon",
|
||||||
|
);
|
||||||
|
if (overlay) {
|
||||||
|
overlay.style.display = "none";
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{ once: true },
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rimuovi il listener dopo l'esecuzione
|
||||||
|
confirmBtn.removeEventListener("click", confirmHandler);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Rimuovi eventuali listener precedenti
|
||||||
|
confirmBtn.removeEventListener("click", confirmHandler);
|
||||||
|
confirmBtn.addEventListener("click", confirmHandler);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
243
public/userarea/export_to_lims.php
Normal file
243
public/userarea/export_to_lims.php
Normal file
@ -0,0 +1,243 @@
|
|||||||
|
<?php
|
||||||
|
// File: export_to_lims.php
|
||||||
|
ini_set('display_errors', '0');
|
||||||
|
error_reporting(E_ALL);
|
||||||
|
ini_set('log_errors', 1);
|
||||||
|
ini_set('error_log', __DIR__ . '/logsapi/export_lims_error.log');
|
||||||
|
|
||||||
|
// Includi il file con la connessione al database e Dotenv
|
||||||
|
require_once __DIR__ . '/include/headscript.php';
|
||||||
|
require_once dirname(__DIR__, 2) . '/vendor/autoload.php';
|
||||||
|
require_once __DIR__ . '/class/VisualLimsApiClient.class.php';
|
||||||
|
|
||||||
|
use Dotenv\Dotenv;
|
||||||
|
|
||||||
|
// Carica il file .env
|
||||||
|
$dotenv = Dotenv::createImmutable(dirname(__DIR__, 3)); // Torna al livello di public
|
||||||
|
$dotenv->load();
|
||||||
|
|
||||||
|
// Leggi la variabile SIMULATE_EXPORT_LIMS
|
||||||
|
$simulate = filter_var($_ENV['SIMULATE_EXPORT_LIMS'] ?? true, FILTER_VALIDATE_BOOLEAN);
|
||||||
|
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Verifica che la richiesta sia POST e contenga iddatadb
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] !== 'POST' || !isset($_POST['iddatadb'])) {
|
||||||
|
throw new Exception('Richiesta non valida: iddatadb mancante');
|
||||||
|
}
|
||||||
|
|
||||||
|
$iddatadb = (int)$_POST['iddatadb'];
|
||||||
|
|
||||||
|
// Crea la cartella logsapi se non esiste
|
||||||
|
$logDir = __DIR__ . '/logsapi';
|
||||||
|
if (!is_dir($logDir)) {
|
||||||
|
mkdir($logDir, 0755, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ottieni connessione al database
|
||||||
|
$db = DBHandlerSelect::getInstance();
|
||||||
|
$pdo = $db->getConnection();
|
||||||
|
|
||||||
|
// Step 1: Creazione payload per CommessaWeb
|
||||||
|
$queryCommessa = "
|
||||||
|
SELECT
|
||||||
|
d.iddatadb,
|
||||||
|
e.idclient AS Cliente,
|
||||||
|
e.idschema AS SchemaCustomField
|
||||||
|
FROM datadb d
|
||||||
|
LEFT JOIN excel_templates e ON d.templateid = e.id
|
||||||
|
WHERE d.iddatadb = :iddatadb
|
||||||
|
";
|
||||||
|
|
||||||
|
$stmtCommessa = $pdo->prepare($queryCommessa);
|
||||||
|
$stmtCommessa->execute(['iddatadb' => $iddatadb]);
|
||||||
|
$recordCommessa = $stmtCommessa->fetch(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
|
if (!$recordCommessa) {
|
||||||
|
throw new Exception("Nessun record trovato per iddatadb: {$iddatadb}");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validazione payload
|
||||||
|
if (empty($recordCommessa['Cliente']) || empty($recordCommessa['SchemaCustomField'])) {
|
||||||
|
throw new Exception("Dati mancanti per CommessaWeb: Cliente o SchemaCustomField non validi");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Payload per creazione CommessaWeb
|
||||||
|
$payloadCommessa = [
|
||||||
|
'Cliente' => (int)$recordCommessa['Cliente'],
|
||||||
|
'SchemaCustomField' => (int)$recordCommessa['SchemaCustomField'],
|
||||||
|
'Richiedente' => null,
|
||||||
|
'Descrizione' => 'example'
|
||||||
|
];
|
||||||
|
|
||||||
|
// Step 2: Creazione payload per campi custom (CommesseCustomFields)
|
||||||
|
$queryCustomFields = "
|
||||||
|
SELECT
|
||||||
|
tm.field_id AS IdCommesseCustomFields,
|
||||||
|
idd.field_value AS Valore
|
||||||
|
FROM import_data_details idd
|
||||||
|
JOIN template_mapping tm ON idd.mapping_id = tm.id
|
||||||
|
WHERE idd.id = :iddatadb
|
||||||
|
";
|
||||||
|
|
||||||
|
$stmtCustomFields = $pdo->prepare($queryCustomFields);
|
||||||
|
$stmtCustomFields->execute(['iddatadb' => $iddatadb]);
|
||||||
|
$customFields = $stmtCustomFields->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
|
// Costruisci l'array CommesseCustomFields
|
||||||
|
$commesseCustomFields = [];
|
||||||
|
foreach ($customFields as $field) {
|
||||||
|
$commesseCustomFields[] = [
|
||||||
|
'IdCommesseCustomFields' => (int)$field['IdCommesseCustomFields'],
|
||||||
|
'Valore' => $field['Valore'] ?? ''
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Payload per aggiornamento campi custom
|
||||||
|
$payloadCustomFields = [
|
||||||
|
'CommesseCustomFields' => $commesseCustomFields
|
||||||
|
];
|
||||||
|
|
||||||
|
// Step 3: Creazione payload per Campioni (da identification_parts)
|
||||||
|
$queryCampioni = "
|
||||||
|
SELECT
|
||||||
|
part_number,
|
||||||
|
idmatrice AS Matrice,
|
||||||
|
part_description AS NoteWeb
|
||||||
|
FROM identification_parts
|
||||||
|
WHERE iddatadb = :iddatadb
|
||||||
|
";
|
||||||
|
|
||||||
|
$stmtCampioni = $pdo->prepare($queryCampioni);
|
||||||
|
$stmtCampioni->execute(['iddatadb' => $iddatadb]);
|
||||||
|
$campioni = $stmtCampioni->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
|
$payloadsCampioni = [];
|
||||||
|
foreach ($campioni as $campione) {
|
||||||
|
if (empty($campione['Matrice'])) {
|
||||||
|
throw new Exception("Matrice non valida per campione: {$campione['part_number']}");
|
||||||
|
}
|
||||||
|
$payloadCampione = [
|
||||||
|
'Commessa' => null, // Sarà impostato dopo
|
||||||
|
'Matrice' => (int)$campione['Matrice'],
|
||||||
|
'SottoMatrice' => null,
|
||||||
|
'SchemaCustomField' => 1,
|
||||||
|
'NoteWeb' => $campione['NoteWeb'] ?? ''
|
||||||
|
];
|
||||||
|
$payloadsCampioni[] = $payloadCampione;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Step 4: Creazione payload per InviaCommessa
|
||||||
|
$payloadInviaCommessa = [];
|
||||||
|
|
||||||
|
// Variabile per idcommessaweb
|
||||||
|
$idcommessaweb = null;
|
||||||
|
$commessaweb = '';
|
||||||
|
|
||||||
|
if ($simulate) {
|
||||||
|
// Flusso simulato
|
||||||
|
$idcommessaweb = 10176; // Fittizio per il test
|
||||||
|
|
||||||
|
// Salva idcommessaweb in datadb
|
||||||
|
$updateStmt = $pdo->prepare("UPDATE datadb SET idcommessaweb = :idcommessaweb WHERE iddatadb = :iddatadb");
|
||||||
|
$updateStmt->execute(['idcommessaweb' => $idcommessaweb, 'iddatadb' => $iddatadb]);
|
||||||
|
|
||||||
|
// Salva i payload in file JSON
|
||||||
|
$outputFileCommessa = $logDir . "/commessaweb_create_{$iddatadb}.json";
|
||||||
|
file_put_contents($outputFileCommessa, json_encode($payloadCommessa, JSON_PRETTY_PRINT));
|
||||||
|
|
||||||
|
$outputFileCustomFields = $logDir . "/commessaweb_customfields_{$iddatadb}.json";
|
||||||
|
file_put_contents($outputFileCustomFields, json_encode($payloadCustomFields, JSON_PRETTY_PRINT));
|
||||||
|
|
||||||
|
foreach ($payloadsCampioni as $index => $payloadCampione) {
|
||||||
|
$payloadCampione['Commessa'] = $idcommessaweb;
|
||||||
|
$outputFileCampione = $logDir . "/campione_{$iddatadb}_{$campioni[$index]['part_number']}.json";
|
||||||
|
file_put_contents($outputFileCampione, json_encode($payloadCampione, JSON_PRETTY_PRINT));
|
||||||
|
}
|
||||||
|
|
||||||
|
$outputFileInviaCommessa = $logDir . "/commessaweb_invia_{$iddatadb}.json";
|
||||||
|
file_put_contents($outputFileInviaCommessa, json_encode($payloadInviaCommessa, JSON_PRETTY_PRINT));
|
||||||
|
|
||||||
|
// Aggiorna lo status a 'l' (To LIMS)
|
||||||
|
$updateStmt = $pdo->prepare("UPDATE datadb SET status = 'l' WHERE iddatadb = :iddatadb");
|
||||||
|
$updateStmt->execute(['iddatadb' => $iddatadb]);
|
||||||
|
|
||||||
|
// Risposta di successo (simulazione)
|
||||||
|
echo json_encode([
|
||||||
|
'success' => true,
|
||||||
|
'mode' => 'simulated',
|
||||||
|
'message' => "Payload generati e salvati in {$outputFileCommessa}, {$outputFileCustomFields}, file campioni e {$outputFileInviaCommessa}",
|
||||||
|
'idcommessaweb' => $idcommessaweb,
|
||||||
|
'commessaweb' => $commessaweb,
|
||||||
|
'payload_commessa' => $payloadCommessa,
|
||||||
|
'payload_customfields' => $payloadCustomFields,
|
||||||
|
'payload_campioni' => $payloadsCampioni,
|
||||||
|
'payload_invia_commessa' => $payloadInviaCommessa
|
||||||
|
]);
|
||||||
|
} else {
|
||||||
|
// Flusso reale
|
||||||
|
$apiClient = VisualLimsApiClient::getInstance();
|
||||||
|
|
||||||
|
// Step 1: Crea CommessaWeb
|
||||||
|
$response = $apiClient->post('/api/odata/CommessaWeb', $payloadCommessa);
|
||||||
|
if (!isset($response['success']) || !isset($response['CommessaId'])) {
|
||||||
|
throw new Exception('Errore nella creazione della CommessaWeb: ' . json_encode($response));
|
||||||
|
}
|
||||||
|
$idcommessaweb = (int)$response['CommessaId'];
|
||||||
|
|
||||||
|
// Salva idcommessaweb in datadb
|
||||||
|
$updateStmt = $pdo->prepare("UPDATE datadb SET idcommessaweb = :idcommessaweb WHERE iddatadb = :iddatadb");
|
||||||
|
$updateStmt->execute(['idcommessaweb' => $idcommessaweb, 'iddatadb' => $iddatadb]);
|
||||||
|
|
||||||
|
// Logga il successo della creazione CommessaWeb
|
||||||
|
file_put_contents($logDir . '/export_lims_success.log', date('Y-m-d H:i:s') . " - CommessaWeb creata: idcommessaweb {$idcommessaweb} per iddatadb {$iddatadb}\n", FILE_APPEND);
|
||||||
|
|
||||||
|
// Step 2: Aggiorna CommesseCustomFields
|
||||||
|
$apiClient->patch("/api/odata/CommessaWeb({$idcommessaweb})", $payloadCustomFields);
|
||||||
|
|
||||||
|
// Step 3: Crea Campioni
|
||||||
|
foreach ($payloadsCampioni as $index => $payloadCampione) {
|
||||||
|
$payloadCampione['Commessa'] = $idcommessaweb;
|
||||||
|
$apiClient->post('/api/odata/Campione', $payloadCampione);
|
||||||
|
$payloadsCampioni[$index] = $payloadCampione; // Aggiorna il payload con Commessa
|
||||||
|
}
|
||||||
|
|
||||||
|
// Step 4: Invia Commessa
|
||||||
|
$apiClient->post("/api/odata/CommessaWeb({$idcommessaweb})/InviaCommessa", $payloadInviaCommessa);
|
||||||
|
|
||||||
|
// Step 5: Recupera il numero commessaweb (opzionale)
|
||||||
|
$commessaData = $apiClient->get("/api/odata/CommessaWeb({$idcommessaweb})");
|
||||||
|
$commessaweb = $commessaData['Numero'] ?? '';
|
||||||
|
if ($commessaweb) {
|
||||||
|
$updateStmt = $pdo->prepare("UPDATE datadb SET commessaweb = :commessaweb WHERE iddatadb = :iddatadb");
|
||||||
|
$updateStmt->execute(['commessaweb' => $commessaweb, 'iddatadb' => $iddatadb]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Aggiorna lo status a 'l' (To LIMS)
|
||||||
|
$updateStmt = $pdo->prepare("UPDATE datadb SET status = 'l' WHERE iddatadb = :iddatadb");
|
||||||
|
$updateStmt->execute(['iddatadb' => $iddatadb]);
|
||||||
|
|
||||||
|
// Risposta di successo (flusso reale)
|
||||||
|
echo json_encode([
|
||||||
|
'success' => true,
|
||||||
|
'mode' => 'real',
|
||||||
|
'message' => "Dati inviati al LIMS con successo",
|
||||||
|
'idcommessaweb' => $idcommessaweb,
|
||||||
|
'commessaweb' => $commessaweb,
|
||||||
|
'payload_commessa' => $payloadCommessa,
|
||||||
|
'payload_customfields' => $payloadCustomFields,
|
||||||
|
'payload_campioni' => $payloadsCampioni,
|
||||||
|
'payload_invia_commessa' => $payloadInviaCommessa
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
} catch (Exception $e) {
|
||||||
|
// Log dell'errore
|
||||||
|
file_put_contents($logDir . '/export_lims_error.log', date('Y-m-d H:i:s') . ' - Flusso ' . ($simulate ? 'simulato' : 'reale') . ' fallito: ' . $e->getMessage() . PHP_EOL, FILE_APPEND);
|
||||||
|
http_response_code(500);
|
||||||
|
echo json_encode([
|
||||||
|
'success' => false,
|
||||||
|
'mode' => $simulate ? 'simulated' : 'real',
|
||||||
|
'message' => 'Errore: ' . $e->getMessage()
|
||||||
|
]);
|
||||||
|
}
|
||||||
@ -405,6 +405,16 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
|||||||
.save-all-btn:hover {
|
.save-all-btn:hover {
|
||||||
background-color: #218838;
|
background-color: #218838;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#exportConfirmModal,
|
||||||
|
#exportResponseModal {
|
||||||
|
z-index: 1300 !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
#exportConfirmModal .modal-backdrop,
|
||||||
|
#exportResponseModal .modal-backdrop {
|
||||||
|
z-index: 1299 !important;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
<title>Edit Imported Data - <?= htmlspecialchars($titlewebsite, ENT_QUOTES, 'UTF-8'); ?></title>
|
<title>Edit Imported Data - <?= htmlspecialchars($titlewebsite, ENT_QUOTES, 'UTF-8'); ?></title>
|
||||||
</head>
|
</head>
|
||||||
@ -708,6 +718,7 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
|||||||
<script src="photos.js"></script>
|
<script src="photos.js"></script>
|
||||||
<script src="parts.js"></script>
|
<script src="parts.js"></script>
|
||||||
<script src="tracking.js"></script>
|
<script src="tracking.js"></script>
|
||||||
|
<script src="export_to_lims.js"></script>
|
||||||
<script>
|
<script>
|
||||||
document.addEventListener("DOMContentLoaded", function() {
|
document.addEventListener("DOMContentLoaded", function() {
|
||||||
console.log("Page loaded, initializing event listeners");
|
console.log("Page loaded, initializing event listeners");
|
||||||
@ -900,6 +911,8 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
window.addEventListener("beforeunload", function(e) {
|
window.addEventListener("beforeunload", function(e) {
|
||||||
if (hasChanges) {
|
if (hasChanges) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
@ -907,6 +920,26 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Gestisci la chiusura dei modali per rimuovere i backdrop
|
||||||
|
document.querySelectorAll('#exportConfirmModal, #exportResponseModal').forEach(modal => {
|
||||||
|
modal.addEventListener('hidden.bs.modal', () => {
|
||||||
|
console.log(`Modal ${modal.id} closed, removing backdrops`);
|
||||||
|
// Rimuovi tutti i backdrop residui
|
||||||
|
document.querySelectorAll('.modal-backdrop').forEach(backdrop => {
|
||||||
|
console.log('Removing backdrop:', backdrop);
|
||||||
|
backdrop.remove();
|
||||||
|
});
|
||||||
|
// Ripristina il body
|
||||||
|
document.body.classList.remove('modal-open');
|
||||||
|
document.body.style.paddingRight = '';
|
||||||
|
// Assicurati che l'overlay sia nascosto
|
||||||
|
const overlay = document.querySelector('.overlay.toggle-icon');
|
||||||
|
if (overlay) {
|
||||||
|
overlay.style.display = 'none';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
<script>
|
<script>
|
||||||
document.addEventListener("DOMContentLoaded", function() {
|
document.addEventListener("DOMContentLoaded", function() {
|
||||||
@ -1066,6 +1099,43 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
|||||||
populateDropdowns();
|
populateDropdowns();
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
<!-- Modale di conferma per l'esportazione -->
|
||||||
|
<div class="modal fade" id="exportConfirmModal" tabindex="-1" aria-labelledby="exportConfirmModalLabel" aria-hidden="true">
|
||||||
|
<div class="modal-dialog">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h5 class="modal-title" id="exportConfirmModalLabel">Conferma Esportazione</h5>
|
||||||
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
<p id="exportConfirmMessage">Confermi l'esportazione al LIMS per iddatadb <span id="exportIddatadb"></span>?</p>
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button type="button" class="btn btn-secondary btn-sm" data-bs-dismiss="modal">Annulla</button>
|
||||||
|
<button type="button" class="btn btn-primary btn-sm" id="exportConfirmBtn">Conferma</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Modale di risposta per l'esportazione -->
|
||||||
|
<div class="modal fade" id="exportResponseModal" tabindex="-1" aria-labelledby="exportResponseModalLabel" aria-hidden="true">
|
||||||
|
<div class="modal-dialog">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h5 class="modal-title" id="exportResponseModalLabel">Risultato Esportazione</h5>
|
||||||
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
<p id="exportResponseMessage"></p>
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button type="button" class="btn btn-primary btn-sm" data-bs-dismiss="modal">Chiudi</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
@ -18,9 +18,9 @@ try {
|
|||||||
$target_table = trim($_POST['target_table']);
|
$target_table = trim($_POST['target_table']);
|
||||||
$idclient = intval($_POST['client_id'] ?? 0); // Usa client_id dal form
|
$idclient = intval($_POST['client_id'] ?? 0); // Usa client_id dal form
|
||||||
$clientname = trim($_POST['client_name'] ?? ''); // Usa client_name dal form
|
$clientname = trim($_POST['client_name'] ?? ''); // Usa client_name dal form
|
||||||
$client_specific_fields = trim($_POST['client_specific_fields'] ?? '{}'); // Recupera il JSON dei campi specifici
|
|
||||||
$idschema = intval($_POST['idschema'] ?? 0); // Nuovo campo
|
$idschema = intval($_POST['idschema'] ?? 0); // Nuovo campo
|
||||||
$schemamaname = trim($_POST['schemamaname'] ?? ''); // Nuovo campo
|
$schemaname = trim($_POST['schemaname'] ?? ''); // Corretto da schemamaname
|
||||||
|
$idroutine = isset($_POST['idroutine']) && $_POST['idroutine'] !== '' ? intval($_POST['idroutine']) : null; // Aggiunto idroutine
|
||||||
|
|
||||||
// Controllo sui campi obbligatori
|
// Controllo sui campi obbligatori
|
||||||
if (empty($id) || empty($name) || empty($header_row) || empty($start_column) || empty($target_table) || $idschema <= 0) {
|
if (empty($id) || empty($name) || empty($header_row) || empty($start_column) || empty($target_table) || $idschema <= 0) {
|
||||||
@ -32,20 +32,14 @@ try {
|
|||||||
throw new Exception("Please select a valid client.");
|
throw new Exception("Please select a valid client.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validazione opzionale del JSON (per sicurezza)
|
|
||||||
$decoded_fields = json_decode($client_specific_fields, true);
|
|
||||||
if (json_last_error() !== JSON_ERROR_NONE && $client_specific_fields !== '{}') {
|
|
||||||
throw new Exception("Invalid JSON format for client-specific fields.");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Connessione al database
|
// Connessione al database
|
||||||
$db = DBHandlerSelect::getInstance();
|
$db = DBHandlerSelect::getInstance();
|
||||||
$pdo = $db->getConnection();
|
$pdo = $db->getConnection();
|
||||||
|
|
||||||
// Aggiorna il database, includendo idschema e schemaname
|
// Aggiorna il database, includendo idschema, schemaname e idroutine
|
||||||
$stmt = $pdo->prepare("UPDATE excel_templates
|
$stmt = $pdo->prepare("UPDATE excel_templates
|
||||||
SET name = ?, header_row = ?, start_column = ?, description = ?, target_table = ?,
|
SET name = ?, header_row = ?, start_column = ?, description = ?, target_table = ?,
|
||||||
idclient = ?, clientname = ?, client_specific_fields = ?, schemaname = ?, idschema = ?, updated_at = NOW()
|
idclient = ?, clientname = ?, schemaname = ?, idschema = ?, idroutine = ?, updated_at = NOW()
|
||||||
WHERE id = ?");
|
WHERE id = ?");
|
||||||
$stmt->execute([
|
$stmt->execute([
|
||||||
$name,
|
$name,
|
||||||
@ -55,9 +49,9 @@ try {
|
|||||||
$target_table,
|
$target_table,
|
||||||
$idclient,
|
$idclient,
|
||||||
$clientname,
|
$clientname,
|
||||||
$client_specific_fields,
|
$schemaname,
|
||||||
$schemamaname,
|
|
||||||
$idschema,
|
$idschema,
|
||||||
|
$idroutine,
|
||||||
$id
|
$id
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|||||||
58
public/userarea/test_auth.php
Normal file
58
public/userarea/test_auth.php
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
<?php
|
||||||
|
// File: test_auth.php
|
||||||
|
ini_set('display_errors', '0');
|
||||||
|
error_reporting(E_ALL);
|
||||||
|
ini_set('log_errors', 1);
|
||||||
|
|
||||||
|
// Includi le dipendenze
|
||||||
|
require_once dirname(__DIR__, 2) . '/vendor/autoload.php';
|
||||||
|
require_once __DIR__ . '/class/VisualLimsApiClient.class.php';
|
||||||
|
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Crea la cartella logsapi se non esiste
|
||||||
|
$logDir = __DIR__ . '/logsapi';
|
||||||
|
if (!is_dir($logDir)) {
|
||||||
|
mkdir($logDir, 0755, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Istanzia il client API (autenticazione automatica tramite .env)
|
||||||
|
$api = VisualLimsApiClient::getInstance();
|
||||||
|
|
||||||
|
// Esegui una chiamata di test per verificare l'autenticazione
|
||||||
|
$endpoint = 'SchemaCustomField';
|
||||||
|
$options = []; // Nessun filtro per il test
|
||||||
|
$data = $api->get($endpoint, $options);
|
||||||
|
|
||||||
|
// Debug: salva URL usato
|
||||||
|
$base_url = 'https://93.43.5.102/limsapi/api/odata/';
|
||||||
|
$query = http_build_query($options);
|
||||||
|
$full_url = $base_url . $endpoint . ($query ? '?' . $query : '');
|
||||||
|
file_put_contents($logDir . '/last_auth_url.txt', $full_url . PHP_EOL, FILE_APPEND);
|
||||||
|
|
||||||
|
// Nota: getToken() è privato, quindi non possiamo accedervi direttamente
|
||||||
|
// Supponiamo che l'autenticazione sia avvenuta correttamente se la GET ha successo
|
||||||
|
$token = null; // Non possiamo accedere al token direttamente
|
||||||
|
$auth_success = true; // La GET ha successo, quindi l'autenticazione funziona
|
||||||
|
|
||||||
|
// Salva un file di conferma dell'autenticazione
|
||||||
|
$outputFile = $logDir . '/auth_token.json';
|
||||||
|
file_put_contents($outputFile, json_encode(['auth_success' => true, 'token' => 'Not directly accessible (private method)'], JSON_PRETTY_PRINT));
|
||||||
|
|
||||||
|
// Risposta di successo
|
||||||
|
echo json_encode([
|
||||||
|
'success' => true,
|
||||||
|
'message' => "Autenticazione completata con successo, dettagli salvati in {$outputFile}",
|
||||||
|
'auth_success' => $auth_success,
|
||||||
|
'schema_data' => $data // Dati di esempio dalla GET
|
||||||
|
]);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
// Log dell'errore
|
||||||
|
file_put_contents($logDir . '/auth_error.log', date('Y-m-d H:i:s') . ' - ' . $e->getMessage() . PHP_EOL, FILE_APPEND);
|
||||||
|
http_response_code(500);
|
||||||
|
echo json_encode([
|
||||||
|
'success' => false,
|
||||||
|
'message' => 'Errore durante l\'autenticazione: ' . $e->getMessage()
|
||||||
|
]);
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user