<?
$k_page=1;

$id_r=intval($_GET['id_r']);
$reflash='45';
if (isset($user))
{
$reflash=$user['reflash'];
}

function reflash($crop_amp){
global $id_r,$reflash;
return str_replace("</title>", "</title>\n<meta http-equiv=\"Refresh\" content=\"$reflash;URL=index.php?id_r=$id_r&amp;".SID."\" />", $crop_amp);
}
ob_start ("reflash");
head();
$q = mysql_query("SELECT * FROM `$mysql[pref]chat_room` WHERE `id` = '$id_r';");
if(mysql_num_rows($q) != 0)
{
$room = mysql_fetch_array($q);
}
else
{
header ("Location: index.php?".SID."");

exit;
}



if ($room['umnik']==1){@include "bot/umnik.php";}
if ($room['shut']==1){@include "bot/shut.php";}


echo "<div class=\"h\">$room[name]</div><hr />\n";
if ($mail_in_new>0)echo "<div class=\"privat\"><img src=\"../SYSTEM/themes/$them/img/mail0.gif\" alt=\"\" /> <a href=\"../mail.php?act=in\">Приват</a> [$mail_in_new]</div><hr />\n";


echo "<a href=\"reload.php?id_r=$id_r\">Обновить</a><hr />\n";
if (isset($user))
{
if ($user['p_vvoda']==1)
{
echo "<form method=\"post\" action=\"add_p.php?act=add&amp;id_r=$id_r&amp;page=$page\">\n";

echo "Сообщение:<br />\n<textarea name=\"msg\" class=\"form\" rows=\"3\"></textarea><br />\n";
echo "<input type=\"checkbox\" name=\"tr\" value=\"1\" /> Транслит<br />\n";
echo "<input value=\"Добавить\" class=\"form\" type=\"submit\" />\n";
echo "</form>";
echo "<hr />\n";

}
else
{
echo "<a href=\"add_p.php?id_r=$id_r&amp;page=$page\">Ответить</a><hr />\n";
}
}

$q = mysql_query("SELECT COUNT(*) FROM `$mysql[pref]chat` WHERE `id_r` = '$id_r';");
$k_post = mysql_result($q, 0);

if ($k_post>1000)
{
mysql_query("DELETE FROM `$mysql[pref]chat` WHERE `id_r` = '$id_r' LIMIT 500;");
}

if (isset($user))
$k_p_str=$user['k_page'];
else
$k_p_str=$set['k_p_s'];


$k_page=k_page($k_post,$k_p_str);
$page=page();

$i=$k_p_str*$page-$k_p_str;
$q2 = mysql_query("SELECT * FROM `$mysql[pref]chat` WHERE `id_r` = '$id_r' ORDER BY id DESC LIMIT $i, $k_p_str;");


if ($k_post>0)
{

while ($post = mysql_fetch_array($q2))
{
$timep=vremja($post['time']+$timesdvig);

include "inc/user";
echo "<div class=\"mess\">";


if ($post['shut']==0 && $post['umnik']==0)
{
user_pic($post_user['id']);
}
elseif($post['shut']!=0)
{
echo "<img src=\"../SYSTEM/themes/$them/img/chat/shut.gif\" alt=\"\" />";
}
elseif($post['umnik']!=0)
{
echo "<img src=\"../SYSTEM/themes/$them/img/chat/umnik.gif\" alt=\"\" />";
}


if ($post['shut']==0 && $post['umnik']==0)
{
if (isset($user))
{
echo " <a href=\"user.php?id_r=$id_r&amp;id_user=$post_user[id]\"><span style=\"color:$color[mess_nick]\"><b>$post[nick]</b></span></a>$stat $on";
}
else
{
echo " <a href=\"../info.php?id=$post_user[id]\"><span style=\"color:$color[mess_nick]\"><b>$post[nick]</b></span></a>$stat $on";
}
}
else
{
echo " <span style=\"color:$color[mess_nick]\"><b>$post[nick]</b></span>$stat $on";
}

echo "<br />\n";
echo "<small><span style=\"color:$color[post_time]\">[$timep]</span></small>";

echo "<br />\n";

if ($post_user['level']>0)
echo "<span style=\"color:$color[post]\">".admin_smiles(smiles(links($post['msg'])))."</span>";
else
echo "<span style=\"color:$color[post]\">".smiles(links($post['msg']))."</span>";

echo "</div>\n";
echo "<br />\n";
}

}
else
{
echo "Нет постов<br />\n";
}


echo "<hr />\n<div class=\"str\">";
str("index.php?id_r=$id_r&amp;",$k_page,$page);
echo "</div>\n";

echo "<hr />\n";




if (isset($user))
{
mysql_query("INSERT INTO `$mysql[pref]chat_who` (nick, id_r, time, id_us) values('$user[nickname]', '$id_r', '$time', '$user[id]')");
}
echo "<a href=\"index.php\">&lt;&lt; В лифт</a><br />\n";
echo "<a href=\"../PAGES/smiles.php/\">&lt;&lt; Смайлики</a><br />\n";
echo "<a href=\"../user.php\">&lt;&lt; Настройки</a><br />\n";
echo "Посетите наш ФОРУМ<br />\n";
include_once "../PAGES/last.php";
?>
