diff --git a/content/showArticle.php b/content/showArticle.php
index fff5b00..3feb0bf 100644
--- a/content/showArticle.php
+++ b/content/showArticle.php
@@ -114,7 +114,9 @@ if (isset($_GET["id"])) {
-
Noch keine Kommentare vorhanden.
+
diff --git a/index.php b/index.php
index 1006322..5b5a7cb 100644
--- a/index.php
+++ b/index.php
@@ -29,55 +29,30 @@ if ($pfad === "deleteAccount") {
}
?>
-
-
-
+
+
+
-
-
-
-
-
-
+
+
+
+
+
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
-
+
- EduForge
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
+ EduForge
+
\ No newline at end of file
diff --git a/js/comments.js b/js/comments.js
new file mode 100644
index 0000000..7ee43f7
--- /dev/null
+++ b/js/comments.js
@@ -0,0 +1,55 @@
+document.addEventListener("DOMContentLoaded", function () {
+ const form = document.getElementById("comment-form");
+ const commentsList = document.getElementById("comments-list");
+ const commentContent = document.getElementById("comment-content");
+
+ if (!form || !commentsList || !commentContent) {
+ return;
+ }
+
+ form.addEventListener("submit", function (event) {
+ event.preventDefault();
+
+ const formData = new FormData(form);
+
+ fetch("php/ajax/add-comment.php", {
+ method: "POST",
+ body: formData
+ })
+ .then(response => response.json())
+ .then(data => {
+ if (!data.success) {
+ alert(data.message);
+ return;
+ }
+
+ const emptyMessage = commentsList.querySelector(".no-comments-message");
+ if (emptyMessage) {
+ emptyMessage.remove();
+ }
+
+ const commentElement = document.createElement("div");
+ commentElement.classList.add("comment-item");
+
+ commentElement.innerHTML = `
+
+ ${escapeHtml(data.author)}
+ ${escapeHtml(data.created)}
+
+ ${escapeHtml(data.content).replace(/\n/g, "
")}
+ `;
+
+ commentsList.prepend(commentElement);
+ commentContent.value = "";
+ })
+ .catch(() => {
+ alert("Kommentar konnte nicht gesendet werden.");
+ });
+ });
+
+ function escapeHtml(text) {
+ const div = document.createElement("div");
+ div.textContent = text;
+ return div.innerHTML;
+ }
+});
\ No newline at end of file
diff --git a/php/ajax/add-comment.php b/php/ajax/add-comment.php
new file mode 100644
index 0000000..0895de3
--- /dev/null
+++ b/php/ajax/add-comment.php
@@ -0,0 +1,48 @@
+ false,
+ "message" => "Du musst angemeldet sein."
+ ]);
+ exit();
+}
+
+$articleId = $_POST["article_id"] ?? null;
+$content = trim($_POST["content"] ?? "");
+
+if (empty($articleId) || empty($content)) {
+ echo json_encode([
+ "success" => false,
+ "message" => "Kommentar darf nicht leer sein."
+ ]);
+ exit();
+}
+
+try {
+ $commentManager = CommentManager::getInstance();
+
+ $commentManager->addComment(
+ $articleId,
+ $_SESSION["user_email"],
+ $content
+ );
+
+ echo json_encode([
+ "success" => true,
+ "author" => $_SESSION["user_email"],
+ "content" => $content,
+ "created" => date("Y-m-d H:i:s")
+ ]);
+
+} catch (Exception $e) {
+ echo json_encode([
+ "success" => false,
+ "message" => "Kommentar konnte nicht gespeichert werden."
+ ]);
+}