Ejemplo n.º 1
0
 static function GetUserData($arParams = array())
 {
     $getDepartment = $arParams['DEPARTMENT'] == 'N' ? false : true;
     $getHrPhoto = $arParams['HR_PHOTO'] == 'Y' ? true : false;
     $getPhones = $arParams['PHONES'] == 'Y' ? true : false;
     $useCache = !$getPhones && $arParams['USE_CACHE'] == 'Y' ? true : false;
     $showOnline = $arParams['SHOW_ONLINE'] == 'N' ? false : true;
     $arFilter = array();
     if (isset($arParams['ID']) && is_array($arParams['ID']) && !empty($arParams['ID'])) {
         foreach ($arParams['ID'] as $key => $value) {
             if (intval($value) > 0) {
                 $arParams['ID'][$key] = intval($value);
             }
         }
         $arFilter['=ID'] = $arParams['ID'];
     } else {
         if (isset($arParams['ID']) && intval($arParams['ID']) > 0) {
             $arFilter['=ID'] = array(intval($arParams['ID']));
         }
     }
     if (empty($arFilter)) {
         return false;
     }
     $nameTemplate = self::GetUserNameTemplate(SITE_ID);
     $nameTemplateSite = CSite::GetNameFormat(false);
     $bIntranetEnable = false;
     if (IsModuleInstalled('intranet') && CModule::IncludeModule('intranet')) {
         $bIntranetEnable = true;
     }
     $bVoximplantEnable = IsModuleInstalled('voximplant');
     $bColorEnabled = IM\Color::isEnabled();
     if ($useCache) {
         global $USER;
         $obCache = new CPHPCache();
         $cache_ttl = intval($arParams['CACHE_TTL']);
         if ($cache_ttl <= 0) {
             $cache_ttl = defined("BX_COMP_MANAGED_CACHE") ? 18144000 : 1800;
         }
         $cache_id = 'user_data_v8_' . (is_object($USER) ? $USER->GetID() : 'AGENT') . '_' . implode('|', $arFilter['=ID']) . '_' . $nameTemplate . '_' . $nameTemplateSite . '_' . $getPhones . '_' . $getDepartment . '_' . $bIntranetEnable . '_' . $bVoximplantEnable . '_' . LANGUAGE_ID . '_' . $bColorEnabled;
         $cache_dir = '/bx/imc/userdata';
         if ($obCache->InitCache($cache_ttl, $cache_id, $cache_dir)) {
             $arCacheResult = $obCache->GetVars();
             if ($showOnline) {
                 $arOnline = CIMStatus::GetList(array('ID' => array_keys($arCacheResult['users']), 'GET_OFFLINE' => 'Y'));
             }
             foreach ($arCacheResult['users'] as $userId => $value) {
                 $arCacheResult['users'][$userId]['birthday'] = $bIntranetEnable ? CIntranetUtils::IsToday($arCacheResult['users'][$userId]['birthday']) : false;
                 if ($showOnline) {
                     $arCacheResult['users'][$userId]['status'] = isset($arOnline['users'][$userId]) ? $arOnline['users'][$userId]['status'] : 'offline';
                     $arCacheResult['users'][$userId]['idle'] = isset($arOnline['users'][$userId]) ? $arOnline['users'][$userId]['idle'] : 0;
                     $arCacheResult['users'][$userId]['mobileLastDate'] = isset($arOnline['users'][$userId]) ? $arOnline['users'][$userId]['mobileLastDate'] : 0;
                     if ($arOnline['users'][$userId]) {
                         $arCacheResult['users'][$userId]['color'] = $arOnline['users'][$userId]['color'];
                     }
                 }
                 if ($getHrPhoto && !isset($arCacheResult['hrphoto'])) {
                     $arPhotoHrTmp = CFile::ResizeImageGet($arCacheResult['source'][$userId]["PERSONAL_PHOTO"], array('width' => 200, 'height' => 200), BX_RESIZE_IMAGE_EXACT, false, false, true);
                     $arCacheResult['hrphoto'][$userId] = empty($arPhotoHrTmp['src']) ? '/bitrix/js/im/images/hidef-avatar-v3.png' : $arPhotoHrTmp['src'];
                     // TODO REMOVE DEFAULT
                 }
             }
             return $arCacheResult;
         }
     }
     $arSelect = array("ID", "LAST_NAME", "NAME", "LOGIN", "PERSONAL_PHOTO", "SECOND_NAME", "PERSONAL_BIRTHDAY", "WORK_POSITION", "PERSONAL_GENDER", "EXTERNAL_AUTH_ID");
     if ($getPhones) {
         $arSelect[] = 'WORK_PHONE';
         $arSelect[] = 'PERSONAL_PHONE';
         $arSelect[] = 'PERSONAL_MOBILE';
     }
     if ($bIntranetEnable) {
         $arSelect[] = 'UF_PHONE_INNER';
         $arSelect[] = 'UF_DEPARTMENT';
     }
     if ($bVoximplantEnable) {
         $arSelect[] = 'UF_VI_PHONE';
         $arSelect[] = 'UF_PHONE_INNER';
     }
     $arUsers = array();
     $arUserInGroup = array();
     $arPhones = array();
     $arWoUserInGroup = array();
     $arHrPhoto = array();
     $arSource = array();
     $query = new \Bitrix\Main\Entity\Query(\Bitrix\Main\UserTable::getEntity());
     $query->registerRuntimeField('', new \Bitrix\Main\Entity\ReferenceField('ref', 'Bitrix\\Im\\StatusTable', array('=this.ID' => 'ref.USER_ID')));
     $query->addSelect('ref.COLOR', 'COLOR')->addSelect('ref.STATUS', 'STATUS')->addSelect('ref.IDLE', 'IDLE')->addSelect('ref.MOBILE_LAST_DATE', 'MOBILE_LAST_DATE');
     $sago = Bitrix\Main\Application::getConnection()->getSqlHelper()->addSecondsToDateTime('-180');
     $query->registerRuntimeField('', new \Bitrix\Main\Entity\ExpressionField('IS_ONLINE_CUSTOM', 'CASE WHEN LAST_ACTIVITY_DATE > ' . $sago . ' THEN \'Y\' ELSE \'N\' END'));
     $query->addSelect('IS_ONLINE_CUSTOM');
     foreach ($arSelect as $value) {
         $query->addSelect($value);
     }
     foreach ($arFilter as $key => $value) {
         $query->addFilter($key, $value);
     }
     $resultQuery = $query->exec();
     global $USER;
     $arExtraUser = array();
     while ($arUser = $resultQuery->fetch()) {
         foreach ($arUser as $key => $value) {
             $arUser[$key] = !is_array($value) && !is_object($value) ? htmlspecialcharsEx($value) : $value;
         }
         $arExtraUser[$arUser["ID"]] = $arUser;
         $arSource[$arUser["ID"]]["PERSONAL_PHOTO"] = $arUser["PERSONAL_PHOTO"];
         $arPhotoTmp = CFile::ResizeImageGet($arUser["PERSONAL_PHOTO"], array('width' => 58, 'height' => 58), BX_RESIZE_IMAGE_EXACT, false, false, true);
         $color = self::GetUserColor($arUser["ID"], $arUser['PERSONAL_GENDER'] == 'M' ? 'M' : 'F');
         if (isset($arUser['COLOR']) && strlen($arUser['COLOR']) > 0) {
             $color = IM\Color::getColor($arUser['COLOR']);
         }
         if (!$color) {
             $color = self::GetUserColor($arUser["ID"], $arUser['PERSONAL_GENDER'] == 'M' ? 'M' : 'F');
         }
         $arUsers[$arUser["ID"]] = array('id' => $arUser["ID"], 'name' => CUser::FormatName($nameTemplateSite, $arUser, true, false), 'nameList' => CUser::FormatName($nameTemplate, $arUser, true, false), 'workPosition' => $arUser['WORK_POSITION'], 'color' => $color, 'avatar' => empty($arPhotoTmp['src']) ? '/bitrix/js/im/images/blank.gif' : $arPhotoTmp['src'], 'status' => 'offline', 'birthday' => $arUser['PERSONAL_BIRTHDAY'], 'gender' => $arUser['PERSONAL_GENDER'] == 'F' ? 'F' : 'M', 'phoneDevice' => $bVoximplantEnable && $arUser['UF_VI_PHONE'] == 'Y', 'extranet' => self::IsExtranet($arUser), 'network' => $arUser['EXTERNAL_AUTH_ID'] == self::NETWORK_AUTH_ID, 'profile' => CIMContactList::GetUserPath($arUser["ID"]));
         if ($getDepartment && is_array($arUser["UF_DEPARTMENT"]) && !empty($arUser["UF_DEPARTMENT"])) {
             foreach ($arUser["UF_DEPARTMENT"] as $dep_id) {
                 if (isset($arUserInGroup[$dep_id])) {
                     $arUserInGroup[$dep_id]['users'][] = $arUser["ID"];
                 } else {
                     $arUserInGroup[$dep_id] = array('id' => $dep_id, 'users' => array($arUser["ID"]));
                 }
             }
             if (isset($arWoUserInGroup['all'])) {
                 $arWoUserInGroup['all']['users'][] = $arUser["ID"];
             } else {
                 $arWoUserInGroup['all'] = array('id' => 'all', 'users' => array($arUser["ID"]));
             }
         }
         if ($getHrPhoto) {
             $arPhotoHrTmp = CFile::ResizeImageGet($arUser["PERSONAL_PHOTO"], array('width' => 200, 'height' => 200), BX_RESIZE_IMAGE_EXACT, false, false, true);
             $arHrPhoto[$arUser["ID"]] = empty($arPhotoHrTmp['src']) ? '/bitrix/js/im/images/hidef-avatar-v3.png' : $arPhotoHrTmp['src'];
             // TODO REMOVE DEFAULT
         }
         if ($getPhones) {
             if (CModule::IncludeModule('voximplant')) {
                 $result = CVoxImplantPhone::Normalize($arUser["WORK_PHONE"]);
                 if ($result) {
                     $arPhones[$arUser["ID"]]['WORK_PHONE'] = $arUser['WORK_PHONE'];
                 }
                 $result = CVoxImplantPhone::Normalize($arUser["PERSONAL_MOBILE"]);
                 if ($result) {
                     $arPhones[$arUser["ID"]]['PERSONAL_MOBILE'] = $arUser['PERSONAL_MOBILE'];
                 }
                 $result = CVoxImplantPhone::Normalize($arUser["PERSONAL_PHONE"]);
                 if ($result) {
                     $arPhones[$arUser["ID"]]['PERSONAL_PHONE'] = $arUser['PERSONAL_PHONE'];
                 }
                 $result = preg_replace("/[^0-9\\#\\*]/i", "", $arUser["UF_PHONE_INNER"]);
                 if ($result) {
                     $arPhones[$arUser["ID"]]['INNER_PHONE'] = $result;
                 }
             } else {
                 $arPhones[$arUser["ID"]]['WORK_PHONE'] = $arUser['WORK_PHONE'];
                 $arPhones[$arUser["ID"]]['PERSONAL_MOBILE'] = $arUser['PERSONAL_MOBILE'];
                 $arPhones[$arUser["ID"]]['PERSONAL_PHONE'] = $arUser['PERSONAL_PHONE'];
             }
         }
     }
     foreach ($arUsers as $userId => $arUser) {
         $arUsers[$userId]['birthday'] = $bIntranetEnable ? CIntranetUtils::IsToday($arUsers[$userId]['birthday']) : false;
         $arUsers[$userId]['status'] = $arExtraUser[$userId]['IS_ONLINE_CUSTOM'] == 'Y' ? $arExtraUser[$userId]['STATUS'] : 'offline';
         $arUsers[$userId]['idle'] = $arExtraUser[$userId]['IS_ONLINE_CUSTOM'] == 'Y' && is_object($arExtraUser[$userId]['IDLE']) ? $arExtraUser[$userId]['IDLE']->getTimestamp() : 0;
         $arUsers[$userId]['mobileLastDate'] = $arExtraUser[$userId]['IS_ONLINE_CUSTOM'] == 'Y' && is_object($arExtraUser[$userId]['MOBILE_LAST_DATE']) ? $arExtraUser[$userId]['MOBILE_LAST_DATE']->getTimestamp() : 0;
     }
     $result = array('users' => $arUsers, 'hrphoto' => $arHrPhoto, 'userInGroup' => $arUserInGroup, 'woUserInGroup' => $arWoUserInGroup, 'phones' => $arPhones, 'source' => $arSource);
     if ($useCache) {
         $cacheTag = array();
         if ($obCache->StartDataCache()) {
             if (defined("BX_COMP_MANAGED_CACHE")) {
                 global $CACHE_MANAGER;
                 $CACHE_MANAGER->StartTagCache($cache_dir);
                 $CACHE_MANAGER->RegisterTag("IM_CONTACT_LIST");
                 if (is_array($arParams['ID'])) {
                     foreach ($arParams['ID'] as $id) {
                         $tag = 'USER_NAME_' . intval($id);
                         if (!in_array($tag, $cacheTag)) {
                             $cacheTag[] = $tag;
                             $CACHE_MANAGER->RegisterTag($tag);
                         }
                     }
                 } elseif (isset($arParams['ID']) && intval($arParams['ID']) > 0) {
                     $tag = 'USER_NAME_' . intval($arParams['ID']);
                     $CACHE_MANAGER->RegisterTag($tag);
                 }
                 $CACHE_MANAGER->EndTagCache();
             }
             $obCache->EndDataCache($result);
             unset($cacheTag);
         }
     }
     unset($result['source']);
     return $result;
 }
