ultimix

- Main Page
- Data Structures
- Files
- Examples

- File List
- Globals

permit_markup.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_markup_1_0_0{
27
38 var $Permits = array();
39
50 var $CachedMultyFS = false;
51 var $PermitAccess = false;
52 var $PermitAlgorithms = false;
53 var $UserAlgorithms = false;
54
65 var $ControllerWasAdded = false;
66
85 private function load_permits_for_user( $UserId = false )
86 {
87 try
88 {
89 if( $UserId === false )
90 {
91 $UserId = $this->UserAlgorithms->get_id();
92 }
93
94 if( isset( $this->Permits[ $UserId ] ) === false )
95 {
96 $this->Permits[ $UserId ] = $this->PermitAlgorithms->get_permits_for_object( $UserId , 'user' );
97 }
98 }
99 catch( Exception $e )
100 {
101 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
102 }
103 }
104
115 function __construct()
116 {
117 try
118 {
119 $this->CachedMultyFS = get_package( 'cached_multy_fs' , 'last' , __FILE__ );
120 $this->Database = get_package( 'database' , 'last' , __FILE__ );
121 $this->PermitAlgorithms = get_package( 'permit::permit_algorithms' , 'last' , __FILE__ );
122 $this->UserAlgorithms = get_package( 'user::user_algorithms' , 'last' , __FILE__ );
123 }
124 catch( Exception $e )
125 {
126 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
127 }
128 }
129
152 private function has_premits( &$Settings )
153 {
154 try
155 {
156 $RawSettings = $Settings->get_raw_settings();
157 $Parmit = array_shift( array_keys( $RawSettings ) );
158
159 $UserId = $this->UserAlgorithms->get_id();
160 $this->load_permits_for_user( $UserId );
161
162 return( in_array( $Parmit , $this->Permits[ $UserId ] ) );
163 }
164 catch( Exception $e )
165 {
166 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
167 }
168 }
169
196 function compile_permit( &$Settings , $Data )
197 {
198 try
199 {
200 $Flag = $this->has_premits( $Settings , $Data );
201
202 if( $Flag )
203 {
204 return( $Data );
205 }
206 else
207 {
208 return( '' );
209 }
210 }
211 catch( Exception $e )
212 {
213 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
214 }
215 }
216
243 function compile_no_permit( &$Settings , $Data )
244 {
245 try
246 {
247 $Flag = $this->has_premits( $Settings , $Data );
248
249 if( $Flag )
250 {
251 return( '' );
252 }
253 else
254 {
255 return( $Data );
256 }
257 }
258 catch( Exception $e )
259 {
260 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
261 }
262 }
263
286 function compile_permit_list( &$Settings )
287 {
288 try
289 {
290 $this->Database->query_as( DB_OBJECT );
291 $Items = $this->Database->select( 'permit' , 'umx_permit' , '1 = 1' );
292 $c = count( $Items );
293 $AllPermits = '';
294 foreach( $Items as $k => $i )
295 {
296 $AllPermits .= $i->permit;
297 if( $k + 1 != $c )
298 {
299 $AllPermits .= ', ';
300 }
301 }
302
303 return( $AllPermits );
304 }
305 catch( Exception $e )
306 {
307 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
308 }
309 }
310
333 function compile_permit_list_for_object( &$Settings )
334 {
335 try
336 {
337 $PermitList = '';
338
339 list( $Object , $Type ) = $Settings->get_settings( 'object,type' , 'public,' );
340 $PermitList = $this->PermitAlgorithms->get_permits_for_object( $Object , $Type , false );
341
342 sort( $PermitList );
343 $PermitList = implode( ', ' , $PermitList );
344
345 return( $PermitList );
346 }
347 catch( Exception $e )
348 {
349 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
350 }
351 }
352
379 private function compile_object_permits( $ObjectPermitList , $PermitListWidget )
380 {
381 try
382 {
383 sort( $ObjectPermitList );
384
385 foreach( $ObjectPermitList as $key => $p )
386 {
387 $Template = $this->CachedMultyFS->get_template( __FILE__ , 'delete_permit_item.tpl' );
388 $Template = str_replace( '{permit}' , $p , $Template );
389 $PermitListWidget = str_replace( '{object_permits}' , $Template , $PermitListWidget );
390 }
391
392 $PermitListWidget = str_replace( '{object_permits}' , '' , $PermitListWidget );
393
394 return( $PermitListWidget );
395 }
396 catch( Exception $e )
397 {
398 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
399 }
400 }
401
428 private function compile_all_permits( $AllPermitList , $ObjectPermitList , $PermitListWidget )
429 {
430 try
431 {
432 sort( $AllPermitList );
433
434 foreach( $AllPermitList as $key => $p )
435 {
436 if( in_array( $p , $ObjectPermitList ) === false )
437 {
438 $Template = $this->CachedMultyFS->get_template( __FILE__ , 'add_permit_item.tpl' );
439 $Template = str_replace( '{permit}' , $p , $Template );
440 $PermitListWidget = str_replace( '{rest_permits}' , $Template , $PermitListWidget );
441 }
442 }
443
444 return( $PermitListWidget );
445 }
446 catch( Exception $e )
447 {
448 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
449 }
450 }
451
474 private function get_permits( &$Settings )
475 {
476 try
477 {
478 $AllPermitList = $Settings->get_setting( 'all' , 'public' );
479 if( strlen( $AllPermitList ) == 0 )
480 {
481 $AllPermitList = array();
482 }
483 else
484 {
485 $AllPermitList = explode( ', ' , $AllPermitList );
486 }
487
488 $ObjectPermitList = $Settings->get_setting( 'object_permits' , '' );
489 $ObjectPermitList = strlen( $ObjectPermitList ) == 0 ? array() :
490 explode( ', ' , $ObjectPermitList );
491
492 return( array( $ObjectPermitList , $AllPermitList ) );
493 }
494 catch( Exception $e )
495 {
496 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
497 }
498 }
499
522 function compile_permit_list_widget( &$Settings )
523 {
524 try
525 {
526 list( $ObjectPermitList , $AllPermitList ) = $this->get_permits( $Settings );
527
528 $PermitListWidget = $this->CachedMultyFS->get_template( __FILE__ , 'permit_list.tpl' );
529 $Object = $Settings->get_setting( 'object' );
530 $PermitListWidget = str_replace( '{object}' , $Object , $PermitListWidget );
531
532 $PermitListWidget = $this->compile_object_permits( $ObjectPermitList , $PermitListWidget );
533
534 return( $this->compile_all_permits( $AllPermitList , $ObjectPermitList , $PermitListWidget ) );
535 }
536 catch( Exception $e )
537 {
538 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
539 }
540 }
541
564 function compile_permit_select( &$Settings )
565 {
566 try
567 {
568
569 list( $Name , $Class ) = $Settings->get_settings( 'name,class', 'permit,flat width_160' );
570
571 $Code = "{select:name=$Name;class=$Class;".
572 "query=SELECT id , title AS value FROM `umx_permit` ORDER BY title}";
573
574 return( $Code );
575 }
576 catch( Exception $e )
577 {
578 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
579 }
580 }
581 }
582
583 ?>