Ephemeriden verbessert

This commit is contained in:
2026-04-28 17:17:03 +02:00
parent dd0a390344
commit 8671ba65bf
+60 -74
View File
@@ -334,15 +334,6 @@ $intervalOptions = [
'43200' => '30 Tage',
];
$rangeUnitOptions = [
'minutes' => 'Minuten',
'hours' => 'Stunden',
'days' => 'Tage',
'weeks' => 'Wochen',
'months' => 'Monate',
'years' => 'Jahre',
];
$selectedBody = (string) ($_POST['body'] ?? 'Mercury');
if (!isset($bodyOptions[$selectedBody])) {
$selectedBody = 'Mercury';
@@ -353,22 +344,16 @@ 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';
}
$startDtInput = trim((string) ($_POST['start_dt'] ?? ''));
// Validierung: muss leer sein (= jetzt) oder dem Format YYYY-MM-DDTHH:MM entsprechen
if ($startDtInput !== '' && !preg_match('/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}$/', $startDtInput)) {
$startDtInput = '';
}
$endDtInput = trim((string) ($_POST['end_dt'] ?? ''));
if ($endDtInput !== '' && !preg_match('/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}$/', $endDtInput)) {
$endDtInput = '';
}
function ephemeriden_h(mixed $value): string
{
return htmlspecialchars((string) $value, ENT_QUOTES, 'UTF-8');
@@ -449,51 +434,63 @@ $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 > 100) {
$errorMessage = 'Der Zeitraum muss als ganze Zahl zwischen 1 und 100 angegeben werden.';
} elseif ($endDtInput === '') {
$errorMessage = 'Bitte ein Enddatum angeben.';
} else {
$pythonAction = 'planet_ephemeris';
$pythonArgs = [
(string) $pageLocation['latitude'],
(string) $pageLocation['longitude'],
(string) $pageLocation['elevation'],
(string) $pageLocation['timezone'],
$selectedBody,
$selectedInterval,
$rangeValueInput,
$selectedRangeUnit,
$startDtInput,
];
$tz = new DateTimeZone($pageLocation['timezone']);
$startDt = $startDtInput !== ''
? DateTimeImmutable::createFromFormat('Y-m-d\TH:i', $startDtInput, $tz)
: new DateTimeImmutable('now', $tz);
$endDt = DateTimeImmutable::createFromFormat('Y-m-d\TH:i', $endDtInput, $tz);
if (isset($minorplanetPayloads[$selectedBody])) {
$pythonAction = 'small_body_ephemeris';
if ($startDt === false || $endDt === false) {
$errorMessage = 'Start- oder Enddatum ist ungültig.';
} elseif ($endDt <= $startDt) {
$errorMessage = 'Das Enddatum muss nach dem Startdatum liegen.';
} else {
$rangeMinutes = (string) (int) round(($endDt->getTimestamp() - $startDt->getTimestamp()) / 60);
$pythonAction = 'planet_ephemeris';
$pythonArgs = [
(string) $pageLocation['latitude'],
(string) $pageLocation['longitude'],
(string) $pageLocation['elevation'],
(string) $pageLocation['timezone'],
'minorplanet',
base64_encode(json_encode($minorplanetPayloads[$selectedBody], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) ?: '{}'),
$selectedBody,
$selectedInterval,
$rangeValueInput,
$selectedRangeUnit,
$rangeMinutes,
'minutes',
$startDtInput,
];
} elseif (isset($cometPayloads[$selectedBody])) {
$pythonAction = 'small_body_ephemeris';
$pythonArgs = [
(string) $pageLocation['latitude'],
(string) $pageLocation['longitude'],
(string) $pageLocation['elevation'],
(string) $pageLocation['timezone'],
'comet',
base64_encode(json_encode($cometPayloads[$selectedBody], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) ?: '{}'),
$selectedInterval,
$rangeValueInput,
$selectedRangeUnit,
$startDtInput,
];
}
if (isset($minorplanetPayloads[$selectedBody])) {
$pythonAction = 'small_body_ephemeris';
$pythonArgs = [
(string) $pageLocation['latitude'],
(string) $pageLocation['longitude'],
(string) $pageLocation['elevation'],
(string) $pageLocation['timezone'],
'minorplanet',
base64_encode(json_encode($minorplanetPayloads[$selectedBody], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) ?: '{}'),
$selectedInterval,
$rangeMinutes,
'minutes',
$startDtInput,
];
} elseif (isset($cometPayloads[$selectedBody])) {
$pythonAction = 'small_body_ephemeris';
$pythonArgs = [
(string) $pageLocation['latitude'],
(string) $pageLocation['longitude'],
(string) $pageLocation['elevation'],
(string) $pageLocation['timezone'],
'comet',
base64_encode(json_encode($cometPayloads[$selectedBody], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) ?: '{}'),
$selectedInterval,
$rangeMinutes,
'minutes',
$startDtInput,
];
}
$pythonResult = runEphemeridenPythonApi($pythonAction, $pythonArgs);
@@ -544,6 +541,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
exit;
}
}
}
}
}
@@ -781,33 +779,21 @@ require __DIR__ . '/header.php';
type="datetime-local"
id="ephemeridenStartDt"
name="start_dt"
value="<?= ephemeriden_h($startDtInput) ?>"
value="<?= ephemeriden_h($startDtInput !== '' ? $startDtInput : (new DateTimeImmutable('now', new DateTimeZone($pageLocation['timezone'] ?? 'Europe/Berlin')))->format('Y-m-d\TH:i')) ?>"
>
</div>
<div class="form-group">
<label for="ephemeridenRangeValue">Zeitraum</label>
<label for="ephemeridenEndDt">Enddatum &amp; Uhrzeit</label>
<input
type="number"
id="ephemeridenRangeValue"
name="range_value"
min="1"
max="100"
step="1"
value="<?= ephemeriden_h($rangeValueInput) ?>"
inputmode="numeric"
type="datetime-local"
id="ephemeridenEndDt"
name="end_dt"
value="<?= ephemeriden_h($endDtInput !== '' ? $endDtInput : (new DateTimeImmutable('+7 days', new DateTimeZone($pageLocation['timezone'] ?? 'Europe/Berlin')))->format('Y-m-d\TH:i')) ?>"
required
>
</div>
<div class="form-group">
<label for="ephemeridenRangeUnit">Einheit</label>
<select id="ephemeridenRangeUnit" name="range_unit">
<?php foreach ($rangeUnitOptions as $rangeUnitValue => $rangeUnitLabel): ?>
<option value="<?= ephemeriden_h($rangeUnitValue) ?>"<?= $rangeUnitValue === $selectedRangeUnit ? ' selected' : '' ?>><?= ephemeriden_h($rangeUnitLabel) ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="ephemeriden-submit-group">
<button type="submit" class="btn btn-primary">Berechnen</button>
</div>