Kometenseite: Hinzufuegen/Entfernen aus der eigenen Liste direkt ermoeglichen
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -203,6 +203,69 @@ $pdo = new PDO(
|
|||||||
);
|
);
|
||||||
|
|
||||||
$userId = isset($_SESSION['user_id']) ? (int) $_SESSION['user_id'] : 0;
|
$userId = isset($_SESSION['user_id']) ? (int) $_SESSION['user_id'] : 0;
|
||||||
|
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && $userId > 0) {
|
||||||
|
$action = $_POST['action'] ?? '';
|
||||||
|
$cometId = (int) ($_POST['comet_id'] ?? 0);
|
||||||
|
|
||||||
|
if ($action === 'add_comet' && $cometId > 0) {
|
||||||
|
$stmtCheck = $pdo->prepare("
|
||||||
|
SELECT `id`
|
||||||
|
FROM `comets_mpc`
|
||||||
|
WHERE `id` = :id
|
||||||
|
LIMIT 1
|
||||||
|
");
|
||||||
|
$stmtCheck->execute([':id' => $cometId]);
|
||||||
|
|
||||||
|
if ($stmtCheck->fetch()) {
|
||||||
|
$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,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($action === 'remove_comet' && $cometId > 0) {
|
||||||
|
$stmtCount = $pdo->prepare("
|
||||||
|
SELECT COUNT(*)
|
||||||
|
FROM `app_user_comets`
|
||||||
|
WHERE `user_id` = :user_id
|
||||||
|
");
|
||||||
|
$stmtCount->execute([':user_id' => $userId]);
|
||||||
|
$cometCount = (int) $stmtCount->fetchColumn();
|
||||||
|
|
||||||
|
if ($cometCount > 1) {
|
||||||
|
$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,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
header('Location: comets.php');
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
$today = new DateTimeImmutable('today', new DateTimeZone('UTC'));
|
$today = new DateTimeImmutable('today', new DateTimeZone('UTC'));
|
||||||
$windowStart = $today->modify('-180 days');
|
$windowStart = $today->modify('-180 days');
|
||||||
$windowEnd = $today->modify('+365 days');
|
$windowEnd = $today->modify('+365 days');
|
||||||
@@ -632,6 +695,9 @@ arsort($orbitTypeCounts);
|
|||||||
<th data-sortable>Perihel</th>
|
<th data-sortable>Perihel</th>
|
||||||
<th data-sortable>Abstand</th>
|
<th data-sortable>Abstand</th>
|
||||||
<th data-sortable title="Grobe Helligkeitsschaetzung fuer heute nach H + 5 log(Delta) + 2,5 * n * log(r).">m grob</th>
|
<th data-sortable title="Grobe Helligkeitsschaetzung fuer heute nach H + 5 log(Delta) + 2,5 * n * log(r).">m grob</th>
|
||||||
|
<?php if ($loggedIn): ?>
|
||||||
|
<th></th>
|
||||||
|
<?php endif; ?>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
@@ -664,6 +730,19 @@ arsort($orbitTypeCounts);
|
|||||||
<td data-sort-value="<?= h((string) $perihelionTs) ?>"><?= h((string) $comet['perihelion_date_display']) ?></td>
|
<td data-sort-value="<?= h((string) $perihelionTs) ?>"><?= h((string) $comet['perihelion_date_display']) ?></td>
|
||||||
<td data-sort-value="<?= h((string) ($comet['days_from_today'] ?? '')) ?>"><span class="comets-days <?= $daysClass ?>"><?= h($daysLabel) ?></span></td>
|
<td data-sort-value="<?= h((string) ($comet['days_from_today'] ?? '')) ?>"><span class="comets-days <?= $daysClass ?>"><?= h($daysLabel) ?></span></td>
|
||||||
<td data-sort-value="<?= h((string) ($comet['estimated_magnitude'] ?? '')) ?>" title="r = <?= h((string) $comet['heliocentric_distance_display']) ?> AE, Δ = <?= h((string) $comet['geocentric_distance_display']) ?> AE"><?= h((string) $comet['estimated_magnitude_display']) ?></td>
|
<td data-sort-value="<?= h((string) ($comet['estimated_magnitude'] ?? '')) ?>" title="r = <?= h((string) $comet['heliocentric_distance_display']) ?> AE, Δ = <?= h((string) $comet['geocentric_distance_display']) ?> AE"><?= h((string) $comet['estimated_magnitude_display']) ?></td>
|
||||||
|
<?php if ($loggedIn): ?>
|
||||||
|
<td class="action-cell">
|
||||||
|
<?php if (count($trackedComets) > 1): ?>
|
||||||
|
<form method="post" action="comets.php" onsubmit="return confirm('Komet wirklich aus deiner Liste entfernen?');">
|
||||||
|
<input type="hidden" name="action" value="remove_comet">
|
||||||
|
<input type="hidden" name="comet_id" value="<?= (int) $comet['id'] ?>">
|
||||||
|
<button type="submit" class="btn btn-sm btn-danger">Entfernen</button>
|
||||||
|
</form>
|
||||||
|
<?php else: ?>
|
||||||
|
<span class="hint">Letzter Komet</span>
|
||||||
|
<?php endif; ?>
|
||||||
|
</td>
|
||||||
|
<?php endif; ?>
|
||||||
</tr>
|
</tr>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
</tbody>
|
</tbody>
|
||||||
@@ -689,6 +768,9 @@ arsort($orbitTypeCounts);
|
|||||||
<th data-sortable>Perihel</th>
|
<th data-sortable>Perihel</th>
|
||||||
<th data-sortable>Abstand</th>
|
<th data-sortable>Abstand</th>
|
||||||
<th data-sortable title="Grobe Helligkeitsschaetzung fuer heute nach H + 5 log(Delta) + 2,5 * n * log(r).">m grob</th>
|
<th data-sortable title="Grobe Helligkeitsschaetzung fuer heute nach H + 5 log(Delta) + 2,5 * n * log(r).">m grob</th>
|
||||||
|
<?php if ($loggedIn): ?>
|
||||||
|
<th></th>
|
||||||
|
<?php endif; ?>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
@@ -722,6 +804,17 @@ arsort($orbitTypeCounts);
|
|||||||
<td data-sort-value="<?= h((string) $perihelionTs) ?>"><?= h((string) $comet['perihelion_date_display']) ?></td>
|
<td data-sort-value="<?= h((string) $perihelionTs) ?>"><?= h((string) $comet['perihelion_date_display']) ?></td>
|
||||||
<td data-sort-value="<?= h((string) ($comet['days_from_today'] ?? '')) ?>"><span class="comets-days <?= $daysClass ?>"><?= h($daysLabel) ?></span></td>
|
<td data-sort-value="<?= h((string) ($comet['days_from_today'] ?? '')) ?>"><span class="comets-days <?= $daysClass ?>"><?= h($daysLabel) ?></span></td>
|
||||||
<td data-sort-value="<?= h((string) ($comet['estimated_magnitude'] ?? '')) ?>" title="r = <?= h((string) $comet['heliocentric_distance_display']) ?> AE, Δ = <?= h((string) $comet['geocentric_distance_display']) ?> AE"><?= h((string) $comet['estimated_magnitude_display']) ?></td>
|
<td data-sort-value="<?= h((string) ($comet['estimated_magnitude'] ?? '')) ?>" title="r = <?= h((string) $comet['heliocentric_distance_display']) ?> AE, Δ = <?= h((string) $comet['geocentric_distance_display']) ?> AE"><?= h((string) $comet['estimated_magnitude_display']) ?></td>
|
||||||
|
<?php if ($loggedIn): ?>
|
||||||
|
<td class="action-cell">
|
||||||
|
<?php if ((int) $comet['is_tracked'] !== 1): ?>
|
||||||
|
<form method="post" action="comets.php">
|
||||||
|
<input type="hidden" name="action" value="add_comet">
|
||||||
|
<input type="hidden" name="comet_id" value="<?= (int) $comet['id'] ?>">
|
||||||
|
<button type="submit" class="btn btn-sm btn-primary">Hinzufügen</button>
|
||||||
|
</form>
|
||||||
|
<?php endif; ?>
|
||||||
|
</td>
|
||||||
|
<?php endif; ?>
|
||||||
</tr>
|
</tr>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|||||||
Reference in New Issue
Block a user