time and date setting
This commit is contained in:
parent
cf44e67922
commit
48d2a3ff42
File diff suppressed because one or more lines are too long
@ -1,6 +1,10 @@
|
||||
<?php
|
||||
include('include/headscript.php');
|
||||
|
||||
// ✅ FIX timezone (Rome)
|
||||
ini_set('date.timezone', 'Europe/Rome');
|
||||
date_default_timezone_set('Europe/Rome');
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] !== 'POST' || !isset($_POST['template_id']) || !isset($_POST['selected_rows']) || !isset($_POST['filename'])) {
|
||||
header("Location: xlstemplates_grid.php?status=error&message=" . urlencode("Richiesta non valida"));
|
||||
exit;
|
||||
@ -22,7 +26,9 @@ $pdo = $db->getConnection();
|
||||
$importReferenceCode = date('YmdHis') . '-' . uniqid();
|
||||
|
||||
// Recupera tutti i mapping dal template, includendo is_visible_import
|
||||
$stmt = $pdo->prepare("SELECT id, excel_column, data_type, is_required, manual_default, is_manual, field_label, field_id, main_field, is_visible_import 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, is_visible_import, auto_value
|
||||
FROM template_mapping
|
||||
WHERE template_id = ?");
|
||||
$stmt->execute([$template_id]);
|
||||
$allMappings = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
@ -33,6 +39,22 @@ $timeLabels = [
|
||||
'Presa in carico, Orario:',
|
||||
];
|
||||
|
||||
// Returns the auto value for current session (import) based on mapping.auto_value
|
||||
function getImportAutoValue(array $mapping): string
|
||||
{
|
||||
$auto = $mapping['auto_value'] ?? 'none';
|
||||
|
||||
if ($auto === 'import_date') {
|
||||
return date('Y-m-d');
|
||||
}
|
||||
|
||||
if ($auto === 'import_time') {
|
||||
// HTML <input type="time"> expects HH:MM (seconds optional)
|
||||
return date('H:i');
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
if (empty($allMappings)) {
|
||||
header("Location: import_xls.php?id=$template_id&status=error&message=" . urlencode("Nessun mapping trovato per il template"));
|
||||
@ -785,7 +807,23 @@ function fixedDefaultValue(array $f): string
|
||||
echo "<button type='button' class='propagate-btn' data-column='auto_$autoIndex'><i class='fas fa-arrow-down'></i></button>";
|
||||
echo "</div>";
|
||||
} else {
|
||||
echo "<div class='grid-cell grid-top-cell' style='flex: 0 0 150px;' data-index='$topColIndex'></div>";
|
||||
// Show auto import date/time in header too (read-only)
|
||||
$autoVal = getImportAutoValue($mapping);
|
||||
|
||||
echo "<div class='grid-cell grid-top-cell' style='flex: 0 0 150px;' data-index='$topColIndex'>";
|
||||
|
||||
if (($mapping['auto_value'] ?? 'none') === 'import_date') {
|
||||
echo "<input type='text' class='custom-field date-picker auto-input' value='" . htmlspecialchars($autoVal) . "' readonly>";
|
||||
echo "<button type='button' class='propagate-btn' data-column='auto_$autoIndex'><i class='fas fa-arrow-down'></i></button>";
|
||||
} elseif (($mapping['auto_value'] ?? 'none') === 'import_time') {
|
||||
echo "<input type='time' class='custom-field auto-input' value='" . htmlspecialchars($autoVal) . "' readonly>";
|
||||
echo "<button type='button' class='propagate-btn' data-column='auto_$autoIndex'><i class='fas fa-arrow-down'></i></button>";
|
||||
} else {
|
||||
// keep empty cell for other auto fields
|
||||
echo "";
|
||||
}
|
||||
|
||||
echo "</div>";
|
||||
}
|
||||
|
||||
$autoIndex++;
|
||||
@ -1028,6 +1066,14 @@ function fixedDefaultValue(array $f): string
|
||||
$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'] ?? '';
|
||||
|
||||
// Auto-fill import date/time only if empty
|
||||
if ($fieldValue === '' || $fieldValue === null) {
|
||||
$autoVal = getImportAutoValue($mapping);
|
||||
if ($autoVal !== '') {
|
||||
$fieldValue = $autoVal;
|
||||
}
|
||||
}
|
||||
$requiredClass = ($mapping['is_required'] && (is_null($fieldValue) || $fieldValue === '')) ? 'missing-required' : '';
|
||||
$inputClass = 'auto-input';
|
||||
if ($mapping['is_required']) $inputClass .= ' required-input';
|
||||
@ -1040,6 +1086,8 @@ function fixedDefaultValue(array $f): string
|
||||
echo "<input type='text' name='rows[$index][details][{$mapping['id']}][field_value]' value='" . htmlspecialchars($fieldValue) . "' class='cell-input date-picker $inputClass' " . ($mapping['is_required'] ? 'required' : '') . ">";
|
||||
} 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' : '') . ">";
|
||||
} elseif (($mapping['auto_value'] ?? 'none') === 'import_time') {
|
||||
echo "<input type='time' name='rows[$index][details][{$mapping['id']}][field_value]' value='" . htmlspecialchars($fieldValue) . "' class='cell-input $inputClass' " . ($mapping['is_required'] ? 'required' : '') . ">";
|
||||
} elseif (in_array($mapping['field_label'], $timeLabels)) {
|
||||
echo "<input type='time' name='rows[$index][details][{$mapping['id']}][field_value]' value='" . htmlspecialchars($fieldValue) . "' class='cell-input $inputClass' " . ($mapping['is_required'] ? 'required' : '') . ">";
|
||||
} else {
|
||||
|
||||
@ -33,7 +33,7 @@ try {
|
||||
}
|
||||
|
||||
// Normalize auto_value
|
||||
$allowedAuto = ['none', 'import_date', 'import_datetime', 'export_date', 'export_datetime'];
|
||||
$allowedAuto = ['none', 'import_date', 'import_time', 'export_date', 'export_time'];
|
||||
if (!in_array($autoValue, $allowedAuto, true)) {
|
||||
$autoValue = 'none';
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user