<?
require'config.php';
$user['avr'] = 0;
$rm = intval($_GET['rm']);
if (empty($rm)) header ('Location: enter?'.SID);
$rooms = $db->sql_fetchrow($db->sql_query("SELECT * FROM `rooms` WHERE `rm` = '$rm'"));
$title='Кто в '.$rooms['name'].'?';
aut();
head();

if ($user['level']<$rooms['level'])
	{
	 who_add(0,'enter');
	 $align='center';
	 echo 'ПНХ Лохопед!<br />';
	 echo gbinroom.'<a href="enter">Прихожая</a><br />'.div;
	 info_compress();
	 echo 'Время:'.$debag->endTimer().' сек<br />'.div;
	 foot();
	}

if($user['posts'] < $rooms['posts'])
{
	$postus = $rooms['posts'] - $user['posts'];
	echo 'Извините, но в эту комнату вам доступ пока закрыт!<br />
	Для входа в комнату вам необходимо набрать <font color="red"><b>'.$postus.'</b></font> постов!<br />';
	$rooms1 = $db->sql_query("SELECT * FROM `rooms` ORDER BY `pos` ASC");
	if($db->sql_numrows($rooms1)!=0)
	{
		echo '<b>Ниже представлены доступные для вас комнаты!</b><br />';
		while($room = $db->sql_fetchrow($rooms1))
		{
			echo menu;
			if($user['posts'] > $room['posts'])
			{
				if ($room['sartir']==1)echo '<a href="room?'.$ref.'&amp;rm='.$room['rm'].'&amp;sartir"><font color="green">'.$room['name'].'</font>('.$db->sql_fetchfield($db->sql_query('SELECT COUNT(*) FROM `who` WHERE `room` = "room" and `rm` = "'.$room['rm'].'"'),0).')</a><br />';
				else if ($room['intim']==1)echo '<a href="room?'.$ref.'&amp;rm='.$room['rm'].'&amp;intim"><font color="green">'.$room['name'].'</font>('.$db->sql_fetchfield($db->sql_query('SELECT COUNT(*) FROM `who` WHERE `room` = "room" and `rm` = "'.$room['rm'].'"'),0).')</a><br />';
				else if ($room['zags']==1)echo '<a href="room?'.$ref.'&amp;rm='.$room['rm'].'&amp;zags=zags"><font color="green">'.$room['name'].'</font>('.$db->sql_fetchfield($db->sql_query('SELECT COUNT(*) FROM `who` WHERE `room` = "room" and `rm` = "'.$room['rm'].'"'),0).')</a><br />';
				else if ($room['level']<=$user['level'])echo '<a href="room?'.$ref.'&amp;rm='.$room['rm'].'"><font color="green">'.$room['name'].'</font>('.$db->sql_fetchfield($db->sql_query('SELECT COUNT(*) FROM `who` WHERE `room` = "room" and `rm` = "'.$room['rm'].'"'),0).')</a><br />';
			}else
			{
				if ($room['sartir']==1)echo '<font color="red"><s>'.$room['name'].'</s></font>('.$db->sql_fetchfield($db->sql_query('SELECT COUNT(*) FROM `who` WHERE `room` = "room" and `rm` = "'.$room['rm'].'"'),0).')<br />';
				else if ($room['intim']==1)echo '<font color="red"><s>'.$room['name'].'</s></font>('.$db->sql_fetchfield($db->sql_query('SELECT COUNT(*) FROM `who` WHERE `room` = "room" and `rm` = "'.$room['rm'].'"'),0).')<br />';
				else if ($room['zags']==1)echo '<font color="red"><s>'.$room['name'].'</s></font>('.$db->sql_fetchfield($db->sql_query('SELECT COUNT(*) FROM `who` WHERE `room` = "room" and `rm` = "'.$room['rm'].'"'),0).')<br />';
				else if ($room['level']<=$user['level'])echo '<font color="red"><s>'.$room['name'].'</s></font>('.$db->sql_fetchfield($db->sql_query('SELECT COUNT(*) FROM `who` WHERE `room` = "room" and `rm` = "'.$room['rm'].'"'),0).')<br />';
			}
			echo div;
		}
	}else{
	echo 'Комнаты в которых можно набрать посты общением пока что не созданы<br />';
	}
	 who_add(0,'enter');
	echo gbinroom.'<a href="enter">Прихожая</a><br/>'.div;
	info_compress();
	echo 'Время:'.$debag->endTimer().' сек<br />'.div;
	foot();
}

if ($rooms['intim']==1){
who_add(0,'enter');
echo 'Это же интим...';
echo gb.'<a href="room?rm='.$rm.'">В чат </a>'.div;
info_compress();
echo 'Время:'.$debag->endTimer().' сек<br />'.div;
foot();
}
who_add($rm,'room');
echo '<br />';
if ($ver=='xhtml')echo '<div style="margin-left:2%">';

$whos = $db->sql_query("SELECT * FROM `who` WHERE `room` = 'room' and `rm` = '$rm' ORDER BY `time` DESC");
if($db->sql_numrows($whos)>1) $zp = ', '; else $zp = '';
while($who = $db->sql_fetchrow($whos)){
echo nik($who['user'],''.H.'inside?rm='.$rm.'&amp;nk='.$who['user'].'').$zp;;
}
if($db->sql_numrows($whos)>0)echo '<br />';
if ($ver=='xhtml')echo '</div>';
echo '<br />';
echo gb.'<a href="room?rm='.$rm.'">В чат </a>'.div;

info_compress();
echo 'Время:'.$debag->endTimer().' сек<br />'.div;
foot();
ob_end_flush();
?>