<?php
defined('DCMS') or die;
global $cache;

global $cache,$user,$dcms;

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 (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);
}

$users = mysql_result(mysql_query("SELECT COUNT(*) FROM `users_online` WHERE `request` LIKE '/forum/%'"),0);

echo "<img src='/sys/images/icons/forum.png' alt='' /> <a href='/forum/'>Форум</a>";
if ($new_posts)
echo "<span style='font-size:xx-small'> <a href='/forum/last.posts.php'>+ $new_posts</a></span>";
if ($new_themes)
echo "<span style='font-size:xx-small'> / <a href='/forum/last.themes.php'>++ $new_themes</a></span>";
if ($users)
echo "<br /><span style='font-size:xx-small'>$users ".misc::number($users,'человек','человека','человек')."</span>";


?>
