• Модуль: voximplant
  • Путь к файлу: ~/bitrix/modules/voximplant/classes/general/vi_event.php
  • Класс: CVoxImplantEvent
  • Вызов: CVoxImplantEvent::OnBeforeUserAdd
static function OnBeforeUserAdd(&$arFields)
{
	global $APPLICATION;
	$error = false;
	if(is_set($arFields, "WORK_PHONE"))
	{
		if ($arFields["WORK_PHONE"] <> '')
		{
			$arCorrectPhones["WORK_PHONE"] = CVoxImplantPhone::Normalize($arFields["WORK_PHONE"]);
			if (!$arCorrectPhones["WORK_PHONE"])
			{
				$APPLICATION->throwException(Loc::getMessage('ERROR_WORK_PHONE').' '.Loc::getMessage('ERROR_NUMBER'));
				$error = true;
			}
		}
		else
		{
			$arCorrectPhones["WORK_PHONE"] = '';
		}
	}
	if(is_set($arFields, "PERSONAL_PHONE"))
	{
		if ($arFields["PERSONAL_PHONE"] <> '')
		{
			$arCorrectPhones["PERSONAL_PHONE"] = CVoxImplantPhone::Normalize($arFields["PERSONAL_PHONE"]);
			if (!$arCorrectPhones["PERSONAL_PHONE"])
			{
				$APPLICATION->throwException(Loc::getMessage('ERROR_PERSONAL_PHONE').' '.Loc::getMessage('ERROR_NUMBER'));
				$error = true;
			}
		}
		else
		{
			$arCorrectPhones["PERSONAL_PHONE"] = '';
		}
	}
	if(is_set($arFields, "PERSONAL_MOBILE"))
	{
		if ($arFields["PERSONAL_MOBILE"] <> '')
		{
			$arCorrectPhones["PERSONAL_MOBILE"] = CVoxImplantPhone::Normalize($arFields["PERSONAL_MOBILE"]);
			if (!$arCorrectPhones["PERSONAL_MOBILE"])
			{
				$APPLICATION->throwException(Loc::getMessage('ERROR_PERSONAL_MOBILE').' '.Loc::getMessage('ERROR_NUMBER'));
				$error = true;
			}
		}
		else
		{
			$arCorrectPhones["PERSONAL_MOBILE"] = '';
		}
	}
	
	if(is_set($arFields, "UF_PHONE_INNER"))
	{
		if ($arFields["UF_PHONE_INNER"] <> '')
		{
			$phoneInner = preg_replace("/D/", "", $arFields["UF_PHONE_INNER"]);
			$phoneLength = mb_strlen($phoneInner);
			if ($phoneLength > 0 && $phoneLength < 5)
			{
				$existingEntity = CVoxImplantIncoming::getByInternalPhoneNumber($phoneInner);
				if ($existingEntity && !($existingEntity['ENTITY_TYPE'] === 'user' && $existingEntity['ENTITY_ID'] == $arFields['ID']))
				{
					$APPLICATION->throwException(Loc::getMessage('ERROR_PHONE_INNER_IN_USAGE'));
					$error = true;
				}
				else
				{
					$arFields["UF_PHONE_INNER"] = $phoneInner;
				}
			}
			else
			{
				$APPLICATION->throwException(Loc::getMessage('ERROR_PHONE_INNER_2'));
				$error = true;
			}
		}
		$arCorrectPhones["UF_PHONE_INNER"] = '';
	}

	if ($error)
		return false;
}