<?php
include_once '../sys/inc/start.php';
$doc = new document();
$doc->title='Новые темы сегодня';
$posts = array();
$pages = new pages;
$pages->posts = 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); 
$pages->this_page(); // получаем текущую страницу

$q = mysql_query("SELECT `th`.* , `tp`.`name` AS `topic_name`, `cat`.`name` AS `category_name`, COUNT(`msg`.`id`) AS `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`
LEFT JOIN `forum_messages` AS `msg` ON `msg`.`id_theme` = `th`.`id` AND `msg`.`group_show`  <= '{$user -> group}'
WHERE `th`.`group_show` <= '{$user -> group}'
AND `tp`.`group_show` <= '{$user -> group}'
AND `cat`.`group_show` <= '{$user -> group}'
AND `th`.`time_create` > '".DAY_TIME."'
GROUP BY `th`.`id`
ORDER BY `th`.`id` DESC LIMIT {$pages->my_start()}, {$pages->items_per_page}");

while ($themes=mysql_fetch_assoc($q)) {
$is_top=$themes['top'];
$is_open=(int)($themes['group_write']<=1);
$i=array('size'=>'small','src'=>"/sys/images/icons/forum.theme.$is_top.$is_open.png");
$t="<a href='theme.php?id={$themes['id']}'>$themes[name]</a> ($themes[count])";
if($themes['count']>$pages->items_per_page)$t.=" <a href='theme.php?id={$themes['id']}&amp;page=end'>&gt;&gt;</a>";
$autor=new user($themes['id_autor']);
$last_msg=new user($themes['id_last']);
$p=($autor->id!=$last_msg->id?$autor->nick.'/'.$last_msg->nick:$autor->nick).' ('.vremja($themes['time_last']).')<br />';
$p.="(<a href='category.php?id=$themes[id_category]'>$themes[category_name]</a> &gt; <a href='topic.php?id=$themes[id_topic]'>$themes[topic_name]</a>)";
$posts[]=array('title'=>$t,'icon'=>$i,'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('?'); // вывод страниц
$doc->ret('Форум','./');
?>