fix deletion and add sorting bypass
This commit is contained in:
parent
70e982c33b
commit
91df09f81b
5 changed files with 34 additions and 11 deletions
|
@ -79,7 +79,7 @@ ul {
|
||||||
}
|
}
|
||||||
|
|
||||||
details {
|
details {
|
||||||
margin: 10px 0;
|
margin: 20px 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
details:not([open]) summary {
|
details:not([open]) summary {
|
||||||
|
@ -87,6 +87,10 @@ details:not([open]) summary {
|
||||||
color: var(--subtext);
|
color: var(--subtext);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
summary {
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
blockquote {
|
blockquote {
|
||||||
margin: 10px 0;
|
margin: 10px 0;
|
||||||
padding-left: 10px;
|
padding-left: 10px;
|
||||||
|
|
|
@ -1,5 +1,13 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
function strip_name(string $name): string {
|
||||||
|
if (str_contains($name, "$")) {
|
||||||
|
return explode("$", $name, 2)[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $name;
|
||||||
|
}
|
||||||
|
|
||||||
function generate_id(): string {
|
function generate_id(): string {
|
||||||
return hash("sha256", uniqid("", true));
|
return hash("sha256", uniqid("", true));
|
||||||
}
|
}
|
||||||
|
|
24
index.php
24
index.php
|
@ -4,6 +4,7 @@ include "config.php";
|
||||||
include "helper.php";
|
include "helper.php";
|
||||||
|
|
||||||
$user = is_logged_in();
|
$user = is_logged_in();
|
||||||
|
$show_settings = false;
|
||||||
|
|
||||||
if ($user === false) {
|
if ($user === false) {
|
||||||
include "boilerplate/head.php";
|
include "boilerplate/head.php";
|
||||||
|
@ -19,6 +20,7 @@ if ($user === false) {
|
||||||
exit();
|
exit();
|
||||||
} else if ($_SERVER["REQUEST_METHOD"] === "POST") {
|
} else if ($_SERVER["REQUEST_METHOD"] === "POST") {
|
||||||
$intent = $_POST["intent"];
|
$intent = $_POST["intent"];
|
||||||
|
$show_settings = true;
|
||||||
|
|
||||||
// TODO: update-texts
|
// TODO: update-texts
|
||||||
if ($intent === "create-section") {
|
if ($intent === "create-section") {
|
||||||
|
@ -57,11 +59,12 @@ if ($user === false) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else if ($intent === "create-item") {
|
} else if ($intent === "create-item") {
|
||||||
|
$show_settings = false;
|
||||||
$row_id = $_POST["row"];
|
$row_id = $_POST["row"];
|
||||||
$date = strtotime($_POST["date"]);
|
$date = strtotime($_POST["date"]);
|
||||||
$description = $_POST["description"];
|
$description = $_POST["description"];
|
||||||
|
|
||||||
if (strlen($row_id) !== 64 || !preg_match("/^[a-f0-9]{64}/$", $row_id)) {
|
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) {
|
} else if ($date === false) {
|
||||||
$err = $lang["add"]["errors"]["date"];
|
$err = $lang["add"]["errors"]["date"];
|
||||||
|
@ -151,6 +154,8 @@ if ($user === false) {
|
||||||
$del_type = explode("-", $_GET["del"])[0];
|
$del_type = explode("-", $_GET["del"])[0];
|
||||||
$del_id = explode("-", $_GET["del"])[1];
|
$del_id = explode("-", $_GET["del"])[1];
|
||||||
|
|
||||||
|
$show_settings = $del_type !== "item";
|
||||||
|
|
||||||
if (strlen($del_id) === 64 && preg_match("/^[a-f0-9]{64}$/", $del_id) && ($del_type === "item" || $del_type === "row" || $del_type === "section")) {
|
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';");
|
pg_query($db, "DELETE FROM $del_type WHERE id='$del_id';");
|
||||||
}
|
}
|
||||||
|
@ -172,7 +177,7 @@ foreach ($sections as $section) {
|
||||||
$rows = pg_fetch_all(pg_query($db, $q));
|
$rows = pg_fetch_all(pg_query($db, $q));
|
||||||
$enable_optgroup = $show_subtitle || count($rows) !== 1;
|
$enable_optgroup = $show_subtitle || count($rows) !== 1;
|
||||||
|
|
||||||
$todo_list .= "<h3>" . htmlspecialchars($section["name"]) . "</h3>";
|
$todo_list .= "<h3>" . strip_name($section["name"]) . "</h3>";
|
||||||
$section_conf .= "<blockquote>
|
$section_conf .= "<blockquote>
|
||||||
<div><label>
|
<div><label>
|
||||||
{$lang['settings']['sections']['section']['title']}
|
{$lang['settings']['sections']['section']['title']}
|
||||||
|
@ -202,10 +207,10 @@ foreach ($sections as $section) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($first && !$show_subtitle) {
|
if ($first && !$show_subtitle) {
|
||||||
$select_options .= htmlspecialchars($section["name"]);
|
$select_options .= htmlspecialchars(strip_name($section["name"]));
|
||||||
} else {
|
} else {
|
||||||
$select_options .= htmlspecialchars($row["name"]);
|
$select_options .= htmlspecialchars(strip_name($row["name"]));
|
||||||
$todo_list .= "<strong>" . htmlspecialchars($row["name"]) . "</strong>";
|
$todo_list .= "<strong>" . htmlspecialchars(strip_name($row["name"])) . "</strong>";
|
||||||
}
|
}
|
||||||
|
|
||||||
$section_conf .= "<blockquote><div><label>
|
$section_conf .= "<blockquote><div><label>
|
||||||
|
@ -293,7 +298,7 @@ foreach ($sections as $section) {
|
||||||
<h2><?php echo $lang["list"]["title"]; ?></h2>
|
<h2><?php echo $lang["list"]["title"]; ?></h2>
|
||||||
<?php echo $todo_list; ?>
|
<?php echo $todo_list; ?>
|
||||||
|
|
||||||
<details>
|
<details<?php if ($show_settings) { echo " open"; } ?>>
|
||||||
<summary><?php echo $lang["settings"]["title"]; ?></summary>
|
<summary><?php echo $lang["settings"]["title"]; ?></summary>
|
||||||
|
|
||||||
<div id="settings-container">
|
<div id="settings-container">
|
||||||
|
@ -318,7 +323,12 @@ foreach ($sections as $section) {
|
||||||
|
|
||||||
<h4><?php echo $lang["settings"]["sections"]["format"]["title"]; ?></h4>
|
<h4><?php echo $lang["settings"]["sections"]["format"]["title"]; ?></h4>
|
||||||
<ul>
|
<ul>
|
||||||
<li><?php echo $lang["settings"]["sections"]["format"]["alphabetical"]; ?></li>
|
<li>
|
||||||
|
<?php echo $lang["settings"]["sections"]["format"]["alphabetical"]; ?>
|
||||||
|
<ul><li>
|
||||||
|
<?php echo $lang["settings"]["sections"]["format"]["alphabetical_bypass"]; ?>
|
||||||
|
</li></ul>
|
||||||
|
</li>
|
||||||
<li><?php echo $lang["settings"]["sections"]["format"]["html"]; ?></li>
|
<li><?php echo $lang["settings"]["sections"]["format"]["html"]; ?></li>
|
||||||
<li>
|
<li>
|
||||||
<?php echo $lang["settings"]["sections"]["format"]["replacements"]["title"] ?>
|
<?php echo $lang["settings"]["sections"]["format"]["replacements"]["title"] ?>
|
||||||
|
|
|
@ -75,6 +75,7 @@
|
||||||
|
|
||||||
"title": "Formatting Information",
|
"title": "Formatting Information",
|
||||||
"alphabetical": "Sorted alphabetically by row/section title",
|
"alphabetical": "Sorted alphabetically by row/section title",
|
||||||
|
"alphabetical_bypass": "Text before a <code>$</code> is hidden but sorted",
|
||||||
"html": "Displayed as raw HTML"
|
"html": "Displayed as raw HTML"
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -13,19 +13,19 @@ $queries = array(
|
||||||
);",
|
);",
|
||||||
"CREATE TABLE IF NOT EXISTS section (
|
"CREATE TABLE IF NOT EXISTS section (
|
||||||
id VARCHAR(64) PRIMARY KEY,
|
id VARCHAR(64) PRIMARY KEY,
|
||||||
users VARCHAR(64) NOT NULL REFERENCES users(id),
|
users VARCHAR(64) NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||||
name VARCHAR(128),
|
name VARCHAR(128),
|
||||||
show_subtitle BOOLEAN NOT NULL -- whether or not to separately show the name of the first item
|
show_subtitle BOOLEAN NOT NULL -- whether or not to separately show the name of the first item
|
||||||
);",
|
);",
|
||||||
"CREATE TABLE IF NOT EXISTS row (
|
"CREATE TABLE IF NOT EXISTS row (
|
||||||
id VARCHAR(64) PRIMARY KEY,
|
id VARCHAR(64) PRIMARY KEY,
|
||||||
section VARCHAR(64) NOT NULL REFERENCES section(id),
|
section VARCHAR(64) NOT NULL REFERENCES section(id) ON DELETE CASCADE,
|
||||||
name VARCHAR(128), -- ignored if first item and show_subtitle is enabled
|
name VARCHAR(128), -- ignored if first item and show_subtitle is enabled
|
||||||
display_format VARCHAR(128) NOT NULL -- %t - date, %d - description, %C - start color, %c - end color
|
display_format VARCHAR(128) NOT NULL -- %t - date, %d - description, %C - start color, %c - end color
|
||||||
);",
|
);",
|
||||||
"CREATE TABLE IF NOT EXISTS item (
|
"CREATE TABLE IF NOT EXISTS item (
|
||||||
id VARCHAR(64) PRIMARY KEY,
|
id VARCHAR(64) PRIMARY KEY,
|
||||||
row VARCHAR(64) NOT NULL REFERENCES row(id),
|
row VARCHAR(64) NOT NULL REFERENCES row(id) ON DELETE CASCADE,
|
||||||
description VARCHAR(256) NOT NULL,
|
description VARCHAR(256) NOT NULL,
|
||||||
date DATE NOT NULL
|
date DATE NOT NULL
|
||||||
);",
|
);",
|
||||||
|
|
Loading…
Reference in a new issue