This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | 1 | require_once('modules/SecurityGroups/SecurityGroup_sugar.php'); |
|
4 | class SecurityGroup extends SecurityGroup_sugar { |
||
5 | |||
6 | |||
7 | 90 | public function __construct(){ |
|
8 | 90 | parent::__construct(); |
|
9 | 90 | } |
|
10 | |||
11 | /** |
||
12 | * @deprecated deprecated since version 7.6, PHP4 Style Constructors are deprecated and will be remove in 7.8, please update your code, use __construct instead |
||
13 | */ |
||
14 | public function SecurityGroup(){ |
||
15 | $deprecatedMessage = 'PHP4 Style Constructors are deprecated and will be remove in 7.8, please update your code'; |
||
16 | if(isset($GLOBALS['log'])) { |
||
17 | $GLOBALS['log']->deprecated($deprecatedMessage); |
||
18 | } |
||
19 | else { |
||
20 | trigger_error($deprecatedMessage, E_USER_DEPRECATED); |
||
21 | } |
||
22 | self::__construct(); |
||
23 | } |
||
24 | |||
25 | |||
26 | var $last_run = array('module' => '', 'record' => '', 'action' => '', 'response' => ''); |
||
27 | |||
28 | |||
29 | /** |
||
30 | * Gets the join statement used for returning all rows in a list view that a user has group rights to. |
||
31 | * Make sure any use of this also return records that the user has owner access to. |
||
32 | * (e.g. caller uses getOwnerWhere as well) |
||
33 | * |
||
34 | * @param GUID $user_id |
||
35 | * @return STRING |
||
36 | */ |
||
37 | 1 | function getGroupWhere($table_name,$module,$user_id) |
|
38 | { |
||
39 | |||
40 | |||
41 | //need a different query if doing a securitygroups check |
||
42 | 1 | if($module == "SecurityGroups") { |
|
43 | 1 | return " $table_name.id in ( |
|
44 | select secg.id from securitygroups secg |
||
45 | inner join securitygroups_users secu on secg.id = secu.securitygroup_id and secu.deleted = 0 |
||
46 | 1 | and secu.user_id = '$user_id' |
|
47 | where secg.deleted = 0 |
||
48 | 1 | )"; |
|
49 | |||
50 | } else { |
||
51 | return " EXISTS (SELECT 1 |
||
52 | FROM securitygroups secg |
||
53 | INNER JOIN securitygroups_users secu |
||
54 | ON secg.id = secu.securitygroup_id |
||
55 | AND secu.deleted = 0 |
||
56 | 1 | AND secu.user_id = '$user_id' |
|
57 | INNER JOIN securitygroups_records secr |
||
58 | ON secg.id = secr.securitygroup_id |
||
59 | AND secr.deleted = 0 |
||
60 | 1 | AND secr.module = '$module' |
|
61 | 1 | WHERE secr.record_id = ".$table_name.".id |
|
62 | 1 | AND secg.deleted = 0) "; |
|
63 | /** old, slow |
||
64 | return " $table_name.id in ( |
||
65 | select secr.record_id from securitygroups secg |
||
66 | inner join securitygroups_users secu on secg.id = secu.securitygroup_id and secu.deleted = 0 |
||
67 | and secu.user_id = '$user_id' |
||
68 | inner join securitygroups_records secr on secg.id = secr.securitygroup_id and secr.deleted = 0 |
||
69 | and secr.module = '$module' |
||
70 | where secg.deleted = 0 |
||
71 | )"; |
||
72 | */ |
||
73 | |||
74 | //and secr.record_id = $table_name.id //not needed as the in clause takes care of this check |
||
75 | } |
||
76 | } |
||
77 | |||
78 | /** |
||
79 | * Gets the join statement used for returning all users that a given user is in the same group with. |
||
80 | * |
||
81 | * @param GUID $user_id |
||
82 | * @return STRING |
||
83 | */ |
||
84 | 1 | static function getGroupUsersWhere($user_id) |
|
85 | { |
||
86 | |||
87 | return " users.id in ( |
||
88 | select sec.user_id from securitygroups_users sec |
||
89 | inner join securitygroups_users secu on sec.securitygroup_id = secu.securitygroup_id and secu.deleted = 0 |
||
90 | 1 | and secu.user_id = '$user_id' |
|
91 | where sec.deleted = 0 |
||
92 | 1 | )"; |
|
93 | |||
94 | } |
||
95 | |||
96 | /** |
||
97 | * Gets the join statement used for returning all rows in a list view that a user has group rights to. |
||
98 | * Make sure any use of this also return records that the user has owner access to. |
||
99 | * (e.g. caller uses getOwnerWhere as well) |
||
100 | * |
||
101 | * NOTE: Make sure to add the check in the where clause for ($table_name.assigned_user_id or securitygroup_join.record_id is not null) |
||
102 | * |
||
103 | * @param STRING $table_name |
||
104 | * @param STRING $module |
||
105 | * @param GUID $user_id |
||
106 | * @return STRING |
||
107 | */ |
||
108 | 1 | function getGroupJoin($table_name,$module,$user_id) |
|
109 | { |
||
110 | |||
111 | //need a different query if doing a securitygroups check |
||
112 | 1 | if($module == "SecurityGroups") { |
|
113 | return " LEFT JOIN (select distinct secg.id from securitygroups secg |
||
114 | inner join securitygroups_users secu on secg.id = secu.securitygroup_id and secu.deleted = 0 |
||
115 | 1 | and secu.user_id = '".$user_id."' |
|
116 | where secg.deleted = 0 |
||
117 | 1 | ) securitygroup_join on securitygroup_join.id = ".$table_name.".id "; |
|
118 | |||
119 | } else { |
||
120 | return " LEFT JOIN (select distinct secr.record_id as id from securitygroups secg |
||
121 | inner join securitygroups_users secu on secg.id = secu.securitygroup_id and secu.deleted = 0 |
||
122 | 1 | and secu.user_id = '".$user_id."' |
|
123 | inner join securitygroups_records secr on secg.id = secr.securitygroup_id and secr.deleted = 0 |
||
124 | 1 | and secr.module = '".$module."' |
|
125 | where secg.deleted = 0 |
||
126 | 1 | ) securitygroup_join on securitygroup_join.id = ".$table_name.".id "; |
|
127 | } |
||
128 | } |
||
129 | |||
130 | /** |
||
131 | * Gets the join statement used for returning all users that a given user is in the same group with. |
||
132 | * |
||
133 | * @param GUID $user_id |
||
134 | * @return STRING |
||
135 | */ |
||
136 | 1 | function getGroupUsersJoin($user_id) |
|
137 | { |
||
138 | return " LEFT JOIN ( |
||
139 | select distinct sec.user_id as id from securitygroups_users sec |
||
140 | inner join securitygroups_users secu on sec.securitygroup_id = secu.securitygroup_id and secu.deleted = 0 |
||
141 | 1 | and secu.user_id = '$user_id' |
|
142 | where sec.deleted = 0 |
||
143 | 1 | ) securitygroup_join on securitygroup_join.id = users.id "; |
|
144 | |||
145 | } |
||
146 | |||
147 | /** |
||
148 | * @returns true if group is assigned to the record |
||
149 | */ |
||
150 | 42 | static function groupHasAccess($module,$id, $action = '') |
|
151 | { |
||
152 | 42 | if(!isset($id) || $id == '[SELECT_ID_LIST]') |
|
153 | { |
||
154 | 35 | return true; //means that this is a listview and everybody is an owner of the listview |
|
155 | } |
||
156 | |||
157 | 11 | global $db; |
|
158 | 11 | global $current_user; |
|
159 | 11 | global $sugar_config; |
|
160 | $query = "select count(securitygroups.id) as results from securitygroups " |
||
161 | ."inner join securitygroups_users on securitygroups.id = securitygroups_users.securitygroup_id and securitygroups_users.deleted = 0 " |
||
162 | 11 | ." and securitygroups_users.user_id = '$current_user->id' " |
|
163 | 11 | ."inner join securitygroups_records on securitygroups.id = securitygroups_records.securitygroup_id and securitygroups_records.deleted = 0 " |
|
164 | 11 | ." and securitygroups_records.record_id = '$id' " |
|
165 | 11 | ." and securitygroups_records.module = '$module' "; |
|
166 | 11 | if(!empty($action) && isset($sugar_config['securitysuite_strict_rights']) && $sugar_config['securitysuite_strict_rights'] == true) { |
|
167 | $query .= " inner join securitygroups_acl_roles on securitygroups.id = securitygroups_acl_roles.securitygroup_id and securitygroups_acl_roles.deleted = 0" |
||
168 | ." inner join acl_roles_actions on securitygroups_acl_roles.role_id = acl_roles_actions.role_id and acl_roles_actions.deleted = 0 " |
||
169 | ." inner join acl_actions on acl_actions.id = acl_roles_actions.action_id and acl_actions.deleted = 0 " |
||
170 | ." and acl_actions.category = '$module' " |
||
171 | ." and acl_actions.name = '$action' "; |
||
172 | } |
||
173 | 11 | $query .= "where securitygroups.deleted = 0 "; |
|
174 | |||
175 | 11 | if(!empty($action) && isset($sugar_config['securitysuite_strict_rights']) && $sugar_config['securitysuite_strict_rights'] == true) { |
|
176 | $query .= " and acl_roles_actions.access_override = 80 "; |
||
177 | } |
||
178 | 11 | $GLOBALS['log']->debug("SecuritySuite: groupHasAccess $query"); |
|
179 | 11 | $result = $db->query($query); |
|
180 | 11 | $row = $db->fetchByAssoc($result); |
|
181 | 11 | if(isset($row) && $row['results']>0) return true; |
|
182 | |||
183 | 11 | return false; |
|
184 | } |
||
185 | |||
186 | 69 | static function inherit(&$focus,$isUpdate) |
|
187 | { |
||
188 | 69 | global $sugar_config; |
|
189 | 69 | SecurityGroup::assign_default_groups($focus,$isUpdate); //this must be first because it does not check for dups |
|
190 | |||
191 | 69 | SecurityGroup::inherit_assigned($focus,$isUpdate); |
|
192 | 69 | SecurityGroup::inherit_parent($focus,$isUpdate); |
|
193 | |||
194 | //don't do creator inheritance if popup selector method is chosen and a user is making the request... |
||
195 | //don't if saving from a popup (subpanel_field_name check. Save2 is the action but to be safe use the subpanel check) |
||
196 | if( |
||
197 | 69 | (isset($sugar_config['securitysuite_popup_select']) && $sugar_config['securitysuite_popup_select'] == true |
|
198 | 69 | && isset($_REQUEST['action']) && $_REQUEST['action'] == 'Save') |
|
199 | 69 | || (!empty($_REQUEST['subpanel_field_name'])) |
|
200 | ) { |
||
201 | //check to see if a member of more than 1 group...if not then just inherit the one. |
||
202 | //Otherwise, this is taken on the edit view on create now |
||
203 | 1 | $groupFocus = new SecurityGroup(); |
|
204 | 1 | $security_modules = $groupFocus->getSecurityModules(); |
|
205 | 1 | if(in_array($focus->module_dir,array_keys($security_modules))) { |
|
206 | //check if user is in more than 1 group. If so then set the session var otherwise inherit it's only group |
||
207 | 1 | global $current_user; |
|
208 | |||
209 | 1 | $memberships = $groupFocus->getMembershipCount($current_user->id); |
|
210 | 1 | if($memberships > 1) { |
|
211 | return; |
||
212 | } |
||
213 | } |
||
214 | } |
||
215 | 69 | SecurityGroup::inherit_creator($focus,$isUpdate); |
|
216 | |||
217 | 69 | } |
|
218 | |||
219 | 70 | static function assign_default_groups(&$focus,$isUpdate) |
|
220 | { |
||
221 | 70 | global $sugar_config; |
|
222 | 70 | global $current_user; |
|
223 | 70 | if(!$isUpdate) { |
|
224 | //inherit only for those that support Security Groups |
||
225 | 65 | $groupFocus = new SecurityGroup(); |
|
226 | 65 | $security_modules = $groupFocus->getSecurityModules(); |
|
227 | 65 | if(!in_array($focus->module_dir,array_keys($security_modules))) { |
|
228 | 57 | return; |
|
229 | } |
||
230 | |||
231 | 26 | $defaultGroups = $groupFocus->retrieveDefaultGroups(); |
|
232 | 26 | foreach($defaultGroups as $default_id => $defaultGroup) { |
|
233 | |||
234 | if($defaultGroup['module'] == "All" || $defaultGroup['module'] == $focus->module_dir) { |
||
235 | if($focus->module_dir == "Users") { |
||
236 | $query = "insert into securitygroups_users(id,date_modified,deleted,securitygroup_id,user_id,noninheritable) " |
||
237 | ."select distinct '".create_guid()."',".db_convert('','today').",0,g.id,'$focus->id',1 " |
||
0 ignored issues
–
show
|
|||
238 | ."from securitygroups g " |
||
239 | ."left join securitygroups_users d on d.securitygroup_id = g.id and d.user_id = '$focus->id' and d.deleted = 0 " |
||
240 | ."where d.id is null and g.id = '".$defaultGroup['securitygroup_id']."' and g.deleted = 0 "; |
||
241 | } else { |
||
242 | $query = "insert into securitygroups_records(id,securitygroup_id,record_id,module,date_modified,deleted) " |
||
243 | ."select distinct '".create_guid()."',g.id,'$focus->id','$focus->module_dir',".db_convert('','today').",0 " |
||
0 ignored issues
–
show
The function
db_convert() has been deprecated with message: use DBManager::convert() instead.
This function has been deprecated. The supplier of the file has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead. ![]() |
|||
244 | ."from securitygroups g " |
||
245 | ."left join securitygroups_records d on d.securitygroup_id = g.id and d.record_id = '$focus->id' and d.module = '$focus->module_dir' and d.deleted = 0 " |
||
246 | ."where d.id is null and g.id = '".$defaultGroup['securitygroup_id']."' and g.deleted = 0 "; |
||
247 | } |
||
248 | $GLOBALS['log']->debug("SecuritySuite: Assign Default Groups: $query"); |
||
249 | $focus->db->query($query,true); |
||
250 | } |
||
251 | } //end foreach default group |
||
252 | } |
||
253 | |||
254 | 38 | } |
|
255 | |||
256 | 70 | static function inherit_creator(&$focus,$isUpdate) |
|
257 | { |
||
258 | 70 | global $sugar_config; |
|
259 | 70 | global $current_user; |
|
260 | 70 | if(!$isUpdate && isset($sugar_config['securitysuite_inherit_creator']) && $sugar_config['securitysuite_inherit_creator'] == true) { |
|
261 | |||
262 | 65 | if(isset($_SESSION['portal_id']) && isset($_SESSION['user_id'])) { |
|
263 | return; //don't inherit if from portal |
||
264 | } |
||
265 | |||
266 | //inherit only for those that support Security Groups |
||
267 | 65 | $groupFocus = new SecurityGroup(); |
|
268 | 65 | $security_modules = $groupFocus->getSecurityModules(); |
|
269 | //if(in_array($focus->module_dir,$security_modules)) { |
||
270 | 65 | if(in_array($focus->module_dir,array_keys($security_modules))) {//rost fix2 |
|
271 | |||
272 | //test to see if works for creating a note for a case from the portal...this may need to be handled slightly differently |
||
273 | //inherits portal users groups? Could be an interesting twist... |
||
274 | $query = "insert into securitygroups_records(id,securitygroup_id,record_id,module,date_modified,deleted) " |
||
275 | 26 | ."select distinct "; |
|
276 | 26 | if($focus->db->dbType == 'mysql') { |
|
277 | 26 | $query .= " uuid() "; |
|
278 | } else if($focus->db->dbType == 'mssql') { |
||
279 | $query .= " lower(newid()) "; |
||
280 | } |
||
281 | 26 | $currentUserId = isset($current_user->id) ? $current_user->id : null; |
|
282 | 26 | $query .= ",u.securitygroup_id,'$focus->id','$focus->module_dir',".db_convert('','today').",0 " |
|
0 ignored issues
–
show
The function
db_convert() has been deprecated with message: use DBManager::convert() instead.
This function has been deprecated. The supplier of the file has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead. ![]() |
|||
283 | 26 | ."from securitygroups_users u " |
|
284 | 26 | ."inner join securitygroups g on u.securitygroup_id = g.id and g.deleted = 0 and (g.noninheritable is null or g.noninheritable <> 1) " |
|
285 | 26 | ."left join securitygroups_records d on d.securitygroup_id = u.securitygroup_id and d.record_id = '$focus->id' and d.module = '$focus->module_dir' and d.deleted = 0 " |
|
286 | 26 | ."where d.id is null and u.user_id = '$currentUserId' and u.deleted = 0 and (u.noninheritable is null or u.noninheritable <> 1)"; |
|
287 | 26 | $GLOBALS['log']->debug("SecuritySuite: Inherit from Creator: $query"); |
|
288 | 26 | $focus->db->query($query,true); |
|
289 | } |
||
290 | } |
||
291 | |||
292 | 70 | } |
|
293 | |||
294 | 70 | static function inherit_assigned(&$focus,$isUpdate) |
|
295 | { |
||
296 | 70 | global $sugar_config; |
|
297 | 70 | global $current_user; |
|
298 | 70 | if(isset($sugar_config['securitysuite_inherit_assigned']) && $sugar_config['securitysuite_inherit_assigned'] == true) { |
|
299 | |||
300 | 70 | if(!empty($focus->assigned_user_id)) { |
|
301 | 11 | $assigned_user_id = $focus->assigned_user_id; |
|
302 | //inherit only for those that support Security Groups |
||
303 | 11 | $groupFocus = new SecurityGroup(); |
|
304 | 11 | $security_modules = $groupFocus->getSecurityModules(); |
|
305 | //if(in_array($focus->module_dir,$security_modules)) { |
||
306 | 11 | if(in_array($focus->module_dir,array_keys($security_modules))) {//rost fix2 |
|
307 | |||
308 | //test to see if works for creating a note for a case from the portal...this may need to be handled slightly differently |
||
309 | //inherits portal users groups? Could be an interesting twist... |
||
310 | $query = "insert into securitygroups_records(id,securitygroup_id,record_id,module,date_modified,deleted) " |
||
311 | 3 | ."select distinct "; |
|
312 | 3 | if($focus->db->dbType == 'mysql') { |
|
313 | 3 | $query .= " uuid() "; |
|
314 | } else if($focus->db->dbType == 'mssql') { |
||
315 | $query .= " lower(newid()) "; |
||
316 | } |
||
317 | 3 | $query .= ",u.securitygroup_id,'$focus->id','$focus->module_dir',".db_convert('','today').",0 " |
|
0 ignored issues
–
show
The function
db_convert() has been deprecated with message: use DBManager::convert() instead.
This function has been deprecated. The supplier of the file has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead. ![]() |
|||
318 | 3 | ."from securitygroups_users u " |
|
319 | 3 | ."inner join securitygroups g on u.securitygroup_id = g.id and g.deleted = 0 and (g.noninheritable is null or g.noninheritable <> 1) " |
|
320 | 3 | ."left join securitygroups_records d on d.securitygroup_id = u.securitygroup_id and d.record_id = '$focus->id' and d.module = '$focus->module_dir' and d.deleted = 0 " |
|
321 | 3 | ."where d.id is null and u.user_id = '$assigned_user_id' and u.deleted = 0 and (u.noninheritable is null or u.noninheritable <> 1)"; |
|
322 | 3 | $GLOBALS['log']->debug("SecuritySuite: Inherit from Assigned: $query"); |
|
323 | 3 | $focus->db->query($query,true); |
|
324 | } |
||
325 | } //if !empty assigned_user_id |
||
326 | } |
||
327 | |||
328 | 70 | } |
|
329 | |||
330 | 70 | static function inherit_parent(&$focus,$isUpdate) |
|
331 | { |
||
332 | 70 | global $sugar_config; |
|
333 | //new record or if update from soap api for cases or bugs |
||
334 | //TEST FOR PORTAL NOTES |
||
335 | //if((!$isUpdate || ($isUpdate && !empty($focus->note_id) && ($focus->object_name == "Case" || $focus->object_name == "Bug"))) |
||
336 | 70 | if(!$isUpdate |
|
337 | 70 | && isset($sugar_config['securitysuite_inherit_parent']) && $sugar_config['securitysuite_inherit_parent'] == true) { |
|
338 | |||
339 | 65 | $focus_module_dir = $focus->module_dir; |
|
340 | 65 | $focus_id = $focus->id; |
|
341 | |||
342 | //inherit only for those that support Security Groups |
||
343 | 65 | $groupFocus = new SecurityGroup(); |
|
344 | 65 | $security_modules = $groupFocus->getSecurityModules(); |
|
345 | //if(!in_array($focus_module_dir,$security_modules)) { |
||
346 | 65 | if(!in_array($focus_module_dir,array_keys($security_modules))) {//rost fix2 |
|
347 | 57 | return; //don't inherit for this module |
|
348 | } |
||
349 | |||
350 | //from subpanel |
||
351 | //PHP Notice error fix |
||
352 | 26 | $parent_type = ""; |
|
353 | 26 | $parent_id = ""; |
|
354 | |||
355 | 26 | if(isset($_REQUEST['relate_to']) && isset($_REQUEST['relate_id'])) { |
|
356 | //relate_to is not guaranteed to be a module name anymore. |
||
357 | //if it isn't load the relationship and find the module name that way |
||
358 | if(!in_array($_REQUEST['relate_to'],array_keys($security_modules))) { |
||
359 | //check to see if relate_to is the relationship name |
||
360 | require_once('modules/Relationships/Relationship.php'); |
||
361 | $rel_module = Relationship::get_other_module($_REQUEST['relate_to'], $focus_module_dir, $focus->db); |
||
362 | if(isset($rel)) { |
||
0 ignored issues
–
show
The variable
$rel seems to never exist, and therefore isset should always return false . Did you maybe rename this variable?
This check looks for calls to This is most likely caused by the renaming of a variable or the removal of a function/method parameter. ![]() |
|||
363 | $parent_type = $rel_module; |
||
364 | $parent_id = $_REQUEST['relate_id']; |
||
365 | } |
||
366 | } else { |
||
367 | $parent_type = $_REQUEST['relate_to']; |
||
368 | $parent_id = $_REQUEST['relate_id']; |
||
369 | } |
||
370 | } |
||
371 | |||
372 | 26 | if(isset($_SESSION['portal_id'])) { |
|
373 | $parent_id = $_SESSION['user_id']; //soap stores contact id in user_id field |
||
374 | $parent_type = "Contacts"; |
||
375 | } |
||
376 | |||
377 | //from activity type creation |
||
378 | 26 | if((empty($parent_type) || empty($parent_id)) && isset($_REQUEST['parent_type']) && isset($_REQUEST['parent_id'])) { |
|
379 | $parent_type = $_REQUEST['parent_type']; |
||
380 | $parent_id = $_REQUEST['parent_id']; |
||
381 | } |
||
382 | |||
383 | //full form from subpanel |
||
384 | 26 | if((empty($parent_type) || empty($parent_id)) && isset($_REQUEST['return_module']) && isset($_REQUEST['return_id'])) { |
|
385 | $parent_type = $_REQUEST['return_module']; |
||
386 | $parent_id = $_REQUEST['return_id']; |
||
387 | } |
||
388 | |||
389 | /** need to find relate fields...for example for Cases look to see if account_id is set */ |
||
390 | //allow inheritance for all relate field types....iterate through and inherit each related field |
||
391 | //if(empty($parent_type) || empty($parent_id)) { |
||
392 | 26 | foreach($focus->field_name_map as $name=>$def) { |
|
393 | |||
394 | 26 | if($def['type']=='relate' && isset($def['id_name']) |
|
395 | 26 | && isset($def['module']) && strtolower($def['module']) != "users" ) { |
|
396 | |||
397 | 17 | if(isset($_REQUEST[$def['id_name']])) { |
|
398 | $relate_parent_id = $_REQUEST[$def['id_name']]; |
||
399 | $relate_parent_type = $def['module']; |
||
400 | |||
401 | SecurityGroup::inherit_parentQuery($focus,$relate_parent_type, $relate_parent_id, $focus_id, $focus_module_dir); |
||
402 | 17 | } else if(isset($_SESSION['portal_id']) && isset($_SESSION[$def['id_name']])) { //catch soap account |
|
403 | $relate_parent_id = $_SESSION[$def['id_name']]; |
||
404 | $relate_parent_type = $def['module']; |
||
405 | |||
406 | 26 | SecurityGroup::inherit_parentQuery($focus, $relate_parent_type, $relate_parent_id, $focus_id, $focus_module_dir); |
|
407 | } |
||
408 | } |
||
409 | } |
||
410 | //} |
||
411 | |||
412 | 26 | if(!empty($parent_type) && !empty($parent_id)) { // && $parent_type != "Emails" && $parent_type != "Meetings") { |
|
413 | SecurityGroup::inherit_parentQuery($focus, $parent_type, $parent_id, $focus_id, $focus_module_dir); |
||
414 | } //end if parent type/id |
||
415 | } //end if new record |
||
416 | 38 | } |
|
417 | |||
418 | 1 | static function inherit_parentQuery(&$focus, $parent_type, $parent_id, $focus_id, $focus_module_dir) { |
|
419 | 1 | if(empty($parent_type) || empty($parent_id)) return; //no info passed |
|
420 | |||
421 | /** can speed this up by doing one query */ |
||
422 | //should be just one query but need a unique guid for each insert |
||
423 | //WE NEED A UNIQUE GUID SO USE THE BUILT IN SQL GUID METHOD |
||
424 | $query = "insert into securitygroups_records(id,securitygroup_id,record_id,module,date_modified,deleted) " |
||
425 | 1 | ."select distinct "; |
|
426 | 1 | if($focus->db->dbType == 'mysql') { |
|
427 | 1 | $query .= " uuid() "; |
|
428 | } else if($focus->db->dbType == 'mssql') { |
||
429 | $query .= " lower(newid()) "; |
||
430 | } |
||
431 | 1 | $query .= ",r.securitygroup_id,'$focus_id','$focus_module_dir',".db_convert('','today').",0 " |
|
0 ignored issues
–
show
The function
db_convert() has been deprecated with message: use DBManager::convert() instead.
This function has been deprecated. The supplier of the file has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead. ![]() |
|||
432 | 1 | ."from securitygroups_records r " |
|
433 | 1 | ."inner join securitygroups g on r.securitygroup_id = g.id and g.deleted = 0 and (g.noninheritable is null or g.noninheritable <> 1) " |
|
434 | 1 | ."left join securitygroups_records d on d.securitygroup_id = r.securitygroup_id and d.record_id = '" .$focus->db->quote($focus_id) . "' and d.module = '" .$focus->db->quote($focus_module_dir) . "' and d.deleted = 0 " |
|
435 | 1 | ."where d.id is null and r.module = '" .$focus->db->quote($parent_type) . "' " |
|
436 | 1 | ."and r.record_id = '" .$focus->db->quote($parent_id) ."' " |
|
437 | 1 | ."and r.deleted = 0 "; |
|
438 | //using left join instead |
||
439 | //and not exists (select top 1 s.id from securitygroups_records s where s.deleted = 0 and s.record_id = '$focus_id' and s.securitygroup_id = r.securitygroup_id and s.module = '$focus_module_dir') "; |
||
440 | 1 | $GLOBALS['log']->debug("SecuritySuite: Inherit from Parent: $query"); |
|
441 | 1 | $focus->db->query($query,true); |
|
442 | 1 | } |
|
443 | |||
444 | /** |
||
445 | * If user is a member of just one group inherit group for new record |
||
446 | * returns true if inherit just one else false |
||
447 | */ |
||
448 | 1 | function inheritOne($user_id, $record_id, $module) { |
|
449 | //check to see if in just one group...if so, inherit that group and return true |
||
450 | 1 | global $db; |
|
451 | |||
452 | $query = "select count(securitygroups.id) as results from securitygroups " |
||
453 | ."inner join securitygroups_users on securitygroups.id = securitygroups_users.securitygroup_id " |
||
454 | ." and securitygroups_users.deleted = 0 " |
||
455 | 1 | ." where securitygroups.deleted = 0 and securitygroups_users.user_id = '$user_id' " |
|
456 | 1 | ." and (securitygroups.noninheritable is null or securitygroups.noninheritable <> 1) " |
|
457 | 1 | ." and (securitygroups_users.noninheritable is null or securitygroups_users.noninheritable <> 1) "; |
|
458 | 1 | $GLOBALS['log']->debug("SecuritySuite: Inherit One Pre-Check Qualifier: $query"); |
|
459 | 1 | $result = $db->query($query); |
|
460 | 1 | $row = $db->fetchByAssoc($result); |
|
461 | 1 | if(isset($row) && $row['results'] == 1) { |
|
462 | |||
463 | $query = "insert into securitygroups_records(id,securitygroup_id,record_id,module,date_modified,deleted) " |
||
464 | ."select distinct '".create_guid()."',u.securitygroup_id,'$record_id','$module',".db_convert('','today').",0 " |
||
0 ignored issues
–
show
The function
db_convert() has been deprecated with message: use DBManager::convert() instead.
This function has been deprecated. The supplier of the file has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead. ![]() |
|||
465 | ."from securitygroups_users u " |
||
466 | ."inner join securitygroups g on u.securitygroup_id = g.id and g.deleted = 0 and (g.noninheritable is null or g.noninheritable <> 1) " |
||
467 | ."left join securitygroups_records d on d.securitygroup_id = u.securitygroup_id and d.record_id = '$record_id' and d.module = '$module' and d.deleted = 0 " |
||
468 | ."where d.id is null and u.user_id = '$user_id' and u.deleted = 0 and (u.noninheritable is null or u.noninheritable <> 1)"; |
||
469 | $GLOBALS['log']->debug("SecuritySuite: Inherit One: $query"); |
||
470 | $db->query($query,true); |
||
471 | return true; |
||
472 | } |
||
473 | |||
474 | 1 | return false; |
|
475 | } |
||
476 | |||
477 | /** |
||
478 | * returns # of groups a user is a member of that are inheritable |
||
479 | * |
||
480 | * TODO: cache this value in the session var |
||
481 | */ |
||
482 | 2 | function getMembershipCount($user_id) { |
|
483 | 2 | global $db; |
|
484 | |||
485 | 2 | if(!isset($_SESSION['securitygroup_count'])) { |
|
486 | $query = "select count(securitygroups.id) as results from securitygroups " |
||
487 | ."inner join securitygroups_users on securitygroups.id = securitygroups_users.securitygroup_id " |
||
488 | ." and securitygroups_users.deleted = 0 " |
||
489 | 2 | ." where securitygroups.deleted = 0 and securitygroups_users.user_id = '$user_id' " |
|
490 | 2 | ." and (securitygroups.noninheritable is null or securitygroups.noninheritable <> 1) " |
|
491 | 2 | ." and (securitygroups_users.noninheritable is null or securitygroups_users.noninheritable <> 1) "; |
|
492 | 2 | $GLOBALS['log']->debug("SecuritySuite: Inherit One Pre-Check Qualifier: $query"); |
|
493 | 2 | $result = $db->query($query); |
|
494 | 2 | $row = $db->fetchByAssoc($result); |
|
495 | 2 | if(isset($row)) { |
|
496 | 2 | $_SESSION['securitygroup_count'] = $row['results']; |
|
497 | } |
||
498 | } |
||
499 | |||
500 | 2 | return $_SESSION['securitygroup_count']; |
|
501 | } |
||
502 | |||
503 | 27 | function retrieveDefaultGroups() { |
|
504 | 27 | global $db; |
|
505 | |||
506 | 27 | $default_groups = array(); |
|
507 | $query = "select securitygroups_default.id, securitygroups.name, securitygroups_default.module, securitygroups_default.securitygroup_id " |
||
508 | ."from securitygroups_default " |
||
509 | ."inner join securitygroups on securitygroups_default.securitygroup_id = securitygroups.id " |
||
510 | 27 | ."where securitygroups_default.deleted = 0 and securitygroups.deleted = 0"; |
|
511 | 27 | $GLOBALS['log']->debug("SecuritySuite: Retrieve Default Groups: $query"); |
|
512 | 27 | $result = $db->query($query); |
|
513 | 27 | while(($row=$db->fetchByAssoc($result)) != null) { |
|
514 | 1 | $default_groups[$row['id']] = array('group'=>$row['name'],'module'=>$row['module'],'securitygroup_id'=>$row['securitygroup_id']); |
|
515 | } |
||
516 | |||
517 | 27 | return $default_groups; |
|
518 | } |
||
519 | |||
520 | 1 | function saveDefaultGroup($group_id, $module) { |
|
521 | $query = "INSERT INTO securitygroups_default (id, securitygroup_id, module, date_modified, deleted) " |
||
522 | 1 | ."VALUES ( "; |
|
523 | 1 | if($this->db->dbType == 'mysql') { |
|
0 ignored issues
–
show
The property
dbType does not exist on object<DBManager> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
524 | 1 | $query .= " uuid() "; |
|
525 | } else if($this->db->dbType == 'mssql') { |
||
0 ignored issues
–
show
The property
dbType does not exist on object<DBManager> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
526 | $query .= " lower(newid()) "; |
||
527 | } |
||
528 | 1 | $query .= ",'" . htmlspecialchars($group_id , ENT_QUOTES) ."', '" . htmlspecialchars($group_id , ENT_QUOTES) . "',".db_convert('','today').",0 )"; |
|
0 ignored issues
–
show
The function
db_convert() has been deprecated with message: use DBManager::convert() instead.
This function has been deprecated. The supplier of the file has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead. ![]() |
|||
529 | 1 | $GLOBALS['log']->debug("SecuritySuite: Save Default Group: $query"); |
|
530 | 1 | $this->db->query($query); |
|
531 | 1 | } |
|
532 | |||
533 | 1 | function removeDefaultGroup($default_id) { |
|
534 | 1 | $query = "delete from securitygroups_default where id = '" . htmlspecialchars($default_id) ."' "; |
|
535 | 1 | $this->db->query($query); |
|
536 | 1 | } |
|
537 | |||
538 | /** |
||
539 | * Used to get the modules that are tied to security groups. |
||
540 | * There should be a relationship of some sort in order to tie the two together. |
||
541 | * |
||
542 | * This will be used for things such as default groups for modules, etc. |
||
543 | */ |
||
544 | 69 | function getSecurityModules() { |
|
545 | 69 | global $app_list_strings; |
|
546 | |||
547 | 69 | $security_modules = array(); |
|
548 | |||
549 | //https://www.sugaroutfitters.com/support/securitysuite/496 |
||
550 | //There are some modules that shouldn't ever inherit groups... |
||
551 | 69 | $module_blacklist = array('SchedulersJobs','Schedulers','Trackers'); |
|
552 | |||
553 | 69 | require_once('modules/Relationships/Relationship.php'); |
|
554 | 69 | $rs = new Relationship(); |
|
555 | 69 | $query = "SELECT lhs_module, rhs_module FROM $rs->table_name WHERE deleted=0 AND (lhs_module = 'SecurityGroups' OR rhs_module='SecurityGroups')"; |
|
556 | 69 | $GLOBALS['log']->debug("SecuritySuite: Get SecuritySuite Enabled Modules: $query"); |
|
557 | 69 | $result = $rs->db->query($query); |
|
558 | 69 | while(($row=$rs->db->fetchByAssoc($result)) != null) { |
|
559 | |||
560 | 69 | if($row['lhs_module'] == 'SecurityGroups') { |
|
561 | 69 | if(in_array($row['rhs_module'],$module_blacklist)) { |
|
562 | continue; |
||
563 | } |
||
564 | |||
565 | //$security_modules[$row['rhs_module']] = $row['rhs_module']; |
||
566 | 69 | $security_modules[$row['rhs_module']] = $app_list_strings['moduleList'][$row['rhs_module']];//rost fix |
|
567 | } else { |
||
568 | 69 | if(in_array($row['lhs_module'],$module_blacklist)) { |
|
569 | continue; |
||
570 | } |
||
571 | |||
572 | //$security_modules[$row['lhs_module']] = $row['lhs_module']; |
||
573 | 69 | $security_modules[$row['lhs_module']] = $app_list_strings['moduleList'][$row['lhs_module']];//rost fix |
|
574 | |||
575 | } |
||
576 | } |
||
577 | |||
578 | 69 | return $security_modules; |
|
579 | } |
||
580 | |||
581 | /** To get the link name used to call load_relationship */ |
||
582 | 1 | function getLinkName($this_module, $rel_module) { |
|
583 | 1 | $GLOBALS['log']->debug("SecurityGroup->getLinkName this_module: $this_module rel_module: $rel_module"); |
|
584 | 1 | include_once('modules/Relationships/RelationshipHandler.php'); |
|
585 | 1 | $rh = new RelationshipHandler($GLOBALS['db'],$this_module); |
|
586 | 1 | $rh->process_by_rel_bean($rel_module); |
|
587 | 1 | $rh->build_info(); |
|
588 | 1 | $rh->get_rel1_vardef_field_base($rh->base_bean->field_defs); |
|
589 | 1 | return $rh->rel1_vardef_field_base; |
|
590 | |||
591 | } |
||
592 | |||
593 | /** |
||
594 | * Add a Security Group to a record |
||
595 | */ |
||
596 | 1 | function addGroupToRecord($module, $record_id, $securitygroup_id) { |
|
597 | 1 | if(empty($module) || empty($record_id) || empty($securitygroup_id)) { |
|
598 | return; //missing data |
||
599 | } |
||
600 | 1 | global $db; |
|
601 | $query = "insert into securitygroups_records(id,securitygroup_id,record_id,module,date_modified,deleted) " |
||
602 | 1 | ."values( '".create_guid()."','".$securitygroup_id."','$record_id','$module',".db_convert('','today').",0) "; |
|
0 ignored issues
–
show
The function
db_convert() has been deprecated with message: use DBManager::convert() instead.
This function has been deprecated. The supplier of the file has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead. ![]() |
|||
603 | 1 | $GLOBALS['log']->debug("SecuritySuite: addGroupToRecord: $query"); |
|
604 | 1 | $db->query($query,true); |
|
605 | 1 | } |
|
606 | |||
607 | /** |
||
608 | * Remove a Security Group from a record |
||
609 | */ |
||
610 | 1 | function removeGroupFromRecord($module, $record_id, $securitygroup_id) { |
|
611 | 1 | if(empty($module) || empty($record_id) || empty($securitygroup_id)) { |
|
612 | return; //missing data |
||
613 | } |
||
614 | 1 | global $db; |
|
615 | 1 | $query = "update securitygroups_records set deleted = 1, date_modified = ".db_convert('','today')." " |
|
0 ignored issues
–
show
The function
db_convert() has been deprecated with message: use DBManager::convert() instead.
This function has been deprecated. The supplier of the file has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead. ![]() |
|||
616 | 1 | ."where securitygroup_id = '".$securitygroup_id."' and record_id = '$record_id' and module = '$module'"; |
|
617 | 1 | $GLOBALS['log']->debug("SecuritySuite: addGroupToRecord: $query"); |
|
618 | 1 | $db->query($query,true); |
|
619 | 1 | } |
|
620 | |||
621 | /** |
||
622 | * Return a list of groups that this user belongs to. |
||
623 | */ |
||
624 | 1 | function getUserSecurityGroups($user_id) |
|
625 | { |
||
626 | 1 | global $db; |
|
627 | $query = "select securitygroups.id, securitygroups.name from securitygroups_users " |
||
628 | ."inner join securitygroups on securitygroups_users.securitygroup_id = securitygroups.id " |
||
629 | ." and securitygroups.deleted = 0 " |
||
630 | 1 | ."where securitygroups_users.user_id='$user_id' and securitygroups_users.deleted = 0 " |
|
631 | 1 | ."order by securitygroups.name asc "; |
|
632 | 1 | $result = $db->query($query,true,"Error finding the full membership list for a user: "); |
|
633 | |||
634 | 1 | $group_array = Array(); |
|
635 | 1 | $result = $db->query($query); |
|
636 | 1 | while(($row=$db->fetchByAssoc($result)) != null) { |
|
637 | $group_array[$row['id']] = $row; |
||
638 | } |
||
639 | |||
640 | 1 | return $group_array; |
|
641 | } |
||
642 | |||
643 | /** |
||
644 | * Return a list of all groups |
||
645 | */ |
||
646 | 1 | function getAllSecurityGroups() |
|
647 | { |
||
648 | 1 | global $db; |
|
649 | $query = "select id, name from securitygroups " |
||
650 | ."where securitygroups.deleted = 0 " |
||
651 | 1 | ."order by name"; |
|
652 | 1 | $result = $db->query($query,true,"Error finding the full membership list for a user: "); |
|
653 | |||
654 | 1 | $group_array = Array(); |
|
655 | 1 | $result = $db->query($query); |
|
656 | 1 | while(($row=$db->fetchByAssoc($result)) != null) { |
|
657 | $group_array[$row['id']] = $row; |
||
658 | } |
||
659 | |||
660 | 1 | return $group_array; |
|
661 | } |
||
662 | |||
663 | /** |
||
664 | * Return a list of all members of a group |
||
665 | */ |
||
666 | 1 | function getMembers() |
|
667 | { |
||
668 | 1 | global $db; |
|
669 | |||
670 | $query = "select users.id, users.user_name, users.first_name, users.last_name " |
||
671 | ."from securitygroups " |
||
672 | ."inner join securitygroups_users on securitygroups.id = securitygroups_users.securitygroup_id " |
||
673 | ." and securitygroups_users.deleted = 0 " |
||
674 | ."inner join users on securitygroups_users.user_id = users.id and users.deleted = 0 " |
||
675 | ." where securitygroups.deleted = 0 and users.employee_status = 'Active' " |
||
676 | 1 | ." and securitygroups.id = '$this->id' " |
|
677 | 1 | ." order by users.user_name asc "; |
|
678 | 1 | $GLOBALS['log']->debug("SecuritySuite: getMembers: $query"); |
|
679 | 1 | $user_array = Array(); |
|
680 | 1 | $result = $db->query($query); |
|
681 | 1 | while(($row=$db->fetchByAssoc($result)) != null) { |
|
682 | $user_array[$row['id']] = $row; |
||
683 | } |
||
684 | |||
685 | 1 | return $user_array; |
|
686 | } |
||
687 | |||
688 | /** |
||
689 | * For the current user, grab the user's primary group (if none, then first related group) |
||
690 | * |
||
691 | * Used in the various MVC views to determine which group layout to load. |
||
692 | */ |
||
693 | 1 | static function getPrimaryGroupID() |
|
694 | { |
||
695 | 1 | $primary_group_id = null; |
|
696 | 1 | global $db, $current_user; |
|
697 | 1 | $query = "select "; |
|
698 | 1 | if($db->dbType == 'mssql') { |
|
699 | $query .= " top 1 "; |
||
700 | } |
||
701 | $query .= "securitygroups.id from securitygroups_users |
||
702 | inner join securitygroups on securitygroups_users.securitygroup_id = securitygroups.id |
||
703 | and securitygroups.deleted = 0 |
||
704 | 1 | where securitygroups_users.user_id='".$current_user->id."' and securitygroups_users.deleted = 0 |
|
705 | 1 | order by securitygroups_users.primary_group desc "; |
|
706 | 1 | if($db->dbType == 'mysql') { |
|
707 | 1 | $query .= " limit 0,1 "; |
|
708 | } |
||
709 | |||
710 | 1 | $result = $db->query($query,true,"Error finding the current users primary group: "); |
|
711 | 1 | if(($row=$db->fetchByAssoc($result)) != null) { |
|
712 | $primary_group_id = $row['id']; |
||
713 | } |
||
714 | |||
715 | 1 | return $primary_group_id; |
|
716 | } |
||
717 | } |
||
718 | ?> |
This function has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.