include_once 'sys/uset.php';
if (isset($_POST['msg_wall']))
{
$msg=$_POST['msg_wall'];
if (isset($_POST['translit']) && $_POST['translit']==1)$msg=translit($msg);
if (strlen2($msg)>1024){$err='Сообщение слишком длинное';}
if (strlen2($msg)<2){$err='Короткое сообщение';}
if (!isset($err)) {
$msg=mysql_real_escape_string($msg);
$q = mysql_query("SELECT * FROM `frends` WHERE `user` = '".$user['id']."'");
while ($f = mysql_fetch_array($q))
{
$a = mysql_fetch_array(mysql_query("SELECT * FROM `user` WHERE `id` = '".$f['frend']."' LIMIT 1"));

if ($user['pol']==1)
{
$ost = "написал";
}
else
{
$ost = "написала";
}

$msg_lenta="Ваш друг[b] $user[nick] [/b] ".$ost." сообщение на [url=/wall/?id=$ank[id]] стену [/url] пользователя [b]$ank[nick][/b]";

mysql_query("INSERT INTO `lenta` (`id_user`, `id_kont`, `msg`, `time`) values('".$user['id']."', '".$a['id']."', '".$msg_lenta."', '".time()."')"); 
}

if (isset($user) && $user['id']!=$ank['id']){

if ($user['pol']==1)
{
$ost = "оставил";
}
else
{
$ost = "оставила";
}

$msg2="[b]$user[nick][/b] ".$ost." запись на Вашей [url=/wall/index.php?id=$ank[id]]стене[/url]";
mysql_query("INSERT INTO `mail` (`id_user`, `id_kont`, `msg`, `time`) values('0', '".$ank['id']."', '".$msg2."', '".time()."')");
}
mysql_query("INSERT INTO `us_wall` (id_user, id_user_adm, time, msg, type) values('".$user['id']."', '".$ank['id']."', '".time()."', '".$msg."', 'msg')");
msg('Сообщение успешно добавлено');
}
}

if(isset($user) && $user['id']!=$ank['id'])
{
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `my_guests` WHERE `id_ank` = '".$ank['id']."' AND `id_user`='".$user['id']."' LIMIT 1"),0)==0)
{
mysql_query("INSERT INTO `my_guests` (`id_ank`, `id_user`, `time`) VALUES ('".$ank['id']."', '".$user['id']."', '".time()."')");
}
else
{
$guest=mysql_fetch_array(mysql_query("SELECT * FROM `my_guests` WHERE `id_ank` = '".$ank['id']."' AND `id_user`='".$user['id']."' LIMIT 1"));
mysql_query("UPDATE `my_guests` SET `count` = '".($guest['count']+1)."', `time`='".time()."' WHERE `id` = '".$guest['id']."' LIMIT 1");
}
}

if (isset($_GET['wall_set']) && is_numeric($_GET['wall_set']))
{
if ($_GET['wall_set']==0)
{
$wset = 0;
}
if ($_GET['wall_set']==1)
{
$wset = 1;
}

mysql_query("UPDATE `uset` SET `wall` = '".$wset."' WHERE `id` = '".$user['id']."' LIMIT 1");

unset($uset);

$uset = mysql_fetch_array(mysql_query("SELECT * FROM `uset` WHERE `id` = '".$user['id']."'"));

}