summaryrefslogtreecommitdiff
path: root/viewcategory.php
blob: 70733da5f0e5e8252ad1c1589f7f0060926e3f14 (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
<?php
include('includes/db_inc.php');
include('includes/model/Category.php');

session_start();

$current = new Category();

if (!isset($_GET['id']) || !filter_var($_GET['id'], FILTER_VALIDATE_INT)) {
	http_response_code(404);
	include('includes/templates/404.php');
	die();
} else {
	$result = $current->get_from_database($_GET['id'], $dbc);
	if ($result == 0) {
		http_response_code(404);
		include('includes/templates/404.php');
		die();
	}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <title><?= $current->name; ?> - cflip.net forum</title>
    <link rel="stylesheet" href="styles/style.css">
</head>
<body>
<?php include('includes/templates/header.php'); ?>
<h1><?= $current->name; ?></h1>
<p><?= $current->description; ?></p>
<span class="info"><?= $current->thread_count . ' threads, ' . $current->post_count . ' posts'; ?></span>
<h2>Threads</h2>
<table>
    <tr>
        <th>Thread Name</th>
        <th>Latest Post</th>
    </tr>
	<?php
	$threads = $current->get_threads($dbc);

	foreach ($threads as $thread) {
		$latest_post = $thread->get_latest_post($dbc);

		echo '<tr>';
		echo '<td><b><a href="viewthread.php?id=' . $thread->id . '">' . $thread->subject . '</a></b>';
		echo '<small> by <b><a href="viewuser.php?id=' . $thread->author->id . '">' . $thread->author->name . '</a></b> on ' . date('M d, Y', strtotime($thread->date_created)) . '</small></td>';

		if (!is_null($latest_post)) {
			echo '<td>by <b><a href="viewuser.php?id=' . $latest_post->author->id . '">' . $latest_post->author->name . '</a></b><small> on ' . $latest_post->date_created . '</small></td>';
		} else {
			echo '<td>No posts yet!</td>';
		}

		echo '</tr>';
	}
	?>
</table>
</body>
</html>