6  * @subpackage PluginsFunction
 
  10  * Smarty {html_checkboxes} function plugin
 
  12  * File:       function.html_checkboxes.php<br>
 
  14  * Name:       html_checkboxes<br>
 
  15  * Date:       24.Feb.2003<br>
 
  16  * Purpose:    Prints out a list of checkbox input types<br>
 
  19  * {html_checkboxes values=$ids output=$names}
 
  20  * {html_checkboxes values=$ids name='box' separator='<br>' output=$names}
 
  21  * {html_checkboxes values=$ids checked=$checked separator='<br>' output=$names}
 
  23  * @link http://smarty.php.net/manual/en/language.function.html.checkboxes.php {html_checkboxes}
 
  24  *      (Smarty online manual)
 
  25  * @author     Christopher Kvarme <christopher.kvarme@flashjab.com>
 
  26  * @author credits to Monte Ohrt <monte at ohrt dot com>
 
  28  * @param array $params parameters
 
  30  *           - name       (optional) - string default "checkbox"
 
  31  *           - values     (required) - array
 
  32  *           - options    (optional) - associative array
 
  33  *           - checked    (optional) - array default not set
 
  34  *           - separator  (optional) - ie <br> or  
 
  35  *           - output     (optional) - the output next to each checkbox
 
  36  *           - assign     (optional) - assign the output as an array to this variable
 
  37  * @param object $template template object
 
  39  * @uses smarty_function_escape_special_chars()
 
  41 function smarty_function_html_checkboxes($params, $template)
 
  43     require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php');
 
  55     foreach($params as $_key => $_val) {
 
  67                 $$_key = (array)$_val;
 
  72                 $$_key = array_values((array)$_val);
 
  77                 $selected = array_map('strval', array_values((array)$_val));
 
  81                 trigger_error('html_checkboxes: the use of the "checkboxes" attribute is deprecated, use "options" instead', E_USER_WARNING);
 
  82                 $options = (array)$_val;
 
  89                 if(!is_array($_val)) {
 
  90                     $extra .= ' '.$_key.'="'.smarty_function_escape_special_chars($_val).'"';
 
  92                     trigger_error("html_checkboxes: extra attribute '$_key' cannot be an array", E_USER_NOTICE);
 
  98     if (!isset($options) && !isset($values))
 
  99         return ''; /* raise error here? */
 
 101     settype($selected, 'array');
 
 102     $_html_result = array();
 
 104     if (isset($options)) {
 
 106         foreach ($options as $_key=>$_val)
 
 107             $_html_result[] = smarty_function_html_checkboxes_output($name, $_key, $_val, $selected, $extra, $separator, $labels);
 
 111         foreach ($values as $_i=>$_key) {
 
 112             $_val = isset($output[$_i]) ? $output[$_i] : '';
 
 113             $_html_result[] = smarty_function_html_checkboxes_output($name, $_key, $_val, $selected, $extra, $separator, $labels);
 
 118     if(!empty($params['assign'])) {
 
 119         $template->assign($params['assign'], $_html_result);
 
 121         return implode("\n",$_html_result);
 
 126 function smarty_function_html_checkboxes_output($name, $value, $output, $selected, $extra, $separator, $labels) {
 
 128     if ($labels) $_output .= '<label>';
 
 129     $_output .= '<input type="checkbox" name="'
 
 130         . smarty_function_escape_special_chars($name) . '[]" value="'
 
 131         . smarty_function_escape_special_chars($value) . '"';
 
 133     if (in_array((string)$value, $selected)) {
 
 134         $_output .= ' checked="checked"';
 
 136     $_output .= $extra . ' />' . $output;
 
 137     if ($labels) $_output .= '</label>';
 
 138     $_output .=  $separator;