summaryrefslogtreecommitdiff
path: root/moderate.php
blob: 21951f6e80cf61ed51e5a5721cfa402274c22ee8 (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
69
70
71
72
73
74
75
76
77
<?php
include_once './includes/model/Thread.php';
include_once './includes/Session.php';
include_once './includes/model/User.php';

$type = filter_input(INPUT_GET, "type", FILTER_SANITIZE_STRING);
$id = filter_input(INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT);

$post = null;
$thread = null;
$is_post = strcasecmp($type, "post") == 0;
$is_thread = strcasecmp($type, "thread") == 0;

if ($is_post) $post = new Post($id);
if ($is_thread) $thread = new Thread($id);

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
	$type = filter_input(INPUT_POST, "type", FILTER_SANITIZE_STRING);
	$id = filter_input(INPUT_POST, 'id', FILTER_SANITIZE_NUMBER_INT);
	$action = filter_input(INPUT_POST, 'action', FILTER_SANITIZE_STRING);

	$user = Session::get()->get_current_user();

	if (Session::get()->is_signed_in() and $user->level == USER_LEVEL_MODERATOR) {
		// Set the value of these again with the variables from the POST request
		$is_post = strcasecmp($type, "post") == 0;
		$is_thread = strcasecmp($type, "thread") == 0;

		if (strcasecmp($type, "thread") == 0) {
			$thread = new Thread($id);
			if (strcasecmp($action, "delete") == 0) Thread::delete($thread);
		} else if (strcasecmp($type, "post") == 0) {
			$post = new Post($id);
			if (strcasecmp($action, "delete") == 0) $post->delete();
		}
	}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
	<title>cflip.net forum Moderation</title>
<?php include_once 'includes/templates/head.php'; ?>
</head>
<body>
<?php include_once 'includes/templates/header.php'; ?>
<?php if (Session::get()->is_signed_in() and Session::get()->get_current_user()->level == USER_LEVEL_MODERATOR): ?>
<?php if ($is_post): ?>
	<h2>Moderate post</h2>
<?php echo $post->get_content(); ?>
	<form action="moderate.php" method="post">
		<input type="hidden" name="id" value="<?= $post->id ?>">
		<input type="hidden" name="type" value="post">
		<select name="action">
			<option value="delete">Delete</option>
		</select>
		<input type="submit">
	</form>
<?php elseif ($is_thread): ?>
	<h2>Moderate thread</h2>
	<p><?= $thread->subject ?></p>
	<form action="moderate.php" method="post">
		<input type="hidden" name="type" value="thread">
		<label for="id">ID: </label>
		<input type="number" name="id" value="<?= $thread->id ?>" readonly>
		<label for="action">Action: </label>
		<select name="action">
			<option value="delete">Delete</option>
		</select>
		<input type="submit">
	</form>
<?php endif ?>
<?php else: ?>
	<section class="error">You must be signed in as a moderator to access this page.</section>
<?php endif ?>
</body>
</html>