public static function SynchronizeUserPhones() { $offset = intval(COption::GetOptionInt("voximplant", "sync_offset", 0)); $result = Bitrix\Main\UserTable::getList(array('select' => array('ID', 'WORK_PHONE', 'PERSONAL_PHONE', 'PERSONAL_MOBILE', 'UF_PHONE_INNER'), 'filter' => array('=Bitrix\\Voximplant\\Phone:USER.USER_ID' => 0), 'limit' => 100, 'offset' => $offset, 'order' => 'ID')); $count = 0; while ($user = $result->fetch()) { $user["WORK_PHONE"] = CVoxImplantPhone::Normalize($user["WORK_PHONE"]); if ($user["WORK_PHONE"]) { VI\PhoneTable::add(array('USER_ID' => intval($user['ID']), 'PHONE_NUMBER' => $user["WORK_PHONE"], 'PHONE_MNEMONIC' => "WORK_PHONE")); } $user["PERSONAL_PHONE"] = CVoxImplantPhone::Normalize($user["PERSONAL_PHONE"]); if ($user["PERSONAL_PHONE"]) { VI\PhoneTable::add(array('USER_ID' => intval($user['ID']), 'PHONE_NUMBER' => $user["PERSONAL_PHONE"], 'PHONE_MNEMONIC' => "PERSONAL_PHONE")); } $user["PERSONAL_MOBILE"] = CVoxImplantPhone::Normalize($user["PERSONAL_MOBILE"]); if ($user["PERSONAL_MOBILE"]) { VI\PhoneTable::add(array('USER_ID' => intval($user['ID']), 'PHONE_NUMBER' => $user["PERSONAL_MOBILE"], 'PHONE_MNEMONIC' => "PERSONAL_MOBILE")); } $user["UF_PHONE_INNER"] = intval(preg_replace("/[^0-9]/i", "", $user["UF_PHONE_INNER"])); if ($user["UF_PHONE_INNER"] > 0 && $user["UF_PHONE_INNER"] < 10000) { VI\PhoneTable::add(array('USER_ID' => intval($user['ID']), 'PHONE_NUMBER' => $user["UF_PHONE_INNER"], 'PHONE_MNEMONIC' => "UF_PHONE_INNER")); } $count++; } if ($count > 0) { $offset = $offset + 100; COption::SetOptionInt("voximplant", "sync_offset", $offset); return "CVoxImplantPhone::SynchronizeUserPhones();"; } else { return false; } }
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 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 OnUserDelete($ID) { VI\PhoneTable::deleteByUser($ID); global $USER_FIELD_MANAGER; if (CVoximplantUser::GetPhoneActive($ID)) { $viUser = new CVoximplantUser(); $viUser->UpdateUserPassword($ID, CVoxImplantUser::MODE_PHONE); $viUser->SetPhoneActive($ID, false); } $USER_FIELD_MANAGER->Update("USER", $ID, array('UF_VI_PASSWORD' => '', 'UF_VI_PHONE_PASSWORD' => '', 'UF_VI_PHONE' => 'N')); }