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

@@ -20,14 +20,38 @@ class NewsController {
}
public function createNews() {
if (!isset($_SESSION['is_admin']) || !$_SESSION['is_admin']) {
header('Location: index.php?controller=News&do=showNews');
exit;
}
$data = [
'name' => $_POST['name'],
'beschreibung' => $_POST['beschreibung'],
'datum' => $_POST['datum'],
'name' => $_POST['name'] ?? '',
'description' => $_POST['description'] ?? '',
'date' => $_POST['date'] ?? date('Y-m-d'),
];
$erg = $this->model->createNews($data);
$this->view->setVars(['news' => $erg]);
exit;
$errors = [];
if (empty($data['name']) || empty($data['description']) || empty($data['date'])) {
$errors['news'] = 'Bitte alle Felder ausfüllen.';
}
if (!empty($errors)) {
$this->view->setVars(['errors' => $errors, 'validData' => $data]);
$this->view->setDoMethodName('createNewsForm');
return;
}
$this->model->createNews($data);
$this->view->setDoMethodName('showCreateSuccess');
}
public function createNewsForm() {
if (!isset($_SESSION['is_admin']) || !$_SESSION['is_admin']) {
header('Location: index.php?controller=News&do=showNews');
exit;
}
// Leere Felder für das Formular
$this->view->setVars([
'errors' => [],
'validData' => []
]);
}
public function editNewsForm() {
@@ -47,7 +71,14 @@ class NewsController {
}
public function deleteNews() {
$id = $_GET['newsid'] ?? null;
$this->model->deleteNews($id);
if (!isset($_SESSION['is_admin']) || !$_SESSION['is_admin']) {
header('Location: index.php?controller=News&do=showNews');
exit;
}
$id = $_GET['id'] ?? null;
if ($id) {
$this->model->deleteNews($id);
}
$this->view->setDoMethodName('showDeleteSuccess');
}
}