1225 lines
59 KiB
PHP
1225 lines
59 KiB
PHP
|
|
<?php
|
|||
|
|
|
|||
|
|
set_time_limit(0);
|
|||
|
|
|
|||
|
|
include $_SERVER['DOCUMENT_ROOT'] . '/engine/PhpImap/Mailbox.php';
|
|||
|
|
include $_SERVER['DOCUMENT_ROOT'] . '/engine/PhpImap/IncomingMailHeader.php';
|
|||
|
|
include $_SERVER['DOCUMENT_ROOT'] . '/engine/PhpImap/IncomingMail.php';
|
|||
|
|
include $_SERVER['DOCUMENT_ROOT'] . '/engine/PhpImap/IncomingMailAttachment.php';
|
|||
|
|
include $_SERVER['DOCUMENT_ROOT'] . '/engine/PhpImap/DataPartInfo.php';
|
|||
|
|
require_once($_SERVER['DOCUMENT_ROOT']."/engine/simple_html_dom.php");
|
|||
|
|
|
|||
|
|
class ParseMailForClients {
|
|||
|
|
|
|||
|
|
public static function parseStats($mdb, $conf = null) {
|
|||
|
|
|
|||
|
|
$debug = false;
|
|||
|
|
if (isset($_GET['dev']) || (isset($conf['debug']) && $conf['debug'] == 1))
|
|||
|
|
$debug = true;
|
|||
|
|
|
|||
|
|
if ($debug) {
|
|||
|
|
error_reporting(E_ALL | E_STRICT);
|
|||
|
|
ini_set('display_errors', 1);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (!$debug && isset($_SESSION['id'])) // закрываем парсинг если не отладка и есть сессия
|
|||
|
|
return;
|
|||
|
|
|
|||
|
|
if (!is_null($conf['mailbox'])) {
|
|||
|
|
$mailbox = new PhpImap\Mailbox(
|
|||
|
|
$conf['mailbox']['imap'], // IMAP server and mailbox folder
|
|||
|
|
$conf['mailbox']['login'], // Username for the before configured mailbox
|
|||
|
|
$conf['mailbox']['password'], // Password for the before configured username
|
|||
|
|
__DIR__, // Directory, where attachments will be saved (optional)
|
|||
|
|
$conf['mailbox']['encoding'] // Server encoding (optional)
|
|||
|
|
);
|
|||
|
|
} else {
|
|||
|
|
$mailbox = new PhpImap\Mailbox(
|
|||
|
|
'{imap.yandex.ru:993/imap/ssl}INBOX', // IMAP server and mailbox folder
|
|||
|
|
'lidy.reclama@yandex.ru', // Username for the before configured mailbox
|
|||
|
|
'lidyeclama', // Password for the before configured username
|
|||
|
|
__DIR__, // Directory, where attachments will be saved (optional)
|
|||
|
|
'UTF-8' // Server encoding (optional)
|
|||
|
|
);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
$target_uid = null;
|
|||
|
|
if (isset($_GET['target_uid']))
|
|||
|
|
$target_uid = (int)$_GET['target_uid'];
|
|||
|
|
|
|||
|
|
//var_export($mailbox);
|
|||
|
|
|
|||
|
|
try {
|
|||
|
|
// Get all emails (messages)
|
|||
|
|
// PHP.net imap_search criteria: http://php.net/manual/en/function.imap-search.php
|
|||
|
|
|
|||
|
|
if (isset($conf['from_sender'])) {
|
|||
|
|
$mailsIds = $mailbox->searchMailbox('ALL FROM "'.trim($conf['from_sender']).'"');
|
|||
|
|
} else {
|
|||
|
|
|
|||
|
|
$date = date("j F Y", strtotime('-1 day'));
|
|||
|
|
if($debug){
|
|||
|
|
$date = '19 July 2024';
|
|||
|
|
echo $date.'***';
|
|||
|
|
var_dump($target_uid);
|
|||
|
|
}
|
|||
|
|
if (!is_null($target_uid) || (
|
|||
|
|
(int)$conf['id_agent'] == 11082 && ($conf['track_code'] == 'last_checked_mail4_id' || $conf['track_code'] == 'last_checked_mail5_id')
|
|||
|
|
) || (
|
|||
|
|
(int)$conf['id_agent'] == 17453 && $conf['track_code'] == 'last_checked_mail32_id'
|
|||
|
|
) || (
|
|||
|
|
(int)$conf['id_agent'] == 10429 && ($conf['track_code'] == 'last_checked_mail14_id' || $conf['track_code'] == 'last_checked_mail16_id' || $conf['track_code'] == 'last_checked_mail141_id')
|
|||
|
|
) || (
|
|||
|
|
(int)$conf['id_agent'] == 14453 && $conf['track_code'] == 'last_checked_mail15_id'
|
|||
|
|
)
|
|||
|
|
)
|
|||
|
|
$mailsIds = $mailbox->searchMailbox('ALL');
|
|||
|
|
else if ((int)$conf['id_agent'] == 13154 && $date == '19 July 2024'){
|
|||
|
|
echo "******";
|
|||
|
|
$mailsIds = $mailbox->searchMailBox('SINCE "'.date('d-M-Y').'"');
|
|||
|
|
} else
|
|||
|
|
$mailsIds = $mailbox->searchMailbox('SINCE "'.$date.'"');
|
|||
|
|
}
|
|||
|
|
if($debug){
|
|||
|
|
var_dump($mailsIds);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
} catch(PhpImap\Exceptions\ConnectionException $ex) {
|
|||
|
|
echo "IMAP connection failed: " . $ex;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// If $mailsIds is empty, no emails could be found
|
|||
|
|
if(!$mailsIds) {
|
|||
|
|
echo 'Mailbox is empty';
|
|||
|
|
} else {
|
|||
|
|
|
|||
|
|
if (!is_null($conf['mailbox']))
|
|||
|
|
echo '<h3>Get mails from ' . $conf['mailbox']['login']." at ".date('d.m.Y H:i:s')."</h3>";
|
|||
|
|
|
|||
|
|
$latest_uid = 0;
|
|||
|
|
if ($debug && isset($_GET['latest_uid'])) {
|
|||
|
|
$latest_uid = intval($_GET['latest_uid']);
|
|||
|
|
} else {
|
|||
|
|
// обходим все ИД и смотрим, какие мы еще не обрабатывали
|
|||
|
|
$sql = "SELECT `value` FROM `params` WHERE `code` = 'last_checked_mail_id'";
|
|||
|
|
|
|||
|
|
if (isset($conf['track_code']))
|
|||
|
|
$sql = "SELECT `value` FROM `params` WHERE `code` = '{$conf['track_code']}'";
|
|||
|
|
|
|||
|
|
$result = mysql_query($sql, $mdb);
|
|||
|
|
$m = mysql_fetch_row($result);
|
|||
|
|
$latest_uid = $m[0];
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (!is_null($conf['id_agent']))
|
|||
|
|
$id_agent = (int)$conf['id_agent'];
|
|||
|
|
else
|
|||
|
|
$id_agent = 9799;
|
|||
|
|
|
|||
|
|
if (!is_null($conf['who_work_id']))
|
|||
|
|
$who_work_id = (int)$conf['who_work_id'];
|
|||
|
|
else
|
|||
|
|
$who_work_id = $id_agent;
|
|||
|
|
|
|||
|
|
$doer_id = null;
|
|||
|
|
if (!empty($conf['doer_id']))
|
|||
|
|
$doer_id = (int)$conf['doer_id'];
|
|||
|
|
|
|||
|
|
//var_export($mailsIds);
|
|||
|
|
|
|||
|
|
$messages = [];
|
|||
|
|
|
|||
|
|
if ($debug)
|
|||
|
|
echo '<h2 style="color: red;">Debug mode!</h2>';
|
|||
|
|
|
|||
|
|
echo '<p><b>Mails ID:</b> '.implode(', ', $mailsIds).'</p>';
|
|||
|
|
|
|||
|
|
//застройщики
|
|||
|
|
if ($id_agent == 19570 || $id_agent == 20947 || $id_agent == 20197) {
|
|||
|
|
$agency_id = $id_agent;
|
|||
|
|
} else {
|
|||
|
|
$agency_id = User::getAgencyIdForUser($id_agent);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
$agency_users_ids = User::getAllAgencyUsers($agency_id);
|
|||
|
|
|
|||
|
|
foreach ($mailsIds as $newId) {
|
|||
|
|
//echo $newId."\n";
|
|||
|
|
|
|||
|
|
if (($newId > $latest_uid) || (!is_null($target_uid) && $target_uid == $newId) || $debug) {
|
|||
|
|
|
|||
|
|
|
|||
|
|
$clients = new Clients();
|
|||
|
|
$requisitions = new Requisitions();
|
|||
|
|
|
|||
|
|
echo '<p><b>New e-mail ID:</b> '.$newId.'</p>';
|
|||
|
|
|
|||
|
|
$mail = $mailbox->getMail($newId);
|
|||
|
|
$mailInfo = $mailbox->getMailsInfo([$newId]);
|
|||
|
|
// getMailsInfo() возвращает массив объектов-заголовков, берём первый элемент
|
|||
|
|
$mailInfoItem = (!empty($mailInfo) && isset($mailInfo[0])) ? $mailInfo[0] : null;
|
|||
|
|
$mailFrom = (is_object($mailInfoItem) && isset($mailInfoItem->from)) ? $mailInfoItem->from : '';
|
|||
|
|
$html = str_get_html($mail->textHtml);
|
|||
|
|
|
|||
|
|
if (!empty($conf['subj_contains']) && strpos($mail->subject, $conf['subj_contains']) === false) {
|
|||
|
|
echo '<br/><span style="color: red">SKIP</span> Mail ID: ' . $newId . ' / Subject: ' . $mail->subject . ' / From: <' . $mailFrom . '>';
|
|||
|
|
continue;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// Пропускаем письма от неизвестных источников, если указаны в конфигурации парсера
|
|||
|
|
if (!empty($mailFrom) && !empty($conf['only_from'])) {
|
|||
|
|
if (!in_array($mailFrom, $conf['only_from'])) {
|
|||
|
|
echo '<br/><span style="color: red">SKIP</span> Mail ID: ' . $newId . ' / Subject: ' . $mail->subject . ' / From: <' . $mailFrom . '>';
|
|||
|
|
continue;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if ($debug)
|
|||
|
|
echo '<br/><span style="color: darkgreen">Processing</span> Mail ID: '.$newId.' / Subject: '.$mail->subject.' / From: <'.$mailFrom.'>';
|
|||
|
|
|
|||
|
|
if ($debug) {
|
|||
|
|
echo 'RAW: ' . '<textarea style="max-height: 320px;" rows="6">' . $html . '</textarea><br>';
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if ((int)$conf['id_agent'] == 11082 && ($conf['track_code'] == 'last_checked_mail13_id' || $conf['track_code'] == 'last_checked_mail4_id' || $conf['track_code'] == 'last_checked_mail5_id' || $conf['track_code'] == 'last_checked_mail7_id' || $conf['track_code'] == 'last_checked_mail8_id' || $conf['track_code'] == 'last_checked_mail11_id')) {
|
|||
|
|
$body = strip_tags(trim($mail->textPlain), 'br,p,strong,h2');
|
|||
|
|
$body = var_export($body, true);
|
|||
|
|
$body = ltrim($body, "'");
|
|||
|
|
$body = rtrim($body, "'");
|
|||
|
|
} else {
|
|||
|
|
if ((int)$conf['id_agent'] == 18763 && $conf['track_code'] == 'last_checked_mail31_id') {
|
|||
|
|
$body = strip_tags(trim($mail->textPlain), 'br,p,strong,h2');
|
|||
|
|
$body = var_export($body, true);
|
|||
|
|
$body = ltrim($body, "'");
|
|||
|
|
$body = rtrim($body, "'");
|
|||
|
|
} else {
|
|||
|
|
$body = strip_tags($html->innertext, '<br>,br,p,strong,h2');
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if ((int)$id_agent == 10429 || (int)$id_agent == 17453 || (int)$id_agent == 19932)
|
|||
|
|
$body = preg_replace('/\s+/', ' ', $body);
|
|||
|
|
|
|||
|
|
echo 'Mail: ' . '<textarea style="max-height: 320px;" rows="6">' . $body . '</textarea>';
|
|||
|
|
|
|||
|
|
$phone = '';
|
|||
|
|
$fio = '';
|
|||
|
|
$mail = '';
|
|||
|
|
$tag_name = '';
|
|||
|
|
$utm = '';
|
|||
|
|
$target_site = null;
|
|||
|
|
if ((int)$id_agent == 13154) {
|
|||
|
|
//Приведи друга
|
|||
|
|
$phoneFriend = false;
|
|||
|
|
$fioFriand = false;
|
|||
|
|
$clientIdFriand = 0;
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if ((int)$id_agent == 11082 || (int)$id_agent == 10429 || (int)$id_agent == 19932 || (int)$id_agent == 17453 || (int)$id_agent == 14453 || ((int)$conf['id_agent'] == 18763 && $conf['track_code'] == 'last_checked_mail31_id')) {
|
|||
|
|
|
|||
|
|
$body_cl = cleanHtml($body, '<p><br><strong><em><ul><ol><li>');
|
|||
|
|
|
|||
|
|
if ((int)$id_agent == 10429 || (int)$id_agent == 17453) {
|
|||
|
|
$body = str_replace('Имя ', "\r\nИмя: ", $body);
|
|||
|
|
$body = str_replace('Телефон ', "\r\nТелефон: ", $body);
|
|||
|
|
$body = str_replace('Цель покупки недвижимости? ', "\r\nЦель покупки недвижимости? ", $body);
|
|||
|
|
echo 'Mail2: ' . '<textarea style="max-height: 320px;" rows="6">' . $body . '</textarea>';
|
|||
|
|
} else if ((int)$id_agent == 14453) {
|
|||
|
|
$body = str_replace(',<br/>', "<br/>", $body);
|
|||
|
|
$body_cl = cleanHtml($body, '');
|
|||
|
|
$body = str_replace('ФИО :', "\r\nИмя: ", $body);
|
|||
|
|
$body = str_replace('Телефон :', "\r\nТелефон: ", $body);
|
|||
|
|
$body = str_replace('Описание :', "\r\nОписание: ", $body);
|
|||
|
|
$body = str_replace('Комментарий :', "\r\nКомментарий: ", $body);
|
|||
|
|
echo 'Mail2: ' . '<textarea style="max-height: 320px;" rows="6">' . $body . '</textarea>';
|
|||
|
|
} else if ((int)$id_agent == 18763) {
|
|||
|
|
$body = str_replace(',<br/>', "<br/>", $body);
|
|||
|
|
$body_cl = cleanHtml($body, '');
|
|||
|
|
$body = str_replace('Имя:', "\r\nИмя: ", $body);
|
|||
|
|
$body = str_replace('Телефон:', "\r\nТелефон: ", $body);
|
|||
|
|
$body = str_replace('Вариант покупки:', "\r\nВариант покупки: ", $body);
|
|||
|
|
$body = str_replace('Проект:', "\r\nПроект: ", $body);
|
|||
|
|
$body = str_replace('Одобрено:', "\r\nОдобрено: ", $body);
|
|||
|
|
echo 'Mail2: ' . '<textarea style="max-height: 320px;" rows="6">' . $body . '</textarea>';
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if ((int)$id_agent == 11082) {
|
|||
|
|
if (strpos($body, "Сообщение с сайта skyview-invest.ru") !== false) {
|
|||
|
|
$html->innertext = str_replace("с сайта skyview-invest.ru", '', $html->innertext);
|
|||
|
|
$target_site = 'skyview-invest.ru';
|
|||
|
|
} else if (strpos($body_cl, "с сайта astris.urbanproperty.moscow") !== false) {
|
|||
|
|
$html->innertext = str_replace("с сайта astris.urbanproperty.moscow", '', $html->innertext);
|
|||
|
|
$target_site = 'astris.urbanproperty.moscow';
|
|||
|
|
} else if (strpos($body_cl, "с сайта astris.urban-property.moscow") !== false) {
|
|||
|
|
$html->innertext = str_replace("с сайта astris.urbanproperty.moscow", '', $html->innertext);
|
|||
|
|
$target_site = 'astris.urbanproperty.moscow';
|
|||
|
|
} else if (strpos($body_cl, "с сайта hide.urbanproperty.moscow") !== false) {
|
|||
|
|
$html->innertext = str_replace("с сайта hide.urbanproperty.moscow", '', $html->innertext);
|
|||
|
|
$target_site = 'hide.urbanproperty.moscow';
|
|||
|
|
} else if (strpos($body_cl, "с сайта hide.urban-property.moscow") !== false) {
|
|||
|
|
$html->innertext = str_replace("с сайта hide.urbanproperty.moscow", '', $html->innertext);
|
|||
|
|
$target_site = 'hide.urbanproperty.moscow';
|
|||
|
|
} else if (strpos($body_cl, "с сайта famous.urbanproperty.moscow") !== false) {
|
|||
|
|
$html->innertext = str_replace("с сайта famous.urbanproperty.moscow", '', $html->innertext);
|
|||
|
|
$target_site = 'famous.urbanproperty.moscow';
|
|||
|
|
} else if (strpos($body_cl, "с сайта famous.urban-property.moscow") !== false) {
|
|||
|
|
$html->innertext = str_replace("с сайта famous.urbanproperty.moscow", '', $html->innertext);
|
|||
|
|
$target_site = 'famous.urbanproperty.moscow';
|
|||
|
|
} else if (strpos($body_cl, "с сайта highgarden.urbanproperty.moscow") !== false) {
|
|||
|
|
$html->innertext = str_replace("с сайта highgarden.urbanproperty.moscow", '', $html->innertext);
|
|||
|
|
$target_site = 'highgarden.urbanproperty.moscow';
|
|||
|
|
} else if (strpos($body_cl, "с сайта highgarden.urban-property.moscow") !== false) {
|
|||
|
|
$html->innertext = str_replace("с сайта highgarden.urbanproperty.moscow", '', $html->innertext);
|
|||
|
|
$target_site = 'highgarden.urbanproperty.moscow';
|
|||
|
|
} else if (strpos($body_cl, "с сайта vesper.urbanproperty.moscow") !== false) {
|
|||
|
|
$html->innertext = str_replace("с сайта vesper.urbanproperty.moscow", '', $html->innertext);
|
|||
|
|
$target_site = 'vesper.urbanproperty.moscow';
|
|||
|
|
} else if (strpos($body_cl, "с сайта vesper.urban-property.moscow") !== false) {
|
|||
|
|
$html->innertext = str_replace("с сайта vesper.urbanproperty.moscow", '', $html->innertext);
|
|||
|
|
$target_site = 'vesper.urbanproperty.moscow';
|
|||
|
|
} else if (strpos($body_cl, "с сайта yards.urbanproperty.moscow") !== false) {
|
|||
|
|
$html->innertext = str_replace("с сайта yards.urbanproperty.moscow", '', $html->innertext);
|
|||
|
|
$target_site = 'yards.urbanproperty.moscow';
|
|||
|
|
} else if (strpos($body_cl, "с сайта yards.urban-property.moscow") !== false) {
|
|||
|
|
$html->innertext = str_replace("с сайта yards.urbanproperty.moscow", '', $html->innertext);
|
|||
|
|
$target_site = 'yards.urbanproperty.moscow';
|
|||
|
|
} else if (strpos($body_cl, "с сайта mecenat.urbanproperty.moscow") !== false) {
|
|||
|
|
$html->innertext = str_replace("с сайта mecenat.urbanproperty.moscow", '', $html->innertext);
|
|||
|
|
$target_site = 'mecenat.urbanproperty.moscow';
|
|||
|
|
} else if (strpos($body_cl, "с сайта mecenat.urban-property.moscow") !== false) {
|
|||
|
|
$html->innertext = str_replace("с сайта mecenat.urbanproperty.moscow", '', $html->innertext);
|
|||
|
|
$target_site = 'mecenat.urbanproperty.moscow';
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (preg_match("/Имя:\s*(.*?)$/m", $body, $match) !== false) {
|
|||
|
|
|
|||
|
|
if (!empty($match[1])) {
|
|||
|
|
$fio = trim($match[1]);
|
|||
|
|
//strpos()
|
|||
|
|
// if(strpos($fio, '<br>') === true){
|
|||
|
|
$temp_fio = explode('<br>',$fio);
|
|||
|
|
if(isset($temp_fio[0])){
|
|||
|
|
$fio = $temp_fio[0];
|
|||
|
|
}
|
|||
|
|
// }
|
|||
|
|
|
|||
|
|
$fio = strip_tags($fio);
|
|||
|
|
}
|
|||
|
|
} else if (preg_match("/ФИО:\s+(.*?)[\r\n|\r|\n]/m", $body, $match) !== false) {
|
|||
|
|
if (!empty($match[1])) {
|
|||
|
|
$fio = trim($match[1]);
|
|||
|
|
$fio = strip_tags($fio);
|
|||
|
|
}
|
|||
|
|
} else if (preg_match("/Имя:\s+(.*?)[\r\n|\r|\n]/m", $body, $match) !== false) {
|
|||
|
|
if (!empty($match[1])) {
|
|||
|
|
$fio = trim($match[1]);
|
|||
|
|
$fio = strip_tags($fio);
|
|||
|
|
}
|
|||
|
|
} else if (preg_match("/<p><strong>От кого:<\/strong>\s+(.*?)<\/p>/m", $html->innertext, $match) !== false) {
|
|||
|
|
if(!empty($match[1])) {
|
|||
|
|
$fio = str_replace(' ', '', $match[1]);
|
|||
|
|
$fio = str_replace(' ', '', htmlentities($fio));
|
|||
|
|
$fio = str_replace("\xc2\xa0",' ',$fio);
|
|||
|
|
$fio = trim($fio);
|
|||
|
|
$fio = strip_tags($fio);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (preg_match("/Телефон:\s*(.*?)$/m", $body, $match) !== false) {
|
|||
|
|
if (!empty($match[1])) {
|
|||
|
|
$phone = str_replace(' ', '', trim($match[1]));
|
|||
|
|
//var_dump($phone);
|
|||
|
|
$temp_phone = explode('<br>',$phone);
|
|||
|
|
if(isset($temp_phone[0])){
|
|||
|
|
$phone = $temp_phone[0];
|
|||
|
|
}
|
|||
|
|
//echo '/////';
|
|||
|
|
|
|||
|
|
|
|||
|
|
$phone = str_replace('.', '', $phone);
|
|||
|
|
$phone = str_replace('-', '', $phone);
|
|||
|
|
$phone = str_replace('(', '', $phone);
|
|||
|
|
$phone = str_replace(')', '', $phone);
|
|||
|
|
$phone = ParseMailForClients::ver_phone($phone);
|
|||
|
|
if( strlen($phone) > 15 ) {
|
|||
|
|
$phone = mb_substr($phone, 0, 15);
|
|||
|
|
// $phone = preg_replace("/[a-zA-Zа-яА-Я]/", '', $phone);
|
|||
|
|
$phone = preg_replace("/[^0-9]/", "", $phone);
|
|||
|
|
}
|
|||
|
|
// var_dump( $phone);
|
|||
|
|
}
|
|||
|
|
} else if (preg_match("/Номер:\s*(.*?)$/m", $body, $match) !== false) {
|
|||
|
|
if (!empty($match[1])) {
|
|||
|
|
$phone = str_replace(' ', '', trim($match[1]));
|
|||
|
|
$phone = str_replace('.', '', $phone);
|
|||
|
|
$phone = str_replace('-', '', $phone);
|
|||
|
|
$phone = str_replace('(', '', $phone);
|
|||
|
|
$phone = str_replace(')', '', $phone);
|
|||
|
|
$phone = ParseMailForClients::ver_phone($phone);
|
|||
|
|
}
|
|||
|
|
} else if (preg_match("/Телефон:\s+(.*?)[\r\n|\r|\n]/m", $body, $match) !== false) {
|
|||
|
|
if (!empty($match[1])) {
|
|||
|
|
$phone = str_replace(' ', '', trim($match[1]));
|
|||
|
|
$phone = str_replace('.', '', $phone);
|
|||
|
|
$phone = str_replace('-', '', $phone);
|
|||
|
|
$phone = str_replace('(', '', $phone);
|
|||
|
|
$phone = str_replace(')', '', $phone);
|
|||
|
|
$phone = ParseMailForClients::ver_phone($phone);
|
|||
|
|
}
|
|||
|
|
} else if (preg_match("/Телефон:\s*(.*?)$/m", $body, $match) !== false) {
|
|||
|
|
if (!empty($match[1])) {
|
|||
|
|
$phone = str_replace(' ', '', trim($match[1]));
|
|||
|
|
$phone = str_replace('.', '', $phone);
|
|||
|
|
$phone = str_replace('-', '', $phone);
|
|||
|
|
$phone = str_replace('(', '', $phone);
|
|||
|
|
$phone = str_replace(')', '', $phone);
|
|||
|
|
$phone = ParseMailForClients::ver_phone($phone);
|
|||
|
|
}
|
|||
|
|
} else if (preg_match("/Номер телефона:\s*(.*?)$/m", $body, $match) !== false) {
|
|||
|
|
if (!empty($match[1])) {
|
|||
|
|
$phone = str_replace(' ', '', trim($match[1]));
|
|||
|
|
$phone = str_replace('.', '', $phone);
|
|||
|
|
$phone = str_replace('-', '', $phone);
|
|||
|
|
$phone = str_replace('(', '', $phone);
|
|||
|
|
$phone = str_replace(')', '', $phone);
|
|||
|
|
$phone = ParseMailForClients::ver_phone($phone);
|
|||
|
|
}
|
|||
|
|
} else if (preg_match("/<p><strong>Телефон:<\/strong>\s+(.*?)<\/p>/m", $html->innertext, $match) !== false) {
|
|||
|
|
if(!empty($match[1])) {
|
|||
|
|
$phone = str_replace(' ', '', $match[1]);
|
|||
|
|
$phone = str_replace('(', '', $phone);
|
|||
|
|
$phone = str_replace(')', '', $phone);
|
|||
|
|
$phone = str_replace('-', '', $phone);
|
|||
|
|
$phone = str_replace(' ', '', $phone);
|
|||
|
|
$phone = str_replace(' ', '', $phone);
|
|||
|
|
$phone = str_replace(' ', '', htmlentities($phone));
|
|||
|
|
$phone = str_replace("\xc2\xa0",' ',$phone);
|
|||
|
|
$phone = trim($phone);
|
|||
|
|
$phone = strip_tags($phone);
|
|||
|
|
$phone = ParseMailForClients::ver_phone($phone);
|
|||
|
|
}
|
|||
|
|
} else if (preg_match("/<p><strong>Номер:<\/strong>\s+(.*?)<\/p>/m", $html->innertext, $match) !== false) {
|
|||
|
|
if(!empty($match[1])) {
|
|||
|
|
$phone = str_replace(' ', '', $match[1]);
|
|||
|
|
$phone = str_replace('(', '', $phone);
|
|||
|
|
$phone = str_replace(')', '', $phone);
|
|||
|
|
$phone = str_replace('-', '', $phone);
|
|||
|
|
$phone = str_replace(' ', '', $phone);
|
|||
|
|
$phone = str_replace(' ', '', $phone);
|
|||
|
|
$phone = str_replace(' ', '', htmlentities($phone));
|
|||
|
|
$phone = str_replace("\xc2\xa0",' ',$phone);
|
|||
|
|
$phone = trim($phone);
|
|||
|
|
$phone = strip_tags($phone);
|
|||
|
|
$phone = ParseMailForClients::ver_phone($phone);
|
|||
|
|
}
|
|||
|
|
} if (preg_match("/Телефон\s*(.*?)$/m", $body, $match) !== false) {
|
|||
|
|
if (!empty($match[1])) {
|
|||
|
|
$phone = str_replace(' ', '', trim($match[1]));
|
|||
|
|
//var_dump($phone);
|
|||
|
|
$temp_phone = explode('<br>',$phone);
|
|||
|
|
if(isset($temp_phone[0])){
|
|||
|
|
$phone = $temp_phone[0];
|
|||
|
|
}
|
|||
|
|
//echo '/////';
|
|||
|
|
|
|||
|
|
|
|||
|
|
$phone = str_replace('.', '', $phone);
|
|||
|
|
$phone = str_replace('-', '', $phone);
|
|||
|
|
$phone = str_replace('(', '', $phone);
|
|||
|
|
$phone = str_replace(')', '', $phone);
|
|||
|
|
$phone = ParseMailForClients::ver_phone($phone);
|
|||
|
|
if( strlen($phone) > 15 ) {
|
|||
|
|
$phone = mb_substr($phone, 0, 15);
|
|||
|
|
// $phone = preg_replace("/[a-zA-Zа-яА-Я]/", '', $phone);
|
|||
|
|
$phone = preg_replace("/[^0-9]/", "", $phone);
|
|||
|
|
}
|
|||
|
|
// var_dump( $phone);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
if (preg_match("/Цель покупки недвижимости?\s*(.*?)$/m", $body, $match) !== false) {
|
|||
|
|
|
|||
|
|
if (!empty($match[1])) {
|
|||
|
|
$utm = $match[0];
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (!empty($phone))
|
|||
|
|
$phone = str_replace('+', '+', $phone);
|
|||
|
|
|
|||
|
|
if (preg_match("/Почта:\s+(.*?)[\r\n|\r|\n]/m", $body, $match) !== false) {
|
|||
|
|
if (!empty($match[1])) {
|
|||
|
|
$mail = trim($match[1]);
|
|||
|
|
}
|
|||
|
|
} elseif (preg_match("/<p><strong>E-mail:<\/strong>\s+(.*?)<\/p>/m", $html->innertext, $match) !== false) {
|
|||
|
|
if(!empty($match[1])) {
|
|||
|
|
$mail = str_replace(' ', '', $match[1]);
|
|||
|
|
$mail = str_replace(' ', '', $mail);
|
|||
|
|
$mail = str_replace(' ', '', htmlentities($mail));
|
|||
|
|
$mail = str_replace("\xc2\xa0",' ',$mail);
|
|||
|
|
$mail = trim($mail);
|
|||
|
|
$mail = strip_tags($mail);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (preg_match("/Тег:\s+(.*?)[\r\n|\r|\n]/m", $body, $match) !== false) {
|
|||
|
|
if(!empty($match[1])) {
|
|||
|
|
$tag_name = trim($match[1]);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
} else {
|
|||
|
|
|
|||
|
|
if ((int)$id_agent == 15533) {
|
|||
|
|
$body = str_replace("<br><br>", '<br>', $body);
|
|||
|
|
if (strpos($body, "<br>") !== false) {
|
|||
|
|
if ($debug) {
|
|||
|
|
echo "sdfasdf sad";
|
|||
|
|
}
|
|||
|
|
$value = explode("<br>", $body);
|
|||
|
|
} else {
|
|||
|
|
if ($debug) {
|
|||
|
|
echo "sdfasdf sad!!!";
|
|||
|
|
}
|
|||
|
|
$value = explode("<br>", $body);
|
|||
|
|
}
|
|||
|
|
} else {
|
|||
|
|
if ((int)$id_agent == 18763 || (int)$id_agent == 20947) {
|
|||
|
|
$body_cl = cleanHtml($body, '<p><br><strong><em><ul><ol><li>');
|
|||
|
|
|
|||
|
|
if ((int)$id_agent == 20947) {
|
|||
|
|
$body_cl = str_replace('a { text-decoration: none; color: #212121; }h3{color: #212121;}.btn.btn-outline.btn-default{border: solid 1px rgba(220, 220, 220, 0.5);margin-top: 15px; margin-right: 10px;background: transparent;color: #212121 !important;padding: 10px 25px; border-radius: 2px; outline: none; box-shadow: none;transition: all 0.3s ease;display: inline-block;margin-bottom: 0; font-size: 14px; font-weight: 400; line-height: 1.42857143; text-align: center; white-space: nowrap; vertical-align: middle; -ms-touch-action: manipulation; touch-action: manipulation; cursor: pointer; -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none;}.btn.btn-outline.btn-default:hover{border: solid 1px gainsboro;background-color: rgba(220, 220, 220, 0.5);}', '', $body_cl);
|
|||
|
|
$body_cl = str_replace('a { text-decoration: none; }h3{color: #212121;}.btn.btn-outline.btn-default{border: solid 1px rgba(220, 220, 220, 0.5);margin-top: 15px; margin-right: 10px;background: transparent;color: #212121 !important;padding: 10px 25px; border-radius: 2px; outline: none; box-shadow: none;transition: all 0.3s ease;display: inline-block;margin-bottom: 0; font-size: 14px; font-weight: 400; line-height: 1.42857143; text-align: center; white-space: nowrap; vertical-align: middle; -ms-touch-action: manipulation; touch-action: manipulation; cursor: pointer; -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none;}.btn.btn-outline.btn-default:hover{border: solid 1px gainsboro;background-color: rgba(220, 220, 220, 0.5);}', '', $body_cl);
|
|||
|
|
$body_cl = trim($body_cl);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
$value = explode("<br/>", $body_cl);
|
|||
|
|
|
|||
|
|
} else {
|
|||
|
|
$value = explode("<br>", $html->innertext);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
foreach ($value as $val) {
|
|||
|
|
|
|||
|
|
if (empty(trim($val)) || strpos('---------', $val))
|
|||
|
|
continue;
|
|||
|
|
|
|||
|
|
echo '<p><b>Check value:</b> ' . '<em>' . var_export($val, true) . '</em></p>';
|
|||
|
|
|
|||
|
|
if (strpos($val, "Вы получили новое сообщение от:") !== false) {
|
|||
|
|
$fio = str_replace('Вы получили новое сообщение от: ', '', $val);
|
|||
|
|
$fio = trim($fio);
|
|||
|
|
$fio = strip_tags($fio);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (strpos($val, "Телефон") !== false) {
|
|||
|
|
$phone = str_replace('Телефон:', '', $val);
|
|||
|
|
$phone = str_replace('Телефон', '', $phone);
|
|||
|
|
$phone = str_replace('(', '', $phone);
|
|||
|
|
$phone = str_replace(')', '', $phone);
|
|||
|
|
$phone = str_replace('-', '', $phone);
|
|||
|
|
$phone = str_replace(' ', '', $phone);
|
|||
|
|
$phone = str_replace(' ', '', $phone);
|
|||
|
|
$phone = str_replace('<br>', '', $phone);
|
|||
|
|
$phone = str_replace(' ', '', htmlentities($phone));
|
|||
|
|
$phone = str_replace('<br>', '', $phone);
|
|||
|
|
$phone = str_replace("\xc2\xa0",' ',$phone);
|
|||
|
|
$phone = trim($phone);
|
|||
|
|
$phone = strip_tags($phone);
|
|||
|
|
$phone = ParseMailForClients::ver_phone($phone);
|
|||
|
|
} else {
|
|||
|
|
if ((int)$id_agent != 13154) {
|
|||
|
|
if (strpos($val, "E-mail") !== false) {
|
|||
|
|
$mail = str_replace('E-mail: ', '', $val);
|
|||
|
|
$mail = str_replace('E-mail', '', $mail);
|
|||
|
|
$mail = str_replace(' ', '', $mail);
|
|||
|
|
$mail = str_replace(' ', '', htmlentities($mail));
|
|||
|
|
$mail = str_replace("\xc2\xa0",' ',$mail);
|
|||
|
|
$mail = trim($mail);
|
|||
|
|
$mail = strip_tags($mail);
|
|||
|
|
} else {
|
|||
|
|
if (strpos($val, "ФИО") !== false) {
|
|||
|
|
$fio = str_replace('ФИО: ', '', $val);
|
|||
|
|
$fio = str_replace('ФИО:', '', $val);
|
|||
|
|
$fio = str_replace('ФИО', '', $fio);
|
|||
|
|
$fio = str_replace(' ', '', $fio);
|
|||
|
|
$fio = str_replace("<br>", '', htmlentities($fio));
|
|||
|
|
$fio = str_replace(' ', '', htmlentities($fio));
|
|||
|
|
$fio = str_replace("\xc2\xa0",' ',$fio);
|
|||
|
|
$fio = trim($fio);
|
|||
|
|
$fio = strip_tags($fio);
|
|||
|
|
} else if (strpos($val, "От кого") !== false) {
|
|||
|
|
$fio = str_replace('От кого: ', '', $val);
|
|||
|
|
$fio = str_replace('От кого', '', $fio);
|
|||
|
|
$fio = str_replace(' ', '', $fio);
|
|||
|
|
$fio = str_replace(' ', '', htmlentities($fio));
|
|||
|
|
$fio = str_replace("\xc2\xa0",' ',$fio);
|
|||
|
|
$fio = trim($fio);
|
|||
|
|
$fio = strip_tags($fio);
|
|||
|
|
} else if (strpos($val, "Имя") !== false) {
|
|||
|
|
$fio = str_replace('Имя: ', '', $val);
|
|||
|
|
$fio = str_replace('Имя', '', $fio);
|
|||
|
|
$fio = str_replace(' ', '', $fio);
|
|||
|
|
$fio = str_replace(' ', '', htmlentities($fio));
|
|||
|
|
$fio = str_replace("\xc2\xa0",' ',$fio);
|
|||
|
|
$fio = trim($fio);
|
|||
|
|
$fio = strip_tags($fio);
|
|||
|
|
} else {
|
|||
|
|
if ((int)$id_agent == 20947) {
|
|||
|
|
$utm = $utm . $val . ' <br/>';
|
|||
|
|
} else {
|
|||
|
|
$utm = $utm . $val . '; ';
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if ((int)$id_agent == 13154) {
|
|||
|
|
//Приведи друга
|
|||
|
|
if (strpos($val, "E-mail") !== false) {
|
|||
|
|
$mail = str_replace('E-mail: ', '', $val);
|
|||
|
|
$mail = str_replace('E-mail', '', $mail);
|
|||
|
|
$mail = str_replace(' ', '', $mail);
|
|||
|
|
$mail = str_replace(' ', '', htmlentities($mail));
|
|||
|
|
$mail = str_replace("\xc2\xa0",' ',$mail);
|
|||
|
|
$mail = trim($mail);
|
|||
|
|
$mail = strip_tags($mail);
|
|||
|
|
} else
|
|||
|
|
if(strpos($val, "FriendPhone:") !== false){
|
|||
|
|
|
|||
|
|
if (preg_match("/FriendPhone:\s+(.*?)$/m", strip_tags($val), $match) !== false) {
|
|||
|
|
if (!empty($match[1])) {
|
|||
|
|
$phone = trim($match[1]);
|
|||
|
|
$phone = strip_tags($phone);
|
|||
|
|
$phone = str_replace('(', '', $phone);
|
|||
|
|
$phone = str_replace(')', '', $phone);
|
|||
|
|
$phone = str_replace('-', '', $phone);
|
|||
|
|
$phone = str_replace(' ', '', $phone);
|
|||
|
|
$phone = str_replace(' ', '', $phone);
|
|||
|
|
$phone = str_replace('<br>', '', $phone);
|
|||
|
|
$phone = str_replace(' ', '', htmlentities($phone));
|
|||
|
|
$phone = str_replace('<br>', '', $phone);
|
|||
|
|
$phone = str_replace("\xc2\xa0",' ',$phone);
|
|||
|
|
$phone = trim($phone);
|
|||
|
|
$phone = ParseMailForClients::ver_phone($phone);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
if(strpos($val, "ClientPhone:") !== false){
|
|||
|
|
if (preg_match("/ClientPhone:\s+(.*?)$/m", strip_tags($val), $match) !== false) {
|
|||
|
|
if (!empty($match[1])) {
|
|||
|
|
$phoneFriend = trim($match[1]);
|
|||
|
|
$phoneFriend = strip_tags($phoneFriend);
|
|||
|
|
$phoneFriend = str_replace('(', '',$phoneFriend);
|
|||
|
|
$phoneFriend = str_replace(')', '', $phoneFriend);
|
|||
|
|
$phoneFriend = str_replace('-', '', $phoneFriend);
|
|||
|
|
$phoneFriend = str_replace(' ', '', $phoneFriend);
|
|||
|
|
$phoneFriend = str_replace(' ', '', $phoneFriend);
|
|||
|
|
$phoneFriend = str_replace('<br>', '', $phoneFriend);
|
|||
|
|
$phoneFriend = str_replace(' ', '', htmlentities($phoneFriend));
|
|||
|
|
$phoneFriend = str_replace('<br>', '', $phoneFriend);
|
|||
|
|
$phoneFriend = str_replace("\xc2\xa0",' ',$phoneFriend);
|
|||
|
|
$phoneFriend = trim($phoneFriend);
|
|||
|
|
$phoneFriend = ParseMailForClients::ver_phone($phoneFriend);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
if(strpos($val, "Client:") !== false){
|
|||
|
|
if (preg_match("/Client:\s+(.*?)$/m", strip_tags($val), $match) !== false) {
|
|||
|
|
if (!empty($match[1])) {
|
|||
|
|
$fioFriand = trim($match[1]);
|
|||
|
|
$fioFriand = strip_tags($fioFriand);
|
|||
|
|
$fioFriand = trim($fioFriand);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
if(strpos($val, "Friend:") !== false){
|
|||
|
|
if (preg_match("/Friend:\s+(.*?)$/m", strip_tags($val), $match) !== false) {
|
|||
|
|
if (!empty($match[1])) {
|
|||
|
|
$fio = trim($match[1]);
|
|||
|
|
$fio = strip_tags($fio);
|
|||
|
|
$fio = trim($fio);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
// парсим источник для АН КВС
|
|||
|
|
if($phoneFriend === false){
|
|||
|
|
if (strpos($val, "<p>ФИО: <br>Email:") !== false) {
|
|||
|
|
$fio = false;
|
|||
|
|
} else {
|
|||
|
|
if (preg_match("/ФИО:\s+(.*?)$/m", strip_tags($val), $match) !== false) {
|
|||
|
|
if (!empty($match[1])) {
|
|||
|
|
$fio = trim($match[1]);
|
|||
|
|
$fio = strip_tags($fio);
|
|||
|
|
}
|
|||
|
|
} else if (preg_match("/Имя -\s+(.*?)$/m", strip_tags($val), $match) !== false) {
|
|||
|
|
if (!empty($match[1])) {
|
|||
|
|
$fio = trim($match[1]);
|
|||
|
|
$fio = strip_tags($fio);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
if (preg_match("/Источник:\s+(.*?)$/m", strip_tags($val), $match) !== false) {
|
|||
|
|
if (!empty($match[1])) {
|
|||
|
|
$conf['source_name'] = trim($match[1]);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
/*var_dump($fio);
|
|||
|
|
var_dump($phone);
|
|||
|
|
var_dump($fioFriand);
|
|||
|
|
var_dump($phoneFriend);*/
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (!$fio)
|
|||
|
|
$fio = "Имя не указано";
|
|||
|
|
|
|||
|
|
if (!is_null($conf['client_funnel_id']))
|
|||
|
|
$client_funnel_id = (int)$conf['client_funnel_id'];
|
|||
|
|
else
|
|||
|
|
$client_funnel_id = 302;
|
|||
|
|
|
|||
|
|
if (!is_null($conf['req_funnel_id']))
|
|||
|
|
$req_funnel_id = (int)$conf['req_funnel_id'];
|
|||
|
|
else
|
|||
|
|
$req_funnel_id = 302;
|
|||
|
|
|
|||
|
|
if (!is_null($conf['req_type_id']))
|
|||
|
|
$req_type_id = (int)$conf['req_type_id'];
|
|||
|
|
else
|
|||
|
|
$req_type_id = null;
|
|||
|
|
|
|||
|
|
if (preg_match("/Номер телефона:\s*(.*?)$/m", $body, $match) !== false) {
|
|||
|
|
if (!empty($match[1])) {
|
|||
|
|
$phone = str_replace(' ', '', trim($match[1]));
|
|||
|
|
$phone = str_replace('.', '', $phone);
|
|||
|
|
$phone = str_replace('-', '', $phone);
|
|||
|
|
$phone = str_replace('(', '', $phone);
|
|||
|
|
$phone = str_replace(')', '', $phone);
|
|||
|
|
$phone = ParseMailForClients::ver_phone($phone);
|
|||
|
|
}
|
|||
|
|
} else if (preg_match("/Телефон:\s*(.*?)$/m", $body, $match) !== false) {
|
|||
|
|
if (!empty($match[1])) {
|
|||
|
|
$phone = str_replace(' ', '', trim($match[1]));
|
|||
|
|
$phone = str_replace('.', '', $phone);
|
|||
|
|
$phone = str_replace('-', '', $phone);
|
|||
|
|
$phone = str_replace('(', '', $phone);
|
|||
|
|
$phone = str_replace(')', '', $phone);
|
|||
|
|
$phone = ParseMailForClients::ver_phone($phone);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if ($phone) {
|
|||
|
|
$phone = str_replace('<br/>', '', $phone);
|
|||
|
|
if (strpos($phone, "+") === false) {
|
|||
|
|
$phone = "+" . $phone;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
$post = [];
|
|||
|
|
$post['phone'] = $phone;
|
|||
|
|
|
|||
|
|
if((int)$id_agent == 13154 && $phoneFriend !== false){
|
|||
|
|
|
|||
|
|
|
|||
|
|
$sqlF = "SELECT * FROM clients_friend WHERE phone='{$phoneFriend}'";
|
|||
|
|
$qF = mysql_query($sqlF, $mdb);
|
|||
|
|
if(mysql_num_rows($qF) > 0){
|
|||
|
|
$clientIdFriand = (int)mysql_fetch_assoc($qF)['id'];
|
|||
|
|
} else {
|
|||
|
|
$sqlFIn = "INSERT INTO clients_friend (phone, fio) VALUES ('{$phoneFriend}', '{$fioFriand}')";
|
|||
|
|
mysql_query($sqlFIn, $mdb);
|
|||
|
|
$clientIdFriand = mysql_insert_id();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if ((int)$id_agent == 11082 && !is_null($target_site))
|
|||
|
|
$utm = 'Заявка с сайта ' . $target_site . ".\r\n" . cleanHtml($html->innertext, '<p><br><strong><em><ul><ol><li>');
|
|||
|
|
else if ((int)$id_agent == 11082)
|
|||
|
|
$utm = 'Заявка с Facebook. ' . "\r\n" . cleanHtml($body, '<p><br><strong><em><ul><ol><li>');
|
|||
|
|
|
|||
|
|
if ((int)$id_agent == 14453) {
|
|||
|
|
$utm = cleanHtml($html->innertext, '<p><br><strong><em><ul><ol><li>');
|
|||
|
|
if (strpos($utm, "Правила отбраковки заявок") !== false) {
|
|||
|
|
$utm = substr($utm, 0, strpos($utm, "Правила отбраковки заявок"));
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if ((int)$id_agent == 10429 || (int)$id_agent == 17453 || (int)$id_agent == 19932) {
|
|||
|
|
$utm = cleanHtml($html->innertext, '<p><br><strong><em><ul><ol><li>');
|
|||
|
|
$utm = substr($utm, strpos($utm, "Новая заявка"));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if ((int)$id_agent == 18763 && $conf['track_code'] == 'last_checked_mail31_id') {
|
|||
|
|
$utm = cleanHtml($body_cl, '<p><br><strong><em><ul><ol><li>');
|
|||
|
|
$utm = substr($utm, 0, strpos($utm, "Это уведомление о том,"));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
$post['opis'] = mysql_real_escape_string($utm);
|
|||
|
|
$post['email'] = $mail;
|
|||
|
|
$post['fio'] = $fio;
|
|||
|
|
$post['id_agent'] = $id_agent;
|
|||
|
|
$post['funnel_id'] = $client_funnel_id;
|
|||
|
|
$post['stage'] = 1;
|
|||
|
|
|
|||
|
|
if((int)$id_agent == 13154 && $phoneFriend !== false){
|
|||
|
|
$post['opis'] = $utm = "Кто привел ФИО: " . $fioFriand ."<br>"."Кто привел телефон: " . $phoneFriend;
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (!is_null($conf['who_work_id']) && $id_agent != 13154) { // Для АН КВС не ставим отвественного (клиенты должны попадать в общие)
|
|||
|
|
$post['who_work'] = $who_work_id;
|
|||
|
|
$post['confirm'] = 1;
|
|||
|
|
} else {
|
|||
|
|
$post['who_work'] = 0;
|
|||
|
|
$post['confirm'] = 0;
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if ($id_agent == 13154){ // Для АН КВС не подтверждаем
|
|||
|
|
$post['confirm'] = false;
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
$idClient = null;
|
|||
|
|
$s = [];
|
|||
|
|
$t = [];
|
|||
|
|
|
|||
|
|
|
|||
|
|
// добавляем источник и теги АН Urban Property, АН КВС, АН BRG
|
|||
|
|
if ((int)$id_agent == 11082 || (int)$id_agent == 13154 || (int)$id_agent == 10429 || (int)$id_agent == 14453 || (int)$id_agent == 19570 || (int)$id_agent == 20947 || (int)$id_agent == 20197) {
|
|||
|
|
if((int)$id_agent == 13154 && $phoneFriend !== false){
|
|||
|
|
$conf['source_name'] = 'Приведи друга';
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
if (!is_null($conf['source_name']) || !is_null($conf['tag_name'])) {
|
|||
|
|
if (!is_null($conf['source_name'])) {
|
|||
|
|
$source = trim($conf['source_name']);
|
|||
|
|
$sql = "SELECT id FROM advertising_sources WHERE upper(source) = upper('$source') AND (user_id = '$id_agent' OR manager_id = '$id_agent')";
|
|||
|
|
|
|||
|
|
if ($debug)
|
|||
|
|
echo "<pre>".$sql."</pre>";
|
|||
|
|
|
|||
|
|
if (!$debug) {
|
|||
|
|
if ($result = mysql_query($sql, $mdb)) {
|
|||
|
|
$s = mysql_fetch_row($result);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (!is_null($conf['tag_name'])) {
|
|||
|
|
$sql = "SELECT id FROM activities WHERE upper(name) = upper('$conf[tag_name]') AND (user_id = '$id_agent' OR manager_id = '$id_agent')";
|
|||
|
|
|
|||
|
|
if ($debug)
|
|||
|
|
echo "<pre>".$sql."</pre>";
|
|||
|
|
|
|||
|
|
if (!$debug) {
|
|||
|
|
if ($result = mysql_query($sql, $mdb)) {
|
|||
|
|
$t = mysql_fetch_row($result);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
} else if (!is_null($target_site)) {
|
|||
|
|
$source = "Сайт " . $target_site;
|
|||
|
|
|
|||
|
|
$sql = "SELECT id FROM advertising_sources WHERE upper(source) = upper('$source') AND (user_id = '$id_agent' OR manager_id = '$id_agent')";
|
|||
|
|
|
|||
|
|
if ($debug)
|
|||
|
|
echo "<pre>".$sql."</pre>";
|
|||
|
|
|
|||
|
|
if (!$debug) {
|
|||
|
|
if ($result = mysql_query($sql, $mdb)) {
|
|||
|
|
$s = mysql_fetch_row($result);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
$sql = "SELECT id FROM activities WHERE upper(name) = upper('$source') AND (user_id = '$id_agent' OR manager_id = '$id_agent')";
|
|||
|
|
|
|||
|
|
if ($debug)
|
|||
|
|
echo "<pre>".$sql."</pre>";
|
|||
|
|
|
|||
|
|
if (!$debug) {
|
|||
|
|
if ($result = mysql_query($sql, $mdb)) {
|
|||
|
|
$t = mysql_fetch_row($result);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// Кастомный тег (если нет в системе у АН - добавляем его)
|
|||
|
|
if (!empty($tag_name)) {
|
|||
|
|
$sql = "SELECT id FROM activities WHERE upper(name) = upper('$tag_name') AND (user_id = '$id_agent' OR manager_id = '$id_agent')";
|
|||
|
|
if ($result = mysql_query($sql, $mdb)) {
|
|||
|
|
if (mysql_num_rows($result)) {
|
|||
|
|
while ($row = mysql_fetch_row($result)) {
|
|||
|
|
$t[] = $row[0];
|
|||
|
|
}
|
|||
|
|
} else {
|
|||
|
|
if (mysql_query("INSERT INTO activities (user_id, manager_id, name) VALUES('$who_work_id', '$id_agent', '$tag_name')", $mdb)) {
|
|||
|
|
$t[] = mysql_insert_id();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (!empty($s))
|
|||
|
|
$post['source'] = $s[0];
|
|||
|
|
|
|||
|
|
|
|||
|
|
if ((int)$id_agent == 10429 && ($conf['track_code'] == 'last_checked_mail141_id' || $conf['track_code'] == 'last_checked_mail14_id')) {
|
|||
|
|
if (strpos($body, "Новостройки") !== false && strpos($body, "СПБ") !== false) {
|
|||
|
|
//тэг СПБ
|
|||
|
|
$t[] = 1884;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (!empty($t))
|
|||
|
|
$post['activities'] = $t;
|
|||
|
|
|
|||
|
|
$sql = "SELECT * FROM `clients` WHERE cancel=0 AND `id_agent` IN (".implode(',', $agency_users_ids).")";
|
|||
|
|
|
|||
|
|
if (!empty($post['phone']))
|
|||
|
|
$sql .= " AND (`phone` LIKE '%$post[phone]%' OR `phone2` LIKE '%$post[phone]%')";
|
|||
|
|
else if (empty($post['phone']) && !empty($post['email']))
|
|||
|
|
$sql .= " AND (`email` LIKE '%$post[email]%')";
|
|||
|
|
else if (!empty($post['phone']) || !empty($post['email']))
|
|||
|
|
$sql .= " AND (`phone` LIKE '%$post[phone]%' OR `phone2` LIKE '%$post[phone]%' OR `email` LIKE '%$post[email]%')";
|
|||
|
|
|
|||
|
|
$sql .= " AND `deleted` = 0";
|
|||
|
|
|
|||
|
|
//if ($debug)
|
|||
|
|
echo '<pre>' . var_dump($sql) . '<pre/>';
|
|||
|
|
|
|||
|
|
if (!$debug && (!empty($post['phone']) || !empty($post['email']))) {
|
|||
|
|
|
|||
|
|
if ($query = mysql_query($sql)) {
|
|||
|
|
if (mysql_num_rows($query) == 0) {
|
|||
|
|
$idClient = $clients->addEdit($post, false, false);
|
|||
|
|
} else if($id_agent == 13154 || $id_agent == 20947){
|
|||
|
|
$idClient = (int)mysql_fetch_assoc($query)['id'];
|
|||
|
|
//echo $idClient;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
echo '<pre><code>' . var_export($post, true) . '</code><pre/>';
|
|||
|
|
|
|||
|
|
|
|||
|
|
if ($debug || $idClient > 0)
|
|||
|
|
$messages[] = "При сборе почты с <b>". $conf['mailbox']['login'] ."</b> добавлен клиент: " . $fio . " (" . $phone .")";
|
|||
|
|
|
|||
|
|
if (intval($idClient) > 1) {
|
|||
|
|
|
|||
|
|
$sql = "UPDATE `clients` SET `id_agent` = '$id_agent' WHERE `id` = '$idClient'";
|
|||
|
|
|
|||
|
|
|
|||
|
|
if ($debug)
|
|||
|
|
echo "<pre>".$sql."</pre>";
|
|||
|
|
|
|||
|
|
if (!$debug) {
|
|||
|
|
if (!mysql_query($sql, $mdb))
|
|||
|
|
echo "<code style='color: red;'>" . $sql . "<br/>Error: " . mysql_error() . "</code>";
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
if ($id_agent != 13154 && $id_agent != 14453 && intval($idClient) > 1) { // + пропуск уведомления для АН КВС и АН BRG
|
|||
|
|
|
|||
|
|
$dop_text = "";
|
|||
|
|
if (!empty($source))
|
|||
|
|
$dop_text = "Источник: " . $source;
|
|||
|
|
|
|||
|
|
// Уведомление в ТГ для руковода
|
|||
|
|
$sql_add = "INSERT INTO `events_clients` (`from_id`, `client_id`, `user_id`, `event`, `dop_text`, `read`, `send_telegramm`)
|
|||
|
|
VALUES ({$id_agent}, {$idClient}, {$id_agent}, 'add', '{$dop_text}', 2, 0)";
|
|||
|
|
if ($debug)
|
|||
|
|
echo "<pre>".$sql_add."</pre>";
|
|||
|
|
|
|||
|
|
if (!$debug) {
|
|||
|
|
if (!mysql_query($sql_add, $mdb))
|
|||
|
|
echo "<code style='color: red;'>".$sql_add."<br/>Error: " . mysql_error() . "</code>";
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// Уведомление в ТГ для ответственного
|
|||
|
|
if (isset($conf['who_work_id'])) {
|
|||
|
|
$sql_add = "INSERT INTO `events_clients` (`from_id`, `client_id`, `user_id`, `event`, `dop_text`, `read`, `send_telegramm`)
|
|||
|
|
VALUES ({$conf['who_work_id']}, {$idClient}, {$id_agent}, 'add', '{$dop_text}', 2, 0)";
|
|||
|
|
if ($debug)
|
|||
|
|
echo "<pre>".$sql_add."</pre>";
|
|||
|
|
|
|||
|
|
if (!$debug) {
|
|||
|
|
if (!mysql_query($sql_add, $mdb))
|
|||
|
|
echo "<code style='color: red;'>".$sql_add."<br/>Error: " . mysql_error() . "</code>";
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
$latest_uid = $newId;
|
|||
|
|
|
|||
|
|
$sql = "UPDATE `params` SET `value` = '$newId' WHERE `code` = 'last_checked_mail_id'";
|
|||
|
|
if (isset($conf['track_code']))
|
|||
|
|
$sql = "UPDATE `params` SET `value` = '$newId' WHERE `code` = '{$conf['track_code']}'";
|
|||
|
|
|
|||
|
|
if ($debug)
|
|||
|
|
echo "<pre>".$sql."</pre>";
|
|||
|
|
|
|||
|
|
if (!$debug) {
|
|||
|
|
if (!mysql_query($sql, $mdb))
|
|||
|
|
echo "<code style='color: red;'>" . $sql . "<br/>Error: " . mysql_error() . "</code>";
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//var_dump(!is_null($req_type_id) && ($idClient > 0 || $debug));
|
|||
|
|
if (!is_null($req_type_id) && ($idClient > 0 || $debug)) { // Если указано - создаём и заявку тоже
|
|||
|
|
|
|||
|
|
if (!is_null($doer_id)) {
|
|||
|
|
|
|||
|
|
$sql_doers = "UPDATE `clients` SET `doers` = '{"$doer_id":1}', `doer_clients` = 1, `doers_confirm` = 1 WHERE `id` = {$idClient}";
|
|||
|
|
$sql_i = "INSERT INTO clients_doers (client_id, user_id, confirm) VALUES (" . $idClient . ", ". $doer_id . ", 1)";
|
|||
|
|
if(!mysql_query($sql_i)) {
|
|||
|
|
echo mysql_error();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if ($debug)
|
|||
|
|
echo "<pre>".$sql_doers."</pre>";
|
|||
|
|
|
|||
|
|
if (!$debug) {
|
|||
|
|
if (!mysql_query($sql_doers, $mdb))
|
|||
|
|
echo "<code style='color: red;'>" . $sql_doers . "<br/>Error: " . mysql_error() . "</code>";
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
$dop_text = "";
|
|||
|
|
if (!empty($source))
|
|||
|
|
$dop_text = "Источник: " . $source;
|
|||
|
|
|
|||
|
|
$user_id = $id_agent;
|
|||
|
|
if (isset($conf['who_work_id']))
|
|||
|
|
$user_id = $conf['who_work_id'];
|
|||
|
|
|
|||
|
|
// Уведомление в ТГ приглашенного к совместной работе
|
|||
|
|
$sql_add = "INSERT INTO `events_clients` (`from_id`, `client_id`, `user_id`, `event`, `dop_text`, `read`, `send_telegramm`)
|
|||
|
|
VALUES ({$doer_id}, {$idClient}, {$user_id}, 'transmitted_parallel', '{$dop_text}', 2, 0)";
|
|||
|
|
|
|||
|
|
if ($debug)
|
|||
|
|
echo "<pre>".$sql_add."</pre>";
|
|||
|
|
|
|||
|
|
if (!$debug) {
|
|||
|
|
if (!mysql_query($sql_add, $mdb))
|
|||
|
|
echo "<code style='color: red;'>".$sql_add."<br/>Error: " . mysql_error() . "</code>";
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
$req = [
|
|||
|
|
'user_id' => $id_agent,
|
|||
|
|
'funnel_id' => $req_funnel_id,
|
|||
|
|
'name' => 'Подбор объекта для ' . trim($fio),
|
|||
|
|
'fio' => trim($fio),
|
|||
|
|
'email' => $mail,
|
|||
|
|
'phone' => $phone,
|
|||
|
|
'opis' => mysql_real_escape_string(strip_tags($utm)),
|
|||
|
|
'type_id' => $req_type_id,
|
|||
|
|
'object_id' => 0,
|
|||
|
|
'client_id' => $idClient,
|
|||
|
|
'priority' => 0,
|
|||
|
|
'hot' => 0,
|
|||
|
|
'who_work' => $who_work_id,
|
|||
|
|
'confirm' => 1,
|
|||
|
|
'stage' => 1
|
|||
|
|
];
|
|||
|
|
|
|||
|
|
if ($id_agent == 20947) { // Для Гирявой Леонид Сергеевич
|
|||
|
|
$req['who_work'] = 21415;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if ($id_agent == 13154) { // Для АН КВС
|
|||
|
|
$req['who_work'] = 0;
|
|||
|
|
$req['confirm'] = 0;
|
|||
|
|
$req['name'] = 'Реализация объекта для ' . trim($fio);
|
|||
|
|
if($clientIdFriand > 0){
|
|||
|
|
$req['friend_client_id'] = $clientIdFriand;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (!empty($s))
|
|||
|
|
$req['source'] = $s[0];
|
|||
|
|
|
|||
|
|
if (!empty($t))
|
|||
|
|
$req['activities'] = $t;
|
|||
|
|
|
|||
|
|
if ($debug) {
|
|||
|
|
echo "<pre>".var_export($req)."</pre>";
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
$req_id = 0;
|
|||
|
|
if (!$debug){
|
|||
|
|
$req_id = $requisitions->add_edit($req);
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if ($debug || $req_id > 0) {
|
|||
|
|
|
|||
|
|
$messages[] = ", а также создана заявка" . $req['name'] . "(ID " . $req_id . ")";
|
|||
|
|
|
|||
|
|
$comment = "Заявка по почте";
|
|||
|
|
if ($id_agent != 14453) {
|
|||
|
|
$sql_in_ev = "INSERT INTO `user_client_events` (`user_id`, `req_id`, `create_date`, `schedule_date`, `type`, `comment`, `calendar_view`, `from_id`)
|
|||
|
|
VALUES ($id_agent, $req_id, '" . date('Y-m-d H:i:s') . "', '" . date('Y-m-d H:i:s', strtotime('+15 minutes')) . "', 'call', '{$comment}', 0, {$id_agent})";
|
|||
|
|
|
|||
|
|
if ($debug)
|
|||
|
|
echo "<pre>" . $sql_in_ev . "</pre>";
|
|||
|
|
|
|||
|
|
if (!$debug) {
|
|||
|
|
if (!mysql_query($sql_in_ev, $mdb))
|
|||
|
|
echo "<code style='color: red;'>" . $sql_in_ev . "<br/>Error: " . mysql_error() . "</code>";
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
$dop_text = "";
|
|||
|
|
if (!empty($source))
|
|||
|
|
$dop_text = "Источник: " . $source;
|
|||
|
|
|
|||
|
|
if ($id_agent != 14453) {
|
|||
|
|
// Уведомление в ТГ для руковода
|
|||
|
|
$sql_add = "INSERT INTO `events_clients` (`from_id`, `client_id`, `req_id`, `user_id`, `event`, `dop_text`, `read`, `send_telegramm`)
|
|||
|
|
VALUES ({$id_agent}, 0, {$req_id}, {$id_agent}, 'add', '{$dop_text}', 2, 0)";
|
|||
|
|
|
|||
|
|
if ($debug)
|
|||
|
|
echo "<pre>" . $sql_add . "</pre>";
|
|||
|
|
|
|||
|
|
if (!$debug) {
|
|||
|
|
if (!mysql_query($sql_add, $mdb))
|
|||
|
|
echo "<code style='color: red;'>" . $sql_add . "<br/>Error: " . mysql_error() . "</code>";
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// Уведомление в ТГ для ответственного
|
|||
|
|
if ($id_agent != 14453 && isset($conf['who_work_id'])) {
|
|||
|
|
$sql_add = "INSERT INTO `events_clients` (`from_id`, `client_id`, `req_id`, `user_id`, `event`, `dop_text`, `read`, `send_telegramm`)
|
|||
|
|
VALUES ({$conf['who_work_id']}, 0, {$req_id}, {$id_agent}, 'add', '{$dop_text}', 2, 0)";
|
|||
|
|
|
|||
|
|
if ($debug)
|
|||
|
|
echo "<pre>" . $sql_add . "</pre>";
|
|||
|
|
|
|||
|
|
if (!$debug) {
|
|||
|
|
if (!mysql_query($sql_add, $mdb))
|
|||
|
|
echo "<code style='color: red;'>" . $sql_add . "<br/>Error: " . mysql_error() . "</code>";
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (!is_null($doer_id)) {
|
|||
|
|
|
|||
|
|
$sql_doers2 = "UPDATE `requisitions` SET `doers` = '{"$doer_id":1}', `doer_clients` = 1, `doers_confirm` = 1 WHERE `id` = {$req_id}";
|
|||
|
|
|
|||
|
|
if ($debug)
|
|||
|
|
echo "<pre>".$sql_doers2."</pre>";
|
|||
|
|
|
|||
|
|
if (!$debug) {
|
|||
|
|
if (!mysql_query($sql_doers2, $mdb))
|
|||
|
|
echo "<code style='color: red;'>" . $sql_doers2 . "<br/>Error: " . mysql_error() . "</code>";
|
|||
|
|
|
|||
|
|
$sql_i = "INSERT INTO requisition_doers (requisition_id, user_id, confirm) VALUES (" . $req_id . ", ". $doer_id . ", 1)";
|
|||
|
|
if(!mysql_query($sql_i)) {
|
|||
|
|
echo mysql_error();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
$user_id = $id_agent;
|
|||
|
|
if (isset($conf['who_work_id']))
|
|||
|
|
$user_id = $conf['who_work_id'];
|
|||
|
|
|
|||
|
|
// Уведомление в ТГ приглашенного к совместной работе
|
|||
|
|
$sql_add = "INSERT INTO `events_clients` (`from_id`, `client_id`, `req_id`, `user_id`, `event`, `dop_text`, `read`, `send_telegramm`)
|
|||
|
|
VALUES ({$doer_id}, 0, {$req_id}, {$user_id}, 'transmitted_parallel', '{$dop_text}', 2, 0)";
|
|||
|
|
|
|||
|
|
if ($debug)
|
|||
|
|
echo "<pre>".$sql_add."</pre>";
|
|||
|
|
|
|||
|
|
if (!$debug) {
|
|||
|
|
if (!mysql_query($sql_add, $mdb))
|
|||
|
|
echo "<code style='color: red;'>".$sql_add."<br/>Error: " . mysql_error() . "</code>";
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
echo '<hr/>';
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (isset($conf['telegram_id'])) {
|
|||
|
|
|
|||
|
|
if (!empty($messages)) {
|
|||
|
|
|
|||
|
|
require_once $_SERVER['DOCUMENT_ROOT'] . "/telegramm/vendor/autoload.php";
|
|||
|
|
|
|||
|
|
$notify_user = $conf['telegram_id'];
|
|||
|
|
$token = '793676666:AAGFo66CjsmO2KxZVRwQbH8pLTvenpsHiHI';
|
|||
|
|
|
|||
|
|
if ($bot = new \TelegramBot\Api\Client($token)) {
|
|||
|
|
|
|||
|
|
$sql = "SELECT * FROM `users` WHERE `id` = '$notify_user' LIMIT 1";
|
|||
|
|
$chatId = (int)mysql_fetch_assoc(mysql_query($sql))['telegramm_chat_id'];
|
|||
|
|
if ($chatId) {
|
|||
|
|
try {
|
|||
|
|
|
|||
|
|
foreach ($messages as $message) {
|
|||
|
|
if (!$debug) {
|
|||
|
|
$result = $bot->sendMessage($chatId, $message, 'html');
|
|||
|
|
echo "<h6 style='color:#4c8538;'>Status: " . var_export($result, true) . "</h6>";
|
|||
|
|
} else {
|
|||
|
|
echo "<h6 style='color:#4c8538;'>Status: ".var_export([$chatId, $message], true)."</h6>";
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
} catch (Exception $e) {
|
|||
|
|
echo "<h6 style='color:#a4402c;'>Send error: $e</h6>";
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
static function ver_phone($phone){
|
|||
|
|
$phone_client = $phone;
|
|||
|
|
if(strlen($phone_client) < 11){
|
|||
|
|
if(strlen($phone_client) == 10){
|
|||
|
|
$phone_client = '+7' . $phone_client;
|
|||
|
|
} else if(strlen($phone_client) == 7) {
|
|||
|
|
$phone_client = '+7812' . $phone_client;
|
|||
|
|
}
|
|||
|
|
} elseif(strlen($phone_client) == 11) {
|
|||
|
|
if(substr($phone_client, 0, 1) == "8"){
|
|||
|
|
$phone_client = substr_replace($phone_client, '+7', 0, 1);
|
|||
|
|
} else {
|
|||
|
|
$phone_client = '+' . $phone_client;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
return $phone_client;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|