adding and deleting works :3

This commit is contained in:
trinkey 2025-03-24 12:57:50 -04:00
parent 18e4d29063
commit a9901df0b4
3 changed files with 67 additions and 10 deletions

View file

@ -38,7 +38,8 @@ h3 {
}
input,
select {
select,
button {
background-color: var(--input-background);
color: var(--color);
border: 1px solid var(--border);
@ -48,11 +49,14 @@ select {
}
input:focus,
select:focus {
select:focus,
button:focus {
outline: 2px solid var(--subtext);
}
input::placeholder {
input::placeholder,
i,
.gray {
color: var(--subtext);
}
@ -65,8 +69,8 @@ a:hover {
text-decoration: underline;
}
i {
color: var(--subtext);
a.plain {
color: var(--color);
}
ul {
@ -88,6 +92,14 @@ ul {
margin-bottom: 20px;
}
.red {
color: var(--red);
}
.yellow {
color: var(--yellow);
}
#container {
text-align: left;
margin: 0 10vw;

View file

@ -2,11 +2,11 @@
include "config.php";
include "helper.php";
include "boilerplate/head.php";
$user = is_logged_in();
if ($user === false) {
include "boilerplate/head.php";
echo "<a href=\"login.php\">{$lang['account']['log_in']}</a>";
$q = "SELECT count(*) FROM users LIMIT 1;";
@ -17,8 +17,36 @@ if ($user === false) {
include "boilerplate/foot.php";
exit();
} else if ($_SERVER["REQUEST_METHOD"] === "POST") {
$intent = $_POST["intent"];
if ($intent === "create-item") {
$row_id = $_POST["row"];
$date = strtotime($_POST["date"]);
$description = $_POST["description"];
if (strlen($row_id) !== 64 || !preg_match("/[a-f0-9]{64}/", $row_id)) {
$err = lang["add"]["errors"]["invalid_id"];
} else if ($date === false) {
$err = lang["add"]["errors"]["date"];
} else if (strlen($description) === 0 || strlen($description) > 256) {
$err = lang["add"]["errors"]["description_length"];
} else {
pg_insert(
$db, "item", array(
"id" => generate_id(),
"row" => $row_id,
"description" => $description,
"date" => date("Y-m-d", $date)
)
);
}
}
} else if ($_GET["del"] && strlen($_GET["del"]) === 64 && preg_match("/[a-f0-9]{64}/", $_GET["del"])) {
pg_query($db, "DELETE FROM item WHERE id='{$_GET['del']}';");
}
include "boilerplate/head.php";
$select_options = "";
$todo_list = "";
@ -40,7 +68,7 @@ foreach ($sections as $section) {
$first = true;
foreach ($rows as $row) {
$select_options .= "<option value=\"{$section['id']}-{$row['id']}\">";
$select_options .= "<option value=\"{$row['id']}\">";
if ($first && !$show_subtitle) {
$select_options .= htmlspecialchars($section["name"]);
@ -57,7 +85,17 @@ foreach ($sections as $section) {
$todo_list .= "<li><i>{$lang['list']['none']}</i></li>";
} else {
foreach ($items as $item) {
$todo_list .= "<li>" . str_replace("%d", htmlspecialchars($item["description"]), $row["display_format"]) . "</li>";
$color = "red";
$todo_list .= "<li>" . str_replace(
"%d", htmlspecialchars($item["description"]), str_replace(
"%c", "</span>", str_replace(
"%C", "<span class=\"$color\">", str_replace(
"%t", date("d M, Y", strtotime($item["date"])), $row["display_format"]
)
)
)
) . " <a class=\"plain\" href=\"index.php?del={$item['id']}\"><button tabindex=\"-1\">{$lang['list']['remove']}</button></a></li>";
}
}
@ -76,11 +114,12 @@ foreach ($sections as $section) {
<div id="container">
<h2><?php echo $lang["add"]["title"]; ?></h2>
<form method="POST">
<input type="hidden" name="intent" value="create-item">
<table>
<tr>
<td class="right"><label for="section"><?php echo $lang["add"]["section"]; ?></label></td>
<td class="right"><label for="row"><?php echo $lang["add"]["section"]; ?></label></td>
<td>
<select required id="section" name="section">
<select required id="row" name="row">
<?php echo $select_options; ?>
</select>
</td>

View file

@ -20,6 +20,12 @@
},
"add": {
"errors": {
"invalid_id": "Invalid ID format",
"date": "Invalid date",
"description_length": "Description must be between 1 and 256 characters"
},
"title": "Add Item",
"section": "Section:",
"date": "Date:",