ultimix

- Main Page
- Data Structures
- Files
- Examples

- File List
- Globals

radiobutton_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 radiobutton_markup_1_0_0
27 {
28
39 var $Database = false;
40 var $Security = false;
41 var $String = false;
42
53 function __construct()
54 {
55 try
56 {
57 $this->Database = get_package( 'database' , 'last' , __FILE__ );
58 $this->Security = get_package( 'security' , 'last' , __FILE__ );
59 $this->String = get_package( 'string' , 'last' , __FILE__ );
60 }
61 catch( Exception $e )
62 {
63 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
64 }
65 }
66
97 private function get_single_radiobutton( $r , $Name , $CurrentValue )
98 {
99 try
100 {
101 $Code = $this->CachedMultyFS->get_template( __FILE__ , 'radio_set_item.tpl' );
102
103 $PlaceHolders = array( '{name}' , '{value}' , '{current_value}' , '{label}' );
104
105 $Data = array( $Name , $r->Value , $CurrentValue , $r->label );
106
107 return( str_replace( $PlaceHolders , $Data , $Code ) );
108 }
109 catch( Exception $e )
110 {
111 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
112 }
113 }
114
149 function compile_radio_set_records( $Records , $Cols , $Name , $CurrentValue )
150 {
151 try
152 {
153 $Counter = 0;
154 $Code = $this->CachedMultyFS->get_template( __FILE__ , 'radio_set_start.tpl' );
155
156 foreach( $Records as $r )
157 {
158 if( $Counter == $Cols )
159 {
160 $Counter = 0;
161 $Code .= $this->CachedMultyFS->get_template( __FILE__ , 'radio_set_line_end.tpl' );
162 }
163
164 $Code .= $this->get_single_radiobutton( $r , $Name , $CurrentValue );
165
166 $Counter++;
167 }
168
169 return( $Code .= $this->CachedMultyFS->get_template( __FILE__ , 'radio_set_end.tpl' ) );
170 }
171 catch( Exception $e )
172 {
173 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
174 }
175 }
176
199 private function get_records( &$Settings )
200 {
201 try
202 {
203 $Query = $Settings->get_setting( 'query' );
204 $this->Database->query_as( DB_OBJECT );
205 $Records = $this->Database->query( $Query );
206 $Records = $this->Database->fetch_results( $Records );
207
208 return( $Records );
209 }
210 catch( Exception $e )
211 {
212 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
213 }
214 }
215
238 function compile_radio_set( &$Settings )
239 {
240 try
241 {
242 list( $Cols , $Name )= $Settings->get_setting( 'cols,name' );
243
244 $CurrentValue = $this->Security->get_gp( $Name , 'command' , '' );
245
246 $Records = $this->get_records( $Settings );
247
248 $Code = $this->compile_radio_set_records( $Records , $Cols , $Name , $CurrentValue );
249
250 return( $Code );
251 }
252 catch( Exception $e )
253 {
254 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
255 }
256 }
257
280 function get_checked( &$Settings )
281 {
282 try
283 {
284 $Value = $Settings->get_setting( 'value' );
285 $Name = $Settings->get_setting( 'name' );
286
287 if( $this->Security->get_gp( $Name ) )
288 {
289 $CurrentValue = $this->Security->get_gp( $Name , 'string' );
290 }
291 else
292 {
293 $CurrentValue = $Settings->get_setting( 'default' , $Value );
294 }
295
296 $Checked = $Value === $CurrentValue ? $Checked = 'checked' : '';
297
298 return( $Checked );
299 }
300 catch( Exception $e )
301 {
302 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
303 }
304 }
305
328 function compile_radio( &$Settings )
329 {
330 try
331 {
332 $Name = $Settings->get_setting( 'name' );
333
334 $Value = $Settings->get_setting( 'value' );
335
336 $Checked = $this->get_checked( $Settings );
337
338 $id = $Settings->get_setting( 'id' , md5( microtime() ) );
339
340 $Template = "<input id=\"$id\" style=\"cursor: pointer;\" ".
341 "type=\"radio\" value=\"$Value\" $Checked name=\"$Name\">";
342
343 $Label = $Settings->get_setting( 'label' , '' );
344
345 if( $Label != '' )
346 {
347 $Template = "<label for=\"$id\" style=\"cursor: pointer;\">$Template {lang:$Label}</label>";
348 }
349
350 return( $Template );
351 }
352 catch( Exception $e )
353 {
354 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
355 }
356 }
357
380 function compile_yes_no( &$Settings )
381 {
382 try
383 {
384 $Settings->set_undefined( 'current_value' , 1 );
385
386 $Name = $Settings->get_setting( 'name' );
387 $CurrentValue = $Settings->get_setting( 'current_value' );
388
389 $Code = "{radio:value=1;current_value=$CurrentValue;name=$Name;label=yes}&nbsp;".
390 "{radio:value=2;current_value=$CurrentValue;name=$Name;label=no}";
391
392 return( $Code );
393 }
394 catch( Exception $e )
395 {
396 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
397 }
398 }
399 }
400
401 ?>