if (!CModule::IncludeModule('bizproc')) { ShowError(GetMessage('BIZPROC_MODULE_NOT_INSTALLED')); return; } } global $USER_FIELD_MANAGER, $USER, $APPLICATION, $DB; $CCrmPerms = CCrmPerms::GetCurrentUserPermissions(); if ($CCrmPerms->HavePerm('CONTACT', BX_CRM_PERM_NONE, 'READ')) { ShowError(GetMessage('CRM_PERMISSION_DENIED')); return; } use Bitrix\Crm\EntityAddress; use Bitrix\Crm\Format\AddressSeparator; use Bitrix\Crm\Format\ContactAddressFormatter; $CCrmContact = new CCrmContact(false); $CCrmBizProc = new CCrmBizProc('CONTACT'); $userID = CCrmSecurityHelper::GetCurrentUserID(); $isAdmin = CCrmPerms::IsAdmin(); $arResult['CURRENT_USER_ID'] = CCrmSecurityHelper::GetCurrentUserID(); $arParams['PATH_TO_CONTACT_LIST'] = CrmCheckPath('PATH_TO_CONTACT_LIST', $arParams['PATH_TO_CONTACT_LIST'], $APPLICATION->GetCurPage()); $arParams['PATH_TO_CONTACT_SHOW'] = CrmCheckPath('PATH_TO_CONTACT_SHOW', $arParams['PATH_TO_CONTACT_SHOW'], $APPLICATION->GetCurPage() . '?contact_id=#contact_id#&show'); $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_COMPANY_SHOW'] = CrmCheckPath('PATH_TO_COMPANY_SHOW', $arParams['PATH_TO_COMPANY_SHOW'], $APPLICATION->GetCurPage() . '?company_id=#company_id#&show'); $arParams['PATH_TO_DEAL_EDIT'] = CrmCheckPath('PATH_TO_DEAL_EDIT', $arParams['PATH_TO_DEAL_EDIT'], $APPLICATION->GetCurPage() . '?deal_id=#deal_id#&edit'); $arParams['PATH_TO_QUOTE_EDIT'] = CrmCheckPath('PATH_TO_QUOTE_EDIT', $arParams['PATH_TO_QUOTE_EDIT'], $APPLICATION->GetCurPage() . '?quote_id=#quote_id#&edit'); $arParams['PATH_TO_INVOICE_EDIT'] = CrmCheckPath('PATH_TO_INVOICE_EDIT', $arParams['PATH_TO_INVOICE_EDIT'], $APPLICATION->GetCurPage() . '?invoice_id=#invoice_id#&edit'); $arParams['PATH_TO_USER_PROFILE'] = CrmCheckPath('PATH_TO_USER_PROFILE', $arParams['PATH_TO_USER_PROFILE'], '/company/personal/user/#user_id#/'); $arParams['PATH_TO_USER_BP'] = CrmCheckPath('PATH_TO_USER_BP', $arParams['PATH_TO_USER_BP'], '/company/personal/bizproc/'); $arParams['NAME_TEMPLATE'] = empty($arParams['NAME_TEMPLATE']) ? CSite::GetNameFormat(false) : str_replace(array("#NOBR#", "#/NOBR#"), array("", ""), $arParams["NAME_TEMPLATE"]); $arResult['IS_AJAX_CALL'] = isset($_REQUEST['bxajaxid']) || isset($_REQUEST['AJAX_CALL']); $arResult['SESSION_ID'] = bitrix_sessid();
} if (!CModule::IncludeModule('sale')) { ShowError(GetMessage('CRM_MODULE_NOT_INSTALLED_SALE')); return; } global $USER_FIELD_MANAGER, $USER, $APPLICATION, $DB; $CCrmPerms = CCrmPerms::GetCurrentUserPermissions(); if ($CCrmPerms->HavePerm('LEAD', BX_CRM_PERM_NONE, 'READ')) { ShowError(GetMessage('CRM_PERMISSION_DENIED')); return; } use Bitrix\Crm\EntityAddress; use Bitrix\Crm\Format\AddressSeparator; use Bitrix\Crm\Format\LeadAddressFormatter; $CCrmLead = new CCrmLead(false); $CCrmBizProc = new CCrmBizProc('LEAD'); $userID = CCrmSecurityHelper::GetCurrentUserID(); $isAdmin = CCrmPerms::IsAdmin(); $arParams['PATH_TO_LEAD_LIST'] = CrmCheckPath('PATH_TO_LEAD_LIST', $arParams['PATH_TO_LEAD_LIST'], $APPLICATION->GetCurPage()); $arParams['PATH_TO_LEAD_EDIT'] = CrmCheckPath('PATH_TO_LEAD_EDIT', $arParams['PATH_TO_LEAD_EDIT'], $APPLICATION->GetCurPage() . '?lead_id=#lead_id#&edit'); $arParams['PATH_TO_LEAD_SHOW'] = CrmCheckPath('PATH_TO_LEAD_SHOW', $arParams['PATH_TO_LEAD_SHOW'], $APPLICATION->GetCurPage() . '?lead_id=#lead_id#&show'); $arParams['PATH_TO_LEAD_CONVERT'] = CrmCheckPath('PATH_TO_LEAD_CONVERT', $arParams['PATH_TO_LEAD_CONVERT'], $APPLICATION->GetCurPage() . '?lead_id=#lead_id#&convert'); $arParams['PATH_TO_QUOTE_EDIT'] = CrmCheckPath('PATH_TO_QUOTE_EDIT', $arParams['PATH_TO_QUOTE_EDIT'], $APPLICATION->GetCurPage() . '?quote_id=#quote_id#&edit'); $arParams['PATH_TO_USER_PROFILE'] = CrmCheckPath('PATH_TO_USER_PROFILE', $arParams['PATH_TO_USER_PROFILE'], '/company/personal/user/#user_id#/'); $arParams['PATH_TO_USER_BP'] = CrmCheckPath('PATH_TO_USER_BP', $arParams['PATH_TO_USER_BP'], '/company/personal/bizproc/'); $arParams['NAME_TEMPLATE'] = empty($arParams['NAME_TEMPLATE']) ? CSite::GetNameFormat(false) : str_replace(array("#NOBR#", "#/NOBR#"), array("", ""), $arParams["NAME_TEMPLATE"]); $arResult['CURRENT_USER_ID'] = CCrmSecurityHelper::GetCurrentUserID(); $arResult['IS_AJAX_CALL'] = isset($_REQUEST['bxajaxid']) || isset($_REQUEST['AJAX_CALL']); $arResult['SESSION_ID'] = bitrix_sessid(); $addressLabels = EntityAddress::getShortLabels(); //Show error message if required
public function Delete($ID, $arOptions = array()) { global $DB, $APPLICATION; $ID = intval($ID); $iUserId = CCrmSecurityHelper::GetCurrentUserID(); if (!is_array($arOptions)) { $arOptions = array(); } $sWherePerm = ''; if ($this->bCheckPermission) { $arEntityAttr = $this->cPerms->GetEntityAttr('DEAL', $ID); $sEntityPerm = $this->cPerms->GetPermType('DEAL', 'DELETE', $arEntityAttr[$ID]); if ($sEntityPerm == BX_CRM_PERM_NONE) { return false; } else { if ($sEntityPerm == BX_CRM_PERM_SELF) { $sWherePerm = " AND ASSIGNED_BY_ID = {$iUserId}"; } else { if ($sEntityPerm == BX_CRM_PERM_OPEN) { $sWherePerm = " AND (OPENED = 'Y' OR ASSIGNED_BY_ID = {$iUserId})"; } } } } $APPLICATION->ResetException(); $events = GetModuleEvents('crm', 'OnBeforeCrmDealDelete'); while ($arEvent = $events->Fetch()) { if (ExecuteModuleEventEx($arEvent, array($ID)) === false) { $err = GetMessage("MAIN_BEFORE_DEL_ERR") . ' ' . $arEvent['TO_NAME']; if ($ex = $APPLICATION->GetException()) { $err .= ': ' . $ex->GetString(); } $APPLICATION->throwException($err); return false; } } //By defaut we need to clean up related bizproc entities $processBizproc = isset($arOptions['PROCESS_BIZPROC']) ? (bool) $arOptions['PROCESS_BIZPROC'] : true; if ($processBizproc) { $bizproc = new CCrmBizProc('DEAL'); $bizproc->ProcessDeletion($ID); } $dbRes = $DB->Query("DELETE FROM b_crm_deal WHERE ID = {$ID}{$sWherePerm}", false, 'FILE: ' . __FILE__ . '<br /> LINE: ' . __LINE__); if (is_object($dbRes) && $dbRes->AffectedRowsCount() > 0) { CCrmSearch::DeleteSearch('DEAL', $ID); $DB->Query("DELETE FROM b_crm_entity_perms WHERE ENTITY='DEAL' AND ENTITY_ID = {$ID}", false, 'FILE: ' . __FILE__ . '<br /> LINE: ' . __LINE__); $GLOBALS['USER_FIELD_MANAGER']->Delete(self::$sUFEntityID, $ID); $CCrmFieldMulti = new CCrmFieldMulti(); $CCrmFieldMulti->DeleteByElement('DEAL', $ID); $CCrmEvent = new CCrmEvent(); $CCrmEvent->DeleteByElement('DEAL', $ID); Bitrix\Crm\History\DealStageHistoryEntry::unregister($ID); Bitrix\Crm\Statistics\DealSumStatisticEntry::unregister($ID); Bitrix\Crm\Statistics\DealInvoiceStatisticEntry::unregister($ID); Bitrix\Crm\Statistics\DealActivityStatisticEntry::unregister($ID); // Deletion of deal details CCrmProductRow::DeleteByOwner('D', $ID); CCrmProductRow::DeleteSettings('D', $ID); CCrmActivity::DeleteByOwner(CCrmOwnerType::Deal, $ID); CCrmSonetSubscription::UnRegisterSubscriptionByEntity(CCrmOwnerType::Deal, $ID); CCrmLiveFeed::DeleteLogEvents(array('ENTITY_TYPE_ID' => CCrmOwnerType::Deal, 'ENTITY_ID' => $ID)); self::PullChange('DELETE', array('ID' => $ID)); if (defined("BX_COMP_MANAGED_CACHE")) { $GLOBALS["CACHE_MANAGER"]->ClearByTag("crm_entity_name_" . CCrmOwnerType::Deal . "_" . $ID); } $afterEvents = GetModuleEvents('crm', 'OnAfterCrmDealDelete'); while ($arEvent = $afterEvents->Fetch()) { ExecuteModuleEventEx($arEvent, array($ID)); } } return true; }
public static function UpdateDocument($documentId, $arFields) { global $DB; $arDocumentID = self::GetDocumentInfo($documentId); if (empty($arDocumentID)) { throw new CBPArgumentNullException('documentId'); } $dbDocumentList = CCrmCompany::GetList(array(), array('ID' => $arDocumentID['ID'], "CHECK_PERMISSIONS" => "N"), array('ID')); $arResult = $dbDocumentList->Fetch(); if (!$arResult) { throw new Exception(GetMessage('CRM_DOCUMENT_ELEMENT_IS_NOT_FOUND')); } $arDocumentFields = self::GetDocumentFields($arDocumentID['TYPE']); $arKeys = array_keys($arFields); foreach ($arKeys as $key) { if (!array_key_exists($key, $arDocumentFields)) { //Fix for issue #40374 unset($arFields[$key]); continue; } $fieldType = $arDocumentFields[$key]["Type"]; if (in_array($fieldType, array("phone", "email", "im", "web"), true)) { CCrmDocument::PrepareEntityMultiFields($arFields, strtoupper($fieldType)); continue; } $arFields[$key] = is_array($arFields[$key]) && !CBPHelper::IsAssociativeArray($arFields[$key]) ? $arFields[$key] : array($arFields[$key]); if ($fieldType == "user") { $ar = array(); foreach ($arFields[$key] as $v1) { if (substr($v1, 0, strlen("user_")) == "user_") { $ar[] = substr($v1, strlen("user_")); } else { $a1 = self::GetUsersFromUserGroup($v1, $documentId); foreach ($a1 as $a11) { $ar[] = $a11; } } } $arFields[$key] = $ar; } elseif ($fieldType == "select" && substr($key, 0, 3) == "UF_") { self::InternalizeEnumerationField('CRM_COMPANY', $arFields, $key); } elseif ($fieldType == "file") { $arFileOptions = array('ENABLE_ID' => true); foreach ($arFields[$key] as &$value) { //Issue #40380. Secure URLs and file IDs are allowed. $file = false; CCrmFileProxy::TryResolveFile($value, $file, $arFileOptions); $value = $file; } unset($value); } elseif ($fieldType == "S:HTML") { foreach ($arFields[$key] as &$value) { $value = array("VALUE" => $value); } unset($value); } if (!$arDocumentFields[$key]["Multiple"] && is_array($arFields[$key])) { if (count($arFields[$key]) > 0) { $a = array_values($arFields[$key]); $arFields[$key] = $a[0]; } else { $arFields[$key] = null; } } } if (isset($arFields['CONTACT_ID']) && !is_array($arFields['CONTACT_ID'])) { $arFields['CONTACT_ID'] = array($arFields['CONTACT_ID']); } if (isset($arFields['COMMENTS']) && $arFields['COMMENTS'] !== '') { $arFields['COMMENTS'] = preg_replace("/[\r\n]+/" . BX_UTF_PCRE_MODIFIER, "<br/>", $arFields['COMMENTS']); } $DB->StartTransaction(); $CCrmEntity = new CCrmCompany(false); $res = $CCrmEntity->Update($arDocumentID['ID'], $arFields); if (!$res) { $DB->Rollback(); throw new Exception($CCrmEntity->LAST_ERROR); } if (COption::GetOptionString("crm", "start_bp_within_bp", "N") == "Y") { $CCrmBizProc = new CCrmBizProc('COMPANY'); if (false === $CCrmBizProc->CheckFields($arDocumentID['ID'], true)) { throw new Exception($CCrmBizProc->LAST_ERROR); } if ($res && !$CCrmBizProc->StartWorkflow($arDocumentID['ID'])) { $DB->Rollback(); throw new Exception($CCrmBizProc->LAST_ERROR); } } if ($res) { $DB->Commit(); } }
trim($phone); } else { $phone = ''; } $arFields['FM'] = array(); if ($email !== '') { $arFields['FM']['EMAIL'] = array('n0' => array('VALUE' => $email, 'VALUE_TYPE' => 'WORK')); } if ($phone !== '') { $arFields['FM']['PHONE'] = array('n0' => array('VALUE' => $phone, 'VALUE_TYPE' => 'WORK')); } } } $arResult['ELEMENT'] = $arFields; unset($arFields); $CCrmBizProc = new CCrmBizProc('CONTACT'); if ($isConverting) { $varsFromForm = true; } else { if ($_SERVER['REQUEST_METHOD'] == 'POST' && check_bitrix_sessid()) { $varsFromForm = true; if (isset($_POST['save']) || isset($_POST['saveAndView']) || isset($_POST['saveAndAdd']) || isset($_POST['apply'])) { $arFields = array('NAME' => trim($_POST['NAME']), 'LAST_NAME' => trim($_POST['LAST_NAME']), 'SECOND_NAME' => trim($_POST['SECOND_NAME'])); if (isset($_POST['POST'])) { $arFields['POST'] = trim($_POST['POST']); } if (isset($_POST['ADDRESS'])) { $arFields['ADDRESS'] = trim($_POST['ADDRESS']); } if (isset($_POST['ADDRESS_2'])) { $arFields['ADDRESS_2'] = trim($_POST['ADDRESS_2']);
public function Delete($ID, $arOptions = array()) { global $DB, $APPLICATION; $ID = intval($ID); $iUserId = CCrmSecurityHelper::GetCurrentUserID(); $this->LAST_ERROR = ''; $APPLICATION->ResetException(); if (!is_array($arOptions)) { $arOptions = array(); } if (isset($arOptions['CHECK_DEPENDENCIES']) && (bool) $arOptions['CHECK_DEPENDENCIES']) { $dbRes = self::GetListEx(array(), array('=ID' => $ID), false, false, array('TITLE', 'STATUS_ID', 'COMPANY_ID', 'CONTACT_ID')); $arFields = $dbRes ? $dbRes->Fetch() : null; if (is_array($arFields) && isset($arFields['STATUS_ID']) && $arFields['STATUS_ID'] === 'CONVERTED' && (CCrmCompany::Exists(isset($arFields['COMPANY_ID']) ? intval($arFields['COMPANY_ID']) : 0) || CCrmContact::Exists(isset($arFields['CONTACT_ID']) ? intval($arFields['CONTACT_ID']) : 0))) { $title = isset($arFields['TITLE']) && $arFields['TITLE'] !== '' ? $arFields['TITLE'] : $ID; $err = GetMessage('CRM_LEAD_DELETION_DEPENDENCIES_FOUND', array('#TITLE#' => $title)); $this->LAST_ERROR = $err; $APPLICATION->throwException($err); return false; } } $sWherePerm = ''; if ($this->bCheckPermission) { $arEntityAttr = $this->cPerms->GetEntityAttr('LEAD', $ID); $sEntityPerm = $this->cPerms->GetPermType('LEAD', 'DELETE', $arEntityAttr[$ID]); if ($sEntityPerm == BX_CRM_PERM_NONE) { return false; } else { if ($sEntityPerm == BX_CRM_PERM_SELF) { $sWherePerm = " AND ASSIGNED_BY_ID = {$iUserId}"; } else { if ($sEntityPerm == BX_CRM_PERM_OPEN) { $sWherePerm = " AND (OPENED = 'Y' OR ASSIGNED_BY_ID = {$iUserId})"; } } } } $events = GetModuleEvents('crm', 'OnBeforeCrmLeadDelete'); while ($arEvent = $events->Fetch()) { if (ExecuteModuleEventEx($arEvent, array($ID)) === false) { $err = GetMessage("MAIN_BEFORE_DEL_ERR") . ' ' . $arEvent['TO_NAME']; if ($ex = $APPLICATION->GetException()) { $err .= ': ' . $ex->GetString(); } $APPLICATION->throwException($err); $this->LAST_ERROR = $err; return false; } } //By defaut we need to clean up related bizproc entities $processBizproc = isset($arOptions['PROCESS_BIZPROC']) ? (bool) $arOptions['PROCESS_BIZPROC'] : true; if ($processBizproc) { $bizproc = new CCrmBizProc('LEAD'); $bizproc->ProcessDeletion($ID); } $tableName = CCrmLead::TABLE_NAME; $sSql = "DELETE FROM {$tableName} WHERE ID = {$ID}{$sWherePerm}"; $obRes = $DB->Query($sSql, false, 'FILE: ' . __FILE__ . '<br /> LINE: ' . __LINE__); if (is_object($obRes) && $obRes->AffectedRowsCount() > 0) { CCrmSearch::DeleteSearch('LEAD', $ID); $DB->Query("DELETE FROM b_crm_entity_perms WHERE ENTITY='LEAD' AND ENTITY_ID = {$ID}", false, 'FILE: ' . __FILE__ . '<br /> LINE: ' . __LINE__); $GLOBALS['USER_FIELD_MANAGER']->Delete(self::$sUFEntityID, $ID); $CCrmFieldMulti = new CCrmFieldMulti(); $CCrmFieldMulti->DeleteByElement('LEAD', $ID); $CCrmEvent = new CCrmEvent(); $CCrmEvent->DeleteByElement('LEAD', $ID); \Bitrix\Crm\EntityAddress::unregister(CCrmOwnerType::Lead, $ID, \Bitrix\Crm\EntityAddress::Primary); \Bitrix\Crm\Integrity\DuplicateEntityRanking::unregisterEntityStatistics(CCrmOwnerType::Lead, $ID); \Bitrix\Crm\Integrity\DuplicatePersonCriterion::unregister(CCrmOwnerType::Lead, $ID); \Bitrix\Crm\Integrity\DuplicateOrganizationCriterion::unregister(CCrmOwnerType::Lead, $ID); \Bitrix\Crm\Integrity\DuplicateCommunicationCriterion::unregister(CCrmOwnerType::Lead, $ID); \Bitrix\Crm\Integrity\DuplicateIndexMismatch::unregisterEntity(CCrmOwnerType::Lead, $ID); $enableDupIndexInvalidation = is_array($arOptions) && isset($arOptions['ENABLE_DUP_INDEX_INVALIDATION']) ? (bool) $arOptions['ENABLE_DUP_INDEX_INVALIDATION'] : true; if ($enableDupIndexInvalidation) { \Bitrix\Crm\Integrity\DuplicateIndexBuilder::markAsJunk(CCrmOwnerType::Lead, $ID); } // Deletion of lead details CCrmProductRow::DeleteByOwner('L', $ID); CCrmProductRow::DeleteSettings('L', $ID); CCrmActivity::DeleteByOwner(CCrmOwnerType::Lead, $ID); CCrmSonetSubscription::UnRegisterSubscriptionByEntity(CCrmOwnerType::Lead, $ID); CCrmLiveFeed::DeleteLogEvents(array('ENTITY_TYPE_ID' => CCrmOwnerType::Lead, 'ENTITY_ID' => $ID)); if (defined("BX_COMP_MANAGED_CACHE")) { $GLOBALS["CACHE_MANAGER"]->ClearByTag("crm_entity_name_" . CCrmOwnerType::Lead . "_" . $ID); } $afterEvents = GetModuleEvents('crm', 'OnAfterCrmLeadDelete'); while ($arEvent = $afterEvents->Fetch()) { ExecuteModuleEventEx($arEvent, array($ID)); } } return true; }
if (!defined('B_PROLOG_INCLUDED') || B_PROLOG_INCLUDED !== true) { die; } if (!CModule::IncludeModule('crm')) { ShowError(GetMessage('CRM_MODULE_NOT_INSTALLED')); return; } CModule::IncludeModule('fileman'); if (IsModuleInstalled('bizproc') && !CModule::IncludeModule('bizproc')) { ShowError(GetMessage('BIZPROC_MODULE_NOT_INSTALLED')); return; } global $USER_FIELD_MANAGER, $DB, $USER; $CCrmDeal = new CCrmDeal(); $CCrmUserType = new CCrmUserType($USER_FIELD_MANAGER, CCrmDeal::$sUFEntityID); $CCrmBizProc = new CCrmBizProc('DEAL'); $userPermissions = CCrmPerms::GetCurrentUserPermissions(); $arParams['PATH_TO_DEAL_LIST'] = CrmCheckPath('PATH_TO_DEAL_LIST', $arParams['PATH_TO_DEAL_LIST'], $APPLICATION->GetCurPage()); $arParams['PATH_TO_DEAL_SHOW'] = CrmCheckPath('PATH_TO_DEAL_SHOW', $arParams['PATH_TO_DEAL_SHOW'], $APPLICATION->GetCurPage() . '?deal_id=#deal_id#&show'); $arParams['PATH_TO_DEAL_EDIT'] = CrmCheckPath('PATH_TO_DEAL_EDIT', $arParams['PATH_TO_DEAL_EDIT'], $APPLICATION->GetCurPage() . '?deal_id=#deal_id#&edit'); $arParams['PATH_TO_USER_PROFILE'] = CrmCheckPath('PATH_TO_USER_PROFILE', $arParams['PATH_TO_USER_PROFILE'], '/company/personal/user/#user_id#/'); $arParams['PATH_TO_CONTACT_SHOW'] = CrmCheckPath('PATH_TO_CONTACT_SHOW', $arParams['PATH_TO_CONTACT_SHOW'], $APPLICATION->GetCurPage() . '?contact_id=#contact_id#&show'); $arParams['PATH_TO_COMPANY_SHOW'] = CrmCheckPath('PATH_TO_COMPANY_SHOW', $arParams['PATH_TO_COMPANY_SHOW'], $APPLICATION->GetCurPage() . '?company_id=#company_id#&show'); $arParams['PATH_TO_PRODUCT_EDIT'] = CrmCheckPath('PATH_TO_PRODUCT_EDIT', $arParams['PATH_TO_PRODUCT_EDIT'], $APPLICATION->GetCurPage() . '?product_id=#product_id#&edit'); $arParams['PATH_TO_PRODUCT_SHOW'] = CrmCheckPath('PATH_TO_PRODUCT_SHOW', $arParams['PATH_TO_PRODUCT_SHOW'], $APPLICATION->GetCurPage() . '?product_id=#product_id#&show'); $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; $bEdit = false; $bCopy = false; $bVarsFromForm = false; if (!empty($arParams['ELEMENT_ID'])) {
$arContactBizProcParams = $CCrmContactBizProc->CheckFields(false, false, $arFields['CONTACT']['ASSIGNED_BY_ID'], null); if ($arContactBizProcParams !== false) { $CCrmContactBizProc->StartWorkflow($iContactId, $arContactBizProcParams); } } } $arFields['DEAL']['CONTACT_ID'] = $iContactId; if (!$CrmPerms->HavePerm('DEAL', BX_CRM_PERM_NONE, 'ADD')) { if ($bConvertDeal) { $arDealFields = $arFields['DEAL']; $iDealId = $CCrmDeal->Add($arDealFields, true, array('REGISTER_SONET_EVENT' => true)); if ($iDealId > 0) { if (!empty($arDealFields['PRODUCT_ROWS'])) { CCrmDeal::SaveProductRows($iDealId, $arDealFields['PRODUCT_ROWS']); } $CCrmDealBizProc = new CCrmBizProc('DEAL'); $arDealBizProcParams = $CCrmDealBizProc->CheckFields(false, false, $arDealFields['ASSIGNED_BY_ID'], null); if ($arDealBizProcParams !== false) { $CCrmDealBizProc->StartWorkflow($iDealId, $arDealBizProcParams); } } } } $CCrmLead = new CCrmLead(); $arFields['LEAD'] = array('STATUS_ID' => 'CONVERTED', 'CONTACT_ID' => $iContactId, 'COMPANY_ID' => $iCompanyId); if ($CCrmLead->Update($arParams['ELEMENT_ID'], $arFields['LEAD'], true, true, array('REGISTER_SONET_EVENT' => true))) { $arErrors = array(); CCrmBizProcHelper::AutoStartWorkflows(CCrmOwnerType::Lead, $arParams['ELEMENT_ID'], CCrmBizProcEventType::Edit, $arErrors); } if (isset($_POST['apply'])) { LocalRedirect(CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_LEAD_CONVERT'], array('lead_id' => $arParams['ELEMENT_ID'])));
public function Delete($ID, $arOptions = array()) { global $DB, $APPLICATION; $ID = intval($ID); $iUserId = CCrmSecurityHelper::GetCurrentUserID(); if (!is_array($arOptions)) { $arOptions = array(); } $sWherePerm = ''; if ($this->bCheckPermission) { $arEntityAttr = $this->cPerms->GetEntityAttr('COMPANY', $ID); $sEntityPerm = $this->cPerms->GetPermType('COMPANY', 'DELETE', $arEntityAttr[$ID]); if ($sEntityPerm == BX_CRM_PERM_NONE) { return false; } else { if ($sEntityPerm == BX_CRM_PERM_SELF) { $sWherePerm = " AND ASSIGNED_BY_ID = {$iUserId}"; } else { if ($sEntityPerm == BX_CRM_PERM_OPEN) { $sWherePerm = " AND (OPENED = 'Y' OR ASSIGNED_BY_ID = {$iUserId})"; } } } } $APPLICATION->ResetException(); $events = GetModuleEvents('crm', 'OnBeforeCrmCompanyDelete'); while ($arEvent = $events->Fetch()) { if (ExecuteModuleEventEx($arEvent, array($ID)) === false) { $err = GetMessage("MAIN_BEFORE_DEL_ERR") . ' ' . $arEvent['TO_NAME']; if ($ex = $APPLICATION->GetException()) { $err .= ': ' . $ex->GetString(); } $APPLICATION->throwException($err); return false; } } //By defaut we need to clean up related bizproc entities $processBizproc = isset($arOptions['PROCESS_BIZPROC']) ? (bool) $arOptions['PROCESS_BIZPROC'] : true; if ($processBizproc) { $bizproc = new CCrmBizProc('COMPANY'); $bizproc->ProcessDeletion($ID); } $obRes = $DB->Query("DELETE FROM b_crm_company WHERE ID = {$ID}{$sWherePerm}", false, 'FILE: ' . __FILE__ . '<br /> LINE: ' . __LINE__); if (is_object($obRes) && $obRes->AffectedRowsCount() > 0) { CCrmSearch::DeleteSearch('COMPANY', $ID); $DB->Query("DELETE FROM b_crm_entity_perms WHERE ENTITY='COMPANY' AND ENTITY_ID = {$ID}", false, 'FILE: ' . __FILE__ . '<br /> LINE: ' . __LINE__); $GLOBALS['USER_FIELD_MANAGER']->Delete(self::$sUFEntityID, $ID); $CCrmFieldMulti = new CCrmFieldMulti(); $CCrmFieldMulti->DeleteByElement('COMPANY', $ID); $CCrmEvent = new CCrmEvent(); $CCrmEvent->DeleteByElement('COMPANY', $ID); \Bitrix\Crm\EntityAddress::unregister(CCrmOwnerType::Company, $ID, \Bitrix\Crm\EntityAddress::Primary); \Bitrix\Crm\EntityAddress::unregister(CCrmOwnerType::Company, $ID, \Bitrix\Crm\EntityAddress::Registered); \Bitrix\Crm\Integrity\DuplicateEntityRanking::unregisterEntityStatistics(CCrmOwnerType::Company, $ID); \Bitrix\Crm\Integrity\DuplicateOrganizationCriterion::unregister(CCrmOwnerType::Company, $ID); \Bitrix\Crm\Integrity\DuplicateCommunicationCriterion::unregister(CCrmOwnerType::Company, $ID); \Bitrix\Crm\Integrity\DuplicateIndexMismatch::unregisterEntity(CCrmOwnerType::Company, $ID); $enableDupIndexInvalidation = isset($arOptions['ENABLE_DUP_INDEX_INVALIDATION']) ? (bool) $arOptions['ENABLE_DUP_INDEX_INVALIDATION'] : true; if ($enableDupIndexInvalidation) { \Bitrix\Crm\Integrity\DuplicateIndexBuilder::markAsJunk(CCrmOwnerType::Company, $ID); } CCrmActivity::DeleteByOwner(CCrmOwnerType::Company, $ID); CCrmSonetSubscription::UnRegisterSubscriptionByEntity(CCrmOwnerType::Company, $ID); CCrmLiveFeed::DeleteLogEvents(array('ENTITY_TYPE_ID' => CCrmOwnerType::Company, 'ENTITY_ID' => $ID)); if (defined("BX_COMP_MANAGED_CACHE")) { $GLOBALS["CACHE_MANAGER"]->ClearByTag("crm_entity_name_" . CCrmOwnerType::Company . "_" . $ID); } $afterEvents = GetModuleEvents('crm', 'OnAfterCrmCompanyDelete'); while ($arEvent = $afterEvents->Fetch()) { ExecuteModuleEventEx($arEvent, array($ID)); } } return true; }
public function Add($data) { global $DB; if (($r = self::CheckAuth()) !== false) { return $r; } $arFieldsInfo = CCrmLead::GetFields(); $arFields = array(); $arEl = $data->elementsByName('Field'); foreach ($arEl as $child) { $children = $child->children(); $sFieldName = $child->getAttribute('id'); // Fix for issue #40193 if (!isset($arFieldsInfo[$sFieldName])) { continue; } if (!is_null($children)) { $arFields[$sFieldName] = array(); foreach ($children as $child) { $arFields[$sFieldName][] = $child->content; } } else { $arFields[$sFieldName] = $child->content; } } CCrmFieldMulti::PrepareFields($arFields); $CCrmUserType = new CCrmUserType($GLOBALS['USER_FIELD_MANAGER'], CCrmLead::$sUFEntityID); $CCrmUserType->InternalizeFields($arFields, ','); $CCrmBizProc = new CCrmBizProc('LEAD'); if (false === $CCrmBizProc->CheckFields(false, true)) { return new CSoapFault('CCrmLead::Add Bizproc', htmlspecialcharsbx(strip_tags(nl2br($CCrmBizProc->LAST_ERROR)))); } $CCrmLead = new CCrmLead(); $DB->StartTransaction(); $ID = $CCrmLead->Add($arFields); if ($ID !== false && !$CCrmBizProc->StartWorkflow($ID)) { $DB->Rollback(); return new CSoapFault('CCrmLead::Add Bizproc', htmlspecialcharsbx(strip_tags(nl2br($CCrmBizProc->LAST_ERROR)))); } if ($ID === false) { $DB->Rollback(); return new CSoapFault('CCrmLead::Add', htmlspecialcharsbx(strip_tags(nl2br($arFields['RESULT_MESSAGE'])))); } $DB->Commit(); return 'ok'; }