diff --git a/public/userarea/get_matrici_db.php b/public/userarea/get_matrici_db.php
new file mode 100644
index 0000000..6148e64
--- /dev/null
+++ b/public/userarea/get_matrici_db.php
@@ -0,0 +1,59 @@
+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);
+}
diff --git a/public/userarea/import_edit2.php b/public/userarea/import_edit2.php
index e7044b5..81ca1e9 100644
--- a/public/userarea/import_edit2.php
+++ b/public/userarea/import_edit2.php
@@ -1183,9 +1183,13 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
diff --git a/public/userarea/parts.js b/public/userarea/parts.js
index c306715..ee615f6 100644
--- a/public/userarea/parts.js
+++ b/public/userarea/parts.js
@@ -143,7 +143,7 @@ $(document).ready(function () {
if (iddatadb) {
if (matrici.length === 0) {
$.ajax({
- url: "get_matrice.php",
+ url: "get_matrici_db.php",
method: "GET",
dataType: "json",
success: function (data) {
@@ -157,6 +157,19 @@ $(document).ready(function () {
initializeGlobalSelect2();
loadPhoto(iddatadb, idquotations);
loadExistingParts(iddatadb, idquotations);
+ const errorMsg = $(
+ '
Errore nel caricamento delle matrici: ' +
+ error +
+ " (" +
+ xhr.status +
+ ")
",
+ );
+ $("#partsModal .modal-body").prepend(errorMsg);
+ setTimeout(function () {
+ errorMsg.fadeOut(500, function () {
+ $(this).remove();
+ });
+ }, 5000);
},
});
} else {
@@ -169,18 +182,39 @@ $(document).ready(function () {
loadExistingParts(iddatadb, idquotations);
}
- const modal = new bootstrap.Modal(
- document.getElementById("partsModal"),
- );
- modal.show();
+ const modalElement = document.getElementById("partsModal");
+ if (modalElement) {
+ // Verifica se il modale è già stato inizializzato
+ 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 = $(
+ 'Errore: Modale non trovato.
',
+ );
+ $("body").prepend(errorMsg);
+ setTimeout(function () {
+ errorMsg.fadeOut(500, function () {
+ $(this).remove();
+ });
+ }, 5000);
+ }
});
$("#partsModal .close-btn, #partsModal").on("click", function (event) {
- if (event.target === this) {
- const modal = bootstrap.Modal.getInstance(
- document.getElementById("partsModal"),
- );
- modal.hide();
+ if (event.target === this || $(event.target).hasClass("close-btn")) {
+ const modalElement = document.getElementById("partsModal");
+ const modal = bootstrap.Modal.getInstance(modalElement);
+ if (modal) {
+ modal.hide();
+ }
}
});
@@ -194,7 +228,7 @@ $(document).ready(function () {
});
$("#partsModal").on("hidden.bs.modal", function () {
- // Reset global state to initial values
+ // Resetta lo stato
photoData = {
naturalWidth: 0,
naturalHeight: 0,
@@ -208,20 +242,29 @@ $(document).ready(function () {
selectedPartNumber = null;
unsavedChanges = false;
if (fabricCanvas) {
- fabricCanvas.off(); // Rimuove tutti gli eventi
+ fabricCanvas.off();
fabricCanvas.dispose();
fabricCanvas = null;
}
descriptionTextbox = null;
markerObjects = {};
matrici = [];
- // Clear UI elements
$("#photoSelectorContainer").empty().hide();
$("#samplePhoto").attr("src", "");
$("#partsTableBody").empty();
- $("#global-matrice").empty(); // Pulisci select globale se presente
- // Remove any temporary messages
+ $("#global-matrice").empty();
$(".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) {
return {
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);
if (matrice) {
const option = new Option(
- matrice.NomeMatriceTraduzione,
+ matrice.NomeMatrice, // Updated to use NomeMatrice
matrice.IdMatrice,
true,
true,
@@ -843,7 +886,7 @@ $(document).ready(function () {
const idquotations = $("#partsModal").data("idquotations");
const endpoint = idquotations
? "save_matrice_quotation.php"
- : "save_matrice.php"; // Assumendo esista per quotations, altrimenti adatta
+ : "save_matrice.php";
const data = idquotations
? { idquotations: idquotations }
: { iddatadb: iddatadb };
@@ -915,7 +958,7 @@ $(document).ready(function () {
const options = matrici.map(function (matrice) {
return {
id: matrice.IdMatrice,
- text: matrice.NomeMatriceTraduzione,
+ text: matrice.NomeMatrice, // Updated to use NomeMatrice
};
});