familyHub/api/family_settings_save.php
Louis Whittington f14de0b7e1 Add NFC chore submission feature and enhance family settings
- Introduced NFC support for chore submissions, allowing specific person credit after Head of Household approval.
- Updated family settings to include NFC base URL, scan cooldown, and confirmation page options.
- Enhanced chore management with options for anyone to complete chores and NFC link generation.
- Improved API endpoints for handling NFC tokens and chore submissions.
- Updated readme to reflect new NFC features and settings.
2026-03-31 10:28:27 -05:00

78 lines
2.8 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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'])) {
$tz = trim((string) $body['timezone']);
if (!in_array($tz, familyHubUsTimezoneIdentifiers(), true)) {
sendJson(['success' => false, 'error' => 'Invalid timezone'], 400);
}
$merged['timezone'] = $tz;
}
if (array_key_exists('calendar_two_way_google', $body)) {
$merged['calendar_two_way_google'] = !empty($body['calendar_two_way_google']);
}
if (isset($body['calendar_bill_days'])) {
$merged['calendar_bill_days'] = normalizeCalendarBillDaysRaw($body['calendar_bill_days']);
}
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 06'], 400);
}
$merged['week_starts_on'] = $w;
}
if (array_key_exists('nfc_base_url', $body)) {
$baseUrl = trim((string) $body['nfc_base_url']);
if ($baseUrl !== '' && !preg_match('#^https?://#i', $baseUrl)) {
sendJson(['success' => false, 'error' => 'nfc_base_url must start with http:// or https://'], 400);
}
$merged['nfc_base_url'] = rtrim($baseUrl, '/');
}
if (array_key_exists('nfc_show_confirmation', $body)) {
$merged['nfc_show_confirmation'] = !empty($body['nfc_show_confirmation']);
}
if (array_key_exists('nfc_scan_cooldown_seconds', $body)) {
$cooldown = (int) $body['nfc_scan_cooldown_seconds'];
if ($cooldown < 0 || $cooldown > 600) {
sendJson(['success' => false, 'error' => 'nfc_scan_cooldown_seconds must be 0-600'], 400);
}
$merged['nfc_scan_cooldown_seconds'] = $cooldown;
}
$merged = normalizeLoadedFamilySettings($merged);
if (!writeJsonFile('family_settings.json', $merged)) {
sendJson(['success' => false, 'error' => 'Failed to save settings'], 500);
}
sendJson(['success' => true, 'settings' => $merged]);