summaryrefslogtreecommitdiffstats
path: root/cardEdit.php
diff options
context:
space:
mode:
Diffstat (limited to 'cardEdit.php')
-rw-r--r--cardEdit.php84
1 files changed, 84 insertions, 0 deletions
diff --git a/cardEdit.php b/cardEdit.php
new file mode 100644
index 0000000..9fce311
--- /dev/null
+++ b/cardEdit.php
@@ -0,0 +1,84 @@
+<?php
+session_start();
+
+require_once "dbCredentials.php";
+require_once "consts.php";
+checkLoggedIn();
+
+$card = $_SESSION["edited_card"];
+$adding = $card["id"] === null;
+if ($card["id"] === null)
+ $id = -1;
+else
+ $id = $card["id"];
+
+if (isset($_POST["body"]) && isset($_POST["title"])) {
+ $pdo = new PDO("mysql:dbname=$dbName;host=$dbHost;charset=utf8mb4", $dbUser, $dbPassword);
+ $pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
+
+ if ($id === -1)
+ $sql = "INSERT INTO `cms_card`(`title`, `body`) VALUES (:title, :body)";
+ else
+ $sql = "UPDATE `cms_card` SET `title`= :title, `body`=:body WHERE `id`=:id";
+
+ $stmt = $pdo->prepare($sql);
+
+ if ($id === -1) {
+ $stmt->execute([
+ "title" => $_POST["title"],
+ "body" => nl2br($_POST["body"]),
+ ]);
+ } else {
+ $stmt->execute([
+ "title" => $_POST["title"],
+ "body" => nl2br($_POST["body"]),
+ "id" => $_POST["id"],
+ ]);
+ }
+
+ $_POST["edited_card"] = null;
+ header("Location: cardsList.php");
+ exit();
+}
+?>
+<!doctype html>
+<html lang="en">
+
+<head>
+ <!-- Required meta tags -->
+ <meta charset="utf-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1">
+
+ <!-- Bootstrap CSS -->
+ <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-+0n0xVW2eSR5OomGNYDnhzAbDsOXxcvSN1TPprVMTNDbiYZCxYbOOl7+AMvyTG2x" crossorigin="anonymous">
+
+ <title>Edit card</title>
+</head>
+
+<body class="bg-dark text-white">
+ <div style="margin: 0 auto; width: 50%;">
+ <!-- class="container"> -->
+ <div style="margin: 5px auto; width: 50%;">
+ <h4>Card <?= 14 ?></h4>
+ <hr style="margin-left: -150%; margin-top: 0; width: 100vw;">
+ <form action="cardEdit.php" method="post" style="width: 140%">
+ <input type="hidden" name="id" value="<?= $id ?>">
+ <label for="title">Title:</label><br>
+ <input type="text" name="title" id="title" value="<?= $card["title"] ?>" required><br>
+ <label for="body">Body:</label><br>
+ <textarea id="body" name="body" rows="4" cols="50" required><?= $card["body"] ?></textarea><br>
+ <?php
+ if ($adding === true)
+ echo "<button type='submit' class='btn btn-warning' style='float: right;'>Dodaj</button>";
+ else
+ echo "<button type='submit' class='btn btn-info' style='float: right;'>Zapisz</button>";
+ ?>
+ </form><br><br>
+ <h3 style="float: left; color: red;"><?= $error ?></h3>
+ </div>
+ </div>
+ <!-- Optional JavaScript; choose one of the two! -->
+ <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/js/bootstrap.bundle.min.js" integrity="sha384-gtEjrD/SeCtmISkJkNUaaKMoLD0//ElJ19smozuHV6z3Iehds+3Ulb9Bn9Plx0x4" crossorigin="anonymous"></script>
+</body>
+
+</html> \ No newline at end of file