Esempio n. 1
0
            $dupControl->enabledFor(CCrmOwnerType::Company, isset($_POST['ENABLE_COMPANY_DUP_CONTROL']) && strtoupper($_POST['ENABLE_COMPANY_DUP_CONTROL']) === 'Y');
            $dupControl->save();
            CCrmStatus::EnableDepricatedTypes(isset($_POST['ENABLE_DEPRECATED_STATUSES']) && strtoupper($_POST['ENABLE_DEPRECATED_STATUSES']) === 'Y');
            \Bitrix\Crm\Settings\DealSettings::enableCloseDateSync(isset($_POST['REFRESH_DEAL_CLOSEDATE']) && strtoupper($_POST['REFRESH_DEAL_CLOSEDATE']) === 'Y');
            if ($_POST['DEAL_DEFAULT_LIST_VIEW']) {
                \Bitrix\Crm\Settings\DealSettings::setDefaultListViewID($_POST['DEAL_DEFAULT_LIST_VIEW']);
            }
            LocalRedirect(CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_SM_CONFIG'], array()));
        }
    }
}
$arResult['FORM_ID'] = 'CRM_SM_CONFIG';
$arResult['BACK_URL'] = $arParams['PATH_TO_SM_CONFIG'];
$arResult['FIELDS'] = array();
$arResult['FIELDS']['tab_deal_config'][] = array('id' => 'DEAL_DEFAULT_LIST_VIEW', 'name' => GetMessage('CRM_FIELD_DEAL_DEFAULT_LIST_VIEW'), 'items' => \Bitrix\Crm\Settings\DealSettings::getViewDescriptions(), 'type' => 'list', 'value' => \Bitrix\Crm\Settings\DealSettings::getDefaultListViewID(), 'required' => false);
$arResult['FIELDS']['tab_deal_config'][] = array('id' => 'REFRESH_DEAL_CLOSEDATE', 'name' => GetMessage('CRM_FIELD_REFRESH_DEAL_CLOSEDATE'), 'type' => 'checkbox', 'value' => \Bitrix\Crm\Settings\DealSettings::isCloseDateSyncEnabled(), 'required' => false);
$arResult['FIELDS']['tab_activity_config'][] = array('id' => 'CALENDAR_DISPLAY_COMPLETED_CALLS', 'name' => GetMessage('CRM_FIELD_DISPLAY_COMPLETED_CALLS_IN_CALENDAR'), 'type' => 'checkbox', 'value' => CCrmActivityCalendarSettings::GetValue(CCrmActivityCalendarSettings::DisplayCompletedCalls, true), 'required' => false);
$arResult['FIELDS']['tab_activity_config'][] = array('id' => 'CALENDAR_DISPLAY_COMPLETED_MEETINGS', 'name' => GetMessage('CRM_FIELD_DISPLAY_COMPLETED_MEETINGS_IN_CALENDAR'), 'type' => 'checkbox', 'value' => CCrmActivityCalendarSettings::GetValue(CCrmActivityCalendarSettings::DisplayCompletedMeetings, true), 'required' => false);
$arResult['FIELDS']['tab_activity_config'][] = array('id' => 'RECKON_ACTIVITYLESS_ITEMS_IN_COUNTERS', 'name' => GetMessage('CRM_FIELD_RECKON_ACTIVITYLESS_ITEMS_IN_COUNTERS'), 'type' => 'checkbox', 'value' => CCrmUserCounterSettings::GetValue(CCrmUserCounterSettings::ReckonActivitylessItems, true), 'required' => false);
$arResult['FIELDS']['tab_outgoing_email'][] = array('id' => 'SERVICE_CODE_ALLOCATION', 'name' => GetMessage('CRM_FIELD_SERVICE_CODE_ALLOCATION'), 'items' => CCrmEMailCodeAllocation::GetAllDescriptions(), 'type' => 'list', 'value' => CCrmEMailCodeAllocation::GetCurrent(), 'required' => false);
if (Bitrix\Crm\Integration\Bitrix24Email::isEnabled()) {
    if (Bitrix\Crm\Integration\Bitrix24Email::allowDisableSignature()) {
        $arResult['FIELDS']['tab_outgoing_email'][] = array('id' => 'ENABLE_B24_EMAIL_SIGNATURE', 'name' => GetMessage('CRM_FIELD_ENABLE_B24_EMAIL_SIGNATURE'), 'type' => 'checkbox', 'value' => Bitrix\Crm\Integration\Bitrix24Email::isSignatureEnabled(), 'required' => false);
    } else {
        $arResult['FIELDS']['tab_outgoing_email'][] = array('id' => 'ENABLE_B24_EMAIL_SIGNATURE', 'name' => GetMessage('CRM_FIELD_ENABLE_B24_EMAIL_SIGNATURE'), 'type' => 'label', 'value' => Bitrix\Crm\Integration\Bitrix24Email::getSignatureExplanation(), 'required' => false);
    }
}
$arResult['FIELDS']['tab_format'][] = array('id' => 'PERSON_NAME_FORMAT_ID', 'name' => GetMessage('CRM_FIELD_PERSON_NAME_FORMAT'), 'type' => 'list', 'items' => \Bitrix\Crm\Format\PersonNameFormatter::getAllDescriptions(), 'value' => \Bitrix\Crm\Format\PersonNameFormatter::getFormatID(), 'required' => false);
$arResult['FIELDS']['tab_format'][] = array('id' => 'CALLTO_FORMAT', 'name' => GetMessage('CRM_FIELD_CALLTO_FORMAT'), 'type' => 'list', 'items' => CCrmCallToUrl::GetAllDescriptions(), 'value' => CCrmCallToUrl::GetFormat(CCrmCallToUrl::Bitrix), 'required' => false);
$calltoSettings = CCrmCallToUrl::GetCustomSettings();
$arResult['FIELDS']['tab_format'][] = array('id' => 'CALLTO_URL_TEMPLATE', 'name' => GetMessage('CRM_FIELD_CALLTO_URL_TEMPLATE'), 'type' => 'text', 'value' => isset($calltoSettings['URL_TEMPLATE']) ? $calltoSettings['URL_TEMPLATE'] : 'callto:[phone]', 'required' => false);
Esempio n. 2
0
 public function Update($ID, array &$arFields, $bCompare = true, $bUpdateSearch = true, $options = array())
 {
     global $DB;
     $this->LAST_ERROR = '';
     $ID = (int) $ID;
     if (!is_array($options)) {
         $options = array();
     }
     $arFilterTmp = array('ID' => $ID);
     if (!$this->bCheckPermission) {
         $arFilterTmp['CHECK_PERMISSIONS'] = 'N';
     }
     $obRes = self::GetListEx(array(), $arFilterTmp);
     if (!($arRow = $obRes->Fetch())) {
         return false;
     }
     $iUserId = CCrmSecurityHelper::GetCurrentUserID();
     if (isset($arFields['DATE_CREATE'])) {
         unset($arFields['DATE_CREATE']);
     }
     if (isset($arFields['DATE_MODIFY'])) {
         unset($arFields['DATE_MODIFY']);
     }
     $arFields['~DATE_MODIFY'] = $DB->CurrentTimeFunction();
     if (!isset($arFields['MODIFY_BY_ID']) || $arFields['MODIFY_BY_ID'] <= 0) {
         $arFields['MODIFY_BY_ID'] = $iUserId;
     }
     if (isset($arFields['ASSIGNED_BY_ID']) && $arFields['ASSIGNED_BY_ID'] <= 0) {
         unset($arFields['ASSIGNED_BY_ID']);
     }
     $assignedByID = (int) (isset($arFields['ASSIGNED_BY_ID']) ? $arFields['ASSIGNED_BY_ID'] : $arRow['ASSIGNED_BY_ID']);
     $bResult = false;
     if (!$this->CheckFields($arFields, $ID, $options)) {
         $arFields['RESULT_MESSAGE'] =& $this->LAST_ERROR;
     } else {
         if ($this->bCheckPermission && !CCrmAuthorizationHelper::CheckUpdatePermission(self::$TYPE_NAME, $ID, $this->cPerms)) {
             $this->LAST_ERROR = GetMessage('CRM_PERMISSION_DENIED');
             $arFields['RESULT_MESSAGE'] =& $this->LAST_ERROR;
             return false;
         }
         $beforeEvents = GetModuleEvents('crm', 'OnBeforeCrmDealUpdate');
         while ($arEvent = $beforeEvents->Fetch()) {
             if (ExecuteModuleEventEx($arEvent, array(&$arFields)) === false) {
                 if (isset($arFields['RESULT_MESSAGE'])) {
                     $this->LAST_ERROR = $arFields['RESULT_MESSAGE'];
                 } else {
                     $this->LAST_ERROR = GetMessage('CRM_DEAL_UPDATE_CANCELED', array('#NAME#' => $arEvent['TO_NAME']));
                     $arFields['RESULT_MESSAGE'] =& $this->LAST_ERROR;
                 }
                 return false;
             }
         }
         $arAttr = array();
         $arAttr['STAGE_ID'] = !empty($arFields['STAGE_ID']) ? $arFields['STAGE_ID'] : $arRow['STAGE_ID'];
         $arAttr['OPENED'] = !empty($arFields['OPENED']) ? $arFields['OPENED'] : $arRow['OPENED'];
         $arEntityAttr = self::BuildEntityAttr($assignedByID, $arAttr);
         $sEntityPerm = $this->cPerms->GetPermType('DEAL', 'WRITE', $arEntityAttr);
         $this->PrepareEntityAttrs($arEntityAttr, $sEntityPerm);
         //Prevent 'OPENED' field change by user restricted by BX_CRM_PERM_OPEN permission
         if ($sEntityPerm === BX_CRM_PERM_OPEN && isset($arFields['OPENED']) && $arFields['OPENED'] !== 'Y' && $assignedByID !== $iUserId) {
             $arFields['OPENED'] = 'Y';
         }
         if (isset($arFields['ASSIGNED_BY_ID']) && $arRow['ASSIGNED_BY_ID'] != $arFields['ASSIGNED_BY_ID']) {
             CCrmEvent::SetAssignedByElement($arFields['ASSIGNED_BY_ID'], 'DEAL', $ID);
         }
         $sonetEventData = array();
         if ($bCompare) {
             $arEvents = self::CompareFields($arRow, $arFields, $this->bCheckPermission);
             foreach ($arEvents as $arEvent) {
                 $arEvent['ENTITY_TYPE'] = 'DEAL';
                 $arEvent['ENTITY_ID'] = $ID;
                 $arEvent['EVENT_TYPE'] = 1;
                 if (!isset($arEvent['USER_ID'])) {
                     $arEvent['USER_ID'] = $iUserId;
                 }
                 $CCrmEvent = new CCrmEvent();
                 $eventID = $CCrmEvent->Add($arEvent, $this->bCheckPermission);
                 if (is_int($eventID) && $eventID > 0) {
                     $fieldID = isset($arEvent['ENTITY_FIELD']) ? $arEvent['ENTITY_FIELD'] : '';
                     if ($fieldID === '') {
                         continue;
                     }
                     switch ($fieldID) {
                         case 'STAGE_ID':
                             $sonetEventData[CCrmLiveFeedEvent::Progress] = array('TYPE' => CCrmLiveFeedEvent::Progress, 'FIELDS' => array('TITLE' => GetMessage('CRM_DEAL_EVENT_UPDATE_STAGE'), 'MESSAGE' => '', 'PARAMS' => array('START_STATUS_ID' => $arRow['STAGE_ID'], 'FINAL_STATUS_ID' => $arFields['STAGE_ID'])));
                             break;
                         case 'ASSIGNED_BY_ID':
                             $sonetEventData[CCrmLiveFeedEvent::Responsible] = array('TYPE' => CCrmLiveFeedEvent::Responsible, 'FIELDS' => array('TITLE' => GetMessage('CRM_DEAL_EVENT_UPDATE_ASSIGNED_BY'), 'MESSAGE' => '', 'PARAMS' => array('START_RESPONSIBLE_ID' => $arRow['ASSIGNED_BY_ID'], 'FINAL_RESPONSIBLE_ID' => $arFields['ASSIGNED_BY_ID'])));
                             break;
                         case 'CONTACT_ID':
                         case 'COMPANY_ID':
                             if (!isset($sonetEventData[CCrmLiveFeedEvent::Client])) {
                                 $oldContactID = isset($arRow['CONTACT_ID']) ? intval($arRow['CONTACT_ID']) : 0;
                                 $oldCompanyID = isset($arRow['COMPANY_ID']) ? intval($arRow['COMPANY_ID']) : 0;
                                 $sonetEventData[CCrmLiveFeedEvent::Client] = array('CODE' => 'CLIENT', 'TYPE' => CCrmLiveFeedEvent::Client, 'FIELDS' => array('TITLE' => GetMessage('CRM_DEAL_EVENT_UPDATE_CLIENT'), 'MESSAGE' => '', 'PARAMS' => array('START_CLIENT_CONTACT_ID' => $oldContactID, 'FINAL_CLIENT_CONTACT_ID' => isset($arFields['CONTACT_ID']) ? intval($arFields['CONTACT_ID']) : $oldContactID, 'START_CLIENT_COMPANY_ID' => $oldCompanyID, 'FINAL_CLIENT_COMPANY_ID' => isset($arFields['COMPANY_ID']) ? intval($arFields['COMPANY_ID']) : $oldCompanyID)));
                             }
                             break;
                         case 'TITLE':
                             $sonetEventData[CCrmLiveFeedEvent::Denomination] = array('TYPE' => CCrmLiveFeedEvent::Denomination, 'FIELDS' => array('TITLE' => GetMessage('CRM_DEAL_EVENT_UPDATE_TITLE'), 'MESSAGE' => '', 'PARAMS' => array('START_TITLE' => $arRow['TITLE'], 'FINAL_TITLE' => $arFields['TITLE'])));
                             break;
                     }
                 }
             }
             // CHECK IF COMPANY/CONTACT WAS ADDED/REMOVED
             if (!isset($sonetEventData[CCrmLiveFeedEvent::Client]) && (!isset($arRow['COMPANY_ID']) && isset($arFields['COMPANY_ID']) || isset($arRow['COMPANY_ID']) && !isset($arFields['COMPANY_ID']) || !isset($arRow['CONTACT_ID']) && isset($arFields['CONTACT_ID']) || isset($arRow['CONTACT_ID']) && !isset($arFields['CONTACT_ID']))) {
                 $sonetEventData[CCrmLiveFeedEvent::Client] = array('CODE' => 'CLIENT', 'TYPE' => CCrmLiveFeedEvent::Client, 'FIELDS' => array('TITLE' => GetMessage('CRM_DEAL_EVENT_UPDATE_CLIENT'), 'MESSAGE' => '', 'PARAMS' => array('START_CLIENT_CONTACT_ID' => isset($arRow['CONTACT_ID']) ? intval($arRow['CONTACT_ID']) : 0, 'FINAL_CLIENT_CONTACT_ID' => isset($arFields['CONTACT_ID']) ? intval($arFields['CONTACT_ID']) : 0, 'START_CLIENT_COMPANY_ID' => isset($arRow['COMPANY_ID']) ? intval($arRow['COMPANY_ID']) : 0, 'FINAL_CLIENT_COMPANY_ID' => isset($arFields['COMPANY_ID']) ? intval($arFields['COMPANY_ID']) : 0)));
             }
         }
         // Calculation of Account Data
         $accData = CCrmAccountingHelper::PrepareAccountingData(array('CURRENCY_ID' => isset($arFields['CURRENCY_ID']) ? $arFields['CURRENCY_ID'] : (isset($arRow['CURRENCY_ID']) ? $arRow['CURRENCY_ID'] : null), 'SUM' => isset($arFields['OPPORTUNITY']) ? $arFields['OPPORTUNITY'] : (isset($arRow['OPPORTUNITY']) ? $arRow['OPPORTUNITY'] : null), 'EXCH_RATE' => isset($arFields['EXCH_RATE']) ? $arFields['EXCH_RATE'] : (isset($arRow['EXCH_RATE']) ? $arRow['EXCH_RATE'] : null)));
         if (is_array($accData)) {
             $arFields['ACCOUNT_CURRENCY_ID'] = $accData['ACCOUNT_CURRENCY_ID'];
             $arFields['OPPORTUNITY_ACCOUNT'] = $accData['ACCOUNT_SUM'];
         }
         $accData = CCrmAccountingHelper::PrepareAccountingData(array('CURRENCY_ID' => isset($arFields['CURRENCY_ID']) ? $arFields['CURRENCY_ID'] : (isset($arRow['CURRENCY_ID']) ? $arRow['CURRENCY_ID'] : null), 'SUM' => isset($arFields['TAX_VALUE']) ? $arFields['TAX_VALUE'] : (isset($arRow['TAX_VALUE']) ? $arRow['TAX_VALUE'] : null), 'EXCH_RATE' => isset($arFields['EXCH_RATE']) ? $arFields['EXCH_RATE'] : (isset($arRow['EXCH_RATE']) ? $arRow['EXCH_RATE'] : null)));
         if (is_array($accData)) {
             $arFields['TAX_VALUE_ACCOUNT'] = $accData['ACCOUNT_SUM'];
         }
         $enableCloseDateSync = \Bitrix\Crm\Settings\DealSettings::isCloseDateSyncEnabled();
         if (isset($arFields['STAGE_ID'])) {
             $now = ConvertTimeStamp(time(), 'SHORT', SITE_ID);
             $isFinalStage = self::GetStageSemantics($arFields['STAGE_ID']) !== 'process';
             $isStageChanged = !isset($arRow['STAGE_ID']) || $arRow['STAGE_ID'] !== $arFields['STAGE_ID'];
             $arFields['CLOSED'] = $isFinalStage ? 'Y' : 'N';
             if ($enableCloseDateSync && $isFinalStage && $isStageChanged) {
                 $arFields['CLOSEDATE'] = $now;
                 $arFields['~CLOSEDATE'] = $DB->CharToDateFunction($now, 'SHORT', false);
             } elseif (isset($arFields['CLOSEDATE']) && $arFields['CLOSEDATE'] !== '') {
                 $arFields['~CLOSEDATE'] = $DB->CharToDateFunction($arFields['CLOSEDATE'], 'SHORT', false);
             }
         } elseif ($enableCloseDateSync && self::GetStageSemantics($arRow['STAGE_ID']) !== 'process' && isset($arFields['CLOSEDATE'])) {
             unset($arFields['CLOSEDATE']);
         }
         if (isset($arFields['BEGINDATE']) && $arFields['BEGINDATE'] !== '') {
             $arFields['~BEGINDATE'] = $DB->CharToDateFunction($arFields['BEGINDATE'], 'SHORT', false);
         }
         if (isset($arFields['BEGINDATE'])) {
             $arFields['__BEGINDATE'] = $arFields['BEGINDATE'];
             unset($arFields['BEGINDATE']);
         }
         if (isset($arFields['CLOSEDATE'])) {
             $arFields['__CLOSEDATE'] = $arFields['CLOSEDATE'];
             unset($arFields['CLOSEDATE']);
         }
         unset($arFields['ID']);
         $sUpdate = $DB->PrepareUpdate('b_crm_deal', $arFields);
         if (strlen($sUpdate) > 0) {
             $DB->Query("UPDATE b_crm_deal SET {$sUpdate} WHERE ID = {$ID}", false, 'FILE: ' . __FILE__ . '<br /> LINE: ' . __LINE__);
             $bResult = true;
         }
         //Restore BEGINDATE and CLOSEDATE
         if (isset($arFields['__BEGINDATE'])) {
             $arFields['BEGINDATE'] = $arFields['__BEGINDATE'];
             unset($arFields['__BEGINDATE']);
         }
         if (isset($arFields['__CLOSEDATE'])) {
             $arFields['CLOSEDATE'] = $arFields['__CLOSEDATE'];
             unset($arFields['__CLOSEDATE']);
         }
         if (defined("BX_COMP_MANAGED_CACHE")) {
             static $arNameFields = array("TITLE");
             $bClear = false;
             foreach ($arNameFields as $val) {
                 if (isset($arFields[$val])) {
                     $bClear = true;
                     break;
                 }
             }
             if ($bClear) {
                 $GLOBALS["CACHE_MANAGER"]->ClearByTag("crm_entity_name_" . CCrmOwnerType::Deal . "_" . $ID);
             }
         }
         CCrmPerms::UpdateEntityAttr('DEAL', $ID, $arEntityAttr);
         CCrmEntityHelper::NormalizeUserFields($arFields, self::$sUFEntityID, $GLOBALS['USER_FIELD_MANAGER'], array('IS_NEW' => false));
         $GLOBALS['USER_FIELD_MANAGER']->Update(self::$sUFEntityID, $ID, $arFields);
         //Statistics & History -->
         $currentDbResult = \CCrmDeal::GetListEx(array(), array('=ID' => $ID, 'CHECK_PERMISSIONS' => 'N'), false, false, array('*', 'UF_*'));
         $currentFields = $currentDbResult->Fetch();
         Bitrix\Crm\Statistics\DealSumStatisticEntry::register($ID, $currentFields);
         Bitrix\Crm\History\DealStageHistoryEntry::synchronize($ID, $currentFields);
         Bitrix\Crm\Statistics\DealInvoiceStatisticEntry::synchronize($ID, $currentFields);
         Bitrix\Crm\Statistics\DealActivityStatisticEntry::synchronize($ID, $currentFields);
         if (isset($arFields['STAGE_ID'])) {
             Bitrix\Crm\History\DealStageHistoryEntry::register($ID, $arFields, array('IS_NEW' => false));
         }
         //<-- Statistics & History
         if ($bUpdateSearch) {
             $arFilterTmp = array('ID' => $ID);
             if (!$this->bCheckPermission) {
                 $arFilterTmp['CHECK_PERMISSIONS'] = 'N';
             }
             CCrmSearch::UpdateSearch($arFilterTmp, 'DEAL', true);
         }
         $arFields['ID'] = $ID;
         if (isset($arFields['FM']) && is_array($arFields['FM'])) {
             $CCrmFieldMulti = new CCrmFieldMulti();
             $CCrmFieldMulti->SetFields('DEAL', $ID, $arFields['FM']);
         }
         // Responsible user sync
         //CCrmActivity::Synchronize(CCrmOwnerType::Deal, $ID);
         $registerSonetEvent = isset($options['REGISTER_SONET_EVENT']) && $options['REGISTER_SONET_EVENT'] === true;
         if ($bResult && isset($arFields['ASSIGNED_BY_ID'])) {
             CCrmSonetSubscription::ReplaceSubscriptionByEntity(CCrmOwnerType::Deal, $ID, CCrmSonetSubscriptionType::Responsibility, $arFields['ASSIGNED_BY_ID'], $arRow['ASSIGNED_BY_ID'], $registerSonetEvent);
         }
         if ($bResult && $bCompare && $registerSonetEvent && !empty($sonetEventData)) {
             //CONTACT
             $newContactID = isset($arFields['CONTACT_ID']) ? intval($arFields['CONTACT_ID']) : 0;
             $oldContactID = isset($arRow['CONTACT_ID']) ? intval($arRow['CONTACT_ID']) : 0;
             $contactID = $newContactID > 0 ? $newContactID : $oldContactID;
             //COMPANY
             $newCompanyID = isset($arFields['COMPANY_ID']) ? intval($arFields['COMPANY_ID']) : 0;
             $oldCompanyID = isset($arRow['COMPANY_ID']) ? intval($arRow['COMPANY_ID']) : 0;
             $companyID = $newCompanyID > 0 ? $newCompanyID : $oldCompanyID;
             $modifiedByID = intval($arFields['MODIFY_BY_ID']);
             foreach ($sonetEventData as &$sonetEvent) {
                 $sonetEventType = $sonetEvent['TYPE'];
                 $sonetEventCode = isset($sonetEvent['CODE']) ? $sonetEvent['CODE'] : '';
                 $sonetEventFields =& $sonetEvent['FIELDS'];
                 $sonetEventFields['ENTITY_TYPE_ID'] = CCrmOwnerType::Deal;
                 $sonetEventFields['ENTITY_ID'] = $ID;
                 $sonetEventFields['USER_ID'] = $modifiedByID;
                 //Register contact & company relations
                 if ($sonetEventCode === 'CLIENT') {
                     $sonetEventFields['PARENTS'] = array();
                     //If contact changed bind events to old and new contacts
                     if ($oldContactID !== $newContactID) {
                         if ($oldContactID > 0) {
                             $sonetEventFields['PARENTS'][] = array('ENTITY_TYPE_ID' => CCrmOwnerType::Contact, 'ENTITY_ID' => $oldContactID);
                         }
                         if ($newContactID > 0) {
                             $sonetEventFields['PARENTS'][] = array('ENTITY_TYPE_ID' => CCrmOwnerType::Contact, 'ENTITY_ID' => $newContactID);
                         }
                     }
                     //If company changed bind events to old and new companies
                     if ($oldCompanyID !== $newCompanyID) {
                         if ($oldCompanyID > 0) {
                             $sonetEventFields['PARENTS'][] = array('ENTITY_TYPE_ID' => CCrmOwnerType::Company, 'ENTITY_ID' => $oldCompanyID);
                         }
                         if ($newCompanyID > 0) {
                             $sonetEventFields['PARENTS'][] = array('ENTITY_TYPE_ID' => CCrmOwnerType::Company, 'ENTITY_ID' => $newCompanyID);
                         }
                     }
                 } elseif ($contactID > 0 || $companyID > 0) {
                     $sonetEventFields['PARENTS'] = array();
                     if ($contactID > 0) {
                         $sonetEventFields['PARENTS'][] = array('ENTITY_TYPE_ID' => CCrmOwnerType::Contact, 'ENTITY_ID' => $contactID);
                     }
                     if ($companyID > 0) {
                         $sonetEventFields['PARENTS'][] = array('ENTITY_TYPE_ID' => CCrmOwnerType::Company, 'ENTITY_ID' => $companyID);
                     }
                 }
                 $logEventID = CCrmLiveFeed::CreateLogEvent($sonetEventFields, $sonetEventType);
                 if ($logEventID && CModule::IncludeModule("im")) {
                     $url = CCrmOwnerType::GetShowUrl(CCrmOwnerType::Deal, $ID);
                     $serverName = (CMain::IsHTTPS() ? "https" : "http") . "://" . (defined("SITE_SERVER_NAME") && strlen(SITE_SERVER_NAME) > 0 ? SITE_SERVER_NAME : COption::GetOptionString("main", "server_name", ""));
                     if ($sonetEvent['TYPE'] == CCrmLiveFeedEvent::Responsible && $sonetEventFields['PARAMS']['FINAL_RESPONSIBLE_ID'] != $modifiedByID) {
                         $arMessageFields = array("MESSAGE_TYPE" => IM_MESSAGE_SYSTEM, "TO_USER_ID" => $sonetEventFields['PARAMS']['FINAL_RESPONSIBLE_ID'], "FROM_USER_ID" => $modifiedByID, "NOTIFY_TYPE" => IM_NOTIFY_FROM, "NOTIFY_MODULE" => "crm", "LOG_ID" => $logEventID, "NOTIFY_EVENT" => "deal_update", "NOTIFY_TAG" => "CRM|DEAL_RESPONSIBLE|" . $ID, "NOTIFY_MESSAGE" => GetMessage("CRM_DEAL_RESPONSIBLE_IM_NOTIFY", array("#title#" => "<a href=\"" . $url . "\" class=\"bx-notifier-item-action\">" . htmlspecialcharsbx($arFields['TITLE']) . "</a>")), "NOTIFY_MESSAGE_OUT" => GetMessage("CRM_DEAL_RESPONSIBLE_IM_NOTIFY", array("#title#" => htmlspecialcharsbx($arFields['TITLE']))) . " (" . $serverName . $url . ")");
                         CIMNotify::Add($arMessageFields);
                     }
                     if ($sonetEvent['TYPE'] == CCrmLiveFeedEvent::Responsible && $sonetEventFields['PARAMS']['START_RESPONSIBLE_ID'] != $modifiedByID) {
                         $arMessageFields = array("MESSAGE_TYPE" => IM_MESSAGE_SYSTEM, "TO_USER_ID" => $sonetEventFields['PARAMS']['START_RESPONSIBLE_ID'], "FROM_USER_ID" => $modifiedByID, "NOTIFY_TYPE" => IM_NOTIFY_FROM, "NOTIFY_MODULE" => "crm", "LOG_ID" => $logEventID, "NOTIFY_EVENT" => "deal_update", "NOTIFY_TAG" => "CRM|DEAL_RESPONSIBLE|" . $ID, "NOTIFY_MESSAGE" => GetMessage("CRM_DEAL_NOT_RESPONSIBLE_IM_NOTIFY", array("#title#" => "<a href=\"" . $url . "\" class=\"bx-notifier-item-action\">" . htmlspecialcharsbx($arFields['TITLE']) . "</a>")), "NOTIFY_MESSAGE_OUT" => GetMessage("CRM_DEAL_NOT_RESPONSIBLE_IM_NOTIFY", array("#title#" => htmlspecialcharsbx($arFields['TITLE']))) . " (" . $serverName . $url . ")");
                         CIMNotify::Add($arMessageFields);
                     }
                     if ($sonetEvent['TYPE'] == CCrmLiveFeedEvent::Progress && $sonetEventFields['PARAMS']['START_STATUS_ID'] && $sonetEventFields['PARAMS']['FINAL_STATUS_ID']) {
                         $assignedByID = isset($arFields['ASSIGNED_BY_ID']) ? $arFields['ASSIGNED_BY_ID'] : $arRow['ASSIGNED_BY_ID'];
                         $infos = CCrmStatus::GetStatus('DEAL_STAGE');
                         if ($assignedByID != $modifiedByID && array_key_exists($sonetEventFields['PARAMS']['START_STATUS_ID'], $infos) && array_key_exists($sonetEventFields['PARAMS']['FINAL_STATUS_ID'], $infos)) {
                             $arMessageFields = array("MESSAGE_TYPE" => IM_MESSAGE_SYSTEM, "TO_USER_ID" => $assignedByID, "FROM_USER_ID" => $modifiedByID, "NOTIFY_TYPE" => IM_NOTIFY_FROM, "NOTIFY_MODULE" => "crm", "LOG_ID" => $logEventID, "NOTIFY_EVENT" => "deal_update", "NOTIFY_TAG" => "CRM|DEAL_PROGRESS|" . $ID, "NOTIFY_MESSAGE" => GetMessage("CRM_DEAL_PROGRESS_IM_NOTIFY", array("#title#" => "<a href=\"" . $url . "\" class=\"bx-notifier-item-action\">" . htmlspecialcharsbx($arFields['TITLE']) . "</a>", "#start_status_title#" => htmlspecialcharsbx($infos[$sonetEventFields['PARAMS']['START_STATUS_ID']]['NAME']), "#final_status_title#" => htmlspecialcharsbx($infos[$sonetEventFields['PARAMS']['FINAL_STATUS_ID']]['NAME']))), "NOTIFY_MESSAGE_OUT" => GetMessage("CRM_DEAL_PROGRESS_IM_NOTIFY", array("#title#" => htmlspecialcharsbx($arFields['TITLE']), "#start_status_title#" => htmlspecialcharsbx($infos[$sonetEventFields['PARAMS']['START_STATUS_ID']]['NAME']), "#final_status_title#" => htmlspecialcharsbx($infos[$sonetEventFields['PARAMS']['FINAL_STATUS_ID']]['NAME']))) . " (" . $serverName . $url . ")");
                             CIMNotify::Add($arMessageFields);
                         }
                     }
                 }
                 unset($sonetEventFields);
             }
             unset($sonetEvent);
         }
         if ($bResult) {
             $afterEvents = GetModuleEvents('crm', 'OnAfterCrmDealUpdate');
             while ($arEvent = $afterEvents->Fetch()) {
                 ExecuteModuleEventEx($arEvent, array(&$arFields));
             }
         }
         self::PullChange('UPDATE', array('ID' => $ID));
     }
     return $bResult;
 }
