<?php
include_once '../sys/inc/start.php';
$doc = new document();
$doc->title = 'Форум - Категории';



$posts = array();

$posts[]=array('icon'=>array('size'=>'small','src'=>'/sys/images/icons/forum.search.png'), 'title'=> '<a href="search.php">Поиск</a>');


if (false ===($new_themes = $cache -> get('forum.new_themes.'.$user->group)))
{
$new_themes = mysql_result(mysql_query("SELECT COUNT(*)
FROM `forum_themes` AS `th`
LEFT JOIN `forum_topics` AS `tp` ON `tp`.`id` = `th`.`id_topic`
LEFT JOIN `forum_categories` AS `cat` ON `cat`.`id` = `th`.`id_category`
WHERE `th`.`group_show` <= '{$user -> group}'
AND `tp`.`group_show` <= '{$user -> group}'
AND `cat`.`group_show` <= '{$user -> group}'
AND `th`.`time_create` > '".DAY_TIME."'"),0);
$cache -> set('forum.new_themes.'.$user->group,$new_themes,60);
}
if ($new_themes)$posts[]=array('icon'=>array('size'=>'small','src'=>'/sys/images/icons/forum.lt.png'), 'title'=>'<a href="last.themes.php">Новые темы</a> +'.$new_themes);


if (false ===($new_posts = $cache -> get('forum.new_posts.'.$user->group)))
{
$new_posts = mysql_result(mysql_query("SELECT COUNT(DISTINCT(`msg`.`id_theme`))
FROM `forum_messages` AS `msg`
LEFT JOIN `forum_themes` AS `th` ON `th`.`id` = `msg`.`id_theme`
LEFT JOIN `forum_topics` AS `tp` ON `tp`.`id` = `th`.`id_topic`
LEFT JOIN `forum_categories` AS `cat` ON `cat`.`id` = `th`.`id_category`
WHERE `th`.`group_show` <= '{$user -> group}'
AND `tp`.`group_show` <= '{$user -> group}'
AND `cat`.`group_show` <= '{$user -> group}'
AND `msg`.`group_show` <= '{$user -> group}'
AND `msg`.`time` > '".DAY_TIME."'"),0);
$cache -> set('forum.new_posts.'.$user->group,$new_posts,60);
}
if ($new_posts)$posts[]=array('icon'=>array('size'=>'small','src'=>'/sys/images/icons/forum.lp.png'), 'title'=>'<a href="last.posts.php">Обновленные темы</a> +'.$new_posts);



$pages = new pages();
$pages->posts = mysql_result(mysql_query("SELECT COUNT(*) FROM `forum_categories` WHERE `group_show` <= '$user->group'"), 0); // количество категорий форума
$pages->this_page(); // получаем текущую страницу


$q = mysql_query("SELECT * FROM `forum_categories` WHERE `group_show` <= '$user->group' ORDER BY `position` ASC LIMIT {$pages->my_start()}, {$pages->items_per_page}");
while ($category=mysql_fetch_assoc($q)) {
$i=array('size'=>'small','src'=>'/sys/images/icons/forum.category.png');
$t="<a href='category.php?id=$category[id]'>$category[name]</a>";
$p=text::for_opis($category['description']);
$posts[]=array('icon'=>$i,'title'=>$t,'post'=>$p);
}

if (!$posts)$posts[]=array('icon'=>array('size'=>'small','src'=>'/sys/images/icons/empty.png'),'title'=>'Доступных Вам категорий нет');

$show = new design();
$show->assign('post',$posts);
$show->display('design.listing.tpl');

$pages->listing('?'); // вывод страниц

if ($user->group >= 5)$doc->act('Создать категорию','category.new.php');


?>