-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
121 lines (99 loc) · 3.49 KB
/
index.php
File metadata and controls
121 lines (99 loc) · 3.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<?php
session_start(); // ← NEU
require_once 'includes/db.php';
// Kategorie-Filter und Suche verarbeiten
$kategorie_id = isset($_GET['kategorie']) ? intval($_GET['kategorie']) : 0;
$suche = isset($_GET['suche']) ? trim($_GET['suche']) : '';
// Kategorien abrufen
$stmt = $pdo->query("SELECT id, name FROM kategorien ORDER BY name ASC");
$kategorien = $stmt->fetchAll(PDO::FETCH_ASSOC);
// Beiträge abrufen
$sql = "SELECT b.id, b.titel, b.erstellt_am, k.name AS kategorie
FROM beitraege b
LEFT JOIN kategorien k ON b.kategorie_id = k.id
WHERE 1";
$params = [];
if ($kategorie_id > 0) {
$sql .= " AND b.kategorie_id = :kategorie_id";
$params[':kategorie_id'] = $kategorie_id;
}
if (!empty($suche)) {
$sql .= " AND (b.titel LIKE :suche OR b.inhalt LIKE :suche)";
$params[':suche'] = '%' . $suche . '%';
}
$sql .= " ORDER BY b.erstellt_am DESC";
$stmt = $pdo->prepare($sql);
$stmt->execute($params);
$beitraege = $stmt->fetchAll(PDO::FETCH_ASSOC);
?>
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<title>Handbuch Übersicht</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<header>
<h1>📘 Handbuch-System</h1>
</header>
<nav>
<a href="index.php">Startseite</a>
<?php if (isset($_SESSION['eingeloggt']) && $_SESSION['eingeloggt']): ?>
<a href="beitrag_erstellen.php">Beitrag erstellen</a>
<a href="kategorie_erstellen.php">Kategorien verwalten</a>
<a href="logout.php">Logout (<?= htmlspecialchars($_SESSION['benutzername']) ?>)</a>
<?php else: ?>
<a href="login.php">Login</a>
<?php endif; ?>
</nav>
<div class="container">
<h2>Inhaltsverzeichnis</h2>
<form method="GET" class="search-box">
<label for="kategorie">Kategorie filtern:</label>
<select name="kategorie" id="kategorie">
<option value="0">-- Alle Kategorien --</option>
<?php foreach ($kategorien as $kat): ?>
<option value="<?= $kat['id'] ?>" <?= ($kat['id'] == $kategorie_id) ? 'selected' : '' ?>>
<?= htmlspecialchars($kat['name']) ?>
</option>
<?php endforeach; ?>
</select>
<label for="suche">Suche:</label>
<input type="text" name="suche" id="suche" value="<?= htmlspecialchars($suche) ?>" placeholder="Suchbegriff...">
<button type="submit">Anzeigen</button>
</form>
<?php if (count($beitraege) === 0): ?>
<p>Keine Beiträge gefunden.</p>
<?php else: ?>
<table>
<thead>
<tr>
<th>Titel</th>
<th>Kategorie</th>
<th>Aktionen</th>
</tr>
</thead>
<tbody>
<?php foreach ($beitraege as $beitrag): ?>
<tr>
<td><a href="beitrag.php?id=<?= $beitrag['id'] ?>"><?= htmlspecialchars($beitrag['titel']) ?></a></td>
<td><?= htmlspecialchars($beitrag['kategorie']) ?></td>
<td>
<a href="beitrag.php?id=<?= $beitrag['id'] ?>">📄</a>
<?php if (isset($_SESSION['eingeloggt']) && $_SESSION['eingeloggt']): ?>
<a href="beitrag_bearbeiten.php?id=<?= $beitrag['id'] ?>">✏️</a>
<a href="beitrag_loeschen.php?id=<?= $beitrag['id'] ?>" onclick="return confirm('Wirklich löschen?')">🗑️</a>
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php endif; ?>
</div>
<footer>
© 2021 - <?= date('Y') ?> <a href="https://wahke.lu">wahke.lu</a> | Kevin Wahl – Alle Rechte vorbehalten.
</footer>
</body>
</html>