ultimix
permit_buttons.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 
27 
38  var $Permits = array();
39 
50  var $CachedMultyFS = false;
51  var $Database = false;
52  var $PermitAccess = false;
53  var $PermitAlgorithms = false;
54  var $Settings = false;
55  var $String = false;
56  var $UserAlgorithms = false;
57 
68  var $ControllerWasAdded = false;
69 
80  function __construct()
81  {
82  try
83  {
84  $this->CachedMultyFS = get_package( 'cached_multy_fs' , 'last' , __FILE__ );
85  $this->Database = get_package( 'database' , 'last' , __FILE__ );
86  $this->PermitAccess = get_package( 'permit::permit_access' , 'last' , __FILE__ );
87  $this->PermitAlgorithms = get_package( 'permit::permit_algorithms' , 'last' , __FILE__ );
88  $this->Settings = get_package_object( 'settings::settings' , 'last' , __FILE__ );
89  $this->String = get_package( 'string' , 'last' , __FILE__ );
90  $this->UserAlgorithms = get_package( 'user::user_algorithms' , 'last' , __FILE__ );
91  }
92  catch( Exception $e )
93  {
94  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
95  }
96  }
97 
116  function get_controller()
117  {
118  try
119  {
120  $Code = '';
121 
122  if( $this->ControllerWasAdded === false )
123  {
124  $Code = '{direct_controller:set_permit=1;delete_permit=1;toggle_permit=1'.
125  'package_name=permit::permit_controller}';
126 
127  $this->ControllerWasAdded = true;
128  }
129 
130  return( $Code );
131  }
132  catch( Exception $e )
133  {
134  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
135  }
136  }
137 
152  private function load_permits()
153  {
154  try
155  {
156  $UserId = $this->UserAlgorithms->get_id();
157 
158  if( isset( $this->Permits[ $UserId ] ) === false )
159  {
160  $this->Permits[ $UserId ] = $this->PermitAlgorithms->get_permits_for_object( $UserId , 'user' );
161  }
162  }
163  catch( Exception $e )
164  {
165  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
166  }
167  }
168 
195  private function compile_permit_button( &$Settings , $Type )
196  {
197  try
198  {
199  $this->load_permits();
200 
201  list( $Text , $Group , $MasterId ) = $Settings->get_settings( 'text,group,master_id' );
202  $MasterType = $Settings->get_setting( 'master_type' , 'user' );
203  $CheckBoxes = $Settings->get_setting( 'checkboxes' , 'user' );
204 
205  $Code = $this->get_controller();
206  $Code .= "{href:text=$Text;page=javascript:ultimix.permit.".$Type."PermitButton".
207  "( '$Permit' , $MasterId , '$MasterType' , '$CheckBoxes' )}";
208 
209  return( $Code );
210  }
211  catch( Exception $e )
212  {
213  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
214  }
215  }
216 
240  {
241  try
242  {
243  return( $this->compile_permit_button( $Settings , 'Set' ) );
244  }
245  catch( Exception $e )
246  {
247  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
248  }
249  }
250 
274  {
275  try
276  {
277  return( $this->compile_permit_button( $Settings , 'Delete' ) );
278  }
279  catch( Exception $e )
280  {
281  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
282  }
283  }
284 
308  {
309  try
310  {
311  return( $this->compile_permit_button( $Settings , 'Toggle' ) );
312  }
313  catch( Exception $e )
314  {
315  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
316  }
317  }
318  }
319 
320 ?>