adding and deleting works :3
This commit is contained in:
parent
18e4d29063
commit
a9901df0b4
3 changed files with 67 additions and 10 deletions
22
css/base.css
22
css/base.css
|
@ -38,7 +38,8 @@ h3 {
|
||||||
}
|
}
|
||||||
|
|
||||||
input,
|
input,
|
||||||
select {
|
select,
|
||||||
|
button {
|
||||||
background-color: var(--input-background);
|
background-color: var(--input-background);
|
||||||
color: var(--color);
|
color: var(--color);
|
||||||
border: 1px solid var(--border);
|
border: 1px solid var(--border);
|
||||||
|
@ -48,11 +49,14 @@ select {
|
||||||
}
|
}
|
||||||
|
|
||||||
input:focus,
|
input:focus,
|
||||||
select:focus {
|
select:focus,
|
||||||
|
button:focus {
|
||||||
outline: 2px solid var(--subtext);
|
outline: 2px solid var(--subtext);
|
||||||
}
|
}
|
||||||
|
|
||||||
input::placeholder {
|
input::placeholder,
|
||||||
|
i,
|
||||||
|
.gray {
|
||||||
color: var(--subtext);
|
color: var(--subtext);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,8 +69,8 @@ a:hover {
|
||||||
text-decoration: underline;
|
text-decoration: underline;
|
||||||
}
|
}
|
||||||
|
|
||||||
i {
|
a.plain {
|
||||||
color: var(--subtext);
|
color: var(--color);
|
||||||
}
|
}
|
||||||
|
|
||||||
ul {
|
ul {
|
||||||
|
@ -88,6 +92,14 @@ ul {
|
||||||
margin-bottom: 20px;
|
margin-bottom: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.red {
|
||||||
|
color: var(--red);
|
||||||
|
}
|
||||||
|
|
||||||
|
.yellow {
|
||||||
|
color: var(--yellow);
|
||||||
|
}
|
||||||
|
|
||||||
#container {
|
#container {
|
||||||
text-align: left;
|
text-align: left;
|
||||||
margin: 0 10vw;
|
margin: 0 10vw;
|
||||||
|
|
49
index.php
49
index.php
|
@ -2,11 +2,11 @@
|
||||||
|
|
||||||
include "config.php";
|
include "config.php";
|
||||||
include "helper.php";
|
include "helper.php";
|
||||||
include "boilerplate/head.php";
|
|
||||||
|
|
||||||
$user = is_logged_in();
|
$user = is_logged_in();
|
||||||
|
|
||||||
if ($user === false) {
|
if ($user === false) {
|
||||||
|
include "boilerplate/head.php";
|
||||||
echo "<a href=\"login.php\">{$lang['account']['log_in']}</a>";
|
echo "<a href=\"login.php\">{$lang['account']['log_in']}</a>";
|
||||||
|
|
||||||
$q = "SELECT count(*) FROM users LIMIT 1;";
|
$q = "SELECT count(*) FROM users LIMIT 1;";
|
||||||
|
@ -17,8 +17,36 @@ if ($user === false) {
|
||||||
|
|
||||||
include "boilerplate/foot.php";
|
include "boilerplate/foot.php";
|
||||||
exit();
|
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 = "";
|
$select_options = "";
|
||||||
$todo_list = "";
|
$todo_list = "";
|
||||||
|
@ -40,7 +68,7 @@ foreach ($sections as $section) {
|
||||||
|
|
||||||
$first = true;
|
$first = true;
|
||||||
foreach ($rows as $row) {
|
foreach ($rows as $row) {
|
||||||
$select_options .= "<option value=\"{$section['id']}-{$row['id']}\">";
|
$select_options .= "<option value=\"{$row['id']}\">";
|
||||||
|
|
||||||
if ($first && !$show_subtitle) {
|
if ($first && !$show_subtitle) {
|
||||||
$select_options .= htmlspecialchars($section["name"]);
|
$select_options .= htmlspecialchars($section["name"]);
|
||||||
|
@ -57,7 +85,17 @@ foreach ($sections as $section) {
|
||||||
$todo_list .= "<li><i>{$lang['list']['none']}</i></li>";
|
$todo_list .= "<li><i>{$lang['list']['none']}</i></li>";
|
||||||
} else {
|
} else {
|
||||||
foreach ($items as $item) {
|
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">
|
<div id="container">
|
||||||
<h2><?php echo $lang["add"]["title"]; ?></h2>
|
<h2><?php echo $lang["add"]["title"]; ?></h2>
|
||||||
<form method="POST">
|
<form method="POST">
|
||||||
|
<input type="hidden" name="intent" value="create-item">
|
||||||
<table>
|
<table>
|
||||||
<tr>
|
<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>
|
<td>
|
||||||
<select required id="section" name="section">
|
<select required id="row" name="row">
|
||||||
<?php echo $select_options; ?>
|
<?php echo $select_options; ?>
|
||||||
</select>
|
</select>
|
||||||
</td>
|
</td>
|
||||||
|
|
|
@ -20,6 +20,12 @@
|
||||||
},
|
},
|
||||||
|
|
||||||
"add": {
|
"add": {
|
||||||
|
"errors": {
|
||||||
|
"invalid_id": "Invalid ID format",
|
||||||
|
"date": "Invalid date",
|
||||||
|
"description_length": "Description must be between 1 and 256 characters"
|
||||||
|
},
|
||||||
|
|
||||||
"title": "Add Item",
|
"title": "Add Item",
|
||||||
"section": "Section:",
|
"section": "Section:",
|
||||||
"date": "Date:",
|
"date": "Date:",
|
||||||
|
|
Loading…
Reference in a new issue