72 lines
2.3 KiB
PHP
72 lines
2.3 KiB
PHP
<?php
|
|
require_once 'templates/header.php';
|
|
|
|
if (!isset($_SESSION['user_id'])) {
|
|
header('Location: login.php');
|
|
exit();
|
|
}
|
|
|
|
require_once 'db/config.php';
|
|
|
|
$forum_id = $_GET['id'] ?? null;
|
|
if (!$forum_id) {
|
|
header('Location: forums.php');
|
|
exit();
|
|
}
|
|
|
|
$pdo = db();
|
|
|
|
// Fetch forum details
|
|
$stmt = $pdo->prepare('SELECT * FROM discussion_forums WHERE id = ?');
|
|
$stmt->execute([$forum_id]);
|
|
$forum = $stmt->fetch();
|
|
|
|
if (!$forum) {
|
|
header('Location: forums.php');
|
|
exit();
|
|
}
|
|
|
|
// Fetch threads in this forum
|
|
$stmt = $pdo->prepare(
|
|
'SELECT t.*, u.username FROM discussion_threads t JOIN users u ON t.user_id = u.id WHERE t.forum_id = ? ORDER BY t.created_at DESC'
|
|
);
|
|
$stmt->execute([$forum_id]);
|
|
$threads = $stmt->fetchAll();
|
|
|
|
?>
|
|
|
|
<div class="container">
|
|
<h1 class="text-center mb-2"><?php echo htmlspecialchars($forum['title']); ?></h1>
|
|
<p class="text-center text-muted mb-4"><?php echo htmlspecialchars($forum['description']); ?></p>
|
|
|
|
<div class="card mb-4">
|
|
<div class="card-body">
|
|
<h5 class="card-title">Create a New Thread</h5>
|
|
<form action="auth.php?action=create_thread" method="POST">
|
|
<input type="hidden" name="forum_id" value="<?php echo $forum_id; ?>">
|
|
<div class="form-group">
|
|
<label for="thread_title">Title</label>
|
|
<input type="text" class="form-control" id="thread_title" name="title" required>
|
|
</div>
|
|
<button type="submit" class="btn btn-primary mt-2">Post Thread</button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
<h3 class="mb-3">Threads</h3>
|
|
<div class="list-group">
|
|
<?php if (empty($threads)): ?>
|
|
<div class="alert alert-info">No threads in this forum yet. Be the first to post!</div>
|
|
<?php else: ?>
|
|
<?php foreach ($threads as $thread): ?>
|
|
<a href="thread.php?id=<?php echo $thread['id']; ?>" class="list-group-item list-group-item-action">
|
|
<h5 class="mb-1"><?php echo htmlspecialchars($thread['title']); ?></h5>
|
|
<small>By <?php echo htmlspecialchars($thread['username']); ?> on <?php echo date('M j, Y', strtotime($thread['created_at'])); ?></small>
|
|
</a>
|
|
<?php endforeach; ?>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
|
|
<?php require_once 'templates/footer.php'; ?>
|