Файл: vsime.com/system/functions/write_mail.php
Строк: 79
<?
function write_mail($user_id, $ank_id, $msg)
{
global $time, $dbi;
$user = profile($user_id);
$ank = profile($ank_id);
if (mysqli_num_rows(mysqli_query($dbi, "SELECT * FROM `mail_conts` WHERE `id_user` = '$ank[id]' AND `id_ank` = '$user[id]' AND `type` = 'all'"))==0)
{
mysqli_query($dbi, "INSERT INTO `mail_conts` (`id_user`, `id_ank`, `time`, `nick`, `time_last`, `count`) VALUES ('$ank[id]', '$user[id]', '$time', '$user[nick]', '$time', '1')");
$hid2=mysqli_insert_id($dbi);
mysqli_query($dbi, "INSERT INTO `mail` SET `id_user` = '$ank[id]', `id_cont` = '".mysqli_insert_id($dbi)."', `msg` = '".my_esc($msg)."', `time` = '$time', `type` = 'to', `read` = '0'");
} else {
$acont=mysqli_fetch_array(mysqli_query($dbi, "SELECT * FROM `mail_conts` WHERE `id_user` = '$ank[id]' AND `id_ank` = '$user[id]' AND `type` = 'all'"));
mysqli_query($dbi, "INSERT INTO `mail` SET `id_user` = '$ank[id]', `id_cont` = '$acont[id]', `msg` = '".my_esc($msg)."', `time` = '$time', `type` = 'to', `read` = '0'");
$count=mysqli_num_rows(mysqli_query($dbi, "SELECT * FROM `mail` WHERE `id_cont` = '$acont[id]' AND `read` = '0' AND `type` = 'to'"));
mysqli_query($dbi, "UPDATE `mail_conts` SET `time_last` = '$time', `count` = '$count' WHERE `id` = '$acont[id]'");
$hid2 = $acont['id'];
}
if (mysqli_num_rows(mysqli_query($dbi, "SELECT * FROM `mail_conts` WHERE `id_user` = '$user[id]' AND `id_ank` = '$ank[id]' AND `type` = 'all'"))==0)
{
mysqli_query($dbi, "INSERT INTO `mail_conts` (`id_user`, `id_ank`, `time`, `nick`, `time_last`) VALUES ('$user[id]', '$ank[id]', '$time', '$ank[nick]', '$time')");
$hid=mysqli_insert_id($dbi);
mysqli_query($dbi, "INSERT INTO `mail` SET `id_user` = '$user[id]', `id_cont` = '".mysqli_insert_id($dbi)."', `msg` = '".my_esc($msg)."', `time` = '$time', `type` = 'at', `read` = '0'");
} else {
$ucont=mysqli_fetch_array(mysqli_query($dbi, "SELECT * FROM `mail_conts` WHERE `id_user` = '$user[id]' AND `id_ank` = '$ank[id]' AND `type` = 'all'"));
mysqli_query($dbi, "UPDATE `mail_conts` SET `time_last` = '$time' WHERE `id` = '$ucont[id]'");
mysqli_query($dbi, "INSERT INTO `mail` SET `id_user` = '$user[id]', `id_cont` = '$ucont[id]', `msg` = '".my_esc($msg)."', `time` = '$time', `type` = 'at', `read` = '0'");
$hid = $ucont['id'];
}
if ($ank['email_system_mail']==1 && $user_id==0 && $ank['email'])
{
$msg_email = output_text($msg, 0)."<br/><a href='http://$_SERVER[HTTP_HOST]/mail/?act=cont&id=$hid2'>Показать переписку >></a>";
$subject = "Новое письмо от: Система";
$adds="From: "system@$_SERVER[HTTP_HOST]" <system@$_SERVER[HTTP_HOST]>n";
$adds .= "Content-Type: text/html; charset=utf-8n";
mail($ank['email'],'=?utf-8?B?'.base64_encode($subject).'?=',$msg_email,$adds);
}
if ($ank['email_user_mail']==1 && $user_id!=0 && $ank['email'])
{
$msg_email = "$user[nick] пишет:<br>";
$msg_email .= output_text($msg, 0)."<br/><h1><a href='http://$_SERVER[HTTP_HOST]/mail/?act=cont&id=$hid2'>Показать переписку >></a>";
$subject = "Новое письмо от: $user[nick]";
$adds="From: "system@$_SERVER[HTTP_HOST]" <system@$_SERVER[HTTP_HOST]>n";
$adds .= "Content-Type: text/html; charset=utf-8n";
mail($ank['email'],'=?utf-8?B?'.base64_encode($subject).'?=',$msg_email,$adds);
}
return $hid;
}
?>