add migrations and a mark read option
This commit is contained in:
parent
f5312187e9
commit
a75dd535bc
9 changed files with 160 additions and 7 deletions
|
@ -10,12 +10,17 @@ $rows = pg_fetch_all($qresp);
|
|||
|
||||
$totalUnresponded = 0;
|
||||
$totalPriv = 0;
|
||||
$totalPrivRead = 0;
|
||||
$totalRespondedPub = 0;
|
||||
foreach (array_reverse($rows) as $i) {
|
||||
if ($i["isrespondedto"] === "f" && $i["ispublic"] === "t") {
|
||||
$totalUnresponded++;
|
||||
} else if ($i["ispublic"] === "f") {
|
||||
$totalPriv++;
|
||||
if ($i["isprivread"] === "t") {
|
||||
$totalPrivRead++;
|
||||
} else {
|
||||
$totalPriv++;
|
||||
}
|
||||
} else {
|
||||
$totalRespondedPub++;
|
||||
}
|
||||
|
@ -31,6 +36,18 @@ if ($_GET["responded"] == 1) {
|
|||
echo("<span class=\"sentconf\">response sent!</span>");
|
||||
}
|
||||
|
||||
if ($_GET["read"] == 1) {
|
||||
echo("<span class=\"sentconf\">marked as read!</span>");
|
||||
}
|
||||
|
||||
if ($_GET["unread"] == 1) {
|
||||
echo("<span class=\"sentconf\">marked as unread!</span>");
|
||||
}
|
||||
|
||||
if ($_GET["migrated"] == 1) {
|
||||
echo("<span class=\"sentconf\">migrations have been run!</span>");
|
||||
}
|
||||
|
||||
asort($rows);
|
||||
|
||||
echo("<h3 class=\"sect\">not responded to ({$totalUnresponded})</h3>");
|
||||
|
@ -46,16 +63,16 @@ foreach (array_reverse($rows) as $i){
|
|||
}
|
||||
}
|
||||
|
||||
echo("<h3 class=\"sect\">private ({$totalPriv})</h3>");
|
||||
echo("<h3 class=\"sect\">unread private ({$totalPriv})</h3>");
|
||||
foreach (array_reverse($rows) as $i){
|
||||
if ($i["ispublic"] === "f") {
|
||||
if ($i["ispublic"] === "f" && $i["isprivread"] === "f") {
|
||||
echo("<div class=\"question\">");
|
||||
if ($i["iscwed"] === "t") {
|
||||
echo("<details><summary>cw: " . htmlspecialchars($i["cw"]) . "</summary><span class=\"cwfiller\"></span>");
|
||||
}
|
||||
echo(htmlspecialchars($i["text"]));
|
||||
echo("<div class=\"time\">" . $i["time"] . "</div>");
|
||||
echo("<a class=\"permalink\" href=\"index.php?page=delete&id=" . $i["id"] . "&pw={$adminPassword}\">delete</a></div>");
|
||||
echo("<a class=\"permalink\" href=\"index.php?page=mark&action=read&id=" . $i["id"] . "&pw={$adminPassword}\">mark read</a> / <a class=\"permalink\" href=\"index.php?page=delete&id=" . $i["id"] . "&pw={$adminPassword}\">delete</a></div>");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -74,4 +91,17 @@ foreach (array_reverse($rows) as $i){
|
|||
}
|
||||
}
|
||||
|
||||
echo("<h3 class=\"sect\">read private ({$totalPrivRead})</h3>");
|
||||
foreach (array_reverse($rows) as $i){
|
||||
if ($i["ispublic"] === "f" && $i["isprivread"] === "t") {
|
||||
echo("<div class=\"question\">");
|
||||
if ($i["iscwed"] === "t") {
|
||||
echo("<details><summary>cw: " . htmlspecialchars($i["cw"]) . "</summary><span class=\"cwfiller\"></span>");
|
||||
}
|
||||
echo(htmlspecialchars($i["text"]));
|
||||
echo("<div class=\"time\">" . $i["time"] . "</div>");
|
||||
echo("<a class=\"permalink\" href=\"index.php?page=mark&action=unread&id=" . $i["id"] . "&pw={$adminPassword}\">mark unread</a> / <a class=\"permalink\" href=\"index.php?page=delete&id=" . $i["id"] . "&pw={$adminPassword}\">delete</a></div>");
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -13,8 +13,6 @@ WHERE id = {$id};
|
|||
|
||||
pg_query($db, $query);
|
||||
|
||||
echo("done");
|
||||
|
||||
header("Location: index.php?deleted=1&pw={$adminPassword}");
|
||||
|
||||
?>
|
|
@ -9,6 +9,10 @@ if ($_GET["pw"] === $adminPassword) {
|
|||
include 'delete.php';
|
||||
} elseif ($_GET["page"] === "respond") {
|
||||
include 'respond.php';
|
||||
} elseif ($_GET["page"] === "mark") {
|
||||
include 'mark.php';
|
||||
} elseif ($_GET["page"] === "migrate") {
|
||||
include 'migrate.php';
|
||||
} else {
|
||||
include 'all.php';
|
||||
}
|
||||
|
|
29
admin/mark.php
Normal file
29
admin/mark.php
Normal file
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
$id = (int)$_GET["id"];
|
||||
|
||||
if ($id === null) {
|
||||
exit();
|
||||
}
|
||||
|
||||
if ($_GET["action"] === "unread") {
|
||||
$query = "
|
||||
UPDATE data
|
||||
SET isprivread = False
|
||||
WHERE id = {$id};
|
||||
";
|
||||
$headerinfo = "Location: index.php?unread=1&pw={$adminPassword}";
|
||||
} elseif ($_GET["action"] === "read") {
|
||||
$query = "
|
||||
UPDATE data
|
||||
SET isprivread = True
|
||||
WHERE id = {$id};
|
||||
";
|
||||
$headerinfo = "Location: index.php?read=1&pw={$adminPassword}";
|
||||
}
|
||||
|
||||
pg_query($db, $query);
|
||||
|
||||
header($headerinfo);
|
||||
|
||||
?>
|
25
admin/migrate.php
Normal file
25
admin/migrate.php
Normal file
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
$query = "
|
||||
SELECT * FROM migrations;
|
||||
";
|
||||
|
||||
$qresp = pg_query($db, $query);
|
||||
|
||||
$rows = pg_fetch_all($qresp);
|
||||
|
||||
$migrations = array(
|
||||
"20240218-AddMigrationsTable-40641e8d",
|
||||
"20240218-AddMarkReadOption-a7e43358",
|
||||
"20240218-AddFalsesToPrivRead-67d82b18"
|
||||
);
|
||||
|
||||
foreach ($migrations as $mig) {
|
||||
if (!in_array($mig, array_column($rows, 'id'))) {
|
||||
include "../migrations/{$mig}.php";
|
||||
}
|
||||
}
|
||||
|
||||
//header("Location: index.php?migrated=1&pw={$adminPassword}");
|
||||
|
||||
?>
|
19
migrations/20240218-AddFalsesToPrivRead-67d82b18.php
Normal file
19
migrations/20240218-AddFalsesToPrivRead-67d82b18.php
Normal file
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
// ensure already private messages still get shown
|
||||
|
||||
$query = "
|
||||
UPDATE data
|
||||
SET isprivread = False
|
||||
WHERE ispublic IS FALSE;
|
||||
";
|
||||
|
||||
pg_query($db, $query);
|
||||
|
||||
$dataArray = array(
|
||||
"id" => "20240218-AddFalsesToPrivRead-67d82b18"
|
||||
);
|
||||
|
||||
pg_insert($db, "migrations", $dataArray);
|
||||
|
||||
?>
|
18
migrations/20240218-AddMarkReadOption-a7e43358.php
Normal file
18
migrations/20240218-AddMarkReadOption-a7e43358.php
Normal file
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
// add "isprivread" to data columns
|
||||
|
||||
$query = "
|
||||
ALTER TABLE data
|
||||
ADD COLUMN isprivread BOOLEAN;
|
||||
";
|
||||
|
||||
pg_query($db, $query);
|
||||
|
||||
$dataArray = array(
|
||||
"id" => "20240218-AddMarkReadOption-a7e43358"
|
||||
);
|
||||
|
||||
pg_insert($db, "migrations", $dataArray);
|
||||
|
||||
?>
|
19
migrations/20240218-AddMigrationsTable-40641e8d.php
Normal file
19
migrations/20240218-AddMigrationsTable-40641e8d.php
Normal file
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
// add migrations table to track migrations that have been run
|
||||
|
||||
$query = "
|
||||
CREATE TABLE migrations (
|
||||
id TEXT NOT NULL
|
||||
);
|
||||
";
|
||||
|
||||
pg_query($db, $query);
|
||||
|
||||
$dataArray = array(
|
||||
"id" => "20240218-AddMigrationsTable-40641e8d"
|
||||
);
|
||||
|
||||
pg_insert($db, "migrations", $dataArray);
|
||||
|
||||
?>
|
13
setup.php
13
setup.php
|
@ -12,12 +12,23 @@ CREATE TABLE data (
|
|||
ispublic BOOLEAN NOT NULL,
|
||||
isrespondedto BOOLEAN NOT NULL,
|
||||
responsetext TEXT,
|
||||
responsetime TIMESTAMPTZ
|
||||
responsetime TIMESTAMPTZ,
|
||||
isprivread BOOLEAN NOT NULL
|
||||
);
|
||||
";
|
||||
|
||||
pg_query($db, $query);
|
||||
|
||||
$query = "
|
||||
CREATE TABLE migrations (
|
||||
id TEXT NOT NULL
|
||||
);
|
||||
";
|
||||
|
||||
pg_query($db, $query);
|
||||
|
||||
include 'admin/migrate.php';
|
||||
|
||||
echo "database set up";
|
||||
|
||||
?>
|
Loading…
Reference in a new issue