ultimix

- Main Page
- Data Structures
- Files
- Examples

- File List
- Globals

group_access.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 group_access_1_0_0{
27
38 var $NativeTable = '`umx_group`';
39
50 var $Database = false;
51 var $DatabaseAlgorithms = false;
52 var $Link = false;
53 var $LinkDictionary = false;
54 var $Security = false;
55 var $SecurityParser = false;
56 var $UserAccess = false;
57
68 function __construct()
69 {
70 try
71 {
72 $this->Database = get_package( 'database' , 'last' , __FILE__ );
73 $this->DatabaseAlgorithms = get_package( 'database::database_algorithms' , 'last' , __FILE__ );
74 $this->Link = get_package( 'link' , 'last' , __FILE__ );
75 $this->LinkDictionary = get_package( 'link::link_dictionary' , 'last' , __FILE__ );
76 $this->Security = get_package( 'security' , 'last' , __FILE__ );
77 $this->SecurityParser = get_package( 'security::security_parser' , 'last' , __FILE__ );
78 $this->UserAccess = get_package( 'user::user_access' , 'last' , __FILE__ );
79 }
80 catch( Exception $e )
81 {
82 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
83 }
84 }
85
96 var $AddLimitations = '1 = 1';
97
116 function set_add_limitations( $theAddLimitation )
117 {
118 try
119 {
120 if( $this->AddLimitations === '1 = 1' )
121 {
122 $this->AddLimitations = $theAddLimitation;
123 }
124 else
125 {
126 throw( new Exception( '"AddLimitations" was already set' ) );
127 }
128 }
129 catch( Exception $e )
130 {
131 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
132 }
133 }
134
157 function unsafe_select( $Condition )
158 {
159 try
160 {
161 $this->Database->query_as( DB_OBJECT );
162
163 $Records = $this->Database->select(
164 '*' , $this->NativeTable , "( $this->AddLimitations ) AND $Condition"
165 );
166
167 foreach( $Records as $k => $v )
168 {
169 $Records[ $k ]->title = htmlspecialchars_decode( $Records[ $k ]->title , ENT_QUOTES );
170 $Records[ $k ]->comment = htmlspecialchars_decode( $Records[ $k ]->comment , ENT_QUOTES );
171 }
172
173 return( $Records );
174 }
175 catch( Exception $e )
176 {
177 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
178 }
179 }
180
203 function get_group_by_name( $Group )
204 {
205 try
206 {
207 $Group = $this->Security->get( $Group , 'command' );
208
209 $Items = $this->unsafe_select( "( $this->AddLimitations ) AND title LIKE '$Group'" );
210
211 if( isset( $Items[ 0 ] ) === false )
212 {
213 throw( new Exception( "Group \"$Group\" was not found" ) );
214 }
215
216 return( $Items[ 0 ] );
217 }
218 catch( Exception $e )
219 {
220 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
221 }
222 }
223
246 function get_group_by_id( $id )
247 {
248 try
249 {
250 $id = $this->Security->get( $id , 'integer' );
251
252 $Items = $this->unsafe_select( "id = $id" );
253
254 if( count( $Items ) == 0 )
255 {
256 throw( new Exception( "Group $id was not found" ) );
257 }
258
259 return( $Items[ 0 ] );
260 }
261 catch( Exception $e )
262 {
263 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
264 }
265 }
266
305 function select( $Start = false , $Limit = false , $Field = false ,
306 $Order = false , $Condition = '1 = 1' )
307 {
308 try
309 {
310 $Condition = $this->DatabaseAlgorithms->select_condition(
311 $Start , $Limit , $Field , $Order , $Condition , $this->NativeTable
312 );
313
314 return( $this->unsafe_select( $Condition ) );
315 }
316 catch( Exception $e )
317 {
318 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
319 }
320 }
321
340 function create( $Record )
341 {
342 try
343 {
344 $Record = $this->SecurityParser->parse_parameters( $Record , 'title:command;comment:string' );
345
346 list( $Fields , $Values ) = $this->DatabaseAlgorithms->compile_fields_values( $Record );
347
348 $id = $this->DatabaseAlgorithms->create( $this->NativeTable , $Fields , $Values );
349
350 return( $id );
351 }
352 catch( Exception $e )
353 {
354 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
355 }
356 }
357
376 function delete( $id )
377 {
378 try
379 {
380 $id = $this->Security->get( $id , 'integer_list' );
381
384 $Database = get_package( 'database' , 'last' , __FILE__ );
385 $this->Database->delete( $this->NativeTable , "( $this->AddLimitations ) AND id IN ( $id )" );
386 $this->Database->commit();
387 }
388 catch( Exception $e )
389 {
390 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
391 }
392 }
393
416 function select_list( $id )
417 {
418 try
419 {
420 $id = $this->Security->get( $id , 'integer_list' );
421
422 return( $this->unsafe_select( $this->NativeTable.".id IN ( $id )" ) );
423 }
424 catch( Exception $e )
425 {
426 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
427 }
428 }
429
452 function update( $id , $Record )
453 {
454 try
455 {
456 $id = $this->Security->get( $id , 'integer_list' );
457 $Record = $this->SecurityParser->parse_parameters(
458 $Record , 'title:command;comment:string' , 'allow_not_set'
459 );
460
461 list( $Fields , $Values ) = $this->DatabaseAlgorithms->compile_fields_values( $Record );
462
463 if( isset( $Fields[ 0 ] ) )
464 {
465 $this->Database->update(
466 $this->NativeTable , $Fields , $Values , "( $this->AddLimitations ) AND id IN ( $id )"
467 );
468 $this->Database->commit();
469 }
470 }
471 catch( Exception $e )
472 {
473 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
474 }
475 }
476
507 function get_groups_for_object( $Object , $ObjectType = 'user' )
508 {
509 try
510 {
511 $Object = $this->Security->get( $Object , 'integer' );
512 $LinkType = $this->LinkDictionary->get_link_type( $ObjectType , 'group' );
513
514 $Items = $this->Database->select(
515 'title' , $this->NativeTable.' , umx_link' ,
516 "( $this->AddLimitations ) AND ".$this->NativeTable.
517 ".id = umx_link.object2_id AND umx_link.object1_id = $Object AND type = $LinkType"
518 );
519
520 $Content = array();
521 if( count( $Items ) > 0 )
522 {
523 foreach( $Items as $i )
524 {
525 $Content [] = $i->title;
526 }
527
528 $Content = array_unique( $Content );
529 }
530
531 return( $Content );
532 }
533 catch( Exception $e )
534 {
535 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
536 }
537 }
538
565 function add_group_for_object( $Group , $Object , $ObjectType = 'user' )
566 {
567 try
568 {
569 $Group = $this->Security->get( $Group , 'command' );
570 $Object = $this->Security->get( $Object , 'string' );
571 $ObjectType = $this->Security->get( $ObjectType , 'command' );
572
573 $Group = $this->unsafe_select( "( $this->AddLimitations ) AND title LIKE '$Group'" );
574 if( isset( $Group[ 0 ] ) )
575 {
576 $Group = $Group[ 0 ];
577 $this->Link->create_link( $Object , get_field( $Group , 'id' ) , $ObjectType , 'group' , true );
578 }
579 else
580 {
581 throw( new Exception( "Group \"$Group\" was not found" ) );
582 }
583 }
584 catch( Exception $e )
585 {
586 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
587 }
588 }
589
616 function delete_group_for_object( $Group , $Object , $ObjectType = 'user' )
617 {
618 try
619 {
620 $Object = $this->Security->get( $Object , 'string' );
621 $ObjectType = $this->Security->get( $ObjectType , 'command' );
622
623 if( $Group === false )
624 {
625 $this->Link->delete_link( $Object , false , $ObjectType , 'group' , true );
626 }
627 else
628 {
629 $Group = $this->Security->get( $Group , 'command' );
630 $Group = $this->unsafe_select( "( $this->AddLimitations ) AND title LIKE '$Group'" );
631 if( isset( $Group[ 0 ] ) )
632 {
633 $this->Link->delete_link(
634 $Object , get_field( $Group[ 0 ] , 'id' ) , $ObjectType , 'group' , true
635 );
636 }
637 }
638 }
639 catch( Exception $e )
640 {
641 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
642 }
643 }
644
671 function toggle_group_for_object( $Group , $Object , $ObjectType = 'page' )
672 {
673 try
674 {
675 $this->PermitsCache = array();
676
677 $Group = $this->get_group_by_name( $Group );
678
679 $Object = $this->Security->get( $Object , 'string' );
680 $ObjectType = $this->Security->get( $ObjectType , 'command' );
681
682 if( $this->Link->link_exists( $Object , get_field( $Group , 'id' ) , $ObjectType , 'group' ) )
683 {
684 $this->Link->delete_link( $Object , get_field( $Group , 'id' ) , $ObjectType , 'group' );
685 }
686 else
687 {
688 $this->Link->create_link( $Object , get_field( $Group , 'id' ) , $ObjectType , 'group' , true );
689 }
690 }
691 catch( Exception $e )
692 {
693 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
694 }
695 }
696
723 function set_group_for_object( $Group , $Object , $ObjectType = 'page' )
724 {
725 try
726 {
727 /* dropping local cache */
728 $this->PermitsCache = array();
729
730 $Group = $this->Security->get( $Group , 'command' );
731 $Group = $this->GroupAccess->unsafe_select( "title LIKE '$Group'" );
732 if( isset( $Group[ 0 ] ) === false )
733 {
734 throw( new Exception( "Group \"$Group\" was not found" ) );
735 }
736
737 $Group = $Group[ 0 ];
738 $Object = $this->Security->get( $Object , 'string' );
739 $ObjectType = $this->Security->get( $ObjectType , 'command' );
740
741 $this->Link->create_link( $Object , get_field( $Group , 'id' ) , $ObjectType , 'group' , true );
742 }
743 catch( Exception $e )
744 {
745 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
746 }
747 }
748 }
749
750 ?>