Ejemplo n.º 2
0
if (!CModule::IncludeModule('voximplant')) {
    return;
}
if ($_SERVER["REQUEST_METHOD"] == "POST" && check_bitrix_sessid()) {
    if (isset($_POST["BLACKLIST_SETTINGS_BUTTON"])) {
        Bitrix\Main\Config\Option::set("voximplant", "blacklist_auto", isset($_POST["BLACKLIST_AUTO"]) ? "Y" : "N");
        $arBlacklistTime = isset($_POST["BLACKLIST_TIME"]) && intval($_POST["BLACKLIST_TIME"]) && $_POST["BLACKLIST_TIME"] > 0 ? intval($_POST["BLACKLIST_TIME"]) : 5;
        Bitrix\Main\Config\Option::set("voximplant", "blacklist_time", $arBlacklistTime);
        $arBlacklistCount = isset($_POST["BLACKLIST_COUNT"]) && intval($_POST["BLACKLIST_COUNT"]) && $_POST["BLACKLIST_COUNT"] > 0 ? intval($_POST["BLACKLIST_COUNT"]) : 5;
        Bitrix\Main\Config\Option::set("voximplant", "blacklist_count", $arBlacklistCount);
        Bitrix\Main\Config\Option::set("voximplant", "blacklist_user_id", $USER->GetID());
        LocalRedirect(POST_FORM_ACTION_URI);
    }
    if (isset($_POST["BLACKLIST_ADD_BUTTON"])) {
        $newNumber = substr($_POST["BLACKLIST_NEW_NUMBER"], 0, 20);
        $newNumber = CVoxImplantPhone::Normalize($newNumber);
        if ($newNumber) {
            $dbBlacklist = Bitrix\Voximplant\BlacklistTable::getList(array("filter" => array("PHONE_NUMBER" => $newNumber)));
            if (!$dbBlacklist->Fetch()) {
                Bitrix\Voximplant\BlacklistTable::add(array("PHONE_NUMBER" => $newNumber));
            }
            LocalRedirect(POST_FORM_ACTION_URI);
        } else {
            $arResult["ERROR"] = GetMessage("VI_BLACKLIST_NUMBER_ERROR");
        }
    }
    if (isset($_POST["action"]) && $_POST["action"] == "delete_number") {
        $dbBlacklist = Bitrix\Voximplant\BlacklistTable::getList(array("filter" => array("PHONE_NUMBER" => $_POST["number"])));
        if ($arBlacklist = $dbBlacklist->Fetch()) {
            Bitrix\Voximplant\BlacklistTable::delete($arBlacklist["ID"]);
        }
Ejemplo n.º 3
0
 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);
 }
