PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, ] ); $stmtLoc = $pdo->prepare( 'SELECT id, name, latitude, longitude, elevation, timezone FROM app_user_locations WHERE user_id = ? AND is_default = 1 LIMIT 1' ); $stmtLoc->execute([(int) $_SESSION['user_id']]); $defaultLocation = $stmtLoc->fetch() ?: null; } catch (Throwable $e) { $defaultLocation = null; } } $planetOptions = [ 'Sun' => 'Sonne', 'Moon' => 'Mond', 'Mercury' => 'Merkur', 'Venus' => 'Venus', 'Mars' => 'Mars', 'Jupiter' => 'Jupiter', 'Saturn' => 'Saturn', 'Uranus' => 'Uranus', 'Neptune' => 'Neptun', ]; $intervalOptions = [ '1' => '1 Minute', '10' => '10 Minuten', '30' => '30 Minuten', '60' => '1 Stunde', '360' => '6 Stunden', '720' => '12 Stunden', '1440' => '1 Tag', '10080' => '7 Tage', '20160' => '14 Tage', '43200' => '30 Tage', ]; $rangeUnitOptions = [ 'minutes' => 'Minuten', 'hours' => 'Stunden', 'days' => 'Tage', 'weeks' => 'Wochen', 'months' => 'Monate', 'years' => 'Jahre', ]; $selectedBody = (string) ($_POST['body'] ?? 'Mercury'); if (!isset($planetOptions[$selectedBody])) { $selectedBody = 'Mercury'; } $selectedInterval = (string) ($_POST['interval_minutes'] ?? '1440'); if (!isset($intervalOptions[$selectedInterval])) { $selectedInterval = '1440'; } $selectedRangeUnit = (string) ($_POST['range_unit'] ?? 'days'); if (!isset($rangeUnitOptions[$selectedRangeUnit])) { $selectedRangeUnit = 'days'; } $rangeValueInput = trim((string) ($_POST['range_value'] ?? '7')); if ($rangeValueInput === '') { $rangeValueInput = '7'; } function ephemeriden_h(mixed $value): string { return htmlspecialchars((string) $value, ENT_QUOTES, 'UTF-8'); } function ephemeriden_slug(string $value): string { $value = strtolower(trim($value)); $value = str_replace( ['ä', 'ö', 'ü', 'ß', ' '], ['ae', 'oe', 'ue', 'ss', '-'], $value ); $value = preg_replace('/[^a-z0-9\-]+/', '-', $value) ?? $value; $value = trim($value, '-'); return $value !== '' ? $value : 'ephemeriden'; } function runEphemeridenPythonApi(string $action, array $args): array { $scriptPath = __DIR__ . '/py/ephemeriden_api.py'; $pythonCandidates = PHP_OS_FAMILY === 'Windows' ? ['python', 'py'] : ['/usr/bin/python3', '/usr/bin/python', 'python3', 'python']; $escapedArguments = array_map('escapeshellarg', array_merge([$scriptPath, $action], $args)); $lastError = 'Python konnte nicht gestartet werden.'; foreach ($pythonCandidates as $pythonBinary) { $command = $pythonBinary . ' ' . implode(' ', $escapedArguments) . ' 2>&1'; $output = []; $resultCode = 0; exec($command, $output, $resultCode); $joined = trim(implode("\n", $output)); $decoded = json_decode($joined, true); if (is_array($decoded)) { return [ 'ok' => (bool) ($decoded['ok'] ?? false), 'data' => $decoded, 'raw' => $joined, 'command' => $command, ]; } if ($joined !== '') { $lastError = $joined; } elseif ($resultCode !== 0) { $lastError = 'Fehlercode ' . $resultCode . ' bei ' . $pythonBinary; } } return [ 'ok' => false, 'error' => $lastError, ]; } $pageLocation = null; if (is_array($defaultLocation) && $defaultLocation !== []) { $pageLocation = [ 'name' => trim((string) ($defaultLocation['name'] ?? '')), 'latitude' => isset($defaultLocation['latitude']) ? (float) $defaultLocation['latitude'] : null, 'longitude' => isset($defaultLocation['longitude']) ? (float) $defaultLocation['longitude'] : null, 'elevation' => isset($defaultLocation['elevation']) && $defaultLocation['elevation'] !== null ? (float) $defaultLocation['elevation'] : 0.0, 'timezone' => (string) ($defaultLocation['timezone'] ?? 'Europe/Berlin'), ]; } $defaultLocationName = $pageLocation['name'] ?? ''; $errorMessage = ''; $ephemerisRows = []; $exportFormat = (string) ($_POST['export_format'] ?? ''); if ($_SERVER['REQUEST_METHOD'] === 'POST') { if ($pageLocation === null || $pageLocation['latitude'] === null || $pageLocation['longitude'] === null) { $errorMessage = 'Kein gültiger Standard-Standort verfügbar. Bitte zuerst in den Einstellungen einen Standard-Standort setzen.'; } elseif (!ctype_digit($rangeValueInput) || (int) $rangeValueInput < 1 || (int) $rangeValueInput > 31) { $errorMessage = 'Der Zeitraum muss als ganze Zahl zwischen 1 und 31 angegeben werden.'; } else { $pythonResult = runEphemeridenPythonApi('planet_ephemeris', [ (string) $pageLocation['latitude'], (string) $pageLocation['longitude'], (string) $pageLocation['elevation'], (string) $pageLocation['timezone'], $selectedBody, $selectedInterval, $rangeValueInput, $selectedRangeUnit, ]); if (!$pythonResult['ok']) { $errorMessage = (string) ( $pythonResult['data']['error'] ?? $pythonResult['error'] ?? 'Die Ephemeriden konnten nicht berechnet werden.' ); } else { $ephemerisRows = $pythonResult['data']['rows'] ?? []; if (!is_array($ephemerisRows)) { $ephemerisRows = []; } if ($exportFormat === 'csv' && $ephemerisRows !== []) { $filename = 'ephemeriden-' . ephemeriden_slug((string) ($planetOptions[$selectedBody] ?? 'objekt')) . '.csv'; header('Content-Type: text/csv; charset=utf-8'); header('Content-Disposition: attachment; filename="' . $filename . '"'); header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0'); echo "\xEF\xBB\xBF"; $handle = fopen('php://output', 'wb'); if ($handle === false) { exit; } fputcsv($handle, ['Name des Objekts', 'Datum', 'Uhrzeit', 'RA (J2000)', 'RA (J2000, dezimal h)', 'Dek (J2000)', 'Dek (J2000, dezimal °)', 'Aufgang', 'Untergang'], ';', '"', '\\'); foreach ($ephemerisRows as $row) { fputcsv($handle, [ (string) ($row['object_name'] ?? ''), (string) ($row['date_local'] ?? ''), (string) ($row['time_local'] ?? ''), (string) ($row['ra'] ?? ''), (string) ($row['ra_decimal_hours'] ?? ''), (string) ($row['dec'] ?? ''), (string) ($row['dec_decimal_deg'] ?? ''), (string) (($row['rise'] ?? null) ?? '—'), (string) (($row['set'] ?? null) ?? '—'), ], ';', '"', '\\'); } fclose($handle); exit; } } } } require __DIR__ . '/header.php'; ?>

Ephemeriden

Standard-Standort:
Name des Objekts Datum Uhrzeit RA (J2000) Dek (J2000) Aufgang Untergang
Für die gewählte Anfrage wurden keine Tabellenzeilen erzeugt.
Noch keine Berechnung ausgeführt.