Calendar v2 - Combined Calendar Feature
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__ . '/../includes/api_bootstrap.php';
|
||||
require_once __DIR__ . '/../includes/family_settings.php';
|
||||
require_once __DIR__ . '/../includes/calendar_helpers.php';
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] !== 'GET') {
|
||||
sendJson(['success' => false, 'error' => 'Method not allowed'], 405);
|
||||
}
|
||||
|
||||
$people = normalizePeopleList(readJsonFile('people.json'));
|
||||
requireActivePerson($people);
|
||||
|
||||
$familySettings = loadFamilySettings();
|
||||
$from = isset($_GET['from']) ? trim((string) $_GET['from']) : '';
|
||||
$to = isset($_GET['to']) ? trim((string) $_GET['to']) : '';
|
||||
|
||||
if ($from === '' || !preg_match('/^\d{4}-\d{2}-\d{2}$/', $from)) {
|
||||
[$from, $to] = hubCalendarDefaultAgendaRange($familySettings);
|
||||
} else {
|
||||
if ($to === '' || !preg_match('/^\d{4}-\d{2}-\d{2}$/', $to)) {
|
||||
sendJson(['success' => false, 'error' => 'to must be YYYY-MM-DD when from is set'], 400);
|
||||
}
|
||||
}
|
||||
|
||||
if ($from > $to) {
|
||||
sendJson(['success' => false, 'error' => 'from must be on or before to'], 400);
|
||||
}
|
||||
|
||||
[, $tzLocal] = familyHubCalendarContext($familySettings);
|
||||
$today = familyHubTodayYmdInTz($tzLocal);
|
||||
$events = hubCalendarAgendaEvents($from, $to, $people, $familySettings);
|
||||
|
||||
sendJson([
|
||||
'success' => true,
|
||||
'events' => $events,
|
||||
'rangeStart' => $from,
|
||||
'rangeEnd' => $to,
|
||||
'today' => $today,
|
||||
]);
|
||||
@@ -31,7 +31,17 @@ if (isset($body['currency_permanence'])) {
|
||||
$merged['currency_permanence'] = $p;
|
||||
}
|
||||
if (isset($body['timezone'])) {
|
||||
$merged['timezone'] = trim((string) $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'];
|
||||
@@ -41,6 +51,8 @@ if (isset($body['week_starts_on'])) {
|
||||
$merged['week_starts_on'] = $w;
|
||||
}
|
||||
|
||||
$merged = normalizeLoadedFamilySettings($merged);
|
||||
|
||||
if (!writeJsonFile('family_settings.json', $merged)) {
|
||||
sendJson(['success' => false, 'error' => 'Failed to save settings'], 500);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user