Files
peehaitchpea/moderation.php

124 lines
2.6 KiB
PHP

<?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>