ultimix
checkbox_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 
27  {
28 
39  var $CachedMultyFS = false;
40  var $Database = false;
41  var $Security = false;
42  var $String = false;
43 
54  function __construct()
55  {
56  try
57  {
58  $this->CachedMultyFS = get_package( 'cached_multy_fs' , 'last' , __FILE__ );
59  $this->Database = get_package( 'database' , 'last' , __FILE__ );
60  $this->Security = get_package( 'security' , 'last' , __FILE__ );
61  $this->String = get_package( 'string' , 'last' , __FILE__ );
62  }
63  catch( Exception $e )
64  {
65  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
66  }
67  }
68 
91  function compile_header_checkbox( &$Settings )
92  {
93  try
94  {
95  $Name = $Settings->get_setting( 'name' );
96 
97  $Code = '{checkbox_ex:self_class=_'.$Name.'_header_checkbox;children_selector=._'.
98  $Name."_item_checkbox;name=$Name}";
99 
100  return( $Code );
101  }
102  catch( Exception $e )
103  {
104  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
105  }
106  }
107 
130  function compile_item_checkbox( &$Settings )
131  {
132  try
133  {
134  $Name = $Settings->get_setting( 'name' );
135  $Id = $Settings->get_setting( 'id' );
136 
137  $Code = '{checkbox_ex:self_class=_'.$Name.'_item_checkbox;parent_selector=._'.$Name.
138  "_header_checkbox;id=_id_$Id;name=_id_$Id}";
139 
140  return( $Code );
141  }
142  catch( Exception $e )
143  {
144  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
145  }
146  }
147 
178  private function compile_checkboxes( $Cols , $Value , $Records )
179  {
180  try
181  {
182  $Counter = 0;
183  $Code = '';
184  foreach( $Records as $r )
185  {
186  if( $Counter == $Cols )
187  {
188  $Counter = 0;
189  $Code .= $this->CachedMultyFS->get_template( __FILE__ , 'checkbox_set_line_end.tpl' );
190  }
191 
192  $Value = $this->Security->get_gp( '_id_'.$r->id , 'command' , $Value );
193  $Code .= $this->CachedMultyFS->get_template( __FILE__ , 'checkbox_set_item.tpl' );
194  $PlaceHolders = array( '{id}' , '{value}' , '{title}' );
195  $Data = array( $r->id , $Value , $r->title );
196  $Code = str_replace( $PlaceHolders , array( $r->id , $Value , $r->title ) , $Code );
197 
198  $Counter++;
199  }
200  return( $Code );
201  }
202  catch( Exception $e )
203  {
204  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
205  }
206  }
207 
238  private function compile_records( $Cols , $Value , $Records )
239  {
240  try
241  {
242  $Code = $this->CachedMultyFS->get_template( __FILE__ , 'checkbox_set_start.tpl' );
243 
244  $Code .= $this->compile_checkboxes( $Cols , $Value , $Records );
245 
246  return( $Code .= $this->CachedMultyFS->get_template( __FILE__ , 'checkbox_set_end.tpl' ) );
247  }
248  catch( Exception $e )
249  {
250  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
251  }
252  }
253 
276  function compile_checkbox_set( &$Settings )
277  {
278  try
279  {
280  $Cols = $Settings->get_setting( 'cols' , 3 );
281  $Value = $Settings->get_setting( 'checked_all' , '0' ) == '0' ? 'off' : 'on';
282  $Query = $Settings->get_setting( 'query' );
283  $this->Database->query_as( DB_OBJECT );
284  $Records = $this->Database->query( $Query );
285  $Records = $this->Database->fetch_results( $Records );
286 
287  $Code = $this->compile_records( $Cols , $Value , $Records );
288 
289  return( $Code );
290  }
291  catch( Exception $e )
292  {
293  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
294  }
295  }
296 
319  function compile_checkbox( &$Settings )
320  {
321  try
322  {
323  $Settings->set_undefined( 'default' , 0 );
324  $Settings->set_undefined( 'id' , md5( microtime() ) );
325  $Settings->set_undefined( 'label' , '' );
326 
327  $Type = $Settings->get_setting( 'type' , 'double' );
328 
329  $Code = $this->CachedMultyFS->get_template( __FILE__ , $Type.'_state_checkbox.tpl' );
330 
331  $Code = $this->String->print_record( $Code , $Settings->get_raw_settings() );
332 
333  return( $Code );
334  }
335  catch( Exception $e )
336  {
337  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
338  }
339  }
340 
365  private function compile_selectors( &$Settings )
366  {
367  try
368  {
369  $SelfClass = $Settings->get_setting( 'self_class' , false );
370  $ParentSelector = $Settings->get_setting( 'parent_selector' , false );
371  $SiblingsSelector = $Settings->get_setting( 'siblings_selector' , '.'.$SelfClass );
372  $ChildrenSelector = $Settings->get_setting( 'children_selector' , false );
373  $Sel = $ParentSelector !== false ? " parent_selector='$ParentSelector'" : '';
374  $Sel = $SiblingsSelector !== false ? $Sel." siblings_selector='$SiblingsSelector'" : $Sel;
375  return( $ChildrenSelector !== false ? $Sel." children_selector='$ChildrenSelector'" : $Sel );
376  }
377  catch( Exception $e )
378  {
379  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
380  }
381  }
382 
405  function compile_checkbox_ex( &$Settings )
406  {
407  try
408  {
409  $SelfClass = $Settings->get_setting( 'self_class' , false );
410  $Sel = $this->compile_selectors( $Settings );
411 
412  $Id = $Settings->get_setting( 'id' , '' );
413  $Name = $Settings->get_setting( 'name' );
414  $Code = $this->CachedMultyFS->get_template( __FILE__ , 'checkbox_ex.tpl' );
415  $PlaceHolders = array( '{id}' , '{name}' , '{self_class}' , '{selector}' );
416  $Data = array( $Id , $Name , $SelfClass , $Sel );
417  $Code = str_replace( $PlaceHolders , $Data , $Code );
418 
419  return( $Code );
420  }
421  catch( Exception $e )
422  {
423  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
424  }
425  }
426  }
427 
428 ?>