diff --git a/php/controller/updateArticle-controller.php b/php/controller/updateArticle-controller.php index 086de7e..3a40f5c 100644 --- a/php/controller/updateArticle-controller.php +++ b/php/controller/updateArticle-controller.php @@ -10,15 +10,19 @@ if ($_SERVER["REQUEST_METHOD"] === "POST") { $_SESSION["old_content"] = $_POST["content"] ?? ''; $_SESSION["old_category"] = $_POST["category"] ?? ''; $_SESSION["old_tags"] = $_POST["tags"] ?? ''; - try { + + if (isset($_GET["id"]) && !empty($_GET["id"])) { $id = $_GET["id"]; - } catch (Exception $e){ + } else { $_SESSION["message"] = "missing_id"; + header("location: ../../index.php?pfad=updateArticle"); + exit(); } + if (!isset($_POST["title"]) ||!isset($_POST["content"]) || !isset($_POST["category"])){ $_SESSION["message"] = "missing_parameters"; - } elseif(!isset($id)) { - $_SESSION["message"] = "missing_id"; + header("location: ../../index.php?pfad=updateArticle"); + exit(); }else{ $title = $_POST["title"]; $content = $_POST["content"]; @@ -33,31 +37,31 @@ if ($_SERVER["REQUEST_METHOD"] === "POST") { // -------------------------------- Validierung der Daten: ------------------------- if (!articleAuthorValidator($author)) { $_SESSION["message"] = "author_not_valid"; - header("location: ../../index.php?pfad=createArticle"); + header("location: ../../index.php?pfad=updateArticle"); exit(); } if (!articleTitleValidator($title)) { $_SESSION["message"] = "invalid_title"; - header("location: ../../index.php?pfad=createArticle"); + header("location: ../../index.php?pfad=updateArticle"); exit(); } if (!articleContentValidator($content)) { $_SESSION["message"] = "invalid_content"; - header("location: ../../index.php?pfad=createArticle"); + header("location: ../../index.php?pfad=updateArticle"); exit(); } if (!articleCategoryValidator($category)) { $_SESSION["message"] = "invalid_category"; - header("location: ../../index.php?pfad=createArticle"); + header("location: ../../index.php?pfad=updateArticle"); exit(); } - if (!articleTagValidator($_POST["tags"])) { + if (!articleTagValidator($tags)) { $_SESSION["message"] = "invalid_tags"; - header("location: ../../index.php?pfad=createArticle"); + header("location: ../../index.php?pfad=updateArticle"); exit(); } else { $cleanedTags = []; @@ -65,10 +69,11 @@ if ($_SERVER["REQUEST_METHOD"] === "POST") { foreach ($rawTags as $rawTag) { // Leerzeichen am Anfang/Ende des einzelnen Tags entfernen: $tag = trim($rawTag); - // Duplikate entfernen: - $cleanedTags = array_unique($cleanedTags); - $cleanedTags = implode(',', $cleanedTags); + $cleanedTags[] = $tag; } + // Duplikate entfernen: + $cleanedTags = array_unique($cleanedTags); + $cleanedTags = implode(',', $cleanedTags); } // ----------------- Übertragung der validierten Daten in ArticleManager: --------------------------- @@ -82,7 +87,7 @@ if ($_SERVER["REQUEST_METHOD"] === "POST") { $articleManager->updateArticle($id ,$article, $author); } catch (Exception $e){ $_SESSION["message"] = "internal_error"; - header("location: ../../index.php?pfad=createArticle"); + header("location: ../../index.php?pfad=updateArticle"); exit(); } $_SESSION["message"] = "article_updated";