[go: up one dir, main page]

Menu

[r3]: / trunk / lib / lib.acl.php  Maximize  Restore  History

Download this file

342 lines (289 with data), 10.3 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
<?php defined("IN_DOCEBO") or die('Direct access is forbidden.');
/* ======================================================================== \
| DOCEBO - The E-Learning Suite |
| |
| Copyright (c) 2008 (Docebo) |
| http://www.docebo.com |
| License http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt |
\ ======================================================================== */
require_once( Docebo::inc(_base_ .'/lib/lib.aclmanager.php') );
/**
* Acl common tasks class
* This class is only for check permissions
* To manage ACLs we must use DoceboACLManager
*
* NOTE: ST means Security Token
*
* @package admin-core
* @subpackage user
* @category ACL
* @author Emanuele Sandri <esandri @ tiscali . it>
* @version $Id: lib.acl.php 852 2006-12-16 14:04:44Z giovanni $
*/
class DoceboACL {
/** Instance of DoceboACLManager */
var $aclManager = NULL;
/**
* constructor
* @param mixed $dbconn the connection to database or FALSE to use default connection
* @param mixed $prefix the prefix of the database or FLASE to use default prefix
*/
function DoceboACL( $dbconn = FALSE, $prefix = FALSE ) {
$this->aclManager = new DoceboACLManager($dbconn, $prefix );
}
function &getACLManager() {
return $this->aclManager;
}
/* NOTE: functions for retrieve single security token */
/**
* get security token of an user
* @param string $userid id of the user
* @return mixed security token associated to user or FALSE
**/
function getUserST( $userid ) {
$arr = $this->aclManager->getUser( FALSE, $userid );
if( $arr === FALSE )
return FALSE;
return $arr[ACL_INFO_IDST];
}
/**
* get security token of a group
* @param string $groupid id of the group
* @return mixed security token associated to groups or FALSE
**/
function getGroupST( $groupid ) {
$arr = $this->aclManager->getGroup( FALSE, $groupid );
if( $arr === FALSE )
return FALSE;
return $arr[ACL_INFO_IDST];
}
/**
* get security token of a role
* @param string $roleid id of the role
* @return mixed security token associated to role or FALSE
**/
function getRoleST( $roleid ) {
$arr = $this->aclManager->getRole( FALSE, $roleid );
if( $arr === FALSE )
return FALSE;
return $arr[ACL_INFO_IDST];
}
/* NOTE: functions for retrieve all security token */
/**
* get all security token of a user
* @param string $userid id of the user
* @param string $filter (Optional). Filter to applay.
* @return mixed array of security tokens associated to the user or FALSE
**/
function getUserAllST( $userid, $filter = '', $user_idst=FALSE ) {
if($user_idst == FALSE) $user_idst = $this->getUserST( $userid );
$arrST = array($user_idst);
$arrRoles = array();
$new_st = array($user_idst);
$loop_check = 0;
do {
$loop_check++;
$new_st = $this->aclManager->getGroupsAllContainer( $new_st, $filter );
if(!empty($new_st)) $arrST = array_merge( $arrST, array_diff($new_st, $arrST ));
} while(!empty($new_st) && ($loop_check < 50));
$new_st = $arrST;
$loop_check = 0;
do {
$loop_check++;
$new_st = $this->aclManager->getRolesAllContainer( $new_st );
if(!empty($new_st)) $arrRoles = array_merge( $arrRoles, array_diff($new_st, $arrRoles ));
} while(!empty($new_st) && ($loop_check < 50));
$arrST = array_merge( $arrST, $arrRoles);
return $arrST;
}
/**
* get all security token of a group
* @param string $groupid id of the group
* @param string $filter (Optional). Filter to applay.
* @return mixed array of security tokens associated to the group or FALSE
**/
function getGroupAllST( $groupid, $filter = '' ) {
$group_idst = $this->getGroupST( $groupid );
$arrST = array($group_idst);
$arrRoles = array();
$new_st = array($group_idst);
$loop_check = 0;
do {
$loop_check++;
$new_st = $this->aclManager->getGroupsAllContainer( $new_st, $filter );
if(!empty($new_st)) $arrST = array_merge( $arrST, array_diff($new_st, $arrST ));
} while(!empty($new_st) && ($loop_check < 50));
$new_st = $arrST;
$loop_check = 0;
do {
$loop_check++;
$new_st = $this->aclManager->getRolesAllContainer( $new_st );
if(!empty($new_st)) $arrRoles = array_merge( $arrRoles, array_diff($new_st, $arrRoles ));
} while(!empty($new_st) && ($loop_check < 50));
$arrST = array_merge( $arrST, $arrRoles);
return $arrST;
}
/* NOTE: functions for retrieve groups */
/**
* get all groups of a idst
* @param int $idst idst
* @param string $filter (Optional). Filter to applay.
* @return mixed array of groups of the user or FALSE
**/
function getSTGroupsST( $idst, $filter = '') {
/*$arrST = $this->aclManager->getGroupsContainer( $idst, $filter );
// search in groups
$count = 0;
while( $count < count( $arrST ) ) {
$idST = $arrST[$count];
$arrResult = $this->aclManager->getGroupsContainer( $idST, $filter );
$arrST = array_merge( $arrST, array_diff($arrResult, $arrST ));
$count++;
}*/
$arrST = array($idst);
$arrRoles = array();
$new_st = array($idst);
$loop_check = 0;
do {
$loop_check++;
$new_st = $this->aclManager->getGroupsAllContainer( $new_st, $filter );
if(!empty($new_st)) $arrST = array_merge( $arrST, array_diff($new_st, $arrST ));
} while(!empty($new_st) && ($loop_check < 50));
return $arrST;
}
/**
* get all groups of an array of idst
* @param int $arr_idst idst
* @param string $filter (Optional). Filter to applay.
* @return mixed array of groups of the user or FALSE
**/
function getArrSTGroupsST( $arr_idst, $filter = '' ) {
$arrST = array_values($arr_idst);
$arrRoles = array();
$new_st = array_values($arr_idst);
$loop_check = 0;
do {
$loop_check++;
$new_st = $this->aclManager->getGroupsAllContainer( $new_st, $filter );
if(!empty($new_st)) $arrST = array_merge( $arrST, array_diff($new_st, $arrST ));
} while(!empty($new_st) && ($loop_check < 50));
return $arrST;
}
/**
* get all groups of a idst_user
* @param int $idst_user idst
* @param string $filter (Optional). Filter to applay.
* @return mixed array of groups of the user or FALSE
**/
function getUserGroupsST( $idst_user, $filter = '' ) {
return $this->getSTGroupsST( $idst_user, $filter );
}
/**
* get all groups of a idst_group
* @param int $idst_group idst
* @param string $filter (Optional). Filter to applay.
* @return mixed array of groups of the user or FALSE
**/
function getGroupGroupsST( $idst_group, $filter = '' ) {
return $this->getSTGroupsST( $idst_group, $filter );
}
/**
* get all groups of a group
* @param int $idst idst of the group
* @return mixed array of groups of the group or FALSE
**/
function getGroupGDescendants( $idst ) {
return $this->aclManager->getGroupGDescendants( $idst );
}
/**
* get all descendant users of a group
* @param int $idst idst of the group
* @return mixed array of users of the group or FALSE
**/
function getGroupUDescendants( $idst ) {
return $this->aclManager->getGroupUDescendants( $idst );
}
/* NOTE: functions for retrieve roles */
/**
* get all roles of a user
* @param string $userid id of the user
* @return mixed array of roles of the user or FALSE
**/
function getUserRoles( $userid ) {
}
/**
* get all roles of a group
* @param string $groupid id of the group
* @return mixed array of roles of the group or FALSE
**/
function getGroupRoles( $groupid ) {
}
/* NOTE: functions to test match with single security token */
function _searchMatch( $idst, $idstMatch ) {
if( in_array($idst,$idstMatch ) )
return TRUE;
$arrST = array($idst);
$arrRoles = array();
$new_st = array($idst);
$loop_check = 0;
do {
$loop_check++;
$new_st = $this->aclManager->getGroupsAllContainer( $new_st, '' );
if( count(array_intersect($idstMatch, $new_st)) > 0 )
return TRUE;
if(!empty($new_st)) $arrST = array_merge( $arrST, array_diff($new_st, $arrST ));
} while(!empty($new_st) && ($loop_check < 50));
$new_st = $arrST;
$loop_check = 0;
do {
$loop_check++;
$new_st = $this->aclManager->getRolesAllContainer( $new_st );
if( count(array_intersect($idstMatch, $new_st)) > 0 )
return TRUE;
if(!empty($new_st)) $arrRoles = array_merge( $arrRoles, array_diff($new_st, $arrRoles ));
} while(!empty($new_st) && ($loop_check < 50));
return false;
}
/**
* match a user with a security token
* @param string $userid id of the user
* @param int $st security token to match
* @return bool TRUE if match, FALSE otherwise
**/
function matchUserST( $userid, $st ) {
$idst = $this->getUserST( $userid );
return $this->_searchMatch( $idst, array($st) );
}
/**
* match a group with a security token
* @param string $groupid id of the group
* @param int $st security token to match
* @return bool TRUE if match, FALSE otherwise
**/
function matchGroupST( $groupid, $st ) {
$idst = $this->getGroupST( $groupid );
return $this->_searchMatch( $idst, array($st) );
}
/* NOTE: functions to test match with multiple security token */
/**
* match a user with an array of security token
* @param string $userid id of the user
* @param array $st array of security token to match
* @return bool TRUE if match, FALSE otherwise
**/
function matchUserSTArray( $userid, $st ) {
$idst = $this->getUserST( $userid );
return $this->_searchMatch( $idst, $st );
}
/**
* match a group with an array of security token
* @param string $groupid id of the group
* @param int $st array of security token to match
* @return bool TRUE if match, FALSE otherwise
**/
function matchGroupSTArray( $groupid, $st ) {
$idst = $this->getGroupST( $groupid );
return $this->_searchMatch( $idst, $st );
}
}
?>