notes postgres backend

This commit is contained in:
bogale 2026-09-29 17:49:35 +09:00
commit 6519fa6827
9 changed files with 82 additions and 55 deletions

View file

@ -1,41 +1,51 @@
<?php
$title = "";
$note = "";
$_shared = $_SERVER["DOCUMENT_ROOT"] . "/templates";
require_once "$_shared/lib.php";
switch ($_SERVER["REQUEST_METHOD"]) {
case "GET":
if (isset($_GET["title"])) {
$title = $_GET["title"];
$note = file_get_contents("notesDir/" . base64_encode($title));
if (isset($_GET["id"])) {
$note_id = $_GET["id"];
$pdo = pdo_init();
if (isset($_GET["delete"])) {
$stmt = $pdo->prepare("delete from notes.entries where id = ?");
$stmt->execute([$note_id]);
header("Location: .");
exit;
}
$stmt = $pdo->prepare("select * from notes.entries where id = ?");
$stmt->execute([$note_id]);
$entry = $stmt->fetch();
$title = $entry["title"];
$note = $entry["note"];
$date = $entry["date"];
$del_href = "<a href='?id=$note_id&delete'>Delele</a>";
};
break;
case "POST":
file_put_contents("notesDir/" . base64_encode($_POST["title"]), $_POST["note"]);
$pdo = pdo_init();
if ($_POST["id"] == "") {
$stmt = $pdo->prepare("insert into notes.entries
(title, note, date) values (?, ?, ?)");
$stmt->execute([$_POST["title"], $_POST["note"], $_POST["date"]]);
} else {
$stmt = $pdo->prepare("update notes.entries
set title = ?, note = ?, date = ? where id = ?");
$stmt->execute([$_POST["title"], $_POST["note"], $_POST["date"], $_POST["id"]]);
}
header("Location: .");
exit;
}
$_title = "Notes";
$root = $_SERVER["DOCUMENT_ROOT"];
require "$root/templates/header.php";
require "$_shared/header.php";
?>
<form method="post">
<input name="title" class="content" placeholder="Title" value="<?= $title ?>">
<input name="id" type="hidden" value="<?=$note_id?>">
<input name="date" type="date" class="content" value="<?=$date?>" required>
<input name="title" class="content" placeholder="Title" value="<?=$title?>" required>
<button type="submit" class="content">Save</button>
<button class="">Delete</button><br><br>
<textarea name="note" class="note content" placeholder="Note"><?= $note ?></textarea>
<?=$del_href?>
<textarea name="note" class="note content" placeholder="Note"><?=$note?></textarea>
</form>
<style>
button {
padding: 5px 10px;
}
.content {
color: #ffffff;
background-color: #303030;
}
.note {
width: 98%;
height: 280px;
}
</style>
<?php
require "$root/templates/footer.php";
require "$_shared/footer.php";
?>