• Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/classes/general/ws_contact.php
  • Класс: \CCrmContactWS
  • Вызов: CCrmContactWS::Add
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']))));
}