1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
authproviders.php
См. документацию.
1<?php
2
9
13
14IncludeModuleLangFile(__FILE__);
15
17{
18 protected $id;
19
20 public function DeleteByUser($USER_ID)
21 {
22 CAccess::RecalculateForUser($USER_ID, $this->id);
23 }
24
25 public function DeleteAll()
26 {
27 CAccess::RecalculateForProvider($this->id);
28 }
29
30 public function AddCode($userId, $code)
31 {
32 CAccess::AddCode($userId, $this->id, $code);
33 }
34
35 public function RemoveCode($userId, $code)
36 {
37 CAccess::RemoveCode($userId, $this->id, $code);
38 }
39}
40
42{
43 public function GetFormHtml($arParams=false);
44 public function GetNames($arCodes);
45}
46
48{
49 const ID = 'group';
50
51 public function __construct()
52 {
53 $this->id = self::ID;
54 }
55
56 public function UpdateCodes($USER_ID)
57 {
58 global $DB;
59
60 $USER_ID = intval($USER_ID);
61
62 $connection = Application::getConnection();
63 $helper = $connection->getSqlHelper();
64
65 $sql = $helper->getInsertIgnore(
66 'b_user_access',
67 '(USER_ID, PROVIDER_ID, ACCESS_CODE)',
68 "SELECT UG.USER_ID, '".$DB->ForSQL($this->id)."', ".$DB->Concat("'G'", "UG.GROUP_ID")."
69 FROM b_user_group UG, b_group G
70 WHERE UG.USER_ID=".$USER_ID."
71 AND G.ID=UG.GROUP_ID
72 AND G.ACTIVE='Y'
73 AND ((UG.DATE_ACTIVE_FROM IS NULL) OR (UG.DATE_ACTIVE_FROM <= ".$DB->CurrentTimeFunction()."))
74 AND ((UG.DATE_ACTIVE_TO IS NULL) OR (UG.DATE_ACTIVE_TO >= ".$DB->CurrentTimeFunction()."))
75 UNION
76 SELECT ID, '".$DB->ForSQL($this->id)."', 'G2'
77 FROM b_user
78 WHERE ID=".$USER_ID
79 );
80
81 $DB->Query($sql);
82 }
83
84 public static function OnAfterSetUserGroup($USER_ID, $groups)
85 {
86 $dates = [];
87 foreach ($groups as $group)
88 {
89 if ($group['DATE_ACTIVE_FROM'] !== null)
90 {
91 $dates[(string)$group['DATE_ACTIVE_FROM']] = $group['DATE_ACTIVE_FROM'];
92 }
93 if ($group['DATE_ACTIVE_TO'] !== null)
94 {
95 $dates[(string)$group['DATE_ACTIVE_TO']] = $group['DATE_ACTIVE_TO'];
96 }
97 }
98
99 CAccess::RecalculateForUser($USER_ID, self::ID);
100
101 foreach ($dates as $date)
102 {
103 CAccess::RecalculateForUser($USER_ID, self::ID, $date);
104 }
105 }
106
107 public static function RecalculateForGroup($ID, $checkTime = true)
108 {
109 $users = UserGroupTable::getList([
110 'filter' => ['=GROUP_ID' => $ID],
111 'cache' => ['ttl' => 3600],
112 ]);
113
114 while ($user = $users->fetch())
115 {
116 if (($user['DATE_ACTIVE_FROM'] == '' && $user['DATE_ACTIVE_TO'] == '') || !$checkTime)
117 {
118 CAccess::RecalculateForUser($user["USER_ID"], self::ID);
119 }
120 else
121 {
122 if ($user['DATE_ACTIVE_FROM'] != '')
123 {
124 CAccess::RecalculateForUser($user["USER_ID"], self::ID, $user['DATE_ACTIVE_FROM']);
125 }
126 if ($user['DATE_ACTIVE_TO'] != '')
127 {
128 CAccess::RecalculateForUser($user["USER_ID"], self::ID, $user['DATE_ACTIVE_TO']);
129 }
130 }
131 }
132 }
133
134 public function AjaxRequest()
135 {
136 global $USER;
137 if(!$USER->CanDoOperation('view_groups'))
138 return false;
139
140 $elements = "";
141 $arFinderParams = array(
142 "PROVIDER" => $this->id,
143 "TYPE" => 1,
144 );
145
146 $search = urldecode($_REQUEST['search']);
147
148 $dbRes = CGroup::GetList('sort', 'asc', array("ANONYMOUS"=>"N", "NAME"=>$search));
149 $dbRes->NavStart(13);
150 while ($arGroup = $dbRes->NavNext(false))
151 {
152 $arItem = array(
153 "ID" => "G".$arGroup["ID"],
154 "NAME" => $arGroup["NAME"],
155 );
156
157 $elements .= CFinder::GetFinderItem($arFinderParams, $arItem);
158 }
159 return $elements;
160 }
161
162 public function GetFormHtml($arParams=false)
163 {
164 global $USER;
165
166 if (isset($arParams["groups"]) && is_array($arParams["groups"]) && $arParams["groups"]["disabled"] == "true")
167 {
168 return false;
169 }
170
171 if(!$USER->CanDoOperation('view_groups'))
172 return false;
173
174 $elements = $last = "";
175 $arFinderParams = array(
176 "PROVIDER" => $this->id,
177 "TYPE" => 1,
178 );
179
180 $arLRU = CAccess::GetLastRecentlyUsed($this->id);
181
182 $res = CGroup::GetList('sort', 'asc', array("ANONYMOUS"=>"N"));
183 while($arGroup = $res->Fetch())
184 {
185 $arItem = array(
186 "ID" => "G".$arGroup["ID"],
187 "NAME" => $arGroup["NAME"],
188 );
189
190 $element = CFinder::GetFinderItem($arFinderParams, $arItem);
191 $elements .= $element;
192
193 if(in_array($arItem["ID"], $arLRU))
194 $last .= $element;
195 }
196
197 $arPanels = array(
198 array(
199 "NAME" => GetMessage("authprov_last"),
200 "ELEMENTS" => $last,
201 ),
202 array(
203 "NAME" => GetMessage("authprov_all_groups"),
204 "ELEMENTS" => $elements,
205 ),
206 array(
207 "NAME" => GetMessage("authprov_search"),
208 "ELEMENTS" => CFinder::GetFinderItem(array("TYPE" => "text"), array("TEXT" => GetMessage("authprov_group_name"))),
209 "SEARCH" => "Y",
210 ),
211 );
212 $html = CFinder::GetFinderAppearance($arFinderParams, $arPanels);
213
214 return array("HTML"=>$html);
215 }
216
217 public function GetNames($arCodes)
218 {
219 $aID = array();
220 foreach($arCodes as $code)
221 if(preg_match('/^G[0-9]+$/', $code))
222 $aID[] = substr($code, 1);
223
224 if(!empty($aID))
225 {
226 $arResult = array();
227 $res = CGroup::GetList('id', 'asc', array("ANONYMOUS"=>"N", "ID"=>implode("|", $aID)));
228 while($arGroup = $res->Fetch())
229 {
230 $arResult["G".$arGroup["ID"]] = array("provider" => GetMessage("authprov_group_prov"), "name"=>$arGroup["NAME"]);
231 }
232
233 return $arResult;
234 }
235 return false;
236 }
237}
238
240{
241 const ID = 'user';
242
243 public function __construct()
244 {
245 $this->id = self::ID;
246 }
247
248 public function UpdateCodes($USER_ID)
249 {
250 global $DB;
251
252 $USER_ID = intval($USER_ID);
253
254 $connection = Application::getConnection();
255 $helper = $connection->getSqlHelper();
256
257 $sql = $helper->getInsertIgnore(
258 'b_user_access',
259 '(user_id, provider_id, access_code)',
260 "select ID, '".$DB->ForSQL($this->id)."', 'U".$USER_ID."'
261 from b_user
262 where id=".$USER_ID
263 );
264
265 $DB->Query($sql);
266 }
267
268 public function AjaxRequest()
269 {
270 global $USER;
271 if(!$USER->CanDoOperation('view_all_users'))
272 return false;
273
274 $search = urldecode($_REQUEST['search']);
275 $elements = "";
276 $arFinderParams = array(
277 "PROVIDER" => $this->id,
278 "TYPE" => 2,
279 );
280
281 $nameFormat = CSite::GetNameFormat(false);
282
284 'ACTIVE' => 'Y',
285 'NAME_SEARCH' => $search,
286 '!EXTERNAL_AUTH_ID' => \Bitrix\Main\UserTable::getExternalUserTypes(),
287 );
288
289 if (
290 IsModuleInstalled('intranet')
291 || COption::GetOptionString("main", "new_user_registration_email_confirmation", "N") == "Y"
292 )
293 {
294 $arFilter['CONFIRM_CODE'] = false;
295 }
296
297 //be careful with field list because of CUser::FormatName()
298 $dbRes = CUser::GetList('last_name', 'asc',
299 $arFilter,
300 array(
301 "FIELDS" => array('ID', 'NAME', 'LAST_NAME', 'SECOND_NAME', 'LOGIN', 'EMAIL'),
302 'NAV_PARAMS' => array('nTopCount' => 20),
303 )
304 );
305 while ($arUser = $dbRes->NavNext(false))
306 {
307 $arItem = array(
308 "ID" => "U".$arUser["ID"],
309 "NAME" => CUser::FormatName($nameFormat, $arUser, true, false),
310 );
311 $elements .= CFinder::GetFinderItem($arFinderParams, $arItem);
312 }
313 return $elements;
314 }
315
316 public function GetFormHtml($arParams=false)
317 {
318 global $USER;
319
320 if (isset($arParams["user"]) && is_array($arParams["user"]) && $arParams["user"]["disabled"] == "true")
321 {
322 return false;
323 }
324
325 if(!$USER->CanDoOperation('view_all_users'))
326 return false;
327
328 $elements = "";
329 $arFinderParams = array(
330 "PROVIDER" => $this->id,
331 "TYPE" => 2,
332 );
333
334 $arLRU = CAccess::GetLastRecentlyUsed($this->id);
335 if(!empty($arLRU))
336 {
337 foreach($arLRU as $i=>$val)
338 $arLRU[$i] = substr($val, 1);
339
340 $nameFormat = CSite::GetNameFormat(false);
341
342 //be careful with field list because of CUser::FormatName()
343 $res = CUser::GetList("LAST_NAME", "asc",
344 array("ID" => implode("|", $arLRU)),
345 array("FIELDS" => array('ID', 'NAME', 'LAST_NAME', 'SECOND_NAME', 'LOGIN', 'EMAIL'))
346 );
347 while($arUser = $res->Fetch())
348 {
349 $arItem = array(
350 "ID" => "U".$arUser["ID"],
351 "NAME" => CUser::FormatName($nameFormat, $arUser, true, false),
352 );
353 $elements .= CFinder::GetFinderItem($arFinderParams, $arItem);
354 }
355 }
356
357 $arPanels = array(
358 array(
359 "NAME" => GetMessage("authprov_last"),
360 "ELEMENTS" => $elements,
361 ),
362 array(
363 "NAME" => GetMessage("authprov_search"),
364 "ELEMENTS" => CFinder::GetFinderItem(array("TYPE" => "text"), array("TEXT" => GetMessage("authprov_user"))),
365 "SEARCH" => "Y",
366 ),
367 );
368 $html = CFinder::GetFinderAppearance($arFinderParams, $arPanels);
369
370 return array("HTML"=>$html);
371 }
372
373 public function GetNames($arCodes)
374 {
375 $aID = array();
376 foreach($arCodes as $code)
377 {
378 if(!isset($aID[$code]) && preg_match('/^U[0-9]+$/', $code))
379 {
380 $aID[$code] = substr($code, 1);
381 }
382 }
383
384 if(!empty($aID))
385 {
386 $nameFormat = CSite::GetNameFormat(false);
387
388 $arResult = array();
389 //be careful with field list because of CUser::FormatName()
390 $res = CUser::GetList('id', 'asc',
391 array("ID" => implode("|", $aID)),
392 array("FIELDS" => array('ID', 'NAME', 'LAST_NAME', 'SECOND_NAME', 'LOGIN', 'EMAIL'))
393 );
394 while($arUser = $res->Fetch())
395 {
396 $arResult["U".$arUser["ID"]] = array(
397 "provider" => GetMessage("authprov_user1"),
398 "name" => CUser::FormatName($nameFormat, $arUser, true, false),
399 );
400 }
401
402 return $arResult;
403 }
404 return false;
405 }
406}
407
409{
410 public function GetFormHtml($arParams=false)
411 {
412 global $USER;
413
414 if (isset($arParams["other"]) && is_array($arParams["other"]) && $arParams["other"]["disabled"] == "true")
415 {
416 return false;
417 }
418
419 $elements = "";
420 $arFinderParams = array(
421 "PROVIDER" => "other",
422 "TYPE" => 3,
423 );
424
425 $arItem = array(
426 "ID" => "U".$USER->GetID(),
427 "AVATAR" => "/bitrix/js/main/core/images/access/avatar-user-auth.png",
428 "NAME" => (($s = trim($USER->GetFormattedName(false, false))) <> ''? $s : $USER->GetLogin()),
429 "DESC" => GetMessage("authprov_user_curr"),
430 );
431 $elements .= CFinder::GetFinderItem($arFinderParams, $arItem);
432
433 if(!isset($arParams["other"]) || !is_array($arParams["other"]) || $arParams["other"]["disabled_cr"] != "true")
434 {
435 $arItem = array(
436 "ID" => "CR",
437 "AVATAR" => "/bitrix/js/main/core/images/access/avatar-user-author.png",
438 "NAME" => GetMessage("authprov_author"),
439 "DESC" => GetMessage("authprov_author_desc"),
440 );
441 $elements .= CFinder::GetFinderItem($arFinderParams, $arItem);
442 }
443
444 if(!isset($arParams["other"]) || !is_array($arParams["other"]) || $arParams["other"]["disabled_g2"] != "true")
445 {
446 $arItem = array(
447 "ID" => "G2",
448 "AVATAR" => "/bitrix/js/main/core/images/access/avatar-user-everyone.png",
449 "NAME" => GetMessage("authprov_all"),
450 "DESC" => GetMessage("authprov_all_desc"),
451 );
452 $elements .= CFinder::GetFinderItem($arFinderParams, $arItem);
453 }
454
455 if(!isset($arParams["other"]["disabled_au"]) || $arParams["other"]["disabled_au"] != "true")
456 {
457 $arItem = array(
458 "ID" => "AU",
459 "AVATAR" => "/bitrix/js/main/core/images/access/avatar-user-auth.png",
460 "NAME" => GetMessage("authprov_authorized"),
461 "DESC" => GetMessage("authprov_authorized_desc"),
462 );
463 $elements .= CFinder::GetFinderItem($arFinderParams, $arItem);
464 }
465
466 $arPanels = array(
467 array(
468 "NAME" => GetMessage("authprov_other"),
469 "ELEMENTS" => $elements,
470 "SELECTED" => "Y",
471 ),
472 );
473 $html = CFinder::GetFinderAppearance($arFinderParams, $arPanels);
474
475 return array("HTML"=>$html);
476 }
477
478 public function GetNames($arCodes)
479 {
480 return array(
481 "CR" => array("provider"=>"", "name"=>GetMessage("authprov_author")),
482 "G2" => array("provider"=>"", "name"=>GetMessage("authprov_all")),
483 "AU" => array("provider"=>"", "name"=>GetMessage("authprov_authorized")),
484 );
485 }
486}
$arParams
Определения access_dialog.php:21
$connection
Определения actionsdefinitions.php:38
$arResult
Определения generate_coupon.php:16
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
static GetList($by='c_sort', $order='asc', $arFilter=[], $SHOW_USERS_AMOUNT="N")
Определения group.php:136
Определения authproviders.php:17
RemoveCode($userId, $code)
Определения authproviders.php:35
AddCode($userId, $code)
Определения authproviders.php:30
DeleteByUser($USER_ID)
Определения authproviders.php:20
DeleteAll()
Определения authproviders.php:25
$id
Определения authproviders.php:18
static GetFinderAppearance($arParams, $arPanels)
Определения finder.php:12
static GetFinderItem($arParams, $arItem)
Определения finder.php:75
const ID
Определения authproviders.php:49
__construct()
Определения authproviders.php:51
UpdateCodes($USER_ID)
Определения authproviders.php:56
AjaxRequest()
Определения authproviders.php:134
GetNames($arCodes)
Определения authproviders.php:217
static RecalculateForGroup($ID, $checkTime=true)
Определения authproviders.php:107
GetFormHtml($arParams=false)
Определения authproviders.php:162
static OnAfterSetUserGroup($USER_ID, $groups)
Определения authproviders.php:84
GetNames($arCodes)
Определения authproviders.php:478
GetFormHtml($arParams=false)
Определения authproviders.php:410
const ID
Определения authproviders.php:241
__construct()
Определения authproviders.php:243
UpdateCodes($USER_ID)
Определения authproviders.php:248
AjaxRequest()
Определения authproviders.php:268
GetNames($arCodes)
Определения authproviders.php:373
GetFormHtml($arParams=false)
Определения authproviders.php:316
$nameFormat
Определения discount_coupon_list.php:278
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$res
Определения filter_act.php:7
$_REQUEST["admin_mnu_menu_id"]
Определения get_menu.php:8
if($ajaxMode) $ID
Определения get_user.php:27
GetNames($arCodes)
GetFormHtml($arParams=false)
global $DB
Определения cron_frame.php:29
global $USER
Определения csv_new_run.php:40
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
Определения options.php:195
$groups
Определения options.php:30
$arCodes
Определения options.php:154
IsModuleInstalled($module_id)
Определения tools.php:5301
IncludeModuleLangFile($filepath, $lang=false, $bReturnArray=false)
Определения tools.php:3778
GetMessage($name, $aReplace=null)
Определения tools.php:3397
$i
Определения factura.php:643
$val
Определения options.php:1793
$arFilter
Определения user_search.php:106
$dbRes
Определения yandex_detail.php:168