From 06dd7883c249293c47fcc348e83d27d7cef0f521 Mon Sep 17 00:00:00 2001 From: Claudio Date: Wed, 27 Aug 2025 12:13:11 +0200 Subject: [PATCH] update historical trf and navbar --- public/userarea/delete_record.php | 64 ++ public/userarea/historical_trf.php | 1158 ++++++++++++++++------------ public/userarea/import_xls2.php | 7 +- public/userarea/include/navbar.php | 3 +- 4 files changed, 744 insertions(+), 488 deletions(-) create mode 100644 public/userarea/delete_record.php diff --git a/public/userarea/delete_record.php b/public/userarea/delete_record.php new file mode 100644 index 0000000..87f0b9c --- /dev/null +++ b/public/userarea/delete_record.php @@ -0,0 +1,64 @@ + false, 'message' => 'ID non valido']); + exit; +} + +// Connessione al database +try { + $db = DBHandlerSelect::getInstance(); + $pdo = $db->getConnection(); +} catch (Exception $e) { + http_response_code(500); + echo json_encode(['success' => false, 'message' => 'Errore di connessione al database: ' . $e->getMessage()]); + error_log("Errore di connessione al database: " . $e->getMessage()); + exit; +} + +// Inizia una transazione +$pdo->beginTransaction(); + +try { + // Elimina i dettagli associati dal tavolo import_data_details + $stmt = $pdo->prepare("DELETE FROM import_data_details WHERE id = ?"); + $stmt->execute([$iddatadb]); + + // Elimina il record principale dal tavolo datadb + $stmt = $pdo->prepare("DELETE FROM datadb WHERE iddatadb = ?"); + $stmt->execute([$iddatadb]); + + // Verifica se il record è stato eliminato + if ($stmt->rowCount() > 0) { + $pdo->commit(); + echo json_encode(['success' => true, 'message' => 'Record eliminato con successo']); + error_log("Record con iddatadb=$iddatadb eliminato con successo"); + } else { + $pdo->rollBack(); + http_response_code(404); + echo json_encode(['success' => false, 'message' => 'Record non trovato']); + error_log("Record con iddatadb=$iddatadb non trovato"); + } +} catch (Exception $e) { + $pdo->rollBack(); + http_response_code(500); + echo json_encode(['success' => false, 'message' => 'Errore durante la cancellazione: ' . $e->getMessage()]); + error_log("Errore durante la cancellazione del record con iddatadb=$iddatadb: " . $e->getMessage()); +} diff --git a/public/userarea/historical_trf.php b/public/userarea/historical_trf.php index 968012c..4dd1954 100644 --- a/public/userarea/historical_trf.php +++ b/public/userarea/historical_trf.php @@ -27,7 +27,11 @@ if (!in_array($status, ['i', 'P', 'l'])) { $is_readonly = in_array($status, ['P', 'l']); -// Paginazione +// Gestione modalità: lista (default per status 'i') o edit +$mode = $_GET['mode'] ?? ($status === 'i' ? 'list' : 'edit'); +$selected_ids = $_POST['selected_ids'] ?? []; + +// Paginazione (solo per mode 'list') $page = max(1, intval($_GET['page'] ?? 1)); $limit = 20; $offset = ($page - 1) * $limit; @@ -36,14 +40,8 @@ $offset = ($page - 1) * $limit; $db = DBHandlerSelect::getInstance(); $pdo = $db->getConnection(); -// Conta il numero totale di record -$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); - // Retrieve all mappings -$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]); $allMappings = $stmt->fetchAll(PDO::FETCH_ASSOC); @@ -52,16 +50,48 @@ if (empty($allMappings)) { 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 -$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); +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)); @@ -436,6 +466,39 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) { background-color: #d4edda; transition: background-color 0.5s ease; } + + .list-table { + width: 100%; + border-collapse: collapse; + } + + .list-table th, + .list-table td { + padding: 10px; + border: 1px solid #dee2e6; + text-align: left; + } + + .list-table th { + background-color: #e9ecef; + } + + .delete-btn { + background: #dc3545; + color: white; + border: none; + padding: 5px 10px; + border-radius: 4px; + cursor: pointer; + } + + .delete-btn:hover { + background: #c82333; + } + + .proceed-btn { + margin-top: 20px; + } Dati Storici - <?= htmlspecialchars($titlewebsite, ENT_QUOTES, 'UTF-8'); ?> @@ -454,7 +517,7 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
- @@ -468,517 +531,642 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) { Nessun dato trovato per il template e lo status selezionato.
-
-
- Visualizzazione di - di record + +
+
+
+ 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() ?? ''; + } + ?> + + + + + + + + + +
FileAzioni
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 = $slugMapping[$col] ?? $col; + echo "
$displayName
"; + $headerIndex++; } - $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++; + echo "
" . htmlspecialchars($mapping['field_label']) . "
"; + $headerIndex++; } } - $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 "
" . htmlspecialchars($mapping['field_label']) . "
"; + $headerIndex++; } } - echo "
"; - echo "
"; + echo "
AWB Number
"; + echo "
Tracking Info
"; ?>
- -
-
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 ""; - } + $row): ?> +
+
+ + + + + +
+
+ +
+
+ +
+ "; + echo "" . htmlspecialchars($row['importreferencecode']) . ""; + 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 ""; + 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++; - $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'); + $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++; } - $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++; } - } - ?> -
- - > - + $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 + +
-
- Shipment Info - -
-
- -
-
+ - - + +
  • + +
  • + +
  • + Successivo +
  • + + + + + +
    + + -
    - - - - - - - - - + + + + + - - \ No newline at end of file + \ No newline at end of file diff --git a/public/userarea/import_xls2.php b/public/userarea/import_xls2.php index 4cff102..2a4873b 100644 --- a/public/userarea/import_xls2.php +++ b/public/userarea/import_xls2.php @@ -126,7 +126,11 @@ error_log("Loaded template: " . print_r($template, true));
    - +
    @@ -136,6 +140,7 @@ error_log("Loaded template: " . print_r($template, true));
    +
    diff --git a/public/userarea/include/navbar.php b/public/userarea/include/navbar.php index 505d1e2..a99b4db 100644 --- a/public/userarea/include/navbar.php +++ b/public/userarea/include/navbar.php @@ -24,8 +24,7 @@ -->
  • XLS Import
  • -
  • Historical TRF -
  • +