getConnection(); // Genera un UUID univoco per importreferencecode $importReferenceCode = date('YmdHis') . '-' . uniqid(); // 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, is_visible_import FROM template_mapping WHERE template_id = ?"); $stmt->execute([$template_id]); $allMappings = $stmt->fetchAll(PDO::FETCH_ASSOC); if (empty($allMappings)) { header("Location: import_xls.php?id=$template_id&status=error&message=" . urlencode("Nessun mapping trovato per il template")); exit; } // Trova il campo main_field $mainFieldMapping = null; foreach ($allMappings as $mapping) { if ($mapping['main_field'] == 1 && $mapping['is_visible_import'] == 1) { $mainFieldMapping = $mapping; break; } } // Recupera l'idclient di default dal template (se presente) $template_stmt = $pdo->prepare("SELECT idclient FROM excel_templates WHERE id = ?"); $template_stmt->execute([$template_id]); $template = $template_stmt->fetch(PDO::FETCH_ASSOC); $default_idclient = $template['idclient'] ?? null; $insertedIds = $_POST['inserted_ids'] ?? $_SESSION['inserted_ids']; // Recupera i dati appena inseriti con i nomi degli utenti $stmt = $pdo->prepare(" SELECT d.*, CONCAT(u.first_name, ' ', u.last_name) AS user_name FROM datadb d LEFT JOIN auth_users u ON d.user_id = u.id WHERE d.iddatadb IN (" . implode(',', array_fill(0, count($insertedIds), '?')) . ") "); $stmt->execute($insertedIds); $importedData = $stmt->fetchAll(PDO::FETCH_ASSOC); // Recupera i dettagli manuali da import_data_details $stmt = $pdo->prepare(" SELECT d.id AS detail_id, d.id AS datadb_id, d.mapping_id, d.field_value, m.field_label, m.data_type, m.is_required, m.manual_default FROM import_data_details d JOIN template_mapping m ON d.mapping_id = m.id WHERE d.id IN (" . implode(',', array_fill(0, count($insertedIds), '?')) . ") "); $stmt->execute($insertedIds); $manualDetails = $stmt->fetchAll(PDO::FETCH_ASSOC); // Recupera il mapping globale per mostrare gli slug leggibili $stmt = $pdo->query("SELECT mysql_column_name, user_friendly_slug FROM column_mapping"); $slugMapping = []; foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) { $slugMapping[$row['mysql_column_name']] = $row['user_friendly_slug']; } // ---------------- FIXED FIELDS (from template_fixed_mapping) ---------------- $fixedStmt = $pdo->prepare(" SELECT id, fixed_field_key, is_manual, data_type, is_required, default_value, is_visible_import FROM template_fixed_mapping WHERE template_id = ? AND is_visible_import = 1 ORDER BY id "); $fixedStmt->execute([$template_id]); $fixedFields = $fixedStmt->fetchAll(PDO::FETCH_ASSOC); // helper default (DATE can use 'today' if you already use it elsewhere) function fixedDefaultValue(array $f): string { $v = $f['default_value'] ?? ''; if ($f['data_type'] === 'DATE' && $v === 'today') return date('Y-m-d'); return (string)$v; } ?> Edit Imported Data - <?= htmlspecialchars($titlewebsite, ENT_QUOTES, 'UTF-8'); ?>
Modifica Dati Importati
"; echo ""; echo ""; echo ""; } elseif ($mainFieldMapping['data_type'] === 'Data') { echo ""; echo ""; } elseif ($mainFieldMapping['data_type'] === 'INT') { echo ""; echo ""; } else { echo ""; echo ""; } ?>
"; echo ""; echo ""; echo "
"; } else { echo "
"; } $autoIndex++; } } $manualIndex = 0; foreach ($allMappings as $mapping) { if ($mapping['is_manual'] && $mapping['main_field'] != 1 && $mapping['is_visible_import'] == 1) { $fieldValue = $mapping['manual_default'] ?? ''; if ($mapping['data_type'] === 'Data' && $mapping['manual_default'] === 'today') { $fieldValue = date('Y-m-d'); } $inputClass = 'manual-input'; if ($mapping['is_required']) $inputClass .= ' required-input'; echo "
"; if ($mapping['data_type'] === 'SceltaMultipla') { echo ""; } elseif ($mapping['data_type'] === 'Data') { echo ""; } elseif ($mapping['data_type'] === 'INT') { echo ""; } else { echo ""; } echo ""; echo "
"; $manualIndex++; } } // Aggiunta per Tested Component (senza propagate) echo "
"; echo "
"; echo "
"; echo "
"; echo "
"; echo "
"; // ---------------- FIXED FIELDS TOP (propagate) ---------------- if (!empty($fixedFields)) { foreach ($fixedFields as $fx => $f) { $key = $f['fixed_field_key']; // datadb column $val = fixedDefaultValue($f); $isRequired = ((int)$f['is_required'] === 1); $inputClass = 'manual-input' . ($isRequired ? ' required-input' : ''); $topRequiredClass = ($isRequired && ($val === '' || $val === null)) ? 'missing-required' : ''; echo "
"; // Forza DATE anche se per errore nel DB è diversa $isDate = ($f['data_type'] === 'DATE' || $key === 'ConsegnaRichiesta'); if ($isDate) { echo ""; } else { $isApiField = in_array($key, [ 'MoltiplicatorePrezzo', 'ClienteResponsabile', 'AnagraficaCertestObject', 'AnagraficaCertestService' ], true); if ($isApiField) { $placeholder = ($key === 'ClienteResponsabile') ? 'Seleziona cliente prima...' : 'Seleziona...'; echo ""; } else { echo ""; } } // UNA SOLA freccia echo ""; echo "
"; } } ?>
Actions
Client
Status
" . htmlspecialchars($mapping['field_label']) . "
"; $headerIndex++; } } foreach ($allMappings as $mapping) { if ($mapping['is_manual'] && $mapping['main_field'] != 1 && $mapping['is_visible_import'] == 1) { echo "
" . htmlspecialchars($mapping['field_label']) . "
"; $headerIndex++; } } // Aggiunta header per Tested Component echo "
Tested Component
"; $headerIndex++; echo "
AWB Number
"; $headerIndex++; echo "
Tracking Info
"; $headerIndex++; echo "
Import Reference Code
"; $headerIndex++; echo "
" . ($slugMapping['filename_import'] ?? 'filename_import') . "
"; $headerIndex++; echo "
" . ($slugMapping['importdate'] ?? 'importdate') . "
"; ?> " . htmlspecialchars($label) . "
"; $headerIndex++; } } ?>
$row): ?>
hasRole('Admin'))) : ?>
$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'] === 'Data' && $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'; ?>
> > >
$d['datadb_id'] == $row['iddatadb']); $autoIndex = 0; foreach ($allMappings as $mapping) { 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 = reset($detail) ?: ['field_value' => $mapping['manual_default']]; $fieldValue = $detail['field_value'] ?? $mapping['manual_default'] ?? ''; $requiredClass = ($mapping['is_required'] && (is_null($fieldValue) || $fieldValue === '')) ? 'missing-required' : ''; $inputClass = 'auto-input'; if ($mapping['is_required']) $inputClass .= ' required-input'; echo "
"; if ($mapping['data_type'] === 'SceltaMultipla') { echo ""; } elseif ($mapping['data_type'] === 'Data') { echo ""; } elseif ($mapping['data_type'] === 'INT') { echo ""; } else { echo ""; } echo "
"; $cellIndex++; $autoIndex++; } } $manualIndex = 0; foreach ($allMappings as $mapping) { 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 = reset($detail) ?: ['field_value' => $mapping['manual_default']]; $fieldValue = $detail['field_value'] ?? $mapping['manual_default'] ?? ''; if ($mapping['data_type'] === 'Data' && $mapping['manual_default'] === 'today' && empty($fieldValue)) { $fieldValue = date('Y-m-d'); } $requiredClass = ($mapping['is_required'] && (is_null($fieldValue) || $fieldValue === '')) ? 'missing-required' : ''; $inputClass = 'manual-input'; if ($mapping['is_required']) $inputClass .= ' required-input'; echo "
"; if ($mapping['data_type'] === 'SceltaMultipla') { echo ""; } elseif ($mapping['data_type'] === 'Data') { echo ""; } elseif ($mapping['data_type'] === 'INT') { echo ""; } else { echo ""; } echo "
"; $cellIndex++; $manualIndex++; } } // Aggiunta cella per Tested Component echo "
"; echo ""; echo ""; echo "
"; $cellIndex++; ?>
Shipment Info
"; if ($f['data_type'] === 'DATE') { echo ""; } else { // INT → diventa select se è uno dei campi API $isApiField = in_array($key, ['MoltiplicatorePrezzo', 'ClienteResponsabile', 'AnagraficaCertestObject', 'AnagraficaCertestService']); $selectClass = $isApiField ? 'api-fixed-select' : ''; echo ""; } echo "
"; $cellIndex++; } } ?>