ultimix

- Main Page
- Data Structures
- Files
- Examples

- File List
- Globals

permit_algorithms.php
Go to the documentation of this file.
1 <?php
2
3 /*
4 * This source code is a part of the Ultimix Project.
5 * It is distributed under BSD license. All other third side source code (like tinyMCE) is distributed under
6 * it's own license wich could be found from the corresponding files or sources.
7 * This source code is provided "as is" without any warranties or garanties.
8 *
9 * Have a nice day!
10 *
11 * @url http://ultimix.sorceforge.net
12 *
13 * @author Alexey "gdever" Dodonov
14 */
15
26 class permit_algorithms_1_0_0{
27
38 var $Database = false;
39 var $Link = false;
40 var $PermitAccess = false;
41 var $Security = false;
42 var $String = false;
43 var $UserAlgorithms = false;
44
59 function __construct()
60 {
61 try
62 {
63 $this->Database = get_package( 'database' , 'last' , __FILE__ );
64 $this->Link = get_package( 'link' , 'last' , __FILE__ );
65 $this->PermitAccess = get_package( 'permit::permit_access' , 'last' , __FILE__ );
66 $this->Security = get_package( 'security' , 'last' , __FILE__ );
67 $this->UserAlgorithms = get_package( 'user::user_algorithms' , 'last' , __FILE__ );
68 }
69 catch( Exception $e )
70 {
71 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
72 }
73 }
74
106 private function get_permits_for_user( $Object , $AddGroupPermits = true )
107 {
108 try
109 {
110 $SessionId = $this->UserAlgorithms->get_id();
111 $Object = ( $Object === false ) ? $SessionId : $this->Security->get( $Object , 'integer' );
112 $Permits = $this->PermitAccess->get_permits_for_object( $Object , 'user' , array( 'public' ) );
113
114 if( $AddGroupPermits )
115 {
116 $Permits = array_merge(
117 $Permits , $this->PermitAccess->get_permits_for_user_group( $Object )
118 );
119 }
120
121 return( $Permits );
122 }
123 catch( Exception $e )
124 {
125 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
126 }
127 }
128
164 function fetch_permits_for_object( $Object , $ObjectType = 'page' , $AddGroupPermits = true )
165 {
166 try
167 {
168 switch( $ObjectType )
169 {
170 case( 'group' ):
171 $Permits = $this->PermitAccess->get_permits_for_object( $Object , 'group' , array() );
172 break;
173 case( 'menu' ):
174 $Permits = $this->PermitAccess->get_permits_for_object( $Object , 'menu' , array( 'admin' ) );
175 break;
176 case( 'page' ):$Permits = $this->PermitAccess->get_permits_for_page( $Object );break;
177 case( 'user' ):$Permits = $this->get_permits_for_user( $Object , $AddGroupPermits );break;
178 }
179
180 return( $Permits );
181 }
182 catch( Exception $e )
183 {
184 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
185 }
186 }
187
223 function get_permits_for_object( $Object , $ObjectType = 'page' , $AddGroupPermits = true )
224 {
225 try
226 {
227 $Key = md5( $Object.$ObjectType.$AddGroupPermits );
228
229 if( isset( $this->PermitAccess->PermitsCache[ $Key ] ) )
230 {
231 return( $this->PermitAccess->PermitsCache[ $Key ] );
232 }
233
234 $Permits = $this->fetch_permits_for_object( $Object , $ObjectType , $AddGroupPermits );
235
236 $this->PermitAccess->PermitsCache[ $Key ] = $Permits;
237
238 return( $this->PermitAccess->PermitsCache[ $Key ] );
239 }
240 catch( Exception $e )
241 {
242 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
243 }
244 }
245
276 function object_has_permit( $Object , $ObjectType , $Permit )
277 {
278 try
279 {
280 if( $Object === false && $ObjectType == 'user' )
281 {
282 $Object = $this->UserAlgorithms->get_id();
283 }
284
285 $ObjectsPermits = $this->get_permits_for_object( $Object , $ObjectType );
286
287 return( in_array( $Permit , $ObjectsPermits ) );
288 }
289 catch( Exception $e )
290 {
291 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
292 }
293 }
294
325 function object_has_all_permits( $Object , $ObjectType , $Permits )
326 {
327 try
328 {
329 $ObjectsPermits = $this->get_permits_for_object( $Object , $ObjectType );
330
331 if( is_array( $Permits ) === false )
332 {
333 $Permits = explode( "," , $Permits );
334 }
335
336 if( count( $Permits ) === count( array_intersect( $ObjectsPermits , $Permits ) ) )
337 {
338 return( true );
339 }
340 else
341 {
342 return( false );
343 }
344 }
345 catch( Exception $e )
346 {
347 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
348 }
349 }
350
385 function validate_permits_ex( $Object1 , $ObjectType1 , $Object2 , $ObjectType2 )
386 {
387 try
388 {
389 $Permits1 = $this->get_permits_for_object( $Object1 , $ObjectType1 );
390
391 $Permits2 = $this->get_permits_for_object( $Object2 , $ObjectType2 );
392
393 if( count( $Permits2 ) === count( array_intersect( $Permits1 , $Permits2 ) ) )
394 {
395 return( true );
396 }
397 else
398 {
399 return( false );
400 }
401 }
402 catch( Exception $e )
403 {
404 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
405 }
406 }
407
430 function get_users_for_permit( $PermitName )
431 {
432 try
433 {
434 $PermitName = $this->Security->get( $PermitName , 'command' );
435
436 $PermitObject = $this->PermitAccess->get_permit_by_name( $PermitName );
437
438 $Links1 = $this->Link->get_links( false , get_field( $PermitObject , 'id' ) , 'user' , 'permit' );
439 $Links2 = $this->Link->get_links( false , get_field( $PermitObject , 'id' ) , 'group' , 'permit' );
440 $Links3 = $this->Link->get_links( false , get_field_ex( $Links2 , 'object1_id' ) , 'user' , 'group' );
441
442 $Users = array_merge( get_field_ex( $Links1 , 'object1_id' ) , get_field_ex( $Links3 , 'object1_id' ) );
443 $Users = array_unique( $Users );
444
445 return( $Users );
446 }
447 catch( Exception $e )
448 {
449 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
450 }
451 }
452 }
453 ?>