diff --git a/public/images/moons/moon4calendar.png b/public/images/moons/moon4calendar.png new file mode 100644 index 0000000..af65e06 Binary files /dev/null and b/public/images/moons/moon4calendar.png differ diff --git a/public/moonyear.php b/public/moonyear.php index c0f8be7..5715a4f 100644 --- a/public/moonyear.php +++ b/public/moonyear.php @@ -3,10 +3,14 @@ declare(strict_types=1); session_start(); -$currentYear = (int) date('Y'); -$selectedYear = isset($_GET['year']) ? max(1900, min(2100, (int) $_GET['year'])) : $currentYear; +$currentYear = (int) date('Y'); +$currentMonth = (int) date('n'); +$selectedYear = isset($_GET['year']) ? max(1900, min(2100, (int) $_GET['year'])) : $currentYear; +$selectedMonth = isset($_GET['month']) ? max(1, min(12, (int) $_GET['month'])) : $currentMonth; +$activeTab = (isset($_GET['tab']) && $_GET['tab'] === 'month') ? 'month' : 'year'; +$doCalc = isset($_GET['calc']); -$pageTitle = 'Mondphasen-Jahresübersicht ' . $selectedYear . ' - AstroTools'; +$pageTitle = 'Mondphasen - AstroTools'; $bodyClass = 'moonyear-page'; $publicBasePath = './'; @@ -20,39 +24,83 @@ if (!empty($currentLocation['timezone'])) { $chartTimezone = (string) $currentLocation['timezone']; } -// ------------------------------------------------------------------------- -// Python: Mondphasen für alle 12 Monate abrufen -// ------------------------------------------------------------------------- $pythonExecutable = PHP_OS_FAMILY === 'Windows' ? 'python' : '/usr/bin/python'; $pythonScriptPath = __DIR__ . '/py/api.py'; -$allPhaseEvents = []; +$monthNamesDE = [ + 1 => 'Januar', 2 => 'Februar', 3 => 'März', 4 => 'April', + 5 => 'Mai', 6 => 'Juni', 7 => 'Juli', 8 => 'August', + 9 => 'September', 10 => 'Oktober', 11 => 'November', 12 => 'Dezember', +]; -for ($m = 1; $m <= 12; $m++) { +// ------------------------------------------------------------------------- +// Python: Jahresübersicht — nur wenn Tab=Jahr und Berechnen geklickt +// ------------------------------------------------------------------------- +$allPhaseEvents = []; +$lunarEclipses = []; // [{kind, month, day, local_time}, ...] +if ($doCalc && $activeTab === 'year') { + for ($m = 1; $m <= 12; $m++) { + $output = []; + $exitCode = 0; + $cmd = $pythonExecutable . ' ' . implode(' ', array_map('escapeshellarg', [ + $pythonScriptPath, 'moon_phases_for_month', + (string) $selectedYear, (string) $m, $chartTimezone, + ])) . ' 2>&1'; + exec($cmd, $output, $exitCode); + $decoded = json_decode(trim(implode("\n", $output)), true); + if (is_array($decoded) && ($decoded['ok'] ?? false) && is_array($decoded['phases'] ?? null)) { + foreach ($decoded['phases'] as $phase) { + $parts = explode('.', (string) ($phase['local_date'] ?? '')); + if (count($parts) === 3) { + $day = (int) $parts[0]; + $month = (int) $parts[1]; + if ($month === $m && $day >= 1 && $day <= 31) { + $allPhaseEvents[] = [ + 'month' => $month, + 'day' => $day, + 'label' => (string) ($phase['label'] ?? ''), + 'time' => (string) ($phase['local_time'] ?? ''), + ]; + } + } + } + } + } + + // Mondfinsternisse für das Jahr + $ecOutput = []; + $ecExitCode = 0; + $ecCmd = $pythonExecutable . ' ' . implode(' ', array_map('escapeshellarg', [ + $pythonScriptPath, 'lunar_eclipses_for_year', + (string) $selectedYear, $chartTimezone, + ])) . ' 2>&1'; + exec($ecCmd, $ecOutput, $ecExitCode); + $ecDecoded = json_decode(trim(implode("\n", $ecOutput)), true); + if (is_array($ecDecoded) && ($ecDecoded['ok'] ?? false) && is_array($ecDecoded['eclipses'] ?? null)) { + $lunarEclipses = $ecDecoded['eclipses']; + } +} + +// ------------------------------------------------------------------------- +// Python: Monatskalender — nur wenn Tab=Monat und Berechnen geklickt +// ------------------------------------------------------------------------- +$calPhaseEvents = []; +if ($doCalc && $activeTab === 'month') { $output = []; $exitCode = 0; - $args = [ - $pythonScriptPath, - 'moon_phases_for_month', - (string) $selectedYear, - (string) $m, - $chartTimezone, - ]; - $cmd = $pythonExecutable . ' ' . implode(' ', array_map('escapeshellarg', $args)) . ' 2>&1'; + $cmd = $pythonExecutable . ' ' . implode(' ', array_map('escapeshellarg', [ + $pythonScriptPath, 'moon_phases_for_month', + (string) $selectedYear, (string) $selectedMonth, $chartTimezone, + ])) . ' 2>&1'; exec($cmd, $output, $exitCode); - $raw = trim(implode("\n", $output)); - $decoded = json_decode($raw, true); + $decoded = json_decode(trim(implode("\n", $output)), true); if (is_array($decoded) && ($decoded['ok'] ?? false) && is_array($decoded['phases'] ?? null)) { foreach ($decoded['phases'] as $phase) { - // local_date format: "DD.MM.YYYY" $parts = explode('.', (string) ($phase['local_date'] ?? '')); if (count($parts) === 3) { - $day = (int) $parts[0]; - $month = (int) $parts[1]; - if ($month === $m && $day >= 1 && $day <= 31) { - $allPhaseEvents[] = [ - 'month' => $month, - 'day' => $day, + $day = (int) $parts[0]; + if ($day >= 1 && $day <= 31) { + $calPhaseEvents[$day] = [ 'label' => (string) ($phase['label'] ?? ''), 'time' => (string) ($phase['local_time'] ?? ''), ]; @@ -60,371 +108,588 @@ for ($m = 1; $m <= 12; $m++) { } } } + + // Mondfinsternisse für das Jahr (für den Monats-Tab benötigt) + $ecOutput = []; + $ecExitCode = 0; + $ecCmd = $pythonExecutable . ' ' . implode(' ', array_map('escapeshellarg', [ + $pythonScriptPath, 'lunar_eclipses_for_year', + (string) $selectedYear, $chartTimezone, + ])) . ' 2>&1'; + exec($ecCmd, $ecOutput, $ecExitCode); + $ecDecoded = json_decode(trim(implode("\n", $ecOutput)), true); + if (is_array($ecDecoded) && ($ecDecoded['ok'] ?? false) && is_array($ecDecoded['eclipses'] ?? null)) { + $lunarEclipses = $ecDecoded['eclipses']; + } } ?>
Zeichne Mondphasen-Jahresübersicht…
-Zeichne Jahresübersicht…
+ +Zeichne Monatskalender…
+ +