db(); $note = Note::byId($db, $variables["id"]); if ($note === null) { (new NotFoundHandler())->handle($env, []); return; } if ($_SERVER["REQUEST_METHOD"] === "POST") { if (isset($_POST["delete"]) && $_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); if (isset($_FILES['attachments'])) Attachment::createFromUploads($env->db(), $env->attachmentsPath(), $note, $_FILES['attachments']); } echo $env->twig()->render("/note.twig", ["note" => new NoteForTemplate($db, $note)]); } }