<?
include_once 'sys/inc/start.php';
include_once 'sys/inc/compress.php';
include_once 'sys/inc/sess.php';
include_once 'sys/inc/home.php';
include_once 'sys/inc/settings.php';
include_once 'sys/inc/db_connect.php';
include_once 'sys/inc/ipua.php';
include_once 'sys/inc/fnc.php';
include_once 'sys/inc/user.php';
only_reg();



if ((!isset($_SESSION['refer']) || $_SESSION['refer']==NULL)
&& isset($_SERVER['HTTP_REFERER']) && $_SERVER['HTTP_REFERER']!=NULL &&
!ereg('mail\.php',$_SERVER['HTTP_REFERER']))
$_SESSION['refer']=str_replace('&','&',ereg_replace('^http://[^/]*/','/', $_SERVER['HTTP_REFERER']));
if (isset($_GET['id']) && mysql_result(mysql_query("SELECT COUNT(*) FROM `user` WHERE `id` = '".intval($_GET['id'])."'"),0)==1)
{



$ank=mysql_fetch_array(mysql_query("SELECT * FROM `user` WHERE `id` = ".intval($_GET['id'])." LIMIT 1"));
if ($_GET['id'] == 20 && $user['id'] == 4){print 'Кыш!!'; exit;}
if ($_GET['id'] == 20 && $user['id'] == 1806){print 'Кыш!!'; exit;}
$set['title']='Почта: '.$ank['nick'];
include_once 'sys/inc/thead.php';
title();


mysql_query("UPDATE `mail` SET `read` = '1' WHERE `id_kont` = '$user[id]' AND `id_user` = '$ank[id]' AND `read` = '0'");
if (isset($_POST['msg']))
{
$msg=$_POST['msg'];
if($user['time']<21600)$msg = strtr($msg, array('B'=>'.', 'b'=>'.', 'C'=>'.', 'c'=>'.', 'D'=>'.', 'd'=>'.', 'F'=>'.', 'f'=>'.', 'G'=>'.', 'g'=>'.', 'H'=>'.', 'h'=>'.', 'I'=>'.', 'i'=>'.', 'J'=>'.', 'j'=>'.', 'K'=>'.', 'k'=>'.', 'L'=>'.', 'l'=>'.', 'M'=>'.', 'm'=>'.', 'N'=>'...', 'n'=>'.', 'O'=>'.', 'o'=>'.', 'P'=>'.', 'p'=>'.', 'Q'=>'.', 'q'=>'.', 'R'=>'.', 'r'=>'.', 'S'=>'.', 's'=>'.', 'T'=>'.', 't'=>'.', 'U'=>'.', 'u'=>'.', 'V'=>'.', 'v'=>'.', 'W'=>'.', 'w'=>'.', 'X'=>'.', 'x'=>'.', 'Y'=>'.', 'y'=>'.', 'Z'=>'.', 'z'=>'.'));
if (isset($_POST['translit']) && $_POST['translit']==1)$msg=translit($msg);
if (strlen2($msg)>1024)$err='Сообщение превышает 1024 символа';
if (strlen2($msg)<2)$err='Слишком короткое сообщение';
if (!isset($err) && mysql_result(mysql_query("SELECT COUNT(*) FROM `mail` WHERE `id_user` = '$user[id]' AND `id_kont` = '$ank[id]' AND `msg` = '".mysql_escape_string($msg)."' LIMIT 1"),0)==0)
{

if (mysql_result(mysql_query("SELECT COUNT(*) FROM `konts` WHERE `id_user` = '$ank[id]' AND `id_kont` = '$user[id]'"), 0)==0)
{
mysql_query("INSERT INTO `konts` (`id_kont`, `id_user`, `time`) values('$user[id]', '$ank[id]', '$time')");

}
$msg=mysql_escape_string($msg);
mysql_query("INSERT INTO `mail` (`id_user`, `id_kont`, `msg`, `time`) values('$user[id]', '$ank[id]', '$msg', '$time')");
mysql_query("UPDATE `konts` SET `time` = '$time' WHERE `id_user` = '$user[id]' AND `id_kont` = '$ank[id]' OR `id_user` = '$ank[id]' AND `id_kont` = '$user[id]'");
msg('Сообщение успешно отправлено');

}
}

aut();


if ($user['id']!=$ank['id'] && mysql_result(mysql_query("SELECT COUNT(*) FROM `konts` WHERE `id_user` = '$user[id]' AND `id_kont` = '$ank[id]'"), 0)==0)
{
mysql_query("INSERT INTO `konts` (`id_user`, `id_kont`, `time`) values('$user[id]', '$ank[id]', '$time')");
msg("\"$ank[nick]\" добавлен в ваш список контактов");
}
if (isset($_GET['spam']) )
{
$q=mysql_fetch_array(mysql_query("SELECT * FROM `mail` WHERE `id` = '".intval($_GET['idd'])."' LIMIT 1"));
$msgrat="[b]$user[nick][/b]|$q[msg]|От: http://aclove.ru/info.php?id=$q[id_user]";
mysql_query("INSERT INTO `notspam` (`id_user`, `id_kont`, `msg`, `time`) values('0', '1', '$msgrat', '$time')");
msg("Администрация уведомлена о спаме! Спасибо...");
}
err();

echo "<form method=\"post\" name='message' action=\"mail.php?id=$ank[id]\">\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 "<a href='sys/fnc/bbcode.php'><font color='red'>ББ-Коды</font></a> | <a href='/smiles/'><font color='blue'>Смайлы</font></a><br />";
echo "Сообщение:<br />\n<textarea name=\"msg\"></textarea><br />\n";
echo "<small>   <a href=\"mail.php?id=$ank[id]\">Обновить</a></small><br />";


echo "<input value=\"Отправить\" type=\"submit\" />\n";
echo "</form>\n";

echo "<table class='post'>\n";
$k_post=mysql_result(mysql_query("SELECT COUNT(*) FROM `mail` WHERE `id_user` = '$user[id]' AND `id_kont` = '$ank[id]' OR `id_user` = '$ank[id]' AND `id_kont` = '$user[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 "  <td class='p_t'>\n";
echo "Нет сообщений\n";
echo "  </td>\n";
echo "   </tr>\n";

}
$q=mysql_query("SELECT * FROM `mail` WHERE `id_user` = '$user[id]' AND `id_kont` = '$ank[id]' OR `id_user` = '$ank[id]' AND `id_kont` = '$user[id]' ORDER BY id DESC LIMIT $start, $set[p_str]");
while ($post = mysql_fetch_array($q))
{
$ank2=mysql_fetch_array(mysql_query("SELECT * FROM `user` WHERE `id` = $post[id_user] LIMIT 1"));

echo "   <tr>\n";
if ($set['set_show_icon']==2){
echo "  <td class='icon48' rowspan='2'>\n";
avatar($ank2['id']);
echo "  </td>\n";
}
elseif ($set['set_show_icon']==1)
{
echo "  <td class='icon14'>\n";
echo "<img src='/style/themes/$set[set_them]/user/$ank2[pol].png' alt='' />";
echo "  </td>\n";
}

echo "  <td class='p_t'>\n";
echo adm($ank2['id'])."<span style='color:$ank2[ncolor]'><a href=\"/info.php?id=$ank2[id]\">";
if ($post['sys'] == 1)
print "Система";
else
print "$ank2[nick]";


print "</a></span>".online($ank2['id'])."\n";
echo "(".vremja($post['time']).")\n";
echo "  </td>\n";
echo "   </tr>\n";


echo "   <tr>\n";
if ($set['set_show_icon']==1)echo "  <td class='p_m' colspan='2'>\n"; else echo "  <td>\n";
if ($post['read']==0)echo "(не прочитано)<br />\n";print "<span style='color:$ank2[prcolor]'>";
if ($post['sys'] == 1)
echo trim(br(bbcode(smiles($post['msg']))))."\n";
else
echo trim(br(bbcode(smiles(links(no_reklam(stripcslashes(htmlspecialchars($post['msg']))))))))."\n";
echo "<br/></span>[<a href='delete.php?id=$post[id]'>Удал</a>] [<a href=\"/mail.php?id=$ank[id]&spam&idd=$post[id]\">Спам</a> ]";
echo "</span>  [<a href=\"/mail.php\">Конт</a>]\n";
echo "  </td>\n";
echo "   </tr>\n";





}
echo "</table>\n";





if ($k_page>1)str("mail.php?id=$ank[id]&",$k_page,$page); // Вывод страниц





echo "[<a href=\"/mail.php?delete=$ank[id]\">Удалить контакт</a>]<br />\n";



include_once 'sys/inc/tfoot.php';
}


$set['title']='Мои контакты';
include_once 'sys/inc/thead.php';
title();
echo "<div class='main_menu'>Если у вас стоит Почта +1, а там нет письма нажмите <a href=\"/mail_tru.php\"><font color='red'>здесь</font></a></div>\n";


if (isset($_GET['delete']) && is_numeric($_GET['delete']))
{
mysql_query("UPDATE `mail` SET `read` = '1' WHERE `id_kont` = '$user[id]' AND `id_user` = '".intval($_GET['delete'])."' AND `read` = '0'");
mysql_query("DELETE FROM `konts` WHERE `id_user` = '$user[id]' AND `id_kont` = '".intval($_GET['delete'])."' LIMIT 1");

if (mysql_result(mysql_query("SELECT COUNT(*) FROM `konts` WHERE `id_kont` = '$user[id]' AND `id_user` = '".intval($_GET['delete'])."'"),0)==0)
{
mysql_query("DELETE FROM `mail` WHERE `id_kont` = '$user[id]' AND `id_user` = '".intval($_GET['delete'])."' OR `id_user` = '$user[id]' AND `id_kont` = '".intval($_GET['delete'])."'");
mysql_query("OPTIMIZE TABLE `mail`");
}
mysql_query("OPTIMIZE TABLE `konts`");
msg('Контакт успешно удален');
}
aut();


echo "<table class='post'>\n";

$k_konts=mysql_result(mysql_query("SELECT COUNT(*) FROM `konts` WHERE `id_user` = '$user[id]'"), 0);
if ($k_konts==0)
{
echo "   <tr>\n";
echo "  <td class='p_t'>\n";
echo "Нет контактов\n";
echo "  </td>\n";
echo "   </tr>\n";

}

$k_page=k_page($k_konts,$set['p_str']);
$page=page($k_page);
$start=$set['p_str']*$page-$set['p_str'];
$q = mysql_query("SELECT * FROM `konts` WHERE `id_user` = '$user[id]' ORDER BY `time` DESC LIMIT $start, $set[p_str]");
while ($konts = mysql_fetch_array($q))
{
$ank=mysql_fetch_array(mysql_query("SELECT * FROM `user` WHERE `id` = $konts[id_kont] LIMIT 1"));

echo "   <tr>\n";
if ($set['set_show_icon']==2){
echo "  <td class='icon48' rowspan='2'>\n";
avatar($ank['id']);
echo "  </td>\n";
}
elseif ($set['set_show_icon']==1)
{
echo "  <td class='icon14'>\n";
echo "<img src='/style/themes/$set[set_them]/user/$ank[pol].png' alt='' />";
echo "  </td>\n";
}
echo "  <td class='p_t'>\n";
echo adm($ank2['id'])."<font color='$ank[ncolor]'><a href=\"/mail.php?id=$ank[id]\">$ank[nick]</a></font>".online($ank['id'])."\n";
echo '('.mysql_result(mysql_query("SELECT COUNT(*) FROM `mail` WHERE `id_kont` = '$user[id]' AND `id_user` = '$ank[id]' AND `read` = '0'"), 0);
echo '/';
echo mysql_result(mysql_query("SELECT COUNT(*) FROM `mail` WHERE `id_user` = '$user[id]' AND `id_kont` = '$ank[id]' OR `id_user` = '$ank[id]' AND `id_kont` = '$user[id]'"), 0).')';
echo "\n  </td>\n";
echo "   </tr>\n";

echo "   <tr>\n";
if ($set['set_show_icon']==1)echo "  <td class='p_m' colspan='2'>\n"; else echo "  <td class='p_m'>\n";
echo "[<a href=\"/info.php?id=$ank[id]\">Анкета</a>]<br />\n";
echo "[<a href=\"/mail.php?delete=$ank[id]\">Удалить контакт</a>]<br />\n";

echo "   </tr>\n";

}

echo "</table>\n";


if ($k_page>1)str("mail.php?",$k_page,$page); // Вывод страниц


include_once 'sys/inc/tfoot.php';
?>\n'.', 'w'=,$k_page,$page); // Вывод страниц





echo '.', 'w'=Удалить контактSELECT COUNT(*) FROM `mail` WHERE `id_kont` = '$user[id]' AND `id_user` = '$ank[id]' AND `read` = '0''.', 'w'=), 0)==0)
{
mysql_query(tr), 0)==0)
{
mysql_query(' AND `read` = '0'