<?
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';
$temp_set=$set;
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_level(10);
//adm_check();

$set['title']='рассылка почты';
include_once '../sys/inc/thead.php';
title();

if (isset($_POST['save']) && isset($_POST['msg']))
{

$msg=$_POST['msg'];
if (isset($_POST['translit']) && $_POST['translit']==1)$msg=translit($msg);
if (strlen2($msg)>1024)$err='Сообщение превышает 1024 символа';
if (strlen2($msg)<2)$err='Слишком короткое сообщение';
if (!isset($err))
{
$q=mysql_query("SELECT `id` FROM `user` WHERE `id` != $user[id]");
$msg=mysql_escape_string($msg);
while ($us = mysql_fetch_array($q))
{


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

}



mysql_query("INSERT INTO `mail` (`id_user`, `id_kont`, `msg`, `time`) values('$user[id]', '$us[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('Сообщения успешно отправлены');



}



}
err();
aut();


$count=mysql_result(mysql_query("SELECT COUNT(*) FROM `user`"),0);
echo'Всего пользователей: <b>'.$count.'</b><br/>';
echo "<form method=\"post\" action=\"?\">\n";
echo "Сообщение:<br />\n<textarea name=\"msg\"></textarea><br />\n";
if ($user['set_translit']==1)echo "<input type=\"checkbox\" name=\"translit\" value=\"1\" /> Транслит<br />\n";

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








echo "<div class='foot'>\n";

echo "<a href='/adm_panel/rekl.php'>Реклама</a><br />\n";
echo "<a href='/adm_panel/'>В админку</a><br />\n";
echo "</div>\n";

include_once '../sys/inc/tfoot.php';
?>