import edit update

This commit is contained in:
Claudio 2025-08-21 12:41:30 +02:00
parent d8eca66747
commit 22e4e652b5
4 changed files with 450 additions and 169 deletions

View File

@ -31,6 +31,6 @@ Content-Length: 51
< strict-transport-security: max-age=2592000 < strict-transport-security: max-age=2592000
< x-powered-by: ASP.NET < x-powered-by: ASP.NET
< x-content-type-options: nosniff < x-content-type-options: nosniff
< date: Mon, 18 Aug 2025 13:57:11 GMT < date: Thu, 21 Aug 2025 10:23:44 GMT
< <
* Connection #0 to host 93.43.5.102 left intact * Connection #0 to host 93.43.5.102 left intact

View File

@ -15,11 +15,11 @@
* [HTTP/2] [1] [:scheme: https] * [HTTP/2] [1] [:scheme: https]
* [HTTP/2] [1] [:authority: 93.43.5.102] * [HTTP/2] [1] [:authority: 93.43.5.102]
* [HTTP/2] [1] [:path: /limsapi/api/odata/CustomField(1083)?$expand=CustomFieldsValues] * [HTTP/2] [1] [:path: /limsapi/api/odata/CustomField(1083)?$expand=CustomFieldsValues]
* [HTTP/2] [1] [authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1laWRlbnRpZmllciI6IjQ5MiIsIlhhZlNlY3VyaXR5QXV0aFBhc3NlZCI6IlhhZlNlY3VyaXR5QXV0aFBhc3NlZCIsImh0dHA6Ly9zY2hlbWFzLnhtbHNvYXAub3JnL3dzLzIwMDUvMDUvaWRlbnRpdHkvY2xhaW1zL25hbWUiOiJXZWJBcGlVc2VyIiwiWGFmU2VjdXJpdHkiOiJYYWZTZWN1cml0eSIsIlhhZkxvZ29uUGFyYW1zIjoicTFZS0xVNHQ4a3ZNVFZXeVVncFBUWElzeUFRSktPa29CU1FXRjVmbkY2VUF4Y3RUa3hJTE1rdUI0Z2FHU3JVQSIsImV4cCI6MTc1NTUzMjYzMiwiaXNzIjoiTXkiLCJhdWQiOiJodHRwOi8vbG9jYWxob3N0OjQyMDAifQ.IaUi3N2ilMGCibN3wnBLWVut_PxznC6t9EfgCnLBJyI] * [HTTP/2] [1] [authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1laWRlbnRpZmllciI6IjQ5MiIsIlhhZlNlY3VyaXR5QXV0aFBhc3NlZCI6IlhhZlNlY3VyaXR5QXV0aFBhc3NlZCIsImh0dHA6Ly9zY2hlbWFzLnhtbHNvYXAub3JnL3dzLzIwMDUvMDUvaWRlbnRpdHkvY2xhaW1zL25hbWUiOiJXZWJBcGlVc2VyIiwiWGFmU2VjdXJpdHkiOiJYYWZTZWN1cml0eSIsIlhhZkxvZ29uUGFyYW1zIjoicTFZS0xVNHQ4a3ZNVFZXeVVncFBUWElzeUFRSktPa29CU1FXRjVmbkY2VUF4Y3RUa3hJTE1rdUI0Z2FHU3JVQSIsImV4cCI6MTc1NTc3OTAyNSwiaXNzIjoiTXkiLCJhdWQiOiJodHRwOi8vbG9jYWxob3N0OjQyMDAifQ.bBV1z1uaxZeUuw-2YS2gLGaxTCQJAHTieM82KVJb5nw]
* [HTTP/2] [1] [accept: application/json] * [HTTP/2] [1] [accept: application/json]
> GET /limsapi/api/odata/CustomField(1083)?$expand=CustomFieldsValues HTTP/2 > GET /limsapi/api/odata/CustomField(1083)?$expand=CustomFieldsValues HTTP/2
Host: 93.43.5.102 Host: 93.43.5.102
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1laWRlbnRpZmllciI6IjQ5MiIsIlhhZlNlY3VyaXR5QXV0aFBhc3NlZCI6IlhhZlNlY3VyaXR5QXV0aFBhc3NlZCIsImh0dHA6Ly9zY2hlbWFzLnhtbHNvYXAub3JnL3dzLzIwMDUvMDUvaWRlbnRpdHkvY2xhaW1zL25hbWUiOiJXZWJBcGlVc2VyIiwiWGFmU2VjdXJpdHkiOiJYYWZTZWN1cml0eSIsIlhhZkxvZ29uUGFyYW1zIjoicTFZS0xVNHQ4a3ZNVFZXeVVncFBUWElzeUFRSktPa29CU1FXRjVmbkY2VUF4Y3RUa3hJTE1rdUI0Z2FHU3JVQSIsImV4cCI6MTc1NTUzMjYzMiwiaXNzIjoiTXkiLCJhdWQiOiJodHRwOi8vbG9jYWxob3N0OjQyMDAifQ.IaUi3N2ilMGCibN3wnBLWVut_PxznC6t9EfgCnLBJyI Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1laWRlbnRpZmllciI6IjQ5MiIsIlhhZlNlY3VyaXR5QXV0aFBhc3NlZCI6IlhhZlNlY3VyaXR5QXV0aFBhc3NlZCIsImh0dHA6Ly9zY2hlbWFzLnhtbHNvYXAub3JnL3dzLzIwMDUvMDUvaWRlbnRpdHkvY2xhaW1zL25hbWUiOiJXZWJBcGlVc2VyIiwiWGFmU2VjdXJpdHkiOiJYYWZTZWN1cml0eSIsIlhhZkxvZ29uUGFyYW1zIjoicTFZS0xVNHQ4a3ZNVFZXeVVncFBUWElzeUFRSktPa29CU1FXRjVmbkY2VUF4Y3RUa3hJTE1rdUI0Z2FHU3JVQSIsImV4cCI6MTc1NTc3OTAyNSwiaXNzIjoiTXkiLCJhdWQiOiJodHRwOi8vbG9jYWxob3N0OjQyMDAifQ.bBV1z1uaxZeUuw-2YS2gLGaxTCQJAHTieM82KVJb5nw
Accept: application/json Accept: application/json
< HTTP/2 200 < HTTP/2 200
@ -30,6 +30,6 @@ Accept: application/json
< odata-version: 4.0 < odata-version: 4.0
< x-powered-by: ASP.NET < x-powered-by: ASP.NET
< x-content-type-options: nosniff < x-content-type-options: nosniff
< date: Mon, 18 Aug 2025 13:57:11 GMT < date: Thu, 21 Aug 2025 10:23:44 GMT
< <
* Connection #0 to host 93.43.5.102 left intact * Connection #0 to host 93.43.5.102 left intact

