From ddbda72c685a7e04e7c78bbb25fff4ff9344b11c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Fri, 10 Apr 2026 20:15:57 +0200 Subject: [PATCH] Favoritenseite Dynamisch gemacht --- config/skyview.sql | 17 ++ public/css/style.css | 16 ++ public/my_favorites.php | 371 ++++++++++++++++++++++++++++++++++------ 3 files changed, 353 insertions(+), 51 deletions(-) diff --git a/config/skyview.sql b/config/skyview.sql index 0944c24..8c8bdae 100644 --- a/config/skyview.sql +++ b/config/skyview.sql @@ -82,6 +82,23 @@ CREATE TABLE IF NOT EXISTS `app_user_locations` ( -- Daten-Export vom Benutzer nicht ausgewählt +-- Exportiere Struktur von Tabelle d0467f49.app_user_comets +CREATE TABLE IF NOT EXISTS `app_user_comets` ( + `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, + `user_id` bigint(20) unsigned NOT NULL, + `comet_id` bigint(20) unsigned NOT NULL, + `is_favorite` tinyint(1) NOT NULL DEFAULT 0, + `created_at` datetime NOT NULL DEFAULT current_timestamp(), + PRIMARY KEY (`id`), + UNIQUE KEY `uq_app_user_comets_user_comet` (`user_id`,`comet_id`), + KEY `idx_app_user_comets_user_id` (`user_id`), + KEY `idx_app_user_comets_comet_id` (`comet_id`), + CONSTRAINT `fk_app_user_comets_comet_id` FOREIGN KEY (`comet_id`) REFERENCES `comets_mpc` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `fk_app_user_comets_user_id` FOREIGN KEY (`user_id`) REFERENCES `app_users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + +-- Daten-Export vom Benutzer nicht ausgewählt + -- Exportiere Struktur von Tabelle d0467f49.app_user_minorplanets CREATE TABLE IF NOT EXISTS `app_user_minorplanets` ( `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, diff --git a/public/css/style.css b/public/css/style.css index faa3dfc..864fc8f 100644 --- a/public/css/style.css +++ b/public/css/style.css @@ -927,6 +927,17 @@ footer a:hover { color: var(--gold); } border-color: var(--cyan); } +.btn-secondary.favorite-active { + border-color: var(--gold-dim); + color: var(--gold); +} + +.btn-secondary.favorite-active:hover { + background: rgba(201, 168, 76, 0.12); + border-color: var(--gold); + color: var(--gold-pale); +} + .btn-danger { border-color: rgba(200, 60, 60, 0.35); color: #f08080; @@ -1368,6 +1379,11 @@ footer a:hover { color: var(--gold); } margin: 0; } +.favorite-text { + color: var(--gold); + font-weight: 600; +} + @media (max-width: 720px) { .favorites-search-summary { flex-direction: column; diff --git a/public/my_favorites.php b/public/my_favorites.php index 33b3c53..e66f49a 100644 --- a/public/my_favorites.php +++ b/public/my_favorites.php @@ -34,8 +34,10 @@ $errors = []; $successMessage = ''; $satelliteSearchResults = []; $minorplanetSearchResults = []; +$cometSearchResults = []; $satelliteSearchQuery = trim($_GET['sat_q'] ?? ''); $minorplanetSearchQuery = trim($_GET['mp_q'] ?? ''); +$cometSearchQuery = trim($_GET['com_q'] ?? ''); $pageTitle = 'Favoriten - AstroTools'; $headerIntroPre = 'Merkliste'; $headerIntroTitle = 'Favoriten'; @@ -98,12 +100,12 @@ function renderLocationsSection(array $locations, bool $oob = false): string - - - - - - + + + + + + @@ -352,22 +348,20 @@ function renderTrackedMinorplanetsSection(array $trackedMinorplanets, bool $oob Bezeichnung Nummer Favorit - Hinzugefuegt - - - - + + +
-
@@ -388,6 +382,118 @@ function renderTrackedMinorplanetsSection(array $trackedMinorplanets, bool $oob return (string) ob_get_clean(); } +function renderCometSearchResults(string $cometSearchQuery, array $cometSearchResults, bool $oob = false): string +{ + ob_start(); + ?> +
+ > + +
+

Noch keine Suche gestartet.

+

Suche nach MPC-Bezeichnung oder Kometenname, um passende Kometen direkt hier einzublenden.

+
+ +
+

Suchergebnisse

+

+ Treffer fuer +

+
+ + +
+

Keine passenden Kometen gefunden.

+

Probiere eine Bezeichnung wie 67P oder einen Namen wie Halley.

+
+ +
+ + + + + + + + + + + + + + + +
Bezeichnung
+ +
+ + + +
+ +
+
+ + +
+ +
> +

Meine Kometen

+ +

Du hast noch keine Kometen ausgewaehlt.

+ + + + + + + + + + + + + + + + + + + + +
BezeichnungTypFavorit
+
+ + + +
+
+ + + +
+
+ +
+ prepare(" + SELECT `id` + FROM `comets_mpc` + WHERE `id` = :id + LIMIT 1 + "); + $stmtCheck->execute([ + ':id' => $cometId, + ]); + + if (!$stmtCheck->fetch()) { + $errors[] = 'Der Komet wurde nicht gefunden.'; + } + } + + if (empty($errors)) { + $stmtInsert = $pdo->prepare(" + INSERT INTO `app_user_comets` ( + `user_id`, + `comet_id`, + `is_favorite`, + `created_at` + ) VALUES ( + :user_id, + :comet_id, + 0, + NOW() + ) + ON DUPLICATE KEY UPDATE + `comet_id` = VALUES(`comet_id`) + "); + $stmtInsert->execute([ + ':user_id' => $userId, + ':comet_id' => $cometId, + ]); + + $successMessage = 'Der Komet wurde hinzugefuegt.'; + } + } + + if ($action === 'remove_comet') { + $cometId = (int) ($_POST['comet_id'] ?? 0); + + if ($cometId <= 0) { + $errors[] = 'Ungueltiger Komet.'; + } + + if (empty($errors)) { + $stmtDelete = $pdo->prepare(" + DELETE FROM `app_user_comets` + WHERE `user_id` = :user_id + AND `comet_id` = :comet_id + "); + $stmtDelete->execute([ + ':user_id' => $userId, + ':comet_id' => $cometId, + ]); + + $successMessage = 'Der Komet wurde entfernt.'; + } + } + + if ($action === 'toggle_comet_favorite') { + $cometId = (int) ($_POST['comet_id'] ?? 0); + + if ($cometId <= 0) { + $errors[] = 'Ungueltiger Komet.'; + } + + if (empty($errors)) { + if (!setExclusiveFavorite($pdo, 'app_user_comets', 'comet_id', $userId, $cometId)) { + $errors[] = 'Der Komet ist nicht in deiner Liste vorhanden.'; + } else { + $successMessage = 'Der Kometen-Favorit wurde aktualisiert.'; + } + } + } + if ($action === 'add_location') { $name = trim($_POST['name'] ?? ''); $latitude = trim($_POST['latitude'] ?? ''); @@ -1271,6 +1466,34 @@ if ($minorplanetSearchQuery !== '') { $minorplanetSearchResults = $stmtMinorplanetSearch->fetchAll(); } +if ($cometSearchQuery !== '') { + $stmtCometSearch = $pdo->prepare(" + SELECT + c.`id`, + c.`designation_and_name`, + c.`designation_packed`, + c.`orbit_type`, + CASE + WHEN auc.`comet_id` IS NULL THEN 0 + ELSE 1 + END AS `already_added` + FROM `comets_mpc` c + LEFT JOIN `app_user_comets` auc + ON auc.`comet_id` = c.`id` + AND auc.`user_id` = :user_id + WHERE c.`designation_and_name` LIKE :query + OR c.`designation_packed` LIKE :query + ORDER BY c.`orbit_type` ASC, c.`designation_and_name` ASC + LIMIT 50 + "); + $stmtCometSearch->execute([ + ':user_id' => $userId, + ':query' => '%' . $cometSearchQuery . '%', + ]); + + $cometSearchResults = $stmtCometSearch->fetchAll(); +} + $stmtTrackedSatellites = $pdo->prepare(" SELECT s.`id`, @@ -1308,6 +1531,24 @@ $stmtTrackedMinorplanets->execute([ ]); $trackedMinorplanets = $stmtTrackedMinorplanets->fetchAll(); +$stmtTrackedComets = $pdo->prepare(" + SELECT + c.`id`, + c.`designation_and_name`, + c.`orbit_type`, + auc.`is_favorite`, + auc.`created_at` + 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.`orbit_type` ASC, c.`designation_and_name` ASC +"); +$stmtTrackedComets->execute([ + ':user_id' => $userId, +]); +$trackedComets = $stmtTrackedComets->fetchAll(); + if (isHtmxRequest()) { if ($_SERVER['REQUEST_METHOD'] === 'GET' && array_key_exists('sat_q', $_GET)) { echo renderSatelliteSearchResults($satelliteSearchQuery, $satelliteSearchResults); @@ -1319,6 +1560,11 @@ if (isHtmxRequest()) { exit; } + if ($_SERVER['REQUEST_METHOD'] === 'GET' && array_key_exists('com_q', $_GET)) { + echo renderCometSearchResults($cometSearchQuery, $cometSearchResults); + exit; + } + if ($_SERVER['REQUEST_METHOD'] === 'POST') { if ($htmxTriggers !== []) { header('HX-Trigger: ' . (string) json_encode($htmxTriggers)); @@ -1328,8 +1574,10 @@ if (isHtmxRequest()) { echo renderLocationsSection($locations, true); echo renderSatelliteSearchResults($satelliteSearchQuery, $satelliteSearchResults, true); echo renderMinorplanetSearchResults($minorplanetSearchQuery, $minorplanetSearchResults, true); + echo renderCometSearchResults($cometSearchQuery, $cometSearchResults, true); echo renderTrackedSatellitesSection($trackedSatellites, true); echo renderTrackedMinorplanetsSection($trackedMinorplanets, true); + echo renderTrackedCometsSection($trackedComets, true); exit; } } @@ -1368,12 +1616,12 @@ $loggedIn = true; - - - - - - + + + + + + + + + + + +
@@ -1657,17 +1928,15 @@ $loggedIn = true; Name NORAD Favorit - Hinzugefuegt - - - - + + + Favorit bleibt gesetzt @@ -1675,7 +1944,7 @@ $loggedIn = true;
-
@@ -1708,22 +1977,20 @@ $loggedIn = true; Bezeichnung Nummer Favorit - Hinzugefuegt - - - - + + +
-
@@ -1739,6 +2006,8 @@ $loggedIn = true;
+ +