[ Index ]
 

Code source de phpMyVisites 2.3

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/libs/smarty/plugins/ -> function.html_radios.php (source)

   1  <?php
   2  /**

   3   * Smarty plugin

   4   * @package Smarty

   5   * @subpackage plugins

   6   */
   7  
   8  
   9  /**

  10   * Smarty {html_radios} function plugin

  11   *

  12   * File:       function.html_radios.php<br>

  13   * Type:       function<br>

  14   * Name:       html_radios<br>

  15   * Date:       24.Feb.2003<br>

  16   * Purpose:    Prints out a list of radio input types<br>

  17   * Input:<br>

  18   *           - name       (optional) - string default "radio"

  19   *           - values     (required) - array

  20   *           - options    (optional) - associative array

  21   *           - checked    (optional) - array default not set

  22   *           - separator  (optional) - ie <br> or &nbsp;

  23   *           - output     (optional) - the output next to each radio button

  24   *           - assign     (optional) - assign the output as an array to this variable

  25   * Examples:

  26   * <pre>

  27   * {html_radios values=$ids output=$names}

  28   * {html_radios values=$ids name='box' separator='<br>' output=$names}

  29   * {html_radios values=$ids checked=$checked separator='<br>' output=$names}

  30   * </pre>

  31   * @link http://smarty.php.net/manual/en/language.function.html.radios.php {html_radios}

  32   *      (Smarty online manual)

  33   * @author     Christopher Kvarme <christopher.kvarme@flashjab.com>

  34   * @author credits to Monte Ohrt <monte at ohrt dot com>

  35   * @version    1.0

  36   * @param array

  37   * @param Smarty

  38   * @return string

  39   * @uses smarty_function_escape_special_chars()

  40   */
  41  function smarty_function_html_radios($params, &$smarty)
  42  {
  43      require_once $smarty->_get_plugin_filepath('shared','escape_special_chars');
  44     
  45      $name = 'radio';
  46      $values = null;
  47      $options = null;
  48      $selected = null;
  49      $separator = '';
  50      $labels = true;
  51      $output = null;
  52      $extra = '';
  53  
  54      foreach($params as $_key => $_val) {
  55          switch($_key) {
  56              case 'name':
  57              case 'separator':
  58                  $$_key = (string)$_val;
  59                  break;
  60  
  61              case 'checked':
  62              case 'selected':
  63                  if(is_array($_val)) {
  64                      $smarty->trigger_error('html_radios: the "' . $_key . '" attribute cannot be an array', E_USER_WARNING);
  65                  } else {
  66                      $selected = (string)$_val;
  67                  }
  68                  break;
  69  
  70              case 'labels':
  71                  $$_key = (bool)$_val;
  72                  break;
  73  
  74              case 'options':
  75                  $$_key = (array)$_val;
  76                  break;
  77  
  78              case 'values':
  79              case 'output':
  80                  $$_key = array_values((array)$_val);
  81                  break;
  82  
  83              case 'radios':
  84                  $smarty->trigger_error('html_radios: the use of the "radios" attribute is deprecated, use "options" instead', E_USER_WARNING);
  85                  $options = (array)$_val;
  86                  break;
  87  
  88              case 'assign':
  89                  break;
  90  
  91              default:
  92                  if(!is_array($_val)) {
  93                      $extra .= ' '.$_key.'="'.smarty_function_escape_special_chars($_val).'"';
  94                  } else {
  95                      $smarty->trigger_error("html_radios: extra attribute '$_key' cannot be an array", E_USER_NOTICE);
  96                  }
  97                  break;
  98          }
  99      }
 100  
 101      if (!isset($options) && !isset($values))
 102          return ''; /* raise error here? */
 103  
 104      $_html_result = array();
 105  
 106      if (isset($options)) {
 107  
 108          foreach ($options as $_key=>$_val)
 109              $_html_result[] = smarty_function_html_radios_output($name, $_key, $_val, $selected, $extra, $separator, $labels);
 110  
 111      } else {
 112  
 113          foreach ($values as $_i=>$_key) {
 114              $_val = isset($output[$_i]) ? $output[$_i] : '';
 115              $_html_result[] = smarty_function_html_radios_output($name, $_key, $_val, $selected, $extra, $separator, $labels);
 116          }
 117  
 118      }
 119  
 120      if(!empty($params['assign'])) {
 121          $smarty->assign($params['assign'], $_html_result);
 122      } else {
 123          return implode("\n",$_html_result);
 124      }
 125  
 126  }
 127  
 128  function smarty_function_html_radios_output($name, $value, $output, $selected, $extra, $separator, $labels) {
 129      $_output = '';
 130      if ($labels) {
 131        $_id = smarty_function_escape_special_chars($name . '_' . $value);
 132        $_output .= '<label for="' . $_id . '">';
 133     }
 134     $_output .= '<input type="radio" name="'
 135          . smarty_function_escape_special_chars($name) . '" value="'
 136          . smarty_function_escape_special_chars($value) . '"';
 137  
 138     if ($labels) $_output .= ' id="' . $_id . '"';
 139  
 140      if ($value==$selected) {
 141          $_output .= ' checked="checked"';
 142      }
 143      $_output .= $extra . ' />' . $output;
 144      if ($labels) $_output .= '</label>';
 145      $_output .=  $separator;
 146  
 147      return $_output;
 148  }
 149  
 150  ?>


Généré le : Mon Nov 26 14:10:01 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics