fixed matrici with db cron
This commit is contained in:
parent
12c6cc5f95
commit
15b6f38e8b
59
public/userarea/get_matrici_db.php
Normal file
59
public/userarea/get_matrici_db.php
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
<?php
|
||||||
|
require_once dirname(__DIR__, 2) . '/vendor/autoload.php'; // Risale a root/vendor/
|
||||||
|
use Dotenv\Dotenv;
|
||||||
|
|
||||||
|
// Set JSON header
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
|
||||||
|
// Debug: Log the path where we expect the .env file
|
||||||
|
$envPath = dirname(__DIR__, 2);
|
||||||
|
file_put_contents(__DIR__ . '/debug_log.txt', date('Y-m-d H:i:s') . ' - Expected .env path: ' . $envPath . PHP_EOL, FILE_APPEND);
|
||||||
|
|
||||||
|
// Carica il file .env dalla root del progetto
|
||||||
|
try {
|
||||||
|
$dotenv = Dotenv::createImmutable($envPath);
|
||||||
|
$dotenv->load();
|
||||||
|
} catch (Exception $e) {
|
||||||
|
file_put_contents(__DIR__ . '/error_log.txt', date('Y-m-d H:i:s') . ' - Errore caricamento .env: ' . $e->getMessage() . PHP_EOL, FILE_APPEND);
|
||||||
|
echo json_encode(['success' => false, 'message' => 'Errore caricamento configurazione: ' . $e->getMessage()]);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Recupera le variabili d'ambiente
|
||||||
|
$dbHost = $_ENV['DB_HOST'];
|
||||||
|
$dbName = $_ENV['DB_DATABASE'];
|
||||||
|
$dbUser = $_ENV['DB_USERNAME'];
|
||||||
|
$dbPass = $_ENV['DB_PASSWORD'];
|
||||||
|
$dbPrefix = $_ENV['DB_PREFIX'];
|
||||||
|
|
||||||
|
// Debug: Log database connection details (excluding password)
|
||||||
|
file_put_contents(__DIR__ . '/debug_log.txt', date('Y-m-d H:i:s') . " - DB Connection: host=$dbHost, dbname=$dbName, user=$dbUser, prefix=$dbPrefix" . PHP_EOL, FILE_APPEND);
|
||||||
|
|
||||||
|
// Connessione al database MySQL
|
||||||
|
try {
|
||||||
|
$pdo = new PDO("mysql:host=$dbHost;dbname=$dbName;charset=utf8mb4", $dbUser, $dbPass);
|
||||||
|
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
file_put_contents(__DIR__ . '/error_log.txt', date('Y-m-d H:i:s') . ' - Errore connessione DB: ' . $e->getMessage() . PHP_EOL, FILE_APPEND);
|
||||||
|
echo json_encode(['success' => false, 'message' => 'Errore connessione al database: ' . $e->getMessage()]);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Query to fetch matrices, excluding those starting with '*' and sorting by NomeMatrice
|
||||||
|
$query = "SELECT IdMatrice, NomeMatrice FROM {$dbPrefix}matrici WHERE NomeMatrice NOT LIKE '*%' ORDER BY NomeMatrice ASC";
|
||||||
|
$stmt = $pdo->prepare($query);
|
||||||
|
$stmt->execute();
|
||||||
|
$matrici = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
|
// Debug: Log the number of matrices retrieved
|
||||||
|
file_put_contents(__DIR__ . '/debug_log.txt', date('Y-m-d H:i:s') . ' - Retrieved ' . count($matrici) . ' matrices from database' . PHP_EOL, FILE_APPEND);
|
||||||
|
|
||||||
|
// Return JSON response
|
||||||
|
echo json_encode(['success' => true, 'value' => $matrici]);
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
// Log error and return error response
|
||||||
|
file_put_contents(__DIR__ . '/error_log.txt', date('Y-m-d H:i:s') . ' - Errore nel recupero delle matrici: ' . $e->getMessage() . PHP_EOL, FILE_APPEND);
|
||||||
|
echo json_encode(['success' => false, 'message' => 'Errore nel recupero delle matrici: ' . $e->getMessage()]);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
@ -1183,9 +1183,13 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
|||||||
</script>
|
</script>
|
||||||
<script>
|
<script>
|
||||||
document.addEventListener("DOMContentLoaded", function() {
|
document.addEventListener("DOMContentLoaded", function() {
|
||||||
// Lazy loading per il modal delle parti
|
|
||||||
$(document).on('click', '.parts-btn', function() {
|
$(document).on('click', '.parts-btn', function() {
|
||||||
const iddatadb = $(this).data('iddatadb');
|
const iddatadb = $(this).data('iddatadb') || null;
|
||||||
|
const idquotations = $(this).data('idquotations') || null;
|
||||||
|
const rowIndex = $(this).data('row');
|
||||||
|
const importRef = $("table tbody tr").eq(rowIndex).find("td").eq(1).text();
|
||||||
|
const description = $("table tbody tr").eq(rowIndex).find("td").eq(2).text() || "Sconosciuto";
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: 'modal_parts.php',
|
url: 'modal_parts.php',
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
@ -1193,25 +1197,65 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
|||||||
iddatadb: iddatadb
|
iddatadb: iddatadb
|
||||||
},
|
},
|
||||||
success: function(response) {
|
success: function(response) {
|
||||||
|
// Inserisci il modale nel container
|
||||||
$('#partsModalContainer').html(response);
|
$('#partsModalContainer').html(response);
|
||||||
$('#partsModal').modal('show');
|
|
||||||
// Carica i dati delle parti, se necessario
|
// Verifica che il modale esista
|
||||||
if (typeof loadParts === 'function') {
|
const modalElement = document.getElementById('partsModal');
|
||||||
loadParts(iddatadb);
|
if (!modalElement) {
|
||||||
|
console.error('Elemento modale non trovato: #partsModal');
|
||||||
|
const errorMsg = $('<div class="alert alert-danger temp-alert" role="alert">Errore: Modale non trovato.</div>');
|
||||||
|
$("body").prepend(errorMsg);
|
||||||
|
setTimeout(() => errorMsg.fadeOut(500, function() {
|
||||||
|
$(this).remove();
|
||||||
|
}), 5000);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Imposta i dati del modale
|
||||||
|
$("#trfHeader").text(`${iddatadb || idquotations} - ${importRef} - ${description}`);
|
||||||
|
$("#partsModal").data("iddatadb", iddatadb).data("idquotations", idquotations);
|
||||||
|
|
||||||
|
// Inizializza il modale con l'API nativa di Bootstrap
|
||||||
|
let modal = bootstrap.Modal.getInstance(modalElement);
|
||||||
|
if (!modal) {
|
||||||
|
modal = new bootstrap.Modal(modalElement, {
|
||||||
|
backdrop: true,
|
||||||
|
keyboard: true,
|
||||||
|
focus: true
|
||||||
|
});
|
||||||
|
}
|
||||||
|
modal.show();
|
||||||
|
|
||||||
|
// Carica i dati delle parti e delle foto
|
||||||
|
if (typeof loadParts === 'function') {
|
||||||
|
loadParts(iddatadb, idquotations);
|
||||||
}
|
}
|
||||||
// Gestisci il backdrop
|
|
||||||
$('.modal-backdrop').remove(); // Rimuovi backdrop precedenti
|
|
||||||
$('body').addClass('modal-open').append('<div class="modal-backdrop fade show"></div>');
|
|
||||||
},
|
},
|
||||||
error: function() {
|
error: function(xhr, status, error) {
|
||||||
alert('Errore nel caricamento del modal delle parti.');
|
console.error('Errore nel caricamento del modale:', error);
|
||||||
|
const errorMsg = $('<div class="alert alert-danger temp-alert" role="alert">Errore nel caricamento del modale: ' + error + '</div>');
|
||||||
|
$("body").prepend(errorMsg);
|
||||||
|
setTimeout(() => errorMsg.fadeOut(500, function() {
|
||||||
|
$(this).remove();
|
||||||
|
}), 5000);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// Pulizia del DOM quando il modal delle parti viene chiuso
|
// Pulizia completa alla chiusura del modale
|
||||||
$(document).on('hidden.bs.modal', '#partsModal', function() {
|
$(document).on('hidden.bs.modal', '#partsModal', function() {
|
||||||
|
const modalElement = document.getElementById('partsModal');
|
||||||
|
if (modalElement) {
|
||||||
|
const modal = bootstrap.Modal.getInstance(modalElement);
|
||||||
|
if (modal) {
|
||||||
|
modal.dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
$('#partsModalContainer').empty();
|
$('#partsModalContainer').empty();
|
||||||
|
$('.modal-backdrop').remove();
|
||||||
|
$('body').removeClass('modal-open').css('padding-right', '');
|
||||||
|
$('.overlay.toggle-icon').css('display', 'none');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@ -143,7 +143,7 @@ $(document).ready(function () {
|
|||||||
if (iddatadb) {
|
if (iddatadb) {
|
||||||
if (matrici.length === 0) {
|
if (matrici.length === 0) {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "get_matrice.php",
|
url: "get_matrici_db.php",
|
||||||
method: "GET",
|
method: "GET",
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
success: function (data) {
|
success: function (data) {
|
||||||
@ -157,6 +157,19 @@ $(document).ready(function () {
|
|||||||
initializeGlobalSelect2();
|
initializeGlobalSelect2();
|
||||||
loadPhoto(iddatadb, idquotations);
|
loadPhoto(iddatadb, idquotations);
|
||||||
loadExistingParts(iddatadb, idquotations);
|
loadExistingParts(iddatadb, idquotations);
|
||||||
|
const errorMsg = $(
|
||||||
|
'<div class="alert alert-danger temp-alert" role="alert">Errore nel caricamento delle matrici: ' +
|
||||||
|
error +
|
||||||
|
" (" +
|
||||||
|
xhr.status +
|
||||||
|
")</div>",
|
||||||
|
);
|
||||||
|
$("#partsModal .modal-body").prepend(errorMsg);
|
||||||
|
setTimeout(function () {
|
||||||
|
errorMsg.fadeOut(500, function () {
|
||||||
|
$(this).remove();
|
||||||
|
});
|
||||||
|
}, 5000);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@ -169,18 +182,39 @@ $(document).ready(function () {
|
|||||||
loadExistingParts(iddatadb, idquotations);
|
loadExistingParts(iddatadb, idquotations);
|
||||||
}
|
}
|
||||||
|
|
||||||
const modal = new bootstrap.Modal(
|
const modalElement = document.getElementById("partsModal");
|
||||||
document.getElementById("partsModal"),
|
if (modalElement) {
|
||||||
);
|
// Verifica se il modale è già stato inizializzato
|
||||||
modal.show();
|
let modal = bootstrap.Modal.getInstance(modalElement);
|
||||||
|
if (!modal) {
|
||||||
|
modal = new bootstrap.Modal(modalElement, {
|
||||||
|
backdrop: true,
|
||||||
|
keyboard: true,
|
||||||
|
focus: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
modal.show();
|
||||||
|
} else {
|
||||||
|
console.error("Elemento modale non trovato: #partsModal");
|
||||||
|
const errorMsg = $(
|
||||||
|
'<div class="alert alert-danger temp-alert" role="alert">Errore: Modale non trovato.</div>',
|
||||||
|
);
|
||||||
|
$("body").prepend(errorMsg);
|
||||||
|
setTimeout(function () {
|
||||||
|
errorMsg.fadeOut(500, function () {
|
||||||
|
$(this).remove();
|
||||||
|
});
|
||||||
|
}, 5000);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$("#partsModal .close-btn, #partsModal").on("click", function (event) {
|
$("#partsModal .close-btn, #partsModal").on("click", function (event) {
|
||||||
if (event.target === this) {
|
if (event.target === this || $(event.target).hasClass("close-btn")) {
|
||||||
const modal = bootstrap.Modal.getInstance(
|
const modalElement = document.getElementById("partsModal");
|
||||||
document.getElementById("partsModal"),
|
const modal = bootstrap.Modal.getInstance(modalElement);
|
||||||
);
|
if (modal) {
|
||||||
modal.hide();
|
modal.hide();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -194,7 +228,7 @@ $(document).ready(function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
$("#partsModal").on("hidden.bs.modal", function () {
|
$("#partsModal").on("hidden.bs.modal", function () {
|
||||||
// Reset global state to initial values
|
// Resetta lo stato
|
||||||
photoData = {
|
photoData = {
|
||||||
naturalWidth: 0,
|
naturalWidth: 0,
|
||||||
naturalHeight: 0,
|
naturalHeight: 0,
|
||||||
@ -208,20 +242,29 @@ $(document).ready(function () {
|
|||||||
selectedPartNumber = null;
|
selectedPartNumber = null;
|
||||||
unsavedChanges = false;
|
unsavedChanges = false;
|
||||||
if (fabricCanvas) {
|
if (fabricCanvas) {
|
||||||
fabricCanvas.off(); // Rimuove tutti gli eventi
|
fabricCanvas.off();
|
||||||
fabricCanvas.dispose();
|
fabricCanvas.dispose();
|
||||||
fabricCanvas = null;
|
fabricCanvas = null;
|
||||||
}
|
}
|
||||||
descriptionTextbox = null;
|
descriptionTextbox = null;
|
||||||
markerObjects = {};
|
markerObjects = {};
|
||||||
matrici = [];
|
matrici = [];
|
||||||
// Clear UI elements
|
|
||||||
$("#photoSelectorContainer").empty().hide();
|
$("#photoSelectorContainer").empty().hide();
|
||||||
$("#samplePhoto").attr("src", "");
|
$("#samplePhoto").attr("src", "");
|
||||||
$("#partsTableBody").empty();
|
$("#partsTableBody").empty();
|
||||||
$("#global-matrice").empty(); // Pulisci select globale se presente
|
$("#global-matrice").empty();
|
||||||
// Remove any temporary messages
|
|
||||||
$(".temp-alert").remove();
|
$(".temp-alert").remove();
|
||||||
|
|
||||||
|
// Rimuovi manualmente il backdrop e ripristina il body
|
||||||
|
const modalElement = document.getElementById("partsModal");
|
||||||
|
const modal = bootstrap.Modal.getInstance(modalElement);
|
||||||
|
if (modal) {
|
||||||
|
modal.dispose(); // Distrugge l'istanza del modale
|
||||||
|
}
|
||||||
|
$(".modal-backdrop").remove();
|
||||||
|
$("body").removeClass("modal-open");
|
||||||
|
$("body").css("padding-right", "");
|
||||||
|
$(":focus").blur();
|
||||||
});
|
});
|
||||||
|
|
||||||
// ===================
|
// ===================
|
||||||
@ -792,7 +835,7 @@ $(document).ready(function () {
|
|||||||
const options = matrici.map(function (matrice) {
|
const options = matrici.map(function (matrice) {
|
||||||
return {
|
return {
|
||||||
id: matrice.IdMatrice,
|
id: matrice.IdMatrice,
|
||||||
text: matrice.NomeMatriceTraduzione,
|
text: matrice.NomeMatrice, // Updated to use NomeMatrice
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -817,7 +860,7 @@ $(document).ready(function () {
|
|||||||
const matrice = matrici.find((m) => m.IdMatrice == idmatrice);
|
const matrice = matrici.find((m) => m.IdMatrice == idmatrice);
|
||||||
if (matrice) {
|
if (matrice) {
|
||||||
const option = new Option(
|
const option = new Option(
|
||||||
matrice.NomeMatriceTraduzione,
|
matrice.NomeMatrice, // Updated to use NomeMatrice
|
||||||
matrice.IdMatrice,
|
matrice.IdMatrice,
|
||||||
true,
|
true,
|
||||||
true,
|
true,
|
||||||
@ -843,7 +886,7 @@ $(document).ready(function () {
|
|||||||
const idquotations = $("#partsModal").data("idquotations");
|
const idquotations = $("#partsModal").data("idquotations");
|
||||||
const endpoint = idquotations
|
const endpoint = idquotations
|
||||||
? "save_matrice_quotation.php"
|
? "save_matrice_quotation.php"
|
||||||
: "save_matrice.php"; // Assumendo esista per quotations, altrimenti adatta
|
: "save_matrice.php";
|
||||||
const data = idquotations
|
const data = idquotations
|
||||||
? { idquotations: idquotations }
|
? { idquotations: idquotations }
|
||||||
: { iddatadb: iddatadb };
|
: { iddatadb: iddatadb };
|
||||||
@ -915,7 +958,7 @@ $(document).ready(function () {
|
|||||||
const options = matrici.map(function (matrice) {
|
const options = matrici.map(function (matrice) {
|
||||||
return {
|
return {
|
||||||
id: matrice.IdMatrice,
|
id: matrice.IdMatrice,
|
||||||
text: matrice.NomeMatriceTraduzione,
|
text: matrice.NomeMatrice, // Updated to use NomeMatrice
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user