add migrations and a mark read option
This commit is contained in:
parent
f5312187e9
commit
35ae905805
7 changed files with 116 additions and 5 deletions
|
@ -10,12 +10,16 @@ $rows = pg_fetch_all($qresp);
|
||||||
|
|
||||||
$totalUnresponded = 0;
|
$totalUnresponded = 0;
|
||||||
$totalPriv = 0;
|
$totalPriv = 0;
|
||||||
|
$totalPrivRead = 0;
|
||||||
$totalRespondedPub = 0;
|
$totalRespondedPub = 0;
|
||||||
foreach (array_reverse($rows) as $i) {
|
foreach (array_reverse($rows) as $i) {
|
||||||
if ($i["isrespondedto"] === "f" && $i["ispublic"] === "t") {
|
if ($i["isrespondedto"] === "f" && $i["ispublic"] === "t") {
|
||||||
$totalUnresponded++;
|
$totalUnresponded++;
|
||||||
} else if ($i["ispublic"] === "f") {
|
} else if ($i["ispublic"] === "f") {
|
||||||
$totalPriv++;
|
$totalPriv++;
|
||||||
|
if ($i["isprivread" === "t"]) {
|
||||||
|
$totalPrivRead++;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
$totalRespondedPub++;
|
$totalRespondedPub++;
|
||||||
}
|
}
|
||||||
|
@ -31,6 +35,14 @@ if ($_GET["responded"] == 1) {
|
||||||
echo("<span class=\"sentconf\">response sent!</span>");
|
echo("<span class=\"sentconf\">response sent!</span>");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($_GET["read"] == 1) {
|
||||||
|
echo("<span class=\"sentconf\">marked as read!</span>");
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($_GET["migrated"] == 1) {
|
||||||
|
echo("<span class=\"sentconf\">migrations have been run!</span>");
|
||||||
|
}
|
||||||
|
|
||||||
asort($rows);
|
asort($rows);
|
||||||
|
|
||||||
echo("<h3 class=\"sect\">not responded to ({$totalUnresponded})</h3>");
|
echo("<h3 class=\"sect\">not responded to ({$totalUnresponded})</h3>");
|
||||||
|
@ -46,16 +58,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){
|
foreach (array_reverse($rows) as $i){
|
||||||
if ($i["ispublic"] === "f") {
|
if ($i["ispublic"] === "f" && $i["isprivread"] === "f") {
|
||||||
echo("<div class=\"question\">");
|
echo("<div class=\"question\">");
|
||||||
if ($i["iscwed"] === "t") {
|
if ($i["iscwed"] === "t") {
|
||||||
echo("<details><summary>cw: " . htmlspecialchars($i["cw"]) . "</summary><span class=\"cwfiller\"></span>");
|
echo("<details><summary>cw: " . htmlspecialchars($i["cw"]) . "</summary><span class=\"cwfiller\"></span>");
|
||||||
}
|
}
|
||||||
echo(htmlspecialchars($i["text"]));
|
echo(htmlspecialchars($i["text"]));
|
||||||
echo("<div class=\"time\">" . $i["time"] . "</div>");
|
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&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 +86,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&unread=1&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);
|
pg_query($db, $query);
|
||||||
|
|
||||||
echo("done");
|
|
||||||
|
|
||||||
header("Location: index.php?deleted=1&pw={$adminPassword}");
|
header("Location: index.php?deleted=1&pw={$adminPassword}");
|
||||||
|
|
||||||
?>
|
?>
|
|
@ -9,6 +9,10 @@ if ($_GET["pw"] === $adminPassword) {
|
||||||
include 'delete.php';
|
include 'delete.php';
|
||||||
} elseif ($_GET["page"] === "respond") {
|
} elseif ($_GET["page"] === "respond") {
|
||||||
include 'respond.php';
|
include 'respond.php';
|
||||||
|
} elseif ($_GET["page"] === "mark") {
|
||||||
|
include 'mark.php';
|
||||||
|
} elseif ($_GET["page"] === "migrate") {
|
||||||
|
include 'migrate.php';
|
||||||
} else {
|
} else {
|
||||||
include 'all.php';
|
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["unread"] === 1) {
|
||||||
|
$query = "
|
||||||
|
UPDATE data
|
||||||
|
SET isprivread = False
|
||||||
|
WHERE id = {$id};
|
||||||
|
";
|
||||||
|
$headerinfo = "Location: index.php?unread=1&pw={$adminPassword}";
|
||||||
|
} else {
|
||||||
|
$query = "
|
||||||
|
UPDATE data
|
||||||
|
SET isprivread = True
|
||||||
|
WHERE id = {$id};
|
||||||
|
";
|
||||||
|
$headerinfo = "Location: index.php?read=1&pw={$adminPassword}";
|
||||||
|
}
|
||||||
|
|
||||||
|
pg_query($db, $query);
|
||||||
|
|
||||||
|
header($headerinfo);
|
||||||
|
|
||||||
|
?>
|
24
admin/migrate.php
Normal file
24
admin/migrate.php
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
$query = "
|
||||||
|
SELECT * FROM migrations;
|
||||||
|
";
|
||||||
|
|
||||||
|
$qresp = pg_query($db, $query);
|
||||||
|
|
||||||
|
$rows = pg_fetch_all($qresp);
|
||||||
|
|
||||||
|
$migrations = array(
|
||||||
|
"20240218-AddMigrationsTable-40641e8d",
|
||||||
|
"20240218-AddMarkReadOption-a7e43358"
|
||||||
|
);
|
||||||
|
|
||||||
|
foreach ($migrations as $mig) {
|
||||||
|
if (!in_array($mig, $rows)) {
|
||||||
|
include "../migrations/{$mig}.php";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
header("Location: index.php?migrated=1&pw={$adminPassword}");
|
||||||
|
|
||||||
|
?>
|
12
migrations/20240218-AddMarkReadOption-a7e43358.php
Normal file
12
migrations/20240218-AddMarkReadOption-a7e43358.php
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
// add "isprivread" to data columns
|
||||||
|
|
||||||
|
$query = "
|
||||||
|
UPDATE TABLE data
|
||||||
|
ADD COLUMN isprivread BOOLEAN NOT NULL
|
||||||
|
";
|
||||||
|
|
||||||
|
pg_query($db, $query);
|
||||||
|
|
||||||
|
?>
|
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);
|
||||||
|
|
||||||
|
?>
|
Loading…
Add table
Reference in a new issue