trf_certest/public/userarea/update_visible_parts.php
2026-02-24 09:06:45 +01:00

32 lines
995 B
PHP

<?php
require_once 'include/headscript.php';
header('Content-Type: application/json');
$data = json_decode(file_get_contents('php://input'), true);
$template_id = isset($data['template_id']) ? (int)$data['template_id'] : 0;
$mapping_id = isset($data['mapping_id']) ? (int)$data['mapping_id'] : 0;
$value = isset($data['value']) ? (int)$data['value'] : null;
// Validate input
if ($template_id <= 0 || $mapping_id <= 0 || $value === null) {
echo json_encode(['success' => false, 'message' => 'Invalid input']);
exit;
}
// Normalize to 0/1
$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]);
if ($result) {
echo json_encode(['success' => true]);
} else {
echo json_encode(['success' => false, 'message' => 'Failed to update is_visible_parts']);
}