// current page index $arResult['PAGE_NAVCOUNT'] = intval($dbRes->NavPageCount); // page count $arResult['PAGER_PARAM'] = "PAGEN_{$arResult['PAGE_NAVNUM']}"; $arResult['PAGE_NEXT_NUMBER'] = $arResult['PAGE_NUMBER'] + 1; while ($item = $dbRes->GetNext()) { CCrmMobileHelper::PrepareContactItem($item, $arParams); $arResult['ITEMS'][] =& $item; unset($item); } //NEXT_PAGE_URL, SEARCH_PAGE_URL, SERVICE_URL --> if ($arResult['PAGE_NEXT_NUMBER'] > $arResult['PAGE_NAVCOUNT']) { $arResult['NEXT_PAGE_URL'] = ''; } elseif ($companyID > 0) { $arResult['NEXT_PAGE_URL'] = $APPLICATION->GetCurPageParam('AJAX_CALL=Y&PAGING=Y&FORMAT=json&company_id=' . $companyID . '&' . $arResult['PAGER_PARAM'] . '=' . $arResult['PAGE_NEXT_NUMBER'], array('AJAX_CALL', 'PAGING', 'FORMAT', 'SEARCH', 'company_id', $arResult['PAGER_PARAM'])); } else { $arResult['NEXT_PAGE_URL'] = $APPLICATION->GetCurPageParam('AJAX_CALL=Y&PAGING=Y&FORMAT=json&SEARCH=' . ($enableSearch ? 'Y' : 'N') . '&' . $arResult['PAGER_PARAM'] . '=' . $arResult['PAGE_NEXT_NUMBER'], array('AJAX_CALL', 'PAGING', 'FORMAT', 'SEARCH', $arResult['PAGER_PARAM'])); } $arResult['SEARCH_PAGE_URL'] = $APPLICATION->GetCurPageParam('AJAX_CALL=Y&SEARCH=Y&FORMAT=json&apply_filter=Y&save=Y', array('AJAX_CALL', 'SEARCH', 'FORMAT', 'save', 'apply_filter', 'clear_filter')); $serviceURLTemplate = $arParams["SERVICE_URL_TEMPLATE"] ? $arParams["SERVICE_URL_TEMPLATE"] : '#SITE_DIR#bitrix/components/bitrix/mobile.crm.contact.edit/ajax.php?site_id=#SITE#&sessid=#SID#'; $arResult['SERVICE_URL'] = CComponentEngine::makePathFromTemplate($serviceURLTemplate, array('SID' => bitrix_sessid())); //<-- NEXT_PAGE_URL, SEARCH_PAGE_URL, SERVICE_URL $arResult['PERMISSIONS'] = array('CREATE' => CCrmContact::CheckCreatePermission()); $arResult['CREATE_URL'] = $arParams['CONTACT_EDIT_URL_TEMPLATE'] !== '' ? CComponentEngine::makePathFromTemplate($arParams['CONTACT_EDIT_URL_TEMPLATE'], array('contact_id' => 0, 'company_id' => $companyID)) : ''; $arResult['RELOAD_URL'] = $APPLICATION->GetCurPageParam('AJAX_CALL=Y&FORMAT=json', array('AJAX_CALL', 'SEARCH', 'FORMAT', 'save', 'apply_filter', 'clear_filter')); $format = isset($_REQUEST['FORMAT']) ? strtolower($_REQUEST['FORMAT']) : ''; // Only JSON format is supported if ($format !== '' && $format !== 'json') { $format = ''; } $this->IncludeComponentTemplate($format);
die; } } if (CModule::IncludeModule('compression')) { CCompress::Disable2048Spaces(); } CUtil::JSPostUnescape(); if (!CModule::IncludeModule('crm')) { __CrmMobileFileEndResonse(array('error' => 'Could not include "crm" module.')); } if (!(check_bitrix_sessid() && CCrmSecurityHelper::IsAuthorized())) { __CrmMobileFileEndResonse(array('error' => 'Access denied.')); } global $APPLICATION; if ($_SERVER['REQUEST_METHOD'] === 'POST' && is_array($_FILES) && !empty($_FILES)) { $ID = isset($_REQUEST['id']) ? intval($_REQUEST['id']) : 0; $hasPermission = $ID > 0 ? CCrmContact::CheckUpdatePermission($ID) : CCrmContact::CheckCreatePermission(); if (!$hasPermission) { __CrmMobileFileEndResonse(array('error' => 'Access denied.')); } else { $result = array(); if (!CCrmMobileHelper::TryUploadFile($result, array('OWNER_TYPE_ID' => CCrmOwnerType::Contact, 'OWNER_ID' => $ID, 'SCOPE' => 'I', 'MAX_FILE_SIZE' => 5242880))) { __CrmMobileFileEndResonse(array('error' => $result['ERROR_MESSAGE'])); } else { $fileID = $result['FILE_ID']; $fileInfo = CFile::ResizeImageGet($fileID, array('width' => 55, 'height' => 55), BX_RESIZE_IMAGE_EXACT, false, false, true); __CrmMobileFileEndResonse(array('fileId' => $fileID, 'showUrl' => is_array($fileInfo) && isset($fileInfo['src']) ? $fileInfo['src'] : '')); } } } require_once $_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/main/include/epilog_after.php';
$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; $arResult['FORM_FIELDS_TO_ADD']['LOCATION_ID'] = $locationField;
$arParams['PATH_TO_CONTACT_EDIT'] = CrmCheckPath('PATH_TO_CONTACT_EDIT', $arParams['PATH_TO_CONTACT_EDIT'], $APPLICATION->GetCurPage() . '?contact_id=#contact_id#&edit'); $arParams['PATH_TO_USER_PROFILE'] = CrmCheckPath('PATH_TO_USER_PROFILE', $arParams['PATH_TO_USER_PROFILE'], '/company/personal/user/#user_id#/'); $arParams['NAME_TEMPLATE'] = empty($arParams['NAME_TEMPLATE']) ? CSite::GetNameFormat(false) : str_replace(array("#NOBR#", "#/NOBR#"), array("", ""), $arParams["NAME_TEMPLATE"]); $arParams['ELEMENT_ID'] = isset($arParams['ELEMENT_ID']) ? (int) $arParams['ELEMENT_ID'] : 0; $isEditMode = false; $isCopyMode = false; $varsFromForm = false; if ($arParams['ELEMENT_ID'] > 0) { $isEditMode = true; } if (!empty($_REQUEST['copy'])) { $isCopyMode = true; $isEditMode = false; } $isConverting = isset($arParams['CONVERT']) && $arParams['CONVERT']; $isPermitted = $isEditMode ? CCrmContact::CheckUpdatePermission($arParams['ELEMENT_ID'], $userPermissions) : CCrmContact::CheckCreatePermission($userPermissions); if (!$isPermitted) { ShowError(GetMessage('CRM_PERMISSION_DENIED')); return; } $arEntityAttr = $arParams['ELEMENT_ID'] > 0 ? $userPermissions->GetEntityAttr('CONTACT', array($arParams['ELEMENT_ID'])) : array(); $isInternal = false; if (isset($arParams['INTERNAL_FILTER']) && !empty($arParams['INTERNAL_FILTER'])) { $isInternal = true; } $arResult['INTERNAL'] = $isInternal; if ($isEditMode || $isCopyMode) { $obFields = CCrmContact::GetListEx(array(), array('=ID' => $arParams['ELEMENT_ID'], 'CHECK_PERMISSIONS' => 'N')); $arFields = is_object($obFields) ? $obFields->GetNext() : false; if ($arFields === false) { $isEditMode = false;
public static function GetEditUrl($typeID, $ID, $bCheckPermissions = false) { $typeID = intval($typeID); $ID = intval($ID); if ($ID <= 0) { $ID = 0; } switch ($typeID) { case self::Lead: if ($bCheckPermissions && !($ID > 0 ? CCrmLead::CheckUpdatePermission($ID) : CCrmLead::CheckCreatePermission())) { return ''; } return CComponentEngine::MakePathFromTemplate(COption::GetOptionString('crm', 'path_to_lead_edit'), array('lead_id' => $ID)); case self::Contact: if ($bCheckPermissions && !($ID > 0 ? CCrmContact::CheckUpdatePermission($ID) : CCrmContact::CheckCreatePermission())) { return ''; } return CComponentEngine::MakePathFromTemplate(COption::GetOptionString('crm', 'path_to_contact_edit'), array('contact_id' => $ID)); case self::Company: if ($bCheckPermissions && !($ID > 0 ? CCrmCompany::CheckUpdatePermission($ID) : CCrmCompany::CheckCreatePermission())) { return ''; } return CComponentEngine::MakePathFromTemplate(COption::GetOptionString('crm', 'path_to_company_edit'), array('company_id' => $ID)); case self::Deal: if ($bCheckPermissions && !($ID > 0 ? CCrmDeal::CheckUpdatePermission($ID) : CCrmDeal::CheckCreatePermission())) { return ''; } return CComponentEngine::MakePathFromTemplate(COption::GetOptionString('crm', 'path_to_deal_edit'), array('deal_id' => $ID)); case self::Invoice: if ($bCheckPermissions && !($ID > 0 ? CCrmInvoice::CheckUpdatePermission($ID) : CCrmInvoice::CheckCreatePermission())) { return ''; } return CComponentEngine::MakePathFromTemplate(COption::GetOptionString('crm', 'path_to_invoice_edit'), array('invoice_id' => $ID)); case self::Quote: if ($bCheckPermissions && !($ID > 0 ? CCrmQuote::CheckUpdatePermission($ID) : CCrmQuote::CheckCreatePermission())) { return ''; } return CComponentEngine::MakePathFromTemplate(COption::GetOptionString('crm', 'path_to_quote_edit'), array('quote_id' => $ID)); case self::Activity: return CComponentEngine::MakePathFromTemplate(COption::GetOptionString('crm', 'path_to_activity_edit'), array('activity_id' => $ID)); default: return ''; } }
public static function GetDataForPopup($callId, $phone, $userId = 0) { if (strlen($phone) <= 0 || !CModule::IncludeModule('crm')) { return false; } if ($userId > 0) { $findParams = array('USER_ID' => $userId); } else { $findParams = array('ENABLE_EXTENDED_MODE' => false); } $crm = CCrmSipHelper::findByPhoneNumber((string) $phone, $findParams); if ($crm) { $dealStatuses = CCrmViewHelper::GetDealStageInfos(); $entity = ''; $entityData = array(); $entities = array(); $arResult = array('FOUND' => 'Y', 'CONTACT' => array(), 'COMPANY' => array(), 'ACTIVITIES' => array(), 'DEALS' => array(), 'RESPONSIBILITY' => array()); if (isset($crm['CONTACT'])) { $entity = 'CONTACT'; $entityData = $crm[$entity][0]; $arResult['CONTACT'] = array('NAME' => $entityData['FORMATTED_NAME'], 'POST' => $entityData['POST'], 'PHOTO' => ''); if (intval($entityData['PHOTO']) > 0) { $arPhoto = CFile::ResizeImageGet($entityData['PHOTO'], array('width' => 37, 'height' => 37), BX_RESIZE_IMAGE_EXACT, false, false, true); $arResult['CONTACT']['PHOTO'] = $arPhoto['src']; } $arResult['COMPANY'] = $entityData['COMPANY_TITLE']; $arResult['CONTACT_DATA'] = array('ID' => $entityData['ID']); } else { if (isset($crm['LEAD'])) { $entity = 'LEAD'; $entityData = $crm[$entity][0]; $arResult['CONTACT'] = array('ID' => 0, 'NAME' => !empty($entityData['FORMATTED_NAME']) ? $entityData['FORMATTED_NAME'] : $entityData['TITLE'], 'POST' => $entityData['POST'], 'PHOTO' => ''); $arResult['COMPANY'] = $entityData['COMPANY_TITLE']; $arResult['LEAD_DATA'] = array('ID' => $entityData['ID'], 'ASSIGNED_BY_ID' => $entityData['ASSIGNED_BY_ID']); } else { if (isset($crm['COMPANY'])) { $entity = 'COMPANY'; $entityData = $crm[$entity][0]; $arResult['COMPANY'] = $entityData['TITLE']; $arResult['COMPANY_DATA'] = array('ID' => $entityData['ID']); } } } if ($entityData['ASSIGNED_BY_ID'] > 0) { $ar = Bitrix\Main\UserTable::getById($entityData['ASSIGNED_BY_ID']); if ($user = $ar->fetch()) { $arPhoto = CFile::ResizeImageGet($user['PERSONAL_PHOTO'], array('width' => 37, 'height' => 37), BX_RESIZE_IMAGE_EXACT, false, false, true); $arResult['RESPONSIBILITY'] = array('ID' => $user['ID'], 'NAME' => CUser::FormatName(CSite::GetNameFormat(false), $user, true, false), 'PHOTO' => $arPhoto ? $arPhoto['src'] : '', 'POST' => $user['WORK_POSITION']); } } if (isset($entityData['SHOW_URL'])) { $arResult['SHOW_URL'] = $entityData['SHOW_URL']; } if (isset($entityData['ACTIVITY_LIST_URL'])) { $arResult['ACTIVITY_URL'] = $entityData['ACTIVITY_LIST_URL']; } if (isset($entityData['INVOICE_LIST_URL'])) { $arResult['INVOICE_URL'] = $entityData['INVOICE_LIST_URL']; } if (isset($entityData['DEAL_LIST_URL'])) { $arResult['DEAL_URL'] = $entityData['DEAL_LIST_URL']; } $activityId = CCrmActivity::GetIDByOrigin('VI_' . $callId); if ($activityId) { $arResult['CURRENT_CALL_URL'] = CCrmOwnerType::GetEditUrl(CCrmOwnerType::Activity, $activityId); if ($arResult['CURRENT_CALL_URL'] !== '') { $arResult['CURRENT_CALL_URL'] = CCrmUrlUtil::AddUrlParams($arResult['CURRENT_CALL_URL'], array("disable_storage_edit" => 'Y')); } } if (isset($crm['CONTACT']) && isset($crm['COMPANY'])) { $entities = array('CONTACT', 'COMPANY', 'LEAD'); } else { if (isset($crm['CONTACT']) && isset($crm['LEAD']) && !isset($crm['COMPANY'])) { $entities = array('CONTACT', 'LEAD'); } else { if (isset($crm['LEAD']) && isset($crm['COMPANY']) && !isset($crm['CONTACT'])) { $entities = array('LEAD', 'COMPANY'); } else { $entities = array($entity); } } } foreach ($entities as $entity) { if (isset($crm[$entity][0]['ACTIVITIES'])) { foreach ($crm[$entity][0]['ACTIVITIES'] as $activity) { if ($activity['ID'] == $activityId) { continue; } $overdue = 'N'; if (strlen($activity['DEADLINE']) > 0 && MakeTimeStamp($activity['DEADLINE']) < time()) { $overdue = 'Y'; } $arResult['ACTIVITIES'][$activity['ID']] = array('TITLE' => $activity['SUBJECT'], 'DATE' => strlen($activity['DEADLINE']) > 0 ? $activity['DEADLINE'] : $activity['END_TIME'], 'OVERDUE' => $overdue, 'URL' => $activity['SHOW_URL']); } if (!empty($arResult['ACTIVITIES'])) { $arResult['ACTIVITIES'] = array_values($arResult['ACTIVITIES']); } } if (isset($crm[$entity][0]['DEALS'])) { foreach ($crm[$entity][0]['DEALS'] as $deal) { $opportunity = CCrmCurrency::MoneyToString($deal['OPPORTUNITY'], $deal['CURRENCY_ID']); if (strpos('&', $opportunity)) { $opportunity = CCrmCurrency::MoneyToString($deal['OPPORTUNITY'], $deal['CURRENCY_ID'], '#') . ' ' . $deal['CURRENCY_ID']; } $opportunity = str_replace('.00', '', $opportunity); $arResult['DEALS'][$deal['ID']] = array('ID' => $deal['ID'], 'TITLE' => $deal['TITLE'], 'STAGE' => $dealStatuses[$deal['STAGE_ID']]['NAME'], 'STAGE_COLOR' => $dealStatuses[$deal['STAGE_ID']]['COLOR'] ? $dealStatuses[$deal['STAGE_ID']]['COLOR'] : "#5fa0ce", 'OPPORTUNITY' => $opportunity, 'URL' => $deal['SHOW_URL']); } if (!empty($arResult['DEALS'])) { $arResult['DEALS'] = array_values($arResult['DEALS']); } } } } else { $arResult = array('FOUND' => 'N'); $userPermissions = CCrmPerms::GetUserPermissions($userId); if (CCrmLead::CheckCreatePermission($userPermissions)) { $arResult['LEAD_URL'] = CCrmOwnerType::GetEditUrl(CCrmOwnerType::Lead, 0); if ($arResult['LEAD_URL'] !== '') { $arResult['LEAD_URL'] = CCrmUrlUtil::AddUrlParams($arResult['LEAD_URL'], array("phone" => (string) $phone, 'origin_id' => 'VI_' . $callId)); } } if (CCrmContact::CheckCreatePermission($userPermissions)) { $arResult['CONTACT_URL'] = CCrmOwnerType::GetEditUrl(CCrmOwnerType::Contact, 0); if ($arResult['CONTACT_URL'] !== '') { $arResult['CONTACT_URL'] = CCrmUrlUtil::AddUrlParams($arResult['CONTACT_URL'], array("phone" => (string) $phone, 'origin_id' => 'VI_' . $callId)); } } } return $arResult; }
} $curUserPrems = CCrmPerms::GetCurrentUserPermissions(); $action = isset($_REQUEST['ACTION']) ? $_REQUEST['ACTION'] : ''; if ($action === 'SAVE_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)))); } $data = isset($_REQUEST['ENTITY_DATA']) && is_array($_REQUEST['ENTITY_DATA']) ? $_REQUEST['ENTITY_DATA'] : array(); if (count($data) == 0) { __CrmMobileContactEditEndResonse(array('ERROR' => GetMessage('CRM_ENTITY_DATA_NOT_FOUND'))); } $ID = isset($data['ID']) ? intval($data['ID']) : 0; $isNew = $ID <= 0; $hasPermission = $isNew ? CCrmContact::CheckCreatePermission() : CCrmContact::CheckUpdatePermission($ID); if (!$hasPermission) { __CrmMobileContactEditEndResonse(array('ERROR' => GetMessage('CRM_ACCESS_DENIED'))); } $currentItem = null; if (!$isNew) { $dbRes = CCrmContact::GetListEx(array(), array('=ID' => $ID, 'CHECK_PERMISSIONS' => 'N')); $currentItem = $dbRes->GetNext(); if (!is_array($currentItem)) { __CrmMobileContactEditEndResonse(array('ERROR' => GetMessage('CRM_CONTACT_NOT_FOUND', array('#ID#' => $ID)))); } } $name = isset($data['NAME']) ? $data['NAME'] : ''; $lastName = isset($data['LAST_NAME']) ? $data['LAST_NAME'] : ''; if ($name === '' && $lastName === '') { __CrmMobileContactEditEndResonse(array('ERROR' => GetMessage('CRM_CONTACT_NAME_NOT_ASSIGNED')));
$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'); $arResult['BUTTONS'][] = array('TEXT' => GetMessage('CRM_CONTACT_IMPORT_OUTLOOK'), 'TITLE' => GetMessage('CRM_CONTACT_IMPORT_OUTLOOK_TITLE'), 'LINK' => CCrmUrlUtil::AddUrlParams($importUrl, array('origin' => 'outlook')), 'ICON' => 'btn-import');
protected function innerAdd(&$fields, &$errors, array $params = null) { if (!CCrmContact::CheckCreatePermission()) { $errors[] = 'Access denied.'; return false; } if (isset($fields['COMMENTS'])) { $fields['COMMENTS'] = $this->sanitizeHtml($fields['COMMENTS']); } $entity = self::getEntity(); $options = array(); if (is_array($params) && isset($params['REGISTER_SONET_EVENT'])) { $options['REGISTER_SONET_EVENT'] = strtoupper($params['REGISTER_SONET_EVENT']) === 'Y'; } $result = $entity->Add($fields, true, $options); if ($result <= 0) { $errors[] = $entity->LAST_ERROR; } elseif (self::isBizProcEnabled()) { CCrmBizProcHelper::AutoStartWorkflows(CCrmOwnerType::Contact, $result, CCrmBizProcEventType::Create, $errors); } return $result; }
public static function PrepareConversionPermissionFlags($ID, array &$params, $userPermissions = null) { if (!$userPermissions) { $userPermissions = CCrmPerms::GetCurrentUserPermissions(); } $canEdit = CCrmAuthorizationHelper::CheckUpdatePermission(self::$TYPE_NAME, $ID, $userPermissions); $canCreateContact = CCrmContact::CheckCreatePermission($userPermissions); $canCreateCompany = CCrmCompany::CheckCreatePermission($userPermissions); $canCreateDeal = CCrmDeal::CheckCreatePermission($userPermissions); $params['CAN_CONVERT_TO_CONTACT'] = $canEdit && $canCreateContact; $params['CAN_CONVERT_TO_COMPANY'] = $canEdit && $canCreateCompany; $params['CAN_CONVERT_TO_DEAL'] = $canEdit && $canCreateDeal; $params['CAN_CONVERT'] = $params['CONVERT'] = $canEdit && ($canCreateContact || $canCreateCompany || $canCreateDeal); $params['CONVERSION_PERMITTED'] = true; }
<?php if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED !== true) { die; } if (!CModule::IncludeModule('crm')) { ShowError(GetMessage('CRM_MODULE_NOT_INSTALLED')); return; } $entityID = $arParams['ENTITY_ID'] = isset($arParams['ENTITY_ID']) ? intval($arParams['ENTITY_ID']) : 0; if ($entityID <= 0 && isset($_GET['contact_id'])) { $entityID = $arParams['ENTITY_ID'] = intval($_GET['contact_id']); } $arResult['ENTITY_ID'] = $entityID; $userPerms = CCrmPerms::GetCurrentUserPermissions(); if (!($entityID > 0 ? CCrmContact::CheckUpdatePermission($entityID, $userPerms) : CCrmContact::CheckCreatePermission($userPerms))) { ShowError(GetMessage('CRM_PERMISSION_DENIED')); return; } global $APPLICATION; //$arParams['ACTIVITY_LIST_URL_TEMPLATE'] = isset($arParams['ACTIVITY_LIST_URL_TEMPLATE']) ? $arParams['ACTIVITY_LIST_URL_TEMPLATE'] : ''; //$arParams['COMMUNICATION_LIST_URL_TEMPLATE'] = isset($arParams['COMMUNICATION_LIST_URL_TEMPLATE']) ? $arParams['COMMUNICATION_LIST_URL_TEMPLATE'] : ''; //$arParams['EVENT_LIST_URL_TEMPLATE'] = isset($arParams['EVENT_LIST_URL_TEMPLATE']) ? $arParams['EVENT_LIST_URL_TEMPLATE'] : ''; //$arParams['DEAL_LIST_URL_TEMPLATE'] = isset($arParams['DEAL_LIST_URL_TEMPLATE']) ? $arParams['DEAL_LIST_URL_TEMPLATE'] : ''; //$arParams['USER_PROFILE_URL_TEMPLATE'] = isset($arParams['USER_PROFILE_URL_TEMPLATE']) ? $arParams['USER_PROFILE_URL_TEMPLATE'] : ''; $arParams['CONTACT_SHOW_URL_TEMPLATE'] = isset($arParams['CONTACT_SHOW_URL_TEMPLATE']) ? $arParams['CONTACT_SHOW_URL_TEMPLATE'] : ''; $arParams['CONTACT_EDIT_URL_TEMPLATE'] = isset($arParams['CONTACT_EDIT_URL_TEMPLATE']) ? $arParams['CONTACT_EDIT_URL_TEMPLATE'] : ''; $arParams['USER_PROFILE_URL_TEMPLATE'] = isset($arParams['USER_PROFILE_URL_TEMPLATE']) ? $arParams['USER_PROFILE_URL_TEMPLATE'] : ''; $arParams['STATUS_SELECTOR_URL_TEMPLATE'] = isset($arParams['STATUS_SELECTOR_URL_TEMPLATE']) ? $arParams['STATUS_SELECTOR_URL_TEMPLATE'] : ''; $arParams['COMPANY_SELECTOR_URL_TEMPLATE'] = isset($arParams['COMPANY_SELECTOR_URL_TEMPLATE']) ? $arParams['COMPANY_SELECTOR_URL_TEMPLATE'] : ''; $arParams['NAME_TEMPLATE'] = empty($arParams['NAME_TEMPLATE']) ? CSite::GetNameFormat(false) : str_replace(array('#NOBR#', '#/NOBR#'), array('', ''), $arParams['NAME_TEMPLATE']);
} } 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 === '') { __CrmContactEditEndResonse(array('ERROR' => 'Entity type is not specified.')); } $entityTypeID = CCrmOwnerType::ResolveID($entityTypeName); if ($entityTypeID === CCrmOwnerType::Undefined) { __CrmContactEditEndResonse(array('ERROR' => 'Undefined entity type is specified.')); } if ($entityTypeID !== CCrmOwnerType::Contact) { __CrmContactEditEndResonse(array('ERROR' => "The '{$entityTypeName}' type is not supported in current context.")); } if (!(CCrmContact::CheckCreatePermission($userPermissions) || CCrmContact::CheckUpdatePermission(0, $userPermissions))) { __CrmContactEditEndResonse(array('ERROR' => 'Access denied.')); } $userProfileUrlTemplate = COption::GetOptionString("main", "TOOLTIP_PATH_TO_USER", "", SITE_ID); $checker = new \Bitrix\Crm\Integrity\ContactDuplicateChecker(); $groupResults = array(); $groupData = isset($params['GROUPS']) && is_array($params['GROUPS']) ? $params['GROUPS'] : array(); foreach ($groupData as &$group) { $fields = array(); $fieldNames = array(); if (isset($group['LAST_NAME'])) { $fieldNames[] = 'LAST_NAME'; $fields['LAST_NAME'] = $group['LAST_NAME']; } if (isset($group['NAME'])) { $fieldNames[] = 'NAME';