1 <?php 2 require_once __DIR__ . '/../includes/bootstrap.php'; 3 must_admin(); 4 $PAGE_TITLE = 'Topics'; 5 $ADMIN_PAGE = 'topics'; 6 $q = get('q'); 7 $page = max(1,(int)get('page','1')); 8 $pp = 30; $off = ($page-1)*$pp; 9 $like = '%'.$q.'%'; 10 $where = $q ? "WHERE t.title LIKE ?" : ""; 11 $params = $q ? [$like] : []; 12 $topics = DB::rows("SELECT t.*,u.username,c.name AS cat FROM topics t JOIN users u ON u.id=t.user_id JOIN categories c ON c.id=t.category_id $where ORDER BY t.created_at DESC LIMIT $pp OFFSET $off", $params); 13 $total = (int)DB::val("SELECT COUNT(*) FROM topics t $where", $params); 14 $pages = max(1,(int)ceil($total/$pp)); 15 include __DIR__ . '/../views/partials/admin_layout.php'; 16 ?> 17 <div class="admin-toolbar"> 18 <form method="GET" class="at-form"> 19 <input type="text" name="q" value="<?= e($q) ?>" placeholder="Search topicsβ¦" class="fi at-fi"> 20 <button type="submit" class="btn-primary">Search</button> 21 <?php if ($q): ?><a href="<?= u('admin/topics.php') ?>" class="btn-ghost">Clear</a><?php endif; ?> 22 </form> 23 </div> 24 <div class="acard"> 25 <table class="atable"> 26 <thead><tr><th>Title</th><th>Category</th><th>By</th><th>Status</th><th>Actions</th></tr></thead> 27 <tbody> 28 <?php foreach ($topics as $t): ?> 29 <tr> 30 <td><a href="<?= u('forum/topic.php?slug='.urlencode($t['slug'])) ?>" target="_blank"><?= e(mb_substr($t['title'],0,50)) ?></a></td> 31 <td><?= e($t['cat']) ?></td> 32 <td>@<?= e($t['username']) ?></td> 33 <td><?= $t['pinned']?'π':'' ?><?= $t['closed']?'π':'' ?><?= $t['archived']?'π¦':'' ?><?= (!$t['pinned']&&!$t['closed']&&!$t['archived'])?'Active':'' ?></td> 34 <td> 35 <?php foreach ([['pin','unpin','π'],['close','open','π'],['archive','unarchive','π¦']] as [$a,$b,$icon]): ?> 36 <form method="POST" action="<?= u('api/topic_action.php') ?>" style="display:inline"> 37 <?= csrf_input() ?><input type="hidden" name="id" value="<?= $t['id'] ?>"> 38 <input type="hidden" name="action" value="<?= $t[$a==='pin'?'pinned':($a==='close'?'closed':'archived')] ? $b : $a ?>"> 39 <button class="btn-ghost btn-sm" title="<?= $a ?>"><?= $icon ?></button> 40 </form> 41 <?php endforeach; ?> 42 </td> 43 </tr> 44 <?php endforeach; ?> 45 <?php if (!$topics): ?><tr><td colspan="5" style="text-align:center;color:#6b7280;padding:2rem">No topics.</td></tr><?php endif; ?> 46 </tbody> 47 </table> 48 </div> 49 <?php if ($pages>1): ?> 50 <nav class="pager"> 51 <?php for($i=1;$i<=$pages;$i++): ?> 52 <a href="?page=<?= $i ?>&q=<?= urlencode($q) ?>" class="pg-btn <?= $i===$page?'active':'' ?>"><?= $i ?></a> 53 <?php endfor; ?> 54 </nav> 55 <?php endif; ?> 56 <?php include __DIR__ . '/../views/partials/admin_layout_end.php'; ?>