public function filter()
 {
     $daysDontAuth = $this->getFieldValue('DAYS_DONT_AUTH');
     if (!is_numeric($daysDontAuth)) {
         $daysDontAuth = 90;
     }
     $dateFrom = new \Bitrix\Main\Type\DateTime();
     $dateTo = new \Bitrix\Main\Type\DateTime();
     $dateFrom->setTime(0, 0, 0)->add('-' . $daysDontAuth . ' days');
     $dateTo->setTime(0, 0, 0)->add('1 days')->add('-' . $daysDontAuth . ' days');
     if ($this->isRunForOldData()) {
         $filter = array('!LAST_LOGIN' => null, '<LAST_LOGIN' => $dateTo);
     } else {
         $filter = array('>LAST_LOGIN' => $dateFrom, '<LAST_LOGIN' => $dateTo);
     }
     $filter['=ACTIVE'] = true;
     $userListDb = \Bitrix\Main\UserTable::getList(array('select' => array('EMAIL', 'ID', 'NAME'), 'filter' => $filter, 'order' => array('ID' => 'ASC')));
     if ($userListDb->getSelectedRowsCount() > 0) {
         $userListDb->addFetchDataModifier(array($this, 'getFetchDataModifier'));
         $this->recipient = $userListDb;
         return true;
     } else {
         return false;
     }
 }
 /**
  * Removes all composite cache
  * Be careful with this method
  * @return void
  */
 public static function deleteAllCache()
 {
     $users = UserTable::getList(array("select" => array("ID")));
     while ($user = $users->fetch()) {
         self::deleteUserCache($user["ID"]);
     }
 }
Exemple #3
0
 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 static function onBeforeAdd(Entity\Event $event)
 {
     $result = new Entity\EventResult();
     $data = $event->getParameter("fields");
     if (isset($data["USER_ID"]) && isset($data['PASSWORD'])) {
         $salt = md5(\CMain::GetServerUniqID() . uniqid());
         $password = $salt . md5($salt . $data['PASSWORD']);
         $modified = array('PASSWORD' => $password);
         $user = Main\UserTable::getRowById($data["USER_ID"]);
         if ($user !== null) {
             $realm = defined('BX_HTTP_AUTH_REALM') ? BX_HTTP_AUTH_REALM : "Bitrix Site Manager";
             $digest = md5($user["LOGIN"] . ':' . $realm . ':' . $data['PASSWORD']);
             $modified['DIGEST_PASSWORD'] = $digest;
         }
         $result->modifyFields($modified);
     }
     return $result;
 }
 /**
  * @inheritdoc
  */
 public function generateRow(&$row, $data)
 {
     $userId = $this->getValue();
     $strUser = '';
     if (!empty($userId) && $userId != 0) {
         $rsUser = UserTable::getById($userId);
         $user = $rsUser->fetch();
         $strUser = '******' . $user['ID'] . '">' . $user['ID'] . '</a>]';
         if ($user['EMAIL']) {
             $strUser .= ' (' . $user['EMAIL'] . ')';
         }
         $strUser .= ' ' . static::prepareToOutput($user['NAME']) . '&nbsp;' . static::prepareToOutput($user['LAST_NAME']);
     }
     if ($strUser) {
         $row->AddViewField($this->getCode(), $strUser);
     } else {
         $row->AddViewField($this->getCode(), '');
     }
 }
 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;
 }
 public static function SearchUsers($search, $nameTemplate = "", $bSelf = true, $bEmployeesOnly = false, $bExtranetOnly = false, $departmentId = false)
 {
     CUtil::JSPostUnescape();
     $arUsers = array();
     $search = trim($search);
     if (strlen($search) <= 0 || !GetFilterQuery("TEST", $search)) {
         return $arUsers;
     }
     $bIntranetEnable = IsModuleInstalled('intranet');
     $bExtranetEnable = CModule::IncludeModule('extranet');
     $bBitrix24Enable = IsModuleInstalled('bitrix24');
     $bExtranetUser = $bExtranetEnable && !CExtranet::IsIntranetUser();
     $current_user_id = intval($GLOBALS["USER"]->GetID());
     if ($bExtranetEnable) {
         CSocNetTools::InitGlobalExtranetArrays();
     }
     $arSearchValue = preg_split('/\\s+/', trim($search));
     array_walk($arSearchValue, array('CSocNetLogDestination', '__percent_walk'));
     $arFilter = array(array('LOGIC' => 'OR', '%=NAME' => $arSearchValue, '%=LAST_NAME' => $arSearchValue, '%=EMAIL' => $search, '%=LOGIN' => $search), 'ACTIVE' => 'Y');
     if ($bIntranetEnable || COption::GetOptionString("main", "new_user_registration_email_confirmation", "N") == "Y") {
         $arFilter["CONFIRM_CODE"] = false;
     }
     if ($bEmployeesOnly || $bBitrix24Enable && !$bExtranetEnable) {
         $arFilter["!UF_DEPARTMENT"] = false;
     } elseif ($bExtranetOnly) {
         $arFilter["UF_DEPARTMENT"] = false;
     }
     if ($bIntranetEnable && $bExtranetEnable && ($bExtranetUser || !$bEmployeesOnly)) {
         $arFilteredUserIDs = CExtranet::GetMyGroupsUsersSimple(CExtranet::GetExtranetSiteID());
         if ($bExtranetUser) {
             $arFilter["ID"] = array_merge(array($current_user_id), $arFilteredUserIDs);
         } else {
             $arFilter[] = array('LOGIC' => 'OR', '!UF_DEPARTMENT' => false, 'ID' => array_merge(array($current_user_id), $arFilteredUserIDs));
         }
     }
     $arSelect = array("ID", "NAME", "LAST_NAME", "SECOND_NAME", "EMAIL", "LOGIN", "WORK_POSITION", "PERSONAL_PROFESSION", "PERSONAL_PHOTO", "PERSONAL_GENDER");
     if ($bIntranetEnable) {
         $arSelect[] = 'UF_DEPARTMENT';
     }
     if (intval($departmentId) > 0) {
         $acc = new CAccess();
     }
     $rsUser = \Bitrix\Main\UserTable::getList(array('order' => array('LAST_NAME' => 'ASC'), 'filter' => $arFilter, 'select' => $arSelect, 'limit' => 20, 'data_doubling' => false));
     while ($arUser = $rsUser->fetch()) {
         if (!$bSelf && $current_user_id == $arUser['ID']) {
             continue;
         }
         if (is_object($acc)) {
             $acc->UpdateCodes(array("USER_ID" => $arUser["ID"]));
             $arUserGroupCode = CAccess::GetUserCodesArray($arUser["ID"], array("PROVIDER_ID" => "intranet"));
             if (!in_array("DR" . intval($departmentId), $arUserGroupCode)) {
                 continue;
             }
         }
         $sName = CUser::FormatName(empty($nameTemplate) ? CSite::GetNameFormat(false) : $nameTemplate, $arUser, true, true);
         $arFileTmp = CFile::ResizeImageGet($arUser["PERSONAL_PHOTO"], array('width' => 32, 'height' => 32), BX_RESIZE_IMAGE_EXACT, false);
         $arUsers['U' . $arUser["ID"]] = array('id' => 'U' . $arUser["ID"], 'entityId' => $arUser["ID"], 'name' => $sName, 'avatar' => empty($arFileTmp['src']) ? '' : $arFileTmp['src'], 'desc' => $arUser['WORK_POSITION'] ? $arUser['WORK_POSITION'] : ($arUser['PERSONAL_PROFESSION'] ? $arUser['PERSONAL_PROFESSION'] : '&nbsp;'), 'isExtranet' => isset($GLOBALS["arExtranetUserID"]) && is_array($GLOBALS["arExtranetUserID"]) && in_array($arUser["ID"], $GLOBALS["arExtranetUserID"]) ? "Y" : "N");
         $checksum = md5(serialize($arUsers['U' . $arUser["ID"]]));
         $arUsers['U' . $arUser["ID"]]['checksum'] = $checksum;
     }
     return $arUsers;
 }
Exemple #8
0
 /**
  * Return user login
  * If custom login not available it will be fetched from DB
  *
  * @return string
  */
 public function getUserLogin()
 {
     if ($this->userLogin === null && $this->userId) {
         $this->userLogin = \Bitrix\Main\UserTable::query()->addFilter('=ID', $this->getUserId())->addSelect('LOGIN')->exec()->fetch();
         $this->userLogin = $this->userLogin['LOGIN'];
     }
     return $this->userLogin;
 }