Ejemplo n.º 4
0
 public static function StartCall($userId, $phoneNumber)
 {
     $phoneNormalized = CVoxImplantPhone::Normalize($phoneNumber);
     $userId = intval($userId);
     if ($userId <= 0 || !$phoneNormalized) {
         return false;
     }
     $call = VI\CallTable::add(array('CALL_ID' => 'temp.' . md5($userId . $phoneNumber) . time(), 'USER_ID' => $userId, 'CALLER_ID' => $phoneNormalized, 'STATUS' => VI\CallTable::STATUS_CONNECTING, 'DATE_CREATE' => new FieldType\DateTime()));
     $viHttp = new CVoxImplantHttp();
     $result = $viHttp->StartOutgoingCall($userId, $phoneNumber);
     VI\CallTable::update($call->GetId(), array('CALL_ID' => $result->call_id, 'ACCESS_URL' => $result->access_url, 'DATE_CREATE' => new FieldType\DateTime()));
     self::SendPullEvent(array('COMMAND' => 'outgoing', 'USER_ID' => $userId, 'PHONE_NUMBER' => $phoneNormalized, 'CALL_ID' => $result->call_id, 'CALL_DEVICE' => 'PHONE', 'EXTERNAL' => true));
     return $result ? true : false;
 }
Ejemplo n.º 5
0
 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;
         }
     }
 }
