Compare commits
15 Commits
4c227b8e01
...
main
Author | SHA1 | Date | |
---|---|---|---|
b08110e3e0 | |||
24a8b4758d | |||
1dba222b4a | |||
83dab7d940 | |||
b6e5b1e806 | |||
31087533f3 | |||
a21f3ef6aa | |||
57635df050 | |||
e4460f0a76 | |||
90048c7632 | |||
4ff4c6eb14 | |||
a4c3d4ce31 | |||
f980c5c9af | |||
ab3a0457e0 | |||
5762e6d5a1 |
@@ -1,2 +1,10 @@
|
||||
# peehaitchpea
|
||||
|
||||
## GET /api.php?cmd=getselectedmessage
|
||||
|
||||
Odpověď je max. 1 řádek, který obsahuje text současně vybrané otázky.
|
||||
|
||||
## POST /api.php?cmd=newmodmessages
|
||||
|
||||
Data: ["Otázka 1", "Otázka 2", ...]
|
||||
|
||||
|
132
api.php
132
api.php
@@ -82,81 +82,91 @@
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;");
|
||||
}
|
||||
|
||||
$cmd = $_GET['cmd'];
|
||||
if(!in_array("counter", $tables)) {
|
||||
query("CREATE TABLE `counter` (
|
||||
`value` int NOT NULL,
|
||||
PRIMARY KEY (`value`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;");
|
||||
}
|
||||
|
||||
switch($cmd) {
|
||||
case "newmodmessages":
|
||||
$arr = json_decode(file_get_contents("php://input"));
|
||||
foreach ($arr as $value) {
|
||||
query("INSERT INTO `for_moderation`(`text`) VALUES (\"" . $conn->real_escape_string($value) . "\");");
|
||||
}
|
||||
break;
|
||||
query("SELECT COUNT(value) AS count FROM counter;", function($row) {
|
||||
if($row["count"] <= 0) {
|
||||
query("INSERT INTO counter(value) VALUES (0);");
|
||||
}
|
||||
});
|
||||
|
||||
case "newstallmanmessages":
|
||||
$arr = json_decode(file_get_contents("php://input"));
|
||||
foreach ($arr as $value) {
|
||||
query("INSERT INTO `for_stallman`(`text`, `selected`) VALUES (\"" . $conn->real_escape_string($value) . "\", false);");
|
||||
}
|
||||
break;
|
||||
if(isset($_GET["cmd"])) {
|
||||
$cmd = $_GET['cmd'];
|
||||
|
||||
case "getselectedmessage":
|
||||
query("SELECT `text` FROM `for_stallman` WHERE `selected` = true LIMIT 1;", function($row) {
|
||||
echo $row["text"];
|
||||
});
|
||||
break;
|
||||
switch($cmd) {
|
||||
case "newmodmessages":
|
||||
$arr = json_decode(file_get_contents("php://input"));
|
||||
foreach ($arr as $value) {
|
||||
query("INSERT INTO `for_moderation`(`text`) VALUES (\"" . $conn->real_escape_string($value) . "\");");
|
||||
}
|
||||
break;
|
||||
|
||||
case "selectmessage":
|
||||
query("SELECT `id` FROM `for_stallman` WHERE `selected` = true;", function($row) {
|
||||
query("UPDATE `for_stallman` SET `selected` = false WHERE `id` = " . $row["id"] . ";");
|
||||
});
|
||||
|
||||
query("UPDATE `for_stallman` SET `selected` = true WHERE `id` = " . file_get_contents("php://input") . ";");
|
||||
break;
|
||||
case "newstallmanmessages":
|
||||
$arr = json_decode(file_get_contents("php://input"));
|
||||
foreach ($arr as $value) {
|
||||
query("INSERT INTO `for_stallman`(`text`, `selected`) VALUES (\"" . $conn->real_escape_string($value) . "\", false);");
|
||||
}
|
||||
break;
|
||||
|
||||
case "unselectmessage":
|
||||
query("SELECT `id` FROM `for_stallman` WHERE `selected` = true;", function($row) {
|
||||
query("UPDATE `for_stallman` SET `selected` = false WHERE `id` = " . $row["id"] . ";");
|
||||
});
|
||||
break;
|
||||
case "getselectedmessage":
|
||||
query("SELECT `text` FROM `for_stallman` WHERE `selected` = true LIMIT 1;", function($row) {
|
||||
echo $row["text"];
|
||||
});
|
||||
break;
|
||||
|
||||
case "getmodmessages":
|
||||
$arr = [];
|
||||
case "selectmessage":
|
||||
query("UPDATE `for_stallman` SET `selected` = false");
|
||||
query("UPDATE `for_stallman` SET `selected` = true WHERE `id` = " . file_get_contents("php://input") . ";");
|
||||
break;
|
||||
|
||||
query("SELECT `id`, `text` FROM `for_moderation`;", function($row) {
|
||||
global $arr;
|
||||
$arr[$row["id"]] = $row["text"];
|
||||
});
|
||||
case "unselectmessage":
|
||||
query("UPDATE `for_stallman` SET `selected` = false");
|
||||
break;
|
||||
|
||||
echo(json_encode($arr));
|
||||
break;
|
||||
case "getmodmessages":
|
||||
$arr = [];
|
||||
|
||||
case "getstallmanmessages":
|
||||
$arr = [];
|
||||
query("SELECT `id`, `text` FROM `for_moderation`;", function($row) {
|
||||
global $arr;
|
||||
$arr[$row["id"]] = $row["text"];
|
||||
});
|
||||
|
||||
query("SELECT `id`, `text` FROM `for_stallman`;", function($row) {
|
||||
global $arr;
|
||||
$arr[$row["id"]] = $row["text"];
|
||||
});
|
||||
echo(json_encode($arr));
|
||||
break;
|
||||
|
||||
echo(json_encode($arr));
|
||||
break;
|
||||
case "getstallmanmessages":
|
||||
$arr = [];
|
||||
|
||||
case "deletemodmessages":
|
||||
$arr = json_decode(file_get_contents("php://input"));
|
||||
foreach ($arr as $value) {
|
||||
query("DELETE FROM `for_moderation` WHERE `id` = " . $conn->real_escape_string($value) . ";");
|
||||
}
|
||||
break;
|
||||
query("SELECT `id`, `text` FROM `for_stallman`;", function($row) {
|
||||
global $arr;
|
||||
$arr[$row["id"]] = $row["text"];
|
||||
});
|
||||
|
||||
case "deletestallmanmessages":
|
||||
$arr = json_decode(file_get_contents("php://input"));
|
||||
foreach ($arr as $value) {
|
||||
query("DELETE FROM `for_stallman` WHERE `id` = " . $conn->real_escape_string($value) . ";");
|
||||
}
|
||||
break;
|
||||
echo(json_encode($arr));
|
||||
break;
|
||||
|
||||
default:
|
||||
die("Loading React...");
|
||||
case "deletemodmessages":
|
||||
$arr = json_decode(file_get_contents("php://input"));
|
||||
foreach ($arr as $value) {
|
||||
query("DELETE FROM `for_moderation` WHERE `id` = " . $conn->real_escape_string($value) . ";");
|
||||
}
|
||||
break;
|
||||
|
||||
case "deletestallmanmessages":
|
||||
$arr = json_decode(file_get_contents("php://input"));
|
||||
foreach ($arr as $value) {
|
||||
query("DELETE FROM `for_stallman` WHERE `id` = " . $conn->real_escape_string($value) . ";");
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
die("Loading React...");
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
|
32
counter.php
Normal file
32
counter.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
include "api.php";
|
||||
|
||||
if(isset($_GET["increment"])) {
|
||||
query("UPDATE counter SET value = value + 1;");
|
||||
header("Location: /counter.php");
|
||||
die();
|
||||
}
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Vkládání otázek</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Počítadlo</h1>
|
||||
<h2>
|
||||
Je tu
|
||||
<?php
|
||||
query("SELECT * FROM counter", function($row) {
|
||||
echo($row["value"]);
|
||||
})
|
||||
?>
|
||||
lidí!
|
||||
</h2>
|
||||
<form action="/counter.php" method="get">
|
||||
<input type="hidden" name="increment" value="dick">
|
||||
<input type="submit" value="Přišel další!">
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
|
139
index.php
Normal file
139
index.php
Normal file
@@ -0,0 +1,139 @@
|
||||
<?php
|
||||
include "api.php";
|
||||
|
||||
$found = false;
|
||||
|
||||
foreach($_GET as $key => $value) {
|
||||
$found = true;
|
||||
|
||||
if($key == "unselectmessage" || $key == "selectmessage") {
|
||||
query("UPDATE `for_stallman` SET `selected` = false");
|
||||
}
|
||||
|
||||
if($key == "selectmessage") {
|
||||
query("UPDATE `for_stallman` SET `selected` = true WHERE `id` = " . $conn->real_escape_string($value) . ";");
|
||||
}
|
||||
|
||||
if($key == "deletemessage") {
|
||||
query("DELETE FROM `for_stallman` WHERE `id` = " . $conn->real_escape_string($value) . ";");
|
||||
}
|
||||
}
|
||||
|
||||
if($found) {
|
||||
header("Location: /index.php");
|
||||
die();
|
||||
}
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Audience questions</title>
|
||||
<style>
|
||||
table {
|
||||
border-collapse: collapse;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
tr {
|
||||
border-bottom: 1px solid black;
|
||||
border-top: 1px solid black;
|
||||
}
|
||||
|
||||
td:first-child {
|
||||
padding-left: 8px;
|
||||
}
|
||||
|
||||
td {
|
||||
width: 1px;
|
||||
white-space: nowrap;
|
||||
padding: 8px 0;
|
||||
}
|
||||
|
||||
td:last-child {
|
||||
width: 100%;
|
||||
padding-right: 8px;
|
||||
}
|
||||
|
||||
input[type="submit"] {
|
||||
margin-right: 8px;
|
||||
}
|
||||
|
||||
label {
|
||||
padding-right: 16px;
|
||||
padding-left: 4px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<?php
|
||||
query("SELECT COUNT(`id`) as `count` FROM `for_stallman`;", function($row) {
|
||||
if($row["count"] <= 0) {
|
||||
echo "<meta http-equiv=\"refresh\" content=\"3\">";
|
||||
}
|
||||
});
|
||||
|
||||
?>
|
||||
<h1>Audience questions</h1>
|
||||
<p>
|
||||
<a href="/index.php">Load new questions</a>
|
||||
</p>
|
||||
<table>
|
||||
<?php
|
||||
$found = false;
|
||||
|
||||
query("SELECT `id`, `text`, `selected` FROM `for_stallman`;", function($row) {
|
||||
global $found;
|
||||
$found = true;
|
||||
|
||||
if(!$row["selected"]) {
|
||||
echo '
|
||||
<tr>
|
||||
<td>
|
||||
<form action="/index.php" method="get">
|
||||
<input type="hidden" name="selectmessage" value="' . $row["id"] . '">
|
||||
<input type="submit" value="Select">
|
||||
</form>
|
||||
</td>
|
||||
<td></td>
|
||||
<td>
|
||||
' . htmlspecialchars($row["text"]) . '
|
||||
</td>
|
||||
</tr>
|
||||
';
|
||||
} else {
|
||||
echo '
|
||||
<tr style="background-color: #EDF;">
|
||||
<td>
|
||||
<form action="/index.php" method="get">
|
||||
<input type="hidden" name="unselectmessage" value="' . $row["id"] . '">
|
||||
<input type="submit" value="Deselect">
|
||||
</form>
|
||||
</td>
|
||||
<td>
|
||||
<form action="/index.php" method="get">
|
||||
<input type="hidden" name="deletemessage" value="' . $row["id"] . '">
|
||||
<input type="submit" value="Delete" style="color: darkred;">
|
||||
</form>
|
||||
</td>
|
||||
<td>
|
||||
' . htmlspecialchars($row["text"]) . '
|
||||
</td>
|
||||
</tr>
|
||||
';
|
||||
}
|
||||
});
|
||||
|
||||
if(!$found) {
|
||||
echo '
|
||||
<tr>
|
||||
<td>
|
||||
No questions found.
|
||||
</td>
|
||||
</tr>';
|
||||
}
|
||||
?>
|
||||
</table><br>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
23
insertion.php
Normal file
23
insertion.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
if(isset($_GET["message"])) {
|
||||
include "api.php";
|
||||
query("INSERT INTO `for_stallman`(`text`, `selected`) VALUES (\"" . $conn->real_escape_string($_GET["message"]) . "\", false);");
|
||||
header("Location: /insertion.php");
|
||||
die();
|
||||
}
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Vkládání otázek</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Vkládání otázek na moderaci pro pana Stallmana</h1>
|
||||
<form action="/insertion.php" method="get">
|
||||
<label for="message">Obsah otázky:</label><br>
|
||||
<textarea id="message" name="message" rows=8 cols=80></textarea><br><br>
|
||||
<input type="submit" value="Odeslat!">
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
|
123
moderation.php
Normal file
123
moderation.php
Normal file
@@ -0,0 +1,123 @@
|
||||
<?php
|
||||
include "api.php";
|
||||
|
||||
$found = false;
|
||||
|
||||
foreach($_GET as $key => $value) {
|
||||
$found = true;
|
||||
if(gettype($key) != "integer") continue;
|
||||
|
||||
if($value == "del") {
|
||||
query("DELETE FROM `for_moderation` WHERE `id` = " . $key . ";");
|
||||
}
|
||||
|
||||
if($value == "ok" && isset($_GET[(string)$key . "message"])) {
|
||||
$message = $_GET[(string)$key . "message"];
|
||||
query("INSERT INTO `for_stallman`(`text`, `selected`) VALUES (\"" . $conn->real_escape_string($message) . "\", false);");
|
||||
query("DELETE FROM `for_moderation` WHERE `id` = " . $key . ";");
|
||||
}
|
||||
}
|
||||
|
||||
if($found) {
|
||||
header("Location: /moderation.php");
|
||||
die();
|
||||
}
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Moderace otázek</title>
|
||||
<style>
|
||||
table {
|
||||
border-collapse: collapse;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
tr {
|
||||
border-bottom: 1px solid black;
|
||||
border-top: 1px solid black;
|
||||
}
|
||||
|
||||
td {
|
||||
width: 1px;
|
||||
white-space: nowrap;
|
||||
padding: 8px 0;
|
||||
}
|
||||
|
||||
td:first-child {
|
||||
padding-left: 8px;
|
||||
}
|
||||
|
||||
td:last-child {
|
||||
width: 100%;
|
||||
padding-right: 8px;
|
||||
}
|
||||
|
||||
input[type="radio"] {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
label {
|
||||
padding-right: 16px;
|
||||
padding-left: 4px;
|
||||
}
|
||||
</style>
|
||||
<?php
|
||||
query("SELECT COUNT(`id`) as `count` FROM `for_moderation`;", function($row) {
|
||||
if($row["count"] <= 0) {
|
||||
echo "<meta http-equiv=\"refresh\" content=\"3\">";
|
||||
}
|
||||
});
|
||||
?>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Moderace otázek pro pana Stallmana</h1>
|
||||
<p>
|
||||
<a href="/moderation.php">Načíst nové otázky</a>
|
||||
</p>
|
||||
<p>- = zatím nechat otázku (beze změn) ve frontě moderátora, ✅ = odeslat otázku panu Stallmanovi (s případnými změnami), ❌ = odstranit otázku</p>
|
||||
<form action="/moderation.php" method="get">
|
||||
<table>
|
||||
<?php
|
||||
$found = false;
|
||||
|
||||
query("SELECT `id`, `text` FROM `for_moderation`;", function($row) {
|
||||
global $found;
|
||||
$found = true;
|
||||
|
||||
echo '
|
||||
<tr>
|
||||
<td>
|
||||
<input type="radio" id="' . $row["id"] . 'nothing" name="' . $row["id"] . '" value="nothing" checked>
|
||||
<label for="' . $row["id"] . 'nothing">-</label>
|
||||
</td>
|
||||
<td>
|
||||
<input type="radio" id="' . $row["id"] . 'ok" name="' . $row["id"] . '" value="ok">
|
||||
<label for="' . $row["id"] . 'ok">✅</label>
|
||||
</td>
|
||||
<td>
|
||||
<input type="radio" id="' . $row["id"] . 'del" name="' . $row["id"] . '" value="del">
|
||||
<label for="' . $row["id"] . 'del">❌</label>
|
||||
</td>
|
||||
<td>
|
||||
<textarea name="' . $row["id"] . 'message" style="width: 100%">' . htmlspecialchars($row["text"]) . '</textarea>
|
||||
</td>
|
||||
</tr>
|
||||
';
|
||||
});
|
||||
|
||||
if(!$found) {
|
||||
echo '
|
||||
<tr>
|
||||
<td>
|
||||
Žádné otázky nenalezeny.
|
||||
</td>
|
||||
</tr>';
|
||||
}
|
||||
?>
|
||||
</table><br>
|
||||
<input type="submit" value="Odeslat!">
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
|
Reference in New Issue
Block a user