Esempio n. 3
0
$arParams['PATH_TO_DEAL_LIST'] = isset($arParams['PATH_TO_DEAL_LIST']) && $arParams['PATH_TO_DEAL_LIST'] !== '' ? $arParams['PATH_TO_DEAL_LIST'] : '#SITE_DIR#crm/deal/list/';
$arParams['PATH_TO_DEAL_EDIT'] = isset($arParams['PATH_TO_DEAL_EDIT']) && $arParams['PATH_TO_DEAL_EDIT'] !== '' ? $arParams['PATH_TO_DEAL_EDIT'] : '#SITE_DIR#crm/deal/edit/#deal_id#/';
$arParams['PATH_TO_DEAL_WIDGET'] = isset($arParams['PATH_TO_DEAL_WIDGET']) && $arParams['PATH_TO_DEAL_WIDGET'] !== '' ? $arParams['PATH_TO_DEAL_WIDGET'] : '#SITE_DIR#crm/deal/widget/';
$arParams['PATH_TO_LEAD_LIST'] = isset($arParams['PATH_TO_LEAD_LIST']) && $arParams['PATH_TO_LEAD_LIST'] !== '' ? $arParams['PATH_TO_LEAD_LIST'] : '#SITE_DIR#crm/lead/';
$arParams['PATH_TO_LEAD_EDIT'] = isset($arParams['PATH_TO_LEAD_EDIT']) && $arParams['PATH_TO_LEAD_EDIT'] !== '' ? $arParams['PATH_TO_LEAD_EDIT'] : '#SITE_DIR#crm/lead/edit/#lead_id#/';
$arParams['PATH_TO_QUOTE_LIST'] = isset($arParams['PATH_TO_QUOTE_LIST']) && $arParams['PATH_TO_QUOTE_LIST'] !== '' ? $arParams['PATH_TO_QUOTE_LIST'] : '#SITE_DIR#crm/quote/';
$arParams['PATH_TO_QUOTE_EDIT'] = isset($arParams['PATH_TO_QUOTE_EDIT']) && $arParams['PATH_TO_QUOTE_EDIT'] !== '' ? $arParams['PATH_TO_QUOTE_EDIT'] : '#SITE_DIR#crm/quote/edit/#quote_id#/';
$arParams['PATH_TO_INVOICE_LIST'] = isset($arParams['PATH_TO_INVOICE_LIST']) && $arParams['PATH_TO_INVOICE_LIST'] !== '' ? $arParams['PATH_TO_INVOICE_LIST'] : '#SITE_DIR#crm/invoice/';
$arParams['PATH_TO_INVOICE_EDIT'] = isset($arParams['PATH_TO_INVOICE_EDIT']) && $arParams['PATH_TO_INVOICE_EDIT'] !== '' ? $arParams['PATH_TO_INVOICE_EDIT'] : '#SITE_DIR#crm/invoice/edit/#invoice_id#/';
$arParams['PATH_TO_REPORT_LIST'] = isset($arParams['PATH_TO_REPORT_LIST']) && $arParams['PATH_TO_REPORT_LIST'] !== '' ? $arParams['PATH_TO_REPORT_LIST'] : '#SITE_DIR#crm/reports/report/';
$arParams['PATH_TO_DEAL_FUNNEL'] = isset($arParams['PATH_TO_DEAL_FUNNEL']) && $arParams['PATH_TO_DEAL_FUNNEL'] !== '' ? $arParams['PATH_TO_DEAL_FUNNEL'] : '#SITE_DIR#crm/reports/';
$arParams['PATH_TO_EVENT_LIST'] = isset($arParams['PATH_TO_EVENT_LIST']) && $arParams['PATH_TO_EVENT_LIST'] !== '' ? $arParams['PATH_TO_EVENT_LIST'] : '#SITE_DIR#crm/events/';
$arParams['PATH_TO_PRODUCT_LIST'] = isset($arParams['PATH_TO_PRODUCT_LIST']) && $arParams['PATH_TO_PRODUCT_LIST'] !== '' ? $arParams['PATH_TO_PRODUCT_LIST'] : '#SITE_DIR#crm/product/';
$arParams['PATH_TO_SETTINGS'] = isset($arParams['PATH_TO_SETTINGS']) && $arParams['PATH_TO_SETTINGS'] !== '' ? $arParams['PATH_TO_SETTINGS'] : '#SITE_DIR#crm/configs/';
$arParams['PATH_TO_SEARCH_PAGE'] = isset($arParams['PATH_TO_SEARCH_PAGE']) && $arParams['PATH_TO_SEARCH_PAGE'] !== '' ? $arParams['PATH_TO_SEARCH_PAGE'] : '#SITE_DIR#search/index.php?where=crm';
$arParams['PATH_TO_DEAL_INDEX'] = DealSettings::getDefaultListViewID() === DealSettings::VIEW_LIST ? $arParams['PATH_TO_DEAL_LIST'] : $arParams['PATH_TO_DEAL_WIDGET'];
$navigationIndex = CUserOptions::GetOption('crm.navigation', 'index');
if (is_array($navigationIndex)) {
    foreach ($navigationIndex as $k => $v) {
        $pageKey = 'PATH_TO_' . strtoupper("{$k}_{$v}");
        $arParams['PATH_TO_' . strtoupper($k) . '_INDEX'] = $arParams['PATH_TO_' . strtoupper("{$k}_{$v}")];
    }
}
//<-- Preparing of URL templates
$arResult['ACTIVE_ITEM_ID'] = isset($arParams['ACTIVE_ITEM_ID']) ? $arParams['ACTIVE_ITEM_ID'] : '';
$arResult['ENABLE_SEARCH'] = isset($arParams['ENABLE_SEARCH']) && is_bool($arParams['ENABLE_SEARCH']) ? $arParams['ENABLE_SEARCH'] : true;
$arResult['SEARCH_PAGE_URL'] = CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_SEARCH_PAGE']);
$arResult['ID'] = isset($arParams['ID']) ? $arParams['ID'] : '';
if ($arResult['ID'] === '') {
    $arResult['ID'] = 'DEFAULT';
}