<?php
require_once('../classes/body.class.php');
require_once('../classes/db.class.php');
require_once('../classes/system.class.php');
$title= new Body;

$id = isset($_GET['id']) ? abs((int)$_GET['id']) : false;
$array = DB::$dbs->query("SELECT * FROM forum_topic WHERE id = ? LIMIT 1", [$id]);
if ($array -> rowCount() == 0) {
header('location: /');
die();
}
$arr = $array -> fetch();
$raz = DB::$dbs->queryFetch("SELECT * FROM forum_razdel WHERE id = ? LIMIT 1", [$arr['rid']]);
$praz = DB::$dbs->queryFetch("SELECT * FROM forum_prazdel WHERE id = ? LIMIT 1", [$arr['prid']]);
$in = DB::$dbs->querySingle("SELECT COUNT(id) FROM forum_inthem WHERE tid = ?", [$id]);
$title->SetTitle('Форум - Тему '.$arr['name'].' посетили '.$in.' человек');

///Подключаем шапку
$title->GetHeader();
echo '<div class="container-fluid page_header"><div class="container"><div class="row"><div class="col-xs-12 col-sm-8 col-md-9 col-lg-9"><h1>Форум - Посетители темы </h1><ol class="breadcrumb" xmlns:v="http://'.homeurl.'/#"><li typeof="v:Breadcrumb"><a href="/" rel="v:url" property="v:title">'.homeurl.'</a></li><li typeof="v:Breadcrumb"><a href="/forum" rel="v:url" property="v:title">Форум</a></li>
<li typeof="v:Breadcrumb"><a href="viewrazd.php?id='.$raz['id'].'" rel="v:url" property="v:title">'.$raz['name'].'</a></li>
<li typeof="v:Breadcrumb"><a href="viewthem.php?id='.$praz['id'].'" rel="v:url" property="v:title">'.$praz['name'].'</a></li>
<li typeof="v:Breadcrumb"><a href="viewtopic.php?id='.$arr['id'].'" rel="v:url" property="v:title">'.$arr['name'].'</a></li>
<li class="active" typeof="v:Breadcrumb"><span property="v:title">Тему "'.$arr['name'].'" посетили '.$in.' человек</span></li></ol></div><div class="col-xs-12 col-sm-4 col-md-3 col-lg-3 text-right page_header_sidebar"></div></div></div></div>';
echo'<div class="container page_body"><div class="row"><div class="col-xs-12 page_content col-lg-9"><div class="navbar page_content_navbar collapse hidden-lg"><div class="container-fluid"><div class="navbar-collapse"></div></div></div><div class="text_box hidden-lg pr_block_small hidden"></div><div class="container-fluid cols_table">';


echo '<div class="catSides"><i class="md-format-list-bulleted"></i> Тему "'.$arr['name'].'" посетили '.$in.' человек</div>';
$mess = DB::$dbs->querySingle("SELECT COUNT(id) FROM forum_mess WHERE tid = ?", array($arr['id']));
if ($mess > 10) {
$pg = ceil($mess / 10);
$st = 'page='.$pg;
} else {
$st = '';
}

$look = DB::$dbs->querySingle("SELECT COUNT(id) FROM forum_inthem WHERE tid = ?", [$id]);
$num = 10;
$k_page = k_page($look, $num);
$page = page($k_page);
$start = $num*$page-$num;
$sql = DB::$dbs->query("SELECT * FROM forum_inthem WHERE tid = ? ORDER BY time DESC LIMIT $start,$num", [$id]);
if ($sql -> rowCount() == 0) {
err('Данную тему никто не посещал!');
} else {
while($a = $sql->fetch()) {
echo '<div class="row"><div class="col-xs-3 col-sm-1"><div class="user_brief">'.Nick($a['user_id']).' ('.vr($a['time']).')</div></div></div>';
}
}
if ($k_page>1) {
str('?do=inthem&id='.$id.'&', $k_page, $page);
}
echo '<div class="mainc"><a href="/forum/thema'.$arr['id'].'?'.$st.'"><i class="md-apps"></i> Вернуться в тему</a></div>';
echo'<div class="catSides"><i class="md-format-list-bulleted"></i> <a href="/rules">Правила</a> | <a href="/bbcodes"> Справка BBcode</a> | <a href="/smiles">Все смайлы</a> | <a href="search">Поиск</a> | <a href="wholly_new">Найти новые</a></div>'; 

///Подключаем меню
$title->GetMenu();


///Подключаем футер
$title->GetFooter();
?>