From fa984e7391ffe7b53fda2f25450b01796788febd Mon Sep 17 00:00:00 2001 From: patrickzerhusen Date: Fri, 24 Apr 2026 17:41:59 +0200 Subject: [PATCH] author can be edited and added in news moderation page --- public/admin.php | 24 ++++++++++++++++++------ public/api/contributions.php | 9 +++++---- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/public/admin.php b/public/admin.php index 98cc4c2..84aba59 100644 --- a/public/admin.php +++ b/public/admin.php @@ -354,7 +354,7 @@ $counts['total'] = count($all_contributions);
-
' + - '
' + + '
' + '' + '' + '
' + + '
' + + '' + + '' + + '
' + '
', showCancelButton: true, confirmButtonText: 'Veröffentlichen', @@ -722,11 +726,12 @@ $counts['total'] = count($all_contributions); preConfirm: function () { const title = document.getElementById('swal-news-title').value.trim(); const content = document.getElementById('swal-news-content').value.trim(); + const author = document.getElementById('swal-news-author').value.trim() || 'Stadtverwaltung'; if (!title || !content) { Swal.showValidationMessage('Titel und Inhalt sind Pflichtfelder.'); return false; } - return { title: title, content: content }; + return { title: title, content: content, author_name: author }; } }).then(function (result) { if (!result.isConfirmed) return; @@ -736,6 +741,7 @@ $counts['total'] = count($all_contributions); formData.append('municipality_id', MUNICIPALITY_ID); formData.append('title', result.value.title); formData.append('content', result.value.content); + formData.append('author_name', result.value.author_name); fetch(API_URL, { method: 'POST', body: formData }) .then(function (r) { return r.json(); }) @@ -754,7 +760,7 @@ $counts['total'] = count($all_contributions); // ============================================================= // Edit News Article // ============================================================= - function editNews(newsId, currentTitle, currentContent) { + function editNews(newsId, currentTitle, currentContent, currentAuthor) { Swal.fire({ title: 'Neuigkeit bearbeiten', html: @@ -763,10 +769,14 @@ $counts['total'] = count($all_contributions); '' + '' + '' + - '
' + + '
' + '' + '' + '
' + + '
' + + '' + + '' + + '
' + '
', showCancelButton: true, confirmButtonText: 'Speichern', @@ -775,7 +785,8 @@ $counts['total'] = count($all_contributions); preConfirm: function () { return { title: document.getElementById('swal-news-title').value.trim(), - content: document.getElementById('swal-news-content').value.trim() + content: document.getElementById('swal-news-content').value.trim(), + author_name: document.getElementById('swal-news-author').value.trim() || 'Stadtverwaltung' }; } }).then(function (result) { @@ -786,6 +797,7 @@ $counts['total'] = count($all_contributions); formData.append('news_id', newsId); formData.append('title', result.value.title); formData.append('content', result.value.content); + formData.append('author_name', result.value.author_name); fetch(API_URL, { method: 'POST', body: formData }) .then(function (r) { return r.json(); }) diff --git a/public/api/contributions.php b/public/api/contributions.php index 73ce5ab..66bc512 100644 --- a/public/api/contributions.php +++ b/public/api/contributions.php @@ -382,13 +382,14 @@ function handle_create_news($input) { try { $stmt = $pdo->prepare(" - INSERT INTO news (municipality_id, title, content) - VALUES (:mid, :title, :content) + INSERT INTO news (municipality_id, title, content, author_name) + VALUES (:mid, :title, :content, :author) "); $stmt->execute([ ':mid' => $input['municipality_id'], ':title' => $input['title'], - ':content' => $input['content'] + ':content' => $input['content'], + ':author' => $input['author_name'] ?? 'Stadtverwaltung' ]); json_response(['message' => 'News created successfully.', 'news_id' => (int) $pdo->lastInsertId()], 201); } catch (PDOException $e) { @@ -411,7 +412,7 @@ function handle_update_news($input) { $set = []; $params = [':id' => $input['news_id']]; - foreach (['title', 'content'] as $field) { + foreach (['title', 'content', 'author_name'] as $field) { if (isset($input[$field]) && $input[$field] !== '') { $set[] = "$field = :$field"; $params[":$field"] = $input[$field];