diff --git a/public/solarsystem.php b/public/solarsystem.php index 8ed2215..b673e33 100644 --- a/public/solarsystem.php +++ b/public/solarsystem.php @@ -7,6 +7,7 @@ session_start(); $loggedIn = isset($_SESSION['user_id']); $trackedMinorplanetsForJs = []; +$trackedCometsForJs = []; function h(?string $value): string { @@ -71,6 +72,39 @@ function formatMinorplanetDisplayName(array $minorplanet): string return $designation !== '' ? $designation : (string) ($minorplanet['packedDesignation'] ?? $minorplanet['desig_packed'] ?? '--'); } +function formatCometDisplayName(array $comet): string +{ + $designation = trim((string) ($comet['designation_and_name'] ?? $comet['designation'] ?? '')); + return $designation !== '' ? $designation : (string) ($comet['designation_packed'] ?? $comet['packedDesignation'] ?? '--'); +} + +function buildCometPerihelionIso(array $comet): ?string +{ + $year = isset($comet['year_of_perihelion']) ? (int) $comet['year_of_perihelion'] : 0; + $month = isset($comet['month_of_perihelion']) ? (int) $comet['month_of_perihelion'] : 0; + $dayValue = isset($comet['day_of_perihelion']) ? (float) $comet['day_of_perihelion'] : 0.0; + + if ($year <= 0 || $month < 1 || $month > 12 || $dayValue <= 0.0) { + return null; + } + + $day = (int) floor($dayValue); + if ($day < 1 || $day > 31) { + return null; + } + + $fractionalDay = $dayValue - $day; + $seconds = (int) round($fractionalDay * 86400.0); + + try { + $date = new DateTimeImmutable(sprintf('%04d-%02d-%02d 00:00:00', $year, $month, $day), new DateTimeZone('UTC')); + } catch (Throwable $e) { + return null; + } + + return $date->modify(sprintf('+%d seconds', $seconds))->format('c'); +} + if ($loggedIn) { try { $config = require __DIR__ . '/../config/database.php'; @@ -138,8 +172,54 @@ if ($loggedIn) { 'isFavorite' => (bool) $minorplanet['is_favorite'], ]; } + + $stmtTrackedComets = $pdo->prepare(" + SELECT + c.`id`, + c.`designation_packed`, + c.`designation_and_name`, + c.`orbit_type`, + c.`year_of_perihelion`, + c.`month_of_perihelion`, + c.`day_of_perihelion`, + c.`perihelion_dist_au`, + c.`eccentricity`, + c.`arg_perihelion_deg`, + c.`ascending_node_deg`, + c.`inclination_deg`, + c.`absolute_magnitude_h`, + c.`slope_parameter_g`, + auc.`is_favorite` + FROM `app_user_comets` auc + INNER JOIN `comets_mpc` c + ON c.`id` = auc.`comet_id` + WHERE auc.`user_id` = :user_id + ORDER BY auc.`is_favorite` DESC, c.`year_of_perihelion` ASC, c.`month_of_perihelion` ASC, c.`day_of_perihelion` ASC, c.`designation_and_name` ASC + "); + $stmtTrackedComets->execute([ + ':user_id' => (int) $_SESSION['user_id'], + ]); + + foreach ($stmtTrackedComets->fetchAll() as $comet) { + $trackedCometsForJs[] = [ + 'id' => (int) $comet['id'], + 'designation' => (string) $comet['designation_and_name'], + 'packedDesignation' => (string) $comet['designation_packed'], + 'orbitType' => (string) $comet['orbit_type'], + 'perihelionIso' => buildCometPerihelionIso($comet), + 'perihelionDistanceAu' => (float) $comet['perihelion_dist_au'], + 'eccentricity' => (float) $comet['eccentricity'], + 'argPerihelionDeg' => (float) $comet['arg_perihelion_deg'], + 'ascendingNodeDeg' => (float) $comet['ascending_node_deg'], + 'inclinationDeg' => (float) $comet['inclination_deg'], + 'absoluteMagnitudeH' => $comet['absolute_magnitude_h'] !== null ? (float) $comet['absolute_magnitude_h'] : null, + 'photometricIndex' => $comet['slope_parameter_g'] !== null ? (float) $comet['slope_parameter_g'] : null, + 'isFavorite' => (bool) $comet['is_favorite'], + ]; + } } catch (Throwable $e) { $trackedMinorplanetsForJs = []; + $trackedCometsForJs = []; } } @@ -219,6 +299,34 @@ $bodyClass = 'solarsystem-page'; +
+
Komet
+
+
> + + + +
+ + + + + +
+
+
+
+ +
+
+
Hinweise