summaryrefslogtreecommitdiff
path: root/moderate.php
blob: afeefa19846422cc80e2d992f881bea148af2ad2 (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
<?php

include_once 'includes/db_inc.php';
include_once 'model/User.php';

session_start();

function delete_thread($dbc, $thread_id) {
	$sql = "DELETE FROM threads WHERE thread_id = $thread_id;";
	mysqli_query($dbc, $sql);
}

if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_SESSION['signed_in'])) {
	$thread_id = filter_input(INPUT_POST, 'id', FILTER_SANITIZE_NUMBER_INT);
	$delete = filter_input(INPUT_POST, "delete", FILTER_SANITIZE_STRING);
	
	$user = new User();
	$user->get_by_id($_SESSION['user_id'], $dbc);

	if ($user->level > 0) {
		if (strcasecmp($delete, "on") == 0) {
			delete_thread($dbc, $thread_id);

			header("Location: /");
			exit();
		}
	}

	header("Location: viewthread.php?id=$thread_id");
	exit();
}

header("Location: /");