<?

require'config.php';
$user['avr'] = 0;
$align='left';

$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();
levels(4);
head();

if (empty($act)){

$topic_time = $rooms['topic_time']+3600;
if($topic_time < $time || $user['level'] >= 9)
{
	if($topic_time > $time and $user['level'] >= 9){
	$tm = intval(abs($time - $topic_time)/60);
	echo 'Топик можно сменить через '.$tm.' мин<br />
	но сисАдминам можно всегда:)<br />';
	}
	if ($ver!='wml')echo '<form action="topic?rm='.$rm.'&amp;act=add&amp;'.SID.'" method="post">';
	if ($ver=='wml')echo '<br/><input name="topic'.$ref.'" value="'.$rooms['topic'].'" maxlength="20" title="Text"/><br/>';
	else echo '<br/><input type="text" name="topic" value="'.$rooms['topic'].'" maxlength="20" title="Text"/><br/>';
	if ($ver=='wml'){
	echo '<br /><anchor title="go">Изменить<go href="tell?rm='.$rm.'&amp;act=add&amp;'.SID.'" method="post">';
	echo '<postfield name="topic" value="topic'.$ref.'"/>
	</go></anchor>';
	echo '<br/><br />';
	}else{
	echo '<br /><input type="submit" class="ibutton" value="Изменить"/></form><br /><br />';
	}
}else
{
	$tm = intval(abs($time - $topic_time)/60);
	echo 'Топик можно сменить через '.$tm.' мин<br />';
}
}else{
if($topic_time < $time || $user['level'] >= 9)
{
	$topic = check($_POST['topic']);
	if (strlen2($topic)<3){echo 'Топик должен быть больше 3 букв...'; exit;}

	$topic = iconv('utf-8', 'windows-1251', $topic);
	$topic = substr($topic,0,20);
	$topic = iconv('windows-1251', 'utf-8', $topic);
	if ($user['translit']==1)$topic = translit($topic);
/*

	$s_post=$db->sql_fetchfield($db->sql_query("select COUNT(*) from rooms WHERE `system` != '0';"),0);
	$k_page=k_page($s_post,$s_post);
	$page=page($k_page);
	$s1=$s_post*$page-$s_post;
	$num = @$db->sql_query("SELECT * FROM rooms WHERE `system` != '0' ORDER BY `rm` DESC LIMIT $s1, $s_post;" );
	while($nums = @$db->sql_fetchrow($num)){*/
if ($set['topic_notify']==1){
	$db->sql_query ("INSERT INTO message (user,user_id,time,msg,rm) VALUES ('$user_system','0','$time','[b]".$user['user']."[/b] cменил топик на [b]". $topic."[/b]','$rm')");///в комнате [b]". $rooms['name']."[/b]
}

	/*}*/
	$db->sql_query ("INSERT INTO logs (log,msg,time) VALUES ('topic','[b]".$user['user']."[/b] cменил топик в комнате [b]".$rooms['name']."[/b] на [b]".$topic."[/b]','$time')");
	$db->sql_query("UPDATE `rooms` SET `topic` = '$topic',`topic_time` = '$time' WHERE `rm` = '$rm';");
}
header ('Location: room?rm='.$rm.'&'.SID);  exit;

}


echo gb.'<a href="room?rm='.$rm.'">В чат </a>'.div;

foot();
?>