added auto user accettatore id
This commit is contained in:
@@ -21,7 +21,7 @@ $schemajson = $template['schemajson'] ? json_decode($template['schemajson'], tru
|
||||
$isSchemajsonEmpty = empty(trim($template['schemajson']));
|
||||
|
||||
// Recupera i campi dalla tabella template_mapping
|
||||
$stmt = $pdo->prepare("SELECT id, field_id, excel_column, is_manual, manual_default, data_type, is_required, default_value, has_list, length, decimals, min_value, max_value, default_curr_date, tablename, field_label, main_field, is_visible_import, is_visible_parts FROM template_mapping WHERE template_id = ?");
|
||||
$stmt = $pdo->prepare("SELECT id, field_id, excel_column, is_manual, manual_default, auto_value, data_type, is_required, default_value, has_list, length, decimals, min_value, max_value, default_curr_date, tablename, field_label, main_field, is_visible_import, is_visible_parts FROM template_mapping WHERE template_id = ?");
|
||||
$stmt->execute([$id]);
|
||||
$mappings = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
@@ -216,9 +216,13 @@ $xlsHeaders = $template['xls_headers'] ? json_decode($template['xls_headers'], t
|
||||
<td>
|
||||
<?php
|
||||
$isSceltaMultipla = ($mapping['data_type'] === 'SceltaMultipla');
|
||||
|
||||
$autoValue = $mapping['auto_value'] ?? 'none';
|
||||
$hasAuto = ($autoValue && $autoValue !== 'none');
|
||||
|
||||
$mappingValue = $isSceltaMultipla
|
||||
? 'manual'
|
||||
: ($mapping['excel_column'] ? 'xls' : ((int)$mapping['is_manual'] === 1 ? 'manual' : ''));
|
||||
: ($hasAuto ? 'auto' : ($mapping['excel_column'] ? 'xls' : ((int)$mapping['is_manual'] === 1 ? 'manual' : '')));
|
||||
?>
|
||||
|
||||
<select class="form-select mapping-select"
|
||||
@@ -229,6 +233,7 @@ $xlsHeaders = $template['xls_headers'] ? json_decode($template['xls_headers'], t
|
||||
<?php if (!$isSceltaMultipla): ?>
|
||||
<option value="">Select Option</option>
|
||||
<option value="xls" <?php echo ($mappingValue === 'xls') ? 'selected' : ''; ?>>Map to XLS Column</option>
|
||||
<option value="auto" <?php echo ($mappingValue === 'auto') ? 'selected' : ''; ?>>Auto value</option>
|
||||
<?php endif; ?>
|
||||
|
||||
<option value="manual" <?php echo ($mappingValue === 'manual') ? 'selected' : ''; ?>>Manual Entry</option>
|
||||
@@ -240,6 +245,16 @@ $xlsHeaders = $template['xls_headers'] ? json_decode($template['xls_headers'], t
|
||||
<?php echo $mapping['excel_column'] ? 'data-current-xls="' . htmlspecialchars($mapping['excel_column']) . '"' : ''; ?>>
|
||||
</select>
|
||||
|
||||
<select class="form-select auto-value-select"
|
||||
style="display:<?php echo ($mappingValue === 'auto') ? 'block' : 'none'; ?>; margin-top:6px;"
|
||||
data-id="<?php echo (int)$mapping['id']; ?>">
|
||||
<option value="none">Select auto value</option>
|
||||
<option value="import_date" <?php echo ($autoValue === 'import_date') ? 'selected' : ''; ?>>Current date (import)</option>
|
||||
<option value="import_time" <?php echo ($autoValue === 'import_time') ? 'selected' : ''; ?>>Current time (import)</option>
|
||||
<option value="export_date" <?php echo ($autoValue === 'export_date') ? 'selected' : ''; ?>>Current date (export)</option>
|
||||
<option value="export_time" <?php echo ($autoValue === 'export_time') ? 'selected' : ''; ?>>Current time (export)</option>
|
||||
</select>
|
||||
|
||||
<?php if (!empty($mapping['excel_column'])): ?>
|
||||
<span class="mapped-column" style="margin-left:5px;">
|
||||
(<?php echo htmlspecialchars($mapping['excel_column']); ?>)
|
||||
@@ -266,7 +281,7 @@ $xlsHeaders = $template['xls_headers'] ? json_decode($template['xls_headers'], t
|
||||
class="form-control manual-default"
|
||||
placeholder="Default value"
|
||||
value="<?php echo htmlspecialchars($mapping['manual_default'] ?? ''); ?>"
|
||||
style="display:<?php echo ((int)$mapping['is_manual'] === 1) ? 'block' : 'none'; ?>"
|
||||
style="display:<?php echo ($mappingValue === 'manual') ? 'block' : 'none'; ?>"
|
||||
data-field-id="<?php echo (int)$mapping['field_id']; ?>">
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
@@ -802,27 +817,57 @@ $xlsHeaders = $template['xls_headers'] ? json_decode($template['xls_headers'], t
|
||||
let mappingId = event.target.getAttribute('data-id');
|
||||
let xlsSelect = tr.querySelector('.xls-columns');
|
||||
let manualInput = tr.querySelector('.manual-default');
|
||||
let autoSelect = tr.querySelector('.auto-value-select');
|
||||
let mappedColumn = tr.querySelector('.mapped-column');
|
||||
let removeBtn = tr.querySelector('.remove-xls');
|
||||
if (event.target.value === 'xls') {
|
||||
xlsSelect.style.display = 'block';
|
||||
if (autoSelect) autoSelect.style.display = 'none';
|
||||
|
||||
manualInput.style.display = 'none';
|
||||
manualInput.value = '';
|
||||
|
||||
if (mappedColumn) mappedColumn.style.display = 'none';
|
||||
if (removeBtn) removeBtn.style.display = xlsSelect.value ? 'inline-block' : 'none';
|
||||
|
||||
} else if (event.target.value === 'manual') {
|
||||
xlsSelect.style.display = 'none';
|
||||
if (autoSelect) autoSelect.style.display = 'none';
|
||||
|
||||
manualInput.style.display = 'block';
|
||||
|
||||
if (mappedColumn) mappedColumn.style.display = 'none';
|
||||
if (removeBtn) removeBtn.style.display = 'none';
|
||||
} else {
|
||||
|
||||
} else if (event.target.value === 'auto') {
|
||||
xlsSelect.style.display = 'none';
|
||||
xlsSelect.value = ''; // libera UI
|
||||
|
||||
manualInput.style.display = 'none';
|
||||
manualInput.value = '';
|
||||
|
||||
if (mappedColumn) mappedColumn.style.display = 'none';
|
||||
if (removeBtn) removeBtn.style.display = 'none';
|
||||
|
||||
if (autoSelect) autoSelect.style.display = 'block';
|
||||
|
||||
} else {
|
||||
xlsSelect.style.display = 'none';
|
||||
if (autoSelect) autoSelect.style.display = 'none';
|
||||
|
||||
manualInput.style.display = 'none';
|
||||
manualInput.value = '';
|
||||
|
||||
if (mappedColumn) mappedColumn.style.display = 'none';
|
||||
if (removeBtn) removeBtn.style.display = 'none';
|
||||
}
|
||||
saveMapping(mappingId, event.target.value, manualInput.value, xlsSelect.value);
|
||||
saveMapping(
|
||||
mappingId,
|
||||
event.target.value,
|
||||
manualInput.value,
|
||||
xlsSelect.value,
|
||||
autoSelect ? autoSelect.value : null
|
||||
);
|
||||
updateXlsDropdowns();
|
||||
} else if (event.target.classList.contains('main-field-checkbox')) {
|
||||
const checkbox = event.target;
|
||||
@@ -930,12 +975,30 @@ $xlsHeaders = $template['xls_headers'] ? json_decode($template['xls_headers'], t
|
||||
document.querySelectorAll('.main-field-checkbox').forEach(cb => {
|
||||
cb.dataset.originalChecked = cb.checked;
|
||||
});
|
||||
// AUTO VALUE select change -> save auto_value
|
||||
document.getElementById('schemaFieldsBody').addEventListener('change', function(event) {
|
||||
if (!event.target.classList.contains('auto-value-select')) return;
|
||||
|
||||
const tr = event.target.closest('tr');
|
||||
const mappingId = event.target.getAttribute('data-id');
|
||||
|
||||
const xlsSelect = tr.querySelector('.xls-columns');
|
||||
const manualInput = tr.querySelector('.manual-default');
|
||||
|
||||
saveMapping(
|
||||
mappingId,
|
||||
'auto',
|
||||
manualInput ? manualInput.value : '',
|
||||
xlsSelect ? xlsSelect.value : null,
|
||||
event.target.value
|
||||
);
|
||||
});
|
||||
document.getElementById('schemaFieldsBody').addEventListener('change', function(event) {
|
||||
if (event.target.classList.contains('xls-columns')) {
|
||||
let tr = event.target.closest('tr');
|
||||
let mappingId = event.target.getAttribute('data-id');
|
||||
let manualInput = tr.querySelector('.manual-default');
|
||||
let autoSelect = tr.querySelector('.auto-value-select');
|
||||
let mappedColumn = tr.querySelector('.mapped-column');
|
||||
let removeBtn = tr.querySelector('.remove-xls');
|
||||
|
||||
@@ -976,6 +1039,10 @@ $xlsHeaders = $template['xls_headers'] ? json_decode($template['xls_headers'], t
|
||||
mappedColumn.style.display = event.target.value ? 'inline' : 'none';
|
||||
}
|
||||
if (removeBtn) removeBtn.style.display = event.target.value ? 'inline-block' : 'none';
|
||||
const mappingSelect = tr.querySelector('.mapping-select');
|
||||
if (mappingSelect && mappingSelect.value !== 'xls') {
|
||||
return; // non salvare XLS se non siamo in modalità XLS
|
||||
}
|
||||
saveMapping(mappingId, 'xls', manualInput.value, event.target.value);
|
||||
updateXlsDropdowns();
|
||||
}
|
||||
@@ -1027,7 +1094,7 @@ $xlsHeaders = $template['xls_headers'] ? json_decode($template['xls_headers'], t
|
||||
}
|
||||
});
|
||||
|
||||
function saveMapping(mappingId, mappingType, defaultValue, excelColumn) {
|
||||
function saveMapping(mappingId, mappingType, defaultValue, excelColumn, autoValue) {
|
||||
console.log("Saving mapping:", {
|
||||
id: mappingId,
|
||||
mapping_type: mappingType,
|
||||
@@ -1044,6 +1111,7 @@ $xlsHeaders = $template['xls_headers'] ? json_decode($template['xls_headers'], t
|
||||
mapping_type: mappingType,
|
||||
excel_column: mappingType === 'xls' ? excelColumn : null,
|
||||
manual_default: mappingType === 'manual' ? defaultValue : null,
|
||||
auto_value: mappingType === 'auto' ? (autoValue || 'none') : 'none',
|
||||
tablename: "<?php echo $template['target_table']; ?>"
|
||||
})
|
||||
}).then(response => response.json())
|
||||
|
||||
Reference in New Issue
Block a user