summaryrefslogtreecommitdiff
path: root/search.php
blob: 0732129723cf7b856c99918c91c6c55e172eb838 (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
<?php session_start() ?>
<!DOCTYPE html>
<html lang="en">
<head>
    <title>Search - cflip.net forum</title>
    <link rel="stylesheet" href="styles/style.css">
</head>
<body>
<?php include_once './includes/templates/header.php'; ?>
<h2>Search cflip.net forum</h2>
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="get">
    <label for="type">Type:</label>
    <select id="type" name="type">
        <option value="thread">Thread</option>
        <option value="post">Post</option>
        <option value="user">User</option>
    </select>
    <label for="sort">Sort By:</label>
    <select id="sort" name="sort">
        <option value="lr">Last Reply</option>
        <option value="cd">Creation Date</option>
        <option value="rc">Reply Count</option>
    </select>
    <label for="text">With Name:</label>
    <input id="text" type="text" name="query">
    <input type="submit" value="Search!">
</form>
<hr>
<?php
include_once './includes/db_inc.php';
include_once './includes/model/Thread.php';
include_once './includes/model/Post.php';

if (!isset($_GET['type'])) {
	echo 'Specify a type to search.';
} else {
	switch ($_GET['type']) {
		case 'thread':
			$threads = get_all_threads($dbc);
			foreach ($threads as $thread) {
				echo '<p>';
				echo '<td><b><a href="viewthread.php?id=' . $thread->id . '">' . $thread->subject . '</a></b>';
				echo '<small> created 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>';
				echo '</p>';
			}
			break;
		case 'post':
			$posts = get_all_posts($dbc);

			foreach ($posts as $post) {
				echo '<h3>From <a href="viewthread.php?id=' . $post->thread->id . '">' . $post->thread->subject . '</a></h3>';
				$post->display_content($dbc);
				echo '<hr>';
			}
			break;
		case 'user':
			break;
		default:
			echo '<h3>Could not search: Invalid type!</h3>';
			break;
	}
}
?>
</body>
</html>