Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| cf45a5bc31 | |||
| 9826331545 | |||
| 62bf4ebd92 | |||
| 6e465e3010 |
+12
@@ -51,4 +51,16 @@ public/userarea/class/curl_request_debug.log
|
||||
# Ignora cartella photostrf in public/userarea
|
||||
/public/userarea/photostrf/
|
||||
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
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
require_once dirname(__DIR__, 3) . '/vendor/autoload.php'; // Torna al livello di public
|
||||
require_once dirname(__DIR__, 3) . '/vendor/autoload.php';
|
||||
|
||||
use Dotenv\Dotenv;
|
||||
|
||||
@@ -13,7 +13,7 @@ class VisualLimsApiClient
|
||||
|
||||
private function __construct()
|
||||
{
|
||||
$dotenv = Dotenv::createImmutable(dirname(__DIR__, 3)); // Torna al livello di public
|
||||
$dotenv = Dotenv::createImmutable(dirname(__DIR__, 3)); // Corretto per C:\xampp8-2-12\htdocs\trf_certest\.env
|
||||
$dotenv->load();
|
||||
|
||||
$this->baseUrl = $_ENV['API_BASE_URL'];
|
||||
@@ -87,6 +87,7 @@ class VisualLimsApiClient
|
||||
$token = $this->getToken();
|
||||
$url = "{$this->baseUrl}/api/odata/{$endpoint}";
|
||||
|
||||
|
||||
$ch = curl_init($url);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
||||
@@ -120,4 +121,88 @@ class VisualLimsApiClient
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function post($endpoint, $payload)
|
||||
{
|
||||
$token = $this->getToken();
|
||||
$url = "{$this->baseUrl}/api/odata/{$endpoint}"; // Corretto per /api/odata/CommessaWeb
|
||||
file_put_contents(__DIR__ . '/url_debug.log', date('Y-m-d H:i:s') . " - POST URL: {$url}\n", FILE_APPEND);
|
||||
$ch = curl_init($url);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_POST, true);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload));
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
||||
"Authorization: Bearer {$token}",
|
||||
"Content-Type: application/json",
|
||||
"Accept: application/json"
|
||||
]);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
||||
curl_setopt($ch, CURLOPT_VERBOSE, true);
|
||||
$log = fopen(__DIR__ . '/curl_request_debug.log', 'w') ?: fopen('php://stderr', 'w');
|
||||
curl_setopt($ch, CURLOPT_STDERR, $log);
|
||||
|
||||
$response = curl_exec($ch);
|
||||
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
$curl_error = curl_error($ch);
|
||||
fclose($log);
|
||||
curl_close($ch);
|
||||
|
||||
if ($response === false) {
|
||||
throw new Exception("Errore nella richiesta POST: {$curl_error}");
|
||||
}
|
||||
|
||||
if ($http_code >= 400) {
|
||||
throw new Exception("Errore nella richiesta POST: HTTP {$http_code}, Risposta: " . substr($response, 0, 1000));
|
||||
}
|
||||
|
||||
$data = json_decode($response, true);
|
||||
if (json_last_error() !== JSON_ERROR_NONE) {
|
||||
throw new Exception("Risposta non JSON valida: " . substr($response, 0, 1000));
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function patch($endpoint, $payload)
|
||||
{
|
||||
$token = $this->getToken();
|
||||
$url = "{$this->baseUrl}/api/odata/{$endpoint}"; // Corretto per /api/odata/CommessaWeb({key})
|
||||
|
||||
$ch = curl_init($url);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PATCH');
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload));
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
||||
"Authorization: Bearer {$token}",
|
||||
"Content-Type: application/json",
|
||||
"Accept: application/json"
|
||||
]);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
||||
curl_setopt($ch, CURLOPT_VERBOSE, true);
|
||||
$log = fopen(__DIR__ . '/curl_request_debug.log', 'w') ?: fopen('php://stderr', 'w');
|
||||
curl_setopt($ch, CURLOPT_STDERR, $log);
|
||||
|
||||
$response = curl_exec($ch);
|
||||
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
$curl_error = curl_error($ch);
|
||||
fclose($log);
|
||||
curl_close($ch);
|
||||
|
||||
if ($response === false) {
|
||||
throw new Exception("Errore nella richiesta PATCH: {$curl_error}");
|
||||
}
|
||||
|
||||
if ($http_code >= 400) {
|
||||
throw new Exception("Errore nella richiesta PATCH: HTTP {$http_code}, Risposta: " . substr($response, 0, 1000));
|
||||
}
|
||||
|
||||
$data = json_decode($response, true);
|
||||
if (json_last_error() !== JSON_ERROR_NONE) {
|
||||
throw new Exception("Risposta non JSON valida: " . substr($response, 0, 1000));
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -12,6 +12,3 @@
|
||||
2025-08-26 16:49:24 - Risposta non JSON valida: <?xml version="1.0" encoding="utf-8"?><edmx:Edmx Version="4.0" xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx"><edmx:DataServices><Schema Namespace="DevExpress.ExpressApp.SystemModule" xmlns="http://docs.oasis-open.org/odata/ns/edm"><EntityType Name="DashboardViewItemDescriptor"><Key><PropertyRef Name="ViewId" /></Key><Property Name="ViewId" Type="Edm.String" Nullable="false" /></EntityType><EntityType Name="DashboardOrganizationItem" BaseType="DevExpress.ExpressApp.NonPersistentLiteObject" Abstract="true"><Property Name="Visibility" Type="DevExpress.ExpressApp.Editors.ViewItemVisibility" Nullable="false" /></EntityType><EntityType Name="DashboardOrganizationItem_1OfIModelDashboardViewItem" BaseType="DevExpress.ExpressApp.SystemModule.DashboardOrganizationItem" Abstract="true" /><EntityType Name="ViewDashboardOrganizationItem" BaseType="DevExpress.ExpressApp.SystemModule.DashboardOrganizationItem_1OfIModelDashboardViewItem"><Property Name="ObjectType" Type="System.Type" /><Proper
|
||||
2025-08-26 16:50:23 - Risposta non JSON valida: <?xml version="1.0" encoding="utf-8"?><edmx:Edmx Version="4.0" xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx"><edmx:DataServices><Schema Namespace="DevExpress.ExpressApp.SystemModule" xmlns="http://docs.oasis-open.org/odata/ns/edm"><EntityType Name="DashboardViewItemDescriptor"><Key><PropertyRef Name="ViewId" /></Key><Property Name="ViewId" Type="Edm.String" Nullable="false" /></EntityType><EntityType Name="DashboardOrganizationItem" BaseType="DevExpress.ExpressApp.NonPersistentLiteObject" Abstract="true"><Property Name="Visibility" Type="DevExpress.ExpressApp.Editors.ViewItemVisibility" Nullable="false" /></EntityType><EntityType Name="DashboardOrganizationItem_1OfIModelDashboardViewItem" BaseType="DevExpress.ExpressApp.SystemModule.DashboardOrganizationItem" Abstract="true" /><EntityType Name="ViewDashboardOrganizationItem" BaseType="DevExpress.ExpressApp.SystemModule.DashboardOrganizationItem_1OfIModelDashboardViewItem"><Property Name="ObjectType" Type="System.Type" /><Proper
|
||||
2025-09-08 08:39:17 - Risposta non JSON valida: <?xml version="1.0" encoding="utf-8"?><edmx:Edmx Version="4.0" xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx"><edmx:DataServices><Schema Namespace="DevExpress.ExpressApp.SystemModule" xmlns="http://docs.oasis-open.org/odata/ns/edm"><EntityType Name="DashboardViewItemDescriptor"><Key><PropertyRef Name="ViewId" /></Key><Property Name="ViewId" Type="Edm.String" Nullable="false" /></EntityType><EntityType Name="DashboardOrganizationItem" BaseType="DevExpress.ExpressApp.NonPersistentLiteObject" Abstract="true"><Property Name="Visibility" Type="DevExpress.ExpressApp.Editors.ViewItemVisibility" Nullable="false" /></EntityType><EntityType Name="DashboardOrganizationItem_1OfIModelDashboardViewItem" BaseType="DevExpress.ExpressApp.SystemModule.DashboardOrganizationItem" Abstract="true" /><EntityType Name="ViewDashboardOrganizationItem" BaseType="DevExpress.ExpressApp.SystemModule.DashboardOrganizationItem_1OfIModelDashboardViewItem"><Property Name="ObjectType" Type="System.Type" /><Proper
|
||||
2025-09-16 13:37:03 - Autenticazione fallita: HTTP 400, Errore cURL: , Risposta: {"title":"Bad Request","status":400,"detail":"Cannot persist the object. It was modified or deleted (purged) by another application.","instance":"POST /api/authentication/authenticate","errorCode":"96bfc1252b"}
|
||||
2025-09-16 13:37:51 - Autenticazione fallita: HTTP 400, Errore cURL: , Risposta: {"title":"Bad Request","status":400,"detail":"Cannot persist the object. It was modified or deleted (purged) by another application.","instance":"POST /api/authentication/authenticate","errorCode":"96bfc1252b"}
|
||||
2025-09-16 13:44:24 - Autenticazione fallita: HTTP 400, Errore cURL: , Risposta: {"title":"Bad Request","status":400,"detail":"Cannot persist the object. It was modified or deleted (purged) by another application.","instance":"POST /api/authentication/authenticate","errorCode":"96bfc1252b"}
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,290 @@
|
||||
<?php
|
||||
// File: export_to_lims.php
|
||||
ini_set('display_errors', '1');
|
||||
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__, 2)); // 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' => 'Richiedente test',
|
||||
'Descrizione' => 'esempio Claudio'
|
||||
];
|
||||
|
||||
// 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);
|
||||
|
||||
$commesseCustomFields = [];
|
||||
foreach ($customFields as $field) {
|
||||
$commesseCustomFields[] = [
|
||||
'IdCommesseCustomFields' => (int)$field['IdCommesseCustomFields'],
|
||||
'Valore' => $field['Valore'] ?? ''
|
||||
];
|
||||
}
|
||||
|
||||
$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
|
||||
try {
|
||||
$response = $apiClient->post('CommessaWeb', $payloadCommessa);
|
||||
if (!isset($response['IdCommessa']) || !isset($response['CodiceCommessa'])) {
|
||||
throw new Exception("Risposta API non valida: IdCommessa o CodiceCommessa mancanti: " . json_encode($response));
|
||||
}
|
||||
$idcommessaweb = (int)$response['IdCommessa'];
|
||||
$commessaweb = $response['CodiceCommessa'];
|
||||
error_log(date('Y-m-d H:i:s') . " - CommessaWeb creata: idcommessaweb {$idcommessaweb}, codice {$commessaweb} per iddatadb {$iddatadb}\n", 3, $logDir . '/export_lims_success.log');
|
||||
// Salva payload CommessaWeb
|
||||
$outputFileCommessa = $logDir . "/commessaweb_create_{$iddatadb}_{$idcommessaweb}.json";
|
||||
file_put_contents($outputFileCommessa, json_encode($payloadCommessa, JSON_PRETTY_PRINT));
|
||||
error_log(date('Y-m-d H:i:s') . " - Payload CommessaWeb salvato in {$outputFileCommessa}\n", 3, $logDir . '/export_lims_success.log');
|
||||
} catch (Exception $e) {
|
||||
error_log(date('Y-m-d H:i:s') . " - Errore nella creazione della CommessaWeb: " . $e->getMessage() . "\n", 3, $logDir . '/export_lims_error.log');
|
||||
throw new Exception("Errore nella creazione della CommessaWeb: " . $e->getMessage());
|
||||
}
|
||||
|
||||
// Salva idcommessaweb e commessaweb in datadb
|
||||
$updateStmt = $pdo->prepare("UPDATE datadb SET idcommessaweb = :idcommessaweb, commessaweb = :commessaweb WHERE iddatadb = :iddatadb");
|
||||
$updateStmt->execute([
|
||||
'idcommessaweb' => $idcommessaweb,
|
||||
'commessaweb' => $commessaweb,
|
||||
'iddatadb' => $iddatadb
|
||||
]);
|
||||
|
||||
// Step 2: Crea Campioni
|
||||
try {
|
||||
foreach ($payloadsCampioni as $index => $payloadCampione) {
|
||||
$payloadCampione['Commessa'] = $idcommessaweb;
|
||||
// Salva payload Campione
|
||||
$outputFileCampione = $logDir . "/campione_{$iddatadb}_{$idcommessaweb}_{$campioni[$index]['part_number']}.json";
|
||||
file_put_contents($outputFileCampione, json_encode($payloadCampione, JSON_PRETTY_PRINT));
|
||||
error_log(date('Y-m-d H:i:s') . " - Payload Campione salvato in {$outputFileCampione}\n", 3, $logDir . '/export_lims_success.log');
|
||||
$apiClient->post('Campione', $payloadCampione);
|
||||
$payloadsCampioni[$index] = $payloadCampione; // Aggiorna il payload con Commessa
|
||||
error_log(date('Y-m-d H:i:s') . " - Campione creato: part_number {$campioni[$index]['part_number']} per idcommessaweb {$idcommessaweb}\n", 3, $logDir . '/export_lims_success.log');
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
error_log(date('Y-m-d H:i:s') . " - Errore nella creazione dei Campioni: " . $e->getMessage() . "\n", 3, $logDir . '/export_lims_error.log');
|
||||
throw new Exception("Errore nella creazione dei Campioni: " . $e->getMessage());
|
||||
}
|
||||
|
||||
// Step 3: Aggiorna CommesseCustomFields
|
||||
try {
|
||||
// Salva payload CustomFields
|
||||
$outputFileCustomFields = $logDir . "/commessaweb_customfields_{$iddatadb}_{$idcommessaweb}.json";
|
||||
file_put_contents($outputFileCustomFields, json_encode($payloadCustomFields, JSON_PRETTY_PRINT));
|
||||
error_log(date('Y-m-d H:i:s') . " - PayloadCustomFields per idcommessaweb {$idcommessaweb}: " . json_encode($payloadCustomFields, JSON_PRETTY_PRINT) . "\n", 3, $logDir . '/export_lims_success.log');
|
||||
error_log(date('Y-m-d H:i:s') . " - Payload CustomFields salvato in {$outputFileCustomFields}\n", 3, $logDir . '/export_lims_success.log');
|
||||
$apiClient->patch("CommessaWeb({$idcommessaweb})", $payloadCustomFields);
|
||||
error_log(date('Y-m-d H:i:s') . " - CommesseCustomFields aggiornati per idcommessaweb {$idcommessaweb}\n", 3, $logDir . '/export_lims_success.log');
|
||||
} catch (Exception $e) {
|
||||
error_log(date('Y-m-d H:i:s') . " - Errore nell'aggiornamento CommesseCustomFields: " . $e->getMessage() . "\n", 3, $logDir . '/export_lims_error.log');
|
||||
throw new Exception("Errore nell'aggiornamento CommesseCustomFields: " . $e->getMessage());
|
||||
}
|
||||
|
||||
// Step 4: Invia Commessa
|
||||
try {
|
||||
// Salva payload InviaCommessa
|
||||
$outputFileInviaCommessa = $logDir . "/commessaweb_invia_{$iddatadb}_{$idcommessaweb}.json";
|
||||
file_put_contents($outputFileInviaCommessa, json_encode($payloadInviaCommessa, JSON_PRETTY_PRINT));
|
||||
error_log(date('Y-m-d H:i:s') . " - Payload InviaCommessa salvato in {$outputFileInviaCommessa}\n", 3, $logDir . '/export_lims_success.log');
|
||||
$apiClient->post("CommessaWeb({$idcommessaweb})/InviaCommessa", $payloadInviaCommessa);
|
||||
error_log(date('Y-m-d H:i:s') . " - Commessa inviata: idcommessaweb {$idcommessaweb}\n", 3, $logDir . '/export_lims_success.log');
|
||||
} catch (Exception $e) {
|
||||
error_log(date('Y-m-d H:i:s') . " - Errore nell'invio della Commessa: " . $e->getMessage() . "\n", 3, $logDir . '/export_lims_error.log');
|
||||
throw new Exception("Errore nell'invio della Commessa: " . $e->getMessage());
|
||||
}
|
||||
|
||||
// Step 5: Recupera il numero commessaweb
|
||||
try {
|
||||
$commessaData = $apiClient->get("CommessaWeb({$idcommessaweb})");
|
||||
$commessaweb = $commessaData['CodiceCommessaWeb'] ?? $commessaweb; // Usa CodiceCommessaWeb o fallback
|
||||
if ($commessaweb) {
|
||||
$updateStmt = $pdo->prepare("UPDATE datadb SET commessaweb = :commessaweb WHERE iddatadb = :iddatadb");
|
||||
$updateStmt->execute(['commessaweb' => $commessaweb, 'iddatadb' => $iddatadb]);
|
||||
}
|
||||
error_log(date('Y-m-d H:i:s') . " - CommessaWeb recuperata: codice {$commessaweb} per idcommessaweb {$idcommessaweb}\n", 3, $logDir . '/export_lims_success.log');
|
||||
} catch (Exception $e) {
|
||||
error_log(date('Y-m-d H:i:s') . " - Errore nel recupero della CommessaWeb: " . $e->getMessage() . "\n", 3, $logDir . '/export_lims_error.log');
|
||||
throw new Exception("Errore nel recupero della CommessaWeb: " . $e->getMessage());
|
||||
}
|
||||
|
||||
// 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()
|
||||
]);
|
||||
}
|
||||
@@ -128,9 +128,6 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
||||
<link rel="icon" href="assets/images/favicon-32x32.png" type="image/png" />
|
||||
<?php include('cssinclude.php'); ?>
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.6.0/css/all.min.css" crossorigin="anonymous" referrerpolicy="no-referrer" />
|
||||
<link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css" rel="stylesheet" />
|
||||
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script>
|
||||
<style>
|
||||
input.auto-input,
|
||||
select.auto-input {
|
||||
@@ -950,7 +947,7 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
||||
<?php include('include/footer.php'); ?>
|
||||
</div>
|
||||
<?php include('jsinclude.php'); ?>
|
||||
|
||||
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/fabric.js/5.3.1/fabric.min.js"></script>
|
||||
<script src="photos.js"></script>
|
||||
<script src="parts.js"></script>
|
||||
|
||||
@@ -405,6 +405,16 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
||||
.save-all-btn:hover {
|
||||
background-color: #218838;
|
||||
}
|
||||
|
||||
#exportConfirmModal,
|
||||
#exportResponseModal {
|
||||
z-index: 1300 !important;
|
||||
}
|
||||
|
||||
#exportConfirmModal .modal-backdrop,
|
||||
#exportResponseModal .modal-backdrop {
|
||||
z-index: 1299 !important;
|
||||
}
|
||||
</style>
|
||||
<title>Edit Imported Data - <?= htmlspecialchars($titlewebsite, ENT_QUOTES, 'UTF-8'); ?></title>
|
||||
</head>
|
||||
@@ -708,6 +718,7 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
||||
<script src="photos.js"></script>
|
||||
<script src="parts.js"></script>
|
||||
<script src="tracking.js"></script>
|
||||
<script src="export_to_lims.js"></script>
|
||||
<script>
|
||||
document.addEventListener("DOMContentLoaded", function() {
|
||||
console.log("Page loaded, initializing event listeners");
|
||||
@@ -900,6 +911,8 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
window.addEventListener("beforeunload", function(e) {
|
||||
if (hasChanges) {
|
||||
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>
|
||||
document.addEventListener("DOMContentLoaded", function() {
|
||||
@@ -1066,6 +1099,43 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
||||
populateDropdowns();
|
||||
});
|
||||
</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>
|
||||
|
||||
</html>
|
||||
@@ -1,7 +1,7 @@
|
||||
<!-- Bootstrap JS -->
|
||||
<script src="assets/js/bootstrap.bundle.min.js"></script>
|
||||
<!--plugins-->
|
||||
|
||||
<script src="assets/js/jquery.min.js"></script>
|
||||
<script src="assets/plugins/simplebar/js/simplebar.min.js"></script>
|
||||
<script src="assets/plugins/metismenu/js/metisMenu.min.js"></script>
|
||||
<script src="assets/plugins/perfect-scrollbar/js/perfect-scrollbar.js"></script>
|
||||
|
||||
@@ -14,9 +14,9 @@ if (!$iddatadb) {
|
||||
}
|
||||
|
||||
try {
|
||||
$stmt = $pdo->prepare("SELECT id, iddatadb, part_number, part_description, idmatrice FROM identification_parts WHERE iddatadb = :iddatadb ORDER BY part_number ASC");
|
||||
$stmt = $pdo->prepare("SELECT id, iddatadb, part_number, part_description FROM identification_parts WHERE iddatadb = :iddatadb ORDER BY part_number ASC");
|
||||
$stmt->execute([':iddatadb' => $iddatadb]);
|
||||
$parts = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
$parts = $stmt->fetchAll();
|
||||
|
||||
echo json_encode(['success' => true, 'parts' => $parts]);
|
||||
} catch (PDOException $e) {
|
||||
|
||||
@@ -9,12 +9,10 @@
|
||||
<div class="modal-body">
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; min-width: 0;">
|
||||
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px;">
|
||||
<h6 style="margin: 0; white-space: nowrap;">Elenco Parti</h6>
|
||||
<div style="display: flex; align-items: center; min-width: 0;">
|
||||
<select id="global-matrice" class="ms-2" style="width: 250px !important; min-width: 250px !important;">
|
||||
</select>
|
||||
<input type="checkbox" id="showMixParts" name="showMixParts" style="margin-right: 5px; margin-left: 10px;">
|
||||
<div style="display: flex; align-items: center;">
|
||||
<input type="checkbox" id="showMixParts" name="showMixParts" style="margin-right: 5px;">
|
||||
<label for="showMixParts" style="font-size: 0.9rem; margin-right: 10px;">Mix</label>
|
||||
<button type="button" class="btn btn-info btn-sm" id="renumberPartsBtn" style="padding: 0.1rem 0.5rem; font-size: 0.8rem;">Rinumera Parti</button>
|
||||
<button type="button" class="btn btn-secondary btn-sm ms-2" id="toggleVoiceBtn" style="padding: 0.1rem 0.5rem; font-size: 0.8rem;"><i class="fas fa-microphone"></i> Voce</button>
|
||||
@@ -172,6 +170,7 @@
|
||||
/* Unsaved changes */
|
||||
#savePhotoBtn.unsaved {
|
||||
background-color: #dc3545 !important;
|
||||
/* Rosso */
|
||||
border-color: #dc3545 !important;
|
||||
color: white !important;
|
||||
animation: pulse 1.2s infinite;
|
||||
@@ -192,58 +191,37 @@
|
||||
}
|
||||
}
|
||||
|
||||
/* Stili per Select2 in #partsList e #global-matrice */
|
||||
#partsList .select2-container,
|
||||
.select2-container--default #global-matrice {
|
||||
width: 250px !important;
|
||||
min-width: 250px !important;
|
||||
margin-left: 10px;
|
||||
/* Stile per il selettore personalizzato dei colori */
|
||||
.color-picker-container {
|
||||
position: relative;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
#partsList .select2-selection--single,
|
||||
.select2-container--default #global-matrice .select2-selection--single {
|
||||
height: 26px !important;
|
||||
padding: 0.2rem 0.5rem !important;
|
||||
font-size: 0.9rem !important;
|
||||
border: 1px solid #ced4da !important;
|
||||
background-color: #fff !important;
|
||||
.color-picker {
|
||||
display: none;
|
||||
position: absolute;
|
||||
top: 25px;
|
||||
left: 0;
|
||||
background: #fff;
|
||||
border: 1px solid #ccc;
|
||||
padding: 5px;
|
||||
z-index: 1002;
|
||||
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
|
||||
flex-wrap: wrap;
|
||||
width: 120px;
|
||||
}
|
||||
|
||||
#partsList .select2-selection__rendered,
|
||||
.select2-container--default #global-matrice .select2-selection__rendered {
|
||||
line-height: 24px !important;
|
||||
overflow: hidden !important;
|
||||
text-overflow: ellipsis !important;
|
||||
white-space: nowrap !important;
|
||||
.color-option {
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
margin: 3px;
|
||||
border: 1px solid #000;
|
||||
cursor: pointer;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
#partsList .select2-selection__arrow,
|
||||
.select2-container--default #global-matrice .select2-selection__arrow {
|
||||
height: 26px !important;
|
||||
}
|
||||
|
||||
#partsList .save-status,
|
||||
#partsList .save-loading {
|
||||
margin-left: 5px;
|
||||
}
|
||||
|
||||
.select2-container--open .select2-dropdown {
|
||||
z-index: 1051 !important;
|
||||
border: 1px solid #aaa !important;
|
||||
border-radius: 4px !important;
|
||||
background: white !important;
|
||||
overflow-y: auto !important;
|
||||
max-height: 200px !important;
|
||||
}
|
||||
|
||||
.select2-container--default .select2-search--dropdown .select2-search__field {
|
||||
width: 100% !important;
|
||||
padding: 0.2rem !important;
|
||||
}
|
||||
|
||||
.select2-container--default .part-matrice,
|
||||
.select2-container--default #global-matrice {
|
||||
width: 250px !important;
|
||||
min-width: 250px !important;
|
||||
.color-option:hover {
|
||||
border: 2px solid #000;
|
||||
margin: 2px;
|
||||
}
|
||||
</style>
|
||||
+105
-262
@@ -16,15 +16,10 @@ $(document).ready(function () {
|
||||
let photoAnnotations = {};
|
||||
// colors keyed by part number
|
||||
let partColors = {};
|
||||
// matrice IDs keyed by part number
|
||||
let partMatrice = {};
|
||||
|
||||
// selection
|
||||
let selectedPartNumber = null;
|
||||
|
||||
// lista delle matrici precaricata
|
||||
let matrici = [];
|
||||
|
||||
// ===================
|
||||
// VOICE RECOGNITION SETUP
|
||||
// ===================
|
||||
@@ -32,13 +27,13 @@ $(document).ready(function () {
|
||||
window.SpeechRecognition || window.webkitSpeechRecognition;
|
||||
let recognition = null;
|
||||
let isVoiceActive = false;
|
||||
const magicWord = "salva"; // Parola magica scelta
|
||||
const magicWord = "salva"; // Parola magica scelta: "prossima" (fa andare alla riga successiva)
|
||||
|
||||
if (SpeechRecognition) {
|
||||
recognition = new SpeechRecognition();
|
||||
recognition.lang = "it-IT";
|
||||
recognition.continuous = true;
|
||||
recognition.interimResults = false;
|
||||
recognition.lang = "it-IT"; // Lingua italiana
|
||||
recognition.continuous = true; // Ascolto continuo
|
||||
recognition.interimResults = false; // Solo risultati finali per semplicità
|
||||
|
||||
recognition.onresult = function (event) {
|
||||
const transcript = event.results[
|
||||
@@ -48,10 +43,11 @@ $(document).ready(function () {
|
||||
.toLowerCase();
|
||||
console.log("Transcript vocale:", transcript);
|
||||
|
||||
const $currentRow = $("#partsTableBody tr:last");
|
||||
const $currentRow = $("#partsTableBody tr:last"); // Ultima riga corrente
|
||||
const $descriptionInput = $currentRow.find(".part-description");
|
||||
|
||||
if (transcript.includes(magicWord)) {
|
||||
// Rimuovi la parola magica e aggiungi il resto alla descrizione corrente
|
||||
const cleanedTranscript = transcript
|
||||
.replace(magicWord, "")
|
||||
.trim();
|
||||
@@ -63,8 +59,9 @@ $(document).ready(function () {
|
||||
cleanedTranscript
|
||||
).trim(),
|
||||
);
|
||||
$descriptionInput.trigger("blur");
|
||||
$descriptionInput.trigger("blur"); // Salva se necessario
|
||||
}
|
||||
// Aggiungi nuova riga (simile a click su +)
|
||||
const maxPartNumber = Math.max(
|
||||
...$("#partsTableBody tr")
|
||||
.map(function () {
|
||||
@@ -76,19 +73,22 @@ $(document).ready(function () {
|
||||
.get(),
|
||||
);
|
||||
addNewRow(maxPartNumber + 1);
|
||||
// Focus sulla nuova descrizione
|
||||
const $newRow = $("#partsTableBody tr:last");
|
||||
$newRow.find(".part-description").focus();
|
||||
} else {
|
||||
// Aggiungi il transcript alla descrizione corrente
|
||||
$descriptionInput.val(
|
||||
($descriptionInput.val() + " " + transcript).trim(),
|
||||
);
|
||||
$descriptionInput.trigger("blur");
|
||||
$descriptionInput.trigger("blur"); // Salva se necessario
|
||||
}
|
||||
};
|
||||
|
||||
recognition.onerror = function (event) {
|
||||
console.error("Errore riconoscimento vocale:", event.error);
|
||||
if (event.error === "no-speech" || event.error === "aborted") {
|
||||
// Riavvia se necessario
|
||||
if (isVoiceActive) recognition.start();
|
||||
} else {
|
||||
alert("Errore nel riconoscimento vocale: " + event.error);
|
||||
@@ -97,15 +97,18 @@ $(document).ready(function () {
|
||||
};
|
||||
|
||||
recognition.onend = function () {
|
||||
if (isVoiceActive) recognition.start();
|
||||
if (isVoiceActive) {
|
||||
recognition.start(); // Riavvia per ascolto continuo
|
||||
}
|
||||
};
|
||||
} else {
|
||||
console.warn("Riconoscimento vocale non supportato dal browser.");
|
||||
$("#toggleVoiceBtn").hide();
|
||||
$("#toggleVoiceBtn").hide(); // Nascondi pulsante se non supportato
|
||||
}
|
||||
|
||||
function toggleVoiceRecognition() {
|
||||
if (!recognition) return;
|
||||
|
||||
isVoiceActive = !isVoiceActive;
|
||||
const $btn = $("#toggleVoiceBtn");
|
||||
if (isVoiceActive) {
|
||||
@@ -113,6 +116,7 @@ $(document).ready(function () {
|
||||
'<i class="fas fa-microphone-slash"></i> Stop Voce',
|
||||
);
|
||||
recognition.start();
|
||||
// Focus iniziale sull'ultima descrizione
|
||||
const $currentRow = $("#partsTableBody tr:last");
|
||||
$currentRow.find(".part-description").focus();
|
||||
} else {
|
||||
@@ -150,39 +154,8 @@ $(document).ready(function () {
|
||||
$("#trfHeader").text(`${iddatadb} - ${importRef} - ${description}`);
|
||||
$("#partsModal").data("iddatadb", iddatadb);
|
||||
|
||||
// Precarica le matrici una volta sola
|
||||
if (matrici.length === 0) {
|
||||
$.ajax({
|
||||
url: "get_matrice.php",
|
||||
method: "GET",
|
||||
dataType: "json",
|
||||
success: function (data) {
|
||||
matrici = data.value || [];
|
||||
console.log(
|
||||
"Matrici precaricate (una volta sola):",
|
||||
matrici,
|
||||
);
|
||||
initializeGlobalSelect2();
|
||||
loadPhoto(iddatadb);
|
||||
loadExistingParts(iddatadb);
|
||||
},
|
||||
error: function (xhr, status, error) {
|
||||
console.error(
|
||||
"Errore nel precaricamento delle matrici:",
|
||||
error,
|
||||
);
|
||||
alert("Errore nel caricamento delle matrici: " + error);
|
||||
matrici = [];
|
||||
loadPhoto(iddatadb);
|
||||
loadExistingParts(iddatadb);
|
||||
},
|
||||
});
|
||||
} else {
|
||||
console.log("Matrici già precaricate, riutilizzo.");
|
||||
initializeGlobalSelect2();
|
||||
loadPhoto(iddatadb);
|
||||
loadExistingParts(iddatadb);
|
||||
}
|
||||
loadPhoto(iddatadb);
|
||||
loadExistingParts(iddatadb);
|
||||
|
||||
if (partsModal) {
|
||||
const modal = new bootstrap.Modal(partsModal);
|
||||
@@ -277,7 +250,7 @@ $(document).ready(function () {
|
||||
|
||||
function loadSinglePhoto(photoPath) {
|
||||
const img = $("#samplePhoto");
|
||||
img.off("load");
|
||||
img.off("load"); // avoid stacking multiple handlers
|
||||
img.attr("src", photoPath);
|
||||
|
||||
img.on("load", function () {
|
||||
@@ -308,6 +281,7 @@ $(document).ready(function () {
|
||||
|
||||
canvas.width = naturalWidth;
|
||||
canvas.height = naturalHeight;
|
||||
|
||||
canvas.style.width = `${displayWidth}px`;
|
||||
canvas.style.height = `${displayHeight}px`;
|
||||
|
||||
@@ -347,6 +321,7 @@ $(document).ready(function () {
|
||||
</tr>`;
|
||||
$("#partsTableBody").append(newRow);
|
||||
updateRowButtons();
|
||||
// Initialize color for the new part
|
||||
const partNumber = nextPartNumber || 1;
|
||||
partColors[partNumber] = defaultColor;
|
||||
}
|
||||
@@ -402,10 +377,9 @@ $(document).ready(function () {
|
||||
if (response.success) {
|
||||
$row.remove();
|
||||
delete partColors[partNumber];
|
||||
delete partMatrice[partNumber];
|
||||
updateRowButtons();
|
||||
updatePartsList();
|
||||
clearCanvasMarkers(false);
|
||||
clearCanvasMarkers(false); // Preserve descriptions
|
||||
} else {
|
||||
alert("Errore nell'eliminazione: " + response.message);
|
||||
}
|
||||
@@ -424,7 +398,6 @@ $(document).ready(function () {
|
||||
} else {
|
||||
$row.remove();
|
||||
delete partColors[partNumber];
|
||||
delete partMatrice[partNumber];
|
||||
updateRowButtons();
|
||||
updatePartsList();
|
||||
}
|
||||
@@ -439,6 +412,7 @@ $(document).ready(function () {
|
||||
const $saveLoading = $row.find(".save-loading");
|
||||
const iddatadb = $("#partsModal").data("iddatadb");
|
||||
const isMix = partDescription.startsWith("Mix") ? "Y" : "N";
|
||||
|
||||
const partId = $row.data("part-id") || null;
|
||||
|
||||
if (partDescription && iddatadb) {
|
||||
@@ -483,168 +457,6 @@ $(document).ready(function () {
|
||||
}
|
||||
});
|
||||
|
||||
$(document).on("change", ".part-color", function () {
|
||||
const partNumber = $(this).closest("li").data("part-number");
|
||||
const partColor = $(this).val();
|
||||
partColors[partNumber] = partColor;
|
||||
updateMarkers();
|
||||
markUnsaved();
|
||||
});
|
||||
|
||||
// Funzione per inizializzare Select2 sulle tendine delle matrici
|
||||
function initializeSelect2($select, partNumber, partId, idmatrice) {
|
||||
if (typeof $.fn.select2 === "undefined") {
|
||||
console.error("Select2 non disponibile per parte " + partNumber);
|
||||
$select.replaceWith(
|
||||
'<input type="text" class="form-control form-control-sm" placeholder="Select2 non disponibile" disabled>',
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
// Popola con i dati precaricati
|
||||
const options = matrici.map(function (matrice) {
|
||||
return {
|
||||
id: matrice.IdMatrice,
|
||||
text: matrice.NomeMatriceTraduzione,
|
||||
};
|
||||
});
|
||||
|
||||
$select.select2({
|
||||
placeholder: "Seleziona matrice",
|
||||
allowClear: true,
|
||||
data: options, // Carica la lista completa all'apertura
|
||||
dropdownParent: $("#partsModal"),
|
||||
matcher: function (params, data) {
|
||||
// Filtraggio lato client sulla descrizione
|
||||
if (!params.term || params.term.length < 3) {
|
||||
return data; // Mostra tutto se meno di 3 caratteri
|
||||
}
|
||||
const term = params.term.toUpperCase();
|
||||
if (data.text.toUpperCase().indexOf(term) >= 0) {
|
||||
return data;
|
||||
}
|
||||
return null;
|
||||
},
|
||||
});
|
||||
|
||||
// Carica la matrice esistente, se presente
|
||||
if (partId && partId !== "new" && idmatrice) {
|
||||
const matrice = matrici.find((m) => m.IdMatrice == idmatrice);
|
||||
if (matrice) {
|
||||
console.log(
|
||||
"Preselezione matrice per partNumber " + partNumber + ":",
|
||||
matrice,
|
||||
);
|
||||
const option = new Option(
|
||||
matrice.NomeMatriceTraduzione,
|
||||
matrice.IdMatrice,
|
||||
true,
|
||||
true,
|
||||
);
|
||||
$select.append(option).trigger("change");
|
||||
partMatrice[partNumber] = matrice.IdMatrice;
|
||||
} else {
|
||||
console.warn(
|
||||
"Matrice con ID " +
|
||||
idmatrice +
|
||||
" non trovata per partNumber " +
|
||||
partNumber,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Gestione del cambio della matrice
|
||||
$select.on("change", function () {
|
||||
const idmatrice = $(this).val();
|
||||
const $listItem = $(this).closest("li");
|
||||
const $saveStatus = $listItem.find(".save-status");
|
||||
const $saveLoading = $listItem.find(".save-loading");
|
||||
|
||||
console.log(
|
||||
"Cambio matrice per partNumber:",
|
||||
partNumber,
|
||||
"nuovo idmatrice:",
|
||||
idmatrice,
|
||||
);
|
||||
partMatrice[partNumber] = idmatrice || null;
|
||||
|
||||
if (partId && partId !== "new") {
|
||||
$saveLoading.show();
|
||||
$saveStatus.hide();
|
||||
|
||||
$.ajax({
|
||||
url: "save_matrice.php",
|
||||
method: "POST",
|
||||
data: JSON.stringify({
|
||||
iddatadb: $("#partsModal").data("iddatadb"),
|
||||
parts: [
|
||||
{
|
||||
id: partId,
|
||||
idmatrice: idmatrice || null,
|
||||
},
|
||||
],
|
||||
}),
|
||||
contentType: "application/json",
|
||||
success: function (response) {
|
||||
if (response.success) {
|
||||
$saveLoading.hide();
|
||||
$saveStatus.show();
|
||||
setTimeout(() => $saveStatus.hide(), 2000);
|
||||
} else {
|
||||
alert(
|
||||
"Errore nel salvataggio della matrice: " +
|
||||
response.message,
|
||||
);
|
||||
$saveLoading.hide();
|
||||
}
|
||||
},
|
||||
error: function (xhr, status, error) {
|
||||
alert("Errore nel salvataggio della matrice: " + error);
|
||||
$saveLoading.hide();
|
||||
},
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Funzione per inizializzare Select2 sul dropdown globale
|
||||
function initializeGlobalSelect2() {
|
||||
const $select = $("#global-matrice");
|
||||
if (typeof $.fn.select2 === "undefined") {
|
||||
console.error("Select2 non disponibile per il dropdown globale");
|
||||
$select.replaceWith(
|
||||
'<input type="text" class="form-control form-control-sm" placeholder="Select2 non disponibile" disabled>',
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
// Popola con i dati precaricati
|
||||
const options = matrici.map(function (matrice) {
|
||||
return {
|
||||
id: matrice.IdMatrice,
|
||||
text: matrice.NomeMatriceTraduzione,
|
||||
};
|
||||
});
|
||||
|
||||
$select.select2({
|
||||
placeholder: "Seleziona matrice globale",
|
||||
allowClear: true,
|
||||
data: options, // Carica la lista completa all'apertura
|
||||
dropdownParent: $("#partsModal"),
|
||||
matcher: function (params, data) {
|
||||
// Filtraggio lato client sulla descrizione
|
||||
if (!params.term || params.term.length < 3) {
|
||||
return data; // Mostra tutto se meno di 3 caratteri
|
||||
}
|
||||
const term = params.term.toUpperCase();
|
||||
if (data.text.toUpperCase().indexOf(term) >= 0) {
|
||||
return data;
|
||||
}
|
||||
return null;
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function loadExistingParts(iddatadb) {
|
||||
$.ajax({
|
||||
url: "load_parts.php",
|
||||
@@ -673,9 +485,6 @@ $(document).ready(function () {
|
||||
</tr>`;
|
||||
$("#partsTableBody").append(newRow);
|
||||
partColors[part.part_number] = defaultColor;
|
||||
if (part.idmatrice) {
|
||||
partMatrice[part.part_number] = part.idmatrice;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
addNewRow(1);
|
||||
@@ -700,10 +509,22 @@ $(document).ready(function () {
|
||||
function updatePartsList() {
|
||||
const showMixParts = $("#showMixParts").is(":checked");
|
||||
$("#partsList").empty();
|
||||
|
||||
// Definizione di 8 colori predefiniti
|
||||
const predefinedColors = [
|
||||
"#ff0000", // Rosso
|
||||
"#0000ff", // Blu
|
||||
"#00ff00", // Verde
|
||||
"#01832cff", // Giallo
|
||||
"#ff00ff", // Magenta
|
||||
"#00ffff", // Ciano
|
||||
"#800080", // Viola
|
||||
"#ffa500", // Arancione
|
||||
];
|
||||
|
||||
$("#partsTableBody tr").each(function () {
|
||||
const partNumber = $(this).find(".part-number").val();
|
||||
const partDescription = $(this).find(".part-description").val();
|
||||
const partId = $(this).data("part-id");
|
||||
const partColor =
|
||||
partColors[partNumber] ||
|
||||
(partDescription.startsWith("Mix") ? "#0000ff" : "#ff0000");
|
||||
@@ -712,30 +533,56 @@ $(document).ready(function () {
|
||||
partDescription &&
|
||||
(showMixParts || !partDescription.startsWith("Mix"))
|
||||
) {
|
||||
const colorOptions = predefinedColors
|
||||
.map(
|
||||
(color) =>
|
||||
`<div class="color-option" style="background-color: ${color};" data-color="${color}"></div>`,
|
||||
)
|
||||
.join("");
|
||||
|
||||
const listItem = `
|
||||
<li class="list-group-item" data-part-number="${partNumber}" data-part-id="${partId}">
|
||||
${partNumber} - ${partDescription}
|
||||
<div style="display: flex; align-items: center;">
|
||||
<button type="button" class="btn btn-primary btn-sm propagate-matrice-btn" style="padding: 0.1rem 0.3rem; font-size: 0.8rem; margin-right: 3px;"><i class="fas fa-arrow-right fa-xs"></i></button>
|
||||
<select class="part-matrice" style="width: 250px !important; margin-right: 10px;"></select>
|
||||
<button type="button" class="btn btn-success btn-sm add-to-mix-btn" style="padding: 0.1rem 0.3rem; font-size: 0.8rem;"><i class="fas fa-plus fa-xs"></i></button>
|
||||
<input type="color" class="part-color" value="${partColor}" style="margin-left: 5px;">
|
||||
<span class="save-status text-success" style="display: none; margin-left: 5px;"><i class="fas fa-check fa-xs"></i></span>
|
||||
<span class="save-loading text-warning" style="display: none; margin-left: 5px;"><i class="fas fa-spinner fa-spin fa-xs"></i></span>
|
||||
</div>
|
||||
</li>`;
|
||||
<li class="list-group-item" data-part-number="${partNumber}">
|
||||
${partNumber} - ${partDescription}
|
||||
<div style="display: flex; align-items: center;">
|
||||
<button type="button" class="btn btn-success btn-sm add-to-mix-btn" style="padding: 0.1rem 0.3rem; font-size: 0.8rem;"><i class="fas fa-plus fa-xs"></i></button>
|
||||
<div class="color-picker-container">
|
||||
<div class="color-option selected-color" style="background-color: ${partColor}; margin-left: 5px;"></div>
|
||||
<div class="color-picker">${colorOptions}</div>
|
||||
</div>
|
||||
</div>
|
||||
</li>`;
|
||||
$("#partsList").append(listItem);
|
||||
const $select = $("#partsList").find(
|
||||
`li[data-part-number="${partNumber}"] .part-matrice`,
|
||||
);
|
||||
initializeSelect2(
|
||||
$select,
|
||||
partNumber,
|
||||
partId,
|
||||
partMatrice[partNumber],
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
// Gestione del selettore colori personalizzato
|
||||
$(".selected-color").on("click", function (e) {
|
||||
e.stopPropagation();
|
||||
const $picker = $(this).siblings(".color-picker");
|
||||
$(".color-picker").not($picker).hide(); // Chiude altri selettori aperti
|
||||
$picker.toggle();
|
||||
});
|
||||
|
||||
$(".color-option").on("click", function (e) {
|
||||
e.stopPropagation();
|
||||
const $this = $(this);
|
||||
const color = $this.data("color");
|
||||
const $listItem = $this.closest("li");
|
||||
const partNumber = $listItem.data("part-number");
|
||||
partColors[partNumber] = color;
|
||||
$listItem.find(".selected-color").css("background-color", color);
|
||||
$this.closest(".color-picker").hide(); // Chiude il selettore dopo la scelta
|
||||
updateMarkers();
|
||||
markUnsaved();
|
||||
});
|
||||
|
||||
// Chiude il selettore se si clicca fuori
|
||||
$(document).on("click", function (e) {
|
||||
if (!$(e.target).closest(".color-picker-container").length) {
|
||||
$(".color-picker").hide();
|
||||
}
|
||||
});
|
||||
|
||||
updateMarkers();
|
||||
}
|
||||
|
||||
@@ -743,8 +590,8 @@ $(document).ready(function () {
|
||||
const $rows = $("#partsTableBody tr");
|
||||
const iddatadb = $("#partsModal").data("iddatadb");
|
||||
let newPartColors = {};
|
||||
let newPartMatrice = {};
|
||||
|
||||
// Raccogli tutte le righe con i loro dati attuali
|
||||
let partsData = $rows
|
||||
.map(function (index) {
|
||||
const $row = $(this);
|
||||
@@ -755,21 +602,23 @@ $(document).ready(function () {
|
||||
})
|
||||
.get();
|
||||
|
||||
// Rinumera in modo sequenziale
|
||||
partsData.forEach((part, index) => {
|
||||
const newNumber = index + 1;
|
||||
newPartColors[newNumber] = partColors[part.partNumber] || "#ff0000";
|
||||
newPartMatrice[newNumber] = partMatrice[part.partNumber] || null;
|
||||
part.partNumber = newNumber;
|
||||
});
|
||||
|
||||
// Aggiorna i valori nella tabella
|
||||
$rows.each(function (index) {
|
||||
const $row = $(this);
|
||||
$row.find(".part-number").val(index + 1);
|
||||
});
|
||||
|
||||
// Aggiorna partColors
|
||||
partColors = newPartColors;
|
||||
partMatrice = newPartMatrice;
|
||||
|
||||
// Aggiorna i marker nelle annotazioni
|
||||
const currentPhoto = $("#samplePhoto").attr("src");
|
||||
if (photoAnnotations[currentPhoto]) {
|
||||
photoAnnotations[currentPhoto].markers.forEach((marker) => {
|
||||
@@ -784,12 +633,12 @@ $(document).ready(function () {
|
||||
});
|
||||
}
|
||||
|
||||
// Salva le modifiche nel database
|
||||
const partsToSave = partsData.map((part) => ({
|
||||
id: part.partId || null,
|
||||
part_number: part.partNumber,
|
||||
part_description: part.partDescription,
|
||||
mix: part.partDescription.startsWith("Mix") ? "Y" : "N",
|
||||
idmatrice: partMatrice[part.partNumber] || null,
|
||||
}));
|
||||
|
||||
console.log(
|
||||
@@ -800,7 +649,10 @@ $(document).ready(function () {
|
||||
$.ajax({
|
||||
url: "renumber_parts.php",
|
||||
method: "POST",
|
||||
data: JSON.stringify({ iddatadb: iddatadb, parts: partsToSave }),
|
||||
data: JSON.stringify({
|
||||
iddatadb: iddatadb,
|
||||
parts: partsToSave,
|
||||
}),
|
||||
contentType: "application/json",
|
||||
success: function (response) {
|
||||
console.log("Risposta da renumber_parts.php:", response);
|
||||
@@ -878,23 +730,10 @@ $(document).ready(function () {
|
||||
updatePartsList();
|
||||
});
|
||||
|
||||
$(document).on("click", ".propagate-matrice-btn", function () {
|
||||
const $listItem = $(this).closest("li");
|
||||
const globalVal = $("#global-matrice").val();
|
||||
if (globalVal) {
|
||||
$listItem.find(".part-matrice").val(globalVal).trigger("change");
|
||||
} else {
|
||||
alert("Seleziona una matrice globale prima di propagare.");
|
||||
}
|
||||
});
|
||||
|
||||
$("#partsList").on("click", "li", function (e) {
|
||||
if (
|
||||
$(e.target).hasClass("add-to-mix-btn") ||
|
||||
$(e.target).hasClass("part-color") ||
|
||||
$(e.target).hasClass("part-matrice") ||
|
||||
$(e.target).hasClass("propagate-matrice-btn") ||
|
||||
$(e.target).closest(".select2-container").length
|
||||
$(e.target).hasClass("part-color")
|
||||
)
|
||||
return;
|
||||
selectedPartNumber = $(this).data("part-number");
|
||||
@@ -908,7 +747,6 @@ $(document).ready(function () {
|
||||
$("#renumberPartsBtn").on("click", function () {
|
||||
renumberParts();
|
||||
});
|
||||
|
||||
// ===================
|
||||
// MARKERS & DESCRIPTIONS
|
||||
// ===================
|
||||
@@ -922,7 +760,7 @@ $(document).ready(function () {
|
||||
const clickX = e.clientX - rect.left;
|
||||
const clickY = e.clientY - rect.top;
|
||||
|
||||
const x = clickX / photoData.scale;
|
||||
const x = clickX / photoData.scale; // convert to NATURAL coords
|
||||
const y = clickY / photoData.scale;
|
||||
|
||||
const currentPhoto = $("#samplePhoto").attr("src");
|
||||
@@ -1163,7 +1001,7 @@ $(document).ready(function () {
|
||||
});
|
||||
|
||||
$("#removeAnnotationsBtn").on("click", function () {
|
||||
clearCanvasMarkers(true);
|
||||
clearCanvasMarkers(true); // Remove only descriptions
|
||||
});
|
||||
|
||||
$("#undoMarkerBtn").on("click", function () {
|
||||
@@ -1172,6 +1010,7 @@ $(document).ready(function () {
|
||||
|
||||
let unsavedChanges = false;
|
||||
|
||||
// --- helper functions ---
|
||||
function markUnsaved() {
|
||||
if (!unsavedChanges) {
|
||||
unsavedChanges = true;
|
||||
@@ -1184,10 +1023,12 @@ $(document).ready(function () {
|
||||
$("#savePhotoBtn").removeClass("unsaved").text("Salva Foto con Nome");
|
||||
}
|
||||
|
||||
// --- event listeners ---
|
||||
$(document).on("input change", "#partsTableBody input", markUnsaved);
|
||||
$(document).on("click", ".add-row, .add-mix-row, .remove-row", markUnsaved);
|
||||
$(document).on("markerChanged descriptionChanged", markUnsaved);
|
||||
|
||||
// --- modal close protection ---
|
||||
$("#partsModal").on("hide.bs.modal", function (e) {
|
||||
if (unsavedChanges) {
|
||||
if (!confirm("Hai modifiche non salvate. Vuoi davvero uscire?")) {
|
||||
@@ -1196,6 +1037,7 @@ $(document).ready(function () {
|
||||
}
|
||||
});
|
||||
|
||||
// --- SAVE BUTTON ---
|
||||
$("#savePhotoBtn").on("click", function () {
|
||||
const canvas = document.getElementById("photoCanvas");
|
||||
const ctx = canvas.getContext("2d");
|
||||
@@ -1283,10 +1125,11 @@ $(document).ready(function () {
|
||||
|
||||
ctx.beginPath();
|
||||
ctx.arc(x, y, radius, 0, 2 * Math.PI);
|
||||
ctx.fillStyle = markerColor;
|
||||
ctx.fillStyle = markerColor; // Use the stored color
|
||||
ctx.fill();
|
||||
|
||||
ctx.lineWidth = 3;
|
||||
ctx.strokeStyle = markerColor;
|
||||
ctx.strokeStyle = markerColor; // Use the same color for the border
|
||||
ctx.stroke();
|
||||
|
||||
ctx.fillStyle = "#ffffff";
|
||||
@@ -1323,7 +1166,7 @@ $(document).ready(function () {
|
||||
);
|
||||
$("#samplePhoto").attr("src", response.file_path);
|
||||
loadPhoto(iddatadb);
|
||||
clearCanvasMarkers(false);
|
||||
clearCanvasMarkers(false); // Preserve descriptions
|
||||
clearUnsaved();
|
||||
} else {
|
||||
alert("Errore: " + response.message);
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
<?php
|
||||
header('Content-Type: application/json');
|
||||
include('include/headscript.php');
|
||||
|
||||
$dbHandler = DBHandlerSelect::getInstance();
|
||||
$pdo = $dbHandler->getConnection();
|
||||
|
||||
$data = json_decode(file_get_contents('php://input'), true);
|
||||
|
||||
$iddatadb = $data['iddatadb'] ?? null;
|
||||
$parts = $data['parts'] ?? [];
|
||||
|
||||
if (!$iddatadb || empty($parts)) {
|
||||
echo json_encode(['success' => false, 'message' => 'Dati mancanti']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$part = $parts[0];
|
||||
$partId = $part['id'] ?? null;
|
||||
$idmatrice = $part['idmatrice'] ?? null;
|
||||
|
||||
if (!$partId) {
|
||||
echo json_encode(['success' => false, 'message' => 'ID della parte mancante']);
|
||||
exit;
|
||||
}
|
||||
|
||||
try {
|
||||
$stmt = $pdo->prepare("UPDATE identification_parts
|
||||
SET idmatrice = :idmatrice, updated_at = NOW()
|
||||
WHERE id = :id AND iddatadb = :iddatadb");
|
||||
$stmt->execute([
|
||||
':idmatrice' => $idmatrice,
|
||||
':id' => $partId,
|
||||
':iddatadb' => $iddatadb
|
||||
]);
|
||||
|
||||
if ($stmt->rowCount() > 0) {
|
||||
echo json_encode(['success' => true, 'message' => 'Matrice salvata con successo']);
|
||||
} else {
|
||||
echo json_encode(['success' => false, 'message' => 'Nessuna riga aggiornata. Verifica l\'ID della parte.']);
|
||||
}
|
||||
} catch (PDOException $e) {
|
||||
echo json_encode(['success' => false, 'message' => 'Errore nel salvataggio della matrice: ' . $e->getMessage()]);
|
||||
}
|
||||
@@ -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()
|
||||
]);
|
||||
}
|
||||
Reference in New Issue
Block a user