<?
// Обновление информации
if (isset($user) && mysql_result(mysql_query("SELECT COUNT(*) FROM `chat_who` WHERE `id_user` = '$user[id]'"),0) == 0) {
	mysql_query("INSERT INTO `chat_who` (`id_user`, `time`,  `room`) values('$user[id]', '$time', '0')");
} elseif (isset($user)) {
	mysql_query("UPDATE `chat_who` SET `room` = '0', `time` = '$time' WHERE `id_user` = '$user[id]' LIMIT 1");
}

$_SESSION['sid'] = mt_rand(000, 999);
$set['title'] = __('Чат - Прихожая');
include_once H.'sys/inc/thead.php';
title();
aut(); 
err();


$k_post = mysql_result(mysql_query("SELECT COUNT(*) FROM `chat_rooms`"), 0);
$k_page = k_page($k_post,$set['p_str']);
$page = page($k_page);
$start = ($set['p_str'] * $page) - $set['p_str'];

?><table class="post"><?

if ($k_post == 0)
{
	?>
	<div class="mess">
	<?= __('Прихожая пуста')?>
	</div>
	<?
}

$q = mysql_query("SELECT `id`, `name`, `opis` FROM `chat_rooms` ORDER BY `pos` LIMIT $start, $set[p_str]");

while ($post = mysql_fetch_assoc($q)) {
	$num++;
	?>
	<div class="<?= ($num % 2 ? 'nav2' : 'nav1')?>">
	<img src="/style/themes/<?= $set['set_them']?>/chat/14/room.png" alt="" /> 
	<a href="?func=room&amp;id=<?= $post['id']?>&amp;sid=<?= $_SESSION['sid']?>"><?= text($post['name'])?></a>  (<?= mysql_result(mysql_query("SELECT COUNT(*) FROM `chat_who` WHERE `room` = '$post[id]' AND `time` > '" . (time() - 120) . "'"), 0)?> чел.) 
	<?= (user_access('chat_room') ? '<a href="?func=set&amp;room=' . $post['id'] . '"><img src="/style/icons/edit.gif" alt="*" /></a>' : '')?> 
	<br />
	<?= output_text($post['opis'])?>
	</div>
	<?
}
?>
</table>

<?
if ($k_page > 1) {
	str('?func=index&amp;sid=' . $_SESSION['sid'] . '&amp;', $k_page, $page);
}
?>

<div class="foot">
 <img src="/style/icons/str.gif" alt="*"> <a href="?func=who&amp;all"><?= __('Кто в чате?')?></a> (<?= mysql_result(mysql_query("SELECT COUNT(*) FROM `chat_who` WHERE `time` > '" . (time() - 120) . "'"), 0)?> чел.)<br />
</div>

<?
if (user_access('chat_room') || user_access('chat_clear')) {
?>
	<div class="foot">
	 <?= (user_access('chat_clear') && mysql_result(mysql_query("SELECT COUNT(*) FROM `chat_rooms`"),0) > 0 ? '<img src="/style/icons/str.gif" alt="*"> <a href="?func=delete&amp;truncate">' . __('Очистить чат от сообщений') . '</a><br />' : '')?>
	 <?= (user_access('chat_room') ? '<img src="/style/icons/str.gif" alt="*"> <a href="?func=set&amp;create">' . __('Создать комнату') . '</a><br />' : '')?>
	</div>
<?
}
?>