$arFields['BIRTHDATE'] = $_POST['BIRTHDATE']; } $USER_FIELD_MANAGER->EditFormAddFields(CCrmContact::$sUFEntityID, $arFields); $originID = isset($_REQUEST['origin_id']) ? $_REQUEST['origin_id'] : ''; if ($originID !== '') { $arFields['ORIGIN_ID'] = $originID; } $arResult['ERROR_MESSAGE'] = ''; if (!$CCrmContact->CheckFields($arFields, $isEditMode ? $arResult['ELEMENT']['ID'] : false)) { if (!empty($CCrmContact->LAST_ERROR)) { $arResult['ERROR_MESSAGE'] .= $CCrmContact->LAST_ERROR; } else { $arResult['ERROR_MESSAGE'] .= GetMessage('UNKNOWN_ERROR'); } } if ($arBizProcParametersValues = $CCrmBizProc->CheckFields($isEditMode ? $arResult['ELEMENT']['ID'] : false, false, $arResult['ELEMENT']['ASSIGNED_BY'], $isEditMode ? array($arResult['ELEMENT']['ID'] => $arEntityAttr[$arResult['ELEMENT']['ID']]) : null) === false) { $arResult['ERROR_MESSAGE'] .= $CCrmBizProc->LAST_ERROR; } if (empty($arResult['ERROR_MESSAGE'])) { $DB->StartTransaction(); $success = false; if ($isEditMode) { $success = $CCrmContact->Update($arResult['ELEMENT']['ID'], $arFields, true, true, array('REGISTER_SONET_EVENT' => true)); } else { $ID = $CCrmContact->Add($arFields, true, array('REGISTER_SONET_EVENT' => true)); $success = $ID !== false; if ($success) { $arResult['ELEMENT']['ID'] = $ID; } } if ($success) {
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(); } }
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']))); } else {
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'; }