1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
user_perms.php
См. документацию.
1<?
3
5{
6 /***************************************/
7 /******** DATA MODIFICATION **********/
8 /***************************************/
9 public static function CheckFields($ACTION, &$arFields, $ID = 0)
10 {
12
13 if ($ACTION != "ADD" && intval($ID) <= 0)
14 {
15 $GLOBALS["APPLICATION"]->ThrowException("System error 870164", "ERROR");
16 return false;
17 }
18
19 if ((is_set($arFields, "USER_ID") || $ACTION=="ADD") && intval($arFields["USER_ID"]) <= 0)
20 {
21 $GLOBALS["APPLICATION"]->ThrowException(GetMessage("SONET_GB_EMPTY_USER_ID"), "EMPTY_USER_ID");
22 return false;
23 }
24 elseif (is_set($arFields, "USER_ID"))
25 {
26 $dbResult = CUser::GetByID($arFields["USER_ID"]);
27 if (!$dbResult->Fetch())
28 {
29 $GLOBALS["APPLICATION"]->ThrowException(GetMessage("SONET_GB_ERROR_NO_USER_ID"), "ERROR_NO_USER_ID");
30 return false;
31 }
32 }
33
34 if ((is_set($arFields, "OPERATION_ID") || $ACTION=="ADD") && $arFields["OPERATION_ID"] == '')
35 {
36 $GLOBALS["APPLICATION"]->ThrowException(GetMessage("SONET_GG_EMPTY_OPERATION_ID"), "EMPTY_OPERATION_ID");
37 return false;
38 }
39 elseif (is_set($arFields, "OPERATION_ID") && !array_key_exists($arFields["OPERATION_ID"], $arSocNetUserOperations))
40 {
41 $GLOBALS["APPLICATION"]->ThrowException(str_replace("#ID#", $arFields["OPERATION_ID"], GetMessage("SONET_GG_ERROR_NO_OPERATION_ID")), "ERROR_NO_OPERATION_ID");
42 return false;
43 }
44
45 if ((is_set($arFields, "RELATION_TYPE") || $ACTION=="ADD") && $arFields["RELATION_TYPE"] == '')
46 {
47 $GLOBALS["APPLICATION"]->ThrowException(GetMessage("SONET_GG_EMPTY_RELATION_TYPE"), "EMPTY_RELATION_TYPE");
48 return false;
49 }
50 elseif (is_set($arFields, "RELATION_TYPE") && !in_array($arFields["RELATION_TYPE"], $arSocNetAllowedRelationsType))
51 {
52 $GLOBALS["APPLICATION"]->ThrowException(str_replace("#ID#", $arFields["RELATION_TYPE"], GetMessage("SONET_GG_ERROR_NO_RELATION_TYPE")), "ERROR_NO_RELATION_TYPE");
53 return false;
54 }
55 elseif (
56 is_set($arFields, "RELATION_TYPE")
57 && $arFields["RELATION_TYPE"] == SONET_RELATIONS_TYPE_FRIENDS2
58 )
59 {
60 $arFields["RELATION_TYPE"] = SONET_RELATIONS_TYPE_FRIENDS;
61 }
62
63 return True;
64 }
65
66 public static function Delete($ID)
67 {
68 global $DB;
69
70 if (!CSocNetGroup::__ValidateID($ID))
71 return false;
72
73 $ID = intval($ID);
74 $bSuccess = True;
75
76 if ($bSuccess)
77 $bSuccess = $DB->Query("DELETE FROM b_sonet_user_perms WHERE ID = ".$ID."", true);
78
79 return $bSuccess;
80 }
81
82 public static function DeleteNoDemand($userID)
83 {
84 global $DB;
85
86 if (!CSocNetGroup::__ValidateID($userID))
87 return false;
88
89 $userID = intval($userID);
90 $bSuccess = True;
91
92 if ($bSuccess)
93 $bSuccess = $DB->Query("DELETE FROM b_sonet_user_perms WHERE USER_ID = ".$userID."", true);
94
95 return $bSuccess;
96 }
97
98 public static function Update($ID, $arFields)
99 {
100 global $DB;
101
102 if (!CSocNetGroup::__ValidateID($ID))
103 return false;
104
105 $ID = intval($ID);
106
108
110 return false;
111
112 $strUpdate = $DB->PrepareUpdate("b_sonet_user_perms", $arFields);
114
115 if ($strUpdate <> '')
116 {
117 $strSql =
118 "UPDATE b_sonet_user_perms SET ".
119 " ".$strUpdate." ".
120 "WHERE ID = ".$ID." ";
121 $DB->Query($strSql);
122 }
123 else
124 {
125 $ID = False;
126 }
127
128 return $ID;
129 }
130
131 /***************************************/
132 /********** DATA SELECTION ***********/
133 /***************************************/
134 public static function GetByID($ID)
135 {
136 global $DB;
137
138 if (!CSocNetGroup::__ValidateID($ID))
139 return false;
140
141 $ID = intval($ID);
142
143 $dbResult = CSocNetUserPerms::GetList(Array(), Array("ID" => $ID));
144 if ($arResult = $dbResult->GetNext())
145 {
146 return $arResult;
147 }
148
149 return False;
150 }
151
152 /***************************************/
153 /********** COMMON METHODS ***********/
154 /***************************************/
155 public static function GetOperationPerms($userID, $operation)
156 {
158 static $arCachedUserPerms;
159
160 if (
161 is_array($userID)
162 && !$arCachedUserPerms
163 )
164 $arCachedUserPerms = array();
165
166 if (!is_array($userID))
167 {
168 $userID = intval($userID);
169 if ($userID <= 0)
170 return false;
171 }
172
173 $operation = mb_strtolower(Trim($operation));
174 if (!array_key_exists($operation, $arSocNetUserOperations))
175 return false;
176
177 $arUserPerms = array();
178 if (
179 !is_array($userID)
180 && isset($GLOBALS["SONET_USER_PERMS_".$userID])
181 && is_array($GLOBALS["SONET_USER_PERMS_".$userID])
182 && !array_key_exists("SONET_USER_PERMS_".$userID, $_REQUEST)
183 )
184 $arUserPerms = $GLOBALS["SONET_USER_PERMS_".$userID];
185 elseif (
186 !is_array($userID)
187 && isset($arCachedUserPerms[$userID])
188 && is_array($arCachedUserPerms[$userID])
189 && !array_key_exists("SONET_USER_PERMS_".$userID, $_REQUEST)
190 )
191 $arUserPerms = $arCachedUserPerms[$userID];
192 else
193 {
194 $dbResult = CSocNetUserPerms::GetList(Array(), Array("USER_ID" => $userID));
195 while ($arResult = $dbResult->Fetch())
196 {
197 if (!is_array($userID))
198 $arUserPerms[$arResult["OPERATION_ID"]] = $arResult["RELATION_TYPE"];
199 else
200 $arCachedUserPerms[$arResult["USER_ID"]][$arResult["OPERATION_ID"]] = $arResult["RELATION_TYPE"];
201 }
202 if (!is_array($userID))
203 $GLOBALS["SONET_USER_PERMS_".$userID] = $arUserPerms;
204 }
205
206 if (!is_array($userID))
207 {
208 $toUserOperationPerms = (
209 array_key_exists($operation, $arUserPerms)
210 ? $arUserPerms[$operation]
211 : $arSocNetUserOperations[$operation]
212 );
213
214 if ($toUserOperationPerms == SONET_RELATIONS_TYPE_FRIENDS2)
215 {
216 $toUserOperationPerms = SONET_RELATIONS_TYPE_FRIENDS;
217 }
218
219 return $toUserOperationPerms;
220 }
221 else
222 {
223 foreach ($userID as $user_id_tmp)
224 if (!array_key_exists($user_id_tmp, $arCachedUserPerms))
225 $arCachedUserPerms[$user_id_tmp] = array();
226
227 return true;
228 }
229 }
230
231 public static function CanPerformOperation($fromUserID, $toUserID, $operation, $bCurrentUserIsAdmin = false)
232 {
234
235 $fromUserID = intval($fromUserID);
236 $toUserID = intval($toUserID);
237 if ($toUserID <= 0)
238 return false;
239 $operation = mb_strtolower(Trim($operation));
240 if (!array_key_exists($operation, $arSocNetUserOperations))
241 return false;
242
243// use no profile private permission restrictions at the extranet site
244 if (CModule::IncludeModule('extranet') && CExtranet::IsExtranetSite())
245 return true;
246
247 if ($bCurrentUserIsAdmin)
248 return true;
249 if ($fromUserID == $toUserID)
250 return true;
251
252 $usersRelation = CSocNetUserRelations::GetRelation($fromUserID, $toUserID);
253
254 if ($usersRelation == SONET_RELATIONS_BAN && !IsModuleInstalled("im"))
255 return false;
256
257 $toUserOperationPerms = CSocNetUserPerms::GetOperationPerms($toUserID, $operation);
258
259 if ($toUserOperationPerms == SONET_RELATIONS_TYPE_NONE)
260 return false;
261 if ($toUserOperationPerms == SONET_RELATIONS_TYPE_ALL)
262 return true;
263
264 if ($toUserOperationPerms == SONET_RELATIONS_TYPE_AUTHORIZED)
265 {
266 return ($fromUserID > 0);
267 }
268
269 if (
270 $toUserOperationPerms == SONET_RELATIONS_TYPE_FRIENDS
271 || $toUserOperationPerms == SONET_RELATIONS_TYPE_FRIENDS2
272 )
273 {
274 return CSocNetUserRelations::IsFriends($fromUserID, $toUserID);
275 }
276
277 return false;
278 }
279
280 public static function InitUserPerms($currentUserID, $userID, $bCurrentUserIsAdmin)
281 {
283
284 $arReturn = array();
285
286 $currentUserID = intval($currentUserID);
287 $userID = intval($userID);
288
289 if ($userID <= 0)
290 {
291 return false;
292 }
293
294 $arReturn["Operations"] = array();
295 if ($currentUserID <= 0)
296 {
297 $arReturn["IsCurrentUser"] = false;
298 $arReturn["Relation"] = false;
299 $arReturn["Operations"]["modifyuser"] = false;
300 $arReturn["Operations"]["viewcontacts"] = false;
301 foreach ($arSocNetUserOperations as $operation => $defPerm)
302 {
303 $arReturn["Operations"][$operation] = CSocNetUserPerms::CanPerformOperation($currentUserID, $userID, $operation, false);
304 }
305 }
306 else
307 {
308 $arReturn["IsCurrentUser"] = ($currentUserID == $userID);
309 $arReturn["Relation"] = (
310 $arReturn["IsCurrentUser"]
311 ? false
312 : CSocNetUserRelations::GetRelation($currentUserID, $userID)
313 );
314
315 if (
316 $bCurrentUserIsAdmin
317 || $arReturn["IsCurrentUser"]
318 )
319 {
320 $arReturn["Operations"]["modifyuser"] = true;
321 $arReturn["Operations"]["viewcontacts"] = true;
322 foreach ($arSocNetUserOperations as $operation => $defPerm)
323 {
324 $arReturn["Operations"][$operation] = true;
325 }
326 }
327 else
328 {
329 $arReturn["Operations"]["modifyuser"] = false;
330 $arReturn["Operations"]["viewcontacts"] = (
331 CSocNetUser::IsFriendsAllowed()
332 ? ($arReturn["Relation"] == SONET_RELATIONS_FRIEND)
333 : true
334 );
335 foreach ($arSocNetUserOperations as $operation => $defPerm)
336 {
337 $arReturn["Operations"][$operation] = CSocNetUserPerms::CanPerformOperation($currentUserID, $userID, $operation, false);
338 }
339 }
340
341 $arReturn["Operations"]["modifyuser_main"] = false;
342 if ($arReturn["IsCurrentUser"])
343 {
344 if ($USER->CanDoOperation('edit_own_profile'))
345 {
346 $arReturn["Operations"]["modifyuser_main"] = true;
347 }
348 }
349 elseif (
350 $USER->CanDoOperation('edit_all_users')
351 || (
352 $USER->CanDoOperation('edit_subordinate_users')
353 && count(array_diff(CUser::GetUserGroup($userID), CSocNetTools::GetSubordinateGroups($currentUserID))) <= 0
354 )
355 )
356 {
357 $arReturn["Operations"]["modifyuser_main"] = true;
358 }
359 }
360
361 return $arReturn;
362 }
363
364 public static function SetPerm($userID, $feature, $perm)
365 {
366 $userID = intval($userID);
367 $feature = Trim($feature);
368 $perm = Trim($perm);
369
371 array(),
372 array(
373 "USER_ID" => $userID,
374 "OPERATION_ID" => $feature,
375 ),
376 false,
377 false,
378 array("ID")
379 );
380
381 if ($arResult = $dbResult->Fetch())
382 $r = CSocNetUserPerms::Update($arResult["ID"], array("RELATION_TYPE" => $perm));
383 else
384 $r = CSocNetUserPerms::Add(array("USER_ID" => $userID, "OPERATION_ID" => $feature, "RELATION_TYPE" => $perm));
385
386 if (!$r)
387 {
388 $errorMessage = "";
389 if ($e = $GLOBALS["APPLICATION"]->GetException())
390 $errorMessage = $e->GetString();
391 if ($errorMessage == '')
392 $errorMessage = GetMessage("SONET_GF_ERROR_SET").".";
393
394 $GLOBALS["APPLICATION"]->ThrowException($errorMessage, "ERROR_SET_RECORD");
395 return false;
396 }
397 elseif ($feature == "viewprofile")
398 unset($GLOBALS["SONET_USER_PERMS_".$userID]);
399
400 return $r;
401 }
402}
$arResult
Определения generate_coupon.php:16
static processEqualityFieldsToUpdate($fields1, &$update)
Определения util.php:239
static getEqualityFields(&$fields)
Определения util.php:207
static GetOperationPerms($userID, $operation)
Определения user_perms.php:155
static Delete($ID)
Определения user_perms.php:66
static InitUserPerms($currentUserID, $userID, $bCurrentUserIsAdmin)
Определения user_perms.php:280
static GetByID($ID)
Определения user_perms.php:134
static CheckFields($ACTION, &$arFields, $ID=0)
Определения user_perms.php:9
static CanPerformOperation($fromUserID, $toUserID, $operation, $bCurrentUserIsAdmin=false)
Определения user_perms.php:231
static SetPerm($userID, $feature, $perm)
Определения user_perms.php:364
static Update($ID, $arFields)
Определения user_perms.php:98
static DeleteNoDemand($userID)
Определения user_perms.php:82
static GetRelation($firstUserID, $secondUserID)
Определения user_relations.php:256
static IsFriends($firstUserID, $secondUserID)
Определения user_relations.php:355
static GetSubordinateGroups($userID=false)
Определения functions.php:1352
static Add($arFields)
Определения user_perms.php:9
static GetList($arOrder=Array("ID"=> "DESC"), $arFilter=Array(), $arGroupBy=false, $arNavStartParams=false, $arSelectFields=array())
Определения user_perms.php:39
$arFields
Определения dblapprove.php:5
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$perm
Определения options.php:169
$_REQUEST["admin_mnu_menu_id"]
Определения get_menu.php:8
if($ajaxMode) $ID
Определения get_user.php:27
while($arParentIBlockProperty=$dbParentIBlockProperty->Fetch()) $errorMessage
global $DB
Определения cron_frame.php:29
global $USER
Определения csv_new_run.php:40
$ACTION
Определения csv_new_setup.php:27
IsModuleInstalled($module_id)
Определения tools.php:5301
IncludeModuleLangFile($filepath, $lang=false, $bReturnArray=false)
Определения tools.php:3778
is_set($a, $k=false)
Определения tools.php:2133
GetMessage($name, $aReplace=null)
Определения tools.php:3397
return false
Определения prolog_main_admin.php:185
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
Определения waybill.php:936
const SONET_RELATIONS_FRIEND
Определения include.php:24
const SONET_RELATIONS_TYPE_FRIENDS
Определения include.php:41
const SONET_RELATIONS_TYPE_FRIENDS2
Определения include.php:40
const SONET_RELATIONS_TYPE_ALL
Определения include.php:38
const SONET_RELATIONS_TYPE_AUTHORIZED
Определения include.php:39
foreach($arLogEvents as $eventCode=> $arLogEventTmp) global $arSocNetUserOperations
Определения include.php:361
const SONET_RELATIONS_TYPE_NONE
Определения include.php:42
global $arSocNetAllowedRelationsType
Определения include.php:111
const SONET_RELATIONS_BAN
Определения include.php:26
$GLOBALS['_____370096793']
Определения update_client.php:1
$dbResult
Определения updtr957.php:3