public static function MailNotifyAgent() { global $DB; $defSiteID = CSite::GetDefSite(); $arMark = array(); $arGroupNotify = array(); $arGroupNotifyUser = array(); $arUnsendNotify = CIMNotify::GetUnsendNotify(); foreach ($arUnsendNotify as $id => $arNotify) { if (!isset($arMark[$arNotify["CHAT_ID"]]) || $arMark[$arNotify["CHAT_ID"]] < $arNotify["ID"]) { $arMark[$arNotify["CHAT_ID"]] = $arNotify["ID"]; } if ($arNotify['TO_USER_ACTIVE'] != 'Y') { unset($arUnsendNotify[$id]); continue; } if (isset($arNotify["NOTIFY_MODULE"]) && isset($arNotify["NOTIFY_EVENT"]) && !CIMNotifySchema::CheckEnableFeature($arNotify["NOTIFY_MODULE"], $arNotify["NOTIFY_EVENT"], IM_FEATURE_MAIL)) { unset($arUnsendNotify[$id]); continue; } $siteID = $arNotify["TO_USER_LID"]; if ($siteID == false || StrLen($siteID) <= 0) { $siteID = $defSiteID; if ($siteID == false || StrLen($siteID) <= 0) { unset($arUnsendNotify[$id]); continue; } } if (strlen($arNotify["MESSAGE_OUT"]) <= 0) { $arNotify["MESSAGE_OUT"] = $arNotify["MESSAGE"]; } if (!(isset($arNotify["EMAIL_TEMPLATE"]) && strlen($arNotify["EMAIL_TEMPLATE"]) > 0)) { $arNotify["EMAIL_TEMPLATE"] = "IM_NEW_NOTIFY"; } $arNotify["USER"] = htmlspecialcharsback(CUser::FormatName(CSite::GetNameFormat(false), array("NAME" => $arNotify["TO_USER_NAME"], "LAST_NAME" => $arNotify["TO_USER_LAST_NAME"], "SECOND_NAME" => $arNotify["TO_USER_SECOND_NAME"], "LOGIN" => $arNotify["TO_USER_LOGIN"]), true)); $arNotify["FROM_USER"] = htmlspecialcharsback(CUser::FormatName(CSite::GetNameFormat(false), array("NAME" => $arNotify["FROM_USER_NAME"], "LAST_NAME" => $arNotify["FROM_USER_LAST_NAME"], "SECOND_NAME" => $arNotify["FROM_USER_SECOND_NAME"], "LOGIN" => $arNotify["FROM_USER_LOGIN"]), true)); $arNotify['NOTIFY_TAG_MD5'] = md5($arNotify['NOTIFY_TAG']); if ($arNotify["EMAIL_TEMPLATE"] == "IM_NEW_NOTIFY" && $arNotify['NOTIFY_TAG'] != '') { if (isset($arGroupNotify[$arNotify['NOTIFY_TAG_MD5']])) { $arGroupNotifyUser[$arNotify['NOTIFY_TAG_MD5']][$arNotify["FROM_USER_ID"]] = $arNotify["FROM_USER"]; unset($arUnsendNotify[$id]); } else { $arGroupNotifyUser[$arNotify['NOTIFY_TAG_MD5']][$arNotify["FROM_USER_ID"]] = $arNotify["FROM_USER"]; $arGroupNotify[$arNotify['NOTIFY_TAG_MD5']] = true; } } $arUnsendNotify[$id] = $arNotify; } foreach ($arMark as $chatId => $lastSendId) { CIMNotify::SetLastSendId($chatId, $lastSendId); } $CTP = new CTextParser(); foreach ($arUnsendNotify as $id => $arNotify) { $arFields = array("MESSAGE_ID" => $arNotify["ID"], "USER" => $arNotify["USER"], "USER_ID" => $arNotify["TO_USER_ID"], "USER_LOGIN" => $arNotify["TO_USER_LOGIN"], "USER_NAME" => $arNotify["TO_USER_NAME"], "USER_LAST_NAME" => $arNotify["TO_USER_LAST_NAME"], "USER_SECOND_NAME" => $arNotify["TO_USER_SECOND_NAME"], "DATE_CREATE" => $arNotify["DATE_CREATE"], "FROM_USER_ID" => $arNotify["FROM_USER_ID"], "FROM_USER_LOGIN" => $arNotify["FROM_USER_LOGIN"], "FROM_USER" => $arNotify["FROM_USER"], "SENDER_ID" => $arNotify["FROM_USER_ID"], "SENDER_LOGIN" => $arNotify["FROM_USER_LOGIN"], "SENDER_NAME" => $arNotify["FROM_USER_NAME"], "SENDER_LAST_NAME" => $arNotify["FROM_USER_LAST_NAME"], "SENDER_SECOND_NAME" => $arNotify["FROM_USER_SECOND_NAME"], "EMAIL_TO" => $arNotify["TO_USER_EMAIL"], "TITLE" => trim($arNotify["NOTIFY_TITLE"]), "MESSAGE" => CTextParser::convert4mail(str_replace("#BR#", "\n", strip_tags($arNotify["MESSAGE_OUT"]))), "MESSAGE_50" => $CTP->html_cut(str_replace(array("<br>", "<br/>", "<br />", "#BR#"), array(" ", " ", " ", " "), nl2br(CTextParser::convert4mail(strip_tags($arNotify["MESSAGE_OUT"])))), 50)); if (strlen($arFields['TITLE']) > 0) { $arFields["MESSAGE_50"] = $arFields['TITLE']; } else { $arFields["TITLE"] = $arFields['MESSAGE_50']; } if (isset($arGroupNotifyUser[$arNotify['NOTIFY_TAG_MD5']]) && count($arGroupNotifyUser[$arNotify['NOTIFY_TAG_MD5']]) > 1) { $arNotify["EMAIL_TEMPLATE"] = "IM_NEW_NOTIFY_GROUP"; $arFields['FROM_USERS'] = implode(', ', $arGroupNotifyUser[$arNotify['NOTIFY_TAG_MD5']]); unset($arFields['FROM_USER']); } $event = new CEvent(); $event->Send($arNotify["EMAIL_TEMPLATE"], $siteID, $arFields, "N"); } return "CIMMail::MailNotifyAgent();"; }