Files
peehaitchpea/index.php

140 lines
2.5 KiB
PHP

<?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: red;">
</form>
</td>
<td>
' . htmlspecialchars($row["text"]) . '
</td>
</tr>
';
}
});
if(!$found) {
echo '
<tr>
<td>
No questions found.
</td>
</tr>';
}
?>
</table><br>
</body>
</html>