<?
require("../config.php");
require("../func.php");
head();
aut();
ban();
if ( $config['status_chat'] == 0) {
    echo "<div class=\"head\">Чат</div><div class=\"main\">";
    echo link1 . 'Чат отключен' . div;
    navig();
    foot();
    exit();
}
$room = num($_GET['room']);
$room_info = mysql_fetch_assoc(mysql_query("SELECT * FROM `room` WHERE `id` = '".$room."'"));

if ( $kik_session > time()) {
    echo katalog;
    echo 'Вы заблокированы. По причине: '.$whykik_session.', администратором/модератором: '.user($whokik_session).'. Осталось ждать: '.t($kik_session-time()).'<br/>';
    navig();
    foot();
    exit();
}

####################Запись онлайна##################
mysql_query("UPDATE `profile` SET `online` = '".$room."' WHERE `id` = '".$id_session."'");
####################################################

if ( empty ( $room_info['id'] ) ) {
    echo "<div class=\"head\">Ошибка</div><div class=\"main\">";
    echo 'Комната не найдена';
    navig();
    foot();
    exit();
}

echo "<div class=\"head\">Чат: <b>".$room_info['room']."</b></div><div class=\"login\">";
if (empty($_POST['submit'])) {
echo '<form action="add.php?room='.$room.'" method="post" name="form">';
echo '<textarea id="tarea" name="msg" cols="30" rows="5" style="width: 99%;"></textarea>';

if($settchat_emo_session==0){
echo '<select name="emo">
<option value="0" selected="selected">[Без эмоции]</option>
<option value="1">Радостно</option>
<option value="2">Печально</option>
<option value="3">Удивленно</option>
<option value="4">Ласково</option>
<option value="5">Смущенно</option>
<option value="6">Кокетливо</option>
<option value="7">Обиженно</option>
<option value="8">Настойчиво</option>
<option value="9">Шепотом</option>
<option value="10">Задумчиво</option>
<option value="11">Злобно</option>
</select><br/ >';
} 
if($settchat_color_session==1){
echo '<select name="color">
<option value="0" selected="selected">[Cтандартный]</option>
<option value="1">Красный</option>
<option value="2">Синий</option>
<option value="3">Зеленый</option>
<option value="4">Оранжевый</option>
<option value="5">Фиолетовый</option>
<option value="6">Розовый</option>
</select><br/ >';
} 
echo '<input name="submit" type="submit" class="button" value="Сказать" /></form>';



echo '</div><div class="katalog">В комнату: <a href="chat.php?room='.$room.'">'.$room_info['room'].'</a><br/ >';
echo '<a href="../smiles.php">Смайлы</a></div>';

} else {
$msg = mysmile(html($_POST['msg']));
$post = $chat_post_session+1;

include '../bots/answer.php';

/////////Антиспам///////////

##Повтор сообщения
$msg_info = mysql_fetch_assoc(mysql_query("SELECT * FROM `chat_msg` where `ot_user` = '".$id_session."'order by id desc limit 1"));
if ( $msg_info['msg'] == $msg ) {
    
    echo rew('chat.php?room='.$room.'&error=msg');
    exit();
}

##Интервал
if ( $msg_info['antispam'] > time()  AND $msg_info['ip'] == $_SERVER['HTTP_X_FORWARDED_FOR']) {
    echo rew('chat.php?room='.$room.'&error=spam');
    exit();
}


if ( empty($msg) ) {
    
    echo rew('chat.php?room='.$room.'');
    exit();
}



$antispam = ( time() + 5 );
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];

/////////////////////////////
if ($room_info['id']==1) require 'bots/bot_bartender.php';
$result = mysql_query("INSERT INTO `chat_msg` SET `msg` = '".$msg."', `ot_user` = '".$id_session."', `room` = '".$room."', `date` = '".time()."', `antispam` = '".$antispam."', `ip` = '".$ip."', `emotion` = '".num($_POST['emo'])."', `color` = '".num($_POST['color'])."'");
mysql_query("UPDATE `profile` SET `akt_rating` = '".($user['akt_rating']+0.1)."' WHERE `id` = '".$id_session."' LIMIT 1");
include 'barmen.php';
mysql_query("UPDATE `profile` SET `postov` = '".$post."' WHERE `id` = '".$id_session."'");
echo rew('chat.php?room='.$room.'');

}
navig();
foot();
?>