Exemple #9
0
 /**
  * Performs the user authorization:
  *    fills session parameters;
  *    remembers auth;
  *    spreads auth through sites
  */
 function Authorize($id, $bSave = false, $bUpdate = true, $applicationId = null)
 {
     /** @global CMain $APPLICATION */
     global $DB, $APPLICATION;
     unset($_SESSION["SESS_OPERATIONS"]);
     unset($_SESSION["MODULE_PERMISSIONS"]);
     $_SESSION["BX_LOGIN_NEED_CAPTCHA"] = false;
     $strSql = "SELECT U.* " . "FROM b_user U  " . "WHERE U.ID='" . intval($id) . "' ";
     $result = $DB->Query($strSql, false, "FILE: " . __FILE__ . "<br> LINE: " . __LINE__);
     if ($arUser = $result->Fetch()) {
         $this->justAuthorized = true;
         $_SESSION["SESS_AUTH"]["AUTHORIZED"] = "Y";
         $_SESSION["SESS_AUTH"]["USER_ID"] = $arUser["ID"];
         $_SESSION["SESS_AUTH"]["LOGIN"] = $arUser["LOGIN"];
         $_SESSION["SESS_AUTH"]["LOGIN_COOKIES"] = $arUser["LOGIN"];
         $_SESSION["SESS_AUTH"]["EMAIL"] = $arUser["EMAIL"];
         $_SESSION["SESS_AUTH"]["PASSWORD_HASH"] = $arUser["PASSWORD"];
         $_SESSION["SESS_AUTH"]["TITLE"] = $arUser["TITLE"];
         $_SESSION["SESS_AUTH"]["NAME"] = $arUser["NAME"] . ($arUser["NAME"] == '' || $arUser["LAST_NAME"] == '' ? "" : " ") . $arUser["LAST_NAME"];
         $_SESSION["SESS_AUTH"]["FIRST_NAME"] = $arUser["NAME"];
         $_SESSION["SESS_AUTH"]["SECOND_NAME"] = $arUser["SECOND_NAME"];
         $_SESSION["SESS_AUTH"]["LAST_NAME"] = $arUser["LAST_NAME"];
         $_SESSION["SESS_AUTH"]["PERSONAL_PHOTO"] = $arUser["PERSONAL_PHOTO"];
         $_SESSION["SESS_AUTH"]["PERSONAL_GENDER"] = $arUser["PERSONAL_GENDER"];
         $_SESSION["SESS_AUTH"]["ADMIN"] = false;
         $_SESSION["SESS_AUTH"]["CONTROLLER_ADMIN"] = false;
         $_SESSION["SESS_AUTH"]["POLICY"] = CUser::GetGroupPolicy($arUser["ID"]);
         $_SESSION["SESS_AUTH"]["AUTO_TIME_ZONE"] = trim($arUser["AUTO_TIME_ZONE"]);
         $_SESSION["SESS_AUTH"]["TIME_ZONE"] = $arUser["TIME_ZONE"];
         $_SESSION["SESS_AUTH"]["APPLICATION_ID"] = $applicationId;
         $_SESSION["SESS_AUTH"]["BX_USER_ID"] = $arUser["BX_USER_ID"];
         // groups
         $_SESSION["SESS_AUTH"]["GROUPS"] = Main\UserTable::getUserGroupIds($arUser["ID"]);
         foreach ($_SESSION["SESS_AUTH"]["GROUPS"] as $groupId) {
             if ($groupId == 1) {
                 $_SESSION["SESS_AUTH"]["ADMIN"] = true;
                 break;
             }
         }
         //sometimes we don't need to update db (REST)
         if ($bUpdate) {
             $tz = '';
             if (CTimeZone::Enabled()) {
                 if (!CTimeZone::IsAutoTimeZone(trim($arUser["AUTO_TIME_ZONE"])) || CTimeZone::GetCookieValue() !== null) {
                     $tz = ', TIME_ZONE_OFFSET = ' . CTimeZone::GetOffset();
                 }
             }
             $bxUid = '';
             if (!empty($_COOKIE['BX_USER_ID']) && preg_match('/^[0-9a-f]{32}$/', $_COOKIE['BX_USER_ID'])) {
                 if ($_COOKIE['BX_USER_ID'] != $arUser['BX_USER_ID']) {
                     // save new bxuid value
                     $bxUid = ", BX_USER_ID = '" . $_COOKIE['BX_USER_ID'] . "'";
                     $arUser['BX_USER_ID'] = $_COOKIE['BX_USER_ID'];
                     $_SESSION["SESS_AUTH"]["BX_USER_ID"] = $_COOKIE['BX_USER_ID'];
                 }
             }
             $DB->Query("\n\t\t\t\t\tUPDATE b_user SET\n\t\t\t\t\t\tSTORED_HASH = NULL,\n\t\t\t\t\t\tLAST_LOGIN = "******",\n\t\t\t\t\t\tTIMESTAMP_X = TIMESTAMP_X,\n\t\t\t\t\t\tLOGIN_ATTEMPTS = 0\n\t\t\t\t\t\t" . $tz . "\n\t\t\t\t\t\t" . $bxUid . "\n\t\t\t\t\tWHERE\n\t\t\t\t\t\tID=" . $arUser["ID"]);
             if ($applicationId === null && ($bSave || COption::GetOptionString("main", "auth_multisite", "N") == "Y")) {
                 $hash = $this->GetSessionHash();
                 $secure = COption::GetOptionString("main", "use_secure_password_cookies", "N") == "Y" && CMain::IsHTTPS();
                 if ($bSave) {
                     $period = time() + 60 * 60 * 24 * 30 * 60;
                     $spread = BX_SPREAD_SITES | BX_SPREAD_DOMAIN;
                 } else {
                     $period = 0;
                     $spread = BX_SPREAD_SITES;
                 }
                 $APPLICATION->set_cookie("UIDH", $hash, $period, '/', false, $secure, $spread, false, true);
                 $APPLICATION->set_cookie("UIDL", $arUser["LOGIN"], $period, '/', false, $secure, $spread, false, true);
                 $stored_id = CUser::CheckStoredHash($arUser["ID"], $hash);
                 if ($stored_id) {
                     $DB->Query("UPDATE b_user_stored_auth SET\n\t\t\t\t\t\t\t\tLAST_AUTH=" . $DB->CurrentTimeFunction() . ",\n\t\t\t\t\t\t\t\t" . ($this->bLoginByHash ? "" : "TEMP_HASH='" . ($bSave ? "N" : "Y") . "', ") . "\n\t\t\t\t\t\t\t\tIP_ADDR='" . sprintf("%u", ip2long($_SERVER["REMOTE_ADDR"])) . "'\n\t\t\t\t\t\t\tWHERE ID=" . $stored_id);
                 } else {
                     $arFields = array('USER_ID' => $arUser["ID"], '~DATE_REG' => $DB->CurrentTimeFunction(), '~LAST_AUTH' => $DB->CurrentTimeFunction(), 'TEMP_HASH' => $bSave ? "N" : "Y", '~IP_ADDR' => sprintf("%u", ip2long($_SERVER["REMOTE_ADDR"])), 'STORED_HASH' => $hash);
                     $stored_id = CDatabase::Add("b_user_stored_auth", $arFields);
                 }
                 $_SESSION["SESS_AUTH"]["STORED_AUTH_ID"] = $stored_id;
             }
         }
         $this->admin = null;
         $arParams = array("user_fields" => $arUser, "save" => $bSave, "update" => $bUpdate, "applicationId" => $applicationId);
         foreach (GetModuleEvents("main", "OnAfterUserAuthorize", true) as $arEvent) {
             ExecuteModuleEventEx($arEvent, array($arParams));
         }
         foreach (GetModuleEvents("main", "OnUserLogin", true) as $arEvent) {
             ExecuteModuleEventEx($arEvent, array($_SESSION["SESS_AUTH"]["USER_ID"]));
         }
         if (COption::GetOptionString("main", "event_log_login_success", "N") === "Y") {
             CEventLog::Log("SECURITY", "USER_AUTHORIZE", "main", $arUser["ID"], $applicationId);
         }
         CHTMLPagesCache::OnUserLogin();
         return true;
     }
     return false;
 }
Exemple #10
0
 $clearStoreUser = (int) Option::get('catalog', 'clear_store_user');
 if ($clearStoreUser < 0) {
     $clearStoreUser = 0;
 }
 $userListID[$clearStoreUser] = true;
 if (isset($userListID[0])) {
     unset($userListID[0]);
 }
 if (!empty($userListID)) {
     $strClearQuantityDate = Option::get('catalog', 'clear_quantity_date');
     $strClearQuantityReservedDate = Option::get('catalog', 'clear_reserved_quantity_date');
     $strClearStoreDate = Option::get('catalog', 'clear_store_date');
     $arUserList = array();
     $strNameFormat = CSite::GetNameFormat(true);
     $canViewUserList = $USER->CanDoOperation('view_subordinate_users') || $USER->CanDoOperation('view_all_users') || $USER->CanDoOperation('edit_all_users') || $USER->CanDoOperation('edit_subordinate_users');
     $userIterator = Main\UserTable::getList(array('select' => array('ID', 'LOGIN', 'NAME', 'LAST_NAME', 'SECOND_NAME'), 'filter' => array('ID' => array_keys($userListID))));
     while ($arOneUser = $userIterator->fetch()) {
         $arOneUser['ID'] = (int) $arOneUser['ID'];
         if ($canViewUserList) {
             $arUserList[$arOneUser['ID']] = '<a href="/bitrix/admin/user_edit.php?lang=' . LANGUAGE_ID . '&ID=' . $arOneUser['ID'] . '">' . CUser::FormatName($strNameFormat, $arOneUser) . '</a>';
         } else {
             $arUserList[$arOneUser['ID']] = CUser::FormatName($strNameFormat, $arOneUser);
         }
     }
     unset($arOneUser, $userIterator, $canViewUserList);
     if (isset($arUserList[$clearQuantityUser])) {
         $strQuantityUser = $arUserList[$clearQuantityUser];
     }
     if (isset($arUserList[$clearQuantityReservedUser])) {
         $strQuantityReservedUser = $arUserList[$clearQuantityReservedUser];
     }
Exemple #11
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;
         }
     }
 }
Exemple #12
0
         $rsPosts = CBlogPost::GetList(array(), array('ID' => $postID, 'BLOG_ID' => $arResult['BLOG_DATA']['BLOG_ID']), false, false, array('ID', 'BLOG_ID', 'NUM_COMMENTS'));
         if ($postInfo = $rsPosts->Fetch()) {
             $postInfo['NUM_COMMENTS'] = (int) $postInfo['NUM_COMMENTS'];
             if ($postInfo['NUM_COMMENTS'] >= 0 && $postInfo['NUM_COMMENTS'] != $commentsCount) {
                 CIBlockElement::SetPropertyValues($arResult['ELEMENT']['ID'], $arResult['ELEMENT']['IBLOCK_ID'], $postInfo['NUM_COMMENTS'], $arResult['BLOG_DATA']['BLOG_COMMENTS_COUNT_PROP']);
                 $commentsCount = $postInfo['NUM_COMMENTS'];
             }
         } else {
             $postID = 0;
         }
         unset($rsPosts);
     }
     if ($postID == 0 && $arParams['BLOG_FROM_AJAX'] === 'N') {
         $ownerID = 1;
         if (!empty($arResult['ELEMENT']['CREATED_BY'])) {
             $ownersIterator = Main\UserTable::getList(array('select' => array('ID'), 'filter' => array('=ID' => $arResult['ELEMENT']['CREATED_BY'])));
             if ($owner = $ownersIterator->fetch()) {
                 $ownerID = $owner['ID'];
             }
             unset($owner, $ownersIterator);
         }
         $arFields = array('TITLE' => $arResult['ELEMENT']['~NAME'], 'DETAIL_TEXT' => "[URL=http://" . $_SERVER['HTTP_HOST'] . $arResult["ELEMENT"]["~DETAIL_PAGE_URL"] . "]" . $arResult["ELEMENT"]["~NAME"] . "[/URL]\n" . ($arResult["ELEMENT"]["~PREVIEW_TEXT"] != '' ? $arResult["ELEMENT"]["~PREVIEW_TEXT"] : '') . "\n", 'PUBLISH_STATUS' => BLOG_PUBLISH_STATUS_PUBLISH, "PERMS_POST" => array(), "PERMS_COMMENT" => array(), "=DATE_CREATE" => $DB->GetNowFunction(), "=DATE_PUBLISH" => $DB->GetNowFunction(), "AUTHOR_ID" => $ownerID, "BLOG_ID" => $arResult['BLOG_DATA']['BLOG_ID'], "ENABLE_TRACKBACK" => "N");
         $postID = (int) CBlogPost::Add($arFields);
         if ($postID > 0) {
             CIBlockElement::SetPropertyValues($arResult['ELEMENT']['ID'], $arResult['ELEMENT']['IBLOCK_ID'], $postID, $arResult['BLOG_DATA']['BLOG_POST_ID_PROP']);
         }
     }
     $arResult['BLOG_DATA']['BLOG_POST_ID'] = $postID;
     $arResult['COMMENT_ID'] = $postID;
 }
 $protocol = CMain::IsHTTPS() ? 'https://' : 'http://';
 protected static function getUserGroups($userId)
 {
     $userId = (int) $userId;
     if ($userId < 0) {
         return false;
     }
     if (!isset(self::$userCache[$userId])) {
         if ($userId == 0) {
             self::$userCache[$userId] = array(2);
         } else {
             self::$userCache[$userId] = false;
             $userIterator = Main\UserTable::getList(array('select' => array('ID'), 'filter' => array('=ID' => $userId)));
             if ($user = $userIterator->fetch()) {
                 $user['ID'] = (int) $user['ID'];
                 self::$userCache[$user['ID']] = CUser::GetUserGroup($user['ID']);
             }
             unset($user, $userIterator);
         }
     }
     return self::$userCache[$userId];
 }
