News-Admin-Workflow aufgebohrt:

- News können jetzt als Admin  erstellt und gelöscht werden, mit Zwischenseite zur Bestätigung.
- Fehler bei den Feldnamen im Model gefixt.
- Nach dem Anlegen/Löschen gibt’s jetzt wie beim Login/Registrieren eine kurze Erfolgsmeldung und automatischen Redirect.
- Includes und Redirects aufgeräumt, damit keine Warnungen mehr kommen.
This commit is contained in:
2025-07-08 10:12:07 +02:00
parent 4f0f1e5f6d
commit 775b752d59
9 changed files with 227 additions and 40 deletions

View File

@@ -0,0 +1,20 @@
<div class="inhalt">
<div class="form-container">
<h1>News erstellen</h1>
<?php if (!empty($errors['news'])): ?>
<div class="form-error"><?=htmlspecialchars($errors['news'])?></div>
<?php endif; ?>
<form class="form-horizontal" action="index.php" method="post">
<input type="hidden" name="controller" value="News">
<input type="hidden" name="do" value="createNews">
<label for="name">Titel</label>
<input type="text" name="name" id="name" required value="<?=htmlspecialchars($validData['name'] ?? '')?>">
<label for="date">Datum</label>
<input type="date" name="date" id="date" required value="<?=htmlspecialchars($validData['date'] ?? date('Y-m-d'))?>">
<label for="description">Beschreibung</label>
<textarea name="description" id="description" rows="7" required><?=htmlspecialchars($validData['description'] ?? '')?></textarea>
<button class="button-register" type="submit">News speichern</button>
</form>
<a href="?controller=News&do=showNews">Zurück zur Übersicht</a>
</div>
</div>

View File

@@ -0,0 +1,14 @@
<div class="inhalt">
<div class="login-success">
<h2>News erfolgreich erstellt!</h2>
<p>Du wirst in wenigen Sekunden zur Übersicht weitergeleitet...</p>
</div>
</div>
<script>
setTimeout(function() {
window.location.href = "?controller=News&do=showNews";
}, 2000);
</script>
<noscript>
<meta http-equiv="refresh" content="2;url=?controller=News&do=showNews">
</noscript>

View File

@@ -0,0 +1,14 @@
<div class="inhalt">
<div class="login-success">
<h2>News erfolgreich gelöscht!</h2>
<p>Du wirst in wenigen Sekunden zur Übersicht weitergeleitet...</p>
</div>
</div>
<script>
setTimeout(function() {
window.location.href = "?controller=News&do=showNews";
}, 2000);
</script>
<noscript>
<meta http-equiv="refresh" content="2;url=?controller=News&do=showNews">
</noscript>

View File

@@ -1,27 +1,24 @@
<?php if (!empty($news)): ?>
<div class="inhalt">
<div class="event-container">
<h2>Alle Infos</h2>
<div class="event-container-inhalt">
<table>
<thead>
<tr>
<th>Name</th>
<th>Beschreibung</th>
<th>Datum</th>
</tr>
</thead>
<tbody>
<h2>Alle News</h2>
<?php if (isset($_SESSION['is_admin']) && $_SESSION['is_admin']): ?>
<a href="?controller=News&do=createNewsForm" class="admin-btn">News erstellen</a>
<?php endif; ?>
<div class="news-cards">
<?php foreach ($news as $item): ?>
<tr>
<td><?php echo htmlspecialchars($item['name']); ?></td>
<td><?php echo nl2br(htmlspecialchars($item['name'])); ?></td>
<td><?php echo nl2br(htmlspecialchars($item['description'])); ?></td>
<td><?php echo date('d.m.Y', strtotime($item['date'])); ?></td>
</tr>
<div class="news-card">
<h3><?=htmlspecialchars($item['name'])?></h3>
<div class="news-date"><?=date('d.m.Y', strtotime($item['date']))?></div>
<div class="news-desc"><?=nl2br(htmlspecialchars($item['description']))?></div>
<?php if (isset($_SESSION['is_admin']) && $_SESSION['is_admin']): ?>
<div>
<a href="?controller=News&do=editNewsForm&id=<?=$item['news_id']?>" class="admin-btn">Bearbeiten</a>
<a href="?controller=News&do=deleteNews&id=<?=$item['news_id']?>" class="admin-btn" onclick="return confirm('Wirklich löschen?');">Löschen</a>
</div>
<?php endif; ?>
</div>
<?php endforeach; ?>
</tbody>
</table>
</div>
<?php else: ?>
<p>Derzeit sind keine News verfügbar.</p>