Compare commits

...

2 Commits

Author SHA1 Message Date
RMubarakzyanov ff61456d91 fix ghost columns 2026-06-22 20:43:52 +03:00
solocla 089886cb9a fixed button 2026-06-22 15:39:28 +02:00
2 changed files with 75 additions and 25 deletions
+1 -3
View File
@@ -679,9 +679,7 @@
div.style.position = "relative"; div.style.position = "relative";
let html = ""; let html = "";
if (meta.isAdmin) { html += `<button type="button" class="export-lims-btn action-btn" data-row="${rowIndex}" data-iddatadb="${row.iddatadb}" title="${isExported ? "Already exported" : "Export to LIMS"}" style="background:${isExported ? "#ccc" : "#eb0b0b"}; color:white; border:none; border-radius:5px; cursor:${isExported ? "not-allowed" : "pointer"}; ${isExported ? "opacity:0.5;" : ""}" ${isExported ? "disabled" : ""}><i class="fas fa-upload"></i></button>`;
html += `<button type="button" class="export-lims-btn action-btn" data-row="${rowIndex}" data-iddatadb="${row.iddatadb}" title="${isExported ? "Already exported" : "Export to LIMS"}" style="background:${isExported ? "#ccc" : "#eb0b0b"}; color:white; border:none; border-radius:5px; cursor:${isExported ? "not-allowed" : "pointer"}; ${isExported ? "opacity:0.5;" : ""}" ${isExported ? "disabled" : ""}><i class="fas fa-upload"></i></button>`;
}
html += `<button type="button" class="save-btn action-btn" data-row="${rowIndex}" title="Save" style="background:#28a745; color:white; border:none; border-radius:5px; cursor:pointer;"><i class="fas fa-save"></i></button>`; html += `<button type="button" class="save-btn action-btn" data-row="${rowIndex}" title="Save" style="background:#28a745; color:white; border:none; border-radius:5px; cursor:pointer;"><i class="fas fa-save"></i></button>`;
html += `<button type="button" class="photos-btn action-btn" data-row="${rowIndex}" data-iddatadb="${row.iddatadb}" title="Photos" style="background:#007bff; color:white; border:none; border-radius:5px; cursor:pointer;"><i class="fas fa-camera"></i></button>`; html += `<button type="button" class="photos-btn action-btn" data-row="${rowIndex}" data-iddatadb="${row.iddatadb}" title="Photos" style="background:#007bff; color:white; border:none; border-radius:5px; cursor:pointer;"><i class="fas fa-camera"></i></button>`;
html += `<button type="button" class="parts-btn action-btn" data-row="${rowIndex}" data-iddatadb="${row.iddatadb}" title="Parts" style="background:#ffc107; color:white; border:none; border-radius:5px; cursor:pointer;"><i class="fas fa-puzzle-piece"></i></button>`; html += `<button type="button" class="parts-btn action-btn" data-row="${rowIndex}" data-iddatadb="${row.iddatadb}" title="Parts" style="background:#ffc107; color:white; border:none; border-radius:5px; cursor:pointer;"><i class="fas fa-puzzle-piece"></i></button>`;
+74 -22
View File
@@ -53,7 +53,44 @@ function normalizeColumnIndex($value): int
return 1; return 1;
} }
/**
* Trim a cell value treating invisible/Unicode spaces as empty.
* PHP's native trim() strips only ASCII whitespace (" \t\n\r\0\x0B"), so a cell
* that contains only a non-breaking space (U+00A0), zero-width space (U+200B),
* BOM (U+FEFF) or another Unicode space looks blank to a human but would still
* count as "filled" pulling a ghost column into the import or retaining a
* visually-empty row. Normalize those to a real space before trimming.
*/
function cleanCellText($value): string
{
$raw = (string)$value;
$cleaned = preg_replace(
'/[\x{00A0}\x{200B}\x{FEFF}\x{2000}-\x{200A}\x{202F}\x{205F}\x{3000}]+/u',
' ',
$raw
);
// preg_replace returns null on malformed UTF-8; fall back to the raw value.
return trim($cleaned ?? $raw);
}
try { try {
// Quando il body POST supera post_max_size, PHP scarta $_POST e $_FILES
// (warning "Content-Length exceeds the limit ... in Unknown on line 0") e lo
// script riceve una richiesta vuota. Lo intercettiamo per dare un messaggio
// chiaro invece di "Richiesta non valida".
if (
$_SERVER['REQUEST_METHOD'] === 'POST'
&& empty($_POST) && empty($_FILES)
&& (int)($_SERVER['CONTENT_LENGTH'] ?? 0) > 0
) {
$postMax = ini_get('post_max_size');
throw new Exception(
"Il file caricato supera il limite di upload del server (post_max_size = {$postMax}). " .
"Chiedi all'amministratore di aumentare post_max_size e upload_max_filesize."
);
}
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['excel_file'])) { if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['excel_file'])) {
$template_id = isset($_POST['template_id']) ? intval($_POST['template_id']) : 0; $template_id = isset($_POST['template_id']) ? intval($_POST['template_id']) : 0;
@@ -70,7 +107,7 @@ try {
* Così non dipendiamo solo dal form e siamo sicuri di usare i dati salvati. * Così non dipendiamo solo dal form e siamo sicuri di usare i dati salvati.
*/ */
$stmt = $pdo->prepare(" $stmt = $pdo->prepare("
SELECT SELECT
id, id,
header_row, header_row,
start_column, start_column,
@@ -142,14 +179,14 @@ try {
// Recupera il mapping da template_mapping // Recupera il mapping da template_mapping
$stmt = $pdo->prepare(" $stmt = $pdo->prepare("
SELECT SELECT
field_id AS excel_column, field_id AS excel_column,
field_id AS mysql_column, field_id AS mysql_column,
data_type, data_type,
is_required, is_required,
default_value, default_value,
is_manual is_manual
FROM template_mapping FROM template_mapping
WHERE template_id = ? WHERE template_id = ?
"); ");
$stmt->execute([$template_id]); $stmt->execute([$template_id]);
@@ -162,7 +199,9 @@ try {
$response['error'] = "Nessun mapping trovato per il template con ID $template_id"; $response['error'] = "Nessun mapping trovato per il template con ID $template_id";
} else { } else {
// Carica il file rinominato con PHPSpreadsheet // Carica il file rinominato con PHPSpreadsheet
$spreadsheet = IOFactory::load($destination); $reader = IOFactory::createReaderForFile($destination);
$reader->setReadEmptyCells(false);
$spreadsheet = $reader->load($destination);
$sheetCount = $spreadsheet->getSheetCount(); $sheetCount = $spreadsheet->getSheetCount();
$sheetNames = $spreadsheet->getSheetNames(); $sheetNames = $spreadsheet->getSheetNames();
@@ -189,8 +228,8 @@ try {
error_log("Selected XLS sheet - index: {$xlsSheetIndex}, name: {$selectedSheetName}"); error_log("Selected XLS sheet - index: {$xlsSheetIndex}, name: {$selectedSheetName}");
$highestRow = $worksheet->getHighestRow(); $highestRow = $worksheet->getHighestDataRow();
$highestColumn = $worksheet->getHighestColumn(); $highestColumn = $worksheet->getHighestDataColumn();
$highestColumnIndex = Coordinate::columnIndexFromString($highestColumn); $highestColumnIndex = Coordinate::columnIndexFromString($highestColumn);
$startRow = max(1, $header_row); $startRow = max(1, $header_row);
@@ -199,7 +238,7 @@ try {
// Advance startColumn to first non-empty cell in header row, matching JS behavior // Advance startColumn to first non-empty cell in header row, matching JS behavior
for ($sc = $startColumn; $sc <= $highestColumnIndex; $sc++) { for ($sc = $startColumn; $sc <= $highestColumnIndex; $sc++) {
$cl = Coordinate::stringFromColumnIndex($sc); $cl = Coordinate::stringFromColumnIndex($sc);
$cv = trim((string)($worksheet->getCell($cl . $header_row)->getCalculatedValue() ?? '')); $cv = cleanCellText($worksheet->getCell($cl . $header_row)->getCalculatedValue() ?? '');
if ($cv !== '') { if ($cv !== '') {
$startColumn = $sc; $startColumn = $sc;
@@ -207,6 +246,19 @@ try {
} }
} }
$lastHeaderCol = $startColumn;
for ($hc = $startColumn; $hc <= $highestColumnIndex; $hc++) {
$hl = Coordinate::stringFromColumnIndex($hc);
$hv = cleanCellText($worksheet->getCell($hl . $header_row)->getCalculatedValue() ?? '');
if ($hv !== '') {
$lastHeaderCol = $hc;
}
}
$highestColumnIndex = $lastHeaderCol;
$highestColumn = Coordinate::stringFromColumnIndex($highestColumnIndex);
// Debug dei parametri // Debug dei parametri
error_log( error_log(
"Processing - template_id: $template_id, " . "Processing - template_id: $template_id, " .
@@ -269,7 +321,7 @@ try {
$columnLetter = Coordinate::stringFromColumnIndex($physCol); $columnLetter = Coordinate::stringFromColumnIndex($physCol);
$cell = $worksheet->getCell($columnLetter . $header_row); $cell = $worksheet->getCell($columnLetter . $header_row);
$cellValue = trim((string)($cell ? $cell->getCalculatedValue() : '')); $cellValue = cleanCellText($cell ? $cell->getCalculatedValue() : '');
$cellValue = preg_replace('/[\r\n\t]+/', ' ', $cellValue); $cellValue = preg_replace('/[\r\n\t]+/', ' ', $cellValue);
// Empty headers get __empty_N__ to match mapping page // Empty headers get __empty_N__ to match mapping page
@@ -306,7 +358,7 @@ try {
$filledCount = 0; $filledCount = 0;
foreach ($headerFilledIndices as $idx) { foreach ($headerFilledIndices as $idx) {
if (isset($rowData[$idx]) && trim((string)$rowData[$idx]) !== '') { if (isset($rowData[$idx]) && cleanCellText($rowData[$idx]) !== '') {
$filledCount++; $filledCount++;
} }
} }
@@ -322,13 +374,13 @@ try {
// Recupera routine dal template // Recupera routine dal template
if ($template && !empty($template['idroutine'])) { if ($template && !empty($template['idroutine'])) {
$stmtRoutine = $pdo->prepare(" $stmtRoutine = $pdo->prepare("
SELECT SELECT
idroutine, idroutine,
name, name,
filename, filename,
headerrow, headerrow,
instruction instruction
FROM routine FROM routine
WHERE idroutine = ? WHERE idroutine = ?
"); ");
$stmtRoutine->execute([$template['idroutine']]); $stmtRoutine->execute([$template['idroutine']]);