<?php
require_once('../classes/body.class.php');
require_once('../classes/db.class.php');
require_once('../classes/system.class.php');
$title= new Body;
$title->SetTitle('Темы на форуме ');
///Подключаем шапку
$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 class="active" typeof="v:Breadcrumb"><span property="v:title">Мои темы</span></li></ol></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">';

$id = isset($_GET['id']) ? abs((int)$_GET['id']) : false;
if (!user_inf($id)) {
header('location: /');
die();
}
echo '<div class="catSides"><i class="md-format-list-bulleted"></i> Темы '.Nick($id).' на форуме</div>';
$look = DB::$dbs -> querySingle("SELECT COUNT(id) FROM forum_topic WHERE user_id = ?", [$id]);
$num = 10;
$k_page = k_page($look, $num);
$page = page($k_page);
$start = $num*$page-$num;
$sql = DB::$dbs->query("SELECT * FROM forum_topic WHERE user_id = ? ORDER BY time DESC LIMIT $start,$num", [$id]);
if ($sql -> rowCount() == 0) {
err('Тем ещё нет!');
} else {
while($a = $sql->fetch()) {
$rid = DB::$dbs->queryFetch("SELECT name,id FROM forum_razdel WHERE id = ? LIMIT 1", [$a['rid']]);
$prid = DB::$dbs->queryFetch("SELECT name,id FROM forum_prazdel WHERE id = ? LIMIT 1", [$a['prid']]);
$us_mess = DB::$dbs->queryFetch("SELECT user_id,tid FROM forum_mess WHERE tid = ? ORDER BY time DESC", [$a['id']]);
$k_mess = DB::$dbs->querySingle("SELECT COUNT(id) FROM forum_mess WHERE tid = ?", array($a['id']));
if ($k_mess > 10) {
$pg = ceil($k_mess / 10);
$st = ' <a href="/forum/thema'.$a['id'].'?page='.$pg.'">>></a>';
} else {
$st = '';
}
echo '<div class="row"><div class="col-xs-3 col-sm-1"><div class="user_brief"><a href="/forum/viewrazd.php?id='.$rid['id'].'"><i class="md-book"></i> '.$rid['name'].'</a> > <a href="/forum/viewthem.php?id='.$prid['id'].'">'.$prid['name'].'</a></br> <a href="/forum/thema'.$a['id'].'"><i class="md-forum"></i>  '.$a['name'].'</a> ['.$k_mess.'] ('.Nick($us_mess['user_id']).') '.$st.'</a></div></div></div>';
}
}
if ($k_page>1) {
str('?id='.$id.'&', $k_page,$page);
} 
///Подключаем меню
$title->GetMenu();


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