require '../../structure/database.php';
require '../../structure/forum.php';
require '../../structure/forum.thread.php';
require '../../structure/base.php';
require '../../structure/user.php';
$database = new database($db_host, $db_name, $db_user, $db_password);
$thread = new thread($database);
$base = new base($database);
$user = new user($database);
$user->updateLastActive();
//useful variables
$username = $user->getUsername($_COOKIE['user'], 2);
$rank = $user->getRank($username);
$id = $_GET['id'];
//take action then log it
if ($thread->checkExistence($id) && $thread->canView($id, $username, $rank) && $rank > 2) {
    $thread_info = $database->processQuery("SELECT `autohiding` FROM `threads` WHERE `id` = ?", array($id), true);
    $database->processQuery("UPDATE `threads` SET `autohiding` = ? WHERE `id` = ?", array($thread_info[0]['autohiding'] == 1 ? 0 : 1, $id), false);
    $base->appendToFile('../logs.txt', array($username . ' toggled the auto-hide of the thread ' . $id));
} else {
    $base->redirect('../viewthread.php?forum=' . $_GET['forum'] . '&id=' . $id . '&goto=start');
}
$redirect = 'http://' . $domain . '/forums/viewthread.php?forum=' . $_GET['forum'] . '&id=' . $id . '&goto=start';
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns:IE>

<!-- LeeStrong Runescape Website Source --!>
<!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=ISO-8859-1"><!-- /Added by HTTrack -->
<head>
<meta http-equiv="Pragma" content="no-cache">
$base = new base($database);
$user = new user($database);
$forum = new forum($database);
$forum_index = new forum_index($database);
$thread = new thread($database);
$post = new post($database);
$user->updateLastActive();
//get config
$config = $base->loadConfig();
//set some variables that are used a lot throughout the page
$username = $user->getUsername($_COOKIE['user'], 2);
$rank = $user->getRank($username);
$f = $_GET['forum'];
$i = $_GET['id'];
//preform basic checks
if (!ctype_digit($f) || !ctype_digit($i) || !$thread->checkExistence($i) || !$thread->canView($i, $username, $rank)) {
    $base->redirect('index.php');
}
//if the GOTO field is set, let's skip to the selected post
if (ctype_digit($_GET['goto'])) {
    $getPageNum = $thread->getPageNum($_GET['goto'], $i);
    if ($getPageNum) {
        $base->redirect('viewthread.php?forum=' . $f . '&id=' . $i . '&page=' . $getPageNum . '&highlight=' . $_GET['goto'] . '#' . $_GET['goto']);
    }
}
//extract thread details
$detail_query = $database->processQuery("SELECT `id`,`lock`,`sticky`,`title`,`username`,`status`,`content`,`date`,`lastedit`,`qfc`,`moved`,`hidden`,`autohiding` FROM `threads` WHERE `id` = ? LIMIT 1", array($i), true);
//assign data to details[] array
$details['lock'] = $detail_query[0]['lock'];
$details['sticky'] = $detail_query[0]['sticky'];
$details['title'] = stripslashes(htmlentities($detail_query[0]['title']));