<?
//////////////////////////////////////////
////////MADE by Green-Day ICQ 9298034 СКРИПТ ЗАПРЕЩЕНО ПЕРЕПРОДАВАТЬ,МЕНЯТЬ,РАЗДАВАТЬ.СОБЛЮДАЙТЕ АВТОРСКИЕ ПРАВА!
///////////////////////////////////////////
if (isset($_POST['msg']) && isset($user))
{
$msg=$_POST['msg'];
if (!empty($_POST['bold'])){
$msg = '[b]'.$msg.'[/b]';}
if (!empty($_POST['under'])){
$msg = '[u]'.$msg.'[/u]';}
if (!empty($_POST['color'])){
$msg = '[color='.$_POST['color'].']'.$msg.'[/color]';}
if (isset($_POST['translit']) && $_POST['translit']==1)$msg=translit($msg);
if (strlen2($msg)>512){$err='Сообщение слишком длинное';}
elseif (strlen2($msg)<2){$err='Короткое сообщение';}
elseif (mysql_result(mysql_query("SELECT COUNT(*) FROM `chat_post` WHERE `id_user` = '$user[id]' AND `msg` = '".mysql_escape_string($msg)."' AND `time` > '".($time-300)."' LIMIT 1"),0)!=0){$err='Ваше сообщение повторяет предыдущее';}
else{
$msg=mysql_escape_string($msg);

if(isset($_POST['privat']))
{
$priv=abs(intval($_POST['privat']));
}else{
$priv=0;
}
mysql_query("INSERT INTO `chat_post` (`id_user`, `time`, `msg`, `room`, `privat`) values('$user[id]', '$time', '$msg', '$room[id]', '$priv')");
mysql_query("UPDATE `user` SET `balls` = '".($user['balls']+3)."' WHERE `id` = '$user[id]' LIMIT 1");
mysql_query("UPDATE `user` SET `lafes` = '".($user['lafes']+1)."' WHERE `id` = '$user[id]' LIMIT 1");
//mysql_query("UPDATE `user` SET `balls` = '".($user['balls']+3)."',`posts` = '".($user['posts']+1)."' WHERE `id` = '$user[id]' LIMIT 1");
msg('Сообщение в эфире + 3 LM');
}
}
if ($room['umnik']=='1')include 'inc/umnik.php';
if ($room['shutnik']=='1')include 'inc/shutnik.php';
if ($room['bot']=='1')include 'inc/bot.php';
err();

echo '<div class="textmes">';
echo "<a href='/smiles/index.php'><font color='black'>Смайлы</font></a> | \n";
echo "<a href='/chat/room/$room[id]/".rand(1000,9999)."/'><font color='black'>Обновить</font></a> |\n";
echo "<a href='/chat/online.php'><font color='black'>Кто Где?</font></a>\n";


if (isset($user))
{


echo "<form method=\"post\" name='message' action=\"/chat/room/$room[id]/".rand(1000,9999)."/\"></textarea> \n";
if ($set['web'] && is_file(H.'style/themes/'.$set['set_them'].'/altername_post_form.php'))
include_once H.'style/themes/'.$set['set_them'].'/altername_post_form.php';
else
echo "<input name=\"msg\" type=\"text\" maxlength='200' value='' />\n";
echo "<input value=\"Сказать\" type=\"submit\" /><br/>\n";
if($user['group_access'] > 1){
echo "<label><input type=\"checkbox\" name=\"bold\" value=\"$user[id]\" /> Жирный</label>\n";
echo "<label><input type=\"checkbox\" name=\"under\" value=\"$user[id]\" /> Подчёркнутый</label><br />\n";}
echo "</form>\n";
echo '</div>';
}

$set['p_str'] = 15;
$k_post=mysql_result(mysql_query("SELECT COUNT(`id`) FROM `chat_post` WHERE `room` = '$room[id]'"),0);
$k_page=k_page($k_post,$set['p_str']);
$page=page($k_page);
$start=$set['p_str']*$page-$set['p_str'];
if ($k_post==0)
{
echo "   <tr>\n";
echo "Нет сообщений\n";
}
$q=mysql_query("SELECT * FROM `chat_post` WHERE `room` = '$room[id]' AND (`privat`='0' OR (`privat`='".$user['id']."' OR `id_user`='".$user['id']."')) ORDER BY id DESC LIMIT $start, $set[p_str]");
while ($post = mysql_fetch_array($q))
{
if ($post['umnik_st']==0 && $post['shutnik']==0 && $post['bot']==NULL) 
//$ank=mysql_fetch_array(mysql_query("SELECT * FROM `user` WHERE `id` = $post[id_user] LIMIT 1"));
$ank=get_user($post['id_user']);
if ($user['zebra_chat']==0)
{
if($num==1){
echo "<div class='linechat'>";
$num=0;
}else{
echo "<div class='linechat'>";
$num=1;}
}
if ($user['zebra_chat']==1)
{
if($num==1){
echo "<div class='tmn'>";
$num=0;
}else{
echo "<div class='zebra_ch'>";
$num=1;}
}
if($post['privat'])
{
$Te6e_cyka='<font color="darkred">[!п]</font>';
$privat = '?priv=1';
}else{
$Te6e_cyka='';
$privat = '';
}
if (user_access('chat_clear'))
{
echo "[<a href='/chat/delete.php?id=$post[id]'>X</a>]\n";
}
if ($post['umnik_st']==0 && $post['shutnik']==0 && $post['bot']==NULL)
echo "".online($ank['id'])." <a href='/chat/room/$room[id]/".rand(1000,9999)."/$ank[id]/'><span style=\"color:$ank[ncolor]\">$ank[nick]</span> $Te6e_cyka </a>(".vremja($post['time']).")</a>\n";
elseif ($post['umnik_st']!=0)
echo "<font color='red'>ЗнАйКа</font> (".vremja($post['time']).")\n";
elseif ($post['shutnik']==1)
echo "ПРиКоЛиСт (".vremja($post['time']).")\n";
elseif ($post['bot']!==NULL)
echo "<img src='/style/bot.png' alt='' /> <a href='/info.php?id=6'>Минни Маус</a> (".vremja($post['time']).")\n";
echo "<span style=\"color:$ank[mcolor]\">";
echo str_replace($user['nick'],"<b><span style=\"color:$user[ncolor]\">".$user['nick']."</span></b>",esc(trim(br(bbcode(smiles(links(stripcslashes(htmlspecialchars($post['msg'])))))))))."\n";
echo "</span>\n";
echo "</div>\n";

}
if ($k_page>1)str("/chat/room/$room[id]/".rand(1000,9999)."/?",$k_page,$page); // Вывод страниц
echo "<div class='tmn'>";
echo "В комнате";
$sql = mysql_query("SELECT `id_user` FROM `chat_who` WHERE `room` = '$room[id]'");
if ($sql==0){echo "Никого нет\n";}

while($us = mysql_fetch_assoc($sql))
{
$login=mysql_fetch_array(mysql_query("select `nick`,`pol`,`ncolor` from `user` where `id`='".$us['id_user']."' limit 1;"));
if ($login['show_secret']==0)
{
echo ":<span style=\"color:$login[ncolor]\"> $login[nick]</a> </span> ";
}
if ($login['show_secret']==1)
{
echo ":SECRET ";
}
}

echo'</div>';

?>