319 lines
14 KiB
PHP
319 lines
14 KiB
PHP
<?php
|
||
require_once($_SERVER['DOCUMENT_ROOT']."/config.php");
|
||
|
||
// hide_client_contacts: блокируем РЕАЛЬНУЮ отправку (mail/whatsapp/telegram) — там
|
||
// контакты получателя должны быть в payload. Генерацию ссылки (link/catalog/links_metro)
|
||
// разрешаем — это просто URL без контактов, юзер может скопировать и переслать вручную
|
||
// через свой канал.
|
||
$_postSendType = isset($_POST['send_type']) ? $_POST['send_type'] : '';
|
||
$_isActualSend = in_array($_postSendType, ['mail', 'whatsapp', 'telegram'], true);
|
||
if ($_isActualSend
|
||
&& function_exists('should_hide_contacts_for_current_user')
|
||
&& should_hide_contacts_for_current_user()
|
||
) {
|
||
http_response_code(403);
|
||
echo json_encode([
|
||
'error' => 'hide_client_contacts',
|
||
'message' => 'Отправка презентаций через E-mail/WhatsApp/Telegram недоступна для вашей учётной записи: контакты клиентов скрыты. Скопируйте ссылку и отправьте вручную.'
|
||
]);
|
||
exit;
|
||
}
|
||
|
||
if($_POST['clients'])
|
||
{
|
||
$user = new User;
|
||
$user->get($_SESSION['id']);
|
||
if($user->agencyName) {
|
||
$title = 'Агентство недвижимости '.$user->agencyName;
|
||
} else {
|
||
$title = $user->fio;
|
||
}
|
||
if($user->phoneAgency) {
|
||
$phone = $user->phoneAgency;
|
||
} else {
|
||
$phone = $user->phone;
|
||
}
|
||
$manager = trim($user->last_name . ' ' . $user->first_name . ' ' . $user->middle_name);
|
||
|
||
$send_type = 0;
|
||
if(!empty($SEND_TYPE_PDF[$_POST['send_type']])){
|
||
$send_type = $SEND_TYPE_PDF[$_POST['send_type']];
|
||
}
|
||
|
||
$token = md5(microtime());
|
||
|
||
$theme = !empty($_POST['theme']) ? $_POST['theme'] : "Презентации объектов недвижимости";
|
||
if($send_type == 0) {
|
||
$txt = !empty($_POST['txt']) ? str_replace("\n", "<br>", $_POST['txt'] . "<br/>") : "Уважаемый клиент, отправляю Вам варианты объектов недвижимости. С удовольствием отвечу на ваши вопросы.<br/>";
|
||
}
|
||
|
||
$clientIds = $_POST['clients'];
|
||
|
||
// без клиента
|
||
$realClientIds = [];
|
||
$dummyMode = false;
|
||
|
||
if ($clientIds === '***') {
|
||
$dummyMode = true;
|
||
$realClientIds = [0];
|
||
} elseif (is_array($clientIds)) {
|
||
$realClientIds = $clientIds;
|
||
} else {
|
||
$realClientIds = explode(',', $clientIds);
|
||
}
|
||
|
||
$requestId = isset($_POST['request']) ? (int)$_POST['request'] : null;
|
||
|
||
$userId = $_SESSION['id'];
|
||
|
||
$toSend = $_SESSION['to_send'];
|
||
$toSendNewBuildings = $_SESSION['to_send_newbuilding'];
|
||
$toSendASFilter = $_SESSION['to_send_asfilter'];
|
||
|
||
if($send_type != 3){
|
||
$_SESSION['to_send'] = array();
|
||
$_SESSION['to_send_newbuilding'] = array();
|
||
$_SESSION['to_send_asfilter'] = array();
|
||
}
|
||
|
||
session_write_close();
|
||
|
||
$closes_contact = array();
|
||
//if($send_type == 0){
|
||
$closes_contact = json_decode($_POST['closes_contact'], true);
|
||
//}
|
||
|
||
$prices = array();
|
||
if(isset($_POST['priсes'])){
|
||
$prices = json_decode($_POST['priсes'], true);
|
||
}
|
||
|
||
$addresses = isset($_POST['addresses']) ? json_decode($_POST['addresses'], true) : [];
|
||
|
||
if($_POST['id']){
|
||
$object_id = $_POST['id'];
|
||
}
|
||
|
||
|
||
foreach($toSend as $sts) {
|
||
//https://joywork.ru/object-view.php?id=648505&token=c0d0e461de8d0024aebcb0a7c68836df
|
||
if($send_type != 3){
|
||
$linkUrl = "https://joywork.ru/object-view.php?id=$sts&token=".md5($userId);
|
||
}
|
||
$sql = "SELECT nazv, adres, phone, sobstv FROM objects WHERE id=$sts";
|
||
$rez = mysql_query($sql);
|
||
$obj = mysql_fetch_assoc($rez);
|
||
|
||
//Доп обработка
|
||
if(!$obj['etazh']) $obj['etazh']=Filter::getFloorFromName($obj['nazv'],true);
|
||
else Filter::getFloorFromName($obj['nazv'],true);
|
||
|
||
if(!$obj['etazh_iz']) $obj['etazh_iz']=Filter::getMaxFloorFromName($obj['nazv'],true);
|
||
else Filter::getMaxFloorFromName($obj['nazv'],true);
|
||
|
||
Filter::getSpaceFromName($obj['nazv'],true);
|
||
$obj['nazv']=Filter::name($obj['nazv']);
|
||
|
||
$hideAddress = isset($addresses[$sts]) ? $addresses[$sts] : 0;
|
||
|
||
foreach ($realClientIds as $id_client) {
|
||
//if($send_type == 0){
|
||
if($send_type == 3){
|
||
if($sts == $object_id){
|
||
if(isset($closes_contact[$sts])){
|
||
$sql_up = "INSERT INTO user_object_contact_close SET close={$closes_contact[$sts]}, user_id={$userId}, object_id = {$sts}, client_id = {$id_client}";
|
||
mysql_query($sql_up);
|
||
|
||
}
|
||
|
||
}
|
||
} else {
|
||
$linkUrl .= "&client=".md5($id_client);
|
||
if(isset($closes_contact[$sts])){
|
||
$sql_up = "INSERT INTO user_object_contact_close SET close={$closes_contact[$sts]}, user_id={$userId}, object_id = {$sts}, client_id = {$id_client}";
|
||
mysql_query($sql_up);
|
||
|
||
}
|
||
}
|
||
//if($_SESSION['id'] == 5238){
|
||
$close_contact = 0;
|
||
if(isset($closes_contact[$sts])){
|
||
$close_contact = $closes_contact[$sts];
|
||
}
|
||
$cena = 0;
|
||
if(isset($prices[$sts])){
|
||
$cena = $prices[$sts];
|
||
}
|
||
|
||
if($send_type == 3){
|
||
if($sts == $object_id){
|
||
$is_link_metro = false;
|
||
if($user->agencyId == 12061){
|
||
$is_link_metro = true;
|
||
if($close_contact == 1 || $hideAddress == 1){
|
||
$is_link_metro = false;
|
||
}
|
||
|
||
if($is_link_metro){
|
||
$sql_obj = "SELECT id, stoim, opis FROM objects WHERE id = {$object_id}";
|
||
$q_obj = mysql_query($sql_obj);
|
||
$r_obj = mysql_fetch_assoc($q_obj);
|
||
if($cena != $r_obj['stoim']){
|
||
$is_link_metro = false;
|
||
}
|
||
}
|
||
|
||
if($is_link_metro){
|
||
$sql_com = "SELECT * FROM user_object_comments WHERE user_id = $userId AND object_id={$object_id}";
|
||
$q_com = mysql_query($sql_com);
|
||
if(mysql_num_rows($q_com) > 0){
|
||
$r_com = mysql_fetch_assoc($q_com);
|
||
if(strcmp(trim($r_com['comment']), trim($r_obj['opis'])) != 0){
|
||
$is_link_metro = false;
|
||
}
|
||
}
|
||
}
|
||
|
||
if($is_link_metro){
|
||
$sql_l = "SELECT * FROM object_agencymetro_links WHERE object_id = {$object_id} AND is_active = 1";
|
||
|
||
$q_l = mysql_query($sql_l);
|
||
if(mysql_num_rows($q_l) == 0){
|
||
$is_link_metro = false;
|
||
} else {
|
||
$r_l = mysql_fetch_assoc($q_l);
|
||
if(!empty($r_l['link'])){
|
||
$linkUrl = $r_l['link']."?agentId=".$userId;
|
||
} else {
|
||
$is_link_metro = false;
|
||
}
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
if($is_link_metro === false){
|
||
$sql = "INSERT INTO sended_pdf(id_agent, id_object, date_send, id_client, nazv, path, send_type, close_contact, hide_address, token, id_request, new_price) VALUES('$userId', '$sts', NOW(), '$id_client', '$obj[nazv] $obj[adres]', '$linkUrl', $send_type, $close_contact, $hideAddress, '$token', '$requestId', '$cena')";
|
||
mysql_query($sql);
|
||
$id_pr = mysql_insert_id();
|
||
$token2 = md5($id_pr);
|
||
$linkUrl = "https://joywork.ru/object-view.php?token=".$token2;
|
||
|
||
$sql_up_pr = "UPDATE sended_pdf SET token = '{$token2}', path='{$linkUrl}' WHERE id={$id_pr}";
|
||
mysql_query($sql_up_pr);
|
||
}
|
||
}
|
||
|
||
} else {
|
||
$sql = "INSERT INTO sended_pdf(id_agent, id_object, date_send, id_client, nazv, path, send_type, close_contact, hide_address, token, id_request, new_price) VALUES('$userId', '$sts', NOW(), '$id_client', '$obj[nazv] $obj[adres]', '$linkUrl', $send_type, $close_contact, $hideAddress, '$token', '$requestId', '$cena')";
|
||
mysql_query($sql);
|
||
$id_pr = mysql_insert_id();
|
||
$token2 = md5($id_pr);
|
||
$linkUrl = "https://joywork.ru/object-view.php?token=".$token2;
|
||
|
||
$sql_up_pr = "UPDATE sended_pdf SET token = '{$token2}', path='{$linkUrl}' WHERE id={$id_pr}";
|
||
mysql_query($sql_up_pr);
|
||
}
|
||
/* } else {
|
||
$sql = "INSERT INTO sended_pdf(id_agent, id_object, date_send, id_client, nazv, path, send_type, token) VALUES('$userId', '$sts', NOW(), '$id_client', '$obj[nazv] $obj[adres]', '$linkUrl', $send_type, '$token')";
|
||
mysql_query($sql);
|
||
}*/
|
||
}
|
||
|
||
if($send_type == 0) {
|
||
$txt .= "<a href='$linkUrl' target='_blank'>$obj[nazv]</a><br/>";
|
||
} else {
|
||
$txt .= " " . $obj[nazv] . " " . $linkUrl ."\r\n";
|
||
}
|
||
|
||
$sql = "INSERT INTO archive(nazv, adres, phone, sobstv, id_obj) VALUES('$obj[nazv]', '$obj[adres]', '$obj[phone]', '$obj[sobstv]', '$sts')";
|
||
mysql_query($sql);
|
||
|
||
|
||
|
||
if (count($toSendASFilter) > 0) {
|
||
$asfilter = new AutoSearch();
|
||
foreach ($toSendASFilter as $filter_id => $object_id) {
|
||
if (!is_null($filter_id) && !is_null($object_id))
|
||
$asfilter->addObjectToSended($filter_id, $object_id);
|
||
}
|
||
}
|
||
|
||
/* if(isset($closes_contact[$sts]) && $closes_contact[$sts] == 0){
|
||
if ($_SESSION['individual']) {
|
||
$txt .= "<br> $manager<br> ".$user->phone."<br> ".$user->email;
|
||
} else {
|
||
$txt .= "<br> $manager<br> ".$user->phone."<br> ".$user->email."<br> $title<br>$phone";
|
||
}if ($_SESSION['individual']) {
|
||
$txt .= "<br> $manager<br> ".$user->phone."<br> ".$user->email;
|
||
} else {
|
||
$txt .= "<br> $manager<br> ".$user->phone."<br> ".$user->email."<br> $title<br>$phone";
|
||
}
|
||
}*/
|
||
}
|
||
|
||
//https://joywork.ru/newbuilding-view.php?id=772546&token=a87ff679a2f3e71d9181a67b7542122c
|
||
foreach($toSendNewBuildings as $sts) {
|
||
$linkUrl = "https://joywork.ru/newbuilding-view.php?id=$sts&token=".md5($userId);
|
||
$sql = "SELECT a.id, a.number, b.name, b.address FROM apartments a, blocks b WHERE b.id = a.block_id AND a.id='$sts'";
|
||
|
||
$rez = mysql_query($sql);
|
||
if (mysql_num_rows($rez) > 0) {
|
||
|
||
$objts = mysql_fetch_assoc($rez);
|
||
|
||
$nazv = "Квартира №$objts[number] в комплексе $objts[name]";
|
||
|
||
if($send_type == 0) {
|
||
$txt .= "<a href='$linkUrl' target='_blank'>$nazv</a><br/>";
|
||
} else {
|
||
$txt .= " " . $nazv . " " . $linkUrl;
|
||
}
|
||
|
||
foreach ($clientIds as $id_client) {
|
||
$sql = "INSERT INTO sended_pdf_newbuildings(id_agent, id_object, date_send, id_client, nazv, path, send_type, token) VALUES('$userId', '$sts', NOW(), '$id_client', '$nazv $objts[address]', '$linkUrl', $send_type, '$token')";
|
||
mysql_query($sql);
|
||
}
|
||
|
||
if (count($toSendASFilter) > 0) {
|
||
$asfilter = new AutoSearch();
|
||
foreach ($toSendASFilter as $filter_id => $object_id) {
|
||
if (!is_null($filter_id) && !is_null($object_id))
|
||
$asfilter->addObjectToSended($filter_id, $object_id);
|
||
}
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
|
||
|
||
if($send_type == 0){
|
||
foreach ($clientIds as $clientId) {
|
||
$mail = mysql_result(mysql_query("SELECT email FROM clients WHERE deleted <> 1 AND id = $clientId"),0);
|
||
mailClientByIdWithConfirm($userId, trim($mail), $theme, $txt, [], []);
|
||
sleep(1);
|
||
}
|
||
} else if ($send_type == 1) {
|
||
$phone = mysql_result(mysql_query("SELECT phone FROM clients WHERE deleted <> 1 AND id = $clientIds[0]"),0);
|
||
$text = !empty($_POST['txt']) ? str_replace("\n", "<br>", $_POST['txt'] . "<br/>") : "Уважаемый клиент, отправляю Вам варианты объектов недвижимости. С удовольствием отвечу на ваши вопросы.<br/>";
|
||
|
||
$txt = $text . " " . $txt;
|
||
|
||
echo "https://wa.me/" . preg_replace("/[^,.0-9]/", '', $phone) . "?text=" .
|
||
urlencode(strip_tags(preg_replace('/<a href="(.*)">/', '$1', $txt))) . " ";
|
||
exit;
|
||
} else if ($send_type == 2){
|
||
$phone = mysql_result(mysql_query("SELECT phone FROM clients WHERE deleted <> 1 AND id = $clientIds[0]"),0);
|
||
$text = !empty($_POST['txt']) ? str_replace("\n", "<br>", $_POST['txt'] . "\n") : "Уважаемый клиент, отправляю Вам варианты объектов недвижимости.\nС удовольствием отвечу на ваши вопросы.\n";
|
||
|
||
$txt = $text . " " . str_replace("<br>","\n",$txt);
|
||
|
||
echo "https://telegram.me/share/url?url=%20&text=" .
|
||
urlencode(strip_tags(preg_replace('/<a href="(.*)">/', '$1', $txt))) . " ";
|
||
exit;
|
||
} else if ($send_type == 3){
|
||
echo $linkUrl;
|
||
}
|
||
}
|