public static function AddLead($params) { if (!CModule::IncludeModule('crm')) { return false; } if (strlen($params['PHONE_NUMBER']) <= 0 || intval($params['USER_ID']) <= 0) { return false; } $result = VI\PhoneTable::getList(array('select' => array('USER_ID', 'PHONE_MNEMONIC'), 'filter' => array('=PHONE_NUMBER' => $params['PHONE_NUMBER']))); if ($row = $result->fetch()) { return false; } $title = GetMessage($params['INCOMING'] ? 'VI_CRM_CALL_INCOMING' : 'VI_CRM_CALL_OUTGOING'); $arFields = array('TITLE' => $params['PHONE_NUMBER'] . ' - ' . $title, 'OPENED' => 'Y', 'PHONE_WORK' => $params['PHONE_NUMBER']); $statuses = CCrmStatus::GetStatusList("SOURCE"); if (isset($statuses[$params['CRM_SOURCE']])) { $arFields['SOURCE_ID'] = $params['CRM_SOURCE']; } else { if (isset($statuses['CALL'])) { $arFields['SOURCE_ID'] = 'CALL'; } else { if (isset($statuses['OTHER'])) { $arFields['SOURCE_ID'] = 'OTHER'; } } } $portalNumbers = CVoxImplantConfig::GetPortalNumbers(); $portalNumber = isset($portalNumbers[$params['SEARCH_ID']]) ? $portalNumbers[$params['SEARCH_ID']] : ''; if ($portalNumber) { $arFields['SOURCE_DESCRIPTION'] = GetMessage('VI_CRM_CALL_TO_PORTAL_NUMBER', array('#PORTAL_NUMBER#' => $portalNumber)); } $arFields['FM'] = CCrmFieldMulti::PrepareFields($arFields); $CCrmLead = new CCrmLead(false); $ID = $CCrmLead->Add($arFields, true, array('CURRENT_USER' => $params['USER_ID'], 'DISABLE_USER_FIELD_CHECK' => true)); $arErrors = array(); CCrmBizProcHelper::AutoStartWorkflows(CCrmOwnerType::Lead, $ID, CCrmBizProcEventType::Create, $arErrors); CVoxImplantHistory::WriteToLog($arFields, 'LEAD CREATED'); return $ID; }
public function GetDialogInfo($phone, $chatTitle = '', $getPhoto = true) { $phoneNormalize = CVoxImplantPhone::Normalize($phone); if (!$phoneNormalize) { $phoneNormalize = preg_replace("/[^0-9\\#\\*]/i", "", $phone); } $phone = $phoneNormalize; $hrPhoto = array(); $openChat = true; $result = VI\PhoneTable::getList(array('select' => array('USER_ID', 'PHONE_MNEMONIC'), 'filter' => array('=PHONE_NUMBER' => $phone))); $userId = false; while ($row = $result->fetch()) { if (!$userId && $row['PHONE_MNEMONIC'] != 'WORK_PHONE') { $userId = $row['USER_ID']; $openChat = false; } else { if (!$userId && $row['PHONE_MNEMONIC'] == 'WORK_PHONE') { $openChat = true; } } } if ($userId == $this->userId) { $openChat = true; } $dialogId = 0; if (CModule::IncludeModule('im')) { if (CVoxImplantConfig::GetChatAction() == CVoxImplantConfig::INTERFACE_CHAT_NONE) { } else { if ($openChat) { $entityId = $phone; if (CVoxImplantConfig::GetChatAction() == CVoxImplantConfig::INTERFACE_CHAT_APPEND) { $entityId = 'UNIFY_CALL_CHAT'; $chatTitle = GetMessage('VI_CALL_CHAT_UNIFY'); } $result = IM\ChatTable::getList(array('select' => array('ID', 'AVATAR'), 'filter' => array('=ENTITY_TYPE' => 'CALL', '=ENTITY_ID' => $entityId, '=AUTHOR_ID' => $this->userId))); if ($row = $result->fetch()) { $dialogId = 'chat' . $row['ID']; $avatarId = $row['AVATAR']; } else { $CIMChat = new CIMChat($this->userId); $chatId = $CIMChat->Add(array('TITLE' => $chatTitle != '' ? $chatTitle : $phone, 'USERS' => false, 'CALL_NUMBER' => $entityId == 'UNIFY_CALL_CHAT' ? '' : $entityId, 'ENTITY_TYPE' => 'CALL', 'ENTITY_ID' => $entityId)); if ($chatId) { $dialogId = 'chat' . $chatId; $avatarId = $CIMChat->lastAvatarId; } } if ($getPhoto && intval($avatarId) > 0) { $arPhotoHrTmp = CFile::ResizeImageGet($avatarId, array('width' => 200, 'height' => 200), BX_RESIZE_IMAGE_EXACT, false, false, true); $hrPhoto[$dialogId] = empty($arPhotoHrTmp['src']) ? '/bitrix/js/im/images/hidef-avatar-v2.png' : $arPhotoHrTmp['src']; } } else { if ($userId) { if ($getPhoto) { $userData = CIMContactList::GetUserData(array('ID' => $userId, 'DEPARTMENT' => 'N', 'HR_PHOTO' => 'Y')); $hrPhoto = $userData['hrphoto']; } $dialogId = $userId; } } } } if (!$dialogId) { $this->error = new CVoxImplantError(__METHOD__, 'ERROR_NEW_CHAT', GetMessage('VI_ERROR_NEW_CHAT')); return false; } //foreach(GetModuleEvents("voximplant", "OnGetDialogInfo", true) as $arEvent) // ExecuteModuleEventEx($arEvent, array('USER_ID' => $this->userId, 'DIALOG_ID' => $dialogId)); return array('DIALOG_ID' => $dialogId, 'HR_PHOTO' => $hrPhoto); }
public function OnBeforeUserUpdate(&$arFields) { if ($arFields["ID"] > 0) { $arPhones = array(); $arCorrectPhones = array(); $dbViPhone = VI\PhoneTable::getList(array('select' => array('ID', 'PHONE_MNEMONIC', 'PHONE_NUMBER'), 'filter' => array('=USER_ID' => intval($arFields['ID'])))); while ($phone = $dbViPhone->fetch()) { if (strlen($phone['PHONE_MNEMONIC']) > 0) { $arPhones[$phone['PHONE_MNEMONIC']] = $phone; } } global $APPLICATION; $error = false; if (is_set($arFields, "WORK_PHONE")) { if (strlen($arFields["WORK_PHONE"]) > 0) { $arCorrectPhones["WORK_PHONE"] = CVoxImplantPhone::Normalize($arFields["WORK_PHONE"]); if (!$arCorrectPhones["WORK_PHONE"]) { $APPLICATION->throwException(GetMessage('ERROR_WORK_PHONE') . ' ' . GetMessage('ERROR_NUMBER')); $error = true; } } else { $arCorrectPhones["WORK_PHONE"] = ''; } } if (is_set($arFields, "PERSONAL_PHONE")) { if (strlen($arFields["PERSONAL_PHONE"]) > 0) { $arCorrectPhones["PERSONAL_PHONE"] = CVoxImplantPhone::Normalize($arFields["PERSONAL_PHONE"]); if (!$arCorrectPhones["PERSONAL_PHONE"]) { $APPLICATION->throwException(GetMessage('ERROR_PERSONAL_PHONE') . ' ' . GetMessage('ERROR_NUMBER')); $error = true; } } else { $arCorrectPhones["PERSONAL_PHONE"] = ''; } } if (is_set($arFields, "PERSONAL_MOBILE")) { if (strlen($arFields["PERSONAL_MOBILE"]) > 0) { $arCorrectPhones["PERSONAL_MOBILE"] = CVoxImplantPhone::Normalize($arFields["PERSONAL_MOBILE"]); if (!$arCorrectPhones["PERSONAL_MOBILE"]) { $APPLICATION->throwException(GetMessage('ERROR_PERSONAL_MOBILE') . ' ' . GetMessage('ERROR_NUMBER')); $error = true; } } else { $arCorrectPhones["PERSONAL_MOBILE"] = ''; } } if (is_set($arFields, "UF_PHONE_INNER")) { if (strlen($arFields["UF_PHONE_INNER"]) > 0) { $phoneInner = intval(preg_replace("/[^0-9]/i", "", $arFields["UF_PHONE_INNER"])); if ($phoneInner > 0 && $phoneInner < 10000) { $result = \Bitrix\Main\UserTable::getList(array('select' => array('COUNT'), 'filter' => array('!=ID' => intval($arFields['ID']), '=UF_PHONE_INNER' => $phoneInner, '=ACTIVE' => 'Y'), 'runtime' => array('COUNT' => array('data_type' => 'integer', 'expression' => array('COUNT(1)'))))); $data = $result->fetch(); if ($data['COUNT'] > 0) { $APPLICATION->throwException(GetMessage('ERROR_PHONE_INNER')); $error = true; } else { $arFields["UF_PHONE_INNER"] = $phoneInner; $arCorrectPhones["UF_PHONE_INNER"] = $phoneInner; } } else { $APPLICATION->throwException(GetMessage('ERROR_PHONE_INNER_2')); $error = true; } } else { $arCorrectPhones["UF_PHONE_INNER"] = ''; } } if ($arFields["ACTIVE"] == 'N' && CVoximplantUser::GetPhoneActive($arFields['ID'])) { $viUser = new CVoximplantUser(); $viUser->UpdateUserPassword($arFields['ID'], CVoxImplantUser::MODE_PHONE); $viUser->SetPhoneActive($arFields['ID'], false); } if (!$error) { foreach ($arCorrectPhones as $mnemonic => $phone) { if (isset($arPhones[$mnemonic])) { if ($phone != $arPhones[$mnemonic]['PHONE_NUMBER']) { if (strlen($phone) == 0) { VI\PhoneTable::delete($arPhones[$mnemonic]['ID']); } else { VI\PhoneTable::update($arPhones[$mnemonic]['ID'], array('PHONE_NUMBER' => $phone)); } } } else { if (strlen($phone) > 0) { VI\PhoneTable::add(array('USER_ID' => intval($arFields['ID']), 'PHONE_NUMBER' => $phone, 'PHONE_MNEMONIC' => $mnemonic)); } } } } else { return false; } } }