Exemple #14
0
//load order
$boolLocked = \Bitrix\Sale\Order::isLocked($ID);
if ($boolLocked) {
    $r = \Bitrix\Sale\Order::getLockedStatus($ID);
    if ($r->isSuccess()) {
        $lockResult = $r->getData();
        if (array_key_exists('LOCKED_BY', $lockResult) && intval($lockResult['LOCKED_BY']) > 0) {
            $intLockUserID = intval($lockResult['LOCKED_BY']);
        }
        if (array_key_exists('DATE_LOCK', $lockResult) && $lockResult['DATE_LOCK'] instanceof \Bitrix\Main\Type\DateTime) {
            $strLockTime = $lockResult['DATE_LOCK']->toString();
        }
    }
    $strLockUser = $intLockUserID;
    $strLockUserInfo = $intLockUserID;
    $userIterator = \Bitrix\Main\UserTable::getList(array('select' => array('ID', 'LOGIN', 'NAME', 'LAST_NAME', 'SECOND_NAME', 'EMAIL'), 'filter' => array('=ID' => $intLockUserID)));
    if ($arOneUser = $userIterator->fetch()) {
        $strLockUser = CUser::FormatName($strNameFormat, $arOneUser);
        $strLockUserInfo = '<a href="/bitrix/admin/user_edit.php?lang=' . LANGUAGE_ID . '&ID=' . $intLockUserID . '">' . $strLockUser . '</a>';
    }
    unset($arOneUser, $userIterator);
    $result->addError(new \Bitrix\Main\Entity\EntityError(GetMessage('SOE_ORDER_LOCKED2', array('#ID#' => $strLockUserInfo, '#DATE#' => $strLockTime))));
}
$allowedStatusesView = array();
$order = Bitrix\Sale\Order::load($_REQUEST["ID"]);
if ($order) {
    $allowedStatusesView = \Bitrix\Sale\OrderStatus::getStatusesUserCanDoOperations($USER->GetID(), array('view'));
}
if (!$order || !in_array($order->getField("STATUS_ID"), $allowedStatusesView)) {
    LocalRedirect("/bitrix/admin/sale_order.php?lang=" . LANGUAGE_ID . GetFilterParams("filter_", false));
}
							echo GetMessage("sender_chain_edit_field_status_def");
						}
						?>
					</span>
					<?if(!empty($str_DATE_SENT) && in_array($str_STATUS, array(\Bitrix\Sender\MailingChainTable::STATUS_END))):?>
						<span class="sender-mailing-status-text-date"><?php 
echo $str_DATE_SENT;
?>
</span>
					<?endif;?>
					<?if(!empty($str_CREATED_BY)):?>
						<span class="sender-mailing-status-creator">
							<?php 
echo GetMessage("sender_chain_edit_field_author");
?>
 <?$arUser = \Bitrix\Main\UserTable::getRowById($str_CREATED_BY);echo htmlspecialcharsbx($arUser['NAME'].' '.$arUser['LAST_NAME']);?>
						</span>
					<?endif;?>
				</span>
				<span>
					<?if($ID>0 && $POST_RIGHT>="W" && \Bitrix\Sender\MailingChainTable::isReadyToSend($ID)):?>
						<input style="margin-left: 80px;" type="button"
							value="<?echo GetMessage("sender_chain_edit_btn_send")?>"
							onclick="window.location='/bitrix/admin/sender_mailing_chain_admin.php?MAILING_ID=<?php 
echo $MAILING_ID;
?>
&ID=<?php 
echo $ID;
?>
&action=send&lang=<?php 
echo LANGUAGE_ID;
Exemple #16
0
 public static function GetList($arParams = array())
 {
     if (!is_array($arParams)) {
         $arParams = array();
     }
     $arID = array();
     if (isset($arParams['ID']) && is_array($arParams['ID']) && !empty($arParams['ID'])) {
         foreach ($arParams['ID'] as $key => $value) {
             $arID[] = intval($value);
         }
     } else {
         if (isset($arParams['ID']) && intval($arParams['ID']) > 0) {
             $arID[] = intval($arParams['ID']);
         }
     }
     global $USER;
     if (!isset($arParams['ID']) && !IsModuleInstalled('intranet') && is_object($USER)) {
         $arID[] = $USER->GetID();
         if (CModule::IncludeModule('socialnetwork') && CSocNetUser::IsFriendsAllowed()) {
             $dbFriends = CSocNetUserRelations::GetList(array(), array("USER_ID" => $USER->GetID(), "RELATION" => SONET_RELATIONS_FRIEND), false, false, array("ID", "FIRST_USER_ID", "SECOND_USER_ID"));
             if ($dbFriends) {
                 while ($arFriends = $dbFriends->GetNext(true, false)) {
                     $friendId = $pref = IntVal($USER->GetID()) == $arFriends["FIRST_USER_ID"] ? $arFriends["SECOND_USER_ID"] : $arFriends["FIRST_USER_ID"];
                     $arID[] = $friendId;
                 }
             }
         }
     }
     $enable = self::Enable();
     $arUsers = array();
     $query = new \Bitrix\Main\Entity\Query(\Bitrix\Main\UserTable::getEntity());
     if ($enable) {
         $query->registerRuntimeField('', new \Bitrix\Main\Entity\ReferenceField('ref', 'Bitrix\\Im\\StatusTable', array('=this.ID' => 'ref.USER_ID')));
     }
     $query->addSelect('ID');
     if ($enable) {
         $query->addSelect('ref.STATUS', 'STATUS')->addSelect('ref.IDLE', 'IDLE');
     }
     $query->addFilter('>LAST_ACTIVITY_DATE', new \Bitrix\Main\DB\SqlExpression(Bitrix\Main\Application::getConnection()->getSqlHelper()->addSecondsToDateTime('-180')));
     $result = $query->exec();
     while ($arUser = $result->fetch()) {
         if (!empty($arID) && !in_array($arUser["ID"], $arID)) {
             continue;
         }
         $arUsers[$arUser["ID"]] = array('id' => $arUser["ID"], 'status' => $enable && in_array($arUser['STATUS'], self::$AVAILABLE_STATUSES) ? $arUser['STATUS'] : 'online', 'idle' => $enable && is_object($arUser['IDLE']) ? $arUser['IDLE']->getTimestamp() : 0);
     }
     return array('users' => $arUsers);
 }
 /**
  * Simple logic.
  * @param array $sectionData
  * @return array
  */
 private function getOwnerBySection(array $sectionData)
 {
     //shared docs
     if ($sectionData['IBLOCK_TYPE'] == 'shared_files' && !empty($sectionData['SECTION_ID']) && !empty($sectionData['CREATED_BY'])) {
         $user = \Bitrix\Main\UserTable::getById($sectionData['CREATED_BY'])->fetch();
         return empty($user) ? array() : $this->reformatUserRow($user);
     }
     $row = \Bitrix\Webdav\FolderInviteTable::getList(array('select' => array('*', 'USER'), 'limit' => 1, 'filter' => array('=IBLOCK_ID' => $sectionData['IBLOCK_ID'], '=SECTION_ID' => $sectionData['SECTION_ID'])))->fetch();
     return empty($row) ? array() : $this->reformatInviteRow($row);
 }
Exemple #18
0
 /**
  * Get common data from cache.
  * @return mixed[]
  */
 protected function getReferences()
 {
     $this->arParams['CACHE_GROUPS'] = isset($this->arParams['CACHE_GROUPS']) && $this->arParams['CACHE_GROUPS'] == 'N' ? 'N' : 'Y';
     $obCache = new CPHPCache();
     if ($this->arParams['CACHE_GROUPS'] == 'Y') {
         $userGroups = implode(",", Main\UserTable::getUserGroupIds($this->getUserId()));
         $cacheId = implode("-", array(__CLASS__, $this->getLanguageId(), $this->getSiteId(), $userGroups));
     } else {
         $cacheId = implode("-", array(__CLASS__, $this->getLanguageId(), $this->getSiteId()));
     }
     $cached = array();
     if ($obCache->StartDataCache($this->arParams["CACHE_TIME"], $cacheId, $this->getSiteId() . '/' . $this->getRelativePath() . '/reference')) {
         // Catalog Groups
         $cached['CATALOG_GROUP'] = array();
         $catalogGroupIterator = CCatalogGroup::GetList(array("SORT" => "ASC"));
         while ($catalogGroup = $catalogGroupIterator->fetch()) {
             $cached['CATALOG_GROUP'][$catalogGroup['NAME']] = $catalogGroup;
         }
         // Catalog Prices
         $cached['CATALOG_PRICE'] = CIBlockPriceTools::GetCatalogPrices(false, array_keys($cached['CATALOG_GROUP']));
         // Catalog Currency
         $cached['CURRENCY'] = array();
         if ($this->isCurrency) {
             $by = "currency";
             $order = "asc";
             $currencyIterator = CCurrency::getList($by, $order);
             while ($currency = $currencyIterator->fetch()) {
                 $cached['CURRENCY'][$currency['CURRENCY']] = $currency;
             }
         }
         // Catalogs list
         $cached['CATALOG'] = array();
         $catalogIterator = CCatalog::getList(array("IBLOCK_ID" => "ASC"));
         while ($catalog = $catalogIterator->fetch()) {
             $info = CCatalogSku::getInfoByIblock($catalog['IBLOCK_ID']);
             $catalog['CATALOG_TYPE'] = $info['CATALOG_TYPE'];
             $cached['CATALOG'][$catalog['IBLOCK_ID']] = $catalog;
         }
         // Measure list
         $cached['MEASURE'] = array();
         $measureIterator = CCatalogMeasure::getList(array("CODE" => "ASC"));
         while ($measure = $measureIterator->fetch()) {
             $cached['MEASURE'][$measure['ID']] = $measure;
         }
         // Default Measure
         $cached['DEFAULT_MEASURE'] = CCatalogMeasure::getDefaultMeasure(true, true);
         $additionalCache = $this->getAdditionalRefereneces();
         if (!empty($additionalCache) && is_array($additionalCache)) {
             foreach ($additionalCache as $cacheKey => $cacheData) {
                 $cached[$cacheKey] = $cacheData;
             }
             unset($cacheKey, $cacheData);
         }
         unset($additionalCache);
         $obCache->EndDataCache($cached);
     } else {
         $cached = $obCache->GetVars();
     }
     return $cached;
 }
