edit templtae lingue e colori
This commit is contained in:
@@ -16,9 +16,11 @@ if (!$data || !isset($data['id'])) {
|
||||
exit;
|
||||
}
|
||||
|
||||
$mappingId = $data['id'];
|
||||
$mappingId = (int)$data['id'];
|
||||
$mappingType = $data['mapping_type'] ?? '';
|
||||
|
||||
$excelColumn = $data['excel_column'] ?? null;
|
||||
$jsonNode = $data['json_node'] ?? null;
|
||||
$manualDefault = $data['manual_default'] ?? null;
|
||||
|
||||
$autoValue = $data['auto_value'] ?? 'none';
|
||||
@@ -26,7 +28,7 @@ $tablename = $data['tablename'] ?? '';
|
||||
|
||||
try {
|
||||
// Normalize mapping type
|
||||
$allowedTypes = ['', 'xls', 'manual', 'auto'];
|
||||
$allowedTypes = ['', 'xls', 'json', 'manual', 'auto'];
|
||||
if (!in_array($mappingType, $allowedTypes, true)) {
|
||||
echo json_encode(["success" => false, "message" => "Invalid mapping_type"]);
|
||||
exit;
|
||||
@@ -41,43 +43,67 @@ try {
|
||||
// Decide what to persist based on mapping_type
|
||||
$isManual = 0;
|
||||
$excelToSave = null;
|
||||
$jsonNodeToSave = null;
|
||||
$manualToSave = null;
|
||||
$autoToSave = 'none';
|
||||
|
||||
if ($mappingType === 'xls') {
|
||||
|
||||
$isManual = 0;
|
||||
$excelToSave = $excelColumn ?: null;
|
||||
$jsonNodeToSave = null;
|
||||
$manualToSave = null;
|
||||
$autoToSave = 'none';
|
||||
} elseif ($mappingType === 'json') {
|
||||
|
||||
$isManual = 0;
|
||||
$excelToSave = null;
|
||||
$jsonNodeToSave = $jsonNode ?: null;
|
||||
$manualToSave = null;
|
||||
$autoToSave = 'none';
|
||||
} elseif ($mappingType === 'manual') {
|
||||
|
||||
$isManual = 1;
|
||||
$excelToSave = null;
|
||||
$jsonNodeToSave = null;
|
||||
$manualToSave = $manualDefault;
|
||||
$autoToSave = 'none';
|
||||
} elseif ($mappingType === 'auto') {
|
||||
|
||||
$isManual = 0;
|
||||
$excelToSave = null;
|
||||
$jsonNodeToSave = null;
|
||||
$manualToSave = null;
|
||||
$autoToSave = $autoValue ?: 'none';
|
||||
} else {
|
||||
// reset
|
||||
|
||||
// Reset mapping
|
||||
$isManual = 0;
|
||||
$excelToSave = null;
|
||||
$jsonNodeToSave = null;
|
||||
$manualToSave = null;
|
||||
$autoToSave = 'none';
|
||||
}
|
||||
|
||||
$stmt = $pdo->prepare("
|
||||
UPDATE template_mapping
|
||||
SET
|
||||
is_manual = ?,
|
||||
excel_column = ?,
|
||||
manual_default = ?,
|
||||
auto_value = ?
|
||||
WHERE id = ?
|
||||
");
|
||||
UPDATE template_mapping
|
||||
SET
|
||||
is_manual = ?,
|
||||
excel_column = ?,
|
||||
json_node = ?,
|
||||
manual_default = ?,
|
||||
auto_value = ?
|
||||
WHERE id = ?
|
||||
");
|
||||
|
||||
$result = $stmt->execute([$isManual, $excelToSave, $manualToSave, $autoToSave, $mappingId]);
|
||||
$result = $stmt->execute([
|
||||
$isManual,
|
||||
$excelToSave,
|
||||
$jsonNodeToSave,
|
||||
$manualToSave,
|
||||
$autoToSave,
|
||||
$mappingId
|
||||
]);
|
||||
|
||||
if (!$result) {
|
||||
echo json_encode(["success" => false, "message" => "Database update failed"]);
|
||||
@@ -88,15 +114,17 @@ try {
|
||||
"success" => true,
|
||||
"message" => "Mapping updated successfully",
|
||||
"saved" => [
|
||||
"id" => (int)$mappingId,
|
||||
"id" => $mappingId,
|
||||
"mapping_type" => $mappingType,
|
||||
"is_manual" => $isManual,
|
||||
"excel_column" => $excelToSave,
|
||||
"json_node" => $jsonNodeToSave,
|
||||
"manual_default" => $manualToSave,
|
||||
"auto_value" => $autoToSave
|
||||
]
|
||||
]);
|
||||
} catch (Exception $e) {
|
||||
} catch (Throwable $e) {
|
||||
echo json_encode(["success" => false, "message" => "Error: " . $e->getMessage()]);
|
||||
}
|
||||
|
||||
exit;
|
||||
|
||||
Reference in New Issue
Block a user