added additional field in parts template e layout
This commit is contained in:
@@ -21,11 +21,37 @@ $value = ($value === 1) ? 1 : 0;
|
||||
$db = DBHandlerSelect::getInstance();
|
||||
$pdo = $db->getConnection();
|
||||
|
||||
$stmt = $pdo->prepare("UPDATE template_mapping SET is_visible_parts = ? WHERE id = ? AND template_id = ?");
|
||||
$result = $stmt->execute([$value, $mapping_id, $template_id]);
|
||||
try {
|
||||
$pdo->beginTransaction();
|
||||
|
||||
if ($result) {
|
||||
echo json_encode(['success' => true]);
|
||||
} else {
|
||||
echo json_encode(['success' => false, 'message' => 'Failed to update is_visible_parts']);
|
||||
if ($value === 1) {
|
||||
// 1) Force ONLY ONE row visible_parts per template:
|
||||
// set all to 0 for this template
|
||||
$stmtReset = $pdo->prepare("
|
||||
UPDATE template_mapping
|
||||
SET is_visible_parts = 0
|
||||
WHERE template_id = ?
|
||||
");
|
||||
$stmtReset->execute([$template_id]);
|
||||
}
|
||||
|
||||
// 2) Set requested mapping to 1 or 0
|
||||
$stmtSet = $pdo->prepare("
|
||||
UPDATE template_mapping
|
||||
SET is_visible_parts = ?
|
||||
WHERE id = ? AND template_id = ?
|
||||
");
|
||||
$stmtSet->execute([$value, $mapping_id, $template_id]);
|
||||
|
||||
$pdo->commit();
|
||||
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'template_id' => $template_id,
|
||||
'mapping_id' => $mapping_id,
|
||||
'value' => $value
|
||||
]);
|
||||
} catch (Exception $e) {
|
||||
if ($pdo->inTransaction()) $pdo->rollBack();
|
||||
echo json_encode(['success' => false, 'message' => $e->getMessage()]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user