From 2eb5a432d2229788ce2fdb09f36c6f4bebdea813 Mon Sep 17 00:00:00 2001 From: Laria Carolin Chabowski Date: Fri, 7 Feb 2020 09:44:59 +0100 Subject: Initial commit --- src/Handlers/NoteHandler.php | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/Handlers/NoteHandler.php (limited to 'src/Handlers/NoteHandler.php') diff --git a/src/Handlers/NoteHandler.php b/src/Handlers/NoteHandler.php new file mode 100644 index 0000000..afdabb5 --- /dev/null +++ b/src/Handlers/NoteHandler.php @@ -0,0 +1,39 @@ +db(); + + $note = Note::byId($db, $variables["id"]); + if ($note === null) { + (new NotFoundHandler())->handle($env, []); + return; + } + + if ($_SERVER["REQUEST_METHOD"] === "POST") { + if ($_POST["delete"] === "delete") { + $note->delete($db); + http_response_code(303); + $url = $env->documentRoot(); + header("Location: {$url}"); + return; + } + + $note->setContent($_POST["content"]); + $note->setTags($_POST["tag"]); + $note->save($db); + } + + echo $env->twig()->render("/note.twig", ["note" => $note]); + } +} \ No newline at end of file -- cgit v1.2.3-70-g09d2