<?
/* Онлайн пользователи */

$k_post = mysql_result(mysql_query("SELECT COUNT(*) FROM `user` WHERE `date_last` > '".(time()-600)."'"), 0);
$q = mysql_query("SELECT `id` FROM `user` WHERE `date_last` > '".(time()-600)."' ORDER BY `rating` DESC LIMIT 10");
if ($k_post > 0)
{
	echo "<a href='/online.php'><div class='main'>";
	echo "Сейчас на сайте ($k_post) чел.</div></a>";

	echo "<div class='mess'>";
	echo '<table>';
	echo '<tr>';
	while ($ank = mysql_fetch_assoc($q))
	{
		$ank = get_user($ank['id']);

		echo '<td style="width:60px; height:70px; vertical-align:top; border:1px solid black; text-align:center; display:inline-table; margin:2px;">';

		echo avatar($ank['id']) . '<br />';
		echo "<b><a href='/info.php?id=$ank[id]'><small>$ank[nick]</small></a></b>";

		echo '</td>';
	}
	echo '</tr>';
	echo '</table>';
	echo '</div>';
}

/* Новости */
$k_post = mysql_result(mysql_query("SELECT COUNT(*) FROM `news`"),0);

$q = mysql_query("SELECT * FROM `news` ORDER BY `id` DESC LIMIT 2");

echo "<a href='/news'><div class='main'>";

echo "<img src='/style/icons/news.png' alt='*' /> Новости ";

include H.'news/count.php';

echo "</div></a>";

if ($k_post > 0)
{
	echo '<div class="mess">';
	echo '<table>';
	echo '<tr>';
	while ($post = mysql_fetch_assoc($q))
	{
		echo '<td style="width:350px; height:70px; vertical-align:top; display:inline-table; margin:2px;">';
		echo "<a href='/news/news.php?id=$post[id]'>" . text($post['title']) . "</a>\n";
		echo "(".vremja($post['time']).")<br />\n";
		echo output_text($post['msg']);
		if ($post['link']!=NULL)	
		echo "<br /><a href='".htmlentities($post['link'], ENT_QUOTES, 'UTF-8')."'>Подробности &rarr;</a><br />\n";
		echo "<img src='/style/icons/bbl4.png' alt='*' /> (".mysql_result(mysql_query("SELECT COUNT(*) FROM `news_komm` WHERE `id_news` = '$post[id]'"),0).")<br />\n";
		echo '</td>';
	}
	echo '</tr>';
	echo '</table>';
	echo '</div>';
}

/* Форум */
echo '<a href="/forum"><div class="main">';

echo '<img src="/style/icons/forum.png" alt="*" /> Форум ';

include H.'forum/count.php';

echo '</div></a>';

$adm_add = NULL;
$adm_add2 = NULL;

if (!isset($user) || $user['level'] == 0)
{
	$q222 = mysql_query("SELECT * FROM `forum_f` WHERE `adm` = '1'");
	
	while ($adm_f = mysql_fetch_assoc($q222)) {
		$adm_add[] = "`id_forum` <> '$adm_f[id]'";
	}
    
	if (sizeof($adm_add) != 0) {
        $adm_add2 = ' WHERE'.implode(' AND ', $adm_add);
    }
}

$k_post = mysql_result(mysql_query("SELECT COUNT(*) FROM `forum_t`$adm_add2"),0);

// Если список пуст
if ($k_post == 0) 
{
	echo '<div class="mess">';
	echo 'Нет новых тем в форуме';
	echo '</div>';
} else {
    
    $q = mysql_query("SELECT * FROM `forum_t`$adm_add2 ORDER BY `time_create` DESC  LIMIT 5");

    while ($them = mysql_fetch_assoc($q))
    {
    	// Определение подфорума
    	$forum = mysql_fetch_array(mysql_query("SELECT * FROM `forum_f` WHERE `id` = '$them[id_forum]' LIMIT 1"));
    	
    	// Определение раздела
    	$razdel = mysql_fetch_array(mysql_query("SELECT * FROM `forum_r` WHERE `id` = '$them[id_razdel]' LIMIT 1"));
    	
    	echo '<div class="' . ($num % 2 ? "nav1" : "nav2") . '">';
    	$num++;
    	
    	// Иконка темы
    	echo '<img src="/style/themes/' . $set['set_them'] . '/forum/14/them_' . $them['up'] . $them['close'] . '.png" alt="" /> ';
    	
    	// Ссылка на тему
    	echo '<a href="/forum/' . $forum['id'] . '/' . $razdel['id'] . '/' . $them['id'] . '/">' . text($them['name']) . '</a> 
    	<a href="/forum/' . $forum['id'] . '/' . $razdel['id'] . '/' . $them['id'] . '/?page=' . $pageEnd . '">
    	(' . mysql_result(mysql_query("SELECT COUNT(*) FROM `forum_p` WHERE `id_forum` = '$forum[id]' AND `id_razdel` = '$razdel[id]' AND `id_them` = '$them[id]'"),0) . ')</a><br/>';
    	
    	// Подфорум и раздел
    	echo '<a href="/forum/' . $forum['id'] . '/">' . text($forum['name']) . '</a> &gt; <a href="/forum/' . $forum['id'] . '/' . $razdel['id'] . '/">' . text($razdel['name']) . '</a><br />';
    	
    	// Автор темы
    	$ank = mysql_fetch_assoc(mysql_query("SELECT * FROM `user` WHERE `id` = $them[id_user] LIMIT 1"));
    	echo 'Автор: <a href="/info.php?id=' . $ank['id'] . '">' . $ank['nick'] . '</a> (' . vremja($them['time_create']) . ')<br />';

    	// Последний пост 
    	$post = mysql_fetch_array(mysql_query("SELECT * FROM `forum_p` WHERE `id_them` = '$them[id]' AND `id_razdel` = '$razdel[id]' AND `id_forum` = '$forum[id]' ORDER BY `time` DESC LIMIT 1"));
    	
        // Автор последнего поста
        if ($post['id']) {
        	$ank2 = mysql_fetch_assoc(mysql_query("SELECT * FROM `user` WHERE `id` = $post[id_user] LIMIT 1"));
        	if ($ank2['id'])echo 'Посл.: <a href="/info.php?id=' . $ank2['id'] . '">' . $ank2['nick'] . '</a> (' . vremja($post['time']) . ')<br />';        
        }
    	
    	echo '</div>';
    }    
}



/*  Чат комнаты */
echo '<a href="/chat"><div class="main">';
echo '<img src="/style/icons/chat.png" alt="*" /> Чат ';
include H.'chat/count.php';
echo '</div></a>';

$q = mysql_query("SELECT * FROM `chat_rooms` ORDER BY `pos` ASC");

if (mysql_num_rows($q) != 0) 
{
	echo '<div class="mess">';
	while ($room = mysql_fetch_assoc($q))
	{
		// Лесенка дивов
		if ($num == 0)
		{
			echo '<div class="nav1">';
			$num = 1;
		}
		elseif ($num == 1)
		{
			echo '<div class="nav2">';
			$num = 0;
		}
		
		echo '<img src="/style/themes/' . $set['set_them'] . '/chat/14/room.png" alt="*" /> ';

		echo '<a href="/chat/room/' . $room['id'] . '/' . rand(1000,9999) . '/">' . $room['name'] . ' (' . mysql_result(mysql_query("SELECT COUNT(*) FROM `chat_who` WHERE `room` = '$room[id]'"),0) . ')</a><br />';

		if ($room['opis'] != NULL)
		echo output_text($room['opis']) . '<br />';
		echo '</div>';
	}
	echo '</div>';
}
?>