Esempio n. 1
0
 public static function AttachRecordToCall($params)
 {
     if (!CModule::IncludeModule('crm')) {
         return false;
     }
     CVoxImplantHistory::WriteToLog($params, 'CRM ATTACH RECORD TO CALL');
     if ($params['CALL_WEBDAV_ID'] > 0) {
         $activityId = CCrmActivity::GetIDByOrigin('VI_' . $params['CALL_ID']);
         if ($activityId) {
             $arFields['STORAGE_TYPE_ID'] = CCrmActivity::GetDefaultStorageTypeID();
             $arFields['STORAGE_ELEMENT_IDS'] = array($params['CALL_WEBDAV_ID']);
             CCrmActivity::Update($activityId, $arFields, false);
         }
     }
     return true;
 }
Esempio n. 2
0
<?php

if (!defined('B_PROLOG_INCLUDED') || B_PROLOG_INCLUDED !== true) {
    die;
}
use Bitrix\Crm\Integration\StorageType;
global $APPLICATION;
$APPLICATION->AddHeadScript('/bitrix/js/crm/instant_editor.js');
$APPLICATION->SetAdditionalCSS('/bitrix/js/crm/css/crm.css');
$APPLICATION->SetAdditionalCSS("/bitrix/themes/.default/crm-entity-show.css");
if (SITE_TEMPLATE_ID === 'bitrix24') {
    $APPLICATION->SetAdditionalCSS("/bitrix/themes/.default/bitrix24/crm-entity-show.css");
}
//Preliminary registration of disk api.
if (CCrmActivity::GetDefaultStorageTypeID() === StorageType::Disk) {
    CJSCore::Init(array('uploader', 'file_dialog'));
}
$arResult['CRM_CUSTOM_PAGE_TITLE'] = GetMessage('CRM_COMPANY_SHOW_TITLE', array('#ID#' => $arResult['ELEMENT']['ID'], '#TITLE#' => $arResult['ELEMENT']['TITLE']));
$enableInstantEdit = $arResult['ENABLE_INSTANT_EDIT'];
$instantEditorID = strtolower($arResult['FORM_ID']) . '_editor';
$bizprocDispatcherID = strtolower($arResult['FORM_ID']) . '_bp_disp';
$arTabs = array();
$arTabsExt = array();
$arTabs[] = array('id' => 'tab_1', 'name' => GetMessage('CRM_TAB_1'), 'title' => GetMessage('CRM_TAB_1_TITLE'), 'icon' => '', 'fields' => $arResult['FIELDS']['tab_1'], 'display' => false);
$arTabs[] = array('id' => 'tab_details', 'name' => GetMessage('CRM_TAB_DETAILS'), 'title' => GetMessage('CRM_TAB_DETAILS_TITLE'), 'icon' => '', 'fields' => $arResult['FIELDS']['tab_details'], 'display' => false);
$liveFeedTab = null;
if (!empty($arResult['FIELDS']['tab_live_feed'])) {
    $liveFeedTab = array('id' => 'tab_live_feed', 'name' => GetMessage('CRM_TAB_LIVE_FEED'), 'title' => GetMessage('CRM_TAB_LIVE_FEED_TITLE'), 'icon' => '', 'fields' => $arResult['FIELDS']['tab_live_feed']);
    $arTabs[] = $liveFeedTab;
}
if (!empty($arResult['FIELDS']['tab_activity'])) {
Esempio n. 3
0
 }
 // <-- 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));
 }
 $descr = isset($data['DESCRIPTION']) ? strval($data['DESCRIPTION']) : '';
 if ($descr === '') {
     $descr = $subject;
 }
 $fields = array('OWNER_ID' => $ownerID, 'OWNER_TYPE_ID' => $ownerTypeID, 'TYPE_ID' => CCrmActivityType::Email, 'SUBJECT' => $subject, 'START_TIME' => $nowStr, 'END_TIME' => $nowStr, 'COMPLETED' => 'Y', 'RESPONSIBLE_ID' => $curUser->GetID(), 'PRIORITY' => CCrmActivityPriority::Medium, 'DESCRIPTION' => $descr, 'DESCRIPTION_TYPE' => CCrmContentType::PlainText, 'DIRECTION' => CCrmActivityDirection::Outgoing, 'LOCATION' => '', 'NOTIFY_TYPE' => CCrmActivityNotifyType::None);
 $storageTypeID = $fields['STORAGE_TYPE_ID'] = isset($data['STORAGE_TYPE_ID']) ? (int) $data['STORAGE_TYPE_ID'] : CCrmActivity::GetDefaultStorageTypeID();
 $storageElements = isset($data['STORAGE_ELEMENT_IDS']) ? $data['STORAGE_ELEMENT_IDS'] : null;
 if (is_array($storageElements) && (!empty($storageElements) || !$isNew)) {
     $fields['STORAGE_ELEMENT_IDS'] = StorageManager::filterFiles($storageElements, $storageTypeID, $curUser->GetID());
 }
 $responsibleID = isset($data['RESPONSIBLE_ID']) ? intval($data['RESPONSIBLE_ID']) : 0;
 //$DB->StartTransaction();
 $successed = false;
 $errorMessage = "";
 if ($isNew) {
     $fields['BINDINGS'] = array_values($bindings);
     $fields['RESPONSIBLE_ID'] = $responsibleID > 0 ? $responsibleID : (int) $curUser->GetID();
     $ID = CCrmActivity::Add($fields, false, false, array('REGISTER_SONET_EVENT' => true));
     $successed = is_int($ID) && $ID > 0;
     if (!$successed) {
         $errorMessage = CCrmActivity::GetLastErrorMessage();
Esempio n. 4
0
 //$description = preg_replace('/<(?:\/)?[a-z0-9]+[^>]*>/i', '', $description);
 $arFields = array('OWNER_ID' => $ownerID, 'OWNER_TYPE_ID' => CCrmOwnerType::ResolveID($ownerTypeName), 'TYPE_ID' => CCrmActivityType::Email, 'SUBJECT' => $subject, 'START_TIME' => $now, 'END_TIME' => $now, 'COMPLETED' => 'Y', 'RESPONSIBLE_ID' => $userID, 'PRIORITY' => CCrmActivityPriority::Medium, 'DESCRIPTION' => $description, 'DESCRIPTION_TYPE' => CCrmContentType::BBCode, 'DIRECTION' => CCrmActivityDirection::Outgoing, 'LOCATION' => '', 'NOTIFY_TYPE' => CCrmActivityNotifyType::None, 'BINDINGS' => array_values($arBindings));
 if (count($arFields['BINDINGS']) === 1) {
     // In single bindind mode override owner data
     $arBinding = $arFields['BINDINGS'][0];
     $arFields['OWNER_TYPE_ID'] = $arBinding['OWNER_TYPE_ID'];
     $arFields['OWNER_ID'] = $arBinding['OWNER_ID'];
 }
 $storageTypeID = isset($data['storageTypeID']) ? intval($data['storageTypeID']) : CCrmActivityStorageType::Undefined;
 if ($storageTypeID === CCrmActivityStorageType::Undefined || !CCrmActivityStorageType::IsDefined($storageTypeID)) {
     if ($isNew) {
         $storageTypeID = CCrmActivity::GetDefaultStorageTypeID();
     } else {
         $storageTypeID = CCrmActivity::GetStorageTypeID($ID);
         if ($storageTypeID === CCrmActivityStorageType::Undefined) {
             $storageTypeID = CCrmActivity::GetDefaultStorageTypeID();
         }
     }
 }
 $arFields['STORAGE_TYPE_ID'] = $storageTypeID;
 if ($storageTypeID === CCrmActivityStorageType::File) {
     $arUserFiles = isset($data['files']) && is_array($data['files']) ? $data['files'] : array();
     if (!empty($arUserFiles) || !$isNew) {
         $arPermittedFiles = array();
         $arPreviousFiles = array();
         if (!$isNew) {
             $arPreviousFields = $ID > 0 ? CCrmActivity::GetByID($ID) : array();
             CCrmActivity::PrepareStorageElementIDs($arPreviousFields);
             $arPreviousFiles = $arPreviousFiles['STORAGE_ELEMENT_IDS'];
             if (is_array($arPreviousFiles) && !empty($arPreviousFiles)) {
                 $arPermittedFiles = array_intersect($arUserFiles, $arPreviousFiles);
Esempio n. 5
0
 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;
 }
Esempio n. 6
0
$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['ENABLE_WEBDAV'] = $storageTypeID === StorageType::WebDav;
if (!$arResult['ENABLE_WEBDAV']) {
    $arResult['WEBDAV_SELECT_URL'] = $arResult['WEBDAV_UPLOAD_URL'] = $arResult['WEBDAV_SHOW_URL'] = '';
} else {
    $webDavPaths = CCrmWebDavHelper::GetPaths();
    $arResult['WEBDAV_SELECT_URL'] = isset($webDavPaths['PATH_TO_FILES']) ? $webDavPaths['PATH_TO_FILES'] : '';
    $arResult['WEBDAV_UPLOAD_URL'] = isset($webDavPaths['ELEMENT_UPLOAD_URL']) ? $webDavPaths['ELEMENT_UPLOAD_URL'] : '';
    $arResult['WEBDAV_SHOW_URL'] = isset($webDavPaths['ELEMENT_SHOW_INLINE_URL']) ? $webDavPaths['ELEMENT_SHOW_INLINE_URL'] : '';
}
$flashPlayerUrl = isset($arParams['~FLASH_PLAYER_URL']) ? $arParams['~FLASH_PLAYER_URL'] : '';
if ($flashPlayerUrl === '') {
    $flashPlayerUrl = CComponentEngine::makePathFromTemplate('#SITE_DIR#bitrix/components/bitrix/player/mediaplayer/player');
}
$arResult['FLASH_PLAYER_URL'] = $flashPlayerUrl;
Esempio n. 7
0
 public static function PrepareActivityItem(&$item, &$params, $options = null)
 {
     if (!is_array($options)) {
         $options = array();
     }
     $itemID = intval($item['ID']);
     if (!isset($item['SUBJECT'])) {
         $item['SUBJECT'] = '';
     }
     if (!isset($item['DESCRIPTION'])) {
         $item['DESCRIPTION'] = '';
     }
     if (!isset($item['LOCATION'])) {
         $item['LOCATION'] = '';
     }
     $typeID = isset($item['TYPE_ID']) ? intval($item['TYPE_ID']) : CCrmActivityType::Undefined;
     $item['TYPE_ID'] = $typeID;
     $direction = isset($item['DIRECTION']) ? intval($item['DIRECTION']) : CCrmActivityDirection::Undefined;
     $item['DIRECTION'] = $direction;
     $priority = isset($item['PRIORITY']) ? intval($item['PRIORITY']) : CCrmActivityPriority::None;
     $item['PRIORITY'] = $priority;
     $item['IS_IMPORTANT'] = $priority === CCrmActivityPriority::High;
     $completed = isset($item['COMPLETED']) ? $item['COMPLETED'] === 'Y' : false;
     $item['COMPLETED'] = $completed ? 'Y' : 'N';
     if ($typeID === CCrmActivityType::Task) {
         $taskID = isset($item['ASSOCIATED_ENTITY_ID']) ? intval($item['ASSOCIATED_ENTITY_ID']) : 0;
         $item['SHOW_URL'] = $taskID > 0 && isset($params['TASK_SHOW_URL_TEMPLATE']) ? CComponentEngine::MakePathFromTemplate($params['TASK_SHOW_URL_TEMPLATE'], array('user_id' => isset($params['USER_ID']) ? $params['USER_ID'] : CCrmSecurityHelper::GetCurrentUserID(), 'task_id' => $taskID)) : '';
         $item['DEAD_LINE'] = isset($item['DEADLINE']) ? $item['DEADLINE'] : (isset($item['END_TIME']) ? $item['END_TIME'] : '');
     } else {
         if (isset($params['ACTIVITY_SHOW_URL_TEMPLATE'])) {
             $item['SHOW_URL'] = CComponentEngine::makePathFromTemplate($params['ACTIVITY_SHOW_URL_TEMPLATE'], array('activity_id' => $itemID));
         }
         $item['DEAD_LINE'] = isset($item['DEADLINE']) ? $item['DEADLINE'] : (isset($item['START_TIME']) ? $item['START_TIME'] : '');
     }
     //OWNER_TITLE
     $ownerTitle = '';
     $ownerID = isset($item['OWNER_ID']) ? intval($item['OWNER_ID']) : 0;
     $item['OWNER_ID'] = $ownerID;
     $ownerTypeID = isset($item['OWNER_TYPE_ID']) ? intval($item['OWNER_TYPE_ID']) : 0;
     $item['OWNER_TYPE_ID'] = $ownerTypeID;
     if ($ownerID > 0 && $ownerTypeID > 0) {
         $ownerTitle = CCrmOwnerType::GetCaption($ownerTypeID, $ownerID);
     }
     $item['OWNER_TITLE'] = $ownerTitle;
     //OWNER_SHOW_URL
     $ownerShowUrl = '';
     if ($ownerID > 0) {
         if ($ownerTypeID === CCrmOwnerType::Lead) {
             $ownerShowUrl = isset($params['LEAD_SHOW_URL_TEMPLATE']) ? CComponentEngine::makePathFromTemplate($params['LEAD_SHOW_URL_TEMPLATE'], array('lead_id' => $ownerID)) : '';
         } elseif ($ownerTypeID === CCrmOwnerType::Contact) {
             $ownerShowUrl = isset($params['CONTACT_SHOW_URL_TEMPLATE']) ? CComponentEngine::makePathFromTemplate($params['CONTACT_SHOW_URL_TEMPLATE'], array('contact_id' => $ownerID)) : '';
         } elseif ($ownerTypeID === CCrmOwnerType::Company) {
             $ownerShowUrl = isset($params['COMPANY_SHOW_URL_TEMPLATE']) ? CComponentEngine::makePathFromTemplate($params['COMPANY_SHOW_URL_TEMPLATE'], array('company_id' => $ownerID)) : '';
         } elseif ($ownerTypeID === CCrmOwnerType::Deal) {
             $ownerShowUrl = isset($params['DEAL_SHOW_URL_TEMPLATE']) ? CComponentEngine::makePathFromTemplate($params['DEAL_SHOW_URL_TEMPLATE'], array('deal_id' => $ownerID)) : '';
         }
     }
     $item['OWNER_SHOW_URL'] = $ownerShowUrl;
     //IS_EXPIRED
     if ($item['COMPLETED'] === 'Y') {
         $item['IS_EXPIRED'] = false;
     } else {
         $time = isset($item['DEAD_LINE']) ? MakeTimeStamp($item['DEAD_LINE']) : 0;
         $item['IS_EXPIRED'] = $time !== 0 && $time <= time() + CTimeZone::GetOffset();
     }
     $responsibleID = isset($item['RESPONSIBLE_ID']) ? intval($item['RESPONSIBLE_ID']) : 0;
     $item['RESPONSIBLE_ID'] = $responsibleID;
     $item['RESPONSIBLE_SHOW_URL'] = $responsibleID > 0 ? CComponentEngine::MakePathFromTemplate($params['USER_PROFILE_URL_TEMPLATE'], array('user_id' => $responsibleID)) : '';
     $item['RESPONSIBLE_FORMATTED_NAME'] = $responsibleID > 0 && isset($params['NAME_TEMPLATE']) ? CUser::FormatName($params['NAME_TEMPLATE'], array('LOGIN' => isset($item['RESPONSIBLE_LOGIN']) ? $item['RESPONSIBLE_LOGIN'] : '', 'NAME' => isset($item['RESPONSIBLE_NAME']) ? $item['RESPONSIBLE_NAME'] : '', 'LAST_NAME' => isset($item['RESPONSIBLE_LAST_NAME']) ? $item['RESPONSIBLE_LAST_NAME'] : '', 'SECOND_NAME' => isset($item['RESPONSIBLE_SECOND_NAME']) ? $item['RESPONSIBLE_SECOND_NAME'] : ''), true, false) : '';
     //COMMUNICATIONS
     if ($itemID > 0 && isset($options['ENABLE_COMMUNICATIONS']) && $options['ENABLE_COMMUNICATIONS'] && !isset($item['COMMUNICATIONS'])) {
         $item['COMMUNICATIONS'] = CCrmActivity::GetCommunications($itemID);
     }
     $storageTypeID = isset($item['STORAGE_TYPE_ID']) ? intval($item['STORAGE_TYPE_ID']) : CCrmActivityStorageType::Undefined;
     if ($storageTypeID === CCrmActivityStorageType::Undefined || !CCrmActivityStorageType::IsDefined($storageTypeID)) {
         $storageTypeID = CCrmActivity::GetDefaultStorageTypeID();
     }
     $item['STORAGE_TYPE_ID'] = $storageTypeID;
     $item['FILES'] = array();
     $item['DISK_FILES'] = array();
     $item['WEBDAV_ELEMENTS'] = array();
     if (isset($options['ENABLE_FILES']) && $options['ENABLE_FILES']) {
         CCrmActivity::PrepareStorageElementIDs($item);
         CCrmActivity::PrepareStorageElementInfo($item);
     }
 }
Esempio n. 8
0
 protected function innerUpdate($ID, &$fields, &$errors, array $params = null)
 {
     $currentFields = CCrmActivity::GetByID($ID);
     CCrmActivity::PrepareStorageElementIDs($currentFields);
     if (!is_array($currentFields)) {
         $errors[] = 'Activity is not found.';
         return false;
     }
     $typeID = intval($currentFields['TYPE_ID']);
     $currentOwnerID = intval($currentFields['OWNER_ID']);
     $currentOwnerTypeID = intval($currentFields['OWNER_TYPE_ID']);
     if (!CCrmActivity::CheckUpdatePermission($currentOwnerTypeID, $currentOwnerID)) {
         $errors[] = 'Access denied.';
         return false;
     }
     $ownerID = isset($fields['OWNER_ID']) ? intval($fields['OWNER_ID']) : 0;
     if ($ownerID <= 0) {
         $ownerID = $currentOwnerID;
     }
     $ownerTypeID = isset($fields['OWNER_TYPE_ID']) ? intval($fields['OWNER_TYPE_ID']) : 0;
     if ($ownerTypeID <= 0) {
         $ownerTypeID = $currentOwnerTypeID;
     }
     if (($ownerTypeID !== $currentOwnerTypeID || $ownerID !== $currentOwnerID) && !CCrmActivity::CheckUpdatePermission($ownerTypeID, $ownerID)) {
         $errors[] = 'Access denied.';
         return false;
     }
     $communications = isset($fields['COMMUNICATIONS']) && is_array($fields['COMMUNICATIONS']) ? $fields['COMMUNICATIONS'] : null;
     if (is_array($communications)) {
         $bindings = array();
         if ($ownerTypeID > 0 && $ownerID > 0) {
             $bindings["{$ownerTypeID}_{$ownerID}"] = array('OWNER_TYPE_ID' => $ownerTypeID, 'OWNER_ID' => $ownerID);
         }
         $this->prepareCommunications($ownerTypeID, $ownerID, $typeID, $communications, $bindings);
         if (empty($communications)) {
             $errors[] = 'The field COMMUNICATIONS is not defined or invalid.';
             return false;
         }
         $fields['BINDINGS'] = array_values($bindings);
         $fields['COMMUNICATIONS'] = $communications;
     }
     $storageTypeID = $fields['STORAGE_TYPE_ID'] = CCrmActivity::GetDefaultStorageTypeID();
     $fields['STORAGE_ELEMENT_IDS'] = array();
     if ($storageTypeID === StorageType::WebDav) {
         $webdavElements = isset($fields['WEBDAV_ELEMENTS']) && is_array($fields['WEBDAV_ELEMENTS']) ? $fields['WEBDAV_ELEMENTS'] : array();
         $prevStorageElementIDs = isset($currentFields['STORAGE_ELEMENT_IDS']) ? $currentFields['STORAGE_ELEMENT_IDS'] : array();
         $oldStorageElementIDs = array();
         foreach ($webdavElements as &$element) {
             $elementID = isset($element['ELEMENT_ID']) ? intval($element['ELEMENT_ID']) : 0;
             if ($elementID > 0) {
                 $fields['STORAGE_ELEMENT_IDS'][] = $elementID;
             }
             $oldElementID = isset($element['OLD_ELEMENT_ID']) ? intval($element['OLD_ELEMENT_ID']) : 0;
             if ($oldElementID > 0 && ($elementID > 0 || isset($element['DELETE']) && $element['DELETE'] === true)) {
                 if (in_array($oldElementID, $prevStorageElementIDs)) {
                     $oldStorageElementIDs[] = $oldElementID;
                 }
             }
         }
         unset($element);
     } else {
         if ($storageTypeID === StorageType::Disk) {
             $diskFiles = isset($fields['FILES']) && is_array($fields['FILES']) ? $fields['FILES'] : array();
             if (empty($diskFiles)) {
                 //For backward compatibility only
                 $diskFiles = isset($fields['WEBDAV_ELEMENTS']) && is_array($fields['WEBDAV_ELEMENTS']) ? $fields['WEBDAV_ELEMENTS'] : array();
             }
             foreach ($diskFiles as &$fileInfo) {
                 $fileID = isset($fileInfo['FILE_ID']) ? (int) $fileInfo['FILE_ID'] : 0;
                 if ($fileID > 0) {
                     $fields['STORAGE_ELEMENT_IDS'][] = $fileID;
                 }
             }
             unset($fileInfo);
         }
     }
     $result = CCrmActivity::Update($ID, $fields, false, true, array());
     if ($result === false) {
         $errors[] = CCrmActivity::GetLastErrorMessage();
     } else {
         if (is_array($communications)) {
             CCrmActivity::SaveCommunications($ID, $communications, $fields, false, false);
         }
         if (!empty($oldStorageElementIDs)) {
             $webdavIBlock = $this->prepareWebDavIBlock();
             foreach ($oldStorageElementIDs as $elementID) {
                 $webdavIBlock->Delete(array('element_id' => $elementID));
             }
         }
     }
     return $result;
 }
Esempio n. 9
0
 protected function externalizeFields(&$fields, &$fieldsInfo)
 {
     $storageTypeID = isset($fields['STORAGE_TYPE_ID']) ? $fields['STORAGE_TYPE_ID'] : CCrmActivity::GetDefaultStorageTypeID();
     if (isset($fields['STORAGE_ELEMENT_IDS'])) {
         CCrmActivity::PrepareStorageElementIDs($fields);
         if ($storageTypeID === Bitrix\Crm\Integration\StorageType::Disk) {
             $fields['FILES'] = $fields['STORAGE_ELEMENT_IDS'];
         } elseif ($storageTypeID === Bitrix\Crm\Integration\StorageType::WebDav) {
             $fields['WEBDAV_ELEMENTS'] = $fields['STORAGE_ELEMENT_IDS'];
         }
         unset($fields['STORAGE_ELEMENT_IDS']);
     }
     parent::externalizeFields($fields, $fieldsInfo);
 }