From 87ffa36c1bfa49259e48d94f09e64f83632f0071 Mon Sep 17 00:00:00 2001 From: Maksymilian Jopek Date: Thu, 13 Apr 2023 15:47:15 +0200 Subject: v1.0.0 --- cardsList.php | 103 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 cardsList.php (limited to 'cardsList.php') diff --git a/cardsList.php b/cardsList.php new file mode 100644 index 0000000..7e2ffc5 --- /dev/null +++ b/cardsList.php @@ -0,0 +1,103 @@ +setAttribute(PDO::ATTR_EMULATE_PREPARES, false); +$stmt = $pdo->prepare("SELECT * FROM `cms_card`"); +$stmt->execute(); +$cards = $stmt->fetchAll(PDO::FETCH_ASSOC); +function strStartsWith(string $needle, string $haystack) +{ + return substr($haystack, 0, strlen($needle)) === $needle; +} +if (isset($_GET["editType"])) { + $type = explode('!', $_GET["editType"]); + if ($type[0] === "Add" || $type[0] === "Edit") { + if ($type[0] === "Edit") { + $stmt = $pdo->prepare("SELECT * FROM `cms_card` WHERE `id` = :id"); + $stmt->execute(["id" => $type[1]]); + $card = $stmt->fetchAll(PDO::FETCH_ASSOC)[0]; + } else { + $card = [ + "title" => "", + "body" => "", + ]; + } + $_SESSION["edited_card"] = $card; + header("Location: cardEdit.php"); + } elseif ($type[0] === "Remove") { + $stmt = $pdo->prepare("DELETE FROM `cms_card` WHERE `id` = :id"); + $stmt->execute(["id" => $type[1]]); + $card = $stmt->fetchAll(PDO::FETCH_ASSOC); + header("Location: cardsList.php"); + } + exit(); +} +?> + + + + + + + + + + + + + Card List + + +
+
+ + + + + + + + + + + 25) + $title = substr($card["title"], 0, 25) . "..."; + else + $title = $card["title"]; + if (strlen($card["body"]) > 150) + $body = substr($card["body"], 0, 150) . "..."; + else + $body = $card["body"]; + echo " + + + + + "; + } + ?> + +
IdTitleBodyEdit
{$card["id"]}$title$body + Edit    + Remove +
+ Add + Go to main +
+ + + + + \ No newline at end of file -- cgit v1.3.1