First pass of features
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__ . '/../includes/api_bootstrap.php';
|
||||
require_once __DIR__ . '/../includes/family_settings.php';
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
||||
sendJson(['success' => false, 'error' => 'Method not allowed'], 405);
|
||||
}
|
||||
|
||||
$people = normalizePeopleList(readJsonFile('people.json'));
|
||||
if (count($people) > 0) {
|
||||
assertHoHCanManagePeople($people);
|
||||
}
|
||||
|
||||
$body = readJsonBody();
|
||||
$merged = loadFamilySettings();
|
||||
|
||||
$allowedPermanence = ['permanent', 'weekly', 'biweekly', 'monthly', 'quarterly', 'yearly'];
|
||||
|
||||
if (isset($body['currency_symbol'])) {
|
||||
$merged['currency_symbol'] = trim((string) $body['currency_symbol']);
|
||||
}
|
||||
if (isset($body['currency_name'])) {
|
||||
$merged['currency_name'] = trim((string) $body['currency_name']);
|
||||
}
|
||||
if (isset($body['currency_permanence'])) {
|
||||
$p = (string) $body['currency_permanence'];
|
||||
if (!in_array($p, $allowedPermanence, true)) {
|
||||
sendJson(['success' => false, 'error' => 'Invalid currency_permanence'], 400);
|
||||
}
|
||||
$merged['currency_permanence'] = $p;
|
||||
}
|
||||
if (isset($body['timezone'])) {
|
||||
$merged['timezone'] = trim((string) $body['timezone']);
|
||||
}
|
||||
if (isset($body['week_starts_on'])) {
|
||||
$w = (int) $body['week_starts_on'];
|
||||
if ($w < 0 || $w > 6) {
|
||||
sendJson(['success' => false, 'error' => 'week_starts_on must be 0–6'], 400);
|
||||
}
|
||||
$merged['week_starts_on'] = $w;
|
||||
}
|
||||
|
||||
if (!writeJsonFile('family_settings.json', $merged)) {
|
||||
sendJson(['success' => false, 'error' => 'Failed to save settings'], 500);
|
||||
}
|
||||
|
||||
sendJson(['success' => true, 'settings' => $merged]);
|
||||
Reference in New Issue
Block a user