<?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="tile"><div class="t-header th-alt bg-teal"><div class="th-title"><i class="zmdi zmdi-widgets"></i><a href="/"style="text-decoration:none; color:white;"> Главная</a> :: Форум</div></div></div>';
echo'<div class="list-group-item media"><span class="label label-danger">Новые</span> <a href="newtheme.php">Темы</a> | <a href="newposts.php">Сообщения</a></br>';
if (isset($b)) {
echo'</br><span class="label label-danger">Мои</span> <a href="user_thems.php?id='.$b['id'].'">Темы</a> | <a href="user_posts.php?id='.$b['id'].'">Сообщения</a> | <a href="podpis.php">Наблюдаемые</a>';
}
echo'</div>';
echo'<div class="tile"><div class="t-header th-alt bg-teal"><div class="th-title"><i class="zmdi zmdi-widgets"></i><a href="/forum"style="text-decoration:none; color:white;"> Форум</a> :: Тему "'.$arr['name'].'" посетили '.$in.' человек</div></div></div>';
$mess = DB::$dbs->querySingle("SELECT COUNT(id) FROM forum_mess WHERE tid = ?", [$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="list-group-item media">'.Nick($a['user_id']).' ('.vr($a['time']).')</div>';
}
}
echo '<div class="list-group-item media"><a href="/forum/thema'.$arr['id'].'?'.$st.'"><i class="zmdi zmdi-apps"></i> Вернуться в тему</a></div>';
echo'<div class="tile"><div class="t-header th-alt bg-teal"><div class="th-title"><i class="zmdi zmdi-format-list-bulleted"></i>  <a href="/rules"style="text-decoration:none; color:white;">Правила</a> | <a href="/bbcodes"style="text-decoration:none; color:white;"> Справка BBcode</a> | <a href="/smiles"style="text-decoration:none; color:white;">Все смайлы</a> | <a href="search"style="text-decoration:none; color:white;">Поиск</a></div></div></div>'; 
if ($k_page>1) {
str('?do=inthem&id='.$id.'&', $k_page, $page);
}
$title->GetMenu();
$title->GetFooter();
?>