• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • Examples
  • File List

E:/E/GEAMP/www/openbiz/openbiz/others/Smarty/libs/plugins/function.html_radios.php

00001 <?php
00041 function smarty_function_html_radios($params, &$smarty)
00042 {
00043     require_once $smarty->_get_plugin_filepath('shared','escape_special_chars');
00044    
00045     $name = 'radio';
00046     $values = null;
00047     $options = null;
00048     $selected = null;
00049     $separator = '';
00050     $labels = true;
00051     $label_ids = false;
00052     $output = null;
00053     $extra = '';
00054 
00055     foreach($params as $_key => $_val) {
00056         switch($_key) {
00057             case 'name':
00058             case 'separator':
00059                 $$_key = (string)$_val;
00060                 break;
00061 
00062             case 'checked':
00063             case 'selected':
00064                 if(is_array($_val)) {
00065                     $smarty->trigger_error('html_radios: the "' . $_key . '" attribute cannot be an array', E_USER_WARNING);
00066                 } else {
00067                     $selected = (string)$_val;
00068                 }
00069                 break;
00070 
00071             case 'labels':
00072             case 'label_ids':
00073                 $$_key = (bool)$_val;
00074                 break;
00075 
00076             case 'options':
00077                 $$_key = (array)$_val;
00078                 break;
00079 
00080             case 'values':
00081             case 'output':
00082                 $$_key = array_values((array)$_val);
00083                 break;
00084 
00085             case 'radios':
00086                 $smarty->trigger_error('html_radios: the use of the "radios" attribute is deprecated, use "options" instead', E_USER_WARNING);
00087                 $options = (array)$_val;
00088                 break;
00089 
00090             case 'assign':
00091                 break;
00092 
00093             default:
00094                 if(!is_array($_val)) {
00095                     $extra .= ' '.$_key.'="'.smarty_function_escape_special_chars($_val).'"';
00096                 } else {
00097                     $smarty->trigger_error("html_radios: extra attribute '$_key' cannot be an array", E_USER_NOTICE);
00098                 }
00099                 break;
00100         }
00101     }
00102 
00103     if (!isset($options) && !isset($values))
00104         return ''; /* raise error here? */
00105 
00106     $_html_result = array();
00107 
00108     if (isset($options)) {
00109 
00110         foreach ($options as $_key=>$_val)
00111             $_html_result[] = smarty_function_html_radios_output($name, $_key, $_val, $selected, $extra, $separator, $labels, $label_ids);
00112 
00113     } else {
00114 
00115         foreach ($values as $_i=>$_key) {
00116             $_val = isset($output[$_i]) ? $output[$_i] : '';
00117             $_html_result[] = smarty_function_html_radios_output($name, $_key, $_val, $selected, $extra, $separator, $labels, $label_ids);
00118         }
00119 
00120     }
00121 
00122     if(!empty($params['assign'])) {
00123         $smarty->assign($params['assign'], $_html_result);
00124     } else {
00125         return implode("\n",$_html_result);
00126     }
00127 
00128 }
00129 
00130 function smarty_function_html_radios_output($name, $value, $output, $selected, $extra, $separator, $labels, $label_ids) {
00131     $_output = '';
00132     if ($labels) {
00133       if($label_ids) {
00134           $_id = smarty_function_escape_special_chars(preg_replace('![^\w\-\.]!', '_', $name . '_' . $value));
00135           $_output .= '<label for="' . $_id . '">';
00136       } else {
00137           $_output .= '<label>';           
00138       }
00139    }
00140    $_output .= '<input type="radio" name="'
00141         . smarty_function_escape_special_chars($name) . '" value="'
00142         . smarty_function_escape_special_chars($value) . '"';
00143 
00144    if ($labels && $label_ids) $_output .= ' id="' . $_id . '"';
00145 
00146     if ((string)$value==$selected) {
00147         $_output .= ' checked="checked"';
00148     }
00149     $_output .= $extra . ' />' . $output;
00150     if ($labels) $_output .= '</label>';
00151     $_output .=  $separator;
00152 
00153     return $_output;
00154 }
00155 
00156 ?>

Generated on Thu Apr 19 2012 17:01:16 for openbiz by  doxygen 1.7.2