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