Kommentare bearbeiten
This commit is contained in:
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
if (session_status() === PHP_SESSION_NONE) {
|
||||
session_start();
|
||||
}
|
||||
|
||||
require_once "php/model/CommentManager.php";
|
||||
|
||||
if ($_SERVER["REQUEST_METHOD"] !== "POST") {
|
||||
header("Location: index.php");
|
||||
exit();
|
||||
}
|
||||
|
||||
if (!isset($_SESSION["user_email"])) {
|
||||
header("Location: index.php?pfad=login");
|
||||
exit();
|
||||
}
|
||||
|
||||
$commentId = filter_input(
|
||||
INPUT_POST,
|
||||
"comment_id",
|
||||
FILTER_VALIDATE_INT
|
||||
);
|
||||
|
||||
$articleId = filter_input(
|
||||
INPUT_POST,
|
||||
"article_id",
|
||||
FILTER_VALIDATE_INT
|
||||
);
|
||||
|
||||
$content = trim($_POST["content"] ?? "");
|
||||
|
||||
/*
|
||||
* Ohne gültige Beitrags-ID kann nicht sicher
|
||||
* zum ursprünglichen Beitrag zurückgeleitet werden.
|
||||
*/
|
||||
if (!$articleId) {
|
||||
header("Location: index.php");
|
||||
exit();
|
||||
}
|
||||
|
||||
/*
|
||||
* Kommentar-ID und Inhalt werden geprüft.
|
||||
*/
|
||||
if (!$commentId || $content === "") {
|
||||
$_SESSION["comment_message"] =
|
||||
"Der Kommentar darf nicht leer sein.";
|
||||
|
||||
$_SESSION["comment_message_type"] = "error";
|
||||
|
||||
header(
|
||||
"Location: index.php?pfad=showArticle&id="
|
||||
. urlencode((string) $articleId)
|
||||
. "#comments"
|
||||
);
|
||||
exit();
|
||||
}
|
||||
|
||||
try {
|
||||
$commentManager = CommentManager::getInstance();
|
||||
|
||||
$updated = $commentManager->updateComment(
|
||||
$commentId,
|
||||
$_SESSION["user_email"],
|
||||
$content
|
||||
);
|
||||
|
||||
if ($updated) {
|
||||
$_SESSION["comment_message"] =
|
||||
"Der Kommentar wurde erfolgreich bearbeitet.";
|
||||
|
||||
$_SESSION["comment_message_type"] = "success";
|
||||
} else {
|
||||
$_SESSION["comment_message"] =
|
||||
"Der Kommentar konnte nicht bearbeitet werden.";
|
||||
|
||||
$_SESSION["comment_message_type"] = "error";
|
||||
}
|
||||
|
||||
} catch (Throwable $e) {
|
||||
$_SESSION["comment_message"] =
|
||||
"Beim Bearbeiten des Kommentars ist ein Fehler aufgetreten.";
|
||||
|
||||
$_SESSION["comment_message_type"] = "error";
|
||||
}
|
||||
|
||||
header(
|
||||
"Location: index.php?pfad=showArticle&id="
|
||||
. urlencode((string) $articleId)
|
||||
. "#comments"
|
||||
);
|
||||
exit();
|
||||
Reference in New Issue
Block a user