<?
require ('../config.php');
$res2=mysql_query("SELECT * FROM tb_mail_ref where status= '1'");
$row2=mysql_fetch_assoc($res2);
$userpisal=$row2["user"];
$text=$row2["text"];
$refer_kon=mysql_query("SELECT * FROM tb_mail_ref WHERE user='$userpisal' ORDER BY id DESC");
if(mysql_num_rows($refer_kon) <= 0){
exit;
}
$res = mysql_query("SELECT * FROM tb_users WHERE referer='$userpisal'");
while ($row = mysql_fetch_assoc($res))
{
$ref=$row["username"];
if($userpisal==$userpisal)
{
$timenow=time();
mysql_query("insert into tb_mail (sender,recipient,subject,message,data) values ('$userpisal','$ref','Рассылка писем рефералам','$text','$timenow')");
$timenow=time();
mysql_query("UPDATE tb_mail_ref SET status='0', time_end='$timenow' WHERE user='$userpisal'");
}}
?>
