<?
include_once "../SYSTEM/include/functions.php";
include_once "../SYSTEM/include/mysql.php";
include_once "../SYSTEM/include/param.php";
include_once "../SYSTEM/include/ban.php";
include_once "../SYSTEM/include/sess.php";
include_once "../SYSTEM/include/ban_2.php";
include_once "../SYSTEM/include/theme.php";
$title='Новое сообщение';
$mesto='Пишет в чат на главной';
head();

if(isset($_GET['mp']))
define('G', BASEDIR);
else
define('G', BASEDIR.'guest/');

if ($_POST['umnik']==1) include "umnik.php";

if (!isset($user))
{
$user_id=0;
$user_nick='Гость';
}
else
{
$user_id=$user['id'];
$user_nick=$user['nickname'];
}

if (isset($_GET['act']) && $_GET['act']=='add' && isset($_POST['msg']))
{
$msg=$_POST['msg'];
$msg = iconv('utf-8', 'windows-1251', $msg);
$msg=substr($msg, 0, 512);
$msg = iconv('windows-1251', 'utf-8', $msg);
$msg=stripcslashes(htmlspecialchars($msg));
$msg=str_replace("\r\n","<br />",$msg);
$msg=str_replace("\r","<br />",$msg);
$msg=str_replace("\n","<br />",$msg);

if (isset($_POST['tr']))
{
$msg=translit($msg);
}



if ($msg=='')
{
header("Location: ".G."index.php?".SID."");
exit;
}
	if (!isset($user)){
	$chislo=intval($_POST['chislo']);	if ($chislo=='' || !is_numeric($chislo) || strlen($chislo)!=3 || $chislo!=$_SESSION['chislo']){	header("Location: ".G."index.php?bot&".SID."");	exit;	};$msg= eregi_replace("((https?|ftp)://[[:alnum:]_=/-]+(\\.[[:alnum:]_=/-]+)*(/[[:alnum:]+&amp;._=/~%#]*(\\?[[:alnum:]?+&amp;_=/%#]*)?)?)", "самый лучший сайт http://yastreba.net .кул3. ", $msg);};
$time_q=$time-30;
$q = mysql_query("SELECT COUNT(*) FROM `$mysql[pref]chat_main` WHERE `time` > '$time_q' AND `text` = '$msg' AND `ip` = '$ip';");
$repeat=mysql_result($q, 0);
if ($repeat==0)
{
mysql_query("INSERT INTO `$mysql[pref]chat_main` (nick, time, text, ip, ua, id_user)
values('$user_nick', '$time', '$msg', '$ip', '$ua', '$user_id')");

if ($_POST['umnik']==1) umnik($msg);

if (isset($user))
{
$user['main_post_k']++;
mysql_query("UPDATE `$mysql[pref]users` SET `main_post_k` = '$user[main_post_k]' WHERE `id` = '".$user['id']."';");
}
ball_add();

}

header("Location: ".G."index.php?".SID."");
exit;
}

header("Location: ".G."index.php?".SID."");



foot();
?>
