First git commit

This commit is contained in:
root
2026-09-08 18:21:10 +01:00
commit 66911dc450
65 changed files with 7012 additions and 0 deletions

View File

@ -0,0 +1,76 @@
<?php
// Admin: moderate topics -- lock/unlock, move between forums, delete.
require_once __DIR__ . '/../lib/bootstrap.php';
$me = require_admin();
$d = db();
$msg = ''; $err = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
require_csrf();
$act = $_POST['act'] ?? '';
$tid = (int)($_POST['tid'] ?? 0);
if ($tid) {
if ($act === 'lock') {
$d->prepare("UPDATE topics SET is_locked = 1 - is_locked WHERE id=?")->execute([$tid]);
$msg = 'Topic lock toggled.';
} elseif ($act === 'del') {
$d->prepare("DELETE FROM topics WHERE id=?")->execute([$tid]);
$msg = 'Topic deleted.';
} elseif ($act === 'move') {
$to = (int)($_POST['forum_id'] ?? 0);
$chk = $d->prepare("SELECT 1 FROM forums WHERE id=?");
$chk->execute([$to]);
if ($chk->fetchColumn()) {
$d->prepare("UPDATE topics SET forum_id=? WHERE id=?")->execute([$to, $tid]);
$msg = 'Topic moved.';
} else $err = 'Target forum does not exist.';
}
}
}
$forums = [];
foreach ($d->query("SELECT id,name FROM forums ORDER BY sort_order,id") as $f) {
$forums[(string)$f['id']] = $f['name'];
}
$page = max(1, (int)($_GET['p'] ?? 1));
$off = ($page - 1) * PER_PAGE;
$s = $d->prepare("SELECT t.*, u.username, f.name AS fname,
(SELECT COUNT(*) FROM posts p WHERE p.topic_id=t.id) pc
FROM topics t LEFT JOIN users u ON u.id=t.user_id
JOIN forums f ON f.id=t.forum_id
ORDER BY t.bumped_at DESC LIMIT ? OFFSET ?");
$s->execute([PER_PAGE + 1, $off]);
$rows = $s->fetchAll();
$more = count($rows) > PER_PAGE;
if ($more) array_pop($rows);
page_start('Admin: topics', ['back' => '/admin/index.php']);
if ($err) p_err($err);
if ($msg) p_ok($msg);
if (!$rows) p_para('No topics.');
foreach ($rows as $r) {
p_para('#' . $r['id'] . ' [' . $r['fname'] . '] ' . $r['title']
. ' - ' . ($r['username'] ?? '?') . ', ' . $r['pc'] . ' posts'
. ($r['is_locked'] ? ' [LOCKED]' : ''));
p_link('/topic.php', 'view', ['t' => $r['id']]);
p_form('/admin/topics.php', [
['name' => 'act', 'type' => 'hidden', 'value' => 'lock'],
['name' => 'tid', 'type' => 'hidden', 'value' => (string)$r['id']],
], $r['is_locked'] ? 'Unlock' : 'Lock');
p_form('/admin/topics.php', [
['name' => 'act', 'type' => 'hidden', 'value' => 'move'],
['name' => 'tid', 'type' => 'hidden', 'value' => (string)$r['id']],
['name' => 'forum_id', 'label' => 'Move to', 'type' => 'select',
'value' => (string)$r['forum_id'], 'options' => $forums],
], 'Move');
p_form('/admin/topics.php', [
['name' => 'act', 'type' => 'hidden', 'value' => 'del'],
['name' => 'tid', 'type' => 'hidden', 'value' => (string)$r['id']],
], 'DELETE');
p_rule();
}
p_pager('/admin/topics.php', $page, $more);
p_links([['/admin/index.php', 'Admin home']]);
page_end();