getConnection(); // Retrieve all mappings $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]); $allMappings = $stmt->fetchAll(PDO::FETCH_ASSOC); if (empty($allMappings)) { header("Location: xlstemplates_grid.php?status=error&message=" . urlencode("Nessun mapping trovato per il template")); exit; } // Trova il main_field $mainFieldMapping = null; foreach ($allMappings as $mapping) { if ($mapping['main_field'] == 1) { $mainFieldMapping = $mapping; break; } } if (!$mainFieldMapping) { $mainFieldMapping = reset(array_filter($allMappings, fn($m) => !$m['is_manual'])); } // Retrieve data from datadb if ($mode === 'edit' && !empty($selected_ids)) { $placeholders = implode(',', array_fill(0, count($selected_ids), '?')); $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.templateid = ? AND d.status = ? AND d.iddatadb IN ($placeholders) "); $params = array_merge([$template_id, $status], $selected_ids); $stmt->execute($params); $importedData = $stmt->fetchAll(PDO::FETCH_ASSOC); $total_records = count($importedData); $total_pages = 1; } else { $stmt = $pdo->prepare("SELECT COUNT(*) FROM datadb WHERE templateid = ? AND status = ?"); $stmt->execute([$template_id, $status]); $total_records = $stmt->fetchColumn(); $total_pages = ceil($total_records / $limit); $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.templateid = ? AND d.status = ? LIMIT ? OFFSET ? "); $stmt->execute([$template_id, $status, $limit, $offset]); $importedData = $stmt->fetchAll(PDO::FETCH_ASSOC); } error_log("Record caricati: " . count($importedData)); $insertedIds = array_column($importedData, 'iddatadb'); // Retrieve manual details $manualDetails = []; if (!empty($insertedIds)) { $placeholders = implode(',', array_fill(0, count($insertedIds), '?')); $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 ($placeholders) "); $stmt->execute($insertedIds); $manualDetails = $stmt->fetchAll(PDO::FETCH_ASSOC); } // Retrieve global mapping for slugs $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']; } ?> Dati Storici - <?= htmlspecialchars($titlewebsite, ENT_QUOTES, 'UTF-8'); ?>
Dati Storici
Nessun dato trovato per il template e lo status selezionato.
Visualizzazione di - di record
prepare("SELECT field_value FROM import_data_details WHERE id = ? AND mapping_id = ?"); $stmt->execute([$row['iddatadb'], $mainFieldMapping['id']]); $mainValue = $stmt->fetchColumn() ?? ''; } ?>
File Azioni
File
Visualizzazione di - di record
"; } $autoIndex = 0; foreach ($allMappings as $mapping) { if (!$mapping['is_manual']) { $inputClass = 'auto-input'; if ($mapping['is_required']) $inputClass .= ' required-input'; if ($mapping['data_type'] === 'SceltaMultipla') { echo "
"; echo ""; echo ""; echo "
"; } else { echo "
"; } $autoIndex++; } } $manualIndex = 0; foreach ($allMappings as $mapping) { if ($mapping['is_manual']) { $fieldValue = $mapping['manual_default'] ?? ''; if ($mapping['data_type'] === 'DATE' && $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 ""; echo ""; } elseif ($mapping['data_type'] === 'DATE') { echo ""; } elseif ($mapping['data_type'] === 'INT') { echo ""; } else { echo ""; } echo ""; echo "
"; $manualIndex++; } } echo "
"; echo "
"; ?>
Save
Photos
Parts
Import Reference Code
$displayName
"; $headerIndex++; } foreach ($allMappings as $mapping) { if (!$mapping['is_manual']) { echo "
" . htmlspecialchars($mapping['field_label']) . "
"; $headerIndex++; } } foreach ($allMappings as $mapping) { if ($mapping['is_manual']) { echo "
" . htmlspecialchars($mapping['field_label']) . "
"; $headerIndex++; } } echo "
AWB Number
"; echo "
Tracking Info
"; ?>
$row): ?>
"; echo "" . htmlspecialchars($row['importreferencecode']) . ""; echo ""; echo "
"; $cellIndex++; foreach ($fixedColumns as $col) { $value = $row[$col] ?? ''; echo "
"; if ($col === 'importdate') { echo "" . htmlspecialchars($value) . ""; echo ""; } elseif ($col === 'filename_import') { echo "File"; echo ""; } elseif ($col === 'status') { $badgeClass = $value === 'i' ? 'status-i' : ($value === 'P' ? 'status-P' : 'status-l'); $badgeText = $value === 'i' ? 'Imported' : ($value === 'P' ? 'Progress' : 'LIMS'); echo "" . htmlspecialchars($badgeText) . ""; echo ""; } echo "
"; $cellIndex++; } $rowDetails = array_filter($manualDetails, fn($d) => $d['datadb_id'] == $row['iddatadb']); $autoIndex = 0; foreach ($allMappings as $mapping) { if (!$mapping['is_manual']) { $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'] === 'DATE') { echo ""; } elseif ($mapping['data_type'] === 'INT') { echo ""; } else { echo ""; } echo "
"; $cellIndex++; $autoIndex++; } } $manualIndex = 0; foreach ($allMappings as $mapping) { if ($mapping['is_manual']) { $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'] === 'DATE' && $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'] === 'DATE') { echo ""; } elseif ($mapping['data_type'] === 'INT') { echo ""; } else { echo ""; } echo "
"; $cellIndex++; $manualIndex++; } } ?>
>
Shipment Info