Files
habit-tracker/app/Views/habits/dashboard.php
T

121 lines
5.8 KiB
PHP

<?php
$weekdayLabels = [
1 => 'Montag',
2 => 'Dienstag',
3 => 'Mittwoch',
4 => 'Donnerstag',
5 => 'Freitag',
6 => 'Samstag',
7 => 'Sonntag',
];
?>
<section class="dashboard-head">
<div>
<p class="eyebrow">Heute</p>
<h1>Deine Habits</h1>
</div>
<a class="button" href="index.php?route=habits/create">Habit erstellen</a>
</section>
<form method="get" action="index.php" class="filters">
<input type="hidden" name="route" value="dashboard">
<label for="category_id">Kategorie</label>
<select id="category_id" name="category_id">
<option value="">Alle Kategorien</option>
<?php foreach ($categories as $category): ?>
<option value="<?= (int) $category['id'] ?>" <?= (string) $filters['category_id'] === (string) $category['id'] ? 'selected' : '' ?>>
<?= e($category['name']) ?>
</option>
<?php endforeach; ?>
</select>
<label for="status">Status</label>
<select id="status" name="status">
<option value="">Alle</option>
<option value="open" <?= $filters['status'] === 'open' ? 'selected' : '' ?>>Offen</option>
<option value="done" <?= $filters['status'] === 'done' ? 'selected' : '' ?>>Erledigt</option>
</select>
<button type="submit">Filtern</button>
</form>
<?php if (empty($habits)): ?>
<p class="empty">Noch keine Habits gefunden. Erstelle deinen ersten Habit.</p>
<?php endif; ?>
<section class="habit-list">
<?php foreach ($habits as $habit): ?>
<?php $habitReminders = $remindersByHabit[(int) $habit['id']] ?? []; ?>
<article class="habit-card <?= $habit['done_today'] ? 'done' : '' ?>">
<div class="habit-main">
<span class="category-dot" style="background-color: <?= e($habit['category_color'] ?? '#9ca3af') ?>"></span>
<div>
<h2><?= e($habit['title']) ?></h2>
<p><?= e($habit['description']) ?></p>
<small>
<?= e($habit['category_name'] ?? 'Ohne Kategorie') ?> |
Woche: <?= (int) $habit['completed_this_week'] ?> / <?= (int) $habit['target_per_week'] ?> erledigt
</small>
</div>
</div>
<div class="habit-actions">
<form method="post" action="index.php?route=habits/toggle">
<?= csrf_field() ?>
<input type="hidden" name="id" value="<?= (int) $habit['id'] ?>">
<button type="submit"><?= $habit['done_today'] ? 'Heute erledigt' : 'Abhaken' ?></button>
</form>
<a href="index.php?route=habits/edit&id=<?= (int) $habit['id'] ?>">Bearbeiten</a>
<form method="post" action="index.php?route=habits/delete" onsubmit="return confirm('Diesen Habit wirklich loeschen?');">
<?= csrf_field() ?>
<input type="hidden" name="id" value="<?= (int) $habit['id'] ?>">
<button class="danger" type="submit">Loeschen</button>
</form>
</div>
<section class="habit-reminders" aria-labelledby="reminders-<?= (int) $habit['id'] ?>">
<div class="reminder-heading">
<h3 id="reminders-<?= (int) $habit['id'] ?>">Erinnerungen</h3>
<a href="index.php?route=reminders/create&habit_id=<?= (int) $habit['id'] ?>">Erinnerung hinzufuegen</a>
</div>
<?php if (empty($habitReminders)): ?>
<p class="reminder-empty">Noch keine Erinnerung eingerichtet.</p>
<?php else: ?>
<ul class="reminder-list">
<?php foreach ($habitReminders as $reminder): ?>
<?php
$weekday = $reminder['weekday'] === null
? 'Taeglich'
: ($weekdayLabels[(int) $reminder['weekday']] ?? 'Unbekannt');
$isActive = (int) $reminder['is_active'] === 1;
?>
<li class="reminder-item <?= $isActive ? '' : 'paused' ?>">
<strong class="reminder-time"><?= e(substr($reminder['reminder_time'], 0, 5)) ?></strong>
<span><?= e($weekday) ?></span>
<span class="reminder-status"><?= $isActive ? 'Aktiv' : 'Pausiert' ?></span>
<div class="reminder-actions">
<form method="post" action="index.php?route=reminders/toggle">
<?= csrf_field() ?>
<input type="hidden" name="id" value="<?= (int) $reminder['id'] ?>">
<button type="submit"><?= $isActive ? 'Pausieren' : 'Aktivieren' ?></button>
</form>
<a href="index.php?route=reminders/edit&id=<?= (int) $reminder['id'] ?>">Bearbeiten</a>
<form method="post" action="index.php?route=reminders/delete" onsubmit="return confirm('Diese Erinnerung wirklich loeschen?');">
<?= csrf_field() ?>
<input type="hidden" name="id" value="<?= (int) $reminder['id'] ?>">
<button class="danger" type="submit">Loeschen</button>
</form>
</div>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</section>
</article>
<?php endforeach; ?>
</section>