public function internalize(array $params) { $this->items = array(); foreach ($params as $k => $v) { $entityTypeID = \CCrmOwnerType::ResolveID($k); if ($entityTypeID !== \CCrmOwnerType::Undefined) { $item = new EntityConversionConfigItem($entityTypeID); $item->internalize($v); $this->addItem($item); } } }
public static function ParseEntityKey($key, &$entityInfo) { if (preg_match(self::$ENTITY_KEY, strval($key), $match) !== 1) { $entityInfo = array(); return false; } $entityTypeAbbr = strtoupper($match[1]); $entityID = intval($match[2]); $entityTypeID = CCrmOwnerType::ResolveID($entityTypeAbbr); $entityTypeName = CCrmOwnerType::ResolveName($entityTypeID); $entityInfo = array('ENTITY_TYPE_ABBR' => $entityTypeAbbr, 'ENTITY_TYPE_ID' => $entityTypeID, 'ENTITY_TYPE_NAME' => $entityTypeName, 'ENTITY_ID' => $entityID); return true; }
protected static function load() { if (self::$items !== null) { return; } self::$items = array(); $s = Main\Config\Option::get('crm', 'crm_uf_history', '', ''); $ary = $s !== '' ? unserialize($s) : null; if (is_array($ary)) { foreach ($ary as $k => $v) { if ($v === '') { continue; } $entityTypeID = \CCrmOwnerType::ResolveID($k); if ($entityTypeID !== \CCrmOwnerType::Undefined) { self::$items[$entityTypeID] = new DateTime($v, \DateTime::ISO8601); } } } }
$enablePermissionCheck = !$isAdminUser; if (!CCrmContact::CheckReadPermission(0, $userPermissions) && !CCrmCompany::CheckReadPermission(0, $userPermissions) && !CCrmLead::CheckReadPermission(0, $userPermissions)) { ShowError(GetMessage('CRM_PERMISSION_DENIED')); return; } $arResult['USER_ID'] = $userID; $listID = isset($arParams['LIST_ID']) ? $arParams['LIST_ID'] : ''; if ($listID === '') { $listID = uniqid('dedupe_'); } $arResult['LIST_ID'] = $listID; $arResult['ERRORS'] = array(); $arResult['MESSAGES'] = array(); $entityTypeID = isset($arParams['ENTITY_TYPE_ID']) ? intval($arParams['ENTITY_TYPE_ID']) : CCrmOwnerType::Undefined; if ($entityTypeID === CCrmOwnerType::Undefined && isset($arParams['ENTITY_TYPE'])) { $entityTypeID = CCrmOwnerType::ResolveID($arParams['ENTITY_TYPE']); } if ($entityTypeID !== CCrmOwnerType::Contact && $entityTypeID !== CCrmOwnerType::Company && $entityTypeID !== CCrmOwnerType::Lead) { ShowError(GetMessage('CRM_DEDUPE_LIST_INVALID_ENTITY_TYPE', array('#TYPE_NAME#' => CCrmOwnerType::ResolveName($entityTypeID)))); return; } $arResult['ENTITY_TYPE_ID'] = $entityTypeID; $entityTypeName = $arResult['ENTITY_TYPE_NAME'] = \CCrmOwnerType::ResolveName($entityTypeID); //TYPE INDEX INFO $typeInfos = array(); $indexedTypes = $arResult['TYPES'] = Integrity\DuplicateIndexBuilder::getExistedTypes($entityTypeID, $userID); $supportedTypes = $arResult['SUPPORTED_TYPES'] = Integrity\DuplicateIndexType::getSupportedTypes($entityTypeID); $typeDescriptions = $arResult['TYPE_DESCRIPTIONS'] = Integrity\DuplicateIndexType::getAllDescriptions(); $selectedTypes = array(); $filterTypeID = isset($_GET['typeId']) ? (int) $_GET['typeId'] : Integrity\DuplicateIndexType::UNDEFINED; $skippedTypeIDs = array();
public static function GetDocumentAuthorID($documentId) { if (!is_array($documentId) || count($documentId) < 3) { return 0; } $documentInfo = self::GetDocumentInfo($documentId[2]); $entityTypeName = isset($documentInfo['TYPE']) ? $documentInfo['TYPE'] : ''; $entityId = isset($documentInfo['ID']) ? intval($documentInfo['ID']) : 0; return CCrmOwnerType::GetResponsibleID(CCrmOwnerType::ResolveID($entityTypeName), $entityId, false); }
} CCrmEntityHelper::PrepareMultiFieldFilter($arFilter); $arImmutableFilters = array('FM', 'ID', 'ASSIGNED_BY_ID', 'CURRENCY_ID', 'CONTACT_ID', 'COMPANY_ID', 'LEAD_ID', 'DEAL_ID', 'CREATED_BY_ID', 'MODIFY_BY_ID', 'PRODUCT_ROW_PRODUCT_ID'); foreach ($arFilter as $k => $v) { if (in_array($k, $arImmutableFilters, true)) { continue; } $arMatch = array(); if (in_array($k, array('PRODUCT_ID', 'STATUS_ID', 'COMPANY_ID', 'LEAD_ID', 'DEAL_ID', 'CONTACT_ID'))) { // Bugfix #23121 - to suppress comparison by LIKE $arFilter['=' . $k] = $v; unset($arFilter[$k]); } elseif ($k === 'ENTITIES_LINKS') { $ownerData = explode('_', $v); if (count($ownerData) > 1) { $ownerTypeName = CCrmOwnerType::ResolveName(CCrmOwnerType::ResolveID($ownerData[0])); $ownerID = intval($ownerData[1]); if (!empty($ownerTypeName) && $ownerID > 0) { $arFilter[$ownerTypeName . '_ID'] = $ownerID; } } unset($arFilter[$k]); } elseif (preg_match('/(.*)_from$/i' . BX_UTF_PCRE_MODIFIER, $k, $arMatch)) { if (strlen($v) > 0) { $arFilter['>=' . $arMatch[1]] = $v; } unset($arFilter[$k]); } elseif (preg_match('/(.*)_to$/i' . BX_UTF_PCRE_MODIFIER, $k, $arMatch)) { if (strlen($v) > 0) { if (($arMatch[1] == 'DATE_CREATE' || $arMatch[1] == 'DATE_MODIFY') && !preg_match('/\\d{1,2}:\\d{1,2}(:\\d{1,2})?$/' . BX_UTF_PCRE_MODIFIER, $v)) { $v .= ' 23:59:59';
if (!CModule::IncludeModule('crm') || !CCrmSecurityHelper::IsAuthorized() || !check_bitrix_sessid()) { die; } $componentData = isset($_REQUEST['PARAMS']) && is_array($_REQUEST['PARAMS']) ? $_REQUEST['PARAMS'] : array(); $componentParams = isset($componentData['params']) && is_array($componentData['params']) ? $componentData['params'] : array(); //Sanitaizing of Bindings (Only one binding is allowed in current context) $bindings = isset($componentParams['BINDINGS']) && is_array($componentParams['BINDINGS']) ? $componentParams['BINDINGS'] : array(); if (empty($bindings)) { die; } $binding = $bindings[0]; if (!is_array($binding)) { die; } $ownerTypeName = isset($binding['TYPE_NAME']) ? $binding['TYPE_NAME'] : ''; $ownerTypeID = CCrmOwnerType::ResolveID($ownerTypeName); $ownerID = isset($binding['ID']) ? (int) $binding['ID'] : 0; if ($ownerTypeID === CCrmOwnerType::Undefined || $ownerID <= 0) { die; } $userPermissions = CCrmPerms::GetCurrentUserPermissions(); if (!CCrmActivity::CheckReadPermission($ownerTypeID, $ownerID, $userPermissions)) { die; } if (count($bindings) > 1) { array_splice($bindings, 1); } $componentParams['BINDINGS'] = $componentData['params']['BINDINGS'] = $bindings; //Sanitaizing of Permission Type $permissionType = isset($componentParams['PERMISSION_TYPE']) ? strtoupper($componentParams['PERMISSION_TYPE']) : 'READ'; if ($permissionType !== 'READ' && !CCrmActivity::CheckUpdatePermission($ownerTypeID, $ownerID, $userPermissions)) {
public static function EmailMessageAdd($arMessageFields, $ACTION_VARS) { if (!CModule::IncludeModule('crm')) { return false; } $date = isset($arMessageFields['FIELD_DATE']) ? $arMessageFields['FIELD_DATE'] : ''; $maxAgeDays = intval(COption::GetOptionString('crm', 'email_max_age', 7)); $maxAge = $maxAgeDays > 0 ? $maxAgeDays * 86400 : 0; if ($maxAge > 0 && $date !== '') { $now = time() + CTimeZone::GetOffset(); $timestamp = MakeTimeStamp($date, FORMAT_DATETIME); if ($now - $timestamp > $maxAge) { //Time threshold is exceeded return false; } } $crmEmail = strtolower(trim(COption::GetOptionString('crm', 'mail', ''))); $msgID = isset($arMessageFields['ID']) ? intval($arMessageFields['ID']) : 0; $mailboxID = isset($arMessageFields['MAILBOX_ID']) ? intval($arMessageFields['MAILBOX_ID']) : 0; $from = isset($arMessageFields['FIELD_FROM']) ? $arMessageFields['FIELD_FROM'] : ''; $replyTo = isset($arMessageFields['FIELD_REPLY_TO']) ? $arMessageFields['FIELD_REPLY_TO'] : ''; if ($replyTo !== '') { // Ignore FROM if REPLY_TO EXISTS $from = $replyTo; } $addresserInfo = CCrmMailHelper::ParseEmail($from); if ($crmEmail !== '' && strcasecmp($addresserInfo['EMAIL'], $crmEmail) === 0) { // Ignore emails from ourselves return false; } $to = isset($arMessageFields['FIELD_TO']) ? $arMessageFields['FIELD_TO'] : ''; $cc = isset($arMessageFields['FIELD_CC']) ? $arMessageFields['FIELD_CC'] : ''; $bcc = isset($arMessageFields['FIELD_BCC']) ? $arMessageFields['FIELD_BCC'] : ''; $addresseeEmails = array_unique(array_merge($to !== '' ? CMailUtil::ExtractAllMailAddresses($to) : array(), $cc !== '' ? CMailUtil::ExtractAllMailAddresses($cc) : array(), $bcc !== '' ? CMailUtil::ExtractAllMailAddresses($bcc) : array()), SORT_STRING); if ($mailboxID > 0) { $dbMailbox = CMailBox::GetById($mailboxID); $arMailbox = $dbMailbox->Fetch(); // POP3 mailboxes are ignored - they bound to single email if ($arMailbox && $arMailbox['SERVER_TYPE'] === 'smtp' && (empty($crmEmail) || !in_array($crmEmail, $addresseeEmails, true))) { return false; } } $subject = isset($arMessageFields['SUBJECT']) ? $arMessageFields['SUBJECT'] : ''; $body = isset($arMessageFields['BODY']) ? $arMessageFields['BODY'] : ''; $arBodyEmails = null; $userID = 0; $parentID = 0; $ownerTypeID = CCrmOwnerType::Undefined; $ownerID = 0; $addresserID = self::FindUserIDByEmail($addresserInfo['EMAIL']); if ($addresserID > 0 && Bitrix\Crm\Integration\IntranetManager::isExternalUser($addresserID)) { //Forget about extranet user $addresserID = 0; } $arCommEmails = $addresserID <= 0 ? array($addresserInfo['EMAIL']) : ($crmEmail !== '' ? array_diff($addresseeEmails, array($crmEmail)) : $addresseeEmails); //Trying to fix strange behaviour of array_diff under OPcache (issue #60862) $arCommEmails = array_filter($arCommEmails); $targInfo = CCrmActivity::ParseUrn(CCrmActivity::ExtractUrnFromMessage($arMessageFields, CCrmEMailCodeAllocation::GetCurrent())); $targActivity = $targInfo['ID'] > 0 ? CCrmActivity::GetByID($targInfo['ID'], false) : null; // Check URN if (!$targActivity && (!isset($targActivity['URN']) || strtoupper($targActivity['URN']) !== strtoupper($targInfo['URN']))) { $targActivity = null; } if ($targActivity) { $postingID = self::ExtractPostingID($arMessageFields); if ($postingID > 0 && isset($targActivity['ASSOCIATED_ENTITY_ID']) && intval($targActivity['ASSOCIATED_ENTITY_ID']) === $postingID) { // Ignore - it is our message. return false; } $parentID = $targActivity['ID']; $subject = CCrmActivity::ClearUrn($subject); if ($addresserID > 0) { $userID = $addresserID; } elseif (isset($targActivity['RESPONSIBLE_ID'])) { $userID = $targActivity['RESPONSIBLE_ID']; } if (isset($targActivity['OWNER_TYPE_ID'])) { $ownerTypeID = intval($targActivity['OWNER_TYPE_ID']); } if (isset($targActivity['OWNER_ID'])) { $ownerID = intval($targActivity['OWNER_ID']); } $arCommData = self::ExtractCommsFromEmails($arCommEmails); if ($ownerTypeID > 0 && $ownerID > 0) { if (empty($arCommData)) { if ($addresserID > 0) { foreach ($addresseeEmails as $email) { if ($email === $crmEmail) { continue; } $arCommData = array(self::CreateComm($ownerTypeID, $ownerID, $email)); } } else { $arCommData = array(self::CreateComm($ownerTypeID, $ownerID, $addresserInfo['EMAIL'])); } } elseif ($ownerTypeID !== CCrmOwnerType::Deal) { //Check if owner in communications. Otherwise clear owner. //There is only one exception for DEAL - it entity has no communications $isOwnerInComms = false; foreach ($arCommData as &$arCommItem) { $commEntityTypeID = isset($arCommItem['ENTITY_TYPE_ID']) ? $arCommItem['ENTITY_TYPE_ID'] : CCrmOwnerType::Undefined; $commEntityID = isset($arCommItem['ENTITY_ID']) ? $arCommItem['ENTITY_ID'] : 0; if ($commEntityTypeID === $ownerTypeID && $commEntityID === $ownerID) { $isOwnerInComms = true; break; } } unset($arCommItem); if (!$isOwnerInComms) { $ownerTypeID = CCrmOwnerType::Undefined; $ownerID = 0; } } } } else { if ($addresserID > 0) { //It is email from registred user $userID = $addresserID; if (empty($arCommEmails)) { $arBodyEmails = self::ExtractEmailsFromBody($body); //Clear system user emails if (!empty($arBodyEmails)) { foreach ($arBodyEmails as $email) { if (self::FindUserIDByEmail($email) <= 0) { $arCommEmails[] = $email; } } } } // Try to resolve communications $arCommData = self::ExtractCommsFromEmails($arCommEmails); } else { //It is email from unknown user //Try to resolve bindings from addresser $arCommData = self::ExtractCommsFromEmails($arCommEmails); if (!empty($arCommData)) { // Try to resolve responsible user foreach ($arCommData as &$arComm) { $userID = self::ResolveResponsibleID($arComm['ENTITY_TYPE_ID'], $arComm['ENTITY_ID']); if ($userID > 0) { break; } } unset($arComm); } } // Try to resolve owner by old-style method--> $arACTION_VARS = explode('&', $ACTION_VARS); for ($i = 0, $ic = count($arACTION_VARS); $i < $ic; $i++) { $v = $arACTION_VARS[$i]; if ($pos = strpos($v, '=')) { $name = substr($v, 0, $pos); ${$name} = urldecode(substr($v, $pos + 1)); } } $arTypeNames = CCrmOwnerType::GetNames(array(CCrmOwnerType::Lead, CCrmOwnerType::Deal, CCrmOwnerType::Contact, CCrmOwnerType::Company)); foreach ($arTypeNames as $typeName) { $regexVar = 'W_CRM_ENTITY_REGEXP_' . $typeName; if (empty(${$regexVar})) { continue; } $match = array(); if (preg_match('/' . ${$regexVar} . '/i' . BX_UTF_PCRE_MODIFIER, $subject, $match) === 1) { $ownerID = intval($match[1]); $ownerTypeID = CCrmOwnerType::ResolveID($typeName); break; } } // <-- Try to resolve owner by old-style method // Filter communications by owner if ($ownerTypeID > 0 && $ownerID > 0) { if (!empty($arCommData)) { foreach ($arCommData as $commKey => $arComm) { if ($arComm['ENTITY_TYPE_ID'] === $ownerTypeID && $arComm['ENTITY_ID'] === $ownerID) { continue; } unset($arCommData[$commKey]); } $arCommData = array_values($arCommData); } if (empty($arCommData)) { if ($addresserID > 0) { foreach ($addresseeEmails as $email) { if ($email === $crmEmail) { continue; } $arCommData = array(self::CreateComm($ownerTypeID, $ownerID, $email)); } } else { $arCommData = array(self::CreateComm($ownerTypeID, $ownerID, $addresserInfo['EMAIL'])); } } } } $arBindingData = self::ConvertCommsToBindings($arCommData); // Check bindings for converted leads --> // Not Existed entities are ignored. Converted leads are ignored if their associated entities (contacts, companies, deals) are contained in bindings. $arCorrectedBindingData = array(); $arConvertedLeadData = array(); foreach ($arBindingData as $bindingKey => &$arBinding) { if ($arBinding['TYPE_ID'] !== CCrmOwnerType::Lead) { if (self::IsEntityExists($arBinding['TYPE_ID'], $arBinding['ID'])) { $arCorrectedBindingData[$bindingKey] = $arBinding; } continue; } $arFields = self::GetEntity(CCrmOwnerType::Lead, $arBinding['ID'], array('STATUS_ID')); if (!is_array($arFields)) { continue; } if (isset($arFields['STATUS_ID']) && $arFields['STATUS_ID'] === 'CONVERTED') { $arConvertedLeadData[$bindingKey] = $arBinding; } else { $arCorrectedBindingData[$bindingKey] = $arBinding; } } unset($arBinding); foreach ($arConvertedLeadData as &$arConvertedLead) { $leadID = $arConvertedLead['ID']; $exists = false; $dbRes = CCrmCompany::GetListEx(array(), array('LEAD_ID' => $leadID, 'CHECK_PERMISSIONS' => 'N'), false, false, array('ID')); if ($dbRes) { while ($arRes = $dbRes->Fetch()) { if (isset($arCorrectedBindingData[self::PrepareEntityKey(CCrmOwnerType::Company, $arRes['ID'])])) { $exists = true; break; } } } if ($exists) { continue; } $dbRes = CCrmContact::GetListEx(array(), array('LEAD_ID' => $leadID, 'CHECK_PERMISSIONS' => 'N'), false, false, array('ID')); if ($dbRes) { while ($arRes = $dbRes->Fetch()) { if (isset($arCorrectedBindingData[self::PrepareEntityKey(CCrmOwnerType::Contact, $arRes['ID'])])) { $exists = true; break; } } } if ($exists) { continue; } $dbRes = CCrmDeal::GetListEx(array(), array('LEAD_ID' => $leadID, 'CHECK_PERMISSIONS' => 'N'), false, false, array('ID')); if ($dbRes) { while ($arRes = $dbRes->Fetch()) { if (isset($arCorrectedBindingData[self::PrepareEntityKey(CCrmOwnerType::Deal, $arRes['ID'])])) { $exists = true; break; } } } if ($exists) { continue; } $arCorrectedBindingData[self::PrepareEntityKey(CCrmOwnerType::Lead, $leadID)] = $arConvertedLead; } unset($arConvertedLead); $arBindingData = $arCorrectedBindingData; // <-- Check bindings for converted leads // If no bindings are found then create new lead from this message // Skip lead creation if email list is empty. Otherwise we will create lead with no email-addresses. It is absolutely useless. $emailQty = count($arCommEmails); if (empty($arBindingData) && $emailQty > 0) { if (strtoupper(COption::GetOptionString('crm', 'email_create_lead_for_new_addresser', 'Y')) !== 'Y') { // Creation of new lead is not allowed return true; } //"Lead from forwarded email..." or "Lead from email..." $title = $subject !== '' ? $subject : GetMessage($addresserID > 0 ? 'CRM_MAIL_LEAD_FROM_USER_EMAIL_TITLE' : 'CRM_MAIL_LEAD_FROM_EMAIL_TITLE', array('%SENDER%' => $addresserInfo['ORIGINAL'])); $comment = ''; if ($body !== '') { // Remove extra new lines (fix for #31807) $comment = preg_replace("/(\r\n|\n|\r)+/", '<br/>', htmlspecialcharsbx($body)); } if ($comment === '') { $comment = htmlspecialcharsbx($subject); } $name = ''; if ($addresserID <= 0) { $name = $addresserInfo['NAME']; } else { //Try get name from body for ($i = 0; $i < $emailQty; $i++) { $email = $arCommEmails[$i]; $match = array(); if (preg_match('/"([^"]+)"\\s*<' . $email . '>/i' . BX_UTF_PCRE_MODIFIER, $body, $match) === 1 && count($match) > 1) { $name = $match[1]; break; } if (preg_match('/"([^"]+)"\\s*[\\s*mailto\\:\\s*' . $email . ']/i' . BX_UTF_PCRE_MODIFIER, $body, $match) === 1 && count($match) > 1) { $name = $match[1]; break; } } if ($name === '') { $name = $arCommEmails[0]; } } $arLeadFields = array('TITLE' => $title, 'NAME' => $name, 'STATUS_ID' => 'NEW', 'COMMENTS' => $comment, 'SOURCE_DESCRIPTION' => GetMessage('CRM_MAIL_LEAD_FROM_EMAIL_SOURCE', array('%SENDER%' => $addresserInfo['ORIGINAL'])), 'OPENED' => 'Y', 'FM' => array('EMAIL' => array())); $sourceList = CCrmStatus::GetStatusList('SOURCE'); $sourceID = COption::GetOptionString('crm', 'email_lead_source_id', ''); if ($sourceID === '' || !isset($sourceList[$sourceID])) { if (isset($sourceList['EMAIL'])) { $sourceID = 'EMAIL'; } elseif (isset($sourceList['OTHER'])) { $sourceID = 'OTHER'; } } if ($sourceID !== '') { $arLeadFields['SOURCE_ID'] = $sourceID; } $responsibleID = intval(COption::GetOptionString('crm', 'email_lead_responsible_id', 0)); if ($responsibleID > 0) { $arLeadFields['CREATED_BY_ID'] = $arLeadFields['MODIFY_BY_ID'] = $arLeadFields['ASSIGNED_BY_ID'] = $responsibleID; if ($userID === 0) { $userID = $responsibleID; } } for ($i = 0; $i < $emailQty; $i++) { $arLeadFields['FM']['EMAIL']['n' . ($i + 1)] = array('VALUE_TYPE' => 'WORK', 'VALUE' => $arCommEmails[$i]); } $leadEntity = new CCrmLead(false); $leadID = $leadEntity->Add($arLeadFields, true, array('DISABLE_USER_FIELD_CHECK' => true, 'REGISTER_SONET_EVENT' => true, 'CURRENT_USER' => $responsibleID)); // TODO: log error if ($leadID > 0) { $arBizProcErrors = array(); CCrmBizProcHelper::AutoStartWorkflows(CCrmOwnerType::Lead, $leadID, CCrmBizProcEventType::Create, $arBizProcErrors); $arCommData = array(); for ($i = 0; $i < $emailQty; $i++) { $arCommData[] = self::CreateComm(CCrmOwnerType::Lead, $leadID, $arCommEmails[$i]); } $arBindingData = array(self::PrepareEntityKey(CCrmOwnerType::Lead, $leadID) => self::CreateBinding(CCrmOwnerType::Lead, $leadID)); } } // Terminate processing if no bindings are found. if (empty($arBindingData)) { // Try to export vcf-files before exit if email from registered user if ($addresserID > 0) { $dbAttachment = CMailAttachment::GetList(array(), array('MESSAGE_ID' => $msgID)); while ($arAttachment = $dbAttachment->Fetch()) { if (GetFileExtension(strtolower($arAttachment['FILE_NAME'])) === 'vcf') { if ($arAttachment['FILE_ID']) { $arAttachment['FILE_DATA'] = CMailAttachment::getContents($arAttachment); } self::TryImportVCard($arAttachment['FILE_DATA']); } } } return false; } // If owner info not defined set it by default if ($ownerID <= 0 || $ownerTypeID <= 0) { if (count($arBindingData) > 1) { // Search owner in specified order: Contact, Company, Lead. $arTypeIDs = array(CCrmOwnerType::Contact, CCrmOwnerType::Company, CCrmOwnerType::Lead); foreach ($arTypeIDs as $typeID) { foreach ($arBindingData as &$arBinding) { if ($arBinding['TYPE_ID'] === $typeID) { $ownerTypeID = $typeID; $ownerID = $arBinding['ID']; break; } } unset($arBinding); if ($ownerID > 0 && $ownerTypeID > 0) { break; } } } if ($ownerID <= 0 || $ownerTypeID <= 0) { $arBinding = array_shift(array_values($arBindingData)); $ownerTypeID = $arBinding['TYPE_ID']; $ownerID = $arBinding['ID']; } } // Precessing of attachments --> $attachmentMaxSizeMb = intval(COption::GetOptionString('crm', 'email_attachment_max_size', 16)); $attachmentMaxSize = $attachmentMaxSizeMb > 0 ? $attachmentMaxSizeMb * 1048576 : 0; $arFilesData = array(); $dbAttachment = CMailAttachment::GetList(array(), array('MESSAGE_ID' => $msgID)); $arBannedAttachments = array(); while ($arAttachment = $dbAttachment->Fetch()) { if ($arAttachment['FILE_NAME'] === '1.tmp') { // HACK: For bug in module 'Mail' continue; } elseif (GetFileExtension(strtolower($arAttachment['FILE_NAME'])) === 'vcf') { if ($arAttachment['FILE_ID']) { $arAttachment['FILE_DATA'] = CMailAttachment::getContents($arAttachment); } self::TryImportVCard($arAttachment['FILE_DATA']); } $fileSize = isset($arAttachment['FILE_SIZE']) ? intval($arAttachment['FILE_SIZE']) : 0; if ($fileSize <= 0) { //Skip zero lenth files continue; } if ($attachmentMaxSize > 0 && $fileSize > $attachmentMaxSize) { //File size limit is exceeded $arBannedAttachments[] = array('name' => $arAttachment['FILE_NAME'], 'size' => $fileSize); continue; } if ($arAttachment['FILE_ID'] && empty($arAttachment['FILE_DATA'])) { $arAttachment['FILE_DATA'] = CMailAttachment::getContents($arAttachment); } $arFilesData[] = array('name' => $arAttachment['FILE_NAME'], 'type' => $arAttachment['CONTENT_TYPE'], 'content' => $arAttachment['FILE_DATA'], 'MODULE_ID' => 'crm'); } //<-- Precessing of attachments // Remove extra new lines (fix for #31807) $body = preg_replace("/(\r\n|\n|\r)+/", PHP_EOL, $body); $encodedBody = htmlspecialcharsbx($body); // Creating of new event --> $arEventBindings = array(); foreach ($arBindingData as &$arBinding) { $arEventBindings[] = array('ENTITY_TYPE' => $arBinding['TYPE_NAME'], 'ENTITY_ID' => $arBinding['ID']); } unset($arBinding); $eventText = ''; $eventText .= '<b>' . GetMessage('CRM_EMAIL_SUBJECT') . '</b>: ' . $subject . PHP_EOL; $eventText .= '<b>' . GetMessage('CRM_EMAIL_FROM') . '</b>: ' . $addresserInfo['EMAIL'] . PHP_EOL; $eventText .= '<b>' . GetMessage('CRM_EMAIL_TO') . '</b>: ' . implode($addresseeEmails, '; ') . PHP_EOL; if (!empty($arBannedAttachments)) { $eventText .= '<b>' . GetMessage('CRM_EMAIL_BANNENED_ATTACHMENTS', array('%MAX_SIZE%' => $attachmentMaxSizeMb)) . '</b>: '; foreach ($arBannedAttachments as &$attachmentInfo) { $eventText .= GetMessage('CRM_EMAIL_BANNENED_ATTACHMENT_INFO', array('%NAME%' => $attachmentInfo['name'], '%SIZE%' => round($attachmentInfo['size'] / 1048576, 1))); } unset($attachmentInfo); $eventText .= PHP_EOL; } $eventText .= $encodedBody; $CCrmEvent = new CCrmEvent(); $CCrmEvent->Add(array('USER_ID' => $userID, 'ENTITY' => array_values($arEventBindings), 'ENTITY_TYPE' => CCrmOwnerType::ResolveName($ownerTypeID), 'ENTITY_ID' => $ownerID, 'EVENT_NAME' => GetMessage('CRM_EMAIL_GET_EMAIL'), 'EVENT_TYPE' => 2, 'EVENT_TEXT_1' => $eventText, 'FILES' => $arFilesData), false); // <-- Creating of new event // Creating new activity --> $siteID = ''; $dbSites = CSite::GetList($by = 'sort', $order = 'desc', array('DEFAULT' => 'Y', 'ACTIVE' => 'Y')); $defaultSite = is_object($dbSites) ? $dbSites->Fetch() : null; if (is_array($defaultSite)) { $siteID = $defaultSite['LID']; } if ($siteID === '') { $siteID = 's1'; } $storageTypeID = CCrmActivity::GetDefaultStorageTypeID(); $arElementIDs = array(); foreach ($arFilesData as $fileData) { $fileID = CFile::SaveFile($fileData, 'crm'); if ($fileID > 0) { $elementID = StorageManager::saveEmailAttachment(CFile::GetFileArray($fileID), $storageTypeID, $siteID); if ($elementID > 0) { $arElementIDs[] = (int) $elementID; } } } $descr = preg_replace("/(\r\n|\n|\r)+/", '<br/>', $encodedBody); $now = ConvertTimeStamp(time() + CTimeZone::GetOffset(), 'FULL', $siteID); $direction = CCrmActivityDirection::Incoming; $completed = 'N'; // Incomming emails must be marked as 'Not Completed'. if ($addresserID > 0 && ActivitySettings::getValue(ActivitySettings::MARK_FORWARDED_EMAIL_AS_OUTGOING)) { $direction = CCrmActivityDirection::Outgoing; $completed = 'Y'; } $arActivityFields = array('OWNER_ID' => $ownerID, 'OWNER_TYPE_ID' => $ownerTypeID, 'TYPE_ID' => CCrmActivityType::Email, 'ASSOCIATED_ENTITY_ID' => 0, 'PARENT_ID' => $parentID, 'SUBJECT' => $subject, 'START_TIME' => $now, 'END_TIME' => $now, 'COMPLETED' => $completed, 'AUTHOR_ID' => $userID, 'RESPONSIBLE_ID' => $userID, 'PRIORITY' => CCrmActivityPriority::Medium, 'DESCRIPTION' => $descr, 'DESCRIPTION_TYPE' => CCrmContentType::Html, 'DIRECTION' => $direction, 'LOCATION' => '', 'NOTIFY_TYPE' => CCrmActivityNotifyType::None, 'STORAGE_TYPE_ID' => $storageTypeID, 'STORAGE_ELEMENT_IDS' => $arElementIDs); $arActivityFields['BINDINGS'] = array(); foreach ($arBindingData as &$arBinding) { $entityTypeID = $arBinding['TYPE_ID']; $entityID = $arBinding['ID']; if ($entityTypeID <= 0 || $entityID <= 0) { continue; } $arActivityFields['BINDINGS'][] = array('OWNER_TYPE_ID' => $entityTypeID, 'OWNER_ID' => $entityID); } unset($arBinding); $activityID = CCrmActivity::Add($arActivityFields, false, false, array('REGISTER_SONET_EVENT' => true)); if ($activityID > 0 && !empty($arCommData)) { CCrmActivity::SaveCommunications($activityID, $arCommData, $arActivityFields, false, false); $arActivityFields['COMMUNICATIONS'] = $arCommData; } //Notity responsible user if ($userID > 0 && $direction === CCrmActivityDirection::Incoming) { CCrmActivity::Notify($arActivityFields, CCrmNotifierSchemeType::IncomingEmail); } // <-- Creating new activity return true; }
$commType = isset($comm['TYPE']) ? strtoupper(strval($comm['TYPE'])) : ''; if ($commType === '') { $commType = 'EMAIL'; } $commValue = isset($comm['VALUE']) ? strval($comm['VALUE']) : ''; if ($commType === 'EMAIL' && $commValue !== '') { if (!check_email($commValue)) { __CrmMobileActivityEditEndResonse(array('ERROR' => GetMessage('CRM_ACTIVITY_EDIT_INVALID_EMAIL', array('#VALUE#' => $commValue)))); } $to[] = strtolower(trim($commValue)); } $comms[] = array('ID' => $commID, 'TYPE' => $commType, 'VALUE' => $commValue, 'ENTITY_ID' => $commEntityID, 'ENTITY_TYPE_ID' => CCrmOwnerType::ResolveID($commEntityType)); if ($commEntityType !== '') { $bindingKey = $commEntityID > 0 ? "{$commEntityType}_{$commEntityID}" : uniqid("{$commEntityType}_"); if (!isset($bindings[$bindingKey])) { $bindings[$bindingKey] = array('OWNER_TYPE_ID' => CCrmOwnerType::ResolveID($commEntityType), 'OWNER_ID' => $commEntityID); } } } unset($comm); if (empty($bindings)) { $bindings["{$ownerTypeName}_{$ownerID}"] = array('OWNER_TYPE_ID' => $ownerTypeID, 'OWNER_ID' => $ownerID); } // <-- Bindings & Communications if (empty($to)) { __CrmMobileActivityEditEndResonse(array('ERROR' => GetMessage('CRM_ACTIVITY_EDIT_EMAIL_EMPTY_TO_FIELD'))); } $nowStr = ConvertTimeStamp($now, 'FULL', SITE_ID); $subject = isset($data['SUBJECT']) ? strval($data['SUBJECT']) : ''; if ($subject === '') { $subject = GetMessage('CRM_ACTIVITY_EDIT_EMAIL_ACTION_DEFAULT_SUBJECT', array('#DATE#' => $nowStr));
public function processMethodRequest($name, $nameDetails, $arParams, $nav, $server) { $userPerms = CCrmPerms::GetCurrentUserPermissions(); if (!CCrmLead::CheckReadPermission(0, $userPerms) && !CCrmContact::CheckReadPermission(0, $userPerms) && !CCrmCompany::CheckReadPermission(0, $userPerms)) { throw new RestException('Access denied.'); } if (strtoupper($name) === 'FINDBYCOMM') { $type = strtoupper($this->resolveParam($arParams, 'type')); if ($type !== 'EMAIL' && $type !== 'PHONE') { if ($type === '') { throw new RestException("Communication type is not defined."); } else { throw new RestException("Communication type '{$type}' is not supported in current context."); } } $values = $this->resolveArrayParam($arParams, 'values'); if (!is_array($values) || count($values) === 0) { throw new RestException("Communication values is not defined."); } $entityTypeID = CCrmOwnerType::ResolveID($this->resolveMultiPartParam($arParams, array('entity', 'type'))); if ($entityTypeID === CCrmOwnerType::Deal) { throw new RestException("Deal is not supported in current context."); } $criterions = array(); $dups = array(); $qty = 0; foreach ($values as $value) { if (!is_string($value) || $value === '') { continue; } $criterion = new \Bitrix\Crm\Integrity\DuplicateCommunicationCriterion($type, $value); $isExists = false; foreach ($criterions as $curCriterion) { /** @var \Bitrix\Crm\Integrity\DuplicateCriterion $curCriterion */ if ($criterion->equals($curCriterion)) { $isExists = true; break; } } if ($isExists) { continue; } $criterions[] = $criterion; $duplicate = $criterion->find($entityTypeID, 20); if ($duplicate !== null) { $dups[] = $duplicate; } $qty++; if ($qty >= 20) { break; } } $entityByType = array(); foreach ($dups as $dup) { /** @var \Bitrix\Crm\Integrity\Duplicate $dup */ $entities = $dup->getEntities(); if (!(is_array($entities) && !empty($entities))) { continue; } //Each entity type limited by 50 items foreach ($entities as $entity) { /** @var \Bitrix\Crm\Integrity\DuplicateEntity $entity */ $entityTypeID = $entity->getEntityTypeID(); $entityTypeName = CCrmOwnerType::ResolveName($entityTypeID); $entityID = $entity->getEntityID(); if (!isset($entityByType[$entityTypeName])) { $entityByType[$entityTypeName] = array($entityID); } elseif (!in_array($entityID, $entityByType[$entityTypeName], true)) { $entityByType[$entityTypeName][] = $entityID; } } } return $entityByType; } throw new RestException('Method not found!', RestException::ERROR_METHOD_NOT_FOUND, CRestServer::STATUS_NOT_FOUND); }
use Bitrix\Crm\Integration\StorageType; if (!defined('B_PROLOG_INCLUDED') || B_PROLOG_INCLUDED !== true) { die; } if (!CModule::IncludeModule('crm')) { ShowError(GetMessage('CRM_MODULE_NOT_INSTALLED')); return; } CModule::IncludeModule('fileman'); $arResult['CONTAINER_ID'] = isset($arParams['~CONTAINER_ID']) ? $arParams['~CONTAINER_ID'] : ''; $arResult['PREFIX'] = isset($arParams['~PREFIX']) ? $arParams['~PREFIX'] : 'crm_default'; $arResult['EDITOR_ID'] = isset($arParams['~EDITOR_ID']) ? $arParams['~EDITOR_ID'] : $arResult['PREFIX'] . '_activity_editor'; $arResult['EDITOR_TYPE'] = isset($arParams['~EDITOR_TYPE']) ? $arParams['~EDITOR_TYPE'] : 'MIXED'; $arResult['EDITOR_ITEMS'] = isset($arParams['~EDITOR_ITEMS']) ? $arParams['~EDITOR_ITEMS'] : array(); $arResult['OWNER_TYPE'] = isset($arParams['~OWNER_TYPE']) ? $arParams['~OWNER_TYPE'] : ''; $arResult['OWNER_TYPE_ID'] = CCrmOwnerType::ResolveID($arResult['OWNER_TYPE']); $arResult['OWNER_ID'] = isset($arParams['~OWNER_ID']) ? $arParams['~OWNER_ID'] : 0; $arResult['READ_ONLY'] = isset($arParams['~READ_ONLY']) ? (bool) $arParams['~READ_ONLY'] : false; $arResult['ENABLE_UI'] = isset($arParams['~ENABLE_UI']) ? (bool) $arParams['~ENABLE_UI'] : true; $arResult['ENABLE_TOOLBAR'] = isset($arParams['~ENABLE_TOOLBAR']) ? (bool) $arParams['~ENABLE_TOOLBAR'] : true; $arResult['TOOLBAR_ID'] = isset($arParams['~TOOLBAR_ID']) ? $arParams['~TOOLBAR_ID'] : ''; $arResult['BUTTON_ID'] = isset($arParams['~BUTTON_ID']) ? $arParams['~BUTTON_ID'] : ''; $arResult['NAME_TEMPLATE'] = empty($arParams['NAME_TEMPLATE']) ? CSite::GetNameFormat(false) : str_replace(array("#NOBR#", "#/NOBR#"), array("", ""), $arParams["NAME_TEMPLATE"]); $arResult['ENABLE_TASK_ADD'] = isset($arParams['~ENABLE_TASK_ADD']) ? (bool) $arParams['~ENABLE_TASK_ADD'] : IsModuleInstalled('tasks'); $arResult['ENABLE_CALENDAR_EVENT_ADD'] = isset($arParams['~ENABLE_CALENDAR_EVENT_ADD']) ? (bool) $arParams['~ENABLE_CALENDAR_EVENT_ADD'] : IsModuleInstalled('calendar'); $arResult['ENABLE_EMAIL_ADD'] = isset($arParams['~ENABLE_EMAIL_ADD']) ? (bool) $arParams['~ENABLE_EMAIL_ADD'] : IsModuleInstalled('subscribe'); $arResult['EVENT_VIEW_TAB_ID'] = isset($arParams['~EVENT_VIEW_TAB_ID']) ? $arParams['~EVENT_VIEW_TAB_ID'] : 'tab_event'; $arResult['FORM_ID'] = isset($arParams['~FORM_ID']) ? $arParams['~FORM_ID'] : ''; $arResult['DISABLE_STORAGE_EDIT'] = isset($arParams['~DISABLE_STORAGE_EDIT']) ? (bool) $arParams['~DISABLE_STORAGE_EDIT'] : false; $storageTypeID = $arResult['STORAGE_TYPE_ID'] = CCrmActivity::GetDefaultStorageTypeID(); $arResult['ENABLE_DISK'] = $storageTypeID === StorageType::Disk;
$arResult['GADGET'] = isset($arParams['GADGET']) && $arParams['GADGET'] == 'Y' ? 'Y' : 'N'; $entityType = isset($arParams['ENTITY_TYPE']) ? $arParams['ENTITY_TYPE'] : ''; $entityTypeID = CCrmOwnerType::ResolveID($entityType); $arFilter = array(); if ($entityType !== '') { $arFilter['ENTITY_TYPE'] = $arResult['ENTITY_TYPE'] = $entityType; } if (isset($arParams['ENTITY_ID'])) { if (is_array($arParams['ENTITY_ID'])) { array_walk($arParams['ENTITY_ID'], create_function('&$v', '$v = (int)$v;')); $arFilter['ENTITY_ID'] = $arResult['ENTITY_ID'] = $arParams['ENTITY_ID']; } elseif ($arParams['ENTITY_ID'] > 0) { $arFilter['ENTITY_ID'] = $arResult['ENTITY_ID'] = (int) $arParams['ENTITY_ID']; } } else { $ownerTypeID = isset($arParams['OWNER_TYPE']) ? CCrmOwnerType::ResolveID($arParams['OWNER_TYPE']) : CCrmOwnerType::Undefined; $ownerID = isset($arParams['OWNER_ID']) ? (int) $arParams['OWNER_ID'] : 0; if ($ownerID > 0 && $ownerTypeID === CCrmOwnerType::Company && $entityTypeID === CCrmOwnerType::Contact) { $dbRes = CCrmContact::GetList(array(), array('COMPANY_ID' => $ownerID), array('ID')); $arContactID = array(); while ($arRow = $dbRes->Fetch()) { $arContactID[] = (int) $arRow['ID']; } if (empty($arContactID)) { return 0; } $arFilter['ENTITY_ID'] = $arResult['ENTITY_ID'] = $arContactID; } } if (isset($arParams['EVENT_COUNT'])) { $arResult['EVENT_COUNT'] = intval($arParams['EVENT_COUNT']) > 0 ? intval($arParams['EVENT_COUNT']) : 50;
/** * Get synchronization history. * @return array */ protected static function getHistory() { if (self::$history !== null) { return self::$history; } self::$history = array(); $s = Main\Config\Option::get('crm', 'crm_uf_sync_history', '', ''); $ary = $s !== '' ? unserialize($s) : null; if (is_array($ary)) { foreach ($ary as $item) { if (!is_array($item)) { continue; } $srcEntityTypeID = \CCrmOwnerType::ResolveID(isset($item['src']) ? $item['src'] : ''); $dstEntityTypeID = \CCrmOwnerType::ResolveID(isset($item['dst']) ? $item['dst'] : ''); if ($srcEntityTypeID === \CCrmOwnerType::Undefined || $dstEntityTypeID === \CCrmOwnerType::Undefined) { continue; } $sync = isset($item['sync']) ? $item['sync'] : ''; $check = isset($item['check']) ? $item['check'] : ''; try { self::$history["{$srcEntityTypeID}_{$dstEntityTypeID}"] = array('src' => $srcEntityTypeID, 'dst' => $dstEntityTypeID, 'sync' => $sync !== '' ? new DateTime($sync, \DateTime::ISO8601) : null, 'check' => $check !== '' ? new DateTime($check, \DateTime::ISO8601) : null, 'required' => isset($item['required']) ? $item['required'] : null); } catch (Main\ObjectException $e) { } } } return self::$history; }
case CTaskColumnList::COLUMN_STATUS: echo GetMessage('TASKS_LIST_ITEMS_STATUS_' . $task['REAL_STATUS']); break; case CTaskColumnList::COLUMN_PRIORITY: echo GetMessage('TASKS_LIST_ITEMS_PRIORITY_' . $task['PRIORITY']); break; case CTaskColumnList::COLUMN_UF_CRM: if (empty($task['UF_CRM_TASK'])) { break; } $collection = array(); sort($task['UF_CRM_TASK']); foreach ($task['UF_CRM_TASK'] as $value) { $crmElement = explode('_', $value); $type = $crmElement[0]; $typeId = CCrmOwnerType::ResolveID(CCrmOwnerTypeAbbr::ResolveName($type)); $title = CCrmOwnerType::GetCaption($typeId, $crmElement[1]); $url = CCrmOwnerType::GetShowUrl($typeId, $crmElement[1]); if (!isset($collection[$type])) { $collection[$type] = array(); } $collection[$type][] = '<a href="' . $url . '">' . $title . '</a>'; } if ($collection) { echo '<div class="tasks-list-crm-div">'; $prevType = null; foreach ($collection as $type => $items) { if ($type !== $prevType) { if ($prevType !== null) { echo ' '; }
public static function OnBeforeSocNetLogEntryGetRights($arEntryParams, &$arRights) { if ((!isset($arEntryParams["ENTITY_TYPE"]) || !isset($arEntryParams["ENTITY_ID"])) && isset($arEntryParams["LOG_ID"]) && intval($arEntryParams["LOG_ID"]) > 0) { if ($arLog = CSocNetLog::GetByID($arEntryParams["LOG_ID"])) { $arEntryParams["ENTITY_TYPE"] = $arLog["ENTITY_TYPE"]; $arEntryParams["ENTITY_ID"] = $arLog["ENTITY_ID"]; $arEntryParams["EVENT_ID"] = $arLog["EVENT_ID"]; } } if (!isset($arEntryParams["ENTITY_TYPE"]) || !in_array($arEntryParams["ENTITY_TYPE"], CCrmLiveFeedEntity::GetAll()) || !isset($arEntryParams["ENTITY_ID"])) { return true; } if ($arEntryParams["ENTITY_TYPE"] == CCrmLiveFeedEntity::Activity) { if (!isset($arEntryParams["ACTIVITY"])) { $arActivity = CCrmActivity::GetByID($arEntryParams["ENTITY_ID"]); if (!$arActivity) { return true; } $arEntryParams["ACTIVITY"] = $arActivity; $arEntryParams["ACTIVITY"]["COMMUNICATIONS"] = CCrmActivity::GetCommunications($arActivity["ID"]); } $arRights[] = CCrmLiveFeedEntity::GetByEntityTypeID($arEntryParams["ACTIVITY"]["OWNER_TYPE_ID"]) . $arEntryParams["ACTIVITY"]["OWNER_ID"]; $ownerEntityCode = $arEntryParams["ACTIVITY"]["OWNER_TYPE_ID"] . "_" . $arEntryParams["ACTIVITY"]["OWNER_ID"]; if (!empty($arEntryParams["ACTIVITY"]["COMMUNICATIONS"])) { foreach ($arEntryParams["ACTIVITY"]["COMMUNICATIONS"] as $arActivityCommunication) { if ($arActivityCommunication["ENTITY_TYPE_ID"] . "_" . $arActivityCommunication["ENTITY_ID"] == $ownerEntityCode) { $arRights[] = CCrmLiveFeedEntity::GetByEntityTypeID($arActivityCommunication["ENTITY_TYPE_ID"]) . $arActivityCommunication["ENTITY_ID"]; } } } if ($arEntryParams["ACTIVITY"]["TYPE_ID"] == CCrmActivityType::Task && intval($arEntryParams["ACTIVITY"]["ASSOCIATED_ENTITY_ID"]) > 0 && CModule::IncludeModule("tasks")) { $dbTask = CTasks::GetByID($arEntryParams["ACTIVITY"]["ASSOCIATED_ENTITY_ID"], false); if ($arTaskFields = $dbTask->Fetch()) { $arTaskOwners = isset($arTaskFields['UF_CRM_TASK']) ? $arTaskFields['UF_CRM_TASK'] : array(); $arOwnerData = array(); if (!is_array($arTaskOwners)) { $arTaskOwners = array($arTaskOwners); } $arFields['BINDINGS'] = array(); if (CCrmActivity::TryResolveUserFieldOwners($arTaskOwners, $arOwnerData, CCrmUserType::GetTaskBindingField())) { foreach ($arOwnerData as $arOwnerInfo) { $arRights[] = CCrmLiveFeedEntity::GetByEntityTypeID(CCrmOwnerType::ResolveID($arOwnerInfo['OWNER_TYPE_NAME'])) . $arOwnerInfo['OWNER_ID']; } } } } } elseif ($arEntryParams["ENTITY_TYPE"] == CCrmLiveFeedEntity::Invoice) { if (!isset($arEntryParams["INVOICE"])) { $arInvoice = CCrmInvoice::GetByID($arEntryParams["ENTITY_ID"]); if (!$arInvoice) { return true; } $arEntryParams["INVOICE"] = $arInvoice; } if (intval($arEntryParams["INVOICE"]["UF_CONTACT_ID"]) > 0) { $arRights[] = CCrmLiveFeedEntity::Contact . $arEntryParams["INVOICE"]["UF_CONTACT_ID"]; } if (intval($arEntryParams["INVOICE"]["UF_COMPANY_ID"]) > 0) { $arRights[] = CCrmLiveFeedEntity::Company . $arEntryParams["INVOICE"]["UF_COMPANY_ID"]; } if (intval($arEntryParams["INVOICE"]["UF_DEAL_ID"]) > 0) { $arRights[] = CCrmLiveFeedEntity::Deal . $arEntryParams["INVOICE"]["UF_DEAL_ID"]; } } else { $arRights[] = $arEntryParams["ENTITY_TYPE"] . $arEntryParams["ENTITY_ID"]; if (in_array($arEntryParams["EVENT_ID"], array("crm_lead_message", "crm_deal_message", "crm_contact_message", "crm_company_message"))) { $dbRight = CSocNetLogRights::GetList(array(), array("LOG_ID" => $arEntryParams["LOG_ID"])); while ($arRight = $dbRight->Fetch()) { $arRights[] = $arRight["GROUP_CODE"]; } } } return false; }
function GetCrmEntityCommunications($entityType, $entityID, $communicationType) { $fullNameFormat = \Bitrix\Crm\Format\PersonNameFormatter::getFormat(); if ($entityType === 'LEAD') { $data = array('ownerEntityType' => 'LEAD', 'ownerEntityId' => $entityID, 'entityType' => 'LEAD', 'entityId' => $entityID, 'entityTitle' => "{$entityType}_{$entityID}", 'entityDescription' => '', 'tabId' => 'main', 'communications' => array()); $entity = CCrmLead::GetByID($entityID); if (!$entity) { return array('ERROR' => 'Invalid data'); } // Prepare title $name = isset($entity['NAME']) ? $entity['NAME'] : ''; $secondName = isset($entity['SECOND_NAME']) ? $entity['SECOND_NAME'] : ''; $lastName = isset($entity['LAST_NAME']) ? $entity['LAST_NAME'] : ''; if ($name !== '' || $secondName !== '' || $lastName !== '') { $data['entityTitle'] = CUser::FormatName($fullNameFormat, array('LOGIN' => '', 'NAME' => $name, 'SECOND_NAME' => $secondName, 'LAST_NAME' => $lastName), false, false); $data['entityDescription'] = isset($entity['TITLE']) ? $entity['TITLE'] : ''; } else { $data['entityTitle'] = isset($entity['TITLE']) ? $entity['TITLE'] : ''; $data['entityDescription'] = ''; } // Try to load entity communications if (!CCrmActivity::CheckReadPermission(CCrmOwnerType::ResolveID($entityType), $entityID)) { return array('ERROR' => GetMessage('CRM_PERMISSION_DENIED')); } if ($communicationType !== '') { $dbResFields = CCrmFieldMulti::GetList(array('ID' => 'asc'), array('ENTITY_ID' => $entityType, 'ELEMENT_ID' => $entityID, 'TYPE_ID' => $communicationType)); while ($arField = $dbResFields->Fetch()) { if (empty($arField['VALUE'])) { continue; } $comm = array('type' => $communicationType, 'value' => $arField['VALUE']); $data['communications'][] = $comm; } } return array('DATA' => array('TABS' => array(array('id' => 'lead', 'title' => GetMessage('CRM_COMMUNICATION_TAB_LEAD'), 'active' => true, 'items' => array($data))))); } elseif ($entityType === 'DEAL') { $entity = CCrmDeal::GetByID($entityID); if (!$entity) { return array('ERROR' => 'Invalid data'); } $dealData = array(); // Prepare company data $entityCompanyData = null; $entityCompanyID = isset($entity['COMPANY_ID']) ? intval($entity['COMPANY_ID']) : 0; $entityCompany = $entityCompanyID > 0 ? CCrmCompany::GetByID($entityCompanyID) : null; if (is_array($entityCompany)) { $entityCompanyData = array('ownerEntityType' => 'DEAL', 'ownerEntityId' => $entityID, 'entityType' => 'COMPANY', 'entityId' => $entityCompanyID, 'entityTitle' => isset($entityCompany['TITLE']) ? $entityCompany['TITLE'] : '', 'entityDescription' => '', 'communications' => array()); if ($communicationType !== '') { $entityCompanyComms = CCrmActivity::PrepareCommunications('COMPANY', $entityCompanyID, $communicationType); foreach ($entityCompanyComms as &$entityCompanyComm) { $comm = array('type' => $entityCompanyComm['TYPE'], 'value' => $entityCompanyComm['VALUE']); $entityCompanyData['communications'][] = $comm; } unset($entityCompanyComm); } } // Try to get contact of deal $entityContactID = isset($entity['CONTACT_ID']) ? intval($entity['CONTACT_ID']) : 0; if ($entityContactID > 0) { $entityContact = CCrmContact::GetByID($entityContactID); if (is_array($entityContact)) { $item = array('ownerEntityType' => 'DEAL', 'ownerEntityId' => $entityID, 'entityType' => 'CONTACT', 'entityId' => $entityContactID, 'entityTitle' => CUser::FormatName($fullNameFormat, array('LOGIN' => '', 'NAME' => $entityContact['NAME'], 'LAST_NAME' => $entityContact['LAST_NAME'], 'SECOND_NAME' => $entityContact['SECOND_NAME']), false, false), 'tabId' => 'deal', 'communications' => array()); $entityCompany = isset($entityContact['COMPANY_ID']) ? CCrmCompany::GetByID($entityContact['COMPANY_ID']) : null; if ($entityCompany && isset($entityCompany['TITLE'])) { $item['entityDescription'] = $entityCompany['TITLE']; } if ($communicationType !== '') { $entityContactComms = CCrmActivity::PrepareCommunications('CONTACT', $entityContactID, $communicationType); foreach ($entityContactComms as &$entityContactComm) { $comm = array('type' => $entityContactComm['TYPE'], 'value' => $entityContactComm['VALUE']); $item['communications'][] = $comm; } unset($entityContactComm); } if ($communicationType === '' || !empty($item['communications'])) { $dealData["CONTACT_{$entityContactID}"] = $item; } } } if ($entityCompanyData && !empty($entityCompanyData['communications'])) { $dealData['COMPANY_' . $entityCompanyID] = $entityCompanyData; $dealData['COMPANY_' . $entityCompanyID]['tabId'] = 'deal'; } // Try to get previous communications $entityComms = CCrmActivity::GetCommunicationsByOwner('DEAL', $entityID, $communicationType); foreach ($entityComms as &$entityComm) { CCrmActivity::PrepareCommunicationInfo($entityComm); $key = "{$entityComm['ENTITY_TYPE']}_{$entityComm['ENTITY_ID']}"; if (!isset($dealData[$key])) { $dealData[$key] = array('ownerEntityType' => 'DEAL', 'ownerEntityId' => $entityID, 'entityType' => CCrmOwnerType::ResolveName($entityComm['ENTITY_TYPE_ID']), 'entityId' => $entityComm['ENTITY_ID'], 'entityTitle' => isset($entityComm['TITLE']) ? $entityComm['TITLE'] : '', 'entityDescription' => isset($entityComm['DESCRIPTION']) ? $entityComm['DESCRIPTION'] : '', 'tabId' => 'deal', 'communications' => array()); } if ($communicationType !== '') { $commFound = false; foreach ($dealData[$key]['communications'] as &$comm) { if ($comm['value'] === $entityComm['VALUE']) { $commFound = true; break; } } unset($comm); if ($commFound) { continue; } $comm = array('type' => $entityComm['TYPE'], 'value' => $entityComm['VALUE']); $dealData[$key]['communications'][] = $comm; } } unset($entityComm); $companyData = array(); // Try to get contacts of company if ($entityCompany > 0) { $entityComms = CCrmActivity::GetCompanyCommunications($entityCompanyID, $communicationType); foreach ($entityComms as &$entityComm) { CCrmActivity::PrepareCommunicationInfo($entityComm); $key = "{$entityComm['ENTITY_TYPE']}_{$entityComm['ENTITY_ID']}"; if (!isset($companyData[$key])) { $companyData[$key] = array('ownerEntityType' => 'DEAL', 'ownerEntityId' => $entityID, 'entityType' => CCrmOwnerType::ResolveName($entityComm['ENTITY_TYPE_ID']), 'entityId' => $entityComm['ENTITY_ID'], 'entityTitle' => isset($entityComm['TITLE']) ? $entityComm['TITLE'] : '', 'entityDescription' => isset($entityComm['DESCRIPTION']) ? $entityComm['DESCRIPTION'] : '', 'tabId' => 'company', 'communications' => array()); } if ($communicationType !== '') { $comm = array('type' => $entityComm['TYPE'], 'value' => $entityComm['VALUE']); $companyData[$key]['communications'][] = $comm; } } unset($entityComm); } if ($entityCompanyData && !empty($entityCompanyData['communications'])) { $companyData['COMPANY_' . $entityCompanyID] = $entityCompanyData; $companyData['COMPANY_' . $entityCompanyID]['tabId'] = 'company'; } return array('DATA' => array('TABS' => array(array('id' => 'deal', 'title' => GetMessage('CRM_COMMUNICATION_TAB_DEAL'), 'active' => true, 'items' => array_values($dealData)), array('id' => 'company', 'title' => GetMessage('CRM_COMMUNICATION_TAB_COMPANY'), 'items' => array_values($companyData))))); } elseif ($entityType === 'COMPANY') { $companyData = array(); $entity = CCrmCompany::GetByID($entityID); if (!$entity) { return array('ERROR' => 'Invalid data'); } $companyItem = array('ownerEntityType' => 'COMPANY', 'ownerEntityId' => $entityID, 'entityType' => 'COMPANY', 'entityId' => $entityID, 'entityTitle' => isset($entity['TITLE']) ? $entity['TITLE'] : "{$entityType}_{$entityID}", 'entityDescription' => '', 'tabId' => 'company', 'communications' => array()); // Try to load entity communications if (!CCrmActivity::CheckReadPermission(CCrmOwnerType::ResolveID($entityType), $entityID)) { return array('ERROR' => GetMessage('CRM_PERMISSION_DENIED')); } if ($communicationType !== '') { $dbResFields = CCrmFieldMulti::GetList(array('ID' => 'asc'), array('ENTITY_ID' => $entityType, 'ELEMENT_ID' => $entityID, 'TYPE_ID' => $communicationType)); while ($arField = $dbResFields->Fetch()) { if (empty($arField['VALUE'])) { continue; } $comm = array('type' => $communicationType, 'value' => $arField['VALUE']); $companyItem['communications'][] = $comm; } } $companyData["{$entityType}_{$entityID}"] = $companyItem; if ($communicationType !== '') { $entityComms = CCrmActivity::GetCompanyCommunications($entityID, $communicationType, 50); foreach ($entityComms as &$entityComm) { CCrmActivity::PrepareCommunicationInfo($entityComm); $key = "{$entityComm['ENTITY_TYPE']}_{$entityComm['ENTITY_ID']}"; if (!isset($companyData[$key])) { $companyData[$key] = array('ownerEntityType' => 'COMPANY', 'ownerEntityId' => $entityID, 'entityType' => $entityComm['ENTITY_TYPE'], 'entityId' => $entityComm['ENTITY_ID'], 'entityTitle' => isset($entityComm['TITLE']) ? $entityComm['TITLE'] : '', 'entityDescription' => isset($entityComm['DESCRIPTION']) ? $entityComm['DESCRIPTION'] : '', 'tabId' => 'company', 'communications' => array()); } $comm = array('type' => $entityComm['TYPE'], 'value' => $entityComm['VALUE']); $companyData[$key]['communications'][] = $comm; } unset($entityComm); } return array('DATA' => array('TABS' => array(array('id' => 'company', 'title' => GetMessage('CRM_COMMUNICATION_TAB_COMPANY'), 'active' => true, 'items' => array_values($companyData))))); } elseif ($entityType === 'CONTACT') { $contactData = array(); $entity = CCrmContact::GetByID($entityID); if (!$entity) { return array('ERROR' => 'Invalid data'); } $entityCompany = isset($entity['COMPANY_ID']) ? CCrmCompany::GetByID($entity['COMPANY_ID']) : null; $contactItem = array('ownerEntityType' => 'CONTACT', 'ownerEntityId' => $entityID, 'entityType' => 'CONTACT', 'entityId' => $entityID, 'entityTitle' => CUser::FormatName($fullNameFormat, array('LOGIN' => '', 'NAME' => $entity['NAME'], 'LAST_NAME' => $entity['LAST_NAME'], 'SECOND_NAME' => $entity['SECOND_NAME']), false, false), 'entityDescription' => $entityCompany && isset($entityCompany['TITLE']) ? $entityCompany['TITLE'] : '', 'tabId' => 'contact', 'communications' => array()); // Try to load entity communications if (!CCrmActivity::CheckReadPermission(CCrmOwnerType::ResolveID($entityType), $entityID)) { return array('ERROR' => GetMessage('CRM_PERMISSION_DENIED')); } if ($communicationType !== '') { $dbResFields = CCrmFieldMulti::GetList(array('ID' => 'asc'), array('ENTITY_ID' => $entityType, 'ELEMENT_ID' => $entityID, 'TYPE_ID' => $communicationType)); while ($arField = $dbResFields->Fetch()) { if (empty($arField['VALUE'])) { continue; } $comm = array('type' => $communicationType, 'value' => $arField['VALUE']); $contactItem['communications'][] = $comm; } } $contactData["{$entityType}_{$entityID}"] = $contactItem; return array('DATA' => array('TABS' => array(array('id' => 'contact', 'title' => GetMessage('CRM_COMMUNICATION_TAB_CONTACT'), 'active' => true, 'items' => array_values($contactData))))); } return array('ERROR' => 'Invalid data'); }
public static function OnBeforeIntantMessangerChatAdd(\Bitrix\Main\Entity\Event $event) { $result = new \Bitrix\Main\Entity\EventResult(); $fields = $event->getParameter('fields'); $entityType = isset($fields['ENTITY_TYPE']) ? $fields['ENTITY_TYPE'] : ''; $m = null; if (preg_match('/^CRM_([A-Z]+)$/i', $entityType, $m) === 1) { $entityTypeName = isset($m[1]) ? $m[1] : ''; $ownerTypeID = CCrmOwnerType::ResolveID($entityTypeName); $ownerID = isset($fields['ENTITY_ID']) ? intval($fields['ENTITY_ID']) : 0; $ownerInfo = null; if (CCrmOwnerType::IsDefined($ownerTypeID) && $ownerID > 0 && CCrmOwnerType::TryGetInfo($ownerTypeID, $ownerID, $ownerInfo, false)) { $changedFields['TITLE'] = $ownerInfo['CAPTION']; $changedFields['AVATAR'] = $ownerInfo['IMAGE_ID']; $result->modifyFields($changedFields); } } return $result; }
public function Execute() { if (!CModule::IncludeModule("tasks")) { return CBPActivityExecutionStatus::Closed; } $rootActivity = $this->GetRootActivity(); $documentId = $rootActivity->GetDocumentId(); $arFields = $this->Fields; $arFields["CREATED_BY"] = CBPHelper::ExtractUsers($this->Fields["CREATED_BY"], $documentId, true); $arFields["RESPONSIBLE_ID"] = CBPHelper::ExtractUsers($this->Fields["RESPONSIBLE_ID"], $documentId, true); $arFields["ACCOMPLICES"] = CBPHelper::ExtractUsers($this->Fields["ACCOMPLICES"], $documentId); $arFields["AUDITORS"] = CBPHelper::ExtractUsers($this->Fields["AUDITORS"], $documentId); if (isset($this->Fields['DESCRIPTION'])) { $arFields['DESCRIPTION'] = preg_replace('/\\[url=(.*)\\](.*)\\[\\/url\\]/i' . BX_UTF_PCRE_MODIFIER, '<a href="${1}">${2}</a>', $this->Fields['DESCRIPTION']); } if (!$arFields["SITE_ID"]) { $arFields["SITE_ID"] = SITE_ID; } if ($this->AUTO_LINK_TO_CRM_ENTITY && CModule::IncludeModule('crm')) { $rootActivity = $this->GetRootActivity(); $documentId = $rootActivity->GetDocumentId(); $documentType = $rootActivity->GetDocumentType(); $letter = CCrmOwnerTypeAbbr::ResolveByTypeID(CCrmOwnerType::ResolveID($documentType[2])); $arFields['UF_CRM_TASK'] = array(str_replace($documentType[2], $letter, $documentId[2])); } $arUnsetFields = array(); foreach ($arFields as $fieldName => $fieldValue) { if (substr($fieldName, -5) === '_text') { $arFields[substr($fieldName, 0, -5)] = $fieldValue; $arUnsetFields[] = $fieldName; } } foreach ($arUnsetFields as $fieldName) { unset($arFields[$fieldName]); } // Check fields for "white" list $arFieldsChecked = array(); foreach (array_keys($arFields) as $fieldName) { if (in_array($fieldName, static::$arAllowedTasksFieldNames, true) || strlen($fieldName) > 3 && substr($fieldName, 0, 3) === 'UF_') { if ('UF_TASK_WEBDAV_FILES' == $fieldName && is_array($arFields[$fieldName])) { foreach ($arFields[$fieldName] as $key => $fileId) { if (!empty($fileId) && is_string($fileId) && substr($fileId, 0, 1) != 'n') { if (CModule::IncludeModule("disk") && \Bitrix\Disk\Configuration::isSuccessfullyConverted()) { $item = \Bitrix\Disk\Internals\FileTable::getList(array('select' => array('ID'), 'filter' => array('=XML_ID' => $fileId, 'TYPE' => \Bitrix\Disk\Internals\FileTable::TYPE_FILE)))->fetch(); if ($item) { $arFields[$fieldName][$key] = 'n' . $item['ID']; } } } } unset($fileId); } $arFieldsChecked[$fieldName] = $arFields[$fieldName]; } } $task = new CTasks(); $result = $task->Add($arFieldsChecked, array('USER_ID' => 1)); if (!$result) { $arErrors = $task->GetErrors(); if (count($arErrors) > 0) { $errorDesc = array(); if (is_array($arErrors) && !empty($arErrors)) { foreach ($arErrors as $error) { $errorDesc[] = $error['text'] . ' (' . $error['id'] . ')'; } } $this->WriteToTrackingService(GetMessage("BPSA_TRACK_ERROR") . (!empty($errorDesc) ? ' ' . implode(', ', $errorDesc) : '')); } return CBPActivityExecutionStatus::Closed; } $this->TaskId = $result; $this->WriteToTrackingService(str_replace("#VAL#", $result, GetMessage("BPSA_TRACK_OK"))); if ($this->isInEventActivityMode || !$this->HoldToClose) { return CBPActivityExecutionStatus::Closed; } $this->Subscribe($this); $this->isInEventActivityMode = false; $this->WriteToTrackingService(GetMessage("BPSA_TRACK_SUBSCR")); return CBPActivityExecutionStatus::Executing; }
if ($siteID !== '') { define('SITE_ID', $siteID); } require_once $_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/main/include/prolog_before.php'; if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED !== true) { die; } if (!CModule::IncludeModule('crm') || !CCrmSecurityHelper::IsAuthorized() || !check_bitrix_sessid()) { die; } $params = isset($_REQUEST['PARAMS']) ? $_REQUEST['PARAMS'] : array(); $entityTypeName = isset($params['ENTITY_TYPE_NAME']) ? strtoupper($params['ENTITY_TYPE_NAME']) : ''; if ($entityTypeName === '') { die; } $entityTypeID = CCrmOwnerType::ResolveID($entityTypeName); if ($entityTypeID === CCrmOwnerType::Undefined) { die; } $entityID = isset($params['ENTITY_ID']) ? $params['ENTITY_ID'] : 0; if ($entityID <= 0) { die; } $userPermissions = CCrmPerms::GetCurrentUserPermissions(); if (!CCrmAuthorizationHelper::CheckReadPermission($entityTypeName, $entityID, $userPermissions)) { die; } $formID = isset($params['FORM_ID']) ? $params['FORM_ID'] : ''; $pathToUserProfile = isset($params['PATH_TO_USER_PROFILE']) ? $params['PATH_TO_USER_PROFILE'] : ''; $postFormUri = isset($params['POST_FORM_URI']) ? $params['POST_FORM_URI'] : ''; if ($postFormUri !== '') {
unset($value); } } elseif ($arResult['CLEAR_FILTER']) { // Clear SHOW_MODE filter if grid filter is enabled $showMode = $arResult['SHOW_MODE'] = 'ALL'; if (isset($arFilter['__INNER_FILTER_SHOW_MODE'])) { unset($arFilter['__INNER_FILTER_SHOW_MODE']); } } $arDatetimeFields = array('CREATED', 'LAST_UPDATED', 'START_TIME', 'END_TIME', 'DEADLINE'); $arUserBindings = array(); foreach ($arFilter as $k => $v) { if ($k === 'REFERENCE' || $k === 'CLIENT') { $ownerData = explode('_', $v); if (count($ownerData) > 1) { $ownerTypeID = CCrmOwnerType::ResolveID($ownerData[0]); $ownerID = intval($ownerData[1]); if ($ownerTypeID > 0 && $ownerID > 0) { $arUserBindings[] = array('OWNER_TYPE_ID' => $ownerTypeID, 'OWNER_ID' => $ownerID); } } unset($arFilter[$k]); } elseif (preg_match('/(.*)_from$/i' . BX_UTF_PCRE_MODIFIER, $k, $arMatch)) { $fieldID = $arMatch[1]; if ($fieldID === 'END') { $fieldID = 'END_TIME'; } elseif ($fieldID === 'START') { $fieldID = 'START_TIME'; } if (strlen($v) > 0 && in_array($fieldID, $arDatetimeFields, true)) { $arFilter['>=' . $fieldID] = $v;