Ejemplo n.º 6
0
	static function GetUserData($arParams = Array())
	{
		$getDepartment = $arParams['DEPARTMENT'] == 'N' ? false : true;
		$getHrPhoto = $arParams['HR_PHOTO'] == 'Y' ? true : false;
		$getPhones = $arParams['PHONES'] == 'Y' ? true : false;
		$useCache = !$getPhones && $arParams['USE_CACHE'] == 'Y' ? true : false;
		$showOnline = $arParams['SHOW_ONLINE'] == 'N' ? false : true;

		$arFilter = Array();
		if (isset($arParams['ID']) && is_array($arParams['ID']) && !empty($arParams['ID']))
		{
			foreach ($arParams['ID'] as $key => $value)
				$arParams['ID'][$key] = intval($value);

			$arFilter['ID'] = implode('|', $arParams['ID']);

		}
		else if (isset($arParams['ID']) && intval($arParams['ID']) > 0)
		{
			$arFilter['ID'] = intval($arParams['ID']);
		}

		if (empty($arFilter))
			return false;

		$nameTemplate = self::GetUserNameTemplate(SITE_ID);
		$nameTemplateSite = CSite::GetNameFormat(false);

		$bIntranetEnable = false;
		if(IsModuleInstalled('intranet') && CModule::IncludeModule('intranet'))
			$bIntranetEnable = true;

		if($useCache)
		{
			global $USER;
			$obCache = new CPHPCache;
			$cache_ttl = intval($arParams['CACHE_TTL']);
			if ($cache_ttl <= 0)
				$cache_ttl = defined("BX_COMP_MANAGED_CACHE") ? 18144000 : 1800;
			$cache_id = 'user_data_'.(is_object($USER)? $USER->GetID(): 'AGENT').'_'.$arFilter['ID'].'_'.$nameTemplate.'_'.$nameTemplateSite.'_'.$getDepartment.'_'.LANGUAGE_ID;
			$cache_dir = '/bx/imc/recent';

			if($obCache->InitCache($cache_ttl, $cache_id, $cache_dir))
			{
				$arCacheResult = $obCache->GetVars();
				if ($showOnline)
					$arOnline = CIMStatus::GetList(Array('ID' => array_keys($arCacheResult['users'])));

				foreach ($arCacheResult['users'] as $userId => $value)
				{
					$arCacheResult['users'][$userId]['birthday'] = $bIntranetEnable? CIntranetUtils::IsToday($arCacheResult['users'][$userId]['birthday']): false;

					if ($showOnline)
					{
						$arCacheResult['users'][$userId]['status'] = isset($arOnline['users'][$userId])? $arOnline['users'][$userId]['status']: 'offline';
						$arCacheResult['users'][$userId]['idle'] = isset($arOnline['users'][$userId])? $arOnline['users'][$userId]['idle']: 0;
					}

					if ($getHrPhoto && !isset($arCacheResult['hrphoto']))
					{
						$arPhotoHrTmp = CFile::ResizeImageGet(
							$arCacheResult['source'][$userId]["PERSONAL_PHOTO"],
							array('width' => 200, 'height' => 200),
							BX_RESIZE_IMAGE_EXACT,
							false,
							false,
							true
						);
						$arCacheResult['hrphoto'][$userId] = empty($arPhotoHrTmp['src'])? '/bitrix/js/im/images/hidef-avatar-v2.png': $arPhotoHrTmp['src']; // TODO REMOVE DEFAULT
					}
				}
				return $arCacheResult;
			}
		}

		$arSelect = array('FIELDS' => array("ID", "LAST_NAME", "NAME", "LOGIN", "PERSONAL_PHOTO", "SECOND_NAME", "PERSONAL_BIRTHDAY", "WORK_POSITION", "PERSONAL_GENDER", "IS_ONLINE"), 'ONLINE_INTERVAL' => 180);
		if ($getPhones)
		{
			$arSelect['FIELDS'][] = 'WORK_PHONE';
			$arSelect['FIELDS'][] = 'PERSONAL_PHONE';
			$arSelect['FIELDS'][] = 'PERSONAL_MOBILE';
		}

		if($bIntranetEnable && $getDepartment)
			$arSelect['SELECT'] = array('UF_DEPARTMENT');

		$arUsers = array();
		$arUserInGroup = array();
		$arPhones = array();
		$arWoUserInGroup = array();
		$arHrPhoto = array();
		$arSource = array();
		$dbUsers = CUser::GetList(($sort_by = Array('is_online'=>'desc', 'last_name'=>'asc')), ($dummy=''), $arFilter, $arSelect);
		while ($arUser = $dbUsers->GetNext(true, false))
		{
			$arSource[$arUser["ID"]]["PERSONAL_PHOTO"] = $arUser["PERSONAL_PHOTO"];

			$arPhotoTmp = CFile::ResizeImageGet(
				$arUser["PERSONAL_PHOTO"],
				array('width' => 58, 'height' => 58),
				BX_RESIZE_IMAGE_EXACT,
				false,
				false,
				true
			);

			$arUsers[$arUser["ID"]] = Array(
				'id' => $arUser["ID"],
				'name' => CUser::FormatName($nameTemplateSite, $arUser, true, false),
				'nameList' => CUser::FormatName($nameTemplate, $arUser, true, false),
				'workPosition' => $arUser['WORK_POSITION'],
				'avatar' => empty($arPhotoTmp['src'])? '/bitrix/js/im/images/blank.gif': $arPhotoTmp['src'],
				'status' => 'offline',
				'birthday' => $arUser['PERSONAL_BIRTHDAY'],
				'gender' => $arUser['PERSONAL_GENDER'] == 'F'? 'F': 'M',
				'extranet' => self::IsExtranet($arUser),
				'profile' => CIMContactList::GetUserPath($arUser["ID"])
			);

			if(is_array($arUser["UF_DEPARTMENT"]) && !empty($arUser["UF_DEPARTMENT"]))
			{
				foreach($arUser["UF_DEPARTMENT"] as $dep_id)
				{
					if (isset($arUserInGroup[$dep_id]))
						$arUserInGroup[$dep_id]['users'][] = $arUser["ID"];
					else
						$arUserInGroup[$dep_id] = Array('id' => $dep_id, 'users' => Array($arUser["ID"]));
				}
				if (isset($arWoUserInGroup['all']))
					$arWoUserInGroup['all']['users'][] = $arUser["ID"];
				else
					$arWoUserInGroup['all'] = Array('id' => 'all', 'users' => Array($arUser["ID"]));
			}

			if ($getHrPhoto)
			{
				$arPhotoHrTmp = CFile::ResizeImageGet(
					$arUser["PERSONAL_PHOTO"],
					array('width' => 200, 'height' => 200),
					BX_RESIZE_IMAGE_EXACT,
					false,
					false,
					true
				);
				$arHrPhoto[$arUser["ID"]] = empty($arPhotoHrTmp['src'])? '/bitrix/js/im/images/hidef-avatar-v2.png': $arPhotoHrTmp['src']; // TODO REMOVE DEFAULT
			}

			if ($getPhones)
			{
				if (CModule::IncludeModule('voximplant'))
				{
					$result = CVoxImplantPhone::Normalize($arUser["WORK_PHONE"]);
					if ($result)
					{
						$arPhones[$arUser["ID"]]['WORK_PHONE'] = $arUser['WORK_PHONE'];
					}
					$result = CVoxImplantPhone::Normalize($arUser["PERSONAL_MOBILE"]);
					if ($result)
					{
						$arPhones[$arUser["ID"]]['PERSONAL_MOBILE'] = $arUser['PERSONAL_MOBILE'];
					}
					$result = CVoxImplantPhone::Normalize($arUser["PERSONAL_PHONE"]);
					if ($result)
					{
						$arPhones[$arUser["ID"]]['PERSONAL_PHONE'] = $arUser['PERSONAL_PHONE'];
					}
				}
				else
				{
					$arPhones[$arUser["ID"]]['WORK_PHONE'] = $arUser['WORK_PHONE'];
					$arPhones[$arUser["ID"]]['PERSONAL_MOBILE'] = $arUser['PERSONAL_MOBILE'];
					$arPhones[$arUser["ID"]]['PERSONAL_PHONE'] = $arUser['PERSONAL_PHONE'];
				}
			}
		}
		$arOnline = Array();
		if ($showOnline)
			$arOnline = CIMStatus::GetList(Array('ID' => array_keys($arUsers)));

		foreach ($arUsers as $userId => $arUser)
		{
			$arUsers[$userId]['birthday'] = $bIntranetEnable? CIntranetUtils::IsToday($arUsers[$userId]['birthday']): false;
			$arUsers[$userId]['status'] = isset($arOnline['users'][$userId])? $arOnline['users'][$userId]['status']: 'offline';
			$arUsers[$userId]['idle'] = isset($arOnline['users'][$userId])? $arOnline['users'][$userId]['idle']: 0;
		}

		$result = array('users' => $arUsers, 'hrphoto' => $arHrPhoto, 'userInGroup' => $arUserInGroup, 'woUserInGroup' => $arWoUserInGroup, 'phones' => $arPhones, 'source' => $arSource);

		if($useCache)
		{
			$cacheTag = array();
			if($obCache->StartDataCache())
			{
				if(defined("BX_COMP_MANAGED_CACHE"))
				{
					global $CACHE_MANAGER;
					$CACHE_MANAGER->StartTagCache($cache_dir);
					if(is_array($arParams['ID']))
					{
						foreach ($arParams['ID'] as $id)
						{
							$tag = 'USER_NAME_'.intval($id);
							if(!in_array($tag, $cacheTag))
							{
								$cacheTag[] = $tag;
								$CACHE_MANAGER->RegisterTag($tag);
							}
						}
					}
					elseif (isset($arParams['ID']) && intval($arParams['ID']) > 0)
					{
						$tag = 'USER_NAME_'.intval($arParams['ID']);
						$CACHE_MANAGER->RegisterTag($tag);
					}
					$CACHE_MANAGER->EndTagCache();
				}
				$obCache->EndDataCache($result);
				unset($cacheTag);
			}
		}
		unset($result['source']);

		return $result;
	}
