1325 lines
79 KiB
PHP
1325 lines
79 KiB
PHP
<?php
|
|
// Enable errors for debugging
|
|
ini_set('display_errors', 1);
|
|
ini_set('display_startup_errors', 1);
|
|
error_reporting(E_ALL);
|
|
ini_set('log_errors', 1);
|
|
ini_set('error_log', __DIR__ . '/historical_debug.log');
|
|
if (!file_exists(__DIR__ . '/historical_debug.log')) {
|
|
file_put_contents(__DIR__ . '/historical_debug.log', "Inizio caricamento dati storici alle " . date('Y-m-d H:i:s') . "\n", FILE_APPEND);
|
|
}
|
|
|
|
// Initial log
|
|
error_log("Inizio caricamento dati storici alle " . date('Y-m-d H:i:s'));
|
|
|
|
include('include/headscript.php');
|
|
|
|
$template_id = intval($_GET['id'] ?? 0);
|
|
if (!$template_id) {
|
|
header("Location: xlstemplates_grid.php?status=error&message=" . urlencode("Template ID non valido"));
|
|
exit;
|
|
}
|
|
|
|
$status = $_GET['status'] ?? 'i';
|
|
if (!in_array($status, ['i', 'P', 'l'])) {
|
|
$status = 'i';
|
|
}
|
|
|
|
$is_readonly = in_array($status, ['P', 'l']);
|
|
|
|
// 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;
|
|
|
|
// Connessione al database
|
|
$db = DBHandlerSelect::getInstance();
|
|
$pdo = $db->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) {
|
|
$filtered = array_filter($allMappings, fn($m) => !$m['is_manual']);
|
|
$mainFieldMapping = reset($filtered);
|
|
}
|
|
|
|
// 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'];
|
|
}
|
|
?>
|
|
|
|
<!doctype html>
|
|
<html lang="en">
|
|
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<link rel="icon" href="assets/images/favicon-32x32.png" type="image/png" />
|
|
<?php include('cssinclude.php'); ?>
|
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.6.0/css/all.min.css" crossorigin="anonymous" referrerpolicy="no-referrer" />
|
|
<style>
|
|
input.auto-input,
|
|
select.auto-input {
|
|
background-color: #d4edda;
|
|
}
|
|
|
|
input.manual-input,
|
|
select.manual-input {
|
|
background-color: #fff3cd;
|
|
}
|
|
|
|
input.required-input,
|
|
select.required-input {
|
|
background-color: #f8d7da;
|
|
}
|
|
|
|
input,
|
|
select {
|
|
width: 100%;
|
|
box-sizing: border-box;
|
|
border: 1px solid #ced4da;
|
|
border-radius: 4px;
|
|
padding: 5px;
|
|
font-size: 14px;
|
|
}
|
|
|
|
input[readonly],
|
|
select[readonly] {
|
|
background-color: #e9ecef;
|
|
cursor: not-allowed;
|
|
}
|
|
|
|
input,
|
|
select {
|
|
color: #333;
|
|
}
|
|
|
|
.status-badge {
|
|
display: inline-block;
|
|
padding: 5px 10px;
|
|
border-radius: 12px;
|
|
font-size: 12px;
|
|
font-weight: 500;
|
|
}
|
|
|
|
.status-i {
|
|
background-color: #007bff;
|
|
color: white;
|
|
}
|
|
|
|
.status-P {
|
|
background-color: #ffc107;
|
|
color: black;
|
|
}
|
|
|
|
.status-l {
|
|
background-color: #28a745;
|
|
color: white;
|
|
}
|
|
|
|
.grid-container {
|
|
overflow-x: auto;
|
|
max-width: 100%;
|
|
margin-bottom: 20px;
|
|
border: 1px solid #dee2e6;
|
|
border-radius: 0.25rem;
|
|
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
|
scroll-behavior: smooth;
|
|
position: relative;
|
|
}
|
|
|
|
.grid-container::-webkit-scrollbar {
|
|
height: 12px;
|
|
}
|
|
|
|
.grid-container::-webkit-scrollbar-track {
|
|
background: #f1f1f1;
|
|
}
|
|
|
|
.grid-container::-webkit-scrollbar-thumb {
|
|
background: #888;
|
|
}
|
|
|
|
.grid-container::-webkit-scrollbar-thumb:hover {
|
|
background: #555;
|
|
}
|
|
|
|
.scrollbar-container {
|
|
width: 100%;
|
|
overflow-x: auto;
|
|
height: 12px;
|
|
background: #f1f1f1;
|
|
margin-bottom: 10px;
|
|
display: none;
|
|
}
|
|
|
|
.scrollbar-container::-webkit-scrollbar {
|
|
height: 12px;
|
|
}
|
|
|
|
.scrollbar-container::-webkit-scrollbar-track {
|
|
background: #f1f1f1;
|
|
}
|
|
|
|
.scrollbar-container::-webkit-scrollbar-thumb {
|
|
background: #888;
|
|
}
|
|
|
|
.scrollbar-container::-webkit-scrollbar-thumb:hover {
|
|
background: #555;
|
|
}
|
|
|
|
.grid-row {
|
|
display: flex;
|
|
align-items: center;
|
|
padding: 0;
|
|
border-bottom: 1px solid #dee2e6;
|
|
}
|
|
|
|
.grid-row:last-child {
|
|
border-bottom: none;
|
|
}
|
|
|
|
.grid-row:nth-child(even) {
|
|
background-color: #f8f9fa;
|
|
}
|
|
|
|
.grid-row:hover {
|
|
background-color: #e9ecef;
|
|
}
|
|
|
|
.grid-header,
|
|
.grid-cell {
|
|
flex: 1;
|
|
min-width: 100px;
|
|
padding: 12px 15px;
|
|
border-right: 1px solid #dee2e6;
|
|
overflow: hidden;
|
|
text-overflow: ellipsis;
|
|
white-space: nowrap;
|
|
transition: max-width 0.3s ease;
|
|
box-sizing: border-box;
|
|
}
|
|
|
|
.grid-header {
|
|
font-weight: 600;
|
|
background-color: #e9ecef;
|
|
color: #495057;
|
|
border-bottom: 2px solid #dee2e6;
|
|
position: relative;
|
|
}
|
|
|
|
.grid-header:last-child,
|
|
.grid-cell:last-child {
|
|
border-right: none;
|
|
}
|
|
|
|
.grid-cell.expanded {
|
|
max-width: 500px !important;
|
|
white-space: normal !important;
|
|
overflow-wrap: break-word !important;
|
|
background-color: #e0f7fa !important;
|
|
flex: 0 0 500px !important;
|
|
}
|
|
|
|
.resizer {
|
|
width: 5px;
|
|
height: 100%;
|
|
background: #ddd;
|
|
cursor: col-resize;
|
|
position: absolute;
|
|
right: 0;
|
|
top: 0;
|
|
bottom: 0;
|
|
}
|
|
|
|
.resizer:hover {
|
|
background: #999;
|
|
}
|
|
|
|
.grid-top {
|
|
display: flex;
|
|
align-items: flex-start;
|
|
padding: 10px 0;
|
|
}
|
|
|
|
.grid-top .grid-cell {
|
|
padding: 5px 10px;
|
|
flex: 0 0 150px;
|
|
position: relative;
|
|
display: flex;
|
|
flex-direction: column;
|
|
align-items: center;
|
|
}
|
|
|
|
.propagate-btn {
|
|
background: none;
|
|
border: none;
|
|
cursor: pointer;
|
|
color: #666;
|
|
font-size: 14px;
|
|
margin-top: 5px;
|
|
padding: 2px 5px;
|
|
border-radius: 3px;
|
|
transition: color 0.3s ease;
|
|
}
|
|
|
|
.propagate-btn:hover {
|
|
color: #28a745;
|
|
}
|
|
|
|
.propagate-btn:disabled {
|
|
color: #ccc;
|
|
cursor: not-allowed;
|
|
}
|
|
|
|
.awb-input {
|
|
width: 40% !important;
|
|
display: inline-block;
|
|
margin-right: 5px;
|
|
}
|
|
|
|
.carrier-select {
|
|
width: 40% !important;
|
|
display: inline-block;
|
|
border: 1px solid #ced4da;
|
|
border-radius: 4px;
|
|
padding: 5px;
|
|
font-size: 14px;
|
|
margin-right: 5px;
|
|
}
|
|
|
|
.go-btn {
|
|
width: 15% !important;
|
|
display: inline-block;
|
|
}
|
|
|
|
.tracking-info .tracking-result {
|
|
font-size: 12px;
|
|
color: #495057;
|
|
}
|
|
|
|
.modal {
|
|
display: none;
|
|
position: fixed;
|
|
z-index: 1050;
|
|
left: 0;
|
|
top: 0;
|
|
width: 100%;
|
|
height: 100%;
|
|
overflow: auto;
|
|
background-color: rgba(0, 0, 0, 0.5);
|
|
}
|
|
|
|
#partsModal {
|
|
z-index: 1200 !important;
|
|
}
|
|
|
|
.modal-content {
|
|
background-color: #fefefe;
|
|
margin: 15% auto;
|
|
padding: 20px;
|
|
border: 1px solid #888;
|
|
width: 80%;
|
|
max-width: 600px;
|
|
border-radius: 8px;
|
|
position: relative;
|
|
}
|
|
|
|
.close-btn {
|
|
color: #aaa;
|
|
float: right;
|
|
font-size: 28px;
|
|
font-weight: bold;
|
|
cursor: pointer;
|
|
}
|
|
|
|
.close-btn:hover,
|
|
.close-btn:focus {
|
|
color: #000;
|
|
text-decoration: none;
|
|
}
|
|
|
|
.overlay {
|
|
display: none;
|
|
position: fixed;
|
|
top: 0;
|
|
left: 0;
|
|
width: 100%;
|
|
height: 100%;
|
|
background: rgba(0, 0, 0, 0.5);
|
|
z-index: 1049;
|
|
}
|
|
|
|
.grid-cell.missing-required {
|
|
border: 2px solid red;
|
|
background-color: #ffe6e6;
|
|
}
|
|
|
|
.dropdown-select {
|
|
width: 100%;
|
|
box-sizing: border-box;
|
|
border: 1px solid #ced4da;
|
|
border-radius: 4px;
|
|
padding: 5px;
|
|
font-size: 14px;
|
|
appearance: none;
|
|
background: white url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" fill="%23333"><path d="M7.293 4.293a1 1 0 011.414 0L10 6.586l1.293-1.293a1 1 0 111.414 1.414l-2 2a1 1 0 01-1.414 0l-2-2a1 1 0 010-1.414z"/></svg>') no-repeat right 5px center;
|
|
}
|
|
|
|
.dropdown-select:focus {
|
|
outline: none;
|
|
border-color: #80bdff;
|
|
box-shadow: 0 0 5px rgba(0, 123, 255, 0.5);
|
|
}
|
|
|
|
.scroll-controls {
|
|
margin-bottom: 10px;
|
|
}
|
|
|
|
#searchInput {
|
|
width: 300px;
|
|
padding: 8px;
|
|
border-radius: 4px;
|
|
border: 1px solid #ced4da;
|
|
margin-bottom: 10px;
|
|
}
|
|
|
|
#noResults {
|
|
display: none;
|
|
color: #dc3545;
|
|
margin-top: 10px;
|
|
}
|
|
|
|
.flash-success {
|
|
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;
|
|
}
|
|
|
|
.grid-cell.button-cell,
|
|
.grid-header.button-header {
|
|
min-width: 210px !important;
|
|
flex: 0 0 210px !important;
|
|
}
|
|
|
|
.action-btn {
|
|
padding: 6px 8px;
|
|
margin-right: 5px;
|
|
border: none;
|
|
border-radius: 5px;
|
|
cursor: pointer;
|
|
width: 50px;
|
|
box-sizing: border-box;
|
|
}
|
|
</style>
|
|
<title>Dati Storici - <?= htmlspecialchars($titlewebsite, ENT_QUOTES, 'UTF-8'); ?></title>
|
|
</head>
|
|
|
|
<body>
|
|
<div class="wrapper">
|
|
<?php include('include/navbar.php'); ?>
|
|
<?php include('include/topbar.php'); ?>
|
|
<div class="page-wrapper">
|
|
<div class="page-content">
|
|
<div class="card radius-10">
|
|
<div class="card-header">
|
|
<div class="d-flex align-items-center justify-content-between">
|
|
<div>
|
|
<h6 class="mb-0">Dati Storici</h6>
|
|
</div>
|
|
<div>
|
|
<label for="status-filter">Filtra per Status:</label>
|
|
<select id="status-filter">
|
|
<option value="i" <?= $status === 'i' ? 'selected' : '' ?>>Imported (i)</option>
|
|
<option value="P" <?= $status === 'P' ? 'selected' : '' ?>>Progress (P)</option>
|
|
<option value="l" <?= $status === 'l' ? 'selected' : '' ?>>LIMS (l)</option>
|
|
</select>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="card-body">
|
|
<?php if (empty($importedData)): ?>
|
|
<div class="alert alert-info text-center">
|
|
Nessun dato trovato per il template e lo status selezionato.
|
|
</div>
|
|
<?php else: ?>
|
|
<?php if ($mode === 'list'): ?>
|
|
<form id="selectForm" method="POST" action="historical_trf.php?id=<?= $template_id ?>&status=<?= $status ?>&mode=edit">
|
|
<div class="mb-3 d-flex align-items-center justify-content-between">
|
|
<div>
|
|
Visualizzazione di <?= min($offset + 1, $total_records) ?>-<?= min($offset + count($importedData), $total_records) ?> di <?= $total_records ?> record
|
|
</div>
|
|
<div>
|
|
<input type="text" id="searchInput" placeholder="Cerca in tutte le colonne..." class="form-control form-control-sm" style="width: 300px;">
|
|
<div id="noResults" class="text-danger" style="display:none;">Nessun risultato trovato</div>
|
|
</div>
|
|
</div>
|
|
<table class="list-table">
|
|
<thead>
|
|
<tr>
|
|
<th><input type="checkbox" id="selectAll"></th>
|
|
<th><?= htmlspecialchars($mainFieldMapping['field_label'] ?? 'Main Field') ?></th>
|
|
<th>File</th>
|
|
<th><?= htmlspecialchars($slugMapping['importdate'] ?? 'Import Date') ?></th>
|
|
<th>Azioni</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($importedData as $row): ?>
|
|
<?php
|
|
$mainValue = '';
|
|
if ($mainFieldMapping) {
|
|
$stmt = $pdo->prepare("SELECT field_value FROM import_data_details WHERE id = ? AND mapping_id = ?");
|
|
$stmt->execute([$row['iddatadb'], $mainFieldMapping['id']]);
|
|
$mainValue = $stmt->fetchColumn() ?? '';
|
|
}
|
|
?>
|
|
<tr>
|
|
<td><input type="checkbox" name="selected_ids[]" value="<?= $row['iddatadb'] ?>"></td>
|
|
<td><?= htmlspecialchars($mainValue) ?></td>
|
|
<td><a href="imported_trf/<?= htmlspecialchars($row['filename_import']) ?>" target="_blank">File</a></td>
|
|
<td><?= htmlspecialchars($row['importdate']) ?></td>
|
|
<td>
|
|
<button type="button" class="delete-btn" data-id="<?= $row['iddatadb'] ?>"><i class="fas fa-trash"></i></button>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
<nav aria-label="Page navigation" class="mt-3">
|
|
<ul class="pagination justify-content-center">
|
|
<li class="page-item <?= $page <= 1 ? 'disabled' : '' ?>">
|
|
<a class="page-link" href="historical_trf.php?id=<?= $template_id ?>&status=<?= $status ?>&mode=list&page=<?= $page - 1 ?>">Precedente</a>
|
|
</li>
|
|
<?php for ($i = 1; $i <= $total_pages; $i++): ?>
|
|
<li class="page-item <?= $i === $page ? 'active' : '' ?>">
|
|
<a class="page-link" href="historical_trf.php?id=<?= $template_id ?>&status=<?= $status ?>&mode=list&page=<?= $i ?>"><?= $i ?></a>
|
|
</li>
|
|
<?php endfor; ?>
|
|
<li class="page-item <?= $page >= $total_pages ? 'disabled' : '' ?>">
|
|
<a class="page-link" href="historical_trf.php?id=<?= $template_id ?>&status=<?= $status ?>&mode=list&page=<?= $page + 1 ?>">Successivo</a>
|
|
</li>
|
|
</ul>
|
|
</nav>
|
|
<div class="text-center">
|
|
<button type="submit" class="btn btn-primary proceed-btn">Prosegui con Modifica Massiva</button>
|
|
</div>
|
|
</form>
|
|
<?php else: ?>
|
|
<div class="mb-3 d-flex align-items-center justify-content-between">
|
|
<div>
|
|
Visualizzazione di <?= min($offset + 1, $total_records) ?>-<?= min($offset + count($importedData), $total_records) ?> di <?= $total_records ?> record
|
|
</div>
|
|
<div class="d-flex align-items-center">
|
|
<input type="text" id="searchInput" placeholder="Cerca..." class="form-control form-control-sm me-2" style="width: 200px;">
|
|
<button type="button" class="btn btn-secondary btn-sm me-1 scroll-left">
|
|
<i class="fas fa-arrow-left"></i>
|
|
</button>
|
|
<button type="button" class="btn btn-secondary btn-sm scroll-right">
|
|
<i class="fas fa-arrow-right"></i>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
<div id="noResults" class="text-danger" style="display:none;">Nessun risultato trovato</div>
|
|
<div class="scrollbar-container"></div>
|
|
|
|
<form id="editForm">
|
|
<div class="grid-container">
|
|
<div class="grid-top">
|
|
<div class="grid-cell actions-cell" style="flex: 0 0 200px;"></div>
|
|
<?php
|
|
// Campo con main_field = 1
|
|
if ($mainFieldMapping) {
|
|
$inputClass = $mainFieldMapping['is_manual'] ? 'manual-input' : 'auto-input';
|
|
if ($mainFieldMapping['is_required']) $inputClass .= ' required-input';
|
|
$index = $mainFieldMapping['is_manual'] ? "manual_0" : "auto_0";
|
|
echo "<div class='grid-cell' style='flex: 0 0 150px;'>";
|
|
if ($mainFieldMapping['data_type'] === 'SceltaMultipla') {
|
|
$fieldValue = $mainFieldMapping['manual_default'] ?? '';
|
|
echo "<select class='custom-field dropdown-select $inputClass' data-column='$index' data-field-id='{$mainFieldMapping['field_id']}' data-selected-value='" . htmlspecialchars($fieldValue) . "' " . ($mainFieldMapping['is_required'] ? 'required' : '') . ($is_readonly ? ' readonly' : '') . ">";
|
|
echo "<option value=''>Seleziona...</option>";
|
|
echo "</select>";
|
|
echo "<button type='button' class='propagate-btn' data-column='$index' " . ($is_readonly ? 'disabled' : '') . "><i class='fas fa-arrow-down'></i></button>";
|
|
} else {
|
|
$fieldValue = $mainFieldMapping['manual_default'] ?? '';
|
|
if ($mainFieldMapping['data_type'] === 'DATE' && $mainFieldMapping['manual_default'] === 'today') {
|
|
$fieldValue = date('Y-m-d');
|
|
}
|
|
if ($mainFieldMapping['data_type'] === 'DATE') {
|
|
echo "<input type='date' class='custom-field $inputClass' data-column='$index' value='" . htmlspecialchars($fieldValue) . "' " . ($mainFieldMapping['is_required'] ? 'required' : '') . ($is_readonly ? ' readonly' : '') . ">";
|
|
} elseif ($mainFieldMapping['data_type'] === 'INT') {
|
|
echo "<input type='number' class='custom-field $inputClass' data-column='$index' value='" . htmlspecialchars($fieldValue) . "' " . ($mainFieldMapping['is_required'] ? 'required' : '') . ($is_readonly ? ' readonly' : '') . ">";
|
|
} else {
|
|
echo "<input type='text' class='custom-field $inputClass' data-column='$index' value='" . htmlspecialchars($fieldValue) . "' " . ($mainFieldMapping['is_required'] ? 'required' : '') . ($is_readonly ? ' readonly' : '') . ">";
|
|
}
|
|
echo "<button type='button' class='propagate-btn' data-column='$index' " . ($is_readonly ? 'disabled' : '') . "><i class='fas fa-arrow-down'></i></button>";
|
|
}
|
|
echo "</div>";
|
|
} else {
|
|
echo "<div class='grid-cell' style='flex: 0 0 150px;'></div>";
|
|
}
|
|
// Status (subito dopo main_field)
|
|
$fixedColumnsReduced = ['status'];
|
|
foreach ($fixedColumnsReduced as $col) {
|
|
echo "<div class='grid-cell' style='flex: 0 0 150px;'></div>";
|
|
}
|
|
// Campi automatici (escluso main_field)
|
|
$autoIndex = ($mainFieldMapping && !$mainFieldMapping['is_manual']) ? 1 : 0;
|
|
foreach ($allMappings as $mapping) {
|
|
if (!$mapping['is_manual'] && $mapping['main_field'] != 1) {
|
|
$inputClass = 'auto-input';
|
|
if ($mapping['is_required']) $inputClass .= ' required-input';
|
|
echo "<div class='grid-cell' style='flex: 0 0 150px;'>";
|
|
if ($mapping['data_type'] === 'SceltaMultipla') {
|
|
$fieldValue = $mapping['manual_default'] ?? '';
|
|
echo "<select class='custom-field dropdown-select $inputClass' data-column='auto_$autoIndex' data-field-id='{$mapping['field_id']}' data-selected-value='" . htmlspecialchars($fieldValue) . "' " . ($mapping['is_required'] ? 'required' : '') . ($is_readonly ? ' readonly' : '') . ">";
|
|
echo "<option value=''>Seleziona...</option>";
|
|
echo "</select>";
|
|
echo "<button type='button' class='propagate-btn' data-column='auto_$autoIndex' " . ($is_readonly ? 'disabled' : '') . "><i class='fas fa-arrow-down'></i></button>";
|
|
} else {
|
|
echo "<div style='height: 34px;'></div>";
|
|
}
|
|
echo "</div>";
|
|
$autoIndex++;
|
|
}
|
|
}
|
|
// Campi manuali (escluso main_field)
|
|
$manualIndex = ($mainFieldMapping && $mainFieldMapping['is_manual']) ? 1 : 0;
|
|
foreach ($allMappings as $mapping) {
|
|
if ($mapping['is_manual'] && $mapping['main_field'] != 1) {
|
|
$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 "<div class='grid-cell' style='flex: 0 0 150px;'>";
|
|
if ($mapping['data_type'] === 'SceltaMultipla') {
|
|
echo "<select class='custom-field dropdown-select $inputClass' data-column='manual_$manualIndex' data-field-id='{$mapping['field_id']}' data-selected-value='" . htmlspecialchars($fieldValue) . "' " . ($mapping['is_required'] ? 'required' : '') . ($is_readonly ? ' readonly' : '') . ">";
|
|
echo "<option value=''>Seleziona...</option>";
|
|
echo "</select>";
|
|
echo "<button type='button' class='propagate-btn' data-column='manual_$manualIndex' " . ($is_readonly ? 'disabled' : '') . "><i class='fas fa-arrow-down'></i></button>";
|
|
} elseif ($mapping['data_type'] === 'DATE') {
|
|
echo "<input type='date' class='custom-field $inputClass' data-column='manual_$manualIndex' value='" . htmlspecialchars($fieldValue) . "' " . ($mapping['is_required'] ? 'required' : '') . ($is_readonly ? ' readonly' : '') . ">";
|
|
echo "<button type='button' class='propagate-btn' data-column='manual_$manualIndex' " . ($is_readonly ? 'disabled' : '') . "><i class='fas fa-arrow-down'></i></button>";
|
|
} elseif ($mapping['data_type'] === 'INT') {
|
|
echo "<input type='number' class='custom-field $inputClass' data-column='manual_$manualIndex' value='" . htmlspecialchars($fieldValue) . "' " . ($mapping['is_required'] ? 'required' : '') . ($is_readonly ? ' readonly' : '') . ">";
|
|
echo "<button type='button' class='propagate-btn' data-column='manual_$manualIndex' " . ($is_readonly ? 'disabled' : '') . "><i class='fas fa-arrow-down'></i></button>";
|
|
} else {
|
|
echo "<input type='text' class='custom-field $inputClass' data-column='manual_$manualIndex' value='" . htmlspecialchars($fieldValue) . "' " . ($mapping['is_required'] ? 'required' : '') . ($is_readonly ? ' readonly' : '') . ">";
|
|
echo "<button type='button' class='propagate-btn' data-column='manual_$manualIndex' " . ($is_readonly ? 'disabled' : '') . "><i class='fas fa-arrow-down'></i></button>";
|
|
}
|
|
echo "</div>";
|
|
$manualIndex++;
|
|
}
|
|
}
|
|
// Colonne Import Reference Code, filename_import
|
|
echo "<div class='grid-cell' style='flex: 0 0 150px;'></div>"; // Import Reference Code
|
|
echo "<div class='grid-cell' style='flex: 0 0 150px;'></div>"; // filename_import
|
|
// AWB Number e Tracking Info
|
|
echo "<div class='grid-cell' style='flex: 0 0 200px;'></div>";
|
|
echo "<div class='grid-cell' style='flex: 0 0 250px;'></div>";
|
|
?>
|
|
</div>
|
|
<div class="grid-row">
|
|
<div class="grid-header actions-cell" style="flex: 0 0 200px; position: relative;">Azioni<div class="resizer"></div>
|
|
</div>
|
|
<?php
|
|
// Header per il campo main_field = 1
|
|
$headerIndex = 1;
|
|
if ($mainFieldMapping) {
|
|
echo "<div class='grid-header' data-index='$headerIndex' style='flex: 0 0 150px; position: relative;'>" . htmlspecialchars($mainFieldMapping['field_label']) . "<div class='resizer'></div></div>";
|
|
$headerIndex++;
|
|
}
|
|
// Header per status (subito dopo main_field)
|
|
foreach ($fixedColumnsReduced as $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>";
|
|
$headerIndex++;
|
|
}
|
|
// Header per campi automatici (escluso main_field)
|
|
foreach ($allMappings as $mapping) {
|
|
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>";
|
|
$headerIndex++;
|
|
}
|
|
}
|
|
// Header per campi manuali (escluso main_field)
|
|
foreach ($allMappings as $mapping) {
|
|
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>";
|
|
$headerIndex++;
|
|
}
|
|
}
|
|
// Header per Import Reference Code, filename_import
|
|
echo "<div class='grid-header' data-index='$headerIndex' style='flex: 0 0 150px; position: relative;'>Import Reference Code<div class='resizer'></div></div>";
|
|
$headerIndex++;
|
|
echo "<div class='grid-header' data-index='$headerIndex' style='flex: 0 0 150px; position: relative;'>File<div class='resizer'></div></div>";
|
|
$headerIndex++;
|
|
// Header per AWB Number e Tracking Info
|
|
echo "<div class='grid-header' data-index='$headerIndex' style='flex: 0 0 200px; position: relative;'>AWB Number<div class='resizer'></div></div>";
|
|
$headerIndex++;
|
|
echo "<div class='grid-header' data-index='$headerIndex' style='flex: 0 0 250px; position: relative;'>Tracking Info<div class='resizer'></div></div>";
|
|
?>
|
|
</div>
|
|
<?php foreach ($importedData as $index => $row): ?>
|
|
<div class="grid-row" data-id="<?= $row['iddatadb'] ?>">
|
|
<div class="grid-cell actions-cell" style="flex: 0 0 200px; position: relative;">
|
|
<div style="display: flex; gap: 5px; justify-content: center;">
|
|
<?php if (!$is_readonly): ?>
|
|
<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; flex: 1;"><i class="fas fa-save"></i></button>
|
|
<?php else: ?>
|
|
<button type="button" class="save-btn action-btn" data-row="<?= $index ?>" style="background: #ccc; color: white; border: none; padding: 8px 12px; border-radius: 5px; cursor: not-allowed; flex: 1;" disabled><i class="fas fa-save"></i></button>
|
|
<?php endif; ?>
|
|
<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; flex: 1;"><i class="fas fa-camera"></i></button>
|
|
<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; flex: 1;"><i class="fas fa-puzzle-piece"></i></button>
|
|
</div>
|
|
</div>
|
|
<?php
|
|
$cellIndex = 1;
|
|
$rowDetails = array_filter($manualDetails, fn($d) => $d['datadb_id'] == $row['iddatadb']);
|
|
// Campo con main_field = 1
|
|
if ($mainFieldMapping) {
|
|
$detail = array_filter($rowDetails, fn($d) => $d['mapping_id'] == $mainFieldMapping['id']);
|
|
$detail = reset($detail) ?: ['field_value' => $mainFieldMapping['manual_default']];
|
|
$fieldValue = $detail['field_value'] ?? $mainFieldMapping['manual_default'] ?? '';
|
|
$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';
|
|
$indexField = $mainFieldMapping['is_manual'] ? "manual_0" : "auto_0";
|
|
echo "<div class='grid-cell editable-cell $requiredClass' data-col='$indexField' data-row='$index' data-index='$cellIndex' style='flex: 0 0 150px;'>";
|
|
if ($mainFieldMapping['data_type'] === 'SceltaMultipla') {
|
|
echo "<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']}' data-selected-value='" . htmlspecialchars($fieldValue) . "' " . ($mainFieldMapping['is_required'] ? 'required' : '') . ($is_readonly ? ' readonly' : '') . ">";
|
|
echo "<option value=''>Seleziona...</option>";
|
|
echo "</select>";
|
|
} elseif ($mainFieldMapping['data_type'] === 'DATE') {
|
|
echo "<input type='date' name='rows[$index][details][{$mainFieldMapping['id']}][field_value]' value='" . htmlspecialchars($fieldValue) . "' class='cell-input $inputClass' " . ($mainFieldMapping['is_required'] ? 'required' : '') . ($is_readonly ? ' readonly' : '') . ">";
|
|
} elseif ($mainFieldMapping['data_type'] === 'INT') {
|
|
echo "<input type='number' name='rows[$index][details][{$mainFieldMapping['id']}][field_value]' value='" . htmlspecialchars($fieldValue) . "' class='cell-input $inputClass' " . ($mainFieldMapping['is_required'] ? 'required' : '') . ($is_readonly ? ' readonly' : '') . ">";
|
|
} else {
|
|
echo "<input type='text' name='rows[$index][details][{$mainFieldMapping['id']}][field_value]' value='" . htmlspecialchars($fieldValue) . "' class='cell-input $inputClass' " . ($mainFieldMapping['is_required'] ? 'required' : '') . ($is_readonly ? ' readonly' : '') . ">";
|
|
}
|
|
echo "</div>";
|
|
$cellIndex++;
|
|
}
|
|
// Status (subito dopo main_field)
|
|
$fixedColumnsReduced = ['status'];
|
|
foreach ($fixedColumnsReduced as $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;'>";
|
|
if ($col === 'status') {
|
|
$badgeClass = $value === 'i' ? 'status-i' : ($value === 'P' ? 'status-P' : 'status-l');
|
|
$badgeText = $value === 'i' ? 'Imported' : ($value === 'P' ? 'Progress' : 'LIMS');
|
|
// Aggiungi il numero di commessaweb se lo status è 'l'
|
|
if ($value === 'l') {
|
|
$commessaWeb = isset($row['commessaweb']) ? htmlspecialchars($row['commessaweb']) : '';
|
|
$badgeText .= " ($commessaWeb)";
|
|
}
|
|
echo "<span class='status-badge $badgeClass'>" . htmlspecialchars($badgeText) . "</span>";
|
|
echo "<input type='hidden' name='rows[$index][$col]' value='" . htmlspecialchars($value ?? 'i') . "'>";
|
|
}
|
|
echo "</div>";
|
|
$cellIndex++;
|
|
}
|
|
// Campi automatici (escluso main_field)
|
|
$autoIndex = ($mainFieldMapping && !$mainFieldMapping['is_manual']) ? 1 : 0;
|
|
foreach ($allMappings as $mapping) {
|
|
if (!$mapping['is_manual'] && $mapping['main_field'] != 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 "<div class='grid-cell editable-cell $requiredClass' data-col='auto_$autoIndex' data-row='$index' data-index='$cellIndex' style='flex: 0 0 150px;'>";
|
|
if ($mapping['data_type'] === 'SceltaMultipla') {
|
|
echo "<select name='rows[$index][details][{$mapping['id']}][field_value]' class='cell-input dropdown-select $inputClass' data-mapping-id='{$mapping['id']}' data-field-id='{$mapping['field_id']}' data-selected-value='" . htmlspecialchars($fieldValue) . "' " . ($mapping['is_required'] ? 'required' : '') . ($is_readonly ? ' readonly' : '') . ">";
|
|
echo "<option value=''>Seleziona...</option>";
|
|
echo "</select>";
|
|
} elseif ($mapping['data_type'] === 'DATE') {
|
|
echo "<input type='date' name='rows[$index][details][{$mapping['id']}][field_value]' value='" . htmlspecialchars($fieldValue) . "' class='cell-input $inputClass' " . ($mapping['is_required'] ? 'required' : '') . ($is_readonly ? ' readonly' : '') . ">";
|
|
} elseif ($mapping['data_type'] === 'INT') {
|
|
echo "<input type='number' name='rows[$index][details][{$mapping['id']}][field_value]' value='" . htmlspecialchars($fieldValue) . "' class='cell-input $inputClass' " . ($mapping['is_required'] ? 'required' : '') . ($is_readonly ? ' readonly' : '') . ">";
|
|
} else {
|
|
echo "<input type='text' name='rows[$index][details][{$mapping['id']}][field_value]' value='" . htmlspecialchars($fieldValue) . "' class='cell-input $inputClass' " . ($mapping['is_required'] ? 'required' : '') . ($is_readonly ? ' readonly' : '') . ">";
|
|
}
|
|
echo "</div>";
|
|
$cellIndex++;
|
|
$autoIndex++;
|
|
}
|
|
}
|
|
// Campi manuali (escluso main_field)
|
|
$manualIndex = ($mainFieldMapping && $mainFieldMapping['is_manual']) ? 1 : 0;
|
|
foreach ($allMappings as $mapping) {
|
|
if ($mapping['is_manual'] && $mapping['main_field'] != 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'] === '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 "<div class='grid-cell editable-cell $requiredClass' data-col='manual_$manualIndex' data-row='$index' data-index='$cellIndex' style='flex: 0 0 150px;'>";
|
|
if ($mapping['data_type'] === 'SceltaMultipla') {
|
|
echo "<select name='rows[$index][details][{$mapping['id']}][field_value]' class='cell-input dropdown-select $inputClass' data-mapping-id='{$mapping['id']}' data-field-id='{$mapping['field_id']}' data-selected-value='" . htmlspecialchars($fieldValue) . "' " . ($mapping['is_required'] ? 'required' : '') . ($is_readonly ? ' readonly' : '') . ">";
|
|
echo "<option value=''>Seleziona...</option>";
|
|
echo "</select>";
|
|
} elseif ($mapping['data_type'] === 'DATE') {
|
|
echo "<input type='date' name='rows[$index][details][{$mapping['id']}][field_value]' value='" . htmlspecialchars($fieldValue) . "' class='cell-input $inputClass' " . ($mapping['is_required'] ? 'required' : '') . ($is_readonly ? ' readonly' : '') . ">";
|
|
} elseif ($mapping['data_type'] === 'INT') {
|
|
echo "<input type='number' name='rows[$index][details][{$mapping['id']}][field_value]' value='" . htmlspecialchars($fieldValue) . "' class='cell-input $inputClass' " . ($mapping['is_required'] ? 'required' : '') . ($is_readonly ? ' readonly' : '') . ">";
|
|
} else {
|
|
echo "<input type='text' name='rows[$index][details][{$mapping['id']}][field_value]' value='" . htmlspecialchars($fieldValue) . "' class='cell-input $inputClass' " . ($mapping['is_required'] ? 'required' : '') . ($is_readonly ? ' readonly' : '') . ">";
|
|
}
|
|
echo "</div>";
|
|
$cellIndex++;
|
|
$manualIndex++;
|
|
}
|
|
}
|
|
// Colonne Import Reference Code e filename_import
|
|
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++;
|
|
echo "<div class='grid-cell' data-col='filename_import' data-row='$index' data-index='$cellIndex' style='flex: 0 0 150px;'>";
|
|
echo "<a href='imported_trf/" . htmlspecialchars($row['filename_import']) . "' target='_blank'>File</a>";
|
|
echo "<input type='hidden' name='rows[$index][filename_import]' value='" . htmlspecialchars($row['filename_import']) . "'>";
|
|
echo "</div>";
|
|
$cellIndex++;
|
|
// Colonne AWB Number e Tracking Info
|
|
?>
|
|
<div class="grid-cell" style="flex: 0 0 200px;">
|
|
<select name="rows[<?= $index ?>][carrier]" class="carrier-select" <?= $is_readonly ? 'disabled' : '' ?>>
|
|
<option value="tnt-it">TNT Italy</option>
|
|
<option value="dhl">DHL</option>
|
|
<option value="gls">GLS</option>
|
|
<option value="sda">SDA</option>
|
|
<option value="ups">UPS</option>
|
|
</select>
|
|
<input type="text" name="rows[<?= $index ?>][awb_number]" class="cell-input awb-input" placeholder="Inserisci AWB Number" <?= $is_readonly ? 'readonly' : '' ?>>
|
|
<button type="button" class="go-btn" data-row="<?= $index ?>" <?= $is_readonly ? 'disabled' : '' ?>><i class="fas fa-play"></i></button>
|
|
</div>
|
|
<div class="grid-cell tracking-info" data-row="<?= $index ?>" style="flex: 0 0 250px;">
|
|
<span class="tracking-result">Shipment Info</span>
|
|
<input type="hidden" name="rows[<?= $index ?>][tracking_info]" class="tracking-hidden">
|
|
</div>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
<nav aria-label="Page navigation" class="mt-3">
|
|
<ul class="pagination justify-content-center">
|
|
<li class="page-item <?= $page <= 1 ? 'disabled' : '' ?>">
|
|
<a class="page-link" href="historical_trf.php?id=<?= $template_id ?>&status=<?= $status ?>&mode=edit&page=<?= $page - 1 ?>">Precedente</a>
|
|
</li>
|
|
<?php for ($i = 1; $i <= $total_pages; $i++): ?>
|
|
<li class="page-item <?= $i === $page ? 'active' : '' ?>">
|
|
<a class="page-link" href="historical_trf.php?id=<?= $template_id ?>&status=<?= $status ?>&mode=edit&page=<?= $i ?>"><?= $i ?></a>
|
|
</li>
|
|
<?php endfor; ?>
|
|
<li class="page-item <?= $page >= $total_pages ? 'disabled' : '' ?>">
|
|
<a class="page-link" href="historical_trf.php?id=<?= $template_id ?>&status=<?= $status ?>&mode=edit&page=<?= $page + 1 ?>">Successivo</a>
|
|
</li>
|
|
</ul>
|
|
</nav>
|
|
</form>
|
|
|
|
<?php
|
|
if (file_exists('modal_parts.php')) {
|
|
include 'modal_parts.php';
|
|
} else {
|
|
error_log("Errore: modal_parts.php non trovato");
|
|
}
|
|
if (file_exists('photos_functions.php')) {
|
|
include 'photos_functions.php';
|
|
} else {
|
|
error_log("Errore: photos_functions.php non trovato");
|
|
}
|
|
?>
|
|
<?php endif; ?>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="overlay toggle-icon"></div>
|
|
<a href="javascript:;" class="back-to-top"><i class='bx bxs-up-arrow-alt'></i></a>
|
|
<?php include('include/footer.php'); ?>
|
|
</div>
|
|
<?php include('jsinclude.php'); ?>
|
|
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/fabric.js/5.3.1/fabric.min.js"></script>
|
|
<script src="photos.js"></script>
|
|
<script src="parts.js"></script>
|
|
<script src="tracking.js"></script>
|
|
<script>
|
|
document.addEventListener("DOMContentLoaded", function() {
|
|
console.log("Righe caricate: <?= count($importedData) ?>");
|
|
console.log("Totale record: <?= $total_records ?>, Pagine: <?= $total_pages ?>");
|
|
|
|
// Gestione del dropdown status-filter
|
|
const statusFilter = document.getElementById('status-filter');
|
|
statusFilter.addEventListener('change', function() {
|
|
const status = this.value;
|
|
const mode = status === 'i' ? 'list' : 'edit';
|
|
window.location.href = `historical_trf.php?id=<?= $template_id ?>&status=${status}&mode=${mode}`;
|
|
});
|
|
|
|
<?php if ($mode === 'list'): ?>
|
|
// Gestione select all
|
|
const selectAll = document.getElementById('selectAll');
|
|
selectAll.addEventListener('change', function() {
|
|
document.querySelectorAll('input[name="selected_ids[]"]').forEach(cb => cb.checked = this.checked);
|
|
});
|
|
|
|
// Gestione filtro unico
|
|
const searchInput = document.querySelector('#searchInput');
|
|
const noResults = document.querySelector('#noResults');
|
|
searchInput.addEventListener('input', function() {
|
|
const filter = this.value.toLowerCase();
|
|
const rows = document.querySelectorAll('.list-table tbody tr');
|
|
let hasResults = false;
|
|
rows.forEach(row => {
|
|
const cells = row.querySelectorAll('td');
|
|
let match = false;
|
|
cells.forEach((cell, index) => {
|
|
if (index >= 1 && index <= 4) { // Cerca in ID, main_field, importreferencecode, filename
|
|
const text = cell.textContent.toLowerCase();
|
|
if (text.includes(filter)) {
|
|
match = true;
|
|
}
|
|
}
|
|
});
|
|
row.style.display = match ? '' : 'none';
|
|
if (match) hasResults = true;
|
|
});
|
|
noResults.style.display = hasResults ? 'none' : 'block';
|
|
});
|
|
|
|
// Gestione cancellazione
|
|
const deleteButtons = document.querySelectorAll('.delete-btn');
|
|
deleteButtons.forEach(btn => {
|
|
btn.addEventListener('click', function() {
|
|
const id = this.getAttribute('data-id');
|
|
if (confirm('Sicuro di voler cancellare questo record?')) {
|
|
fetch('delete_record.php', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
body: JSON.stringify({
|
|
id: id
|
|
})
|
|
})
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
if (data.success) {
|
|
this.closest('tr').remove();
|
|
const currentCount = document.querySelectorAll('.list-table tbody tr').length;
|
|
if (currentCount === 0) {
|
|
location.reload();
|
|
}
|
|
} else {
|
|
alert('Errore: ' + data.message);
|
|
}
|
|
})
|
|
.catch(error => alert('Errore durante la cancellazione: ' + error.message));
|
|
}
|
|
});
|
|
});
|
|
|
|
// Gestione eliminazione multipla
|
|
const bulkActionForm = document.getElementById('bulkActionForm');
|
|
bulkActionForm.addEventListener('submit', function(e) {
|
|
const selectedCheckboxes = document.querySelectorAll('input[name="selected_ids[]"]:checked');
|
|
if (selectedCheckboxes.length === 0) {
|
|
e.preventDefault();
|
|
alert('Seleziona almeno un record da eliminare.');
|
|
} else if (!confirm('Sicuro di voler eliminare i record selezionati?')) {
|
|
e.preventDefault();
|
|
}
|
|
});
|
|
<?php else: ?>
|
|
// Gestione input e celle espandibili
|
|
const inputs = document.querySelectorAll('.cell-input');
|
|
inputs.forEach(input => {
|
|
input.addEventListener('focus', function() {
|
|
if (!this.hasAttribute('readonly')) {
|
|
this.closest('.grid-cell').classList.add('expanded');
|
|
}
|
|
});
|
|
input.addEventListener('blur', function() {
|
|
this.closest('.grid-cell').classList.remove('expanded');
|
|
});
|
|
});
|
|
|
|
// Gestione salvataggio
|
|
const saveButtons = document.querySelectorAll('.save-btn');
|
|
saveButtons.forEach(button => {
|
|
button.addEventListener('click', function() {
|
|
if (this.hasAttribute('disabled')) return;
|
|
const rowIndex = this.getAttribute('data-row');
|
|
const row = this.closest('.grid-row');
|
|
const iddatadb = row.getAttribute('data-id');
|
|
const formData = new FormData();
|
|
const inputs = row.querySelectorAll(`input[name^="rows[${rowIndex}]"], select[name^="rows[${rowIndex}]"]`);
|
|
inputs.forEach(input => {
|
|
const name = input.name.replace(`rows[${rowIndex}]`, '').replace(/\[|\]/g, '');
|
|
formData.append(name, input.value);
|
|
// Aggiorna data-selected-value per i dropdown
|
|
if (input.tagName === 'SELECT' && input.classList.contains('dropdown-select')) {
|
|
input.setAttribute('data-selected-value', input.value);
|
|
}
|
|
});
|
|
formData.append('iddatadb', iddatadb);
|
|
formData.append('mapping', JSON.stringify(<?= json_encode($allMappings) ?>));
|
|
fetch('save_edited_row.php', {
|
|
method: 'POST',
|
|
body: formData
|
|
})
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
if (data.success) {
|
|
const cells = row.querySelectorAll('.grid-cell');
|
|
cells.forEach(cell => {
|
|
cell.classList.remove('flash-success');
|
|
void cell.offsetWidth;
|
|
cell.classList.add('flash-success');
|
|
});
|
|
setTimeout(() => cells.forEach(cell => cell.classList.remove('flash-success')), 500);
|
|
alert('Salvataggio avvenuto con successo!');
|
|
} else {
|
|
alert('Errore durante il salvataggio: ' + data.message);
|
|
}
|
|
})
|
|
.catch(error => alert('Errore durante il salvataggio: ' + error.message));
|
|
});
|
|
});
|
|
|
|
// Gestione propagazione
|
|
const propagateButtons = document.querySelectorAll('.propagate-btn');
|
|
propagateButtons.forEach(button => {
|
|
button.addEventListener('click', function() {
|
|
if (this.hasAttribute('disabled')) return;
|
|
const column = this.getAttribute('data-column');
|
|
const input = this.previousElementSibling;
|
|
const value = input.value;
|
|
const gridTopCells = document.querySelector('.grid-top').querySelectorAll('.grid-cell');
|
|
const targetTopIndex = Array.from(gridTopCells).findIndex(cell =>
|
|
cell.querySelector('.propagate-btn[data-column="' + column + '"]')
|
|
);
|
|
if (targetTopIndex !== -1) {
|
|
const rows = document.querySelectorAll('.grid-row');
|
|
rows.forEach(row => {
|
|
const cells = row.querySelectorAll('.grid-cell');
|
|
if (cells.length > targetTopIndex) {
|
|
const targetInput = cells[targetTopIndex].querySelector('input, select');
|
|
if (targetInput && !targetInput.hasAttribute('readonly')) {
|
|
targetInput.value = value;
|
|
if (targetInput.tagName === 'SELECT') {
|
|
targetInput.setAttribute('data-selected-value', value);
|
|
const event = new Event('change');
|
|
targetInput.dispatchEvent(event);
|
|
}
|
|
}
|
|
}
|
|
});
|
|
}
|
|
});
|
|
});
|
|
|
|
// Gestione ridimensionamento colonne
|
|
const resizers = document.querySelectorAll('.resizer');
|
|
let currentResizer = null;
|
|
let startX = 0;
|
|
let startWidth = 0;
|
|
let columnIndex = 0;
|
|
resizers.forEach(resizer => {
|
|
resizer.addEventListener('mousedown', function(e) {
|
|
currentResizer = resizer;
|
|
const header = resizer.parentElement;
|
|
columnIndex = header.getAttribute('data-index');
|
|
startX = e.pageX;
|
|
startWidth = header.offsetWidth;
|
|
document.addEventListener('mousemove', resize);
|
|
document.addEventListener('mouseup', stopResize);
|
|
});
|
|
|
|
function resize(e) {
|
|
if (currentResizer) {
|
|
const dx = e.pageX - startX;
|
|
const newWidth = startWidth + dx;
|
|
const headers = document.querySelectorAll(`.grid-header[data-index="${columnIndex}"]`);
|
|
const cells = document.querySelectorAll(`.grid-cell[data-index="${columnIndex}"]`);
|
|
headers.forEach(header => header.style.flex = `0 0 ${newWidth}px`);
|
|
cells.forEach(cell => cell.style.flex = `0 0 ${newWidth}px`);
|
|
}
|
|
}
|
|
|
|
function stopResize() {
|
|
if (currentResizer) {
|
|
document.removeEventListener('mousemove', resize);
|
|
document.removeEventListener('mouseup', stopResize);
|
|
currentResizer = null;
|
|
}
|
|
}
|
|
});
|
|
|
|
// Gestione filtro di ricerca (per la griglia)
|
|
const searchInput = document.querySelector('#searchInput');
|
|
const noResults = document.querySelector('#noResults');
|
|
searchInput.addEventListener('input', function() {
|
|
const filter = this.value.toLowerCase();
|
|
if (filter.length < 3) {
|
|
const rows = document.querySelectorAll('.grid-row');
|
|
rows.forEach(row => row.style.display = '');
|
|
noResults.style.display = 'none';
|
|
return;
|
|
}
|
|
const rows = document.querySelectorAll('.grid-row');
|
|
let hasResults = false;
|
|
rows.forEach(row => {
|
|
const cells = row.querySelectorAll('.grid-cell');
|
|
let match = false;
|
|
cells.forEach(cell => {
|
|
const text = (cell.textContent || '').toLowerCase();
|
|
const inputs = cell.querySelectorAll('input, select');
|
|
inputs.forEach(input => {
|
|
const inputValue = (input.value || '').toLowerCase();
|
|
if (inputValue.includes(filter)) {
|
|
match = true;
|
|
}
|
|
});
|
|
if (text.includes(filter)) {
|
|
match = true;
|
|
}
|
|
});
|
|
row.style.display = match ? '' : 'none';
|
|
if (match) hasResults = true;
|
|
});
|
|
noResults.style.display = hasResults ? 'none' : 'block';
|
|
});
|
|
|
|
// Gestione scorrimento orizzontale
|
|
const gridContainer = document.querySelector('.grid-container');
|
|
const scrollbarContainer = document.querySelector('.scrollbar-container');
|
|
const scrollLeftBtn = document.querySelector('.scroll-left');
|
|
const scrollRightBtn = document.querySelector('.scroll-right');
|
|
|
|
scrollbarContainer.style.width = `${gridContainer.scrollWidth}px`;
|
|
gridContainer.addEventListener('scroll', () => {
|
|
scrollbarContainer.scrollLeft = gridContainer.scrollLeft;
|
|
});
|
|
scrollbarContainer.addEventListener('scroll', () => {
|
|
gridContainer.scrollLeft = scrollbarContainer.scrollLeft;
|
|
});
|
|
|
|
window.addEventListener('scroll', () => {
|
|
const gridRect = gridContainer.getBoundingClientRect();
|
|
scrollbarContainer.style.display = gridRect.bottom < 0 ? 'block' : 'none';
|
|
});
|
|
|
|
scrollLeftBtn.addEventListener('click', () => {
|
|
gridContainer.scrollBy({
|
|
left: -200,
|
|
behavior: 'smooth'
|
|
});
|
|
});
|
|
scrollRightBtn.addEventListener('click', () => {
|
|
gridContainer.scrollBy({
|
|
left: 200,
|
|
behavior: 'smooth'
|
|
});
|
|
});
|
|
|
|
// Gestione dropdown
|
|
const dropdownData = {};
|
|
async function populateDropdowns() {
|
|
if (<?= json_encode($is_readonly) ?>) return;
|
|
const dropdowns = document.querySelectorAll('.dropdown-select');
|
|
console.log('Dropdown trovati:', dropdowns.length);
|
|
if (dropdowns.length === 0) {
|
|
console.warn('Nessun dropdown trovato con classe .dropdown-select');
|
|
return;
|
|
}
|
|
|
|
const uniqueFieldIds = [...new Set(Array.from(dropdowns).map(d => d.getAttribute('data-field-id')))].filter(fieldId => fieldId);
|
|
console.log('Field IDs unici:', uniqueFieldIds);
|
|
const missingFieldIds = uniqueFieldIds.filter(fieldId => !dropdownData[fieldId]);
|
|
|
|
if (missingFieldIds.length > 0) {
|
|
try {
|
|
const response = await fetch(`get_customfield_values.php?field_ids=${missingFieldIds.join(',')}`);
|
|
if (!response.ok) {
|
|
throw new Error(`Errore HTTP: ${response.status} ${response.statusText}`);
|
|
}
|
|
const data = await response.json();
|
|
console.log('Risposta da get_customfield_values.php:', data);
|
|
|
|
if (data.error) {
|
|
console.error('Errore dal server:', data.error);
|
|
dropdowns.forEach(dropdown => {
|
|
dropdown.innerHTML = '<option value="">Errore server</option>';
|
|
});
|
|
return;
|
|
}
|
|
|
|
for (const fieldId of Object.keys(data)) {
|
|
dropdownData[fieldId] = data[fieldId] || [];
|
|
}
|
|
} catch (error) {
|
|
console.error('Errore nel fetch dei valori dei dropdown:', error);
|
|
dropdowns.forEach(dropdown => {
|
|
dropdown.innerHTML = '<option value="">Errore caricamento</option>';
|
|
});
|
|
return;
|
|
}
|
|
}
|
|
|
|
dropdowns.forEach(dropdown => {
|
|
const fieldId = dropdown.getAttribute('data-field-id');
|
|
const mappingId = dropdown.getAttribute('data-mapping-id');
|
|
const selectedValue = dropdown.getAttribute('data-selected-value') || '';
|
|
const currentValue = dropdown.value || '';
|
|
console.log(`Popolamento dropdown field_id=${fieldId}, mapping_id=${mappingId}, valore corrente=${currentValue}, valore selezionato=${selectedValue}`);
|
|
|
|
if (!fieldId || !dropdownData[fieldId]) {
|
|
dropdown.innerHTML = '<option value="">Nessun dato</option>';
|
|
return;
|
|
}
|
|
|
|
// Preserva il valore corrente o usa quello salvato
|
|
dropdown.innerHTML = '<option value="">Seleziona...</option>';
|
|
dropdownData[fieldId].forEach(value => {
|
|
const option = document.createElement('option');
|
|
option.value = value.IdCustomFieldsValue;
|
|
option.textContent = value.Valore;
|
|
// Dai priorità a data-selected-value per il caricamento iniziale
|
|
if (selectedValue === String(value.IdCustomFieldsValue)) {
|
|
option.selected = true;
|
|
} else if (currentValue === String(value.IdCustomFieldsValue)) {
|
|
option.selected = true;
|
|
}
|
|
dropdown.appendChild(option);
|
|
});
|
|
|
|
// Verifica se il valore selezionato esiste tra le opzioni
|
|
if ((selectedValue || currentValue) && dropdown.value !== (selectedValue || currentValue)) {
|
|
dropdown.value = '';
|
|
console.warn(`Valore ${selectedValue || currentValue} non trovato per fieldId ${fieldId}`);
|
|
}
|
|
});
|
|
}
|
|
populateDropdowns();
|
|
<?php endif; ?>
|
|
});
|
|
</script>
|
|
</body>
|
|
|
|
</html>
|