diff --git a/TODO.md b/TODO.md new file mode 100644 index 0000000..b68f2be --- /dev/null +++ b/TODO.md @@ -0,0 +1,4 @@ +- saving section info +- account deletion +- admin page + - invite codes diff --git a/config.php b/config.php index 60502b4..190e1dd 100644 --- a/config.php +++ b/config.php @@ -16,21 +16,24 @@ $db_username = "postgres"; $db_password = "postgres"; // DO NOT CHANGE THIS!!! +$lang = json_decode(file_get_contents("lang/$language.json"), true); $db_info = "host=$db_host dbname=$db_name user=$db_username password=$db_password"; $db = pg_connect($db_info); // default schema // DON'T CHANGE THIS UNLESS YOU KNOW WHAT YOU'RE DOING!!! -$lang = json_decode(file_get_contents("lang/$language.json"), true); $default_format = "For %C%t%c - %d"; +$default_section_name = "New Section"; +$default_row_name = "New Row"; + $default_schema = array( "general" => array( "name" => "General", "show_subtitle" => false, "items" => array( "general" => array( - "name" => "", - "display_format" => "For %C%t%c - %d" + "name" => $default_row_name, + "display_format" => $default_format ) ) ) diff --git a/css/base.css b/css/base.css index c7e15c9..9c900e0 100644 --- a/css/base.css +++ b/css/base.css @@ -33,7 +33,7 @@ body { font-size: 18px; } -h3 { +h3, h4 { margin-bottom: 0; } @@ -87,6 +87,12 @@ details:not([open]) summary { color: var(--subtext); } +blockquote { + margin: 10px 0; + padding-left: 10px; + border-left: 4px solid var(--subtext); +} + code { font-family: monospace; padding: 1px 3px; @@ -138,3 +144,11 @@ code { flex-wrap: wrap; gap: 3px 30px; } + +#section-config { + display: flex; + flex-direction: column; + flex-wrap: nowrap; + gap: 10px; + margin-bottom: 10px; +} diff --git a/index.php b/index.php index 2e13fcf..2e72822 100644 --- a/index.php +++ b/index.php @@ -20,17 +20,53 @@ if ($user === false) { } else if ($_SERVER["REQUEST_METHOD"] === "POST") { $intent = $_POST["intent"]; - if ($intent === "create-item") { + // TODO: update-texts + if ($intent === "create-section") { + $section_id = generate_id(); + + pg_insert( + $db, "section", array( + "id" => $section_id, + "users" => $user["id"], + "name" => $default_section_name, + "show_subtitle" => false + ) + ); + + pg_insert( + $db, "row", array( + "id" => generate_id(), + "section" => $section_id, + "name" => $default_row_name, + "display_format" => $default_format + ) + ); + } else if ($intent === "create-row") { + $section_id = $_POST["section"]; + + if (strlen($section_id) !== 64 || !preg_match("/[a-f0-9]{64}/", $section_id)) { + $err = $lang["add"]["errors"]["invalid_id"]; + } else { + pg_insert( + $db, "row", array( + "id" => generate_id(), + "section" => $section_id, + "name" => $default_row_name, + "display_format" => $default_format + ) + ); + } + } else 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"]; + $err = $lang["add"]["errors"]["invalid_id"]; } else if ($date === false) { - $err = lang["add"]["errors"]["date"]; + $err = $lang["add"]["errors"]["date"]; } else if (strlen($description) === 0 || strlen($description) > 256) { - $err = lang["add"]["errors"]["description_length"]; + $err = $lang["add"]["errors"]["description_length"]; } else { $repopulate = array( "row_id" => $row_id, @@ -75,25 +111,47 @@ if ($user === false) { $err = $lang["account"]["errors"]["incorrect_password"]; } } -} 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']}';"); +} else if ($_GET["del"]) { + $del_type = explode("-", $_GET["del"])[0]; + $del_id = explode("-", $_GET["del"])[1]; + + if (strlen($del_id) === 64 && preg_match("/[a-f0-9]{64}/", $del_id) && ($del_type === "item" || $del_type === "row" || $del_type === "section")) { + pg_query($db, "DELETE FROM $del_type WHERE id='$del_id';"); + } } include "boilerplate/head.php"; $select_options = ""; $todo_list = ""; +$section_conf = ""; +$section_forms = ""; -$q = "SELECT * FROM section WHERE users='{$user['id']}' ORDER BY LOWER(name) ASC;"; +$q = "SELECT * FROM section WHERE users='{$user['id']}' ORDER BY LOWER(name) ASC, id ASC;"; $sections = pg_fetch_all(pg_query($db, $q)); foreach ($sections as $section) { - $q = "SELECT * FROM row WHERE section='{$section['id']}' ORDER BY LOWER(name) ASC;"; - $rows = pg_fetch_all(pg_query($db, $q)); $show_subtitle = $section["show_subtitle"] === "t"; + $q = "SELECT * FROM row WHERE section='{$section['id']}' ORDER BY LOWER(name) ASC, id ASC;"; + $rows = pg_fetch_all(pg_query($db, $q)); $enable_optgroup = $show_subtitle || count($rows) !== 1; $todo_list .= "
+ + +"; + if ($enable_optgroup) { $select_options .= ""; } @@ -185,6 +263,37 @@ foreach ($sections as $section) {+ + + ++ "; if ($enable_optgroup) { $select_options .= "
%t
- %d
- %C
- %c
-