From 5dfc805915ef6a8e264cbb6be1ccfae84ea77661 Mon Sep 17 00:00:00 2001 From: Eskimue Date: Sun, 5 Apr 2026 15:03:36 +0200 Subject: [PATCH] Favoriten gefixt --- .codex-temp/php-server-error.log | 127 +++++++++++++++ public/css/style.css | 8 + public/my_favorites.php | 266 ++++++++++++++++++++++++++++++- 3 files changed, 393 insertions(+), 8 deletions(-) diff --git a/.codex-temp/php-server-error.log b/.codex-temp/php-server-error.log index cd52f14..1b0c7d3 100644 --- a/.codex-temp/php-server-error.log +++ b/.codex-temp/php-server-error.log @@ -350,3 +350,130 @@ [Sun Apr 5 14:33:51 2026] 127.0.0.1:49497 Closing [Sun Apr 5 14:33:53 2026] 127.0.0.1:62595 [200]: GET /favicon.ico [Sun Apr 5 14:33:53 2026] 127.0.0.1:62595 Closing +[Sun Apr 5 14:37:33 2026] 127.0.0.1:63475 Accepted +[Sun Apr 5 14:37:36 2026] 127.0.0.1:63475 [200]: GET /sternbedeckungen.php +[Sun Apr 5 14:37:36 2026] 127.0.0.1:63475 Closing +[Sun Apr 5 14:37:36 2026] 127.0.0.1:50828 Accepted +[Sun Apr 5 14:37:36 2026] 127.0.0.1:50828 [200]: GET /css/style.css +[Sun Apr 5 14:37:36 2026] 127.0.0.1:50828 Closing +[Sun Apr 5 14:37:36 2026] 127.0.0.1:53794 Accepted +[Sun Apr 5 14:37:36 2026] 127.0.0.1:53794 [200]: GET /js/astronomy.browser.min.js +[Sun Apr 5 14:37:36 2026] 127.0.0.1:53794 Closing +[Sun Apr 5 14:37:36 2026] 127.0.0.1:51101 Accepted +[Sun Apr 5 14:37:36 2026] 127.0.0.1:57430 Accepted +[Sun Apr 5 14:37:36 2026] 127.0.0.1:51101 [200]: GET /images/star16x16.png +[Sun Apr 5 14:37:36 2026] 127.0.0.1:57430 [200]: GET /images/star16x16_rays.png +[Sun Apr 5 14:37:36 2026] 127.0.0.1:51101 Closing +[Sun Apr 5 14:37:36 2026] 127.0.0.1:57430 Closing +[Sun Apr 5 14:37:36 2026] 127.0.0.1:56849 Accepted +[Sun Apr 5 14:37:38 2026] 127.0.0.1:56849 [200]: GET /favicon.ico +[Sun Apr 5 14:37:38 2026] 127.0.0.1:56849 Closing +[Sun Apr 5 14:37:38 2026] 127.0.0.1:53001 Accepted +[Sun Apr 5 14:37:39 2026] 127.0.0.1:53001 [200]: POST /sternbedeckungen.php +[Sun Apr 5 14:37:39 2026] 127.0.0.1:53001 Closing +[Sun Apr 5 14:37:50 2026] 127.0.0.1:63695 Accepted +[Sun Apr 5 14:37:50 2026] 127.0.0.1:63695 [200]: POST /sternbedeckungen.php +[Sun Apr 5 14:37:50 2026] 127.0.0.1:63695 Closing +[Sun Apr 5 14:37:50 2026] 127.0.0.1:56501 Accepted +[Sun Apr 5 14:37:51 2026] 127.0.0.1:56501 [200]: POST /sternbedeckungen.php +[Sun Apr 5 14:37:51 2026] 127.0.0.1:56501 Closing +[Sun Apr 5 14:37:51 2026] 127.0.0.1:53862 Accepted +[Sun Apr 5 14:37:52 2026] 127.0.0.1:53862 [200]: POST /sternbedeckungen.php +[Sun Apr 5 14:37:52 2026] 127.0.0.1:53862 Closing +[Sun Apr 5 14:37:52 2026] 127.0.0.1:55669 Accepted +[Sun Apr 5 14:37:52 2026] 127.0.0.1:55669 [200]: POST /sternbedeckungen.php +[Sun Apr 5 14:37:52 2026] 127.0.0.1:55669 Closing +[Sun Apr 5 14:37:52 2026] 127.0.0.1:56347 Accepted +[Sun Apr 5 14:37:53 2026] 127.0.0.1:56347 [200]: POST /sternbedeckungen.php +[Sun Apr 5 14:37:53 2026] 127.0.0.1:56347 Closing +[Sun Apr 5 14:37:53 2026] 127.0.0.1:56477 Accepted +[Sun Apr 5 14:37:54 2026] 127.0.0.1:56477 [200]: POST /sternbedeckungen.php +[Sun Apr 5 14:37:54 2026] 127.0.0.1:56477 Closing +[Sun Apr 5 14:37:55 2026] 127.0.0.1:53425 Accepted +[Sun Apr 5 14:37:56 2026] 127.0.0.1:53425 [200]: POST /sternbedeckungen.php +[Sun Apr 5 14:37:56 2026] 127.0.0.1:53425 Closing +[Sun Apr 5 14:37:56 2026] 127.0.0.1:60491 Accepted +[Sun Apr 5 14:37:56 2026] 127.0.0.1:60491 [200]: POST /sternbedeckungen.php +[Sun Apr 5 14:37:56 2026] 127.0.0.1:60491 Closing +[Sun Apr 5 14:37:56 2026] 127.0.0.1:53960 Accepted +[Sun Apr 5 14:37:57 2026] 127.0.0.1:53960 [200]: POST /sternbedeckungen.php +[Sun Apr 5 14:37:57 2026] 127.0.0.1:53960 Closing +[Sun Apr 5 14:37:57 2026] 127.0.0.1:52660 Accepted +[Sun Apr 5 14:37:57 2026] 127.0.0.1:52660 [200]: POST /sternbedeckungen.php +[Sun Apr 5 14:37:57 2026] 127.0.0.1:52660 Closing +[Sun Apr 5 14:37:58 2026] 127.0.0.1:49392 Accepted +[Sun Apr 5 14:37:58 2026] 127.0.0.1:49392 [200]: POST /sternbedeckungen.php +[Sun Apr 5 14:37:58 2026] 127.0.0.1:49392 Closing +[Sun Apr 5 14:37:58 2026] 127.0.0.1:59111 Accepted +[Sun Apr 5 14:37:59 2026] 127.0.0.1:59111 [200]: POST /sternbedeckungen.php +[Sun Apr 5 14:37:59 2026] 127.0.0.1:59111 Closing +[Sun Apr 5 14:37:59 2026] 127.0.0.1:62989 Accepted +[Sun Apr 5 14:38:00 2026] 127.0.0.1:62989 [200]: POST /sternbedeckungen.php +[Sun Apr 5 14:38:00 2026] 127.0.0.1:62989 Closing +[Sun Apr 5 14:38:00 2026] 127.0.0.1:61425 Accepted +[Sun Apr 5 14:38:00 2026] 127.0.0.1:61425 [200]: POST /sternbedeckungen.php +[Sun Apr 5 14:38:00 2026] 127.0.0.1:61425 Closing +[Sun Apr 5 14:38:00 2026] 127.0.0.1:64278 Accepted +[Sun Apr 5 14:38:01 2026] 127.0.0.1:64278 [200]: POST /sternbedeckungen.php +[Sun Apr 5 14:38:01 2026] 127.0.0.1:64278 Closing +[Sun Apr 5 14:38:01 2026] 127.0.0.1:49551 Accepted +[Sun Apr 5 14:38:01 2026] 127.0.0.1:49551 [200]: POST /sternbedeckungen.php +[Sun Apr 5 14:38:01 2026] 127.0.0.1:49551 Closing +[Sun Apr 5 14:38:02 2026] 127.0.0.1:61669 Accepted +[Sun Apr 5 14:38:02 2026] 127.0.0.1:61669 [200]: POST /sternbedeckungen.php +[Sun Apr 5 14:38:02 2026] 127.0.0.1:61669 Closing +[Sun Apr 5 14:38:02 2026] 127.0.0.1:55531 Accepted +[Sun Apr 5 14:38:03 2026] 127.0.0.1:55531 [200]: POST /sternbedeckungen.php +[Sun Apr 5 14:38:03 2026] 127.0.0.1:55531 Closing +[Sun Apr 5 14:38:03 2026] 127.0.0.1:55255 Accepted +[Sun Apr 5 14:38:04 2026] 127.0.0.1:55255 [200]: POST /sternbedeckungen.php +[Sun Apr 5 14:38:04 2026] 127.0.0.1:55255 Closing +[Sun Apr 5 14:38:04 2026] 127.0.0.1:57557 Accepted +[Sun Apr 5 14:38:05 2026] 127.0.0.1:57557 [200]: POST /sternbedeckungen.php +[Sun Apr 5 14:38:05 2026] 127.0.0.1:57557 Closing +[Sun Apr 5 14:38:05 2026] 127.0.0.1:50586 Accepted +[Sun Apr 5 14:38:06 2026] 127.0.0.1:50586 [200]: POST /sternbedeckungen.php +[Sun Apr 5 14:38:06 2026] 127.0.0.1:50586 Closing +[Sun Apr 5 14:38:06 2026] 127.0.0.1:64881 Accepted +[Sun Apr 5 14:38:06 2026] 127.0.0.1:64881 [200]: POST /sternbedeckungen.php +[Sun Apr 5 14:38:06 2026] 127.0.0.1:64881 Closing +[Sun Apr 5 14:38:06 2026] 127.0.0.1:51722 Accepted +[Sun Apr 5 14:38:07 2026] 127.0.0.1:51722 [200]: POST /sternbedeckungen.php +[Sun Apr 5 14:38:07 2026] 127.0.0.1:51722 Closing +[Sun Apr 5 14:38:07 2026] 127.0.0.1:55884 Accepted +[Sun Apr 5 14:38:07 2026] 127.0.0.1:55884 [200]: POST /sternbedeckungen.php +[Sun Apr 5 14:38:07 2026] 127.0.0.1:55884 Closing +[Sun Apr 5 14:38:08 2026] 127.0.0.1:55037 Accepted +[Sun Apr 5 14:38:08 2026] 127.0.0.1:55037 [200]: POST /sternbedeckungen.php +[Sun Apr 5 14:38:08 2026] 127.0.0.1:55037 Closing +[Sun Apr 5 14:38:08 2026] 127.0.0.1:53400 Accepted +[Sun Apr 5 14:38:09 2026] 127.0.0.1:53400 [200]: POST /sternbedeckungen.php +[Sun Apr 5 14:38:09 2026] 127.0.0.1:53400 Closing +[Sun Apr 5 14:38:09 2026] 127.0.0.1:63405 Accepted +[Sun Apr 5 14:38:10 2026] 127.0.0.1:63405 [200]: POST /sternbedeckungen.php +[Sun Apr 5 14:38:10 2026] 127.0.0.1:63405 Closing +[Sun Apr 5 14:38:10 2026] 127.0.0.1:55186 Accepted +[Sun Apr 5 14:38:10 2026] 127.0.0.1:55186 [200]: POST /sternbedeckungen.php +[Sun Apr 5 14:38:10 2026] 127.0.0.1:55186 Closing +[Sun Apr 5 14:38:10 2026] 127.0.0.1:50160 Accepted +[Sun Apr 5 14:38:11 2026] 127.0.0.1:50160 [200]: POST /sternbedeckungen.php +[Sun Apr 5 14:38:11 2026] 127.0.0.1:50160 Closing +[Sun Apr 5 14:38:11 2026] 127.0.0.1:56629 Accepted +[Sun Apr 5 14:38:11 2026] 127.0.0.1:56629 [200]: POST /sternbedeckungen.php +[Sun Apr 5 14:38:11 2026] 127.0.0.1:56629 Closing +[Sun Apr 5 14:40:25 2026] 127.0.0.1:65518 Accepted +[Sun Apr 5 14:40:25 2026] 127.0.0.1:65518 [200]: POST /sternbedeckungen.php +[Sun Apr 5 14:40:25 2026] 127.0.0.1:65518 Closing +[Sun Apr 5 14:40:25 2026] 127.0.0.1:50591 Accepted +[Sun Apr 5 14:40:32 2026] 127.0.0.1:50591 [200]: POST /sternbedeckungen.php +[Sun Apr 5 14:40:32 2026] 127.0.0.1:50591 Closing +[Sun Apr 5 14:40:38 2026] 127.0.0.1:60053 Accepted +[Sun Apr 5 14:40:39 2026] 127.0.0.1:60053 [200]: POST /sternbedeckungen.php +[Sun Apr 5 14:40:39 2026] 127.0.0.1:60053 Closing +[Sun Apr 5 14:40:39 2026] 127.0.0.1:58428 Accepted +[Sun Apr 5 14:40:44 2026] 127.0.0.1:58428 [200]: POST /sternbedeckungen.php +[Sun Apr 5 14:40:44 2026] 127.0.0.1:58428 Closing +[Sun Apr 5 14:40:48 2026] 127.0.0.1:54921 Accepted +[Sun Apr 5 14:40:50 2026] 127.0.0.1:54921 [200]: POST /sternbedeckungen.php +[Sun Apr 5 14:40:50 2026] 127.0.0.1:54921 Closing +[Sun Apr 5 14:40:50 2026] 127.0.0.1:61192 Accepted diff --git a/public/css/style.css b/public/css/style.css index 114ff33..a63665c 100644 --- a/public/css/style.css +++ b/public/css/style.css @@ -1301,6 +1301,12 @@ footer a:hover { color: var(--gold); } line-height: 1.4; } +.favorites-loading-hint-error { + border-color: rgba(200, 60, 60, 0.35); + background: rgba(200, 60, 60, 0.12); + color: #f08080; +} + .favorites-loading-form.is-loading .btn { opacity: 0.75; cursor: wait; @@ -1439,6 +1445,8 @@ footer a:hover { color: var(--gold); } border: none; padding: 0; background: transparent; + margin: auto; + max-width: min(92vw, 560px); } .admin-dialog::backdrop { diff --git a/public/my_favorites.php b/public/my_favorites.php index dcd1f01..c9bf855 100644 --- a/public/my_favorites.php +++ b/public/my_favorites.php @@ -123,6 +123,53 @@ function countUserRows(PDO $pdo, string $tableName, int $userId): int return (int) $stmtCount->fetchColumn(); } +function validateLocationForm(array $input, array &$errors): array +{ + $name = trim((string) ($input['name'] ?? '')); + $latitude = trim((string) ($input['latitude'] ?? '')); + $longitude = trim((string) ($input['longitude'] ?? '')); + $elevation = trim((string) ($input['elevation'] ?? '')); + $timezone = trim((string) ($input['timezone'] ?? 'Europe/Berlin')); + + if ($name === '') { + $errors[] = 'Bitte einen Namen für den Standort eingeben.'; + } + + if ($latitude === '' || !is_numeric($latitude)) { + $errors[] = 'Bitte einen gültigen Breitengrad eingeben.'; + } else { + $lat = (float) $latitude; + if ($lat < -90 || $lat > 90) { + $errors[] = 'Der Breitengrad muss zwischen -90 und 90 liegen.'; + } + } + + if ($longitude === '' || !is_numeric($longitude)) { + $errors[] = 'Bitte einen gültigen Längengrad eingeben.'; + } else { + $lon = (float) $longitude; + if ($lon < -180 || $lon > 180) { + $errors[] = 'Der Längengrad muss zwischen -180 und 180 liegen.'; + } + } + + if ($elevation !== '' && !is_numeric($elevation)) { + $errors[] = 'Die Höhe muss numerisch sein.'; + } + + if (!validTimezone($timezone)) { + $errors[] = 'Bitte eine gültige IANA-Zeitzone angeben, z. B. Europe/Berlin.'; + } + + return [ + 'name' => $name, + 'latitude' => $latitude, + 'longitude' => $longitude, + 'elevation' => $elevation, + 'timezone' => $timezone, + ]; +} + if ($_SERVER['REQUEST_METHOD'] === 'POST') { $action = $_POST['action'] ?? ''; @@ -494,6 +541,85 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { } } + if ($action === 'update_location') { + $locationId = (int) ($_POST['location_id'] ?? 0); + $locationForm = validateLocationForm($_POST, $errors); + $setDefault = isset($_POST['is_default']) ? 1 : 0; + + if ($locationId <= 0) { + $errors[] = 'Ungültiger Standort.'; + } + + $existingLocation = null; + if (empty($errors)) { + $stmtLocation = $pdo->prepare(" + SELECT `id`, `is_default` + FROM `app_user_locations` + WHERE `id` = :id + AND `user_id` = :user_id + LIMIT 1 + "); + $stmtLocation->execute([ + ':id' => $locationId, + ':user_id' => $userId, + ]); + $existingLocation = $stmtLocation->fetch(); + + if (!$existingLocation) { + $errors[] = 'Der Standort wurde nicht gefunden.'; + } + } + + if (empty($errors)) { + $pdo->beginTransaction(); + + try { + if ($setDefault === 1) { + $stmtReset = $pdo->prepare(" + UPDATE `app_user_locations` + SET `is_default` = 0 + WHERE `user_id` = :user_id + "); + $stmtReset->execute([ + ':user_id' => $userId, + ]); + } + + $stmtUpdate = $pdo->prepare(" + UPDATE `app_user_locations` + SET + `name` = :name, + `latitude` = :latitude, + `longitude` = :longitude, + `elevation` = :elevation, + `timezone` = :timezone, + `is_default` = :is_default, + `updated_at` = NOW() + WHERE `id` = :id + AND `user_id` = :user_id + "); + $stmtUpdate->execute([ + ':id' => $locationId, + ':user_id' => $userId, + ':name' => $locationForm['name'], + ':latitude' => (float) $locationForm['latitude'], + ':longitude' => (float) $locationForm['longitude'], + ':elevation' => $locationForm['elevation'] !== '' ? (float) $locationForm['elevation'] : null, + ':timezone' => $locationForm['timezone'], + ':is_default' => $setDefault === 1 ? 1 : (int) ($existingLocation['is_default'] ?? 0), + ]); + + $pdo->commit(); + $successMessage = 'Der Standort wurde aktualisiert.'; + } catch (Throwable $e) { + if ($pdo->inTransaction()) { + $pdo->rollBack(); + } + $errors[] = 'Der Standort konnte nicht aktualisiert werden.'; + } + } + } + if ($action === 'set_default_location') { $locationId = (int) ($_POST['location_id'] ?? 0); @@ -874,6 +1000,17 @@ $loggedIn = true; +
@@ -885,7 +1022,7 @@ $loggedIn = true; - +
Letzter Standort @@ -911,12 +1048,25 @@ $loggedIn = true;
-
+
- + +

+ >Bitte einen Namen für den Standort eingeben.

@@ -940,11 +1090,50 @@ $loggedIn = true; Als Standard-Standort speichern - +
+ +
+ + +

Standort bearbeiten

+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ +
+ + +
+ +
+
+

Satelliten suchen

@@ -959,7 +1148,7 @@ $loggedIn = true; >
- + @@ -1014,7 +1203,7 @@ $loggedIn = true; >
- + @@ -1336,13 +1525,40 @@ $loggedIn = true; })(); document.querySelectorAll('.favorites-loading-form').forEach((form) => { - form.addEventListener('submit', () => { + form.addEventListener('submit', (event) => { + if (form.id === 'add-location-form') { + const nameField = form.querySelector('#name'); + const nameError = document.getElementById('add-location-name-error'); + + if (nameField) { + const trimmedName = nameField.value.trim(); + + if (trimmedName === '') { + event.preventDefault(); + nameField.value = ''; + nameField.focus(); + + if (nameError) { + nameError.textContent = 'Bitte einen Namen für den Standort eingeben.'; + nameError.hidden = false; + } + + return; + } + + if (nameError) { + nameError.hidden = true; + } + } + } + const message = form.dataset.loadingMessage || 'Bitte warten...'; - let hint = form.querySelector('.favorites-loading-hint'); + let hint = form.querySelector('[data-loading-hint]'); if (!hint) { hint = document.createElement('p'); hint.className = 'favorites-loading-hint'; + hint.dataset.loadingHint = 'true'; form.appendChild(hint); } @@ -1361,6 +1577,40 @@ document.querySelectorAll('.favorites-loading-form').forEach((form) => { }); }); }); + +(function () { + const dialog = document.getElementById('editLocationDialog'); + const cancelButton = document.getElementById('editLocationCancel'); + + if (!dialog || typeof dialog.showModal !== 'function') { + return; + } + + const idInput = document.getElementById('edit-location-id'); + const nameInput = document.getElementById('edit-location-name'); + const latitudeInput = document.getElementById('edit-location-latitude'); + const longitudeInput = document.getElementById('edit-location-longitude'); + const elevationInput = document.getElementById('edit-location-elevation'); + const timezoneInput = document.getElementById('edit-location-timezone'); + const defaultInput = document.getElementById('edit-location-default'); + + document.querySelectorAll('.js-edit-location').forEach((button) => { + button.addEventListener('click', () => { + idInput.value = button.dataset.locationId || ''; + nameInput.value = button.dataset.locationName || ''; + latitudeInput.value = button.dataset.locationLatitude || ''; + longitudeInput.value = button.dataset.locationLongitude || ''; + elevationInput.value = button.dataset.locationElevation || ''; + timezoneInput.value = button.dataset.locationTimezone || 'Europe/Berlin'; + defaultInput.checked = button.dataset.locationDefault === '1'; + dialog.showModal(); + }); + }); + + cancelButton?.addEventListener('click', () => { + dialog.close(); + }); +})();