Ejemplo n.º 7
0
 public static function GetByPhone($phone, $type = CVoxImplantPhone::PHONE_USER_INNER)
 {
     $phoneNormalize = CVoxImplantPhone::Normalize($phone);
     if (!$phoneNormalize) {
         $phoneNormalize = preg_replace("/[^0-9\\#\\*]/i", "", $phone);
     }
     $phone = $phoneNormalize;
     $result = Bitrix\Voximplant\PhoneTable::getList(array('select' => array('USER_ID', 'PHONE_MNEMONIC'), 'filter' => array('=PHONE_NUMBER' => $phone)));
     $userId = false;
     while ($row = $result->fetch()) {
         if ($row['PHONE_MNEMONIC'] == $type) {
             $userId = $row['USER_ID'];
             break;
         }
     }
     return $userId;
 }
Ejemplo n.º 8
0
 public static function ActivateCallerID($number, $code)
 {
     $number = CVoxImplantPhone::Normalize($number);
     if ($number && strlen($code) > 0) {
         $ViHttp = new CVoxImplantHttp();
         $result = $ViHttp->ActivateCallerID($number, $code);
         if ($result) {
             return array('NUMBER' => $result->callerid_number, 'VERIFIED' => $result->verified, 'VERIFIED_UNTIL' => $result->verified_until);
         }
     }
     return false;
 }