if ($email !== '') { if (!check_email($email)) { echo CUtil::PhpToJSObject(array('ERROR' => GetMessage('CRM_COMPANY_EDIT_INVALID_EMAIL', array('#VALUE#' => $email)))); die; } $arFields['FM']['EMAIL'] = array('n0' => array('VALUE_TYPE' => 'WORK', 'VALUE' => $email)); } $phone = isset($data['phone']) ? $data['phone'] : ''; if ($phone !== '') { $arFields['FM']['PHONE'] = array('n0' => array('VALUE_TYPE' => 'WORK', 'VALUE' => $phone)); } $CrmCompany = new CCrmCompany(); $ID = $CrmCompany->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('COMPANY', $ID); echo CUtil::PhpToJSObject(array('DATA' => $data, 'INFO' => array('title' => $info['TITLE'], 'url' => $info['URL']))); } else { echo CUtil::PhpToJSObject(array('ERROR' => $CrmCompany->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::CompanyName && $entityID > 0 && CCrmCompany::CheckReadPermission($entityID)) { $isEnabled = CCrmSonetSubscription::IsRelationRegistered(CCrmOwnerType::Company, $entityID, CCrmSonetSubscriptionType::Observation, $userID); $enable = isset($_POST['ENABLE']) && strtoupper($_POST['ENABLE']) === 'Y'; if ($isEnabled !== $enable) { if ($enable) { CCrmSonetSubscription::RegisterSubscription(CCrmOwnerType::Company, $entityID, CCrmSonetSubscriptionType::Observation, $userID); } else {
echo CUtil::JSEscape($selectorID); ?> ', '', <?php echo CUtil::PhpToJsObject(CCrmEntitySelectorHelper::PreparePopupItems($entityType, true, isset($params['NAME_TEMPLATE']) ? $params['NAME_TEMPLATE'] : '')); ?> , false, false, <?php echo CUtil::PhpToJsObject($entityType); ?> , <?php echo CUtil::PhpToJsObject(CCrmEntitySelectorHelper::PrepareCommonMessages()); ?> , true ); BX.CrmEntityEditor.messages = { 'unknownError': '<?php echo GetMessageJS('interface_form_ajax_unknown_error'); ?> ' }; BX.CrmEntityEditor.create( '<?php
if (!isset($arFields['FM'])) { $arFields['FM'] = array(); } $arFields['FM']['PHONE'] = array('n0' => array('VALUE_TYPE' => 'WORK', 'VALUE' => $phone)); } $CrmContact = new CCrmContact(); if ($ID > 0) { if ($CrmContact->Update($ID, $arFields, true, array('DISABLE_USER_FIELD_CHECK' => true, 'REGISTER_SONET_EVENT' => true))) { $info = CCrmEntitySelectorHelper::PrepareEntityInfo('CONTACT', $ID); echo CUtil::PhpToJSObject(array('DATA' => $data, 'INFO' => array('title' => $info['TITLE'], 'url' => $info['URL']))); } } 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);