File diff suppressed because one or more lines are too long

View File

@ -40,7 +40,7 @@ $pdo = $db->getConnection();
$importReferenceCode = date('YmdHis') . '-' . uniqid(); $importReferenceCode = date('YmdHis') . '-' . uniqid();
// Recupera tutti i mapping dal template // Recupera tutti i mapping dal template
$stmt = $pdo->prepare("SELECT id, excel_column, data_type, is_required, manual_default, is_manual, field_label, field_id 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 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);
@ -49,6 +49,15 @@ if (empty($allMappings)) {
exit; exit;
} }
// Trova il campo main_field
$mainFieldMapping = null;
foreach ($allMappings as $mapping) {
if ($mapping['main_field'] == 1) {
$mainFieldMapping = $mapping;
break;
}
}
// Inserisci le righe selezionate in datadb (solo campi generici con templateid) // Inserisci le righe selezionate in datadb (solo campi generici con templateid)
$insertedIds = []; $insertedIds = [];
foreach ($selected_rows as $rowIndex) { foreach ($selected_rows as $rowIndex) {
@ -221,7 +230,8 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
.grid-header, .grid-header,
.grid-cell { .grid-cell {
flex: 1; flex: 1;
min-width: 100px; min-width: 70px;
/* Ridotto da 100px per compatibilità con pulsanti */
padding: 12px 15px; padding: 12px 15px;
border-right: 1px solid #dee2e6; border-right: 1px solid #dee2e6;
overflow: hidden; overflow: hidden;
@ -397,6 +407,25 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
border-color: #80bdff; border-color: #80bdff;
box-shadow: 0 0 5px rgba(0, 123, 255, 0.5); box-shadow: 0 0 5px rgba(0, 123, 255, 0.5);
} }
/* Sovrascrivi min-width per le celle dei pulsanti */
.grid-cell.button-cell,
.grid-header.button-header {
min-width: 70px !important;
flex: 0 0 70px !important;
}
/* Stile per l'header dei pulsanti */
.button-header {
min-height: 48px;
/* Altezza minima per uniformare */
padding: 12px 0;
/* Centra verticalmente, no padding orizzontale */
background-color: #e9ecef !important;
/* Grigio uniforme */
border-right: 1px solid #dee2e6 !important;
/* Bordo destro coerente */
}
</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>
@ -427,19 +456,46 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
<div class="grid-container"> <div class="grid-container">
<!-- Riga superiore per gli input dei campi manuali --> <!-- Riga superiore per gli input dei campi manuali -->
<div class="grid-top"> <div class="grid-top">
<div class="grid-cell" style="flex: 0 0 100px;"></div> <!-- Save --> <div class="grid-cell button-cell" style="flex: 0 0 70px;"></div> <!-- Save -->
<div class="grid-cell" style="flex: 0 0 100px;"></div> <!-- Photos --> <div class="grid-cell button-cell" style="flex: 0 0 70px;"></div> <!-- Photos -->
<div class="grid-cell" style="flex: 0 0 100px;"></div> <!-- Parts --> <div class="grid-cell button-cell" style="flex: 0 0 70px;"></div> <!-- Parts -->
<?php if ($mainFieldMapping): ?>
<div class="grid-cell" style="flex: 0 0 150px;">
<?php
$fieldValue = $mainFieldMapping['manual_default'] ?? '';
if ($mainFieldMapping['data_type'] === 'DATE' && $mainFieldMapping['manual_default'] === 'today') {
$fieldValue = date('Y-m-d');
}
$inputClass = $mainFieldMapping['is_manual'] ? 'manual-input' : 'auto-input';
if ($mainFieldMapping['is_required']) $inputClass .= ' required-input';
if ($mainFieldMapping['data_type'] === 'SceltaMultipla') {
echo "<select class='custom-field dropdown-select $inputClass' data-column='main_field' data-field-id='{$mainFieldMapping['field_id']}' " . ($mainFieldMapping['is_required'] ? 'required' : '') . ">";
echo "<option value=''>Seleziona...</option>";
echo "</select>";
echo "<button type='button' class='propagate-btn' data-column='main_field'><i class='fas fa-arrow-down'></i></button>";
} elseif ($mainFieldMapping['data_type'] === 'DATE') {
echo "<input type='date' class='custom-field $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>";
} 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 "<button type='button' class='propagate-btn' data-column='main_field'><i class='fas fa-arrow-down'></i></button>";
} else {
echo "<input type='text' class='custom-field $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>";
}
?>
</div>
<?php endif; ?>
<div class="grid-cell" style="flex: 0 0 150px;"></div> <!-- importreferencecode --> <div class="grid-cell" style="flex: 0 0 150px;"></div> <!-- importreferencecode -->
<?php <?php
$fixedColumns = ['filename_import', 'status', 'importdate']; $fixedColumns = ['filename_import', 'status', 'importdate'];
foreach ($fixedColumns as $col) { foreach ($fixedColumns as $col) {
echo "<div class='grid-cell' style='flex: 0 0 150px;'></div>"; echo "<div class='grid-cell' style='flex: 0 0 150px;'></div>";
} }
// Campi automatici (is_manual = 0) - Solo SceltaMultipla ha campo e propagazione // Campi automatici (is_manual = 0) escluso main_field
$autoIndex = 0; $autoIndex = 0;
foreach ($allMappings as $mapping) { foreach ($allMappings as $mapping) {
if (!$mapping['is_manual']) { if (!$mapping['is_manual'] && $mapping['main_field'] != 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') {
@ -450,15 +506,15 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
echo "<button type='button' class='propagate-btn' data-column='auto_$autoIndex'><i class='fas fa-arrow-down'></i></button>"; echo "<button type='button' class='propagate-btn' data-column='auto_$autoIndex'><i class='fas fa-arrow-down'></i></button>";
echo "</div>"; echo "</div>";
} else { } else {
echo "<div class='grid-cell' style='flex: 0 0 150px;'></div>"; // Nessun input per altri tipi echo "<div class='grid-cell' style='flex: 0 0 150px;'></div>";
} }
$autoIndex++; $autoIndex++;
} }
} }
// Campi manuali (is_manual = 1) con propagate-btn - Rimane invariato // Campi manuali (is_manual = 1) escluso main_field
$manualIndex = 0; $manualIndex = 0;
foreach ($allMappings as $mapping) { foreach ($allMappings as $mapping) {
if ($mapping['is_manual']) { if ($mapping['is_manual'] && $mapping['main_field'] != 1) {
$fieldValue = $mapping['manual_default'] ?? ''; $fieldValue = $mapping['manual_default'] ?? '';
if ($mapping['data_type'] === 'DATE' && $mapping['manual_default'] === 'today') { if ($mapping['data_type'] === 'DATE' && $mapping['manual_default'] === 'today') {
$fieldValue = date('Y-m-d'); $fieldValue = date('Y-m-d');
@ -470,7 +526,6 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
echo "<select class='custom-field dropdown-select $inputClass' data-column='manual_$manualIndex' data-field-id='{$mapping['field_id']}' " . ($mapping['is_required'] ? 'required' : '') . ">"; echo "<select class='custom-field dropdown-select $inputClass' data-column='manual_$manualIndex' data-field-id='{$mapping['field_id']}' " . ($mapping['is_required'] ? 'required' : '') . ">";
echo "<option value=''>Seleziona...</option>"; echo "<option value=''>Seleziona...</option>";
echo "</select>"; echo "</select>";
echo "<button type='button' class='propagate-btn' data-column='manual_$manualIndex'><i class='fas fa-arrow-down'></i></button>";
} elseif ($mapping['data_type'] === 'DATE') { } elseif ($mapping['data_type'] === 'DATE') {
echo "<input type='date' class='custom-field $inputClass' data-column='manual_$manualIndex' value='" . htmlspecialchars($fieldValue) . "' " . ($mapping['is_required'] ? 'required' : '') . ">"; echo "<input type='date' class='custom-field $inputClass' data-column='manual_$manualIndex' value='" . htmlspecialchars($fieldValue) . "' " . ($mapping['is_required'] ? 'required' : '') . ">";
} elseif ($mapping['data_type'] === 'INT') { } elseif ($mapping['data_type'] === 'INT') {
@ -490,26 +545,32 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
<!-- Header della tabella --> <!-- Header della tabella -->
<div class="grid-row"> <div class="grid-row">
<div class="grid-header" style="flex: 0 0 100px;">Save</div> <div class="grid-header button-header" style="flex: 0 0 70px;"></div> <!-- Save -->
<div class="grid-header" style="flex: 0 0 100px;">Photos</div> <div class="grid-header button-header" style="flex: 0 0 70px;"></div> <!-- Photos -->
<div class="grid-header" style="flex: 0 0 100px;">Parts</div> <div class="grid-header button-header" style="flex: 0 0 70px;"></div> <!-- Parts -->
<div class="grid-header" data-index="3" style="flex: 0 0 150px; position: relative;">Import Reference Code<div class="resizer"></div> <?php if ($mainFieldMapping): ?>
<div class="grid-header" data-index="3" style="flex: 0 0 150px; position: relative;">
<?= htmlspecialchars($mainFieldMapping['field_label']) ?>
<div class="resizer"></div>
</div>
<?php endif; ?>
<div class="grid-header" data-index="<?= $mainFieldMapping ? 4 : 3 ?>" style="flex: 0 0 150px; position: relative;">Import Reference Code<div class="resizer"></div>
</div> </div>
<?php <?php
$headerIndex = 4; $headerIndex = $mainFieldMapping ? 5 : 4;
foreach ($fixedColumns as $col) { foreach ($fixedColumns as $col) {
$displayName = $slugMapping[$col] ?? $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>"; echo "<div class='grid-header' data-index='$headerIndex' style='flex: 0 0 150px; position: relative;'>$displayName<div class='resizer'></div></div>";
$headerIndex++; $headerIndex++;
} }
foreach ($allMappings as $mapping) { foreach ($allMappings as $mapping) {
if (!$mapping['is_manual']) { if (!$mapping['is_manual'] && $mapping['main_field'] != 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']) { if ($mapping['is_manual'] && $mapping['main_field'] != 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++;
} }
@ -522,22 +583,47 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
<!-- Righe della tabella --> <!-- Righe della tabella -->
<?php foreach ($importedData as $index => $row): ?> <?php foreach ($importedData as $index => $row): ?>
<div class="grid-row" data-id="<?= $row['iddatadb'] ?>"> <div class="grid-row" data-id="<?= $row['iddatadb'] ?>">
<div class="grid-cell" style="flex: 0 0 100px; position: relative;"> <div class="grid-cell button-cell" style="flex: 0 0 70px; position: relative;">
<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; width: 100%; box-sizing: border-box;"><i class="fas fa-save"></i></button> <button type="button" class="save-btn action-btn" data-row="<?= $index ?>" title="Save" style="background: #28a745; color: white; border: none; padding: 6px 8px; border-radius: 5px; cursor: pointer; width: 100%; box-sizing: border-box;"><i class="fas fa-save"></i></button>
</div> </div>
<div class="grid-cell" style="flex: 0 0 100px; position: relative;"> <div class="grid-cell button-cell" style="flex: 0 0 70px; position: relative;">
<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; width: 100%; box-sizing: border-box;"><i class="fas fa-camera"></i></button> <button type="button" class="photos-btn action-btn" data-row="<?= $index ?>" data-iddatadb="<?= $row['iddatadb'] ?>" title="Photos" style="background: #007bff; color: white; border: none; padding: 6px 8px; border-radius: 5px; cursor: pointer; width: 100%; box-sizing: border-box;"><i class="fas fa-camera"></i></button>
</div> </div>
<div class="grid-cell" style="flex: 0 0 100px; position: relative;"> <div class="grid-cell button-cell" style="flex: 0 0 70px; position: relative;">
<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; width: 100%; box-sizing: border-box;"><i class="fas fa-puzzle-piece"></i></button> <button type="button" class="parts-btn action-btn" data-row="<?= $index ?>" data-iddatadb="<?= $row['iddatadb'] ?>" title="Parts" style="background: #ffc107; color: white; border: none; padding: 6px 8px; border-radius: 5px; cursor: pointer; width: 100%; box-sizing: border-box;"><i class="fas fa-puzzle-piece"></i></button>
</div>
<?php if ($mainFieldMapping): ?>
<?php
$detail = array_filter($manualDetails, fn($d) => $d['mapping_id'] == $mainFieldMapping['id'] && $d['datadb_id'] == $row['iddatadb']);
$detail = reset($detail) ?: ['field_value' => $mainFieldMapping['manual_default']];
$fieldValue = $detail['field_value'] ?? $mainFieldMapping['manual_default'] ?? '';
if ($mainFieldMapping['data_type'] === 'DATE' && $mainFieldMapping['manual_default'] === 'today' && empty($fieldValue)) {
$fieldValue = date('Y-m-d');
}
$requiredClass = ($mainFieldMapping['is_required'] && (is_null($fieldValue) || $fieldValue === '')) ? 'missing-required' : '';
$inputClass = $mainFieldMapping['is_manual'] ? 'manual-input' : 'auto-input';
if ($mainFieldMapping['is_required']) $inputClass .= ' required-input';
?>
<div class="grid-cell editable-cell <?= $requiredClass ?>" data-col="main_field" data-row="<?= $index ?>" data-index="3" style="flex: 0 0 150px;">
<?php if ($mainFieldMapping['data_type'] === 'SceltaMultipla'): ?>
<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'] ?>" <?= $mainFieldMapping['is_required'] ? 'required' : '' ?>>
<option value="">Seleziona...</option>
</select>
<?php elseif ($mainFieldMapping['data_type'] === 'DATE'): ?>
<input type="date" name="rows[<?= $index ?>][details][<?= $mainFieldMapping['id'] ?>][field_value]" value="<?= htmlspecialchars($fieldValue) ?>" class="cell-input <?= $inputClass ?>" <?= $mainFieldMapping['is_required'] ? 'required' : '' ?>>
<?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' : '' ?>>
<?php else: ?>
<input type="text" name="rows[<?= $index ?>][details][<?= $mainFieldMapping['id'] ?>][field_value]" value="<?= htmlspecialchars($fieldValue) ?>" class="cell-input <?= $inputClass ?>" <?= $mainFieldMapping['is_required'] ? 'required' : '' ?>>
<?php endif; ?>
</div>
<?php endif; ?>
<div class="grid-cell" data-col="importreferencecode" data-row="<?= $index ?>" data-index="<?= $mainFieldMapping ? 4 : 3 ?>" style="flex: 0 0 150px;">
<span><?= htmlspecialchars($row['importreferencecode']) ?></span>
<input type="hidden" name="rows[<?= $index ?>][importreferencecode]" value="<?= htmlspecialchars($row['importreferencecode']) ?>">
</div> </div>
<?php <?php
$cellIndex = 3; // Inizia dopo importreferencecode $cellIndex = $mainFieldMapping ? 5 : 4;
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 "<input type='hidden' name='rows[$index][importreferencecode]' value='" . htmlspecialchars($row['importreferencecode']) . "'>";
echo "</div>";
$cellIndex++;
foreach ($fixedColumns as $col) { foreach ($fixedColumns as $col) {
$value = $row[$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;'>"; echo "<div class='grid-cell editable-cell' data-col='$col' data-row='$index' data-index='$cellIndex' style='flex: 0 0 150px;'>";
@ -557,7 +643,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']) { if (!$mapping['is_manual'] && $mapping['main_field'] != 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'] ?? '';
@ -583,7 +669,7 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
} }
$manualIndex = 0; $manualIndex = 0;
foreach ($allMappings as $mapping) { foreach ($allMappings as $mapping) {
if ($mapping['is_manual']) { if ($mapping['is_manual'] && $mapping['main_field'] != 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'] ?? '';
@ -697,14 +783,14 @@ 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() {
const columnIndex = this.getAttribute('data-column').replace('manual_', ''); const column = this.getAttribute('data-column');
const input = this.previousElementSibling; const input = this.previousElementSibling;
const value = input.value; const value = input.value;
// Trova la colonna target nella griglia superiore e propaga solo verticalmente // Trova la colonna target nella griglia superiore e propaga solo verticalmente
const gridTopCells = document.querySelector('.grid-top').querySelectorAll('.grid-cell'); const gridTopCells = document.querySelector('.grid-top').querySelectorAll('.grid-cell');
const targetTopIndex = Array.from(gridTopCells).findIndex(cell => const targetTopIndex = Array.from(gridTopCells).findIndex(cell =>
cell.querySelector('.propagate-btn') === button cell.querySelector('.propagate-btn[data-column="' + column + '"]')
); );
if (targetTopIndex !== -1) { if (targetTopIndex !== -1) {
@ -761,7 +847,7 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
}); });
}); });
</script> </script>
<!-- script dropdonw senza overlay --> <!-- script dropdown senza overlay -->
<script> <script>
document.addEventListener("DOMContentLoaded", function() { document.addEventListener("DOMContentLoaded", function() {
// Oggetto per memorizzare i dati delle tendine recuperati // Oggetto per memorizzare i dati delle tendine recuperati
@ -823,13 +909,13 @@ 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() {
const columnIndex = this.getAttribute('data-column').replace('manual_', ''); const column = this.getAttribute('data-column');
const input = this.previousElementSibling; const input = this.previousElementSibling;
const value = input.value; const value = input.value;
const gridTopCells = document.querySelector('.grid-top').querySelectorAll('.grid-cell'); const gridTopCells = document.querySelector('.grid-top').querySelectorAll('.grid-cell');
const targetTopIndex = Array.from(gridTopCells).findIndex(cell => const targetTopIndex = Array.from(gridTopCells).findIndex(cell =>
cell.querySelector('.propagate-btn') === button cell.querySelector('.propagate-btn[data-column="' + column + '"]')
); );
if (targetTopIndex !== -1) { if (targetTopIndex !== -1) {
@ -837,14 +923,15 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
rows.forEach(row => { rows.forEach(row => {
const cells = row.querySelectorAll('.grid-cell'); const cells = row.querySelectorAll('.grid-cell');
if (cells.length > targetTopIndex) { if (cells.length > targetTopIndex) {
const targetInput = cells[targetTopIndex].querySelector('select.dropdown-select'); const targetInput = cells[targetTopIndex].querySelector('select.dropdown-select, input');
if (targetInput) { if (targetInput) {
targetInput.value = value; targetInput.value = value;
// Aggiorna visivamente il dropdown if (targetInput.tagName === 'SELECT') {
const event = new Event('change'); const event = new Event('change');
targetInput.dispatchEvent(event); targetInput.dispatchEvent(event);
} }
} }
}
}); });
} }
}); });
@ -852,9 +939,8 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
}); });
</script> </script>
<!-- dropdown with overlay --> <!-- dropdown with overlay -->
<!-- <!-- <script>
<script> document.addEventListener("DOMContentLoaded", function() {
document.addEventListener("DOMContentLoaded", function() {
// Crea un overlay di caricamento // Crea un overlay di caricamento
const loadingOverlay = document.createElement('div'); const loadingOverlay = document.createElement('div');
loadingOverlay.id = 'loading-overlay'; loadingOverlay.id = 'loading-overlay';
@ -976,9 +1062,8 @@ document.addEventListener("DOMContentLoaded", function() {
} }
}); });
}); });
}); });
</script> </script> -->
-->
</body> </body>
</html> </html>