Exemple #19
0
 /**
  * @param array $networkIds
  *
  * @return array|null
  */
 public static function getUsersId($networkIds)
 {
     if (!is_array($networkIds)) {
         return null;
     }
     $searchArray = array();
     foreach ($networkIds as $networkId) {
         $searchArray[] = substr($networkId, 0, 1) . intval(substr($networkId, 1)) . "|%";
     }
     $result = \Bitrix\Main\UserTable::getList(array('select' => array('ID', 'WORK_PHONE', 'PERSONAL_PHONE', 'PERSONAL_MOBILE', 'UF_PHONE_INNER', 'XML_ID'), 'filter' => array('=%XML_ID' => $searchArray, '=EXTERNAL_AUTH_ID' => self::EXTERNAL_AUTH_ID), 'order' => 'ID'));
     $users = array();
     while ($user = $result->fetch()) {
         list($networkId, ) = explode("|", $user['XML_ID']);
         $users[$networkId] = $user['ID'];
     }
     if (empty($users)) {
         $users = null;
     }
     return $users;
 }
Exemple #20
0
 public static function catchCatalogOrder($orderId, $arFields, $arOrder, $isNew)
 {
     if (!static::isOn()) {
         return;
     }
     if (!$isNew) {
         // only new orders
         return;
     }
     $data = static::getOrderInfo($orderId);
     // catalog items only
     if (empty($data['products'])) {
         return;
     }
     // add bxuid
     $data['bx_user_id'] = static::getBxUserId();
     if (empty($data['bx_user_id']) && !empty($data['user_id'])) {
         $orderUser = UserTable::getRow(array('select' => array('BX_USER_ID'), 'filter' => array('=ID' => $data['user_id'])));
         if (!empty($orderUser) && !empty($orderUser['BX_USER_ID'])) {
             $data['bx_user_id'] = $orderUser['BX_USER_ID'];
         }
     }
     // add general info
     $data['paid'] = '0';
     $data['domain'] = Context::getCurrent()->getServer()->getHttpHost();
     $data['date'] = date(DATE_ISO8601);
     // add debug info
     global $USER;
     $data['real_user_id'] = $USER->getId() ?: 0;
     $data['cookie_size'] = count($_COOKIE);
     $data['is_admin'] = (int) $USER->IsAdmin();
     $data['admin_section'] = (int) (defined('ADMIN_SECTION') && ADMIN_SECTION);
     $data['admin_panel'] = (int) \CTopPanel::shouldShowPanel();
     // try to guess unnatural orders
     $data['artificial_order'] = (int) ($data['user_id'] != $data['real_user_id'] || !$data['cookie_size'] || $data['is_admin'] || $data['admin_section'] || $data['admin_panel']);
     CounterDataTable::add(array('TYPE' => 'order', 'DATA' => $data));
     // set bxuid to the order
     if (!empty($data['bx_user_id'])) {
         // if sale version is fresh enough
         if (OrderTable::getEntity()->hasField('BX_USER_ID')) {
             OrderTable::update($data['order_id'], array('BX_USER_ID' => $data['bx_user_id']));
         }
     }
 }
    public static function SearchUsers($search, $nameTemplate = "", $bSelf = true, $bEmployeesOnly = false, $bExtranetOnly = false, $departmentId = false)
    {
        CUtil::JSPostUnescape();
        $arUsers = array();
        $search = trim($search);
        if (strlen($search) <= 0 || !GetFilterQuery("TEST", $search)) {
            return $arUsers;
        }
        $bIntranetEnable = IsModuleInstalled('intranet');
        $bExtranetEnable = CModule::IncludeModule('extranet');
        $bBitrix24Enable = IsModuleInstalled('bitrix24');
        $bExtranetUser = $bExtranetEnable && !CExtranet::IsIntranetUser();
        $current_user_id = intval($GLOBALS["USER"]->GetID());
        if ($bExtranetEnable) {
            CSocNetTools::InitGlobalExtranetArrays();
        }
        $arSearchValue = preg_split('/\\s+/', trim(ToUpper($search)));
        array_walk($arSearchValue, array('CSocNetLogDestination', '__percent_walk'));
        $arFilter = array(array('LOGIC' => 'OR', 'NAME' => $arSearchValue, 'LAST_NAME' => $arSearchValue, '%=EMAIL' => $search, '%=LOGIN' => $search), 'ACTIVE' => 'Y');
        if ($bIntranetEnable || COption::GetOptionString("main", "new_user_registration_email_confirmation", "N") == "Y") {
            $arFilter["CONFIRM_CODE"] = false;
        }
        if ($bEmployeesOnly || $bBitrix24Enable && !$bExtranetEnable) {
            $arFilter["!UF_DEPARTMENT"] = false;
        } elseif ($bExtranetOnly) {
            $arFilter["UF_DEPARTMENT"] = false;
        }
        if ($bIntranetEnable && $bExtranetEnable && ($bExtranetUser || !$bEmployeesOnly)) {
            $arFilteredUserIDs = CExtranet::GetMyGroupsUsersSimple(CExtranet::GetExtranetSiteID());
            if ($bExtranetUser) {
                $arFilter["ID"] = array_merge(array($current_user_id), $arFilteredUserIDs);
            } else {
                $arFilter[] = array('LOGIC' => 'OR', '!UF_DEPARTMENT' => false, 'ID' => array_merge(array($current_user_id), $arFilteredUserIDs));
            }
        }
        $arSelect = array("ID", "NAME", "LAST_NAME", "SECOND_NAME", "EMAIL", "LOGIN", "WORK_POSITION", "PERSONAL_PROFESSION", "PERSONAL_PHOTO", "PERSONAL_GENDER", new \Bitrix\Main\Entity\ExpressionField('MAX_LAST_USE_DATE', 'MAX(%s)', array('\\Bitrix\\Main\\FinderDest:CODE_USER_CURRENT.LAST_USE_DATE')));
        //		$arFilter["\Bitrix\Main\FinderDest:CODE_USER_CURRENT.USER_ID"] = array(false, intval($GLOBALS["USER"]->GetID()));
        $helper = \Bitrix\Main\Application::getConnection()->getSqlHelper();
        $connection = \Bitrix\Main\Application::getConnection();
        $castType = $connection instanceof \Bitrix\Main\DB\MysqlCommonConnection ? 'UNSIGNED' : 'INT';
        $arFilter["@ID"] = new \Bitrix\Main\DB\SqlExpression('
(SELECT
    CAST(' . $helper->quote("MAIN_USER_TMP20258") . '.' . $helper->quote("ID") . ' AS ' . $castType . ') AS ' . $helper->quote("ID") . '
    FROM b_user ' . $helper->quote("MAIN_USER_TMP20258") . '
    LEFT JOIN
    	b_finder_dest ' . $helper->quote("TALIAS_1_TMP20258") . '
    	ON
    		' . $helper->quote("TALIAS_1_TMP20258") . '.' . $helper->quote("CODE_USER_ID") . ' = ' . $helper->quote("MAIN_USER_TMP20258") . '.' . $helper->quote("ID") . '
    		AND ' . $helper->quote("TALIAS_1_TMP20258") . '.' . $helper->quote("USER_ID") . ' = ' . intval($GLOBALS["USER"]->GetID()) . '
    WHERE (
        ' . $helper->quote("TALIAS_1_TMP20258") . '.' . $helper->quote("USER_ID") . ' IS NULL
        or ' . $helper->quote("TALIAS_1_TMP20258") . '.' . $helper->quote("USER_ID") . ' in (0, ' . intval($GLOBALS["USER"]->GetID()) . ')
	)
)');
        $rsUser = \Bitrix\Main\UserTable::getList(array('order' => array("\\Bitrix\\Main\\FinderDest:CODE_USER_CURRENT.LAST_USE_DATE" => 'DESC', 'LAST_NAME' => 'ASC'), 'filter' => $arFilter, 'select' => $arSelect, 'limit' => 50, 'data_doubling' => false));
        while ($arUser = $rsUser->fetch()) {
            if (!$bSelf && $current_user_id == $arUser['ID']) {
                continue;
            }
            if (intval($departmentId) > 0) {
                $arUserGroupCode = CAccess::GetUserCodesArray($arUser["ID"]);
                if (!in_array("DR" . intval($departmentId), $arUserGroupCode)) {
                    continue;
                }
            }
            $sName = CUser::FormatName(empty($nameTemplate) ? CSite::GetNameFormat(false) : $nameTemplate, $arUser, true, true);
            $arFileTmp = CFile::ResizeImageGet($arUser["PERSONAL_PHOTO"], array('width' => 32, 'height' => 32), BX_RESIZE_IMAGE_EXACT, false);
            $arUsers['U' . $arUser["ID"]] = array('id' => 'U' . $arUser["ID"], 'entityId' => $arUser["ID"], 'name' => $sName, 'avatar' => empty($arFileTmp['src']) ? '' : $arFileTmp['src'], 'desc' => $arUser['WORK_POSITION'] ? $arUser['WORK_POSITION'] : ($arUser['PERSONAL_PROFESSION'] ? $arUser['PERSONAL_PROFESSION'] : '&nbsp;'), 'isExtranet' => isset($GLOBALS["arExtranetUserID"]) && is_array($GLOBALS["arExtranetUserID"]) && in_array($arUser["ID"], $GLOBALS["arExtranetUserID"]) ? "Y" : "N");
            $checksum = md5(serialize($arUsers['U' . $arUser["ID"]]));
            $arUsers['U' . $arUser["ID"]]['checksum'] = $checksum;
        }
        return $arUsers;
    }
                    $lAdmin->AddGroupError(GetMessage("sender_mailing_chain_adm_del_error"), $ID);
                }
                $DB->Commit();
                break;
        }
    }
}
$groupListDb = \Bitrix\Sender\MailingChainTable::getList(array('select' => array('ID', 'MAILING_ID', 'POSTING_ID', 'CREATED_BY', 'STATUS', 'REITERATE', 'LAST_EXECUTED', 'EMAIL_FROM', 'AUTO_SEND_TIME', 'DAYS_OF_MONTH', 'DAYS_OF_WEEK', 'TIMES_OF_DAY', 'NAME' => 'SUBJECT'), 'filter' => $arFilter, 'order' => array($by => $order)));
$rsData = new CAdminResult($groupListDb, $sTableID);
$rsData->NavStart();
$lAdmin->NavText($rsData->GetNavPrint(GetMessage("sender_mailing_chain_adm_nav")));
$lAdmin->AddHeaders(array(array("id" => "ID", "content" => "ID", "sort" => "ID", "align" => "right", "default" => true), array("id" => "NAME", "content" => GetMessage("sender_mailing_chain_adm_field_name"), "sort" => "NAME", "default" => true), array("id" => "CREATED_BY", "content" => GetMessage("sender_mailing_chain_adm_field_created_by"), "sort" => "CREATED_BY", "default" => true), array("id" => "STATUS", "content" => GetMessage("sender_mailing_chain_adm_field_status"), "sort" => "STATUS", "default" => true), array("id" => "EMAIL_FROM", "content" => GetMessage("sender_mailing_chain_adm_field_email_from"), "sort" => "EMAIL_FROM", "default" => false), array("id" => "REITERATE", "content" => GetMessage("sender_mailing_chain_adm_field_reiterate"), "sort" => "REITERATE", "default" => false), array("id" => "AUTO_SEND_TIME", "content" => GetMessage("sender_mailing_chain_adm_field_auto_send_time"), "sort" => "AUTO_SEND_TIME", "default" => false)));
while ($arRes = $rsData->NavNext(true, "f_")) {
    $row =& $lAdmin->AddRow($f_ID, $arRes);
    $row->AddViewField("NAME", '<a href="/bitrix/admin/sender_mailing_chain_edit.php?MAILING_ID=' . $MAILING_ID . '&ID=' . $f_ID . '&amp;lang=' . LANG . '">' . $f_NAME . '</a>');
    $arUser = \Bitrix\Main\UserTable::getRowById(intval($f_CREATED_BY));
    $row->AddViewField("CREATED_BY", '<a href="/bitrix/admin/user_edit.php?lang=' . LANGUAGE_ID . '&ID=' . $f_CREATED_BY . '">' . htmlspecialcharsbx($arUser['NAME'] . " " . $arUser['LAST_NAME']) . "</a>");
    $arStatus = MailingChainTable::getStatusList();
    $row->AddViewField("STATUS", $arStatus[$f_STATUS]);
    $row->AddViewField("REITERATE", $f_REITERATE == 'Y' ? GetMessage("MAIN_YES") : GetMessage("MAIN_NO"));
    $arActions = array();
    $arActions[] = array("ICON" => "edit", "DEFAULT" => true, "TEXT" => GetMessage("sender_mailing_chain_adm_action_edit"), "ACTION" => $lAdmin->ActionRedirect("sender_mailing_chain_edit.php?MAILING_ID=" . $MAILING_ID . "&ID=" . $f_ID));
    if ($POST_RIGHT >= "W") {
        $arActions[] = array("ICON" => "delete", "TEXT" => GetMessage("sender_mailing_chain_adm_action_delete"), "ACTION" => "if(confirm('" . GetMessage('sender_mailing_chain_adm_action_delete_confirm') . "')) " . $lAdmin->ActionDoGroup($f_ID, "delete", "MAILING_ID=" . $MAILING_ID));
    }
    $arActions[] = array("SEPARATOR" => true);
    switch ($f_STATUS) {
        case MailingChainTable::STATUS_NEW:
            if ($POST_RIGHT >= "W") {
                $arActions[] = array("ICON" => "", "DEFAULT" => false, "TEXT" => GetMessage("sender_mailing_chain_adm_action_send"), "ACTION" => $lAdmin->ActionRedirect("/bitrix/admin/sender_mailing_chain_admin.php?MAILING_ID=" . $MAILING_ID . "&ID=" . $f_ID . "&action=send&lang=" . LANGUAGE_ID));
            }
Exemple #23
0
	public static function ValidateAtoms($arValues, $arParams, $arControl, $boolShow)
	{
		static $userNameFormat = null;

		$boolShow = ($boolShow === true);
		$boolError = false;
		$arMsg = array();

		$arResult = array(
			'values' => array(),
			'labels' => array(),
			'titles' => array()
		);

		if (!isset($arControl['ATOMS']) || empty($arControl['ATOMS']) || !is_array($arControl['ATOMS']))
		{
			$boolError = true;
			$arMsg[] = Loc::getMessage('BT_GLOBAL_COND_ERR_ATOMS_ABSENT');
		}
		if (!$boolError)
		{
			if ($boolShow)
			{
				foreach ($arControl['ATOMS'] as &$arOneAtom)
				{
					$strID = $arOneAtom['ATOM']['ID'];
					if (!isset($arOneAtom['ATOM']['VALIDATE']) || empty($arOneAtom['ATOM']['VALIDATE']))
					{
						$arResult['values'][$strID] = $arValues[$strID];
						continue;
					}
					switch ($arOneAtom['ATOM']['VALIDATE'])
					{
						case 'list':
							if (isset($arOneAtom['JS']) && isset($arOneAtom['JS']['values']) && !empty($arOneAtom['JS']['values']))
							{
								if (is_array($arValues[$strID]))
								{
									$arCheckResult = array();
									foreach ($arValues[$strID] as &$strValue)
									{
										if (isset($arOneAtom['JS']['values'][$strValue]))
											$arCheckResult[] = $strValue;
									}
									if (isset($strValue))
										unset($strValue);
									if (!empty($arCheckResult))
									{
										$arResult['values'][$strID] = $arCheckResult;
									}
									else
									{
										$boolError = true;
										$arMsg[] = Loc::getMessage('BT_MOD_COND_ERR_CHECK_DATA_LIST_ABSENT_MULTI');
									}
								}
								else
								{
									if (isset($arOneAtom['JS']['values'][$arValues[$strID]]))
									{
										$arResult['values'][$strID] = $arValues[$strID];
									}
									else
									{
										$boolError = true;
										$arMsg[] = Loc::getMessage('BT_MOD_COND_ERR_CHECK_DATA_LIST_ABSENT');
									}
								}
							}
							else
							{
								$boolError = true;
							}
							break;
						case 'element':
							$rsItems = CIBlockElement::GetList(array(), array('ID' => $arValues[$strID]), false, false, array('ID', 'NAME'));
							if (is_array($arValues[$strID]))
							{
								$arCheckResult = array();
								while ($arItem = $rsItems->Fetch())
								{
									$arCheckResult[(int)$arItem['ID']] = $arItem['NAME'];
								}
								if (!empty($arCheckResult))
								{
									$arResult['values'][$strID] = array_keys($arCheckResult);
									$arResult['labels'][$strID] = array_values($arCheckResult);
								}
								else
								{
									$boolError = true;
									$arMsg[] = Loc::getMessage('BT_MOD_COND_ERR_CHECK_DATA_ELEMENT_ABSENT_MULTI');
								}
							}
							else
							{
								if ($arItem = $rsItems->Fetch())
								{
									$arResult['values'][$strID] = (int)$arItem['ID'];
									$arResult['labels'][$strID] = $arItem['NAME'];
								}
								else
								{
									$boolError = true;
									$arMsg[] = Loc::getMessage('BT_MOD_COND_ERR_CHECK_DATA_ELEMENT_ABSENT');
								}
							}
							break;
						case 'section':
							$rsSections = CIBlockSection::GetList(array(), array('ID' => $arValues[$strID]), false, array('ID', 'NAME'));
							if (is_array($arValues[$strID]))
							{
								$arCheckResult = array();
								while ($arSection = $rsSections->Fetch())
								{
									$arCheckResult[(int)$arSection['ID']] = $arSection['NAME'];
								}
								if (!empty($arCheckResult))
								{
									$arResult['values'][$strID] = array_keys($arCheckResult);
									$arResult['labels'][$strID] = array_values($arCheckResult);
								}
								else
								{
									$boolError = true;
									$arMsg[] = Loc::getMessage('BT_MOD_COND_ERR_CHECK_DATA_SECTION_ABSENT_MULTI');
								}
							}
							else
							{
								if ($arSection = $rsSections->Fetch())
								{
									$arResult['values'][$strID] = (int)$arSection['ID'];
									$arResult['labels'][$strID] = $arSection['NAME'];
								}
								else
								{
									$boolError = true;
									$arMsg[] = Loc::getMessage('BT_MOD_COND_ERR_CHECK_DATA_SECTION_ABSENT');
								}
							}
							break;
						case 'iblock':
							if (is_array($arValues[$strID]))
							{
								$arCheckResult = array();
								foreach ($arValues[$strID] as &$intIBlockID)
								{
									$strName = CIBlock::GetArrayByID($intIBlockID, 'NAME');
									if ($strName !== false && $strName !== null)
									{
										$arCheckResult[$intIBlockID] = $strName;
									}
								}
								if (isset($intIBlockID))
									unset($intIBlockID);
								if (!empty($arCheckResult))
								{
									$arResult['values'][$strID] = array_keys($arCheckResult);
									$arResult['labels'][$strID] = array_values($arCheckResult);
								}
								else
								{
									$boolError = true;
									$arMsg[] = Loc::getMessage('BT_MOD_COND_ERR_CHECK_DATA_IBLOCK_ABSENT_MULTI');
								}
							}
							else
							{
								$strName = CIBlock::GetArrayByID($arValues[$strID], 'NAME');
								if ($strName !== false && $strName !== null)
								{
									$arResult['values'][$strID] = $arValues[$strID];
									$arResult['labels'][$strID] = $strName;
								}
								else
								{
									$boolError = true;
									$arMsg[] = Loc::getMessage('BT_MOD_COND_ERR_CHECK_DATA_IBLOCK_ABSENT');
								}
							}
							break;
						case 'user':
							if ($userNameFormat === null)
								$userNameFormat = CSite::GetNameFormat(true);
							if (is_array($arValues[$strID]))
							{
								$arCheckResult = array();
								$userIterator = UserTable::getList(array(
									'select' => array('ID', 'LOGIN', 'NAME', 'LAST_NAME', 'SECOND_NAME', 'EMAIL'),
									'filter' => array('ID' => $arValues[$strID])
								));
								while ($user = $userIterator->fetch())
								{
									$user['ID'] = (int)$user['ID'];
									$arCheckResult[$user['ID']] = CUser::FormatName($userNameFormat, $user);
								}
								if (!empty($arCheckResult))
								{
									$arResult['values'][$strID] = array_keys($arCheckResult);
									$arResult['labels'][$strID] = array_values($arCheckResult);
								}
								else
								{
									$boolError = true;
									$arMsg[] = Loc::getMessage('BT_MOD_COND_ERR_CHECK_DATA_USER_ABSENT_MULTI');
								}
							}
							else
							{
								$userIterator = UserTable::getList(array(
									'select' => array('ID', 'LOGIN', 'NAME', 'LAST_NAME', 'SECOND_NAME', 'EMAIL'),
									'filter' => array('ID' => $arValues[$strID])
								));
								if ($user = $userIterator->fetch())
								{
									$arResult['values'] = (int)$user['ID'];
									$arResult['labels'] = CUser::FormatName($userNameFormat, $user);
								}
								else
								{
									$boolError = true;
									$arMsg[] = Loc::getMessage('BT_MOD_COND_ERR_CHECK_DATA_USER_ABSENT');
								}
							}
							break;
					}
				}
				if (isset($arOneAtom))
					unset($arOneAtom);
			}
			else
			{
				foreach ($arControl['ATOMS'] as &$arOneAtom)
				{
					$strID = $arOneAtom['ATOM']['ID'];
					if (!isset($arOneAtom['ATOM']['VALIDATE']) || empty($arOneAtom['ATOM']['VALIDATE']))
					{
						$arResult['values'][$strID] = $arValues[$strID];
						continue;
					}
					switch ($arOneAtom['ATOM']['VALIDATE'])
					{
						case 'list':
							if (isset($arOneAtom['JS']) && isset($arOneAtom['JS']['values']) && !empty($arOneAtom['JS']['values']))
							{
								if (is_array($arValues[$strID]))
								{
									$arCheckResult = array();
									foreach ($arValues[$strID] as &$strValue)
									{
										if (isset($arOneAtom['JS']['values'][$strValue]))
											$arCheckResult[] = $strValue;
									}
									if (isset($strValue))
										unset($strValue);
									if (!empty($arCheckResult))
									{
										$arResult['values'][$strID] = $arCheckResult;
									}
									else
									{
										$boolError = true;
									}
								}
								else
								{
									if (isset($arOneAtom['JS']['values'][$arValues[$strID]]))
									{
										$arResult['values'][$strID] = $arValues[$strID];
									}
									else
									{
										$boolError = true;
									}
								}
							}
							else
							{
								$boolError = true;
							}
							break;
						case 'element':
							$rsItems = CIBlockElement::GetList(array(), array('ID' => $arValues[$strID]), false, false, array('ID'));
							if (is_array($arValues[$strID]))
							{
								$arCheckResult = array();
								while ($arItem = $rsItems->Fetch())
								{
									$arCheckResult[] = (int)$arItem['ID'];
								}
								if (!empty($arCheckResult))
								{
									$arResult['values'][$strID] = $arCheckResult;
								}
								else
								{
									$boolError = true;
								}
							}
							else
							{
								if ($arItem = $rsItems->Fetch())
								{
									$arResult['values'][$strID] = (int)$arItem['ID'];
								}
								else
								{
									$boolError = true;
								}
							}
							break;
						case 'section':
							$rsSections = CIBlockSection::GetList(array(), array('ID' => $arValues[$strID]), false, array('ID'));
							if (is_array($arValues[$strID]))
							{
								$arCheckResult = array();
								while ($arSection = $rsSections->Fetch())
								{
									$arCheckResult[] = (int)$arSection['ID'];
								}
								if (!empty($arCheckResult))
								{
									$arResult['values'][$strID] = $arCheckResult;
								}
								else
								{
									$boolError = true;
								}
							}
							else
							{
								if ($arSection = $rsSections->Fetch())
								{
									$arResult['values'][$strID] = (int)$arSection['ID'];
								}
								else
								{
									$boolError = true;
								}
							}
							break;
						case 'iblock':
							if (is_array($arValues[$strID]))
							{
								$arCheckResult = array();
								foreach ($arValues[$strID] as &$intIBlockID)
								{
									$strName = CIBlock::GetArrayByID($intIBlockID, 'NAME');
									if ($strName !== false && $strName !== null)
									{
										$arCheckResult[] = $intIBlockID;
									}
								}
								if (isset($intIBlockID))
									unset($intIBlockID);
								if (!empty($arCheckResult))
								{
									$arResult['values'][$strID] = $arCheckResult;
								}
								else
								{
									$boolError = true;
								}
							}
							else
							{
								$strName = CIBlock::GetArrayByID($arValues[$strID], 'NAME');
								if ($strName !== false && $strName !== null)
								{
									$arResult['values'][$strID] = $arValues[$strID];
								}
								else
								{
									$boolError = true;
								}
							}
							break;
						case 'user':
							if (is_array($arValues[$strID]))
							{
								$arCheckResult = array();
								$userIterator = UserTable::getList(array(
									'select' => array('ID'),
									'filter' => array('ID' => $arValues[$strID])
								));
								while ($user = $userIterator->fetch())
								{
									$arCheckResult[] = (int)$user['ID'];
								}
								if (!empty($arCheckResult))
								{
									$arResult['values'][$strID] = $arCheckResult;
								}
								else
								{
									$boolError = true;
								}
							}
							else
							{
								$userIterator = UserTable::getList(array(
									'select' => array('ID'),
									'filter' => array('ID' => $arValues[$strID])
								));
								if ($user = $userIterator->fetch())
								{
									$arCheckResult[] = (int)$user['ID'];
								}
								else
								{
									$boolError = true;
								}
							}
							break;
					}
				}
				if (isset($arOneAtom))
					unset($arOneAtom);
			}
		}

		if ($boolShow)
		{
			if ($boolError)
			{
				$arResult['err_cond'] = 'Y';
				$arResult['err_cond_mess'] = $arMsg;
			}
			return $arResult;
		}
		else
		{
			return (!$boolError ? $arResult : false);
		}
	}
Exemple #24
0
 public static function getUserByPassword($login, $password, $passwordIsOriginal = true)
 {
     if (empty($login)) {
         throw new Main\ArgumentNullException("login");
     }
     $event = new Main\Event("main", "OnBeforeUserLogin", array(array("LOGIN" => $login, "PASSWORD" => $password, "PASSWORD_ORIGINAL" => $passwordIsOriginal)));
     $event->send();
     if (($eventResults = $event->getResults()) !== null) {
         foreach ($eventResults as $eventResult) {
             if ($eventResult->getResultType() === Main\EventResult::ERROR) {
                 static::$lastError = $eventResult->getParameters();
                 return null;
             } elseif ($eventResult->getResultType() === Main\EventResult::SUCCESS) {
                 if (($resultParams = $eventResult->getParameters()) && is_array($resultParams)) {
                     if (isset($resultParams["LOGIN"])) {
                         $login = $resultParams["LOGIN"];
                     }
                     if (isset($resultParams["PASSWORD"])) {
                         $password = $resultParams["PASSWORD"];
                     }
                     if (isset($resultParams["PASSWORD_ORIGINAL"])) {
                         $passwordIsOriginal = $resultParams["PASSWORD_ORIGINAL"];
                     }
                 }
             }
         }
     }
     $user = null;
     $event = new Main\Event("main", "OnUserLoginExternal", array(array("LOGIN" => $login, "PASSWORD" => $password, "PASSWORD_ORIGINAL" => $passwordIsOriginal)));
     $event->send();
     if (($eventResults = $event->getResults()) !== null) {
         foreach ($eventResults as $eventResult) {
             if ($eventResult->getResultType() === Main\EventResult::SUCCESS) {
                 $userId = $eventResult->getParameters();
                 if (!Main\Type\Int::isInteger($userId)) {
                     throw new SecurityException();
                 }
                 $user = new CurrentUser($userId);
                 break;
             }
         }
     }
     $connection = Main\Application::getDbConnection();
     $sqlHelper = $connection->getSqlHelper();
     if (is_null($user)) {
         $sql = "SELECT U.ID, U.PASSWORD, U.LOGIN_ATTEMPTS " . "FROM b_user U  " . "WHERE U.LOGIN = '******' " . "\tAND (U.EXTERNAL_AUTH_ID IS NULL OR U.EXTERNAL_AUTH_ID = '') " . "   AND U.ACTIVE = 'Y' ";
         $userRecordset = $connection->query($sql);
         if ($userRecord = $userRecordset->fetch()) {
             $userTmp = new CurrentUser($userRecord["ID"]);
             $salt = substr($userRecord["PASSWORD"], 0, -32);
             $passwordFromDb = substr($userRecord["PASSWORD"], -32);
             if ($passwordIsOriginal) {
                 $passwordFromUser = md5($salt . $password);
             } else {
                 $passwordFromUser = strlen($password) > 32 ? substr($password, -32) : $password;
             }
             $policy = $userTmp->getPolicy();
             $policyLoginAttempts = intval($policy["LOGIN_ATTEMPTS"]);
             $userLoginAttempts = intval($userRecord["LOGIN_ATTEMPTS"]) + 1;
             if ($policyLoginAttempts > 0 && $userLoginAttempts > $policyLoginAttempts) {
                 //					$_SESSION["BX_LOGIN_NEED_CAPTCHA"] = true;
                 //					if (!$APPLICATION->captchaCheckCode($_REQUEST["captcha_word"], $_REQUEST["captcha_sid"]))
                 //					{
                 //						$passwordUser = false;
                 //					}
             }
             if ($passwordFromDb === $passwordFromUser) {
                 $user = $userTmp;
                 //update digest hash for http digest authorization
                 if ($passwordIsOriginal && Main\Config\Option::get('main', 'use_digest_auth', 'N') == 'Y') {
                     static::updateDigest($user->getUserId(), $password);
                 }
             } else {
                 $connection->query("UPDATE b_user SET " . "   LOGIN_ATTEMPTS = " . $userLoginAttempts . " " . "WHERE ID = " . intval($userRecord["ID"]));
             }
         }
     }
     if (is_null($user)) {
         if (Main\Config\Option::get("main", "event_log_login_fail", "N") === "Y") {
             \CEventLog::log("SECURITY", "USER_LOGIN", "main", $login, "LOGIN_FAILED");
         }
         return null;
     }
     if ($user->getUserId() !== 1) {
         $limitUsersCount = intval(Main\Config\Option::get("main", "PARAM_MAX_USERS", 0));
         if ($limitUsersCount > 0) {
             $usersCount = Main\UserTable::getActiveUsersCount();
             if ($usersCount > $limitUsersCount) {
                 $sql = "SELECT 'x' " . "FROM b_user " . "WHERE ACTIVE = 'Y' " . "   AND ID = " . intval($user->getUserId()) . " " . "   AND LAST_LOGIN IS NULL ";
                 $recordset = $connection->query($sql);
                 if ($recordset->fetch()) {
                     $user = null;
                     static::$lastError = array("CODE" => "LIMIT_USERS_COUNT", "MESSAGE" => Main\Localization\Loc::getMessage("LIMIT_USERS_COUNT"));
                 }
             }
         }
     }
     if (is_null($user)) {
         if (Main\Config\Option::get("main", "event_log_login_fail", "N") === "Y") {
             \CEventLog::log("SECURITY", "USER_LOGIN", "main", $login, "LIMIT_USERS_COUNT");
         }
         return null;
     }
     $user->setAuthType(static::AUTHENTICATED_BY_PASSWORD);
     $event = new \Bitrix\Main\Event("main", "OnAfterUserLogin", array(array("LOGIN" => $login, "PASSWORD" => $password, "PASSWORD_ORIGINAL" => $passwordIsOriginal, "USER_ID" => $user->getUserId())));
     $event->send();
     return $user;
 }
			'TEXT' => Loc::getMessage('BT_SALE_DISCOUNT_COUPON_LIST_CONTEXT_DELETE'),
			'ACTION' => "if(confirm('".Loc::getMessage('BT_SALE_DISCOUNT_COUPON_LIST_CONTEXT_DELETE_CONFIRM')."')) ".$adminList->ActionDoGroup($coupon['ID'], 'delete')
		);
	}
	$row->AddActions($actions);
	unset($actions);
}
if (isset($row))
	unset($row);

