commit 98c8eca4614b42a5f3406340c8ff37206d018112
parent cc17104abd4810fbfbf23b4cb624ffeff8b45507
Author: JayVii <jayvii[AT]posteo[DOT]de>
Date: Fri, 25 Oct 2024 14:58:18 +0200
feat: add option to list a single category
Diffstat:
M | index.php | | | 71 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----- |
1 file changed, 66 insertions(+), 5 deletions(-)
diff --git a/index.php b/index.php
@@ -6,7 +6,7 @@
/* DEVELOPMENT SETTINGS */
if (is_null($_POST["action"])) {
- $_POST["action"] = "list_all";
+ $_POST["action"] = "list";
}
$_POST["user"] = "test_user";
@@ -38,6 +38,7 @@
<header>
<!-- Buttons -->
<nav>
+
<!-- New Note: Edit-Action -->
<form action="/" target="_self" method="post">
<input
@@ -70,18 +71,78 @@
>
</form>
</nav>
+
<!-- Headline -->
<h1>Rememori</h1>
+
+ <!-- List all categories -->
+ <form action="/" target="_self" method="post">
+ <input
+ id="user"
+ name="user"
+ type="hidden"
+ value="<?php echo $_POST["user"]; ?>"
+ >
+ <input
+ id="action"
+ name="action"
+ type="hidden"
+ value="list"
+ >
+ <input
+ type="submit"
+ value="<?php echo $GLOBALS["i18n_list"]; ?>"
+ >
+ </form>
+
+<?php
+ /* Fetch all categories of the user */
+ $categories_path = glob("./data/" . $_POST["user"] . "/*");
+ foreach ($categories_path as $category_path) {
+?>
+ <form action="/" target="_self" method="post">
+ <input
+ id="user"
+ name="user"
+ type="hidden"
+ value="<?php echo $_POST["user"]; ?>"
+ >
+ <input
+ id="category"
+ name="category"
+ type="hidden"
+ value="<?php echo basename($category_path); ?>"
+ >
+ <input
+ id="action"
+ name="action"
+ type="hidden"
+ value="list"
+ >
+ <input
+ type="submit"
+ value="<?php echo basename($category_path); ?>"
+ >
+ </form>
+<?php
+ } // foreach-loop
+?>
+
</header>
<?php
/* Listing action */
- if ($_POST["action"] == "list_all") {
+ if ($_POST["action"] == "list") {
- /* Fetch all categories of the user */
- foreach (glob("./data/" . $_POST["user"] . "/*") as $categorypath) {
- list_notes($_POST["user"], basename($categorypath));
+ /* if no category is given, list all. otherwise only show given */
+ if (!is_null($_POST["category"])) {
+ $categories_path = array(
+ "./data/" . $_POST["user"] . "/" . $_POST["category"]
+ );
+ }
+ foreach ($categories_path as $category_path) {
+ list_notes($_POST["user"], basename($category_path));
}
}