<?php if (!defined('B_PROLOG_INCLUDED') || B_PROLOG_INCLUDED !== true) { die; } global $APPLICATION; use Bitrix\Crm\BirthdayReminder; if (!CModule::IncludeModule('crm')) { ShowError(GetMessage('CRM_MODULE_NOT_INSTALLED')); return; } $userID = CCrmSecurityHelper::GetCurrentUserID(); $isAdminUser = CCrmPerms::IsAdmin($userID); $userPermissions = CCrmPerms::GetUserPermissions($userID); $canReadLead = CCrmLead::CheckReadPermission(0, $userPermissions); $canReadContact = CCrmContact::CheckReadPermission(0, $userPermissions); if (!$canReadLead && !$canReadContact) { ShowError(GetMessage('CRM_PERMISSION_DENIED')); return; } $arResult['USER_ID'] = $userID; $listID = isset($arParams['LIST_ID']) ? $arParams['LIST_ID'] : ''; if ($listID === '') { $listID = uniqid('birthdays_'); } $arResult['LIST_ID'] = $listID; $arResult['ERRORS'] = array(); $arResult['MESSAGES'] = array(); $arParams['NAME_FORMAT'] = isset($arParams['NAME_FORMAT']) ? $arParams['NAME_FORMAT'] : ''; $arResult['NAME_FORMAT'] = $arParams['NAME_FORMAT'] !== '' ? $arParams['NAME_FORMAT'] : \Bitrix\Crm\Format\PersonNameFormatter::getFormat(); $utils = new CComponentUtil();
$arResult['RESPONSIBLE_SELECTOR_PARAMS'] = array('NAME' => 'crm_quote_edit_resonsible', 'INPUT_NAME' => 'ASSIGNED_BY_ID', 'SEARCH_INPUT_NAME' => 'ASSIGNED_BY_NAME', 'NAME_TEMPLATE' => $arParams['NAME_TEMPLATE']); $arResult['FIELDS']['tab_1'][] = array('id' => 'ASSIGNED_BY_ID', 'componentParams' => $arResult['RESPONSIBLE_SELECTOR_PARAMS'], 'name' => GetMessage('CRM_QUOTE_FIELD_ASSIGNED_BY_ID'), 'type' => 'intranet_user_search', 'value' => isset($arResult['ELEMENT']['ASSIGNED_BY_ID']) ? $arResult['ELEMENT']['ASSIGNED_BY_ID'] : $USER->GetID()); //Fix for issue #36848 $beginDate = isset($arResult['ELEMENT']['BEGINDATE']) ? $arResult['ELEMENT']['BEGINDATE'] : ''; $closeDate = isset($arResult['ELEMENT']['CLOSEDATE']) ? $arResult['ELEMENT']['CLOSEDATE'] : ''; $arResult['FIELDS']['tab_1'][] = array('id' => 'BEGINDATE', 'name' => GetMessage('CRM_QUOTE_FIELD_BEGINDATE'), 'params' => array('sale_order_marker' => 'Y'), 'type' => 'date_link', 'value' => $beginDate !== '' ? ConvertTimeStamp(MakeTimeStamp($beginDate), 'SHORT', SITE_ID) : ''); $arResult['FIELDS']['tab_1'][] = array('id' => 'CLOSEDATE', 'name' => GetMessage('CRM_QUOTE_FIELD_CLOSEDATE'), 'type' => 'date_short', 'value' => $closeDate !== '' ? ConvertTimeStamp(MakeTimeStamp($closeDate), 'SHORT', SITE_ID) : '', 'params' => array('class' => 'bx-crm-dialog-input bx-crm-dialog-input-date')); if (CCrmLead::CheckReadPermission()) { $arResult['FIELDS']['tab_1'][] = array('id' => 'LEAD_ID', 'name' => GetMessage('CRM_QUOTE_FIELD_LEAD_ID'), 'type' => 'crm_entity_selector', 'componentParams' => array('ENTITY_TYPE' => 'LEAD', 'INPUT_NAME' => 'LEAD_ID', 'NEW_INPUT_NAME' => '', 'INPUT_VALUE' => isset($arResult['ELEMENT']['LEAD_ID']) ? $arResult['ELEMENT']['LEAD_ID'] : '', 'FORM_NAME' => $arResult['FORM_ID'], 'MULTIPLE' => 'N', 'NAME_TEMPLATE' => \Bitrix\Crm\Format\PersonNameFormatter::getFormat())); } if (CCrmDeal::CheckReadPermission()) { $arResult['FIELDS']['tab_1'][] = array('id' => 'DEAL_ID', 'name' => GetMessage('CRM_QUOTE_FIELD_DEAL_ID'), 'type' => 'crm_entity_selector', 'componentParams' => array('ENTITY_TYPE' => 'DEAL', 'INPUT_NAME' => 'DEAL_ID', 'NEW_INPUT_NAME' => '', 'INPUT_VALUE' => isset($arResult['ELEMENT']['DEAL_ID']) ? $arResult['ELEMENT']['DEAL_ID'] : '', 'FORM_NAME' => $arResult['FORM_ID'], 'MULTIPLE' => 'N', 'NAME_TEMPLATE' => \Bitrix\Crm\Format\PersonNameFormatter::getFormat())); } $arResult['FIELDS']['tab_1'][] = array('id' => 'OPENED', 'name' => GetMessage('CRM_QUOTE_FIELD_OPENED'), 'type' => 'vertical_checkbox', 'params' => array(), 'value' => isset($arResult['ELEMENT']['OPENED']) ? $arResult['ELEMENT']['OPENED'] : true, 'title' => GetMessage('CRM_QUOTE_FIELD_OPENED_TITLE')); $arResult['FIELDS']['tab_1'][] = array('id' => 'section_contact_info', 'name' => GetMessage('CRM_SECTION_CLIENT_INFO'), 'type' => 'section'); if (CCrmContact::CheckReadPermission()) { $arResult['FIELDS']['tab_1'][] = array('id' => 'CONTACT_ID', 'name' => GetMessage('CRM_QUOTE_FIELD_CONTACT_ID'), 'type' => 'crm_entity_selector', 'componentParams' => array('ENTITY_TYPE' => 'CONTACT', 'INPUT_NAME' => 'CONTACT_ID', 'NEW_INPUT_NAME' => CCrmContact::CheckCreatePermission() ? 'NEW_CONTACT_ID' : '', 'INPUT_VALUE' => isset($arResult['ELEMENT']['CONTACT_ID']) ? $arResult['ELEMENT']['CONTACT_ID'] : '', 'FORM_NAME' => $arResult['FORM_ID'], 'MULTIPLE' => 'N', 'NAME_TEMPLATE' => \Bitrix\Crm\Format\PersonNameFormatter::getFormat())); } if (CCrmCompany::CheckReadPermission()) { $arResult['FIELDS']['tab_1'][] = array('id' => 'COMPANY_ID', 'name' => GetMessage('CRM_QUOTE_FIELD_COMPANY_ID'), 'type' => 'crm_entity_selector', 'componentParams' => array('ENTITY_TYPE' => 'COMPANY', 'INPUT_NAME' => 'COMPANY_ID', 'NEW_INPUT_NAME' => CCrmCompany::CheckCreatePermission() ? 'NEW_COMPANY_ID' : '', 'INPUT_VALUE' => isset($arResult['ELEMENT']['COMPANY_ID']) ? $arResult['ELEMENT']['COMPANY_ID'] : '', 'FORM_NAME' => $arResult['FORM_ID'], 'MULTIPLE' => 'N', 'NAME_TEMPLATE' => \Bitrix\Crm\Format\PersonNameFormatter::getFormat())); } if ($bTaxMode) { // CLIENT LOCATION $sLocationHtml = ''; $locValue = isset($arResult['ELEMENT']['LOCATION_ID']) ? $arResult['ELEMENT']['LOCATION_ID'] : ''; ob_start(); CSaleLocation::proxySaleAjaxLocationsComponent(array('AJAX_CALL' => 'N', 'COUNTRY_INPUT_NAME' => 'LOC_COUNTRY', 'REGION_INPUT_NAME' => 'LOC_REGION', 'CITY_INPUT_NAME' => 'LOC_CITY', 'CITY_OUT_LOCATION' => 'Y', 'LOCATION_VALUE' => $locValue, 'ORDER_PROPS_ID' => 'QUOTE_' . $arResult['ELEMENT']['ID'], 'ONCITYCHANGE' => 'BX.onCustomEvent(\'CrmProductRowSetLocation\', [\'LOC_CITY\']);', 'SHOW_QUICK_CHOOSE' => 'N'), array("CODE" => $locValue, "ID" => "", "PROVIDE_LINK_BY" => "code", "JS_CALLBACK" => 'CrmProductRowSetLocation'), 'popup'); $sLocationHtml = ob_get_contents(); ob_end_clean(); $locationField = array('id' => 'LOCATION_ID', 'name' => GetMessage('CRM_QUOTE_FIELD_LOCATION_ID'), 'type' => 'custom', 'value' => $sLocationHtml . '<div>' . '<span class="bx-crm-edit-content-location-description">' . GetMessage('CRM_QUOTE_FIELD_LOCATION_ID_DESCRIPTION') . '</span>' . '</div>', 'required' => true); $arResult['FIELDS']['tab_1'][] = $locationField;
public static function GetShowUrl($typeID, $ID, $bCheckPermissions = false) { $typeID = intval($typeID); $ID = intval($ID); if ($ID <= 0) { return ''; } switch ($typeID) { case self::Lead: if ($bCheckPermissions && !CCrmLead::CheckReadPermission($ID)) { return ''; } return CComponentEngine::MakePathFromTemplate(COption::GetOptionString('crm', 'path_to_lead_show'), array('lead_id' => $ID)); case self::Contact: if ($bCheckPermissions && !CCrmContact::CheckReadPermission($ID)) { return ''; } return CComponentEngine::MakePathFromTemplate(COption::GetOptionString('crm', 'path_to_contact_show'), array('contact_id' => $ID)); case self::Company: if ($bCheckPermissions && !CCrmCompany::CheckReadPermission($ID)) { return ''; } return CComponentEngine::MakePathFromTemplate(COption::GetOptionString('crm', 'path_to_company_show'), array('company_id' => $ID)); case self::Deal: if ($bCheckPermissions && !CCrmDeal::CheckReadPermission($ID)) { return ''; } return CComponentEngine::MakePathFromTemplate(COption::GetOptionString('crm', 'path_to_deal_show'), array('deal_id' => $ID)); case self::Activity: return CComponentEngine::MakePathFromTemplate(COption::GetOptionString('crm', 'path_to_activity_show'), array('activity_id' => $ID)); case self::Invoice: if ($bCheckPermissions && !CCrmInvoice::CheckReadPermission($ID)) { return ''; } return CComponentEngine::MakePathFromTemplate(COption::GetOptionString('crm', 'path_to_invoice_show'), array('invoice_id' => $ID)); case self::Quote: if ($bCheckPermissions && !CCrmQuote::CheckReadPermission($ID)) { return ''; } return CComponentEngine::MakePathFromTemplate(COption::GetOptionString('crm', 'path_to_quote_show'), array('quote_id' => $ID)); default: return ''; } }
<?php if (!defined('B_PROLOG_INCLUDED') || B_PROLOG_INCLUDED !== true) { die; } global $APPLICATION; use Bitrix\Crm\Integrity; if (!CModule::IncludeModule('crm')) { ShowError(GetMessage('CRM_MODULE_NOT_INSTALLED')); return; } $userID = CCrmSecurityHelper::GetCurrentUserID(); $isAdminUser = CCrmPerms::IsAdmin($userID); $userPermissions = CCrmPerms::GetUserPermissions($userID); $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 ($successed) { //$DB->Commit(); __CrmMobileContactEditEndResonse(array('DELETED_ENTITY_ID' => $ID)); } else { //$DB->Rollback(); __CrmMobileContactEditEndResonse(array('ERROR' => GetMessage('CRM_CONTACT_COULD_NOT_DELETE'))); } } elseif ($action === 'GET_ENTITY') { __IncludeLang(dirname(__FILE__) . '/lang/' . LANGUAGE_ID . '/' . basename(__FILE__)); $typeName = isset($_REQUEST['ENTITY_TYPE_NAME']) ? $_REQUEST['ENTITY_TYPE_NAME'] : ''; if ($typeName !== 'CONTACT') { __CrmMobileContactEditEndResonse(array('ERROR' => GetMessage('CRM_ENTITY_TYPE_NOT_SUPPORTED', array('#ENTITY_TYPE#' => $typeName)))); } $ID = isset($_REQUEST['ENTITY_ID']) ? intval($_REQUEST['ENTITY_ID']) : 0; if ($ID <= 0) { __CrmMobileContactEditEndResonse(array('ERROR' => GetMessage('CRM_ENTITY_ID_NOT_FOUND'))); } if (!CCrmContact::CheckReadPermission($ID)) { __CrmMobileContactEditEndResonse(array('ERROR' => GetMessage('CRM_ACCESS_DENIED'))); } $dbRes = CCrmContact::GetListEx(array(), array('=ID' => $ID, 'CHECK_PERMISSIONS' => 'N')); $item = $dbRes ? $dbRes->GetNext() : null; if (!is_array($item)) { __CrmMobileContactEditEndResonse(array('ERROR' => GetMessage('CRM_CONTACT_NOT_FOUND', array('#ID#' => $ID)))); } $formatParams = isset($_REQUEST['FORMAT_PARAMS']) ? $_REQUEST['FORMAT_PARAMS'] : array(); CCrmMobileHelper::PrepareContactItem($item, $formatParams); __CrmMobileContactEditEndResonse(array('ENTITY' => CCrmMobileHelper::PrepareContactData($item))); } else { __CrmMobileContactEditEndResonse(array('ERROR' => 'Action is not supported in current context.')); }
protected function checkEntityReadPermission($entityID, $userPermissions) { return \CCrmContact::CheckReadPermission($entityID, $userPermissions); }
public static function findByPhoneNumber($number, $params = array()) { if (!is_string($number)) { throw new \Bitrix\Main\ArgumentTypeException('number', 'string'); } if ($number === '') { throw new \Bitrix\Main\ArgumentException('Is empty', 'number'); } if (!is_array($params)) { $params = array(); } $userID = isset($params['USER_ID']) ? intval($params['USER_ID']) : 0; if ($userID <= 0) { $userID = CCrmPerms::GetCurrentUserID(); } $isAdmin = CCrmPerms::IsAdmin($userID); $userPermissions = CCrmPerms::GetUserPermissions($userID); $enableExtendedMode = isset($params['ENABLE_EXTENDED_MODE']) ? (bool) $params['ENABLE_EXTENDED_MODE'] : true; $contactFormID = isset($params['CONTACT_FORM_ID']) ? intval($params['CONTACT_FORM_ID']) : ''; if ($contactFormID === '') { $contactFormID = CCrmContact::DEFAULT_FORM_ID; } $dups = array(); $criterion = new \Bitrix\Crm\Integrity\DuplicateCommunicationCriterion('PHONE', $number); $entityTypes = array(CCrmOwnerType::Contact, CCrmOwnerType::Company, CCrmOwnerType::Lead); foreach ($entityTypes as $entityType) { $duplicate = $criterion->find($entityType, 1); if ($duplicate !== null) { $dups[] = $duplicate; } } $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(); $entityID = $entity->getEntityID(); $fields = null; if ($entityTypeID === CCrmOwnerType::Contact) { $dbEntity = CCrmContact::GetListEx(array(), array('=ID' => $entityID, 'CHECK_PERMISSIONS' => 'N'), false, false, array('ID', 'HONORIFIC', 'NAME', 'SECOND_NAME', 'LAST_NAME', 'PHOTO', 'POST', 'COMPANY_ID', 'COMPANY_TITLE', 'ASSIGNED_BY_ID')); $entityFields = is_object($dbEntity) ? $dbEntity->Fetch() : null; if (is_array($entityFields)) { $formattedName = CCrmContact::PrepareFormattedName(array('HONORIFIC' => isset($entityFields['HONORIFIC']) ? $entityFields['HONORIFIC'] : '', 'NAME' => isset($entityFields['NAME']) ? $entityFields['NAME'] : '', 'SECOND_NAME' => isset($entityFields['SECOND_NAME']) ? $entityFields['SECOND_NAME'] : '', 'LAST_NAME' => isset($entityFields['LAST_NAME']) ? $entityFields['LAST_NAME'] : '')); $fields = array('ID' => intval($entityFields['ID']), 'FORMATTED_NAME' => $formattedName, 'PHOTO' => isset($entityFields['PHOTO']) ? intval($entityFields['PHOTO']) : 0, 'COMPANY_ID' => isset($entityFields['COMPANY_ID']) ? intval($entityFields['COMPANY_ID']) : 0, 'COMPANY_TITLE' => isset($entityFields['COMPANY_TITLE']) ? $entityFields['COMPANY_TITLE'] : '', 'POST' => isset($entityFields['POST']) ? $entityFields['POST'] : '', 'ASSIGNED_BY_ID' => isset($entityFields['ASSIGNED_BY_ID']) ? intval($entityFields['ASSIGNED_BY_ID']) : 0, 'CAN_READ' => CCrmContact::CheckReadPermission($entityID, $userPermissions)); if ($fields['CAN_READ'] && $enableExtendedMode) { $deals = array(); $dbDeal = CCrmDeal::GetListEx(array('BEGINDATE' => 'ASC'), array('=CONTACT_ID' => $entityID, 'CLOSED' => 'N', 'CHECK_PERMISSIONS' => $isAdmin ? 'N' : 'Y'), false, array('nTopCount' => 2), array('ID', 'TITLE', 'STAGE_ID'), array('PERMS' => $userPermissions)); if (is_object($dbDeal)) { while ($dealFields = $dbDeal->Fetch()) { $dealID = intval($dealFields['ID']); //$dealFields['CAN_READ'] = CCrmDeal::CheckReadPermission($dealID, $userPermissions); $dealFields['SHOW_URL'] = CCrmOwnerType::GetShowUrl(CCrmOwnerType::Deal, $dealID); $deals[] = $dealFields; } } $fields['DEALS'] =& $deals; unset($deals); } } } elseif ($entityTypeID === CCrmOwnerType::Company) { $dbEntity = CCrmCompany::GetListEx(array(), array('=ID' => $entityID, 'CHECK_PERMISSIONS' => 'N'), false, false, array('ID', 'TITLE', 'LOGO', 'ASSIGNED_BY_ID')); $entityFields = is_object($dbEntity) ? $dbEntity->Fetch() : null; if (is_array($entityFields)) { $fields = array('ID' => intval($entityFields['ID']), 'TITLE' => isset($entityFields['TITLE']) ? $entityFields['TITLE'] : '', 'LOGO' => isset($entityFields['LOGO']) ? intval($entityFields['LOGO']) : 0, 'ASSIGNED_BY_ID' => isset($entityFields['ASSIGNED_BY_ID']) ? intval($entityFields['ASSIGNED_BY_ID']) : 0, 'CAN_READ' => CCrmCompany::CheckReadPermission($entityID, $userPermissions)); if ($fields['CAN_READ'] && $enableExtendedMode) { $deals = array(); $dbDeal = CCrmDeal::GetListEx(array('BEGINDATE' => 'ASC'), array('=COMPANY_ID' => $entityID, 'CLOSED' => 'N', 'CHECK_PERMISSIONS' => $isAdmin ? 'N' : 'Y'), false, array('nTopCount' => 2), array('ID', 'TITLE', 'STAGE_ID'), array('PERMS' => $userPermissions)); if (is_object($dbDeal)) { while ($dealFields = $dbDeal->Fetch()) { $dealID = intval($dealFields['ID']); //$dealFields['CAN_READ'] = CCrmDeal::CheckReadPermission($dealID, $userPermissions); $dealFields['SHOW_URL'] = CCrmOwnerType::GetShowUrl(CCrmOwnerType::Deal, $dealID); $deals[] = $dealFields; } } $fields['DEALS'] =& $deals; unset($deals); } } } elseif ($entityTypeID === CCrmOwnerType::Lead) { $dbEntity = CCrmLead::GetListEx(array(), array('=ID' => $entityID, 'CHECK_PERMISSIONS' => 'N'), false, false, array('ID', 'TITLE', 'HONORIFIC', 'NAME', 'SECOND_NAME', 'LAST_NAME', 'POST', 'COMPANY_TITLE', 'ASSIGNED_BY_ID')); $entityFields = is_object($dbEntity) ? $dbEntity->Fetch() : null; if (is_array($entityFields)) { $formattedName = ''; if (!empty($entityFields['NAME']) || !empty($entityFields['SECOND_NAME']) || !empty($entityFields['LAST_NAME'])) { $formattedName = CCrmLead::PrepareFormattedName(array('HONORIFIC' => isset($entityFields['HONORIFIC']) ? $entityFields['HONORIFIC'] : '', 'NAME' => isset($entityFields['NAME']) ? $entityFields['NAME'] : '', 'SECOND_NAME' => isset($entityFields['SECOND_NAME']) ? $entityFields['SECOND_NAME'] : '', 'LAST_NAME' => isset($entityFields['LAST_NAME']) ? $entityFields['LAST_NAME'] : '')); } $fields = array('ID' => intval($entityFields['ID']), 'TITLE' => isset($entityFields['TITLE']) ? $entityFields['TITLE'] : '', 'FORMATTED_NAME' => $formattedName, 'COMPANY_TITLE' => isset($entityFields['COMPANY_TITLE']) ? $entityFields['COMPANY_TITLE'] : '', 'POST' => isset($entityFields['POST']) ? $entityFields['POST'] : '', 'ASSIGNED_BY_ID' => isset($entityFields['ASSIGNED_BY_ID']) ? intval($entityFields['ASSIGNED_BY_ID']) : 0, 'CAN_READ' => CCrmLead::CheckReadPermission($entityID, $userPermissions)); } } if (!is_array($fields)) { continue; } if ($fields['CAN_READ'] && $enableExtendedMode) { $showUrl = $fields['SHOW_URL'] = CCrmOwnerType::GetShowUrl($entityTypeID, $entityID); if ($showUrl !== '') { $fields['ACTIVITY_LIST_URL'] = CCrmUrlUtil::AddUrlParams($showUrl, array("{$contactFormID}_active_tab" => 'tab_activity')); $fields['INVOICE_LIST_URL'] = CCrmUrlUtil::AddUrlParams($showUrl, array("{$contactFormID}_active_tab" => 'tab_invoice')); if ($entityTypeID === CCrmOwnerType::Contact || $entityTypeID === CCrmOwnerType::Company) { $fields['DEAL_LIST_URL'] = CCrmUrlUtil::AddUrlParams($showUrl, array("{$contactFormID}_active_tab" => 'tab_deal')); } } $activities = array(); $dbActivity = CCrmActivity::GetList(array('DEADLINE' => 'ASC'), array('COMPLETED' => 'N', 'BINDINGS' => array(array('OWNER_TYPE_ID' => $entityTypeID, 'OWNER_ID' => $entityID)), 'CHECK_PERMISSIONS' => $isAdmin ? 'N' : 'Y'), false, array('nTopCount' => 4), array('ID', 'SUBJECT', 'START_TIME', 'END_TIME', 'DEADLINE'), array('PERMS' => $userPermissions)); if (is_object($dbActivity)) { while ($activityFields = $dbActivity->Fetch()) { $activityFields['SHOW_URL'] = CCrmOwnerType::GetShowUrl(CCrmOwnerType::Activity, $activityFields['ID']); $activities[] =& $activityFields; unset($activityFields); } } $fields['ACTIVITIES'] =& $activities; unset($activities); } $entityTypeName = CCrmOwnerType::ResolveName($entityTypeID); if (!isset($entityByType[$entityTypeName])) { $entityByType[$entityTypeName] = array($fields); } elseif (!in_array($entityID, $entityByType[$entityTypeName], true)) { $entityByType[$entityTypeName][] = $fields; } } } unset($dup); return $entityByType; }
if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED !== true) { die; } 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(); //Security check $userPermissions = CCrmPerms::GetCurrentUserPermissions(); $filter = isset($componentParams['INTERNAL_FILTER']) && is_array($componentParams['INTERNAL_FILTER']) ? $componentParams['INTERNAL_FILTER'] : array(); $ID = isset($filter['ID']) ? $filter['ID'] : 0; $companyID = isset($filter['COMPANY_ID']) ? $filter['COMPANY_ID'] : 0; $isPermitted = false; if ($ID > 0) { $isPermitted = CCrmContact::CheckReadPermission($ID, $userPermissions); } elseif ($companyID > 0) { $isPermitted = CCrmCompany::CheckReadPermission($companyID, $userPermissions); } if (!$isPermitted) { die; } //For custom reload with params $ajaxLoaderParams = array('url' => '', 'method' => 'POST', 'dataType' => 'ajax', 'data' => array('PARAMS' => $componentData)); global $APPLICATION; Header('Content-Type: text/html; charset=' . LANG_CHARSET); $APPLICATION->ShowAjaxHead(); //Force AJAX mode $componentParams['AJAX_MODE'] = 'Y'; $componentParams['AJAX_OPTION_JUMP'] = 'N'; $componentParams['AJAX_OPTION_HISTORY'] = 'N';
} $arResult['TOOLBAR_ID'] = $toolbarID; $arResult['BUTTONS'] = array(); if ($arParams['TYPE'] == 'list') { $bRead = !$CrmPerms->HavePerm('CONTACT', BX_CRM_PERM_NONE, 'READ'); $bExport = !$CrmPerms->HavePerm('CONTACT', BX_CRM_PERM_NONE, 'EXPORT'); $bImport = !$CrmPerms->HavePerm('CONTACT', BX_CRM_PERM_NONE, 'IMPORT'); $bAdd = !$CrmPerms->HavePerm('CONTACT', BX_CRM_PERM_NONE, 'ADD'); $bWrite = !$CrmPerms->HavePerm('CONTACT', BX_CRM_PERM_NONE, 'WRITE'); $bDelete = false; $bDedupe = !$CrmPerms->HavePerm('CONTACT', BX_CRM_PERM_NONE, 'WRITE') && !$CrmPerms->HavePerm('CONTACT', BX_CRM_PERM_NONE, 'DELETE'); } else { $bExport = false; $bImport = false; $bDedupe = false; $bRead = CCrmContact::CheckReadPermission($arParams['ELEMENT_ID'], $CrmPerms); $bAdd = CCrmContact::CheckCreatePermission($CrmPerms); $bWrite = CCrmContact::CheckUpdatePermission($arParams['ELEMENT_ID'], $CrmPerms); $bDelete = CCrmContact::CheckDeletePermission($arParams['ELEMENT_ID'], $CrmPerms); } if (!$bRead && !$bAdd && !$bWrite) { return false; } if ($arParams['TYPE'] === 'list') { if ($bAdd) { $arResult['BUTTONS'][] = array('TEXT' => GetMessage('CRM_CONTACT_ADD'), 'TITLE' => GetMessage('CRM_CONTACT_ADD_TITLE'), 'LINK' => CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_CONTACT_EDIT'], array('contact_id' => 0)), 'HIGHLIGHT' => true); } if ($bImport) { $arResult['BUTTONS'][] = array('TEXT' => GetMessage('CRM_CONTACT_IMPORT_VCARD'), 'TITLE' => GetMessage('CRM_CONTACT_IMPORT_VCARD_TITLE'), 'LINK' => CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_CONTACT_IMPORTVCARD'], array()), 'ICON' => 'btn-import'); $importUrl = CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_CONTACT_IMPORT'], array()); $arResult['BUTTONS'][] = array('TEXT' => GetMessage('CRM_CONTACT_IMPORT_GMAIL'), 'TITLE' => GetMessage('CRM_CONTACT_IMPORT_GMAIL_TITLE'), 'LINK' => CCrmUrlUtil::AddUrlParams($importUrl, array('origin' => 'gmail')), 'ICON' => 'btn-import');
ob_start(); $APPLICATION->IncludeComponent('bitrix:crm.field_multi.edit', 'new', array('FM_MNEMONIC' => 'COMFM', 'ENTITY_ID' => 'COMPANY', 'ELEMENT_ID' => $arResult['ELEMENT']['ID'], 'TYPE_ID' => 'WEB', 'VALUES' => isset($arResult['ELEMENT']['FM']) ? $arResult['ELEMENT']['FM'] : array(), 'SKIP_VALUES' => array('HOME')), null, array('HIDE_ICONS' => 'Y')); $sVal = ob_get_contents(); ob_end_clean(); $arResult['FIELDS']['tab_1'][] = array('id' => 'WEB', 'name' => GetMessage('CRM_FIELD_WEB'), 'type' => 'custom', 'value' => $sVal); ob_start(); $APPLICATION->IncludeComponent('bitrix:crm.field_multi.edit', 'new', array('FM_MNEMONIC' => 'COMFM', 'ENTITY_ID' => 'COMPANY', 'ELEMENT_ID' => $arResult['ELEMENT']['ID'], 'TYPE_ID' => 'IM', 'VALUES' => isset($arResult['ELEMENT']['FM']) ? $arResult['ELEMENT']['FM'] : array()), null, array('HIDE_ICONS' => 'Y')); $sVal = ob_get_contents(); ob_end_clean(); $arResult['FIELDS']['tab_1'][] = array('id' => 'IM', 'name' => GetMessage('CRM_FIELD_MESSENGER'), 'type' => 'custom', 'value' => $sVal); $arResult['FIELDS']['tab_1'][] = array('id' => 'ADDRESS', 'name' => GetMessage('CRM_FIELD_ADDRESS'), 'type' => 'address', 'componentParams' => array('SERVICE_URL' => '/bitrix/components/bitrix/crm.company.edit/ajax.php?siteID=' . SITE_ID . '&' . bitrix_sessid_get(), 'DATA' => array('ADDRESS' => array('NAME' => 'ADDRESS', 'IS_MULTILINE' => true, 'VALUE' => isset($arResult['ELEMENT']['~ADDRESS']) ? $arResult['ELEMENT']['~ADDRESS'] : ''), 'ADDRESS_2' => array('NAME' => 'ADDRESS_2', 'VALUE' => isset($arResult['ELEMENT']['~ADDRESS_2']) ? $arResult['ELEMENT']['~ADDRESS_2'] : ''), 'CITY' => array('NAME' => 'ADDRESS_CITY', 'VALUE' => isset($arResult['ELEMENT']['~ADDRESS_CITY']) ? $arResult['ELEMENT']['~ADDRESS_CITY'] : ''), 'REGION' => array('NAME' => 'ADDRESS_REGION', 'VALUE' => isset($arResult['ELEMENT']['~ADDRESS_REGION']) ? $arResult['ELEMENT']['~ADDRESS_REGION'] : ''), 'PROVINCE' => array('NAME' => 'ADDRESS_PROVINCE', 'VALUE' => isset($arResult['ELEMENT']['~ADDRESS_PROVINCE']) ? $arResult['ELEMENT']['~ADDRESS_PROVINCE'] : ''), 'POSTAL_CODE' => array('NAME' => 'ADDRESS_POSTAL_CODE', 'VALUE' => isset($arResult['ELEMENT']['~ADDRESS_POSTAL_CODE']) ? $arResult['ELEMENT']['~ADDRESS_POSTAL_CODE'] : ''), 'COUNTRY' => array('NAME' => 'ADDRESS_COUNTRY', 'VALUE' => isset($arResult['ELEMENT']['~ADDRESS_COUNTRY']) ? $arResult['ELEMENT']['~ADDRESS_COUNTRY'] : '', 'LOCALITY' => array('TYPE' => 'COUNTRY', 'NAME' => 'ADDRESS_COUNTRY_CODE', 'VALUE' => isset($arResult['ELEMENT']['~ADDRESS_COUNTRY_CODE']) ? $arResult['ELEMENT']['~ADDRESS_COUNTRY_CODE'] : ''))))); $arResult['FIELDS']['tab_1'][] = array('id' => 'ADDRESS_LEGAL', 'name' => GetMessage('CRM_FIELD_ADDRESS_LEGAL'), 'type' => 'address', 'componentParams' => array('SERVICE_URL' => '/bitrix/components/bitrix/crm.company.edit/ajax.php?siteID=' . SITE_ID . '&' . bitrix_sessid_get(), 'DATA' => array('ADDRESS' => array('NAME' => 'REG_ADDRESS', 'IS_MULTILINE' => true, 'VALUE' => isset($arResult['ELEMENT']['~REG_ADDRESS']) ? $arResult['ELEMENT']['~REG_ADDRESS'] : ''), 'ADDRESS_2' => array('NAME' => 'REG_ADDRESS_2', 'VALUE' => isset($arResult['ELEMENT']['~REG_ADDRESS_2']) ? $arResult['ELEMENT']['~REG_ADDRESS_2'] : ''), 'CITY' => array('NAME' => 'REG_ADDRESS_CITY', 'VALUE' => isset($arResult['ELEMENT']['~REG_ADDRESS_CITY']) ? $arResult['ELEMENT']['~REG_ADDRESS_CITY'] : ''), 'REGION' => array('NAME' => 'REG_ADDRESS_REGION', 'VALUE' => isset($arResult['ELEMENT']['~REG_ADDRESS_REGION']) ? $arResult['ELEMENT']['~REG_ADDRESS_REGION'] : ''), 'PROVINCE' => array('NAME' => 'REG_ADDRESS_PROVINCE', 'VALUE' => isset($arResult['ELEMENT']['~REG_ADDRESS_PROVINCE']) ? $arResult['ELEMENT']['~REG_ADDRESS_PROVINCE'] : ''), 'POSTAL_CODE' => array('NAME' => 'REG_ADDRESS_POSTAL_CODE', 'VALUE' => isset($arResult['ELEMENT']['~REG_ADDRESS_POSTAL_CODE']) ? $arResult['ELEMENT']['~REG_ADDRESS_POSTAL_CODE'] : ''), 'COUNTRY' => array('NAME' => 'REG_ADDRESS_COUNTRY', 'VALUE' => isset($arResult['ELEMENT']['~REG_ADDRESS_COUNTRY']) ? $arResult['ELEMENT']['~REG_ADDRESS_COUNTRY'] : '', 'LOCALITY' => array('TYPE' => 'COUNTRY', 'NAME' => 'REG_ADDRESS_COUNTRY_CODE', 'VALUE' => isset($arResult['ELEMENT']['~REG_ADDRESS_COUNTRY_CODE']) ? $arResult['ELEMENT']['~REG_ADDRESS_COUNTRY_CODE'] : ''))))); $arResult['FIELDS']['tab_1'][] = array('id' => 'BANKING_DETAILS', 'name' => GetMessage('CRM_FIELD_BANKING_DETAILS'), 'type' => 'textarea', 'params' => array(), 'value' => isset($arResult['ELEMENT']['BANKING_DETAILS']) ? $arResult['ELEMENT']['BANKING_DETAILS'] : ''); // Contacts selector $arResult['FIELDS']['tab_1'][] = array('id' => 'section_contacts', 'name' => GetMessage('CRM_SECTION_CONTACTS'), 'type' => 'section'); if (CCrmContact::CheckReadPermission(0, $userPermissions)) { ob_start(); $GLOBALS['APPLICATION']->IncludeComponent('bitrix:crm.entity.selector', '', array('ENTITY_TYPE' => 'CONTACT', 'INPUT_NAME' => 'CONTACT_ID', 'INPUT_VALUE' => isset($arResult['CONTACT_ID']) ? $arResult['CONTACT_ID'] : '', 'FORM_NAME' => $arResult['FORM_ID'], 'MULTIPLE' => 'Y'), false, array('HIDE_ICONS' => 'Y')); $sVal = ob_get_contents(); ob_end_clean(); $arResult['FIELDS']['tab_1'][] = array('id' => 'CONTACT_ID', 'name' => GetMessage('CRM_FIELD_CONTACT_ID'), 'type' => 'custom', 'wrap' => true, 'value' => $sVal); } $arResult['FIELDS']['tab_1'][] = array('id' => 'section_additional', 'name' => GetMessage('CRM_SECTION_ADDITIONAL'), 'type' => 'section'); $CCrmUserType->AddFields($arResult['FIELDS']['tab_1'], $arResult['ELEMENT']['ID'], $arResult['FORM_ID'], $bConvert ? isset($arParams['~VARS_FROM_FORM']) && $arParams['~VARS_FROM_FORM'] === true : $bVarsFromForm, false, false, array('FILE_URL_TEMPLATE' => "/bitrix/components/bitrix/crm.company.show/show_file.php?ownerId=#owner_id#&fieldName=#field_name#&fileId=#file_id#")); if (IsModuleInstalled('bizproc')) { CBPDocument::AddShowParameterInit('crm', 'only_users', 'COMPANY'); $bizProcIndex = 0; if (!isset($arDocumentStates)) { $arDocumentStates = CBPDocument::GetDocumentStates(array('crm', 'CCrmDocumentCompany', 'COMPANY'), $bEdit ? array('crm', 'CCrmDocumentCompany', 'COMPANY_' . $arResult['ELEMENT']['ID']) : null); } foreach ($arDocumentStates as $arDocumentState) {
$liveFeedHtml = ob_get_contents(); ob_end_clean(); $arResult['ENABLE_LIVE_FEED_LAZY_LOAD'] = false; } else { $liveFeedContainerID = $arResult['LIVE_FEED_CONTAINER_ID'] = $arResult['FORM_ID'] . '_live_feed_wrapper'; $liveFeedHtml = '<div id="' . htmlspecialcharsbx($liveFeedContainerID) . '"></div>'; $arResult['ENABLE_LIVE_FEED_LAZY_LOAD'] = true; } } $arResult['FIELDS']['tab_live_feed'][] = array('id' => 'LIVE_FEED', 'name' => GetMessage('CRM_FIELD_LIVE_FEED'), 'colspan' => true, 'type' => 'custom', 'value' => $liveFeedHtml); // <-- LIVE FEED SECTION $arResult['FIELDS']['tab_activity'][] = array('id' => 'section_activity_grid', 'name' => GetMessage('CRM_SECTION_ACTIVITY_MAIN'), 'type' => 'section'); $arResult['FIELDS']['tab_activity'][] = array('id' => 'DEAL_ACTIVITY_GRID', 'name' => GetMessage('CRM_FIELD_DEAL_ACTIVITY'), 'colspan' => true, 'type' => 'crm_activity_list', 'componentData' => array('template' => 'grid', 'enableLazyLoad' => true, 'params' => array('BINDINGS' => array(array('TYPE_NAME' => 'DEAL', 'ID' => $arParams['ELEMENT_ID'])), 'PREFIX' => 'DEAL_ACTIONS_GRID', 'PERMISSION_TYPE' => 'WRITE', 'ENABLE_NAVIGATION' => 'Y', 'FORM_TYPE' => 'show', 'FORM_ID' => $arResult['FORM_ID'], 'TAB_ID' => 'tab_activity', 'USE_QUICK_FILTER' => 'Y'))); $formTabKey = $arResult['FORM_ID'] . '_active_tab'; $currentFormTabID = $_SERVER['REQUEST_METHOD'] === 'GET' && isset($_GET[$formTabKey]) ? $_GET[$formTabKey] : ''; if ($contactID > 0 && CCrmContact::CheckReadPermission($contactID, $currentUserPermissions)) { $arResult['FIELDS']['tab_contact'][] = array('id' => 'DEAL_CONTACTS', 'name' => GetMessage('CRM_FIELD_DEAL_CONTACTS'), 'colspan' => true, 'type' => 'crm_contact_list', 'componentData' => array('template' => '', 'enableLazyLoad' => true, 'params' => array('CONTACT_COUNT' => '20', 'PATH_TO_CONTACT_SHOW' => $arParams['PATH_TO_CONTACT_SHOW'], 'PATH_TO_CONTACT_EDIT' => $arParams['PATH_TO_CONTACT_EDIT'], 'PATH_TO_DEAL_EDIT' => $arParams['PATH_TO_DEAL_EDIT'], 'INTERNAL_FILTER' => array('ID' => $contactID), 'GRID_ID_SUFFIX' => 'DEAL_SHOW', 'FORM_ID' => $arResult['FORM_ID'], 'TAB_ID' => 'tab_contact'))); } if ($companyID > 0 && CCrmCompany::CheckReadPermission($companyID, $currentUserPermissions)) { $arResult['FIELDS']['tab_company'][] = array('id' => 'DEAL_COMPANY', 'name' => GetMessage('CRM_FIELD_DEAL_COMPANY'), 'colspan' => true, 'type' => 'crm_company_list', 'componentData' => array('template' => '', 'enableLazyLoad' => true, 'params' => array('COMPANY_COUNT' => '20', 'PATH_TO_COMPANY_SHOW' => $arParams['PATH_TO_COMPANY_SHOW'], 'PATH_TO_COMPANY_EDIT' => $arParams['PATH_TO_COMPANY_EDIT'], 'PATH_TO_CONTACT_EDIT' => $arParams['PATH_TO_CONTACT_EDIT'], 'PATH_TO_DEAL_EDIT' => $arParams['PATH_TO_DEAL_EDIT'], 'INTERNAL_FILTER' => array('ID' => $companyID), 'GRID_ID_SUFFIX' => 'DEAL_SHOW', 'FORM_ID' => $arResult['FORM_ID'], 'TAB_ID' => 'tab_company', 'NAME_TEMPLATE' => $arParams['NAME_TEMPLATE']))); } if (!$CCrmDeal->cPerms->HavePerm('QUOTE', BX_CRM_PERM_NONE, 'READ')) { $arResult['FIELDS']['tab_quote'][] = array('id' => 'DEAL_QUOTE', 'name' => GetMessage('CRM_FIELD_DEAL_QUOTE'), 'colspan' => true, 'type' => 'crm_quote_list', 'componentData' => array('template' => '', 'enableLazyLoad' => true, 'params' => array('QUOTE_COUNT' => '20', 'PATH_TO_QUOTE_SHOW' => $arResult['PATH_TO_QUOTE_SHOW'], 'PATH_TO_QUOTE_EDIT' => $arResult['PATH_TO_QUOTE_EDIT'], 'INTERNAL_FILTER' => array('DEAL_ID' => $arResult['ELEMENT']['ID']), 'INTERNAL_CONTEXT' => array('DEAL_ID' => $arResult['ELEMENT']['ID']), 'GRID_ID_SUFFIX' => 'DEAL_SHOW', 'FORM_ID' => $arResult['FORM_ID'], 'TAB_ID' => 'tab_quote', 'NAME_TEMPLATE' => $arParams['NAME_TEMPLATE'], 'ENABLE_TOOLBAR' => true))); } if (!$CCrmDeal->cPerms->HavePerm('INVOICE', BX_CRM_PERM_NONE, 'READ')) { $arResult['FIELDS']['tab_invoice'][] = array('id' => 'DEAL_INVOICE', 'name' => GetMessage('CRM_FIELD_DEAL_INVOICE'), 'colspan' => true, 'type' => 'crm_invoice_list', 'componentData' => array('template' => '', 'enableLazyLoad' => true, 'params' => array('INVOICE_COUNT' => '20', 'PATH_TO_COMPANY_SHOW' => $arParams['PATH_TO_COMPANY_SHOW'], 'PATH_TO_COMPANY_EDIT' => $arParams['PATH_TO_COMPANY_EDIT'], 'PATH_TO_CONTACT_EDIT' => $arParams['PATH_TO_CONTACT_EDIT'], 'PATH_TO_DEAL_EDIT' => $arParams['PATH_TO_DEAL_EDIT'], 'PATH_TO_INVOICE_EDIT' => $arParams['PATH_TO_INVOICE_EDIT'], 'PATH_TO_INVOICE_PAYMENT' => $arParams['PATH_TO_INVOICE_PAYMENT'], 'INTERNAL_FILTER' => array('UF_DEAL_ID' => $arResult['ELEMENT']['ID']), 'SUM_PAID_CURRENCY' => $currencyID, 'GRID_ID_SUFFIX' => 'DEAL_SHOW', 'FORM_ID' => $arResult['FORM_ID'], 'TAB_ID' => 'tab_invoice', 'NAME_TEMPLATE' => $arParams['NAME_TEMPLATE'], 'ENABLE_TOOLBAR' => 'Y', 'INTERNAL_ADD_BTN_TITLE' => GetMessage('CRM_DEAL_ADD_INVOICE_TITLE')))); } if (IsModuleInstalled('bizproc') && CModule::IncludeModule('bizproc')) { //HACK: main.interface.grid may override current tab if ($_SERVER['REQUEST_METHOD'] === 'GET' && $currentFormTabID !== '') { $_GET[$formTabKey] = $currentFormTabID;
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); }
$arResult['FIELDS']['tab_1'][] = array('id' => 'PAY_VOUCHER_NUM', 'name' => GetMessage('CRM_FIELD_PAY_VOUCHER_NUM'), 'type' => 'label', 'value' => isset($arResult['ELEMENT']['PAY_VOUCHER_NUM']) ? $arResult['ELEMENT']['PAY_VOUCHER_NUM'] : '', 'visible' => $bStatusSuccess, 'isTactile' => true); $arResult['FIELDS']['tab_1'][] = array('id' => 'REASON_MARKED_SUCCESS', 'name' => GetMessage('CRM_FIELD_REASON_MARKED_SUCCESS'), 'value' => isset($arResult['ELEMENT']['REASON_MARKED_SUCCESS']) ? $arResult['ELEMENT']['REASON_MARKED_SUCCESS'] : '', 'type' => 'label', 'visible' => $bStatusSuccess, 'isTactile' => true); $arResult['FIELDS']['tab_1'][] = array('id' => 'DATE_MARKED', 'name' => GetMessage('CRM_FIELD_DATE_MARKED'), 'type' => 'label', 'value' => !empty($arResult['ELEMENT']['DATE_MARKED']) ? CCrmComponentHelper::TrimDateTimeString(ConvertTimeStamp(MakeTimeStamp($arResult['ELEMENT']['DATE_MARKED']), 'SHORT', SITE_ID)) : '', 'visible' => $bStatusFailed, 'isTactile' => true); $arResult['FIELDS']['tab_1'][] = array('id' => 'REASON_MARKED', 'name' => GetMessage('CRM_FIELD_REASON_MARKED'), 'value' => isset($arResult['ELEMENT']['REASON_MARKED']) ? $arResult['ELEMENT']['REASON_MARKED'] : '', 'type' => 'label', 'visible' => $bStatusFailed, 'isTactile' => true); $arResult['FIELDS']['tab_1'][] = array('id' => 'DATE_BILL', 'name' => GetMessage('CRM_FIELD_DATE_BILL'), 'type' => 'label', 'value' => !empty($arResult['ELEMENT']['DATE_BILL']) ? CCrmComponentHelper::TrimDateTimeString(ConvertTimeStamp(MakeTimeStamp($arResult['ELEMENT']['DATE_BILL']), 'SHORT', SITE_ID)) : '', 'isTactile' => true); $arResult['FIELDS']['tab_1'][] = array('id' => 'DATE_PAY_BEFORE', 'name' => GetMessage('CRM_FIELD_DATE_PAY_BEFORE'), 'type' => 'label', 'value' => !empty($arResult['ELEMENT']['DATE_PAY_BEFORE']) ? CCrmComponentHelper::TrimDateTimeString(ConvertTimeStamp(MakeTimeStamp($arResult['ELEMENT']['DATE_PAY_BEFORE']), 'SHORT', SITE_ID)) : '', 'isTactile' => true); $arResult['FIELDS']['tab_1'][] = array('id' => 'RESPONSIBLE_ID', 'name' => GetMessage('CRM_FIELD_RESPONSIBLE_ID'), 'type' => 'custom', 'value' => isset($arResult['ELEMENT']['RESPONSIBLE_ID']) ? CCrmViewHelper::PrepareFormResponsible($arResult['ELEMENT']['RESPONSIBLE_ID'], $arParams['NAME_TEMPLATE'], $arParams['PATH_TO_USER_PROFILE']) : '', 'isTactile' => true); $arResult['FIELDS']['tab_1'][] = array('id' => 'CURRENCY_ID', 'name' => GetMessage('CRM_FIELD_CURRENCY_ID'), 'params' => array('size' => 50), 'type' => 'label', 'value' => htmlspecialcharsbx(isset($arResult['CURRENCY_LIST'][$currencyID]) ? $arResult['CURRENCY_LIST'][$currencyID] : $currencyID), 'isTactile' => true); $arResult['FIELDS']['tab_1'][] = array('id' => 'UF_DEAL_ID', 'name' => GetMessage('CRM_FIELD_UF_DEAL_ID'), 'value' => isset($arResult['ELEMENT']['UF_DEAL_TITLE']) ? !CCrmDeal::CheckReadPermission($dealID) ? htmlspecialcharsbx($arResult['ELEMENT']['UF_DEAL_TITLE']) : '<a href="' . $arResult['PATH_TO_DEAL_SHOW'] . '" id="balloon_' . $arResult['GRID_ID'] . '_D_' . $dealID . '">' . htmlspecialcharsbx($arResult['ELEMENT']['UF_DEAL_TITLE']) . '</a>' . '<script type="text/javascript">BX.tooltip("DEAL_' . $dealID . '", "balloon_' . $arResult['GRID_ID'] . '_D_' . $dealID . '", "/bitrix/components/bitrix/crm.deal.show/card.ajax.php", "crm_balloon_deal", true);</script>' : GetMessage('CRM_INVOICE_DEAL_NOT_ASSIGNED'), 'type' => 'custom', 'isTactile' => true); $arResult['FIELDS']['tab_1'][] = array('id' => 'UF_QUOTE_ID', 'name' => GetMessage('CRM_FIELD_UF_QUOTE_ID'), 'value' => isset($arResult['ELEMENT']['UF_QUOTE_TITLE']) ? !CCrmQuote::CheckReadPermission($quoteID) ? htmlspecialcharsbx($arResult['ELEMENT']['UF_QUOTE_TITLE']) : '<a href="' . $arResult['PATH_TO_QUOTE_SHOW'] . '" id="balloon_' . $arResult['GRID_ID'] . '_Q_' . $quoteID . '">' . htmlspecialcharsbx($arResult['ELEMENT']['UF_QUOTE_TITLE']) . '</a>' . '<script type="text/javascript">BX.tooltip("QUOTE_' . $quoteID . '", "balloon_' . $arResult['GRID_ID'] . '_Q_' . $quoteID . '", "/bitrix/components/bitrix/crm.quote.show/card.ajax.php", "crm_balloon_quote", true);</script>' : GetMessage('CRM_INVOICE_QUOTE_NOT_ASSIGNED'), 'type' => 'custom', 'isTactile' => true); $arResult['FIELDS']['tab_1'][] = array('id' => 'section_invoice_payer', 'name' => GetMessage('CRM_SECTION_INVOICE_PAYER'), 'type' => 'section', 'isTactile' => true); $clientField = array('id' => 'CLIENT_ID', 'name' => GetMessage('CRM_FIELD_CLIENT_ID'), 'value' => '', 'type' => 'custom', 'isTactile' => true); $contactHtml = ''; if ($contactID > 0) { $formattedName = isset($arResult['ELEMENT']['UF_CONTACT_FORMATTED_NAME']) ? htmlspecialcharsbx($arResult['ELEMENT']['UF_CONTACT_FORMATTED_NAME']) : ''; $contactHtml = $formattedName !== '' ? !CCrmContact::CheckReadPermission($contactID) ? $formattedName : '<a href="' . $arResult['PATH_TO_CONTACT_SHOW'] . '" id="balloon_' . $arResult['GRID_ID'] . '_C_' . $contactID . '">' . $formattedName . '</a>' . '<script type="text/javascript">BX.tooltip("CONTACT_' . $contactID . '", "balloon_' . $arResult['GRID_ID'] . '_C_' . $contactID . '", "' . SITE_DIR . 'bitrix/components/bitrix/crm.contact.show/card.ajax.php", "crm_balloon_contact", true);</script>' : ''; } if ($companyID > 0) { $title = isset($arResult['ELEMENT']['UF_COMPANY_TITLE']) ? htmlspecialcharsbx($arResult['ELEMENT']['UF_COMPANY_TITLE']) : ''; $clientField['value'] = $title !== '' ? !CCrmCompany::CheckReadPermission($companyID) ? $title : '<a href="' . $arResult['PATH_TO_COMPANY_SHOW'] . '" id="balloon_' . $arResult['GRID_ID'] . '_CO_' . $companyID . '">' . $title . '</a>' . '<script type="text/javascript">BX.tooltip("COMPANY_' . $companyID . '", "balloon_' . $arResult['GRID_ID'] . '_CO_' . $companyID . '", "' . SITE_DIR . 'bitrix/components/bitrix/crm.company.show/card.ajax.php", "crm_balloon_company", true);</script>' : GetMessage('CRM_INVOICE_CLIENT_NOT_ASSIGNED'); } elseif ($contactID > 0) { $clientField['value'] = $contactHtml !== '' ? $contactHtml : GetMessage('CRM_INVOICE_CLIENT_NOT_ASSIGNED'); } $arResult['FIELDS']['tab_1'][] =& $clientField; unset($clientField); $arResult['FIELDS']['tab_1'][] = array('id' => 'UF_CONTACT_ID', 'name' => GetMessage('CRM_FIELD_CONTACT_PERSON_ID'), 'value' => '', 'type' => 'custom', 'value' => $contactHtml !== '' ? $contactHtml : GetMessage('CRM_INVOICE_CONTACT_PERSON_NOT_ASSIGNED'), 'isTactile' => true, 'visible' => $companyID > 0); $arResult['FIELDS']['tab_1'][] = array('id' => 'LOCATION_ID', 'name' => GetMessage('CRM_FIELD_LOCATION'), 'params' => array('size' => 50), 'type' => 'label', 'value' => $bTaxMode && isset($arResult['ELEMENT']['PR_LOCATION']) ? CCrmLocations::getLocationString($arResult['ELEMENT']['PR_LOCATION']) : '', 'isTactile' => true, 'visible' => $bTaxMode); $arResult['FIELDS']['tab_1'][] = array('id' => 'PAYER_INFO', 'name' => GetMessage('CRM_FIELD_PAYER_INFO'), 'type' => 'label', 'value' => isset($arResult['ELEMENT']['PAYER_INFO']) ? $arResult['ELEMENT']['PAYER_INFO'] : '', 'isTactile' => true); $arResult['FIELDS']['tab_1'][] = array('id' => 'section_pay_system', 'name' => GetMessage('CRM_SECTION_PAY_SYSTEM'), 'type' => 'section', 'isTactile' => true); $arResult['FIELDS']['tab_1'][] = array('id' => 'PAY_SYSTEM_ID', 'name' => GetMessage('CRM_FIELD_PAY_SYSTEM_ID'), 'type' => 'label', 'value' => isset($arResult['ELEMENT']['PAY_SYSTEM_NAME']) ? $arResult['ELEMENT']['PAY_SYSTEM_NAME'] : '', 'isTactile' => true); $arResult['FIELDS']['tab_1'][] = array('id' => 'section_comments', 'name' => GetMessage('CRM_SECTION_COMMENTS'), 'type' => 'section', 'isTactile' => true);
} $enablePayerInfo = isset($data['ENABLE_PAYER_INFO']) ? strtoupper($data['ENABLE_PAYER_INFO']) === "Y" : false; $enableProductRows = isset($data['ENABLE_PRODUCT_ROWS']) ? strtoupper($data['ENABLE_PRODUCT_ROWS']) === "Y" : false; $productRows = $enableProductRows && isset($data['PRODUCT_ROWS']) && is_array($data['PRODUCT_ROWS']) ? $data['PRODUCT_ROWS'] : array(); $productRowQty = count($productRows); //Save initial row's order for ($i = 0; $i < $productRowQty; $i++) { $productRows[$i]['IDX'] = $i; } $ID = isset($data['ID']) ? intval($data['ID']) : 0; $companyID = isset($data['COMPANY_ID']) ? intval($data['COMPANY_ID']) : 0; if ($companyID > 0 && !CCrmCompany::CheckReadPermission($companyID, $curUserPrems)) { $companyID = 0; } $contactID = isset($data['CONTACT_ID']) ? intval($data['CONTACT_ID']) : 0; if ($contactID > 0 && !CCrmContact::CheckReadPermission($contactID, $curUserPrems)) { $contactID = 0; } $personTypeID = isset($data['PERSON_TYPE_ID']) ? intval($data['PERSON_TYPE_ID']) : 0; $resolvedPersonTypeID = $companyID > 0 || $contactID > 0 ? CCrmInvoice::ResolvePersonTypeID($companyID, $contactID) : 0; $paySystemID = isset($data['PAY_SYSTEM_ID']) ? intval($data['PAY_SYSTEM_ID']) : 0; $paySystems = CCrmPaySystem::GetPaySystemsListItems($resolvedPersonTypeID); $resolvedPaySystemID = 0; if ($personTypeID === $resolvedPersonTypeID && $paySystemID > 0 && array_key_exists($paySystemID, $paySystems)) { // Pay system does not changed $resolvedPaySystemID = $paySystemID; } elseif (!empty($paySystems)) { // Take first pay system $resolvedPaySystemID = array_shift(array_keys($paySystems)); } $arFields = array('ID' => $ID, 'PRODUCT_ROWS' => $productRows, 'PAY_SYSTEM_ID' => $resolvedPaySystemID, 'PERSON_TYPE_ID' => $resolvedPersonTypeID);
} } else { $ID = $CrmContact->Add($arFields, true, array('DISABLE_USER_FIELD_CHECK' => true, 'REGISTER_SONET_EVENT' => true)); if (is_int($ID) && $ID > 0) { $data['id'] = $ID; $info = CCrmEntitySelectorHelper::PrepareEntityInfo('CONTACT', $ID, array('NAME_TEMPLATE' => isset($_POST['NAME_TEMPLATE']) ? $_POST['NAME_TEMPLATE'] : '')); echo CUtil::PhpToJSObject(array('DATA' => $data, 'INFO' => array('title' => $info['TITLE'], 'url' => $info['URL']))); } else { echo CUtil::PhpToJSObject(array('ERROR' => $CrmContact->LAST_ERROR)); } } } elseif ($action === 'ENABLE_SONET_SUBSCRIPTION') { $userID = CCrmSecurityHelper::GetCurrentUserID(); $entityTypeName = isset($_POST['ENTITY_TYPE']) ? strtoupper($_POST['ENTITY_TYPE']) : ''; $entityID = isset($_POST['ENTITY_ID']) ? intval($_POST['ENTITY_ID']) : 0; if ($userID > 0 && $entityTypeName === CCrmOwnerType::ContactName && $entityID > 0 && CCrmContact::CheckReadPermission($entityID)) { $isEnabled = CCrmSonetSubscription::IsRelationRegistered(CCrmOwnerType::Contact, $entityID, CCrmSonetSubscriptionType::Observation, $userID); $enable = isset($_POST['ENABLE']) && strtoupper($_POST['ENABLE']) === 'Y'; if ($isEnabled !== $enable) { if ($enable) { CCrmSonetSubscription::RegisterSubscription(CCrmOwnerType::Contact, $entityID, CCrmSonetSubscriptionType::Observation, $userID); } else { CCrmSonetSubscription::UnRegisterSubscription(CCrmOwnerType::Contact, $entityID, CCrmSonetSubscriptionType::Observation, $userID); } } } } elseif ($action === 'FIND_DUPLICATES') { $userPermissions = CCrmPerms::GetCurrentUserPermissions(); $params = isset($_POST['PARAMS']) && is_array($_POST['PARAMS']) ? $_POST['PARAMS'] : array(); $entityTypeName = isset($params['ENTITY_TYPE_NAME']) ? $params['ENTITY_TYPE_NAME'] : ''; if ($entityTypeName === '') {