<?
include '../config.php';
include '../func.php';
head();
ban();

/////////////////////////////

if ( $id_session )
mysql_query("UPDATE `profile` SET `online` = 'forum' WHERE `id` = '".$id_session."'");


if ( $id_session )
echo head . "Добро пожаловать, <b>".$login_session."</b>!" . div;
else
echo head . "<b>Добро пожаловать, <b>гость</b>!</b>" . div;

if(isset($_GET['search']))
{
	echo katalog . '<form action="search.php" method="post">
 	<div>Что искать:<br/>
 	<input name="query" type="text" value="" /><br/>
 	Искать в:<br/>
 	<select size="1" name="in">
 	<option value="1">Темах</option>
 	<option value="2">Сообщениях</option>
 	</select><br/>
 	<input type="submit" value="Искать"></div></form>' . div;
 	pod_navig();
foot();
exit();
}
   
echo katalog . "Новые: <a href=\"nthemes.php\">Темы</a> | <a href=\"nposts.php\">Посты</a>" . div;
echo head . '<b>Форумы:</b>' . div;

$all = mysql_result(mysql_query("SELECT count(*) FROM `forum_razdel`"), 0);

if( $all == 0 ) {
echo katalog . "Форумы не созданы" . div;

} else {
//echo katalog;    
$result = mysql_query("SELECT * FROM forum_razdel");
while($razdel = mysql_fetch_assoc($result)){

$all_themes = mysql_result(mysql_query("SELECT count(*) FROM `forum_themes` WHERE `razdel_id` = '".$razdel['id']."'"), 0);
$all_msg = mysql_result(mysql_query("SELECT count(*) FROM `forum_msg` WHERE `razdel_id` = '".$razdel['id']."'"), 0);

echo "<div class='link2'><img src=\"../images/forumcat.gif\" alt=\" * \"/> <a href=\"forum.php?id=".$razdel['id']."\">".$razdel['name']."</a> (".$all_themes." | ".$all_msg.")<br/>";

$result_2 = mysql_query ("SELECT * FROM `forum_themes` WHERE `razdel_id` = '".$razdel['id']."' ORDER BY `date` DESC LIMIT 1");
while ($a = mysql_fetch_array($result_2))
{
$theme = '<a href="theme.php?razdel='.$a['razdel_id'].'&pod_forum='.$a['pod_forum'].'&theme='.$a['id'].'">'.$a['name'].'</a>';
}

if ( $theme )
echo "<b>Тема:</b> ".$theme."</div>";
else
echo '<b>Темы еще не созданы</b><hr>';

}
echo div;

}
//echo div;
echo div . katalog;
echo "<b>Меню:</b><br/>";
if ( $id_session ) {
echo "<a href=\"?search\">Поиск</a> .: <a href=\"../mail.php\">Почта</a> .: <a href=\"../cabimet.php?act=exit\">Выход</a><br/>";
echo "<a href=\"../faq.php\">FAQ / Помощь</a><br/>";
echo "<a href=\"elita.php\">Администрация форума</a><br/>";
echo "<a href=\"../cabinet.php\">Личный кабинет</a><br/>";
echo div . link1;
echo "Мои: [<a href=\"my_themes.php\"><b>Темы</b></a>] [<a href=\"my_posts.php\"><b>Посты</b></a>]</div>";
} else {
    echo 'Меню скрыто для гостей.<br/>';
}


echo "<div class='link2'><b>Статистика:</b><br/>";
$on = mysql_result(mysql_query("SELECT count(*) FROM `profile` WHERE `time` > '".(time()-600)."' ORDER BY `time` AND `online` = 'forum'"), 0);
$kol_msg = mysql_result(mysql_query("SELECT count(*) FROM `forum_msg`"), 0);
$kol_user = mysql_result(mysql_query("SELECT count(*) FROM `profile`"), 0);
$user_msg = mysql_fetch_assoc(mysql_query("SELECT * FROM `forum_msg` order by id desc limit 1 "));
$all_themes = mysql_result(mysql_query("SELECT count(*) FROM `forum_themes`"), 0);
$u = mysql_fetch_assoc(mysql_query("SELECT * FROM `profile` WHERE `id` = '$user_msg[user_id]'"));
echo "<a href=\"online.php\">На форуме: $on</a> чел.<br/>";

echo "Всего сообщений: $kol_msg<br/>";
echo "Всего тем: $all_themes<br/>";
echo "Всего пользователей: $kol_user<br/>";
echo "Последний: $u[login]<br/>";
echo "<b><a href=\"../top.php?mod=forum\">ТОП-20</a></b><br/>";
echo '</div>';




pod_navig();
foot();
?>