public function Add($data) { if (($r = self::CheckAuth()) !== false) { return $r; } $arFieldsInfo = CCrmContact::GetFields(); $arFields = array(); $arEl = $data->elementsByName('Field'); foreach ($arEl as $el) { $children = $el->children(); $sFieldName = $el->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] = $el->content; } } CCrmFieldMulti::PrepareFields($arFields); if (isset($arFields['PHOTO'])) { $arFile = null; if (CCrmUrlUtil::HasScheme($arFields['PHOTO']) && CCrmUrlUtil::IsSecureUrl($arFields['PHOTO'])) { $arFile = CFile::MakeFileArray($arFields['PHOTO']); if (is_array($arFile)) { $arFile += array('MODULE_ID' => 'crm'); } } if (is_array($arFile)) { $arFields['PHOTO'] = $arFile; } else { unset($arFields['PHOTO']); } } $arUserFields = $GLOBALS['USER_FIELD_MANAGER']->GetUserFields(CCrmContact::$sUFEntityID); foreach ($arUserFields as $FIELD_NAME => $arUserField) { if ($arUserField['USER_TYPE']['BASE_TYPE'] == 'file') { if (!isset($arFields[$FIELD_NAME])) { continue; } if (is_array($arFields[$FIELD_NAME])) { $arFiles = array(); foreach ($arFields[$FIELD_NAME] as $sFilePath) { if (!(CCrmUrlUtil::HasScheme($sFilePath) && CCrmUrlUtil::IsSecureUrl($sFilePath))) { continue; } $arFile = CFile::MakeFileArray($sFilePath); if (is_array($arFile)) { $arFile += array('MODULE_ID' => 'crm'); $arFiles[] = $arFile; } } $arFields[$FIELD_NAME] = $arFiles; } else { $arFile = null; $sFilePath = $arFields[$FIELD_NAME]; if (CCrmUrlUtil::HasScheme($sFilePath) && CCrmUrlUtil::IsSecureUrl($sFilePath)) { $arFile = CFile::MakeFileArray($sFilePath); if (is_array($arFile)) { $arFile += array('MODULE_ID' => 'crm'); } } if (is_array($arFile)) { $arFields[$FIELD_NAME] = $arFile; } else { unset($arFields[$FIELD_NAME]); } } } } $CCrmContact = new CCrmContact(); return $CCrmContact->Add($arFields) ? 'ok' : new CSoapFault('CCrmLead::Add', htmlspecialcharsbx(strip_tags(nl2br($arFields['RESULT_MESSAGE'])))); }
} } if ($success) { $DB->Commit(); } else { $DB->Rollback(); $arResult['ERROR_MESSAGE'] = !empty($arFields['RESULT_MESSAGE']) ? $arFields['RESULT_MESSAGE'] : GetMessage('UNKNOWN_ERROR'); } } if (empty($arResult['ERROR_MESSAGE']) && !$CCrmBizProc->StartWorkflow($arResult['ELEMENT']['ID'], $arBizProcParametersValues)) { $arResult['ERROR_MESSAGE'] = $CCrmBizProc->LAST_ERROR; } $ID = isset($arResult['ELEMENT']['ID']) ? $arResult['ELEMENT']['ID'] : 0; if (!empty($arResult['ERROR_MESSAGE'])) { ShowError($arResult['ERROR_MESSAGE']); $arResult['ELEMENT'] = CCrmComponentHelper::PrepareEntityFields(array_merge(array('ID' => $ID), $arFields), CCrmContact::GetFields()); } else { if (!isset($_POST['COMPANY_ID']) && isset($_POST['COMPANY_NAME'])) { if (CCrmCompany::CheckCreatePermission()) { $arFields = array('TITLE' => trim($_POST['COMPANY_NAME']), 'CONTACT_ID' => array($ID)); $CCrmCompany = new CCrmCompany(); $companyId = $CCrmCompany->Add($arFields); $CCrmContact->UpdateCompanyId($ID, $companyId); } } if (isset($_POST['apply'])) { if (CCrmContact::CheckUpdatePermission($ID)) { LocalRedirect(CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_CONTACT_EDIT'], array('contact_id' => $ID))); } } elseif (isset($_POST['saveAndAdd'])) { $redirectUrl = CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_CONTACT_EDIT'], array('contact_id' => 0));