Compare commits

..

5 Commits

14 changed files with 589 additions and 156 deletions
+131
View File
@@ -0,0 +1,131 @@
<?php
require_once "class/VisualLimsApiClient.class.php";
include('include/headscript.php');
$dbHandler = DBHandlerSelect::getInstance();
$pdo = $dbHandler->getConnection();
header("Content-Type: application/json");
// 🔹 Configura directory log (creala se non esiste)
$logDir = __DIR__ . '/logs/api/';
if (!is_dir($logDir)) {
mkdir($logDir, 0755, true);
}
// 🔹 Base URL API
$apiBaseUrl = 'https://93.43.5.102/limsapi/api/odata/';
// 🔹 Hardcoded values
$iddatadb = 846;
$commessaId = 533357;
try {
// 🔹 STEP 4: Fetch Field Values with Labels (usa dati reali per iddatadb=845)
$stmt = $pdo->prepare("
SELECT
idd.field_value,
m.field_label,
m.schema_id,
m.field_id
FROM
import_data_details as idd
JOIN template_mapping m ON idd.mapping_id = m.id
WHERE idd.id = :iddatadb
");
$stmt->execute(['iddatadb' => $iddatadb]);
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
$fieldValues = [];
$valueMap = []; // Mappa per field_id -> valore
foreach ($rows as $row) {
$fieldValues[] = [
"IdCommesseCustomFields" => (int) $row['field_id'],
"Valore" => $row['field_value'],
"FieldLabel" => $row['field_label']
];
$valueMap[(int) $row['field_id']] = $row['field_value']; // Mappa per ID definizione
}
// Logga i fieldValues in error_log
$logFieldValues = "FieldValues dal DB (iddatadb={$iddatadb}):\n" . json_encode($fieldValues, JSON_PRETTY_PRINT);
error_log($logFieldValues);
// 🔹 Initialize API client
$api = VisualLimsApiClient::getInstance();
// 🔹 STEP A: GET iniziale per CommesseCustomFields con espansione CustomField
$expand = "CommesseCustomFields(\$expand=CustomField)"; // Espansione come da istruzioni fornitore
$commessaWithFields = $api->get("CommessaWeb(" . $commessaId . ")?\$expand=" . $expand);
// 🔹 STEP B: Prepara payload PATCH (tutti i campi, sovrascrivi se match su CustomField.IdCustomField == field_id)
$commessaCustomFields = [];
foreach ($commessaWithFields["CommesseCustomFields"] as $customField) {
$definitionId = (int) ($customField["CustomField"]["IdCustomField"] ?? 0); // Usa IdCustomField dal CustomField
$currentValue = $customField["Valore"] ?? '';
$newValue = isset($valueMap[$definitionId]) ? $valueMap[$definitionId] : $currentValue;
$commessaCustomFields[] = [
"IdCommesseCustomFields" => (int) $customField["IdCommesseCustomFields"],
"Valore" => $newValue
];
}
// 🔹 Unico file di log per tutto
$logFile = $logDir . "commessa_{$commessaId}_patch_and_get_" . time() . ".txt";
$logContent = "FieldValues dal DB (iddatadb={$iddatadb}):\n" . json_encode($fieldValues, JSON_PRETTY_PRINT) . "\n\n";
// Log curl-like per GET iniziale
$logContent .= "GET iniziale:\n" .
"curl --location --request GET '{$apiBaseUrl}CommessaWeb({$commessaId})?\$expand=CommesseCustomFields(\$expand=CustomField)' \\\n" .
"--header 'Authorization: Bearer ••••••'\n\n" .
"RESPONSE:\n" . json_encode($commessaWithFields, JSON_PRETTY_PRINT) . "\n\n---\n";
if (!empty($commessaCustomFields)) {
$updatePayload = ["CommesseCustomFields" => $commessaCustomFields];
// Log curl-like per PATCH
$jsonPayload = json_encode($updatePayload, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
$logContent .= "PATCH:\n" .
"curl --location --request PATCH '{$apiBaseUrl}CommessaWeb({$commessaId})' \\\n" .
"--header 'Content-Type: application/json' \\\n" .
"--header 'Authorization: Bearer ••••••' \\\n" .
"--data '{$jsonPayload}'\n\n";
$patchResponse = $api->patch("CommessaWeb({$commessaId})", $updatePayload);
$logContent .= "PATCH RESPONSE:\n" . json_encode($patchResponse, JSON_PRETTY_PRINT) . "\n\n---\n";
} else {
$logContent .= "PATCH: Nessun campo custom da aggiornare\n\n---\n";
}
// 🔹 STEP C: GET di controllo post-PATCH
$commessaAfterPatch = $api->get("CommessaWeb(" . $commessaId . ")?\$expand=" . $expand);
// Log curl-like per GET di controllo
$logContent .= "GET di controllo:\n" .
"curl --location --request GET '{$apiBaseUrl}CommessaWeb({$commessaId})?\$expand=CommesseCustomFields(\$expand=CustomField)' \\\n" .
"--header 'Authorization: Bearer ••••••'\n\n" .
"RESPONSE:\n" . json_encode($commessaAfterPatch, JSON_PRETTY_PRINT);
// Salva log unico
file_put_contents($logFile, $logContent);
// 🔹 Output a schermo
echo json_encode([
"success" => true,
"message" => "PATCH eseguito su commessa {$commessaId} con dati da iddatadb {$iddatadb}",
"commessaAfterPatch" => $commessaAfterPatch,
"totalCustomFieldsUpdated" => count($commessaCustomFields),
"fieldValues" => $fieldValues,
"logFile" => $logFile
]);
} catch (Exception $e) {
error_log("Patch Error: " . $e->getMessage() . "\nTrace: " . $e->getTraceAsString());
echo json_encode([
"success" => false,
"message" => "Patch failed: " . $e->getMessage(),
"logFile" => $logFile ?? 'Nessun log generato'
]);
}
File diff suppressed because one or more lines are too long
+25 -1
View File
@@ -48,7 +48,7 @@ $routines = $stmt->fetchAll(PDO::FETCH_ASSOC);
<div class="page-content"> <div class="page-content">
<div class="card mb-4"> <div class="card mb-4">
<div class="card-header"> <div class="card-header">
<h5 class="mb-0">UpdateXLS Template</h5> <h5 class="mb-0">Update XLS Template</h5>
</div> </div>
<div class="card-body"> <div class="card-body">
<p class="mb-2">Edit the following form in order to update the selected import XLS template</p> <p class="mb-2">Edit the following form in order to update the selected import XLS template</p>
@@ -99,6 +99,30 @@ $routines = $stmt->fetchAll(PDO::FETCH_ASSOC);
<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>
<div class="mb-3">
<label class="form-label">Button Size</label>
<select name="button_size" class="form-control">
<option value="small" <?php echo ($template['button_size'] ?? 'medium') === 'small' ? 'selected' : ''; ?>>Small</option>
<option value="medium" <?php echo ($template['button_size'] ?? 'medium') === 'medium' ? 'selected' : ''; ?>>Medium</option>
<option value="large" <?php echo ($template['button_size'] ?? 'medium') === 'large' ? 'selected' : ''; ?>>Large</option>
</select>
</div>
<div class="mb-3">
<label class="form-label">Button Background Color</label>
<input type="color" name="button_bg_color" class="form-control" value="<?php echo htmlspecialchars($template['button_bg_color'] ?? '#007bff'); ?>">
</div>
<div class="mb-3">
<label class="form-label">Button Text Color</label>
<input type="color" name="button_text_color" class="form-control" value="<?php echo htmlspecialchars($template['button_text_color'] ?? '#ffffff'); ?>">
</div>
<div class="mb-3">
<label class="form-label">Button Label</label>
<input type="text" name="button_label" class="form-control" value="<?php echo htmlspecialchars($template['button_label'] ?? 'Click Me'); ?>">
</div>
<div class="mb-3"> <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>
+138 -19
View File
@@ -7,6 +7,26 @@ $pdo = $dbHandler->getConnection();
header("Content-Type: application/json"); header("Content-Type: application/json");
// 🔹 Configura directory log (creala se non esiste)
$logDir = __DIR__ . '/logs/api/';
if (!is_dir($logDir)) {
mkdir($logDir, 0755, true);
}
// 🔹 Base URL API
$apiBaseUrl = 'https://93.43.5.102/limsapi/api/odata/';
// 🔹 Funzione per validare e convertire date
function validateDate($value)
{
// Prova a validare come data (accetta formati comuni)
$date = DateTime::createFromFormat('Y-m-d', $value) ?: DateTime::createFromFormat('Y-m-d H:i:s', $value);
if ($date) {
return $date->format('Y-m-d\TH:i:sP'); // Formato ISO 8601
}
return null; // Imposta null se non è una data valida
}
try { try {
$iddatadb = $_POST['iddatadb'] ?? null; $iddatadb = $_POST['iddatadb'] ?? null;
if (!$iddatadb) { if (!$iddatadb) {
@@ -56,13 +76,20 @@ try {
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC); $rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
$fieldValues = []; $fieldValues = [];
$valueMap = [];
foreach ($rows as $row) { foreach ($rows as $row) {
$fieldValues[] = [ $fieldValues[] = [
"IdCommesseCustomFields" => (int) $row['field_id'], "IdCommesseCustomFields" => (int) $row['field_id'],
"Valore" => $row['field_value'] "Valore" => $row['field_value'],
"FieldLabel" => $row['field_label']
]; ];
$valueMap[(int) $row['field_id']] = $row['field_value'];
} }
// Logga i fieldValues in error_log
$logFieldValues = "FieldValues dal DB (iddatadb={$iddatadb}):\n" . json_encode($fieldValues, JSON_PRETTY_PRINT);
error_log($logFieldValues);
// 🔹 Initialize API client // 🔹 Initialize API client
$api = VisualLimsApiClient::getInstance(); $api = VisualLimsApiClient::getInstance();
@@ -73,14 +100,29 @@ try {
"Richiedente" => "Test Web Import", "Richiedente" => "Test Web Import",
"Descrizione" => "TEST CommessaWeb", "Descrizione" => "TEST CommessaWeb",
]; ];
// Costruisci log curl-like per STEP 5
$jsonPayload = json_encode($commessaWebPayload, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
$logContentStep5 = "curl --location --request POST '{$apiBaseUrl}CommessaWeb' \\\n" .
"--header 'Content-Type: application/json' \\\n" .
"--header 'Authorization: Bearer ••••••' \\\n" .
"--data '{$jsonPayload}'";
$commessaWeb = $api->post("CommessaWeb", $commessaWebPayload); $commessaWeb = $api->post("CommessaWeb", $commessaWebPayload);
$logContentStep5 .= "\n\nRESPONSE:\n" . json_encode($commessaWeb, JSON_PRETTY_PRINT);
// Salva log
$logFileStep5 = $logDir . "commessa_create_step5_" . $iddatadb . "_" . time() . ".txt";
file_put_contents($logFileStep5, $logContentStep5);
$commessaId = $commessaWeb["IdCommessa"]; $commessaId = $commessaWeb["IdCommessa"];
// Estraiamo il numero della commessa usando CodiceCommessa
$commessaWebCode = substr($commessaWeb["CodiceCommessa"] ?? "TEST CommessaWeb", 0, 30); // Limite a 30 caratteri $commessaWebCode = substr($commessaWeb["CodiceCommessa"] ?? "TEST CommessaWeb", 0, 30); // Limite a 30 caratteri
// 🔹 STEP 6: Create Campioni (Samples) for each part // 🔹 STEP 6: Create Campioni (Samples) for each part
$campioni = []; $campioni = [];
$logContentStep6 = "";
foreach ($parts as $index => $part) { foreach ($parts as $index => $part) {
$matriceId = (int) ($part["idmatrice"] ?? 0); $matriceId = (int) ($part["idmatrice"] ?? 0);
@@ -96,8 +138,18 @@ try {
"NoteWeb" => $part["part_description"] ?? "" "NoteWeb" => $part["part_description"] ?? ""
]; ];
// Costruisci curl-like per questo campione
$jsonPayload = json_encode($campionePayload, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
$logContentStep6 .= "CAMPIONE #{$index}\n" .
"curl --location --request POST '{$apiBaseUrl}Campione' \\\n" .
"--header 'Content-Type: application/json' \\\n" .
"--header 'Authorization: Bearer ••••••' \\\n" .
"--data '{$jsonPayload}'\n\n";
$campione = $api->post("Campione", $campionePayload); $campione = $api->post("Campione", $campionePayload);
$logContentStep6 .= "RESPONSE:\n" . json_encode($campione, JSON_PRETTY_PRINT) . "\n\n---\n";
$campione["PartNumber"] = $part["part_number"] ?? ""; $campione["PartNumber"] = $part["part_number"] ?? "";
$campione["Material"] = $part["material"] ?? ""; $campione["Material"] = $part["material"] ?? "";
$campione["Color"] = $part["color"] ?? ""; $campione["Color"] = $part["color"] ?? "";
@@ -106,25 +158,58 @@ try {
$campioni[] = $campione; $campioni[] = $campione;
} }
// Salva log per STEP 6
$logFileStep6 = $logDir . "commessa_{$commessaId}_campioni_step6_" . time() . ".txt";
file_put_contents($logFileStep6, $logContentStep6);
// 🔹 STEP 7: Update Custom Fields for CommessaWeb // 🔹 STEP 7: Update Custom Fields for CommessaWeb
if (!empty($fieldValues)) { if (!empty($fieldValues)) {
$commessaWithFields = $api->get("CommessaWeb(" . $commessaId . ")?\$expand=CommesseCustomFields"); // GET con espansione per CustomField
$expand = "CommesseCustomFields(\$expand=CustomField)";
$commessaWithFields = $api->get("CommessaWeb(" . $commessaId . ")?\$expand=" . $expand);
// Logga il GET
$logContentGet = "curl --location --request GET '{$apiBaseUrl}CommessaWeb({$commessaId})?\$expand=CommesseCustomFields(\$expand=CustomField)' \\\n" .
"--header 'Authorization: Bearer ••••••'\n\n" .
"RESPONSE:\n" . json_encode($commessaWithFields, JSON_PRETTY_PRINT);
$logFileGet = $logDir . "commessa_{$commessaId}_get_step7_" . time() . ".txt";
file_put_contents($logFileGet, $logContentGet);
// Prepara payload PATCH
$commessaCustomFields = []; $commessaCustomFields = [];
foreach ($commessaWithFields["CommesseCustomFields"] as $customField) { foreach ($commessaWithFields["CommesseCustomFields"] as $customField) {
foreach ($fieldValues as $fieldValue) { $definitionId = (int) ($customField["CustomField"]["IdCustomField"] ?? 0);
if ($customField["IdCommesseCustomFields"] == $fieldValue["IdCommesseCustomFields"]) { $fieldId = (int) $customField["IdCommesseCustomFields"];
$commessaCustomFields[] = [ $currentValue = $customField["Valore"] ?? '';
"IdCommesseCustomFields" => $customField["IdCommesseCustomFields"], $fieldType = $customField["CustomField"]["Tipo"] ?? '';
"Valore" => $fieldValue["Valore"] $newValue = isset($valueMap[$definitionId]) ? $valueMap[$definitionId] : $currentValue;
];
break; // Valida se il campo è di tipo Data
} if ($fieldType === 'Data' && $newValue !== $currentValue) {
$newValue = validateDate($newValue);
} }
$commessaCustomFields[] = [
"IdCommesseCustomFields" => $fieldId,
"Valore" => $newValue
];
} }
if (!empty($commessaCustomFields)) { if (!empty($commessaCustomFields)) {
$updatePayload = ["CommesseCustomFields" => $commessaCustomFields]; $updatePayload = ["CommesseCustomFields" => $commessaCustomFields];
$api->patch("CommessaWeb({$commessaId})", $updatePayload);
// Logga payload e response
$jsonPayload = json_encode($updatePayload, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
$logContentStep7 = "curl --location --request PATCH '{$apiBaseUrl}CommessaWeb({$commessaId})' \\\n" .
"--header 'Content-Type: application/json' \\\n" .
"--header 'Authorization: Bearer ••••••' \\\n" .
"--data '{$jsonPayload}'";
$patchResponse = $api->patch("CommessaWeb({$commessaId})", $updatePayload);
$logContentStep7 .= "\n\nRESPONSE:\n" . json_encode($patchResponse, JSON_PRETTY_PRINT);
$logFileStep7 = $logDir . "commessa_{$commessaId}_update_step7_" . time() . ".txt";
file_put_contents($logFileStep7, $logContentStep7);
} }
} }
@@ -140,18 +225,40 @@ try {
'iddatadb' => $iddatadb 'iddatadb' => $iddatadb
]); ]);
// 🔹 STEP 9: Send CommessaWeb to laboratory // 🔹 STEP 9: Send CommessaWeb to laboratory (commentato come richiesto)
/*
$sendResult = $api->post("CommessaWeb({$commessaId})/InviaCommessa", []); $sendResult = $api->post("CommessaWeb({$commessaId})/InviaCommessa", []);
// 🔹 STEP 10: Prepare final response // Logga il POST
$logContentStep9 = "curl --location --request POST '{$apiBaseUrl}CommessaWeb({$commessaId})/InviaCommessa' \\\n" .
"--header 'Content-Type: application/json' \\\n" .
"--header 'Authorization: Bearer ••••••' \\\n" .
"--data '{}'\n\n" .
"RESPONSE:\n" . json_encode($sendResult, JSON_PRETTY_PRINT);
$logFileStep9 = $logDir . "commessa_{$commessaId}_send_step9_" . time() . ".txt";
file_put_contents($logFileStep9, $logContentStep9);
*/
// 🔹 STEP 10: GET di controllo post-PATCH
$expand = "CommesseCustomFields(\$expand=CustomField)";
$commessaAfterPatch = $api->get("CommessaWeb(" . $commessaId . ")?\$expand=" . $expand);
// Logga il GET di controllo
$logContentStep10 = "curl --location --request GET '{$apiBaseUrl}CommessaWeb({$commessaId})?\$expand=CommesseCustomFields(\$expand=CustomField)' \\\n" .
"--header 'Authorization: Bearer ••••••'\n\n" .
"RESPONSE:\n" . json_encode($commessaAfterPatch, JSON_PRETTY_PRINT);
$logFileStep10 = $logDir . "commessa_{$commessaId}_get_step10_" . time() . ".txt";
file_put_contents($logFileStep10, $logContentStep10);
// 🔹 STEP 11: Prepare final response
$finalCommessa = [ $finalCommessa = [
"Cliente" => $clienteId, "Cliente" => $clienteId,
"SchemaCustomField" => $schemaId, "SchemaCustomField" => $schemaId,
"Richiedente" => $commessaWeb["Richiedente"] ?? "Web Import", "Richiedente" => $commessaWeb["Richiedente"] ?? "Web Import",
"Descrizione" => $commessaWeb["Descrizione"] ?? "", "Descrizione" => $commessaWeb["Descrizione"] ?? "",
"CommesseCustomFields" => $fieldValues, "CommesseCustomFields" => $commessaAfterPatch["CommesseCustomFields"] ?? [],
"Campioni" => $campioni, "Campioni" => $campioni,
"Inviata" => 1 "Inviata" => 0 // Non inviato, come richiesto
]; ];
echo json_encode([ echo json_encode([
@@ -159,14 +266,26 @@ try {
"commessaWeb" => $finalCommessa, "commessaWeb" => $finalCommessa,
"commessaWebApiResponse" => $commessaWeb, // Incluso per debug "commessaWebApiResponse" => $commessaWeb, // Incluso per debug
"totalCampioni" => count($campioni), "totalCampioni" => count($campioni),
"totalCustomFields" => count($fieldValues), "totalCustomFields" => count($commessaAfterPatch["CommesseCustomFields"] ?? []),
"message" => "Export successful" "message" => "Export successful",
"logFiles" => [
"step5_create" => $logFileStep5,
"step6_campioni" => $logFileStep6,
"step7_patch" => $logFileStep7,
"step10_get" => $logFileStep10
]
]); ]);
} catch (Exception $e) { } catch (Exception $e) {
error_log("LIMS Export Error: " . $e->getMessage() . "\nTrace: " . $e->getTraceAsString()); error_log("LIMS Export Error: " . $e->getMessage() . "\nTrace: " . $e->getTraceAsString());
echo json_encode([ echo json_encode([
"success" => false, "success" => false,
"message" => "Export failed: " . $e->getMessage() "message" => "Export failed: " . $e->getMessage(),
"logFiles" => [
"step5_create" => $logFileStep5 ?? null,
"step6_campioni" => $logFileStep6 ?? null,
"step7_patch" => $logFileStep7 ?? null,
"step10_get" => $logFileStep10 ?? null
]
]); ]);
} }
+1 -1
View File
@@ -9,7 +9,7 @@ error_reporting(E_ALL);
try { try {
$api = VisualLimsApiClient::getInstance(); $api = VisualLimsApiClient::getInstance();
$rapporto_id = 515081; $rapporto_id = 533329;
// Costruzione manuale dell'endpoint con espansione annidata // Costruzione manuale dell'endpoint con espansione annidata
$endpoint = "Rapporto($rapporto_id)?\$expand=CampioniDatiRapporto(\$expand=AnalisiDatiRapporto,CustomFieldsDatiRapporto)"; $endpoint = "Rapporto($rapporto_id)?\$expand=CampioniDatiRapporto(\$expand=AnalisiDatiRapporto,CustomFieldsDatiRapporto)";
+34 -29
View File
@@ -662,6 +662,11 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
} else { } else {
echo "<div class='grid-cell' style='flex: 0 0 150px;'></div>"; echo "<div class='grid-cell' style='flex: 0 0 150px;'></div>";
} }
// Status (subito dopo main_field)
$fixedColumnsReduced = ['status'];
foreach ($fixedColumnsReduced as $col) {
echo "<div class='grid-cell' style='flex: 0 0 150px;'></div>";
}
// Campi automatici (escluso main_field) // Campi automatici (escluso main_field)
$autoIndex = ($mainFieldMapping && !$mainFieldMapping['is_manual']) ? 1 : 0; $autoIndex = ($mainFieldMapping && !$mainFieldMapping['is_manual']) ? 1 : 0;
foreach ($allMappings as $mapping) { foreach ($allMappings as $mapping) {
@@ -712,11 +717,7 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
$manualIndex++; $manualIndex++;
} }
} }
// Colonne status, Import Reference Code, filename_import // Colonne Import Reference Code, filename_import
$fixedColumnsReduced = ['status'];
foreach ($fixedColumnsReduced as $col) {
echo "<div class='grid-cell' style='flex: 0 0 150px;'></div>";
}
echo "<div class='grid-cell' style='flex: 0 0 150px;'></div>"; // Import Reference Code echo "<div class='grid-cell' style='flex: 0 0 150px;'></div>"; // Import Reference Code
echo "<div class='grid-cell' style='flex: 0 0 150px;'></div>"; // filename_import echo "<div class='grid-cell' style='flex: 0 0 150px;'></div>"; // filename_import
// AWB Number e Tracking Info // AWB Number e Tracking Info
@@ -734,6 +735,12 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
echo "<div class='grid-header' data-index='$headerIndex' style='flex: 0 0 150px; position: relative;'>" . htmlspecialchars($mainFieldMapping['field_label']) . "<div class='resizer'></div></div>"; echo "<div class='grid-header' data-index='$headerIndex' style='flex: 0 0 150px; position: relative;'>" . htmlspecialchars($mainFieldMapping['field_label']) . "<div class='resizer'></div></div>";
$headerIndex++; $headerIndex++;
} }
// Header per status (subito dopo main_field)
foreach ($fixedColumnsReduced as $col) {
$displayName = $slugMapping[$col] ?? $col;
echo "<div class='grid-header' data-index='$headerIndex' style='flex: 0 0 150px; position: relative;'>$displayName<div class='resizer'></div></div>";
$headerIndex++;
}
// Header per campi automatici (escluso main_field) // Header per campi automatici (escluso main_field)
foreach ($allMappings as $mapping) { foreach ($allMappings as $mapping) {
if (!$mapping['is_manual'] && $mapping['main_field'] != 1) { if (!$mapping['is_manual'] && $mapping['main_field'] != 1) {
@@ -748,12 +755,7 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
$headerIndex++; $headerIndex++;
} }
} }
// Header per status, Import Reference Code, filename_import // Header per Import Reference Code, filename_import
foreach ($fixedColumnsReduced as $col) {
$displayName = $slugMapping[$col] ?? $col;
echo "<div class='grid-header' data-index='$headerIndex' style='flex: 0 0 150px; position: relative;'>$displayName<div class='resizer'></div></div>";
$headerIndex++;
}
echo "<div class='grid-header' data-index='$headerIndex' style='flex: 0 0 150px; position: relative;'>Import Reference Code<div class='resizer'></div></div>"; echo "<div class='grid-header' data-index='$headerIndex' style='flex: 0 0 150px; position: relative;'>Import Reference Code<div class='resizer'></div></div>";
$headerIndex++; $headerIndex++;
echo "<div class='grid-header' data-index='$headerIndex' style='flex: 0 0 150px; position: relative;'>File<div class='resizer'></div></div>"; echo "<div class='grid-header' data-index='$headerIndex' style='flex: 0 0 150px; position: relative;'>File<div class='resizer'></div></div>";
@@ -770,13 +772,11 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
<div style="display: flex; gap: 5px; justify-content: center;"> <div style="display: flex; gap: 5px; justify-content: center;">
<?php if (!$is_readonly): ?> <?php if (!$is_readonly): ?>
<button type="button" class="save-btn action-btn" data-row="<?= $index ?>" style="background: #28a745; color: white; border: none; padding: 8px 12px; border-radius: 5px; cursor: pointer; flex: 1;"><i class="fas fa-save"></i></button> <button type="button" class="save-btn action-btn" data-row="<?= $index ?>" style="background: #28a745; color: white; border: none; padding: 8px 12px; border-radius: 5px; cursor: pointer; flex: 1;"><i class="fas fa-save"></i></button>
<button type="button" class="photos-btn action-btn" data-row="<?= $index ?>" data-iddatadb="<?= $row['iddatadb'] ?>" style="background: #007bff; color: white; border: none; padding: 8px 12px; border-radius: 5px; cursor: pointer; flex: 1;"><i class="fas fa-camera"></i></button>
<button type="button" class="parts-btn action-btn" data-row="<?= $index ?>" data-iddatadb="<?= $row['iddatadb'] ?>" style="background: #ffc107; color: white; border: none; padding: 8px 12px; border-radius: 5px; cursor: pointer; flex: 1;"><i class="fas fa-puzzle-piece"></i></button>
<?php else: ?> <?php else: ?>
<button type="button" class="save-btn action-btn" data-row="<?= $index ?>" style="background: #ccc; color: white; border: none; padding: 8px 12px; border-radius: 5px; cursor: not-allowed; flex: 1;" disabled><i class="fas fa-save"></i></button> <button type="button" class="save-btn action-btn" data-row="<?= $index ?>" style="background: #ccc; color: white; border: none; padding: 8px 12px; border-radius: 5px; cursor: not-allowed; flex: 1;" disabled><i class="fas fa-save"></i></button>
<button type="button" class="photos-btn action-btn" data-row="<?= $index ?>" data-iddatadb="<?= $row['iddatadb'] ?>" style="background: #ccc; color: white; border: none; padding: 8px 12px; border-radius: 5px; cursor: not-allowed; flex: 1;" disabled><i class="fas fa-camera"></i></button>
<button type="button" class="parts-btn action-btn" data-row="<?= $index ?>" data-iddatadb="<?= $row['iddatadb'] ?>" style="background: #ccc; color: white; border: none; padding: 8px 12px; border-radius: 5px; cursor: not-allowed; flex: 1;" disabled><i class="fas fa-puzzle-piece"></i></button>
<?php endif; ?> <?php endif; ?>
<button type="button" class="photos-btn action-btn" data-row="<?= $index ?>" data-iddatadb="<?= $row['iddatadb'] ?>" style="background: #007bff; color: white; border: none; padding: 8px 12px; border-radius: 5px; cursor: pointer; flex: 1;"><i class="fas fa-camera"></i></button>
<button type="button" class="parts-btn action-btn" data-row="<?= $index ?>" data-iddatadb="<?= $row['iddatadb'] ?>" style="background: #ffc107; color: white; border: none; padding: 8px 12px; border-radius: 5px; cursor: pointer; flex: 1;"><i class="fas fa-puzzle-piece"></i></button>
</div> </div>
</div> </div>
<?php <?php
@@ -806,6 +806,25 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
echo "</div>"; echo "</div>";
$cellIndex++; $cellIndex++;
} }
// Status (subito dopo main_field)
$fixedColumnsReduced = ['status'];
foreach ($fixedColumnsReduced as $col) {
$value = $row[$col] ?? '';
echo "<div class='grid-cell editable-cell' data-col='$col' data-row='$index' data-index='$cellIndex' style='flex: 0 0 150px;'>";
if ($col === 'status') {
$badgeClass = $value === 'i' ? 'status-i' : ($value === 'P' ? 'status-P' : 'status-l');
$badgeText = $value === 'i' ? 'Imported' : ($value === 'P' ? 'Progress' : 'LIMS');
// Aggiungi il numero di commessaweb se lo status è 'l'
if ($value === 'l') {
$commessaWeb = isset($row['commessaweb']) ? htmlspecialchars($row['commessaweb']) : '';
$badgeText .= " ($commessaWeb)";
}
echo "<span class='status-badge $badgeClass'>" . htmlspecialchars($badgeText) . "</span>";
echo "<input type='hidden' name='rows[$index][$col]' value='" . htmlspecialchars($value ?? 'i') . "'>";
}
echo "</div>";
$cellIndex++;
}
// Campi automatici (escluso main_field) // Campi automatici (escluso main_field)
$autoIndex = ($mainFieldMapping && !$mainFieldMapping['is_manual']) ? 1 : 0; $autoIndex = ($mainFieldMapping && !$mainFieldMapping['is_manual']) ? 1 : 0;
foreach ($allMappings as $mapping) { foreach ($allMappings as $mapping) {
@@ -863,20 +882,6 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
$manualIndex++; $manualIndex++;
} }
} }
// Colonna status
$fixedColumnsReduced = ['status'];
foreach ($fixedColumnsReduced as $col) {
$value = $row[$col] ?? '';
echo "<div class='grid-cell editable-cell' data-col='$col' data-row='$index' data-index='$cellIndex' style='flex: 0 0 150px;'>";
if ($col === 'status') {
$badgeClass = $value === 'i' ? 'status-i' : ($value === 'P' ? 'status-P' : 'status-l');
$badgeText = $value === 'i' ? 'Imported' : ($value === 'P' ? 'Progress' : 'LIMS');
echo "<span class='status-badge $badgeClass'>" . htmlspecialchars($badgeText) . "</span>";
echo "<input type='hidden' name='rows[$index][$col]' value='" . htmlspecialchars($value ?? 'i') . "'>";
}
echo "</div>";
$cellIndex++;
}
// Colonne Import Reference Code e filename_import // Colonne Import Reference Code e filename_import
echo "<div class='grid-cell' data-col='importreferencecode' data-row='$index' data-index='$cellIndex' style='flex: 0 0 150px;'>"; echo "<div class='grid-cell' data-col='importreferencecode' data-row='$index' data-index='$cellIndex' style='flex: 0 0 150px;'>";
echo "<span>" . htmlspecialchars($row['importreferencecode']) . "</span>"; echo "<span>" . htmlspecialchars($row['importreferencecode']) . "</span>";
+125 -76
View File
@@ -1,17 +1,4 @@
<?php <?php
// Abilita errori per debug
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
ini_set('log_errors', 1);
ini_set('error_log', __DIR__ . '/import_debug.log');
if (!file_exists(__DIR__ . '/import_debug.log')) {
file_put_contents(__DIR__ . '/import_debug.log', "Inizio importazione alle " . date('Y-m-d H:i:s') . "\n", FILE_APPEND);
}
// Log iniziale
error_log("Inizio importazione alle " . date('Y-m-d H:i:s'));
include('include/headscript.php'); include('include/headscript.php');
if ($_SERVER['REQUEST_METHOD'] !== 'POST' || !isset($_POST['template_id']) || !isset($_POST['selected_rows']) || !isset($_POST['filename'])) { if ($_SERVER['REQUEST_METHOD'] !== 'POST' || !isset($_POST['template_id']) || !isset($_POST['selected_rows']) || !isset($_POST['filename'])) {
@@ -25,11 +12,6 @@ $columns = json_decode($_POST['columns'], true) ?? $_SESSION['columns'];
$rows = json_decode($_POST['rows'], true) ?? $_SESSION['rows']; $rows = json_decode($_POST['rows'], true) ?? $_SESSION['rows'];
$newFilename = htmlspecialchars($_POST['filename']) ?? $_SESSION['filename']; $newFilename = htmlspecialchars($_POST['filename']) ?? $_SESSION['filename'];
// Log dei dati ricevuti
error_log("Received Data - Template ID: $template_id, Selected Rows: " . json_encode($selected_rows));
error_log("Columns: " . json_encode($columns));
error_log("Rows: " . json_encode($rows));
// Recupera l'ID dell'utente loggato // Recupera l'ID dell'utente loggato
$user_id = $iduserlogin ?? 1; $user_id = $iduserlogin ?? 1;
@@ -39,8 +21,8 @@ $pdo = $db->getConnection();
// Genera un UUID univoco per importreferencecode // Genera un UUID univoco per importreferencecode
$importReferenceCode = date('YmdHis') . '-' . uniqid(); $importReferenceCode = date('YmdHis') . '-' . uniqid();
// Recupera tutti i mapping dal template // Recupera tutti i mapping dal template, includendo is_visible_import
$stmt = $pdo->prepare("SELECT id, excel_column, data_type, is_required, manual_default, is_manual, field_label, field_id, main_field FROM template_mapping WHERE template_id = ?"); $stmt = $pdo->prepare("SELECT id, excel_column, data_type, is_required, manual_default, is_manual, field_label, field_id, main_field, is_visible_import FROM template_mapping WHERE template_id = ?");
$stmt->execute([$template_id]); $stmt->execute([$template_id]);
$allMappings = $stmt->fetchAll(PDO::FETCH_ASSOC); $allMappings = $stmt->fetchAll(PDO::FETCH_ASSOC);
@@ -52,7 +34,7 @@ if (empty($allMappings)) {
// Trova il campo main_field // Trova il campo main_field
$mainFieldMapping = null; $mainFieldMapping = null;
foreach ($allMappings as $mapping) { foreach ($allMappings as $mapping) {
if ($mapping['main_field'] == 1) { if ($mapping['main_field'] == 1 && $mapping['is_visible_import'] == 1) {
$mainFieldMapping = $mapping; $mainFieldMapping = $mapping;
break; break;
} }
@@ -97,6 +79,7 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
<link rel="icon" href="assets/images/favicon-32x32.png" type="image/png" /> <link rel="icon" href="assets/images/favicon-32x32.png" type="image/png" />
<?php include('cssinclude.php'); ?> <?php include('cssinclude.php'); ?>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css" integrity="sha512-DTOQO9RWCH3ppGqcWaEA1BIZOC6xxalwEsw9c2QQeAIftl+Vegovlnee1c9QX4TctnWMn13TZye+giMm8e2Lw==" crossorigin="anonymous" referrerpolicy="no-referrer" /> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css" integrity="sha512-DTOQO9RWCH3ppGqcWaEA1BIZOC6xxalwEsw9c2QQeAIftl+Vegovlnee1c9QX4TctnWMn13TZye+giMm8e2Lw==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/flatpickr@4.6.13/dist/flatpickr.min.css">
<style> <style>
.cell-changed { .cell-changed {
background-color: #fff3b0 !important; background-color: #fff3b0 !important;
@@ -415,6 +398,17 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
#exportResponseModal .modal-backdrop { #exportResponseModal .modal-backdrop {
z-index: 1299 !important; z-index: 1299 !important;
} }
.add-part-btn {
padding: 2px 5px;
font-size: 10px;
line-height: 1;
border-radius: 3px;
}
.flatpickr-input {
cursor: pointer;
}
</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>
@@ -453,7 +447,7 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
<div class="grid-cell" style="flex: 0 0 150px;"> <div class="grid-cell" style="flex: 0 0 150px;">
<?php <?php
$fieldValue = $mainFieldMapping['manual_default'] ?? ''; $fieldValue = $mainFieldMapping['manual_default'] ?? '';
if ($mainFieldMapping['data_type'] === 'DATE' && $mainFieldMapping['manual_default'] === 'today') { if ($mainFieldMapping['data_type'] === 'Data' && $mainFieldMapping['manual_default'] === 'today') {
$fieldValue = date('Y-m-d'); $fieldValue = date('Y-m-d');
} }
$inputClass = $mainFieldMapping['is_manual'] ? 'manual-input' : 'auto-input'; $inputClass = $mainFieldMapping['is_manual'] ? 'manual-input' : 'auto-input';
@@ -463,8 +457,8 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
echo "<option value=''>Seleziona...</option>"; echo "<option value=''>Seleziona...</option>";
echo "</select>"; echo "</select>";
echo "<button type='button' class='propagate-btn' data-column='main_field'><i class='fas fa-arrow-down'></i></button>"; echo "<button type='button' class='propagate-btn' data-column='main_field'><i class='fas fa-arrow-down'></i></button>";
} elseif ($mainFieldMapping['data_type'] === 'DATE') { } elseif ($mainFieldMapping['data_type'] === 'Data') {
echo "<input type='date' class='custom-field $inputClass' data-column='main_field' value='" . htmlspecialchars($fieldValue) . "' " . ($mainFieldMapping['is_required'] ? 'required' : '') . ">"; echo "<input type='text' class='custom-field date-picker $inputClass' data-column='main_field' value='" . htmlspecialchars($fieldValue) . "' " . ($mainFieldMapping['is_required'] ? 'required' : '') . ">";
echo "<button type='button' class='propagate-btn' data-column='main_field'><i class='fas fa-arrow-down'></i></button>"; echo "<button type='button' class='propagate-btn' data-column='main_field'><i class='fas fa-arrow-down'></i></button>";
} elseif ($mainFieldMapping['data_type'] === 'INT') { } elseif ($mainFieldMapping['data_type'] === 'INT') {
echo "<input type='number' class='custom-field $inputClass' data-column='main_field' value='" . htmlspecialchars($fieldValue) . "' " . ($mainFieldMapping['is_required'] ? 'required' : '') . ">"; echo "<input type='number' class='custom-field $inputClass' data-column='main_field' value='" . htmlspecialchars($fieldValue) . "' " . ($mainFieldMapping['is_required'] ? 'required' : '') . ">";
@@ -480,7 +474,7 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
<?php <?php
$autoIndex = 0; $autoIndex = 0;
foreach ($allMappings as $mapping) { foreach ($allMappings as $mapping) {
if (!$mapping['is_manual'] && $mapping['main_field'] != 1) { if (!$mapping['is_manual'] && $mapping['main_field'] != 1 && $mapping['is_visible_import'] == 1) {
$inputClass = 'auto-input'; $inputClass = 'auto-input';
if ($mapping['is_required']) $inputClass .= ' required-input'; if ($mapping['is_required']) $inputClass .= ' required-input';
if ($mapping['data_type'] === 'SceltaMultipla') { if ($mapping['data_type'] === 'SceltaMultipla') {
@@ -498,20 +492,20 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
} }
$manualIndex = 0; $manualIndex = 0;
foreach ($allMappings as $mapping) { foreach ($allMappings as $mapping) {
if ($mapping['is_manual'] && $mapping['main_field'] != 1) { if ($mapping['is_manual'] && $mapping['main_field'] != 1 && $mapping['is_visible_import'] == 1) {
$fieldValue = $mapping['manual_default'] ?? ''; $fieldValue = $mapping['manual_default'] ?? '';
if ($mapping['data_type'] === 'DATE' && $mapping['manual_default'] === 'today') { if ($mapping['data_type'] === 'Data' && $mapping['manual_default'] === 'today') {
$fieldValue = date('Y-m-d'); $fieldValue = date('Y-m-d');
} }
$inputClass = 'manual-input'; $inputClass = 'manual-input';
if ($mapping['is_required']) $inputClass .= ' required-input'; if ($mapping['is_required']) $inputClass .= ' required-input';
echo "<div class='grid-cell' style='flex: 0 0 150px;'>"; echo "<div class='grid-cell' style='flex: 0 0 150px;'>";
if ($mapping['data_type'] === 'SceltaMultipla') { if ($mapping['data_type'] === 'SceltaMultipla') {
echo "<select class='custom-field dropdown-select $inputClass' data-column='manual_$manualIndex' data-field-id='{$mapping['field_id']}' data-selected-value='" . htmlspecialchars($fieldValue) . "' " . ($mainFieldMapping['is_required'] ? 'required' : '') . ">"; echo "<select class='custom-field dropdown-select $inputClass' data-column='manual_$manualIndex' data-field-id='{$mapping['field_id']}' data-selected-value='" . htmlspecialchars($fieldValue) . "' " . ($mapping['is_required'] ? 'required' : '') . ">";
echo "<option value=''>Seleziona...</option>"; echo "<option value=''>Seleziona...</option>";
echo "</select>"; echo "</select>";
} elseif ($mapping['data_type'] === 'DATE') { } elseif ($mapping['data_type'] === 'Data') {
echo "<input type='date' class='custom-field $inputClass' data-column='manual_$manualIndex' value='" . htmlspecialchars($fieldValue) . "' " . ($mapping['is_required'] ? 'required' : '') . ">"; echo "<input type='text' class='custom-field date-picker $inputClass' data-column='manual_$manualIndex' value='" . htmlspecialchars($fieldValue) . "' " . ($mapping['is_required'] ? 'required' : '') . ">";
} elseif ($mapping['data_type'] === 'INT') { } elseif ($mapping['data_type'] === 'INT') {
echo "<input type='number' class='custom-field $inputClass' data-column='manual_$manualIndex' value='" . htmlspecialchars($fieldValue) . "' " . ($mapping['is_required'] ? 'required' : '') . ">"; echo "<input type='number' class='custom-field $inputClass' data-column='manual_$manualIndex' value='" . htmlspecialchars($fieldValue) . "' " . ($mapping['is_required'] ? 'required' : '') . ">";
} else { } else {
@@ -522,6 +516,8 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
$manualIndex++; $manualIndex++;
} }
} }
// Aggiunta per Tested Component (senza propagate)
echo "<div class='grid-cell' style='flex: 0 0 150px;'></div>";
echo "<div class='grid-cell' style='flex: 0 0 200px;'></div>"; echo "<div class='grid-cell' style='flex: 0 0 200px;'></div>";
echo "<div class='grid-cell' style='flex: 0 0 250px;'></div>"; echo "<div class='grid-cell' style='flex: 0 0 250px;'></div>";
echo "<div class='grid-cell' style='flex: 0 0 150px;'></div>"; echo "<div class='grid-cell' style='flex: 0 0 150px;'></div>";
@@ -543,17 +539,20 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
<?php <?php
$headerIndex = $mainFieldMapping ? 3 : 2; $headerIndex = $mainFieldMapping ? 3 : 2;
foreach ($allMappings as $mapping) { foreach ($allMappings as $mapping) {
if (!$mapping['is_manual'] && $mapping['main_field'] != 1) { if (!$mapping['is_manual'] && $mapping['main_field'] != 1 && $mapping['is_visible_import'] == 1) {
echo "<div class='grid-header' data-index='$headerIndex' style='flex: 0 0 150px; position: relative;'>" . htmlspecialchars($mapping['field_label']) . "<div class='resizer'></div></div>"; echo "<div class='grid-header' data-index='$headerIndex' style='flex: 0 0 150px; position: relative;'>" . htmlspecialchars($mapping['field_label']) . "<div class='resizer'></div></div>";
$headerIndex++; $headerIndex++;
} }
} }
foreach ($allMappings as $mapping) { foreach ($allMappings as $mapping) {
if ($mapping['is_manual'] && $mapping['main_field'] != 1) { if ($mapping['is_manual'] && $mapping['main_field'] != 1 && $mapping['is_visible_import'] == 1) {
echo "<div class='grid-header' data-index='$headerIndex' style='flex: 0 0 150px; position: relative;'>" . htmlspecialchars($mapping['field_label']) . "<div class='resizer'></div></div>"; echo "<div class='grid-header' data-index='$headerIndex' style='flex: 0 0 150px; position: relative;'>" . htmlspecialchars($mapping['field_label']) . "<div class='resizer'></div></div>";
$headerIndex++; $headerIndex++;
} }
} }
// Aggiunta header per Tested Component
echo "<div class='grid-header' data-index='$headerIndex' style='flex: 0 0 150px; position: relative;'>Tested Component<div class='resizer'></div></div>";
$headerIndex++;
echo "<div class='grid-header' data-index='$headerIndex' style='flex: 0 0 200px; position: relative;'>AWB Number<div class='resizer'></div></div>"; echo "<div class='grid-header' data-index='$headerIndex' style='flex: 0 0 200px; position: relative;'>AWB Number<div class='resizer'></div></div>";
$headerIndex++; $headerIndex++;
echo "<div class='grid-header' data-index='$headerIndex' style='flex: 0 0 250px; position: relative;'>Tracking Info<div class='resizer'></div></div>"; echo "<div class='grid-header' data-index='$headerIndex' style='flex: 0 0 250px; position: relative;'>Tracking Info<div class='resizer'></div></div>";
@@ -583,7 +582,7 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
$detail = array_filter($manualDetails, fn($d) => $d['mapping_id'] == $mainFieldMapping['id'] && $d['datadb_id'] == $row['iddatadb']); $detail = array_filter($manualDetails, fn($d) => $d['mapping_id'] == $mainFieldMapping['id'] && $d['datadb_id'] == $row['iddatadb']);
$detail = reset($detail) ?: ['field_value' => $mainFieldMapping['manual_default']]; $detail = reset($detail) ?: ['field_value' => $mainFieldMapping['manual_default']];
$fieldValue = $detail['field_value'] ?? $mainFieldMapping['manual_default'] ?? ''; $fieldValue = $detail['field_value'] ?? $mainFieldMapping['manual_default'] ?? '';
if ($mainFieldMapping['data_type'] === 'DATE' && $mainFieldMapping['manual_default'] === 'today' && empty($fieldValue)) { if ($mainFieldMapping['data_type'] === 'Data' && $mainFieldMapping['manual_default'] === 'today' && empty($fieldValue)) {
$fieldValue = date('Y-m-d'); $fieldValue = date('Y-m-d');
} }
$requiredClass = ($mainFieldMapping['is_required'] && (is_null($fieldValue) || $fieldValue === '')) ? 'missing-required' : ''; $requiredClass = ($mainFieldMapping['is_required'] && (is_null($fieldValue) || $fieldValue === '')) ? 'missing-required' : '';
@@ -595,8 +594,8 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
<select name="rows[<?= $index ?>][details][<?= $mainFieldMapping['id'] ?>][field_value]" class="cell-input dropdown-select <?= $inputClass ?>" data-mapping-id="<?= $mainFieldMapping['id'] ?>" data-field-id="<?= $mainFieldMapping['field_id'] ?>" data-selected-value="<?= htmlspecialchars($fieldValue) ?>" <?= $mainFieldMapping['is_required'] ? 'required' : '' ?>> <select name="rows[<?= $index ?>][details][<?= $mainFieldMapping['id'] ?>][field_value]" class="cell-input dropdown-select <?= $inputClass ?>" data-mapping-id="<?= $mainFieldMapping['id'] ?>" data-field-id="<?= $mainFieldMapping['field_id'] ?>" data-selected-value="<?= htmlspecialchars($fieldValue) ?>" <?= $mainFieldMapping['is_required'] ? 'required' : '' ?>>
<option value="">Seleziona...</option> <option value="">Seleziona...</option>
</select> </select>
<?php elseif ($mainFieldMapping['data_type'] === 'DATE'): ?> <?php elseif ($mainFieldMapping['data_type'] === 'Data'): ?>
<input type="date" name="rows[<?= $index ?>][details][<?= $mainFieldMapping['id'] ?>][field_value]" value="<?= htmlspecialchars($fieldValue) ?>" class="cell-input <?= $inputClass ?>" <?= $mainFieldMapping['is_required'] ? 'required' : '' ?>> <input type="text" name="rows[<?= $index ?>][details][<?= $mainFieldMapping['id'] ?>][field_value]" value="<?= htmlspecialchars($fieldValue) ?>" class="cell-input date-picker <?= $inputClass ?>" <?= $mainFieldMapping['is_required'] ? 'required' : '' ?>>
<?php elseif ($mainFieldMapping['data_type'] === 'INT'): ?> <?php elseif ($mainFieldMapping['data_type'] === 'INT'): ?>
<input type="number" name="rows[<?= $index ?>][details][<?= $mainFieldMapping['id'] ?>][field_value]" value="<?= htmlspecialchars($fieldValue) ?>" class="cell-input <?= $inputClass ?>" <?= $mainFieldMapping['is_required'] ? 'required' : '' ?>> <input type="number" name="rows[<?= $index ?>][details][<?= $mainFieldMapping['id'] ?>][field_value]" value="<?= htmlspecialchars($fieldValue) ?>" class="cell-input <?= $inputClass ?>" <?= $mainFieldMapping['is_required'] ? 'required' : '' ?>>
<?php else: ?> <?php else: ?>
@@ -615,7 +614,7 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
$rowDetails = array_filter($manualDetails, fn($d) => $d['datadb_id'] == $row['iddatadb']); $rowDetails = array_filter($manualDetails, fn($d) => $d['datadb_id'] == $row['iddatadb']);
$autoIndex = 0; $autoIndex = 0;
foreach ($allMappings as $mapping) { foreach ($allMappings as $mapping) {
if (!$mapping['is_manual'] && $mapping['main_field'] != 1) { if (!$mapping['is_manual'] && $mapping['main_field'] != 1 && $mapping['is_visible_import'] == 1) {
$detail = array_filter($rowDetails, fn($d) => $d['mapping_id'] == $mapping['id']); $detail = array_filter($rowDetails, fn($d) => $d['mapping_id'] == $mapping['id']);
$detail = reset($detail) ?: ['field_value' => $mapping['manual_default']]; $detail = reset($detail) ?: ['field_value' => $mapping['manual_default']];
$fieldValue = $detail['field_value'] ?? $mapping['manual_default'] ?? ''; $fieldValue = $detail['field_value'] ?? $mapping['manual_default'] ?? '';
@@ -627,8 +626,8 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
echo "<select name='rows[$index][details][{$mapping['id']}][field_value]' class='cell-input dropdown-select $inputClass' data-mapping-id='{$mapping['id']}' data-field-id='{$mapping['field_id']}' data-selected-value='" . htmlspecialchars($fieldValue) . "' " . ($mapping['is_required'] ? 'required' : '') . ">"; echo "<select name='rows[$index][details][{$mapping['id']}][field_value]' class='cell-input dropdown-select $inputClass' data-mapping-id='{$mapping['id']}' data-field-id='{$mapping['field_id']}' data-selected-value='" . htmlspecialchars($fieldValue) . "' " . ($mapping['is_required'] ? 'required' : '') . ">";
echo "<option value=''>Seleziona...</option>"; echo "<option value=''>Seleziona...</option>";
echo "</select>"; echo "</select>";
} elseif ($mapping['data_type'] === 'DATE') { } elseif ($mapping['data_type'] === 'Data') {
echo "<input type='date' name='rows[$index][details][{$mapping['id']}][field_value]' value='" . htmlspecialchars($fieldValue) . "' class='cell-input $inputClass' " . ($mapping['is_required'] ? 'required' : '') . ">"; echo "<input type='text' name='rows[$index][details][{$mapping['id']}][field_value]' value='" . htmlspecialchars($fieldValue) . "' class='cell-input date-picker $inputClass' " . ($mapping['is_required'] ? 'required' : '') . ">";
} elseif ($mapping['data_type'] === 'INT') { } elseif ($mapping['data_type'] === 'INT') {
echo "<input type='number' name='rows[$index][details][{$mapping['id']}][field_value]' value='" . htmlspecialchars($fieldValue) . "' class='cell-input $inputClass' " . ($mapping['is_required'] ? 'required' : '') . ">"; echo "<input type='number' name='rows[$index][details][{$mapping['id']}][field_value]' value='" . htmlspecialchars($fieldValue) . "' class='cell-input $inputClass' " . ($mapping['is_required'] ? 'required' : '') . ">";
} else { } else {
@@ -641,11 +640,11 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
} }
$manualIndex = 0; $manualIndex = 0;
foreach ($allMappings as $mapping) { foreach ($allMappings as $mapping) {
if ($mapping['is_manual'] && $mapping['main_field'] != 1) { if ($mapping['is_manual'] && $mapping['main_field'] != 1 && $mapping['is_visible_import'] == 1) {
$detail = array_filter($rowDetails, fn($d) => $d['mapping_id'] == $mapping['id']); $detail = array_filter($rowDetails, fn($d) => $d['mapping_id'] == $mapping['id']);
$detail = reset($detail) ?: ['field_value' => $mapping['manual_default']]; $detail = reset($detail) ?: ['field_value' => $mapping['manual_default']];
$fieldValue = $detail['field_value'] ?? $mapping['manual_default'] ?? ''; $fieldValue = $detail['field_value'] ?? $mapping['manual_default'] ?? '';
if ($mapping['data_type'] === 'DATE' && $mapping['manual_default'] === 'today' && empty($fieldValue)) { if ($mapping['data_type'] === 'Data' && $mapping['manual_default'] === 'today' && empty($fieldValue)) {
$fieldValue = date('Y-m-d'); $fieldValue = date('Y-m-d');
} }
$requiredClass = ($mapping['is_required'] && (is_null($fieldValue) || $fieldValue === '')) ? 'missing-required' : ''; $requiredClass = ($mapping['is_required'] && (is_null($fieldValue) || $fieldValue === '')) ? 'missing-required' : '';
@@ -656,8 +655,8 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
echo "<select name='rows[$index][details][{$mapping['id']}][field_value]' class='cell-input dropdown-select $inputClass' data-mapping-id='{$mapping['id']}' data-field-id='{$mapping['field_id']}' data-selected-value='" . htmlspecialchars($fieldValue) . "' " . ($mapping['is_required'] ? 'required' : '') . ">"; echo "<select name='rows[$index][details][{$mapping['id']}][field_value]' class='cell-input dropdown-select $inputClass' data-mapping-id='{$mapping['id']}' data-field-id='{$mapping['field_id']}' data-selected-value='" . htmlspecialchars($fieldValue) . "' " . ($mapping['is_required'] ? 'required' : '') . ">";
echo "<option value=''>Seleziona...</option>"; echo "<option value=''>Seleziona...</option>";
echo "</select>"; echo "</select>";
} elseif ($mapping['data_type'] === 'DATE') { } elseif ($mapping['data_type'] === 'Data') {
echo "<input type='date' name='rows[$index][details][{$mapping['id']}][field_value]' value='" . htmlspecialchars($fieldValue) . "' class='cell-input $inputClass' " . ($mapping['is_required'] ? 'required' : '') . ">"; echo "<input type='text' name='rows[$index][details][{$mapping['id']}][field_value]' value='" . htmlspecialchars($fieldValue) . "' class='cell-input date-picker $inputClass' " . ($mapping['is_required'] ? 'required' : '') . ">";
} elseif ($mapping['data_type'] === 'INT') { } elseif ($mapping['data_type'] === 'INT') {
echo "<input type='number' name='rows[$index][details][{$mapping['id']}][field_value]' value='" . htmlspecialchars($fieldValue) . "' class='cell-input $inputClass' " . ($mapping['is_required'] ? 'required' : '') . ">"; echo "<input type='number' name='rows[$index][details][{$mapping['id']}][field_value]' value='" . htmlspecialchars($fieldValue) . "' class='cell-input $inputClass' " . ($mapping['is_required'] ? 'required' : '') . ">";
} else { } else {
@@ -668,6 +667,12 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
$manualIndex++; $manualIndex++;
} }
} }
// Aggiunta cella per Tested Component
echo "<div class='grid-cell editable-cell' data-col='tested_component' data-row='$index' data-index='$cellIndex' style='flex: 0 0 150px; display: flex; align-items: center;'>";
echo "<input type='text' name='rows[$index][tested_component]' value='' class='cell-input manual-input' style='flex: 1; margin-right: 5px;'>";
echo "<button type='button' class='add-part-btn btn btn-sm btn-primary' data-row='$index'><i class='fas fa-plus'></i></button>";
echo "</div>";
$cellIndex++;
?> ?>
<div class="grid-cell" style="flex: 0 0 200px;"> <div class="grid-cell" style="flex: 0 0 200px;">
<select name="rows[<?= $index ?>][carrier]" class="carrier-select"> <select name="rows[<?= $index ?>][carrier]" class="carrier-select">
@@ -719,11 +724,29 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
<?php include('jsinclude.php'); ?> <?php include('jsinclude.php'); ?>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <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="https://cdnjs.cloudflare.com/ajax/libs/fabric.js/5.3.1/fabric.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/flatpickr@4.6.13/dist/flatpickr.min.js"></script>
<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 src="export_to_lims.js"></script>
<script> <script>
// Initialize Flatpickr for all date inputs
document.addEventListener("DOMContentLoaded", function() {
flatpickr(".date-picker", {
dateFormat: "Y-m-d",
allowInput: true,
onOpen: function(selectedDates, dateStr, instance) {
instance.input.closest('.grid-cell').classList.add('expanded');
},
onClose: function(selectedDates, dateStr, instance) {
instance.input.closest('.grid-cell').classList.remove('expanded');
// Trigger change event to handle unsaved changes
const event = new Event('change');
instance.input.dispatchEvent(event);
}
});
});
$(document).on("click", ".export-lims-btn", function() { $(document).on("click", ".export-lims-btn", function() {
let rowId = $(this).data("row"); let rowId = $(this).data("row");
let idDataDb = $(this).data("iddatadb"); let idDataDb = $(this).data("iddatadb");
@@ -752,16 +775,13 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
}); });
document.addEventListener("DOMContentLoaded", function() { document.addEventListener("DOMContentLoaded", function() {
console.log("Page loaded, initializing event listeners"); const inputs = document.querySelectorAll(".cell-input, .dropdown-select, .carrier-select, .awb-input, .date-picker");
const inputs = document.querySelectorAll(".cell-input, .dropdown-select, .carrier-select, .awb-input");
const unsavedDiv = document.getElementById("unsavedChanges"); const unsavedDiv = document.getElementById("unsavedChanges");
const changedList = document.getElementById("changedFields"); const changedList = document.getElementById("changedFields");
let hasChanges = false; let hasChanges = false;
let changedFields = {}; let changedFields = {};
function renderChangedList() { function renderChangedList() {
console.log("Rendering changed fields list:", changedFields);
changedList.innerHTML = ""; changedList.innerHTML = "";
Object.keys(changedFields).forEach(rowIndex => { Object.keys(changedFields).forEach(rowIndex => {
const fields = changedFields[rowIndex]; const fields = changedFields[rowIndex];
@@ -776,7 +796,6 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
inputs.forEach(el => { inputs.forEach(el => {
el.addEventListener("change", () => { el.addEventListener("change", () => {
console.log("Input changed:", el.name);
hasChanges = true; hasChanges = true;
const gridCell = el.closest(".grid-cell"); const gridCell = el.closest(".grid-cell");
const colIndex = gridCell?.dataset.index; const colIndex = gridCell?.dataset.index;
@@ -807,7 +826,6 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
document.querySelectorAll(".save-btn").forEach(btn => { document.querySelectorAll(".save-btn").forEach(btn => {
btn.addEventListener("click", () => { btn.addEventListener("click", () => {
const rowIndex = btn.dataset.row; const rowIndex = btn.dataset.row;
console.log(`Saving row ${rowIndex}`);
const row = btn.closest('.grid-row'); const row = btn.closest('.grid-row');
const iddatadb = row.getAttribute('data-id'); const iddatadb = row.getAttribute('data-id');
const formData = new FormData(); const formData = new FormData();
@@ -834,7 +852,6 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
return response.json(); return response.json();
}) })
.then(data => { .then(data => {
console.log("Save response:", data);
if (data.success) { if (data.success) {
const cells = row.querySelectorAll('.grid-cell'); const cells = row.querySelectorAll('.grid-cell');
cells.forEach(cell => { cells.forEach(cell => {
@@ -858,14 +875,12 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
} }
}) })
.catch(error => { .catch(error => {
console.error("Save error:", error);
alert('Errore durante il salvataggio: ' + error.message); alert('Errore durante il salvataggio: ' + error.message);
}); });
}); });
}); });
document.querySelector('.save-all-btn').addEventListener('click', async () => { document.querySelector('.save-all-btn').addEventListener('click', async () => {
console.log("Saving all rows");
const rows = document.querySelectorAll('.grid-row'); const rows = document.querySelectorAll('.grid-row');
let successCount = 0; let successCount = 0;
let errorMessages = []; let errorMessages = [];
@@ -873,16 +888,13 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
for (const row of rows) { for (const row of rows) {
const saveBtn = row.querySelector('.save-btn'); const saveBtn = row.querySelector('.save-btn');
if (!saveBtn) { if (!saveBtn) {
console.warn(`No save button found in row with data-id: ${row.getAttribute('data-id')}`);
continue; continue;
} }
const rowIndex = saveBtn.dataset.row; const rowIndex = saveBtn.dataset.row;
const iddatadb = row.getAttribute('data-id'); const iddatadb = row.getAttribute('data-id');
if (!rowIndex || !iddatadb) { if (!rowIndex || !iddatadb) {
console.warn(`Missing rowIndex or iddatadb in row:`, row);
continue; continue;
} }
console.log(`Processing row ${rowIndex} with iddatadb ${iddatadb}`);
const formData = new FormData(); const formData = new FormData();
const inputs = row.querySelectorAll(`input[name^="rows[${rowIndex}][details]"], select[name^="rows[${rowIndex}][details]"]`); const inputs = row.querySelectorAll(`input[name^="rows[${rowIndex}][details]"], select[name^="rows[${rowIndex}][details]"]`);
@@ -906,7 +918,6 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`); if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
const data = await response.json(); const data = await response.json();
console.log(`Row ${rowIndex} save response:`, data);
if (data.success) { if (data.success) {
successCount++; successCount++;
const cells = row.querySelectorAll('.grid-cell'); const cells = row.querySelectorAll('.grid-cell');
@@ -926,14 +937,12 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
errorMessages.push(`Riga ${parseInt(rowIndex) + 1}: ${data.message}`); errorMessages.push(`Riga ${parseInt(rowIndex) + 1}: ${data.message}`);
} }
} catch (error) { } catch (error) {
console.error(`Row ${rowIndex} save error:`, error);
errorMessages.push(`Riga ${parseInt(rowIndex) + 1}: ${error.message}`); errorMessages.push(`Riga ${parseInt(rowIndex) + 1}: ${error.message}`);
} }
} }
renderChangedList(); renderChangedList();
hasChanges = Object.keys(changedFields).length > 0; hasChanges = Object.keys(changedFields).length > 0;
console.log(`Save all completed: ${successCount} successes, ${errorMessages.length} errors`);
if (errorMessages.length === 0) { if (errorMessages.length === 0) {
alert(`Tutte le ${successCount} righe salvate con successo!`); alert(`Tutte le ${successCount} righe salvate con successo!`);
@@ -942,8 +951,6 @@ 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();
@@ -955,10 +962,8 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
// Gestisci la chiusura dei modali per rimuovere i backdrop // Gestisci la chiusura dei modali per rimuovere i backdrop
document.querySelectorAll('#exportConfirmModal, #exportResponseModal').forEach(modal => { document.querySelectorAll('#exportConfirmModal, #exportResponseModal').forEach(modal => {
modal.addEventListener('hidden.bs.modal', () => { modal.addEventListener('hidden.bs.modal', () => {
console.log(`Modal ${modal.id} closed, removing backdrops`);
// Rimuovi tutti i backdrop residui // Rimuovi tutti i backdrop residui
document.querySelectorAll('.modal-backdrop').forEach(backdrop => { document.querySelectorAll('.modal-backdrop').forEach(backdrop => {
console.log('Removing backdrop:', backdrop);
backdrop.remove(); backdrop.remove();
}); });
// Ripristina il body // Ripristina il body
@@ -974,7 +979,6 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
</script> </script>
<script> <script>
document.addEventListener("DOMContentLoaded", function() { document.addEventListener("DOMContentLoaded", function() {
console.log("Initializing cell expansion and propagation");
const inputs = document.querySelectorAll('.cell-input'); const inputs = document.querySelectorAll('.cell-input');
inputs.forEach(input => { inputs.forEach(input => {
input.addEventListener('focus', function() { input.addEventListener('focus', function() {
@@ -988,7 +992,6 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
const propagateButtons = document.querySelectorAll('.propagate-btn'); const propagateButtons = document.querySelectorAll('.propagate-btn');
propagateButtons.forEach(button => { propagateButtons.forEach(button => {
button.addEventListener('click', function() { button.addEventListener('click', function() {
console.log("Propagating value for column:", this.getAttribute('data-column'));
const column = this.getAttribute('data-column'); const column = this.getAttribute('data-column');
const input = this.previousElementSibling; const input = this.previousElementSibling;
const value = input.value; const value = input.value;
@@ -1010,6 +1013,17 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
targetInput.setAttribute('data-selected-value', value); targetInput.setAttribute('data-selected-value', value);
const event = new Event('change'); const event = new Event('change');
targetInput.dispatchEvent(event); targetInput.dispatchEvent(event);
} else if (targetInput.classList.contains('date-picker')) {
// Update Flatpickr instance
const flatpickrInstance = targetInput._flatpickr;
if (flatpickrInstance && value) {
flatpickrInstance.setDate(value, true);
}
const event = new Event('change');
targetInput.dispatchEvent(event);
} else {
const event = new Event('change');
targetInput.dispatchEvent(event);
} }
} }
} }
@@ -1025,7 +1039,6 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
let columnIndex = 0; let columnIndex = 0;
resizers.forEach(resizer => { resizers.forEach(resizer => {
resizer.addEventListener('mousedown', function(e) { resizer.addEventListener('mousedown', function(e) {
console.log("Starting column resize");
currentResizer = resizer; currentResizer = resizer;
const header = resizer.parentElement; const header = resizer.parentElement;
columnIndex = header.getAttribute('data-index'); columnIndex = header.getAttribute('data-index');
@@ -1048,7 +1061,6 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
function stopResize() { function stopResize() {
if (currentResizer) { if (currentResizer) {
console.log("Stopping column resize");
document.removeEventListener('mousemove', resize); document.removeEventListener('mousemove', resize);
document.removeEventListener('mouseup', stopResize); document.removeEventListener('mouseup', stopResize);
currentResizer = null; currentResizer = null;
@@ -1059,13 +1071,11 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
</script> </script>
<script> <script>
document.addEventListener("DOMContentLoaded", function() { document.addEventListener("DOMContentLoaded", function() {
console.log("Initializing dropdown population");
const dropdownData = {}; const dropdownData = {};
async function populateDropdowns() { async function populateDropdowns() {
const dropdowns = document.querySelectorAll('.dropdown-select'); const dropdowns = document.querySelectorAll('.dropdown-select');
if (dropdowns.length === 0) { if (dropdowns.length === 0) {
console.log("No dropdowns found");
return; return;
} }
@@ -1076,7 +1086,6 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
const missingFieldIds = uniqueFieldIds.filter(fieldId => !dropdownData[fieldId]); const missingFieldIds = uniqueFieldIds.filter(fieldId => !dropdownData[fieldId]);
if (missingFieldIds.length > 0) { if (missingFieldIds.length > 0) {
console.log("Fetching dropdown data for field IDs:", missingFieldIds);
try { try {
const response = await fetch( const response = await fetch(
`get_customfield_values.php?field_ids=${missingFieldIds.join(",")}` `get_customfield_values.php?field_ids=${missingFieldIds.join(",")}`
@@ -1084,16 +1093,12 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`); if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
const data = await response.json(); const data = await response.json();
if (data.error) { if (data.error) {} else {
console.error("Fetch error:", data.error);
} else {
for (const fieldId of Object.keys(data)) { for (const fieldId of Object.keys(data)) {
dropdownData[fieldId] = data[fieldId] || []; dropdownData[fieldId] = data[fieldId] || [];
} }
} }
} catch (error) { } catch (error) {}
console.error("Fetch error:", error);
}
} }
dropdowns.forEach(dropdown => { dropdowns.forEach(dropdown => {
@@ -1103,7 +1108,6 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
if (!fieldId || !dropdownData[fieldId]) { if (!fieldId || !dropdownData[fieldId]) {
dropdown.innerHTML = '<option value="">Errore nel caricamento</option>'; dropdown.innerHTML = '<option value="">Errore nel caricamento</option>';
console.warn(`No data for fieldId ${fieldId}`);
return; return;
} }
@@ -1122,7 +1126,6 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
if ((currentValue || selectedValue) && dropdown.value !== (currentValue || selectedValue)) { if ((currentValue || selectedValue) && dropdown.value !== (currentValue || selectedValue)) {
dropdown.value = ''; dropdown.value = '';
console.warn(`Value ${currentValue || selectedValue} not found for fieldId ${fieldId}`);
} }
}); });
} }
@@ -1130,6 +1133,52 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
populateDropdowns(); populateDropdowns();
}); });
</script> </script>
<script>
$(document).on('click', '.add-part-btn', function() {
const rowIndex = $(this).data('row');
const row = $(this).closest('.grid-row');
const iddatadb = row.data('id');
const input = row.find(`input[name="rows[${rowIndex}][tested_component]"]`);
const description = input.val().trim();
if (!description) {
alert('Inserisci un valore per Tested Component');
return;
}
const data = {
iddatadb: iddatadb,
parts: [{
part_number: '1', // Imposta part_number a '1'
part_description: description,
mix: 'N'
}]
};
$.ajax({
url: 'save_parts.php',
method: 'POST',
contentType: 'application/json',
data: JSON.stringify(data),
success: function(response) {
if (response.success) {
alert('Parte aggiunta con successo!');
input.val(''); // Pulisci l'input dopo l'aggiunta
// Opzionale: aggiorna la tabella delle parti se il modal è aperto
const partsModal = $('#partsModal');
if (partsModal.hasClass('show')) {
loadParts(iddatadb);
}
} else {
alert('Errore: ' + response.message);
}
},
error: function() {
alert('Errore durante la richiesta AJAX');
}
});
});
</script>
<!-- Modale di conferma per l'esportazione --> <!-- Modale di conferma per l'esportazione -->
<div class="modal fade" id="exportConfirmModal" tabindex="-1" aria-labelledby="exportConfirmModalLabel" aria-hidden="true"> <div class="modal fade" id="exportConfirmModal" tabindex="-1" aria-labelledby="exportConfirmModalLabel" aria-hidden="true">
<div class="modal-dialog"> <div class="modal-dialog">
+46 -18
View File
@@ -185,13 +185,21 @@ document.addEventListener("DOMContentLoaded", function () {
return; return;
} }
for (const file of files) { loader.style.display = "flex";
console.log(`Inizio upload di ${files.length} file`);
let successCount = 0;
let errorMessages = [];
let uploadPromises = [];
for (let i = 0; i < files.length; i++) {
const file = files[i];
if (!file.type.startsWith("image/")) { if (!file.type.startsWith("image/")) {
alert("Per favore, carica solo immagini!"); alert(`File ${file.name} non è un'immagine, saltato!`);
continue; continue;
} }
loader.style.display = "flex"; console.log(`Preparazione upload file ${i + 1}: ${file.name}`);
const formData = new FormData(); const formData = new FormData();
formData.append("photo", file); formData.append("photo", file);
@@ -201,23 +209,43 @@ document.addEventListener("DOMContentLoaded", function () {
formData.append("iddatadb", iddatadb); formData.append("iddatadb", iddatadb);
} }
try { const uploadPromise = fetch("upload_photo.php", {
const response = await fetch("upload_photo.php", { method: "POST",
method: "POST", body: formData,
body: formData, })
.then((response) => response.json())
.then((result) => {
if (result.success) {
successCount++;
console.log(`Successo per ${file.name}`);
} else {
errorMessages.push(
`Errore per ${file.name}: ${result.message}`,
);
}
})
.catch((error) => {
errorMessages.push(
`Errore per ${file.name}: ${error.message}`,
);
}); });
const result = await response.json();
if (result.success) { uploadPromises.push(uploadPromise);
loadPopupContent(iddatadb, idquotations);
} else {
alert("Errore durante il caricamento: " + result.message);
}
} catch (error) {
alert("Errore durante il caricamento: " + error.message);
} finally {
loader.style.display = "none";
}
} }
await Promise.all(uploadPromises);
loader.style.display = "none";
console.log(
`Fine upload: ${successCount} riusciti, ${errorMessages.length} errori`,
);
if (errorMessages.length > 0) {
alert("Errori durante l'upload:\n" + errorMessages.join("\n"));
}
// Ricarica sempre alla fine per aggiornare la lista, anche se parziale successo
loadPopupContent(iddatadb, idquotations);
} }
function attachPhotoEventListeners(iddatadb, idquotations) { function attachPhotoEventListeners(iddatadb, idquotations) {
+12 -2
View File
@@ -21,6 +21,10 @@ try {
$idschema = intval($_POST['idschema'] ?? 0); // Nuovo campo $idschema = intval($_POST['idschema'] ?? 0); // Nuovo campo
$schemaname = trim($_POST['schemaname'] ?? ''); // Corretto da schemamaname $schemaname = trim($_POST['schemaname'] ?? ''); // Corretto da schemamaname
$idroutine = isset($_POST['idroutine']) && $_POST['idroutine'] !== '' ? intval($_POST['idroutine']) : null; // Aggiunto idroutine $idroutine = isset($_POST['idroutine']) && $_POST['idroutine'] !== '' ? intval($_POST['idroutine']) : null; // Aggiunto idroutine
$button_size = trim($_POST['button_size'] ?? 'medium'); // Nuovo campo
$button_bg_color = trim($_POST['button_bg_color'] ?? '#007bff'); // Nuovo campo
$button_text_color = trim($_POST['button_text_color'] ?? '#ffffff'); // Nuovo campo
$button_label = trim($_POST['button_label'] ?? 'Click Me'); // Nuovo campo
// 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) {
@@ -36,10 +40,12 @@ try {
$db = DBHandlerSelect::getInstance(); $db = DBHandlerSelect::getInstance();
$pdo = $db->getConnection(); $pdo = $db->getConnection();
// Aggiorna il database, includendo idschema, schemaname e idroutine // Aggiorna il database, includendo i nuovi campi
$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 = ?, schemaname = ?, idschema = ?, idroutine = ?, updated_at = NOW() idclient = ?, clientname = ?, schemaname = ?, idschema = ?, idroutine = ?,
button_size = ?, button_bg_color = ?, button_text_color = ?, button_label = ?,
updated_at = NOW()
WHERE id = ?"); WHERE id = ?");
$stmt->execute([ $stmt->execute([
$name, $name,
@@ -52,6 +58,10 @@ try {
$schemaname, $schemaname,
$idschema, $idschema,
$idroutine, $idroutine,
$button_size,
$button_bg_color,
$button_text_color,
$button_label,
$id $id
]); ]);
File diff suppressed because one or more lines are too long
+68
View File
@@ -0,0 +1,68 @@
<?php
require_once "class/VisualLimsApiClient.class.php";
include('include/headscript.php');
header("Content-Type: application/json");
// 🔹 Configura directory log (creala se non esiste)
$logDir = __DIR__ . '/logs/api/';
if (!is_dir($logDir)) {
mkdir($logDir, 0755, true);
}
// 🔹 Base URL API
$apiBaseUrl = 'https://93.43.5.102/limsapi/api/odata/';
// 🔹 Hardcoded commessaId
$commessaId = 533357;
try {
// 🔹 Initialize API client
$api = VisualLimsApiClient::getInstance();
// 🔹 STEP 1: POST InviaCommessa
$logContentStep1 = "curl --location --request POST '{$apiBaseUrl}CommessaWeb({$commessaId})/InviaCommessa' \\\n" .
"--header 'Content-Type: application/json' \\\n" .
"--header 'Authorization: Bearer ••••••' \\\n" .
"--data '{}'\n\n";
$sendResult = $api->post("CommessaWeb({$commessaId})/InviaCommessa", []);
$logContentStep1 .= "RESPONSE:\n" . json_encode($sendResult, JSON_PRETTY_PRINT);
$logFileStep1 = $logDir . "commessa_{$commessaId}_send_step1_" . time() . ".txt";
file_put_contents($logFileStep1, $logContentStep1);
// 🔹 STEP 2: GET di controllo post-invio
$expand = "CommesseCustomFields(\$expand=CustomField)";
$commessaAfterSend = $api->get("CommessaWeb(" . $commessaId . ")?\$expand=" . $expand);
// Log curl-like per GET di controllo
$logContentStep2 = "curl --location --request GET '{$apiBaseUrl}CommessaWeb({$commessaId})?\$expand=CommesseCustomFields(\$expand=CustomField)' \\\n" .
"--header 'Authorization: Bearer ••••••'\n\n" .
"RESPONSE:\n" . json_encode($commessaAfterSend, JSON_PRETTY_PRINT);
$logFileStep2 = $logDir . "commessa_{$commessaId}_get_step2_" . time() . ".txt";
file_put_contents($logFileStep2, $logContentStep2);
// 🔹 Output a schermo
echo json_encode([
"success" => true,
"message" => "Commessa {$commessaId} inviata e verificata",
"sendResult" => $sendResult,
"commessaAfterSend" => $commessaAfterSend,
"logFiles" => [
"step1_send" => $logFileStep1,
"step2_get" => $logFileStep2
]
]);
} catch (Exception $e) {
error_log("Send/Check Error: " . $e->getMessage() . "\nTrace: " . $e->getTraceAsString());
echo json_encode([
"success" => false,
"message" => "Operation failed: " . $e->getMessage(),
"logFiles" => [
"step1_send" => $logFileStep1 ?? null,
"step2_get" => $logFileStep2 ?? null
]
]);
}
+7 -8
View File
@@ -90,11 +90,11 @@
<tr> <tr>
<th>ID</th> <th>ID</th>
<th><?= htmlspecialchars($nametemplate, ENT_QUOTES, 'UTF-8'); ?></th> <th><?= htmlspecialchars($nametemplate, ENT_QUOTES, 'UTF-8'); ?></th>
<th><?= htmlspecialchars($lastmodtemplate, ENT_QUOTES, 'UTF-8'); ?></th>
<th><?= htmlspecialchars($rowheader, ENT_QUOTES, 'UTF-8'); ?></th> <th><?= htmlspecialchars($rowheader, ENT_QUOTES, 'UTF-8'); ?></th>
<th><?= htmlspecialchars($columnheader, ENT_QUOTES, 'UTF-8'); ?></th> <th><?= htmlspecialchars($columnheader, ENT_QUOTES, 'UTF-8'); ?></th>
<th><?= htmlspecialchars($desctemplate, ENT_QUOTES, 'UTF-8'); ?></th> <th><?= htmlspecialchars($desctemplate, ENT_QUOTES, 'UTF-8'); ?></th>
<th>Client Name</th> <th>Client Name</th>
<th>Button Label</th>
<th>Status</th> <!-- Aggiunta colonna Status --> <th>Status</th> <!-- Aggiunta colonna Status -->
<th><?= htmlspecialchars($action, ENT_QUOTES, 'UTF-8'); ?></th> <th><?= htmlspecialchars($action, ENT_QUOTES, 'UTF-8'); ?></th>
</tr> </tr>
@@ -147,13 +147,7 @@
data: 'name', // Nome del template data: 'name', // Nome del template
title: "Template Name" title: "Template Name"
}, },
{
data: 'updated_at', // Ultima modifica, formattata come data leggibile
title: "Last Modified",
render: function(data) {
return new Date(data).toLocaleDateString();
}
},
{ {
data: 'header_row', // Riga degli header data: 'header_row', // Riga degli header
title: "Header Row" title: "Header Row"
@@ -176,6 +170,11 @@
return `${clientName} (ID: ${clientId})`; return `${clientName} (ID: ${clientId})`;
} }
}, },
{
data: 'button_label', // Nuova colonna per Button Label
title: "Button Label",
defaultContent: 'Click Me'
},
{ {
data: 'status', // Stato con Toggle Switch data: 'status', // Stato con Toggle Switch
title: "Status", title: "Status",