78 lines
2.4 KiB
PHP
78 lines
2.4 KiB
PHP
<?php
|
|
require_once 'templates/header.php';
|
|
|
|
if (!isset($_SESSION['user_id'])) {
|
|
header('Location: login.php');
|
|
exit();
|
|
}
|
|
|
|
require_once 'db/config.php';
|
|
|
|
$thread_id = $_GET['id'] ?? null;
|
|
if (!$thread_id) {
|
|
header('Location: forums.php');
|
|
exit();
|
|
}
|
|
|
|
$pdo = db();
|
|
|
|
// Fetch thread details
|
|
$stmt = $pdo->prepare('SELECT t.*, u.username FROM discussion_threads t JOIN users u ON t.user_id = u.id WHERE t.id = ?');
|
|
$stmt->execute([$thread_id]);
|
|
$thread = $stmt->fetch();
|
|
|
|
if (!$thread) {
|
|
header('Location: forums.php');
|
|
exit();
|
|
}
|
|
|
|
// Fetch posts in this thread
|
|
$stmt = $pdo->prepare(
|
|
'SELECT p.*, u.username FROM discussion_posts p JOIN users u ON p.user_id = u.id WHERE p.thread_id = ? ORDER BY p.created_at ASC'
|
|
);
|
|
$stmt->execute([$thread_id]);
|
|
$posts = $stmt->fetchAll();
|
|
|
|
?>
|
|
|
|
<div class="container">
|
|
<h1 class="mb-2"><?php echo htmlspecialchars($thread['title']); ?></h1>
|
|
<p class="text-muted">Started by <?php echo htmlspecialchars($thread['username']); ?> on <?php echo date('M j, Y', strtotime($thread['created_at'])); ?></p>
|
|
<hr>
|
|
|
|
<div id="posts-container">
|
|
<?php if (empty($posts)): ?>
|
|
<div class="alert alert-info">No replies yet.</div>
|
|
<?php else: ?>
|
|
<?php foreach ($posts as $post): ?>
|
|
<div class="card mb-3">
|
|
<div class="card-body">
|
|
<p class="card-text"><?php echo nl2br(htmlspecialchars($post['content'])); ?></p>
|
|
</div>
|
|
<div class="card-footer text-muted">
|
|
By <?php echo htmlspecialchars($post['username']); ?> on <?php echo date('M j, Y, g:i a', strtotime($post['created_at'])); ?>
|
|
</div>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
<?php endif; ?>
|
|
</div>
|
|
|
|
<hr>
|
|
|
|
<div class="card">
|
|
<div class="card-body">
|
|
<h5 class="card-title">Post a Reply</h5>
|
|
<form action="auth.php?action=create_post" method="POST">
|
|
<input type="hidden" name="thread_id" value="<?php echo $thread_id; ?>">
|
|
<div class="form-group">
|
|
<textarea class="form-control" id="post_content" name="content" rows="5" required></textarea>
|
|
</div>
|
|
<button type="submit" class="btn btn-primary mt-2">Submit Reply</button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<?php require_once 'templates/footer.php'; ?>
|