$DB->Commit(); } break; } } } $arLID = array(); $db_res = CLanguage::GetList($by_ = "sort", $order_ = "asc"); if ($db_res && ($res = $db_res->GetNext())) { do { $arLID[$res["LID"]] = $res["LID"]; } while ($res = $db_res->GetNext()); } $lAdmin->AddHeaders(array(array("id" => "ID", "content" => "ID", "default" => true), array("id" => "LID", "content" => Loc::getMessage("LANG"), "default" => true), array("id" => "EVENT_NAME", "content" => Loc::getMessage("EVENT_TYPE"), "sort" => "event_name", "default" => true), array("id" => "NAME", "content" => Loc::getMessage("EVENT_NAME"), "default" => true), array("id" => "DESCRIPTION", "content" => Loc::getMessage("EVENT_DESCRIPTION"), "default" => false), array("id" => "TEMPLATES", "content" => Loc::getMessage("EVENT_TEMPLATES"), "default" => false))); $resultMessageByTypeList = array(); $resultMessageByTypeDb = \Bitrix\Main\Mail\Internal\EventMessageTable::getList(array('select' => array('ID', 'EVENT_NAME'))); while ($messageByType = $resultMessageByTypeDb->fetch()) { $resultMessageByTypeList[$messageByType['EVENT_NAME']][] = $messageByType['ID']; } $resultList = array(); $runtimeList = array(); $arFilter['!EVENT_NAME'] = null; if (isset($arFilter['MESSAGE_ID'])) { $runtimeList[] = new \Bitrix\Main\Entity\ReferenceField('MESSAGE', 'Bitrix\\Main\\Mail\\Internal\\EventMessageTable', array('=this.EVENT_NAME' => 'ref.EVENT_NAME')); $arFilter['MESSAGE.ID'] = $arFilter['MESSAGE_ID']; unset($arFilter['MESSAGE_ID']); } $resultDb = \Bitrix\Main\Mail\Internal\EventTypeTable::getList(array('filter' => $arFilter, 'runtime' => $runtimeList, 'order' => array('EVENT_NAME' => strtoupper($order) == 'DESC' ? 'DESC' : 'ASC'))); $resultTypeList = $resultDb->fetchAll(); foreach ($resultTypeList as $type) { if (!isset($resultList[$type['EVENT_NAME']])) {
/** * @param $mailingChainId * @param array $params * @return string * @throws \Bitrix\Main\ArgumentException * @throws \Bitrix\Main\DB\Exception */ protected static function sendInternal($mailingChainId, array $params) { if (static::$currentMailingChainFields !== null) { if (static::$currentMailingChainFields['ID'] != $mailingChainId) { static::$currentMailingChainFields = null; } } if (static::$currentMailingChainFields === null) { $mailingChainDb = MailingChainTable::getList(array('select' => array('*', 'SITE_ID' => 'MAILING.SITE_ID'), 'filter' => array('ID' => $mailingChainId))); if (!($mailingChain = $mailingChainDb->fetch())) { return PostingRecipientTable::SEND_RESULT_ERROR; } $charset = false; $siteDb = \Bitrix\Main\SiteTable::getList(array('select' => array('SERVER_NAME', 'NAME', 'CULTURE_CHARSET' => 'CULTURE.CHARSET'), 'filter' => array('LID' => $mailingChain['SITE_ID']))); if ($site = $siteDb->fetch()) { $charset = $site['CULTURE_CHARSET']; $serverName = $site['SERVER_NAME']; } else { throw new \Bitrix\Main\DB\Exception(Loc::getMessage('SENDER_POSTING_MANAGER_ERR_SITE', array('#SITE_ID#' => $mailingChain['SITE_ID']))); } if (!$charset) { throw new \Bitrix\Main\DB\Exception(Loc::getMessage('SENDER_POSTING_MANAGER_ERR_CHARSET', array('#SITE_ID#' => "[" . $mailingChain['SITE_ID'] . "]" . $site['NAME']))); } $attachmentList = array(); $attachmentDb = \Bitrix\Sender\MailingAttachmentTable::getList(array('select' => array('FILE_ID'), 'filter' => array('CHAIN_ID' => $mailingChainId))); while ($attachment = $attachmentDb->fetch()) { $attachmentList[] = $attachment['FILE_ID']; } static::$currentMailingChainFields = array(); static::$currentMailingChainFields['EVENT'] = array('FILE' => $attachmentList); static::$currentMailingChainFields['ID'] = $mailingChain['ID']; static::$currentMailingChainFields['MESSAGE'] = array('BODY_TYPE' => 'html', 'EMAIL_FROM' => $mailingChain['EMAIL_FROM'], 'EMAIL_TO' => '#EMAIL_TO#', 'SUBJECT' => $mailingChain['SUBJECT'], 'MESSAGE' => $mailingChain['MESSAGE'], 'MESSAGE_PHP' => \Bitrix\Main\Mail\Internal\EventMessageTable::replaceTemplateToPhp($mailingChain['MESSAGE'])); static::$currentMailingChainFields['SITE'] = array($mailingChain['SITE_ID']); static::$currentMailingChainFields['CHARSET'] = $charset; static::$currentMailingChainFields['SERVER_NAME'] = $serverName; static::$currentMailingChainFields['LINK_PROTOCOL'] = \Bitrix\Main\Config\Option::get("sender", "link_protocol", 'http'); } $messageParams = array('EVENT' => static::$currentMailingChainFields['EVENT'], 'FIELDS' => $params['FIELDS'], 'MESSAGE' => static::$currentMailingChainFields['MESSAGE'], 'SITE' => static::$currentMailingChainFields['SITE'], 'CHARSET' => static::$currentMailingChainFields['CHARSET']); if (!empty($params['FIELDS']['UNSUBSCRIBE_LINK'])) { if (substr($params['FIELDS']['UNSUBSCRIBE_LINK'], 0, 4) !== 'http') { if (!empty(static::$currentMailingChainFields['SERVER_NAME'])) { $serverName = static::$currentMailingChainFields['SERVER_NAME']; } else { $serverName = \Bitrix\Main\Config\Option::get("main", "server_name", $GLOBALS["SERVER_NAME"]); } $linkProtocol = static::$currentMailingChainFields['LINK_PROTOCOL']; $params['FIELDS']['UNSUBSCRIBE_LINK'] = $linkProtocol . '://' . $serverName . $params['FIELDS']['UNSUBSCRIBE_LINK']; } } $message = Mail\EventMessageCompiler::createInstance($messageParams); $message->compile(); $mailHeaders = $message->getMailHeaders(); if (!empty($params['FIELDS']['UNSUBSCRIBE_LINK'])) { $unsubUrl = $params['FIELDS']['UNSUBSCRIBE_LINK']; $mailHeaders['List-Unsubscribe'] = '<' . $unsubUrl . '>'; } // send mail $result = Mail\Mail::send(array('TO' => $message->getMailTo(), 'SUBJECT' => $message->getMailSubject(), 'BODY' => $message->getMailBody(), 'HEADER' => $mailHeaders, 'CHARSET' => $message->getMailCharset(), 'CONTENT_TYPE' => $message->getMailContentType(), 'MESSAGE_ID' => '', 'ATTACHMENT' => $message->getMailAttachment(), 'LINK_PROTOCOL' => static::$currentMailingChainFields['LINK_PROTOCOL'], 'LINK_DOMAIN' => static::$currentMailingChainFields['SERVER_NAME'], 'TRACK_READ' => isset($params['TRACK_READ']) ? $params['TRACK_READ'] : null, 'TRACK_CLICK' => isset($params['TRACK_CLICK']) ? $params['TRACK_CLICK'] : null)); if ($result) { return PostingRecipientTable::SEND_RESULT_SUCCESS; } else { return PostingRecipientTable::SEND_RESULT_ERROR; } }
/** * @return string */ public static function handleEvent(array $arEvent) { if (!isset($arEvent['FIELDS']) && isset($arEvent['C_FIELDS'])) { $arEvent['FIELDS'] = $arEvent['C_FIELDS']; } if (!is_array($arEvent['FIELDS'])) { throw new \Bitrix\Main\ArgumentTypeException("FIELDS"); } $flag = static::SEND_RESULT_TEMPLATE_NOT_FOUND; // no templates $arResult = array("Success" => false, "Fail" => false, "Was" => false); $trackRead = null; $trackClick = null; if (array_key_exists('TRACK_READ', $arEvent)) { $trackRead = $arEvent['TRACK_READ']; } if (array_key_exists('TRACK_CLICK', $arEvent)) { $trackClick = $arEvent['TRACK_CLICK']; } $arSites = explode(",", $arEvent["LID"]); if (count($arSites) <= 0) { return $flag; } // get charset and server name for languages of event $charset = false; $serverName = null; $siteDb = Main\SiteTable::getList(array('select' => array('SERVER_NAME', 'CULTURE_CHARSET' => 'CULTURE.CHARSET'), 'filter' => array('LID' => $arSites))); if ($arSiteDb = $siteDb->fetch()) { $charset = $arSiteDb['CULTURE_CHARSET']; $serverName = $arSiteDb['SERVER_NAME']; } if (!$charset) { return $flag; } // get filter for list of message templates $arEventMessageFilter = array(); $MESSAGE_ID = intval($arEvent["MESSAGE_ID"]); if ($MESSAGE_ID > 0) { $eventMessageDb = MailInternal\EventMessageTable::getById($MESSAGE_ID); if ($eventMessageDb->Fetch()) { $arEventMessageFilter['ID'] = $MESSAGE_ID; $arEventMessageFilter['ACTIVE'] = 'Y'; } } if (count($arEventMessageFilter) == 0) { $arEventMessageFilter = array('ACTIVE' => 'Y', 'EVENT_NAME' => $arEvent["EVENT_NAME"], 'EVENT_MESSAGE_SITE.SITE_ID' => $arSites); } // get list of message templates of event $messageDb = MailInternal\EventMessageTable::getList(array('select' => array('ID'), 'filter' => $arEventMessageFilter, 'group' => array('ID'))); while ($arMessage = $messageDb->fetch()) { $eventMessage = MailInternal\EventMessageTable::getRowById($arMessage['ID']); $eventMessage['FILES'] = array(); $attachmentDb = MailInternal\EventMessageAttachmentTable::getList(array('select' => array('FILE_ID'), 'filter' => array('EVENT_MESSAGE_ID' => $arMessage['ID']))); while ($arAttachmentDb = $attachmentDb->fetch()) { $eventMessage['FILE'][] = $arAttachmentDb['FILE_ID']; } $arFields = $arEvent['FIELDS']; foreach (GetModuleEvents("main", "OnBeforeEventSend", true) as $event) { if (ExecuteModuleEventEx($event, array(&$arFields, &$eventMessage)) === false) { continue 2; } } // get message object for send mail $arMessageParams = array('EVENT' => $arEvent, 'FIELDS' => $arFields, 'MESSAGE' => $eventMessage, 'SITE' => $arSites, 'CHARSET' => $charset); $message = EventMessageCompiler::createInstance($arMessageParams); $message->compile(); // send mail $result = Main\Mail\Mail::send(array('TO' => $message->getMailTo(), 'SUBJECT' => $message->getMailSubject(), 'BODY' => $message->getMailBody(), 'HEADER' => $message->getMailHeaders(), 'CHARSET' => $message->getMailCharset(), 'CONTENT_TYPE' => $message->getMailContentType(), 'MESSAGE_ID' => $message->getMailId(), 'ATTACHMENT' => $message->getMailAttachment(), 'TRACK_READ' => $trackRead, 'TRACK_CLICK' => $trackClick, 'LINK_PROTOCOL' => \Bitrix\Main\Config\Option::get("main", "mail_link_protocol", ''), 'LINK_DOMAIN' => $serverName)); if ($result) { $arResult["Success"] = true; } else { $arResult["Fail"] = true; } $arResult["Was"] = true; } if ($arResult["Was"]) { if ($arResult["Success"]) { if ($arResult["Fail"]) { $flag = static::SEND_RESULT_PARTLY; } else { $flag = static::SEND_RESULT_SUCCESS; } // all sent } else { if ($arResult["Fail"]) { $flag = static::SEND_RESULT_ERROR; } // all templates failed } } return $flag; }
/** * @param */ protected function setMailBody() { $isHtml = $this->eventMessageFields["BODY_TYPE"] == "html"; // replace placeholders in body $message = $this->eventMessageFields["MESSAGE_PHP"]; if (empty($message) && !empty($this->eventMessageFields["MESSAGE"])) { $message = MailInternal\EventMessageTable::replaceTemplateToPhp($this->eventMessageFields["MESSAGE"]); if ($this->eventMessageFields["ID"] > 0) { MailInternal\EventMessageTable::update($this->eventMessageFields["ID"], array('MESSAGE_PHP' => $message)); } } if (!empty($this->eventMessageFields['SITE_TEMPLATE_ID'])) { $siteTemplateId = $this->eventMessageFields['SITE_TEMPLATE_ID']; } else { $siteTemplateId = null; } $themeCompiler = EventMessageThemeCompiler::createInstance($siteTemplateId, $message, $isHtml); if (empty($siteTemplateId)) { $siteTemplateId = ".default"; } // set context variables for components $themeCompiler->setSiteTemplateId($siteTemplateId); $themeCompiler->setSiteId($this->siteId); $themeCompiler->setLanguageId($this->languageId); Loc::setCurrentLang($themeCompiler->getLanguageId()); // set values of $arParams, used by components $eventSiteFields = $this->eventSiteFields; if ($isHtml) { foreach ($eventSiteFields as $fieldKey => $fieldValue) { if (strpos($fieldValue, "<") === false) { $eventSiteFields[$fieldKey] = nl2br($fieldValue); } } } $themeCompiler->setParams($eventSiteFields); // eval site template and body $themeCompiler->execute(); // get eval result of site template and body $message = $themeCompiler->getResult(); $this->mailBody = $message; Loc::setCurrentLang(null); EventMessageThemeCompiler::unsetInstance(); }
/** * @param $mailingChainId * @param array $arParams * @return string * @throws \Bitrix\Main\ArgumentException * @throws \Bitrix\Main\DB\Exception */ protected static function sendInternal($mailingChainId, array $arParams) { if (static::$currentMailingChainFields !== null) { if (static::$currentMailingChainFields['ID'] != $mailingChainId) { static::$currentMailingChainFields = null; } } if (static::$currentMailingChainFields === null) { $mailingChainDb = MailingChainTable::getList(array('select' => array('*', 'SITE_ID' => 'MAILING.SITE_ID'), 'filter' => array('ID' => $mailingChainId))); if (!($arMailingChain = $mailingChainDb->fetch())) { return PostingRecipientTable::SEND_RESULT_ERROR; } $charset = false; $siteDb = \Bitrix\Main\SiteTable::getList(array('select' => array('NAME', 'CULTURE_CHARSET' => 'CULTURE.CHARSET'), 'filter' => array('LID' => $arMailingChain['SITE_ID']))); if ($arSiteDb = $siteDb->fetch()) { $charset = $arSiteDb['CULTURE_CHARSET']; } else { throw new \Bitrix\Main\DB\Exception(Loc::getMessage('SENDER_POSTING_MANAGER_ERR_SITE', array('#SITE_ID#' => $arMailingChain['SITE_ID']))); } if (!$charset) { throw new \Bitrix\Main\DB\Exception(Loc::getMessage('SENDER_POSTING_MANAGER_ERR_CHARSET', array('#SITE_ID#' => "[" . $arMailingChain['SITE_ID'] . "]" . $arSiteDb['NAME']))); } static::$currentMailingChainFields = array(); static::$currentMailingChainFields['ID'] = $arMailingChain['ID']; static::$currentMailingChainFields['MESSAGE'] = array('BODY_TYPE' => 'html', 'EMAIL_FROM' => $arMailingChain['EMAIL_FROM'], 'EMAIL_TO' => '#EMAIL_TO#', 'SUBJECT' => $arMailingChain['SUBJECT'], 'MESSAGE' => $arMailingChain['MESSAGE'], 'MESSAGE_PHP' => \Bitrix\Main\Mail\Internal\EventMessageTable::replaceTemplateToPhp($arMailingChain['MESSAGE'])); static::$currentMailingChainFields['SITE'] = array($arMailingChain['SITE_ID']); static::$currentMailingChainFields['CHARSET'] = $charset; } $arMessageParams = array('FIELDS' => $arParams['FIELDS'], 'MESSAGE' => static::$currentMailingChainFields['MESSAGE'], 'SITE' => static::$currentMailingChainFields['SITE'], 'CHARSET' => static::$currentMailingChainFields['CHARSET']); $message = Mail\EventMessageCompiler::createInstance($arMessageParams); $message->compile(); // send mail $result = Mail\Mail::send(array('TO' => $message->getMailTo(), 'SUBJECT' => $message->getMailSubject(), 'BODY' => $message->getMailBody(), 'HEADER' => $message->getMailHeaders(), 'CHARSET' => $message->getMailCharset(), 'CONTENT_TYPE' => $message->getMailContentType(), 'MESSAGE_ID' => '', 'ATTACHMENT' => $message->getMailAttachment(), 'TRACK_READ' => isset($arParams['TRACK_READ']) ? $arParams['TRACK_READ'] : null, 'TRACK_CLICK' => isset($arParams['TRACK_CLICK']) ? $arParams['TRACK_CLICK'] : null)); if ($result) { return PostingRecipientTable::SEND_RESULT_SUCCESS; } else { return PostingRecipientTable::SEND_RESULT_ERROR; } }
/** * * @param $mailingChainId * @param array $params * @return string * @throws \Bitrix\Main\ArgumentException * @throws \Bitrix\Main\DB\Exception */ protected static function sendInternal($mailingChainId, array $params) { // event before sending $eventSendParams = $params; $eventSendParams['MAILING_CHAIN_ID'] = $mailingChainId; $event = new Event('sender', 'OnBeforePostingSendRecipient', array($eventSendParams)); $event->send(); foreach ($event->getResults() as $eventResult) { if ($eventResult->getType() == \Bitrix\Main\EventResult::ERROR) { return PostingRecipientTable::SEND_RESULT_ERROR; } if (is_array($eventResult->getParameters())) { $eventSendParams = array_merge($eventSendParams, $eventResult->getParameters()); } } unset($eventSendParams['MAILING_CHAIN_ID']); $params = $eventSendParams; // prepare common params if (static::$currentMailingChainFields !== null) { if (static::$currentMailingChainFields['ID'] != $mailingChainId) { static::$currentMailingChainFields = null; } } if (static::$currentMailingChainFields === null) { $mailingChainDb = MailingChainTable::getList(array('select' => array('*', 'SITE_ID' => 'MAILING.SITE_ID'), 'filter' => array('=ID' => $mailingChainId))); if (!($mailingChain = $mailingChainDb->fetch())) { return PostingRecipientTable::SEND_RESULT_ERROR; } $charset = false; $siteDb = \Bitrix\Main\SiteTable::getList(array('select' => array('SERVER_NAME', 'NAME', 'CULTURE_CHARSET' => 'CULTURE.CHARSET'), 'filter' => array('=LID' => $mailingChain['SITE_ID']))); if ($site = $siteDb->fetch()) { $charset = $site['CULTURE_CHARSET']; $serverName = $site['SERVER_NAME']; } else { throw new \Bitrix\Main\DB\Exception(Loc::getMessage('SENDER_POSTING_MANAGER_ERR_SITE', array('#SITE_ID#' => $mailingChain['SITE_ID']))); } if (!$charset) { throw new \Bitrix\Main\DB\Exception(Loc::getMessage('SENDER_POSTING_MANAGER_ERR_CHARSET', array('#SITE_ID#' => "[" . $mailingChain['SITE_ID'] . "]" . $site['NAME']))); } $attachmentList = array(); $attachmentDb = \Bitrix\Sender\MailingAttachmentTable::getList(array('select' => array('FILE_ID'), 'filter' => array('CHAIN_ID' => $mailingChainId))); while ($attachment = $attachmentDb->fetch()) { $attachmentList[] = $attachment['FILE_ID']; } static::$currentMailingChainFields = array(); static::$currentMailingChainFields['EVENT'] = array('FILE' => $attachmentList); static::$currentMailingChainFields['ID'] = $mailingChain['ID']; // create final mail-text due to filling template by blocks static::$currentMailingChainFields['IS_MESSAGE_WITH_TEMPLATE'] = false; if ($mailingChain['TEMPLATE_TYPE'] && $mailingChain['TEMPLATE_ID']) { $chainTemplate = \Bitrix\Sender\Preset\Template::getById($mailingChain['TEMPLATE_TYPE'], $mailingChain['TEMPLATE_ID']); if ($chainTemplate && $chainTemplate['HTML']) { $document = new \Bitrix\Main\Web\DOM\Document(); $document->loadHTML($chainTemplate['HTML']); \Bitrix\Main\Loader::includeModule('fileman'); if (\Bitrix\Fileman\Block\Editor::fillDocumentBySliceContent($document, $mailingChain['MESSAGE'])) { \Bitrix\Main\Web\DOM\StyleInliner::inlineDocument($document); $mailingChain['MESSAGE'] = $document->saveHTML(); static::$currentMailingChainFields['IS_MESSAGE_WITH_TEMPLATE'] = true; } else { unset($document); } } } static::$currentMailingChainFields['MESSAGE'] = array('BODY_TYPE' => 'html', 'EMAIL_FROM' => $mailingChain['EMAIL_FROM'], 'EMAIL_TO' => '#EMAIL_TO#', 'PRIORITY' => $mailingChain['PRIORITY'], 'SUBJECT' => $mailingChain['SUBJECT'], 'MESSAGE' => $mailingChain['MESSAGE'], 'MESSAGE_PHP' => \Bitrix\Main\Mail\Internal\EventMessageTable::replaceTemplateToPhp($mailingChain['MESSAGE'])); static::$currentMailingChainFields['SITE'] = array($mailingChain['SITE_ID']); static::$currentMailingChainFields['CHARSET'] = $charset; static::$currentMailingChainFields['SERVER_NAME'] = $serverName; static::$currentMailingChainFields['LINK_PROTOCOL'] = \Bitrix\Main\Config\Option::get("sender", "link_protocol", 'http'); static::$currentMailingChainFields['LINK_PARAMS'] = $mailingChain['LINK_PARAMS']; } $trackClick = isset($params['TRACK_CLICK']) ? $params['TRACK_CLICK'] : null; if ($trackClick && static::$currentMailingChainFields['LINK_PARAMS']) { if (!is_array($trackClick['URL_PARAMS'])) { $trackClick['URL_PARAMS'] = array(); } parse_str(static::$currentMailingChainFields['LINK_PARAMS'], $trackClickTmp); if (is_array($trackClickTmp)) { $trackClick['URL_PARAMS'] = array_merge($trackClick['URL_PARAMS'], $trackClickTmp); } } // prepare params for send email $messageParams = array('EVENT' => static::$currentMailingChainFields['EVENT'], 'FIELDS' => $params['FIELDS'], 'MESSAGE' => static::$currentMailingChainFields['MESSAGE'], 'SITE' => static::$currentMailingChainFields['SITE'], 'CHARSET' => static::$currentMailingChainFields['CHARSET']); if (!empty($params['FIELDS']['UNSUBSCRIBE_LINK'])) { if (substr($params['FIELDS']['UNSUBSCRIBE_LINK'], 0, 4) !== 'http') { if (!empty(static::$currentMailingChainFields['SERVER_NAME'])) { $serverName = static::$currentMailingChainFields['SERVER_NAME']; } else { $serverName = \Bitrix\Main\Config\Option::get("main", "server_name", $GLOBALS["SERVER_NAME"]); } $linkProtocol = static::$currentMailingChainFields['LINK_PROTOCOL']; $params['FIELDS']['UNSUBSCRIBE_LINK'] = $linkProtocol . '://' . $serverName . $params['FIELDS']['UNSUBSCRIBE_LINK']; } } // event on sending $eventMessageParams = $messageParams; $eventMessageParams['MAILING_CHAIN_ID'] = $mailingChainId; $eventMessageParams['IS_MESSAGE_WITH_TEMPLATE'] = static::$currentMailingChainFields['IS_MESSAGE_WITH_TEMPLATE']; $event = new Event('sender', 'OnPostingSendRecipient', array($eventMessageParams)); $event->send(); foreach ($event->getResults() as $eventResult) { if ($eventResult->getType() == \Bitrix\Main\EventResult::ERROR) { return PostingRecipientTable::SEND_RESULT_ERROR; } if (is_array($eventResult->getParameters())) { $eventMessageParams = array_merge($eventMessageParams, $eventResult->getParameters()); } } static::$currentMailingChainFields['IS_MESSAGE_WITH_TEMPLATE'] = $eventMessageParams['IS_MESSAGE_WITH_TEMPLATE']; unset($eventMessageParams['IS_MESSAGE_WITH_TEMPLATE']); unset($eventMessageParams['MAILING_CHAIN_ID']); $messageParams = $eventMessageParams; $message = Mail\EventMessageCompiler::createInstance($messageParams); $message->compile(); // add unsubscribe info to header $mailHeaders = $message->getMailHeaders(); if (!empty($params['FIELDS']['UNSUBSCRIBE_LINK'])) { $unsubUrl = $params['FIELDS']['UNSUBSCRIBE_LINK']; $mailHeaders['List-Unsubscribe'] = '<' . $unsubUrl . '>'; } $mailBody = null; if (static::$currentMailingChainFields['IS_MESSAGE_WITH_TEMPLATE'] && Option::get('sender', 'use_inliner_for_each_template_mail', 'N') == 'Y') { // inline styles $mailBody = \Bitrix\Main\Web\DOM\StyleInliner::inlineHtml($message->getMailBody()); } if (!$mailBody) { $mailBody = $message->getMailBody(); } // set email params $mailParams = array('TO' => $message->getMailTo(), 'SUBJECT' => $message->getMailSubject(), 'BODY' => $mailBody, 'HEADER' => $mailHeaders, 'CHARSET' => $message->getMailCharset(), 'CONTENT_TYPE' => $message->getMailContentType(), 'MESSAGE_ID' => '', 'ATTACHMENT' => $message->getMailAttachment(), 'LINK_PROTOCOL' => static::$currentMailingChainFields['LINK_PROTOCOL'], 'LINK_DOMAIN' => static::$currentMailingChainFields['SERVER_NAME'], 'TRACK_READ' => isset($params['TRACK_READ']) ? $params['TRACK_READ'] : null, 'TRACK_CLICK' => $trackClick); // event on sending email $eventMailParams = $mailParams; $eventMailParams['MAILING_CHAIN_ID'] = $mailingChainId; $event = new Event('sender', 'OnPostingSendRecipientEmail', array($eventMailParams)); $event->send(); foreach ($event->getResults() as $eventResult) { if ($eventResult->getType() == \Bitrix\Main\EventResult::ERROR) { return PostingRecipientTable::SEND_RESULT_ERROR; } if (is_array($eventResult->getParameters())) { $eventMailParams = array_merge($eventMailParams, $eventResult->getParameters()); } } unset($eventMailParams['MAILING_CHAIN_ID']); $mailParams = $eventMailParams; // send mail $result = Mail\Mail::send($mailParams); if ($result) { return PostingRecipientTable::SEND_RESULT_SUCCESS; } else { return PostingRecipientTable::SEND_RESULT_ERROR; } }
function GetListEx($arOrder = array(), $arFilter = array(), $arParams = array()) { global $DB; $arSearch = $arSearch1 = $arSearch2 = array(); $arSelect = array(); $arSqlSearch = array(); $strSqlSearch = ""; $arSqlOrder = array(); foreach ($arFilter as $key => $val) { if (strlen($val) <= 0) { continue; } $val = $DB->ForSql($val); $key_res = CEventType::GetFilterOperation($key); $key = strToUpper($key_res["FIELD"]); $strNegative = $key_res["NEGATIVE"]; $strOperation = $key_res["OPERATION"]; $strNOperation = $key_res["NOPERATION"]; $arOperationReplace = array('LIKE' => '=%', 'QUERY' => '', 'IN' => ''); switch ($key) { case "EVENT_NAME": case "TYPE_ID": if ($strOperation == "LIKE") { $val = "%" . $val . "%"; } $arSearch[] = array($strNOperation . 'EVENT_NAME' => $val); break; case "DESCRIPTION": case "NAME": if ($strOperation == "LIKE") { $val = "%" . $val . "%"; } $arSearch1[] = array($strNOperation . 'EVENT_MESSAGE_TYPE.' . $key => $val); $arSearch2[] = array($strNOperation . $key => $val); break; case "LID": $arSearch1[] = array($strNOperation . 'EVENT_MESSAGE_TYPE.' . $key => $val); $arSearch2[] = array($strNOperation . $key => $val); break; case "ID": $val = intVal($val); $arSearch1[] = array($strNOperation . 'EVENT_MESSAGE_TYPE.' . $key => $val); $arSearch2[] = array($strNOperation . $key => $val); break; case "MESSAGE_ID": $val = intVal($val); $arSearch1[] = array($strNOperation . "ID" => $val); $arSearch2[] = array($strNOperation . 'EVENT_MESSAGE.ID' => $val); break; } } if (is_array($arOrder)) { foreach ($arOrder as $by => $order) { $by = strtoupper($by); $order = strtoupper($order); $order = $order != "DESC" ? "ASC" : "DESC"; if ($by == "EVENT_NAME" || $by == "ID") { $arSqlOrder["EVENT_NAME"] = "EVENT_NAME1 " . $order; } } } if (empty($arSqlOrder)) { $arSqlOrder["EVENT_NAME"] = "EVENT_NAME1 ASC"; } $strSqlOrder = " ORDER BY " . implode(", ", $arSqlOrder); $arSearch['!EVENT_NAME'] = null; $arQuerySelect = array('ID1' => 'EVENT_NAME', 'EVENT_NAME1' => 'EVENT_NAME'); $query1 = new \Bitrix\Main\Entity\Query(Mail\Internal\EventMessageTable::getEntity()); $query1->setSelect($arQuerySelect); $query1->setFilter(array_merge($arSearch, $arSearch1)); $query1->registerRuntimeField('EVENT_MESSAGE_TYPE', array('data_type' => 'Bitrix\\Main\\Mail\\Internal\\EventType', 'reference' => array('=this.EVENT_NAME' => 'ref.EVENT_NAME'))); $query2 = new \Bitrix\Main\Entity\Query(Mail\Internal\EventTypeTable::getEntity()); $query2->setSelect($arQuerySelect); $query2->setFilter(array_merge($arSearch, $arSearch2)); $query2->registerRuntimeField('EVENT_MESSAGE', array('data_type' => 'Bitrix\\Main\\Mail\\Internal\\EventMessage', 'reference' => array('=this.EVENT_NAME' => 'ref.EVENT_NAME'))); $connection = \Bitrix\Main\Application::getConnection(); $strSql = $query1->getQuery() . " UNION " . $query2->getQuery() . " " . $strSqlOrder; $db_res = $connection->query($strSql); $db_res->addFetchDataModifier(array('CEventType', 'GetListExFetchDataModifier')); $db_res = new _CEventTypeResult($db_res, $arParams); return $db_res; }