false, 'message' => 'Sessione non valida']); exit; } $db = DBHandlerSelect::getInstance(); $pdo = $db->getConnection(); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $page = (string)($_POST['page'] ?? ''); $action = (string)($_POST['action'] ?? ''); try { if (!UiPrefs::validPage($page)) throw new Exception('Pagina non valida'); if ($action === 'save') { $raw = (string)($_POST['layout'] ?? ''); if (strlen($raw) > 8000) throw new Exception('Layout troppo grande'); $layout = json_decode($raw, true); if (!is_array($layout)) throw new Exception('Layout non valido'); UiPrefs::save($pdo, $uid, $page, $layout); echo json_encode(['ok' => true]); } elseif ($action === 'reset') { UiPrefs::reset($pdo, $uid, $page); echo json_encode(['ok' => true]); } else { throw new Exception('Azione non valida'); } } catch (Throwable $e) { echo json_encode(['ok' => false, 'message' => $e->getMessage()]); }