diff --git a/admin.php b/admin.php deleted file mode 100644 index e69de29..0000000 diff --git a/admin/all.php b/admin/all.php new file mode 100644 index 0000000..7c62451 --- /dev/null +++ b/admin/all.php @@ -0,0 +1,65 @@ +=0; $i--) { + if ($rows[$i]["isrespondedto"] === "f" && $rows[$i]["ispublic"] === "t") { + $totalUnresponded++; + } else if ($rows[$i]["ispublic"] === "f") { + $totalPriv++; + } else { + $totalRespondedPub++; + } +} + +echo("

not responded to ({$totalUnresponded})

"); +for ($i=count($rows); $i>=0; $i--) { + if ($rows[$i]["isrespondedto"] === "f" && $rows[$i]["ispublic"] == "t") { + echo("
"); + if ($rows[$i]["iscwed"] === "t") { + echo("
cw: " . $rows[$i]["cw"] . ""); + } + echo(htmlspecialchars($rows[$i]["text"])); + echo("
" . $rows[$i]["time"] . "
"); + echo("edit / respond / delete
"); + } +} + +echo("

private ({$totalPriv})

"); +for ($i=count($rows); $i>=0; $i--) { + if ($rows[$i]["ispublic"] === "f") { + echo("
"); + if ($rows[$i]["iscwed"] === "t") { + echo("
cw: " . $rows[$i]["cw"] . ""); + } + echo(htmlspecialchars($rows[$i]["text"])); + echo("
" . $rows[$i]["time"] . "
"); + echo("edit
"); + } +} + +echo("

public ({$totalRespondedPub})

"); +for ($i=count($rows); $i>=0; $i--) { + if ($rows[$i]["ispublic"] === "t" && $rows[$i]["isrespondedto"] === "t") { + echo("
"); + if ($rows[$i]["iscwed"] === "t") { + echo("
cw: " . $rows[$i]["cw"] . ""); + } + echo(htmlspecialchars($rows[$i]["text"])); + echo("
" . $rows[$i]["time"] . "
"); + echo("
" . htmlspecialchars($rows[$i]["responsetext"]) . ""); + echo("
" . $rows[$i]["responsetime"] . "
"); + echo("edit
"); + } +} + +?> \ No newline at end of file diff --git a/admin/index.php b/admin/index.php new file mode 100644 index 0000000..dd790e0 --- /dev/null +++ b/admin/index.php @@ -0,0 +1,20 @@ +"); + +if ($_GET["pw"] === $adminPassword) { + if ($_GET["page"] === "all") { + include 'all.php'; + } elseif ($_GET["page" === "edit"]) { + include 'edit.php'; + } else { + include 'all.php'; + } +} else { + echo("

enter password

"); + echo("

"); +} + +?> \ No newline at end of file diff --git a/config.example.php b/config.example.php index d8f3999..e35bb61 100644 --- a/config.example.php +++ b/config.example.php @@ -3,12 +3,26 @@ // timezone (valid ones: https://www.php.net/manual/en/timezones.php) date_default_timezone_set('America/New_York'); +// admin +$adminPassword = "setAPasswordHere!123"; + +// page title +$pageTitle = "the cool qna"; + +$pageDomainEnabled = True; +$pageDomain = "example.com"; +$pageDomainOther = $pageDomain; // you can comment out and change this to a subdomain you want to "go back to". eg your site is me.example.org but you want it to say example.org +//$pageDomainOther = "me.example.com"; +$pageRoot = "/"; // path to go to + // database setup $dbHost = "localhost"; $dbName = "postgres"; $dbUsername = "postgres"; $dbPassword = "postgres"; + +// !!! DON'T CHANGE ANYTHING AFTER THIS UNLESS YOU KNOW WHAT YOU'RE DOING !!! $dbInfo = "host={$dbHost} dbname={$dbName} user={$dbUsername} password={$dbPassword}"; $db = pg_connect($dbInfo); diff --git a/css/admin.css b/css/admin.css new file mode 100644 index 0000000..3c64e82 --- /dev/null +++ b/css/admin.css @@ -0,0 +1,83 @@ +body { + background-image: url(https://notfire.cc/design/images/groundback.gif); + background-color: black; + color: white; + font-family: Arial, Helvetica, sans-serif; +} + +.permalink { + color: #ff0000; + font-size: .9em; +} + +.goback { + color: #ff0000; +} + +.title { + margin-bottom: .1em; +} + +.question { + margin-top: .7em; + background-color: #2c2c2c; + border-radius: 5px; + max-width: fit-content; + padding: .5em; +} + +.response { + background-color: #505050; + border-radius: 5px; + margin-top: .3em; + padding: .4em; + margin-bottom: .25em; +} + +.time { + font-size: .8em; +} + +.cwfiller { + height: 1.3em; + display: inline-block; +} + +.sect { + margin-top: .2em; + margin-bottom: .2em; +} + +.sentconf { + color: lime; + margin-top: .3em; + margin-bottom: .3em; +} + +.sendsum { + font-size: 1.17em; + font-weight: bold; +} + +.sendmsg { + margin-top: 1em; + border-radius: 5px; + background-color: #2c2c2c; + max-width: fit-content; + padding: .7em; +} + +#passinput, .submitbutton { + background-color: black; + color: white; + margin-bottom: .3em; +} + +.submitbutton { + font-size: 1.17em; + margin-top: .3em; +} + +.frm { + margin-bottom: 0px; +} \ No newline at end of file diff --git a/indiv.css b/css/indiv.css similarity index 87% rename from indiv.css rename to css/indiv.css index 659c87e..dae1538 100644 --- a/indiv.css +++ b/css/indiv.css @@ -1,4 +1,5 @@ body { + background-image: url(https://notfire.cc/design/images/groundback.gif); background-color: black; color: white; font-family: Arial, Helvetica, sans-serif; diff --git a/css/main.css b/css/main.css new file mode 100644 index 0000000..2b692c6 --- /dev/null +++ b/css/main.css @@ -0,0 +1,83 @@ +body { + background-image: url(https://notfire.cc/design/images/groundback.gif); + background-color: black; + color: white; + font-family: Arial, Helvetica, sans-serif; +} + +.permalink { + color: #ff0000; + font-size: .9em; +} + +.goback { + color: #ff0000; +} + +.title { + margin-bottom: .1em; +} + +.question { + margin-top: .7em; + background-color: #2c2c2c; + border-radius: 5px; + max-width: fit-content; + padding: .5em; +} + +.response { + background-color: #505050; + border-radius: 5px; + margin-top: .3em; + padding: .4em; + margin-bottom: .25em; +} + +.time { + font-size: .8em; +} + +.cwfiller { + height: 1.3em; + display: inline-block; +} + +.sect { + margin-bottom: .2em; + margin-top: .2em; +} + +.sentconf { + color: lime; + margin-top: .3em; + margin-bottom: .3em; +} + +.sendsum { + font-size: 1.17em; + font-weight: bold; +} + +.sendmsg { + margin-top: 1em; + border-radius: 5px; + background-color: #2c2c2c; + max-width: fit-content; + padding: .7em; +} + +#questioninput, #cwinput, .submitbutton { + background-color: black; + color: white; + margin-bottom: .3em; +} + +.submitbutton { + font-size: 1.17em; + margin-top: .3em; +} + +.frm { + margin-bottom: 0px; +} \ No newline at end of file diff --git a/fetch.php b/fetch.php index 0969032..44fa25e 100644 --- a/fetch.php +++ b/fetch.php @@ -16,19 +16,21 @@ WHERE id = {$id}; $qresp = pg_query($db, $query); $arr = pg_fetch_array($qresp); -echo(""); +echo(""); if (pg_num_rows($qresp) === 0 || $arr["ispublic"] === "f" || $arr["isrespondedto"] === "f") { - echo("

no such question exists

"); + echo("

{$pageTitle} – no such question exists

"); + echo("(go back?)"); + http_response_code(404); } else { - echo("

individual question

"); + echo("

{$pageTitle} – question number " . $arr["id"] . "

"); echo("(go back?)"); echo("
"); if ($arr["iscwed"] === "t") { echo("
cw: " . $arr["cw"] . ""); } - echo($arr["text"]); + echo(htmlspecialchars($arr["text"])); echo("
" . $arr["time"] . "
"); echo("
" . $arr["responsetext"] . ""); echo("
" . $arr["responsetime"] . "
"); diff --git a/index.php b/index.php index 983e03d..987c32e 100644 --- a/index.php +++ b/index.php @@ -2,21 +2,46 @@ include 'config.php'; -$_SERVER["id"] = 1; - -$id = $_SERVER["id"]; - -if ($id === null) { - exit(); -} - $query = " -SELECT * FROM data -WHERE id = {$id}; +SELECT * FROM data; "; $qresp = pg_query($db, $query); -echo (pg_fetch_array($qresp)[1]); +$rows = pg_fetch_all($qresp); + +echo(""); + +echo("

" . $pageTitle . "

"); + +if ($pageDomainEnabled) { + echo("(go back to " . $pageDomain . "?)"); +} + +if ($_GET["sent"] == 1) { + echo("
message sent!
"); +} + +echo("
send a message!"); + +echo("



"); + +echo("
"); + +echo("

all past messages

"); + +for ($i=count($rows); $i>=0; $i--) { + if ($rows[$i]["ispublic"] === "t" && $rows[$i]["isrespondedto"] === "t") { + echo("
"); + if ($rows[$i]["iscwed"] === "t") { + echo("
cw: " . $rows[$i]["cw"] . ""); + } + echo(htmlspecialchars($rows[$i]["text"])); + echo("
" . $rows[$i]["time"] . "
"); + echo("
" . htmlspecialchars($rows[$i]["responsetext"]) . ""); + echo("
" . $rows[$i]["responsetime"] . "
"); + echo("permalink
"); + } +} ?> \ No newline at end of file diff --git a/respond.php b/respond.php index 3c0d806..ab53918 100644 --- a/respond.php +++ b/respond.php @@ -9,7 +9,7 @@ UPDATE data SET isrespondedto = true, responsetext = 'teeheee HHIIIIII!!!!!', responsetime = timestamptz'{$timed}' -WHERE id = 1"; +"; pg_query($db, $query); diff --git a/send.php b/send.php index a617f93..644324f 100644 --- a/send.php +++ b/send.php @@ -2,16 +2,22 @@ include 'config.php'; -if ($_GET["text"] === null || $_GET["public"] === null) { +if ($_GET["text"] === null) { exit(); } -if ($_GET["cw"] === null) { +if ($_GET["cw"] === null || $_GET["cw"] === "") { $iscw = False; } else { $iscw = True; } +if ($_GET["public"] == 1) { + $isPublic = True; +} else { + $isPublic = False; +} + $curTime = date("Y-m-d h:i:sP"); $dataArray = array( @@ -19,7 +25,7 @@ $dataArray = array( "cw" => $_GET["cw"], "iscwed" => $iscw, "time" => $curTime, - "ispublic" => $_GET["public"], + "ispublic" => $isPublic, "isrespondedto" => False );