summaryrefslogtreecommitdiff
path: root/thread.php
blob: 97ab6b94ceea4a460f2b869f1a99171b771f762f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php include_once 'header.php'; ?>

<?php
include_once 'includes/db_inc.php';
include_once 'includes/functions_display.php';

if (!isset($_GET['id']) || !filter_var($_GET['id'], FILTER_VALIDATE_INT)) {
	echo '<section>Unknown category.</section>';
} else {
	$sql = "SELECT thread_id, thread_subject, thread_date, user_id, user_name FROM threads LEFT JOIN users ON thread_author = user_id WHERE thread_id = " . mysqli_real_escape_string($dbc, $_GET['id']);
	$result = mysqli_query($dbc, $sql);

	if (!$result) {
		die('Error trying to display thread page: ' . mysqli_error($dbc));
	}

	if (mysqli_num_rows($result) == 0) {
		echo 'This thread does not exist';
	} else {
		while ($row = mysqli_fetch_assoc($result)) {
			echo '<section><h1>' . $row['thread_subject'] . '</h1>';
			echo 'Created by <a href="user.php?id='. $row['user_id'] .'">' . $row['user_name'] . '</a> on ' . date('M d, Y', strtotime($row['thread_date'])) . '</section>';
			$thread_id = $row['thread_id'];
		}
	}

	echo '</section>';

	mysqli_free_result($result);

	$sql = "SELECT post_id, post_content, post_date, post_author, user_id, user_name FROM posts LEFT JOIN users ON post_author = user_id WHERE post_thread = " . mysqli_real_escape_string($dbc, $_GET['id']);
	$result = mysqli_query($dbc, $sql);

	if (!$result) {
		die('Error trying to display posts: ' . mysqli_error($dbc));
	}

	if (mysqli_num_rows($result) == 0) {
		echo '<section>This thread has no posts</section>';
	} else {
		display_posts($dbc, $result);
	}

	mysqli_free_result($result);

	if (isset($_SESSION['signed_in'])) {
		echo '
		<section>
			<form action="includes/reply_inc.php?reply_to=' . $thread_id .'" method="post">
				<h2>Reply to this thread</h2>
				<i>Quote a post with ># and the number above the post (example: >#7)</i>
				<textarea name="reply_content"></textarea>
				<br>
				<input type="submit" name="submit">
			</form>
		</section>
		';
	} else {
		echo '
		<section>
			<a href="signin.php">Sign in</a> to reply to this thread</a>
		</section>
		';
	}
}

include_once 'footer.php';
?>