if ($selectFieldsMap['CREATED_BY'] || $selectFieldsMap['MODIFIED_BY'] || $selectFieldsMap['USER_ID'])
{
	if (!empty($userIDs))
	{
		$userIterator = UserTable::getList(array(
			'select' => array('ID', 'LOGIN', 'NAME', 'LAST_NAME', 'SECOND_NAME', 'EMAIL'),
			'filter' => array('ID' => array_keys($userIDs)),
		));
		while ($oneUser = $userIterator->fetch())
		{
			$oneUser['ID'] = (int)$oneUser['ID'];
			if ($canViewUserList)
				$userList[$oneUser['ID']] = '<a href="/bitrix/admin/user_edit.php?lang='.LANGUAGE_ID.'&ID='.$oneUser['ID'].'">'.CUser::FormatName($nameFormat, $oneUser).'</a>';
			else
				$userList[$oneUser['ID']] = CUser::FormatName($nameFormat, $oneUser);
		}
		unset($oneUser, $userIterator);
	}

	foreach ($rowList as &$row)
	{
		if ($selectFieldsMap['CREATED_BY'])
						<span class="sender-mailing-status-text-date"><?php 
    echo $str_DATE_SENT;
    ?>
</span>
					<?php 
}
?>
					<?php 
if (!empty($str_CREATED_BY)) {
    ?>
						<span class="sender-mailing-status-creator">
							<?php 
    echo GetMessage("sender_chain_edit_field_author");
    ?>
 <?php 
    $arUser = \Bitrix\Main\UserTable::getRowById($str_CREATED_BY);
    echo htmlspecialcharsbx($arUser['NAME'] . ' ' . $arUser['LAST_NAME']);
    ?>
						</span>
					<?php 
}
?>
				</span>
				<span>
					<?php 
if ($ID > 0 && $POST_RIGHT >= "W" && \Bitrix\Sender\MailingChainTable::isReadyToSend($ID)) {
    ?>
						<input style="margin-left: 80px;" type="button"
							value="<?php 
    echo GetMessage("sender_chain_edit_btn_send");
    ?>
Exemple #27
0
 public static function GetDeviceInfo($userId, $appId = 'Bitrix24')
 {
     $result = array();
     if (is_array($userId)) {
         foreach ($userId as $key => $id) {
             $id = intval($id);
             if ($id > 0) {
                 $result[$id] = array('mode' => self::RECORD_NOT_FOUND, 'device' => array());
             }
         }
     } else {
         if (intval($userId) > 0) {
             $result[intval($userId)] = array('mode' => self::RECORD_NOT_FOUND, 'device' => array());
         }
     }
     if (empty($result)) {
         return false;
     }
     $imInclude = false;
     if (CModule::IncludeModule('im')) {
         $imInclude = true;
     }
     $query = new \Bitrix\Main\Entity\Query(\Bitrix\Main\UserTable::getEntity());
     $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('ID')->addSelect('EMAIL')->addSelect('IS_ONLINE_CUSTOM');
     if ($imInclude) {
         $query->registerRuntimeField('', new \Bitrix\Main\Entity\ReferenceField('im', 'Bitrix\\Im\\StatusTable', array('=this.ID' => 'ref.USER_ID')));
         $query->addSelect('im.IDLE', 'IDLE')->addSelect('im.MOBILE_LAST_DATE', 'MOBILE_LAST_DATE');
     }
     $query->registerRuntimeField('', new \Bitrix\Main\Entity\ReferenceField('push', 'Bitrix\\Pull\\PushTable', array('=this.ID' => 'ref.USER_ID')));
     $query->registerRuntimeField('', new \Bitrix\Main\Entity\ExpressionField('HAS_MOBILE', 'CASE WHEN main_user_push.USER_ID > 0 THEN \'Y\' ELSE \'N\' END'));
     $query->addSelect('HAS_MOBILE')->addSelect('push.APP_ID', 'APP_ID')->addSelect('push.UNIQUE_HASH', 'UNIQUE_HASH')->addSelect('push.DEVICE_TYPE', 'DEVICE_TYPE')->addSelect('push.DEVICE_TOKEN', 'DEVICE_TOKEN');
     $query->addFilter('=ID', array_keys($result));
     $queryResult = $query->exec();
     while ($user = $queryResult->fetch()) {
         $uniqueHashes[] = CPullPush::getUniqueHash($user["ID"], $appId);
         $uniqueHashes[] = CPullPush::getUniqueHash($user["ID"], $appId . "_bxdev");
         if (in_array($user['UNIQUE_HASH'], $uniqueHashes)) {
             $result[$user['ID']]['device'][] = array('APP_ID' => $user['APP_ID'], 'USER_ID' => $user['ID'], 'DEVICE_TYPE' => $user['DEVICE_TYPE'], 'DEVICE_TOKEN' => $user['DEVICE_TOKEN']);
             //$result[$user['ID']]['email'] = $user['EMAIL'];
         } else {
             continue;
         }
         if ($result[$user['ID']]['mode'] != self::RECORD_NOT_FOUND) {
             continue;
         }
         $isMobile = false;
         $isOnline = false;
         $isDesktop = false;
         $isDesktopIdle = false;
         if ($user['HAS_MOBILE'] == 'N') {
             $result[$user['ID']]['mode'] = self::RECORD_NOT_FOUND;
             $result[$user['ID']]['device'] = array();
             continue;
         }
         if ($user['IS_ONLINE_CUSTOM'] == 'Y') {
             $isOnline = true;
         }
         if ($imInclude) {
             $mobileLastDate = 0;
             if (is_object($user['MOBILE_LAST_DATE'])) {
                 $mobileLastDate = $user['MOBILE_LAST_DATE']->getTimestamp();
             }
             if ($mobileLastDate > 0 && $mobileLastDate + 180 > time()) {
                 $isMobile = true;
             }
             $isDesktop = CIMMessenger::CheckDesktopStatusOnline($user['ID']);
             if ($isDesktop && $isOnline && is_object($user['IDLE'])) {
                 if ($user['IDLE']->getTimestamp() > 0) {
                     $isDesktopIdle = true;
                 }
             }
         }
         $status = self::SEND_IMMEDIATELY;
         if ($isMobile) {
             $status = self::SEND_IMMEDIATELY;
         } else {
             if ($isOnline) {
                 $status = self::SEND_DEFERRED;
                 if ($isDesktop) {
                     $status = self::SEND_SKIP;
                     if ($isDesktopIdle) {
                         $status = self::SEND_IMMEDIATELY;
                     } else {
                         $result[$user['ID']]['device'] = array();
                     }
                 } else {
                     $result[$user['ID']]['device'] = array();
                 }
             }
         }
         $result[$user['ID']]['mode'] = $status;
     }
     return $result;
 }
Exemple #28
0
function GetFormatedUserName($userId, $bEnableId = true, $createEditLink = true)
{
    static $formattedUsersName = array();
    static $siteNameFormat = '';
    $result = !is_array($userId) ? '' : array();
    $newUsers = array();
    if (is_array($userId)) {
        foreach ($userId as $id) {
            if (!isset($formattedUsersName[$id])) {
                $newUsers[] = $id;
            }
        }
    } else {
        if (!isset($formattedUsersName[$userId])) {
            $newUsers[] = $userId;
        }
    }
    if (count($newUsers) > 0) {
        $resUsers = \Bitrix\Main\UserTable::getList(array('select' => array('ID', 'NAME', 'LAST_NAME', 'SECOND_NAME', 'LOGIN', 'EMAIL'), 'filter' => array('ID' => $newUsers)));
        while ($arUser = $resUsers->Fetch()) {
            if (strlen($siteNameFormat) == 0) {
                $siteNameFormat = CSite::GetNameFormat(false);
            }
            $formattedUsersName[$arUser['ID']] = CUser::FormatName($siteNameFormat, $arUser, true, true);
        }
    }
    if (is_array($userId)) {
        foreach ($userId as $uId) {
            $formatted = '';
            if ($bEnableId) {
                $formatted = '[<a href="/bitrix/admin/user_edit.php?ID=' . $uId . '&lang=' . LANGUAGE_ID . '">' . $uId . '</a>] ';
            }
            if (CBXFeatures::IsFeatureEnabled('SaleAccounts') && !$createEditLink) {
                $formatted .= '<a href="/bitrix/admin/sale_buyers_profile.php?USER_ID=' . $uId . '&lang=' . LANGUAGE_ID . '">';
            } else {
                $formatted .= '<a href="/bitrix/admin/user_edit.php?ID=' . $uId . '&lang=' . LANGUAGE_ID . '">';
            }
            $formatted .= $formattedUsersName[$uId];
            $formatted .= '</a>';
            $result[$uId] = $formatted;
        }
    } else {
        if ($bEnableId) {
            $result .= '[<a href="/bitrix/admin/user_edit.php?ID=' . $userId . '&lang=' . LANGUAGE_ID . '">' . $userId . '</a>] ';
        }
        if (CBXFeatures::IsFeatureEnabled('SaleAccounts') && !$createEditLink) {
            $result .= '<a href="/bitrix/admin/sale_buyers_profile.php?USER_ID=' . $userId . '&lang=' . LANGUAGE_ID . '">';
        } else {
            $result .= '<a href="/bitrix/admin/user_edit.php?ID=' . $userId . '&lang=' . LANGUAGE_ID . '">';
        }
        $result .= $formattedUsersName[$userId];
        $result .= '</a>';
    }
    return $result;
}
Exemple #29
0
    public function Authorize()
    {
        global $APPLICATION;
        $APPLICATION->RestartBuffer();
        $bSuccess = false;
        $authError = SOCSERV_AUTHORISATION_ERROR;
        if (isset($_REQUEST["code"]) && $_REQUEST["code"] != '' && CSocServAuthManager::CheckUniqueKey()) {
            if (IsModuleInstalled('bitrix24') && defined('BX24_HOST_NAME')) {
                $redirect_uri = static::CONTROLLER_URL . "/redirect.php";
            } else {
                $redirect_uri = CSocServUtil::ServerName() . "/bitrix/tools/oauth/google.php";
            }
            $this->entityOAuth = $this->getEntityOAuth($_REQUEST['code']);
            if ($this->entityOAuth->GetAccessToken($redirect_uri) !== false) {
                $arGoogleUser = $this->entityOAuth->GetCurrentUser();
                if (is_array($arGoogleUser)) {
                    $first_name = "";
                    $last_name = "";
                    if (is_array($arGoogleUser['name'])) {
                        $first_name = $arGoogleUser['name']['givenName'];
                        $last_name = $arGoogleUser['name']['familyName'];
                    } elseif ($arGoogleUser['name'] != '') {
                        $aName = explode(" ", $arGoogleUser['name']);
                        if ($arGoogleUser['given_name'] != '') {
                            $first_name = $arGoogleUser['given_name'];
                        } else {
                            $first_name = $aName[0];
                        }
                        if ($arGoogleUser['family_name'] != '') {
                            $last_name = $arGoogleUser['family_name'];
                        } elseif (isset($aName[1])) {
                            $last_name = $aName[1];
                        }
                    }
                    $id = $arGoogleUser['id'];
                    $email = $arGoogleUser['email'];
                    if (strlen($arGoogleUser['email']) > 0) {
                        $dbRes = \Bitrix\Main\UserTable::getList(array('filter' => array('=EXTERNAL_AUTH_ID' => 'socservices', '=XML_ID' => $email), 'select' => array('ID'), 'limit' => 1));
                        if ($dbRes->fetch()) {
                            $id = $email;
                        }
                    }
                    $arFields = array('EXTERNAL_AUTH_ID' => static::ID, 'XML_ID' => $id, 'LOGIN' => static::LOGIN_PREFIX . $id, 'EMAIL' => $email, 'NAME' => $first_name, 'LAST_NAME' => $last_name, 'OATOKEN' => $this->entityOAuth->getToken(), 'OATOKEN_EXPIRES' => $this->entityOAuth->getAccessTokenExpires(), 'REFRESH_TOKEN' => $this->entityOAuth->getRefreshToken());
                    if ($arGoogleUser['gender'] != '') {
                        if ($arGoogleUser['gender'] == 'male') {
                            $arFields["PERSONAL_GENDER"] = 'M';
                        } elseif ($arGoogleUser['gender'] == 'female') {
                            $arFields["PERSONAL_GENDER"] = 'F';
                        }
                    }
                    if (isset($arGoogleUser['picture']) && static::CheckPhotoURI($arGoogleUser['picture'])) {
                        $arGoogleUser['picture'] = preg_replace("/\\?.*\$/", '', $arGoogleUser['picture']);
                        $arPic = CFile::MakeFileArray($arGoogleUser['picture']);
                        if ($arPic) {
                            $arFields["PERSONAL_PHOTO"] = $arPic;
                        }
                    }
                    $arFields["PERSONAL_WWW"] = isset($arGoogleUser['link']) ? $arGoogleUser['link'] : $arGoogleUser['url'];
                    if (strlen(SITE_ID) > 0) {
                        $arFields["SITE_ID"] = SITE_ID;
                    }
                    $authError = $this->AuthorizeUser($arFields);
                    $bSuccess = $authError === true;
                }
            }
        }
        $url = $APPLICATION->GetCurDir() == "/login/" ? "" : $APPLICATION->GetCurDir();
        $aRemove = array("logout", "auth_service_error", "auth_service_id", "code", "error_reason", "error", "error_description", "check_key", "current_fieldset");
        $mode = 'opener';
        if (isset($_REQUEST["state"])) {
            $arState = array();
            parse_str($_REQUEST["state"], $arState);
            if (isset($arState['backurl']) || isset($arState['redirect_url'])) {
                $parseUrl = parse_url(!empty($arState['redirect_url']) ? $arState['redirect_url'] : $arState['backurl']);
                $urlPath = $parseUrl["path"];
                $arUrlQuery = explode('&', $parseUrl["query"]);
                foreach ($arUrlQuery as $key => $value) {
                    foreach ($aRemove as $param) {
                        if (strpos($value, $param . "=") === 0) {
                            unset($arUrlQuery[$key]);
                            break;
                        }
                    }
                }
                $url = !empty($arUrlQuery) ? $urlPath . '?' . implode("&", $arUrlQuery) : $urlPath;
            }
            if (isset($arState['mode'])) {
                $mode = $arState['mode'];
            }
        }
        if ($authError === SOCSERV_REGISTRATION_DENY) {
            $url = preg_match("/\\?/", $url) ? $url . '&' : $url . '?';
            $url .= 'auth_service_id=' . static::ID . '&auth_service_error=' . SOCSERV_REGISTRATION_DENY;
        } elseif ($bSuccess !== true) {
            $url = isset($urlPath) ? $urlPath . '?auth_service_id=' . static::ID . '&auth_service_error=' . $authError : $APPLICATION->GetCurPageParam('auth_service_id=' . static::ID . '&auth_service_error=' . $authError, $aRemove);
        }
        if (CModule::IncludeModule("socialnetwork") && strpos($url, "current_fieldset=") === false) {
            $url = preg_match("/\\?/", $url) ? $url . "&current_fieldset=SOCSERV" : $url . "?current_fieldset=SOCSERV";
        }
        $url = CUtil::JSEscape($url);
        $location = $mode == "opener" ? 'if(window.opener) window.opener.location = \'' . $url . '\'; window.close();' : ' window.location = \'' . $url . '\';';
        $JSScript = '
		<script type="text/javascript">
		' . $location . '
		</script>
		';
        echo $JSScript;
        die;
    }
Exemple #30
0
 public function prepareUser($arGoogleUser, $short = false)
 {
     $first_name = "";
     $last_name = "";
     if (is_array($arGoogleUser['name'])) {
         $first_name = $arGoogleUser['name']['givenName'];
         $last_name = $arGoogleUser['name']['familyName'];
     } elseif ($arGoogleUser['name'] != '') {
         $aName = explode(" ", $arGoogleUser['name']);
         if ($arGoogleUser['given_name'] != '') {
             $first_name = $arGoogleUser['given_name'];
         } else {
             $first_name = $aName[0];
         }
         if ($arGoogleUser['family_name'] != '') {
             $last_name = $arGoogleUser['family_name'];
         } elseif (isset($aName[1])) {
             $last_name = $aName[1];
         }
     }
     $id = $arGoogleUser['id'];
     $email = $arGoogleUser['email'];
     if (strlen($arGoogleUser['email']) > 0) {
         $dbRes = \Bitrix\Main\UserTable::getList(array('filter' => array('=EXTERNAL_AUTH_ID' => 'socservices', '=XML_ID' => $email), 'select' => array('ID'), 'limit' => 1));
         if ($dbRes->fetch()) {
             $id = $email;
         }
     }
     $arFields = array('EXTERNAL_AUTH_ID' => static::ID, 'XML_ID' => $id, 'LOGIN' => static::LOGIN_PREFIX . $id, 'EMAIL' => $email, 'NAME' => $first_name, 'LAST_NAME' => $last_name, 'OATOKEN' => $this->entityOAuth->getToken(), 'OATOKEN_EXPIRES' => $this->entityOAuth->getAccessTokenExpires(), 'REFRESH_TOKEN' => $this->entityOAuth->getRefreshToken());
     if ($arGoogleUser['gender'] != '') {
         if ($arGoogleUser['gender'] == 'male') {
             $arFields["PERSONAL_GENDER"] = 'M';
         } elseif ($arGoogleUser['gender'] == 'female') {
             $arFields["PERSONAL_GENDER"] = 'F';
         }
     }
     if (!$short && isset($arGoogleUser['picture']) && static::CheckPhotoURI($arGoogleUser['picture'])) {
         $arGoogleUser['picture'] = preg_replace("/\\?.*\$/", '', $arGoogleUser['picture']);
         $arPic = CFile::MakeFileArray($arGoogleUser['picture']);
         if ($arPic) {
             $arFields["PERSONAL_PHOTO"] = $arPic;
         }
     }
     $arFields["PERSONAL_WWW"] = isset($arGoogleUser['link']) ? $arGoogleUser['link'] : $arGoogleUser['url'];
     if (strlen(SITE_ID) > 0) {
         $arFields["SITE_ID"] = SITE_ID;
     }
     return $arFields;
 }