From f83592dc82a3d30c4433c62f7b75af3a0bc17f42 Mon Sep 17 00:00:00 2001 From: mohrt Date: Mon, 24 Feb 2003 21:10:01 +0000 Subject: [PATCH] commit checkboxes, update radios --- NEWS | 1 + libs/plugins/function.html_checkboxes.php | 61 ++++++++++++++++++ libs/plugins/function.html_radios.php | 75 ++++++++++------------- 3 files changed, 95 insertions(+), 42 deletions(-) create mode 100644 libs/plugins/function.html_checkboxes.php diff --git a/NEWS b/NEWS index 3cc5c854..e5588aeb 100644 --- a/NEWS +++ b/NEWS @@ -3,6 +3,7 @@ - added << >> <> support to if statments (SMK, Monte) - fix _assign_smarty_interface to not overwrite keys other than 'request' (Jerome Poudevigne, Monte) + - added html_checkboxes to distribution (Christopher Kvarme, Monte) - added html_radios to distribution (Christopher Kvarme, Monte) - fixed string_format modifier args (wrong order) (Paul Lockaby, Monte) diff --git a/libs/plugins/function.html_checkboxes.php b/libs/plugins/function.html_checkboxes.php new file mode 100644 index 00000000..29dfd328 --- /dev/null +++ b/libs/plugins/function.html_checkboxes.php @@ -0,0 +1,61 @@ + or   + * output (optional) - without this one the buttons don't have names + * Author: Christopher Kvarme + * Credits: Monte Ohrt + * Examples: {html_checkboxes values=$ids output=$names} + * {html_checkboxes values=$ids name='box' separator='
' output=$names} + * {html_checkboxes values=$ids checked=$checked separator='
' output=$names} + * ------------------------------------------------------------- + */ +function smarty_function_html_checkboxes($params, &$smarty) +{ + extract($params); + + $_html_result = ''; + if(!isset($name)){ + $name = 'checkbox'; + } + settype($checked, 'array'); + if (isset($checkboxes)) { + settype($checkboxes, 'array'); + foreach ($checkboxes as $_key => $_val) { + $_html_result .= smarty_function_html_checkboxes_output($name, $_key, $_val, $checked, $separator); + } + } else { + settype($output, 'array'); + settype($values, 'array'); + for ($_i = 0, $_for_max = count($output); $_i < $_for_max; $_i++) { + $_html_result .= smarty_function_html_checkboxes_output($name, $values[$_i], $output[$_i], $checked, $separator); + } + } + + return $_html_result; +} + +function smarty_function_html_checkboxes_output($name, $value, $output, $checked, $separator) { + $_output = ' diff --git a/libs/plugins/function.html_radios.php b/libs/plugins/function.html_radios.php index 55eae1cc..31f2ac73 100644 --- a/libs/plugins/function.html_radios.php +++ b/libs/plugins/function.html_radios.php @@ -2,69 +2,60 @@ /* * Smarty plugin - * --------------------------------------------------------------------------------------------- - * Type: function - * Name: html_radios - * Purpose: Prints the list of or   - * output[optional] - without this one the buttons don't have names - * Author: Christopher Kvarme - * --------------------------------------------------------------------------------------------- + * ------------------------------------------------------------- + * File: function.html_radios.php + * Type: function + * Name: html_radios + * Version: 1.0 + * Date: 24.Feb.2003 + * Purpose: Prints out a list of radio button input types + * Input: name (optional) - string default "radio" + * values (required) - array + * checked (optional) - array default not set + * separator (optional) - ie
or   + * output (optional) - without this one the buttons don't have names + * Author: Christopher Kvarme + * Credits: Monte Ohrt + * Examples: {html_radios values=$ids output=$names} + * {html_radios values=$ids name='choices' separator='
' output=$names} + * {html_radios values=$ids checked=$checked separator='
' output=$names} + * ------------------------------------------------------------- */ function smarty_function_html_radios($params, &$smarty) { extract($params); - $html_result = ''; + $_html_result = ''; if(!isset($name)){ - $name = "radio"; + $name = 'radio'; } settype($checked, 'array'); if (isset($radios)) { settype($radios, 'array'); - foreach ($radios as $key => $value) { - $html_result .= smarty_function_html_radios_optoutput($key, $value, $checked); + foreach ($radios as $_key => $_val) { + $_html_result .= smarty_function_html_radios_output($name, $_key, $_val, $checked, $separator); } } else { settype($output, 'array'); settype($values, 'array'); - for ($i = 0, $for_max = count($output); $i < $for_max; $i++) { - if ($i < count($values)) { - $html_result .= smarty_function_html_radios_optoutput($values[$i], $output[$i], $checked, $name, $separator); - } else { - $html_result .= smarty_function_html_radios_optoutput($output[$i], $output[$i], $checked, $name, $separator); - } + for ($_i = 0, $_for_max = count($output); $_i < $_for_max; $_i++) { + $_html_result .= smarty_function_html_radios_output($name, $values[$_i], $output[$_i], $checked, $separator); } } - return $html_result; + return $_html_result; } -function smarty_function_html_radios_optoutput($key, $value, $checked, $name, $separator) { - if(!is_array($value)) { - $html_result = '' . "\n"; - foreach ($values as $key => $value) { - $optgroup_html .= smarty_function_html_radios_optoutput($key, $value, $checked); - } - $optgroup_html .= "\n"; - return $optgroup_html; -} - -/* vim: set expandtab: */ ?>