5 Modification information for LGPL compliance
7 r56990 - 2010-06-16 13:05:36 -0700 (Wed, 16 Jun 2010) - kjing - snapshot "Mango" svn branch to a new one for GitHub sync
9 r56989 - 2010-06-16 13:01:33 -0700 (Wed, 16 Jun 2010) - kjing - defunt "Mango" svn dev branch before github cutover
11 r55980 - 2010-04-19 13:31:28 -0700 (Mon, 19 Apr 2010) - kjing - create Mango (6.1) based on windex
13 r51719 - 2009-10-22 10:18:00 -0700 (Thu, 22 Oct 2009) - mitani - Converted to Build 3 tags and updated the build system
15 r51634 - 2009-10-19 13:32:22 -0700 (Mon, 19 Oct 2009) - mitani - Windex is the branch for Sugar Sales 1.0 development
17 r50375 - 2009-08-24 18:07:43 -0700 (Mon, 24 Aug 2009) - dwong - branch kobe2 from tokyo r50372
19 r42807 - 2008-12-29 11:16:59 -0800 (Mon, 29 Dec 2008) - dwong - Branch from trunk/sugarcrm r42806 to branches/tokyo/sugarcrm
21 r8230 - 2005-10-03 17:47:19 -0700 (Mon, 03 Oct 2005) - majed - Added Sugar_Smarty to the code tree.
35 * Smarty {html_checkboxes} function plugin
37 * File: function.html_checkboxes.php<br>
39 * Name: html_checkboxes<br>
40 * Date: 24.Feb.2003<br>
41 * Purpose: Prints out a list of checkbox input types<br>
43 * - name (optional) - string default "checkbox"
44 * - values (required) - array
45 * - options (optional) - associative array
46 * - checked (optional) - array default not set
47 * - separator (optional) - ie <br> or
48 * - output (optional) - the output next to each checkbox
49 * - assign (optional) - assign the output as an array to this variable
52 * {html_checkboxes values=$ids output=$names}
53 * {html_checkboxes values=$ids name='box' separator='<br>' output=$names}
54 * {html_checkboxes values=$ids checked=$checked separator='<br>' output=$names}
56 * @link http://smarty.php.net/manual/en/language.function.html.checkboxes.php {html_checkboxes}
57 * (Smarty online manual)
58 * @author Christopher Kvarme <christopher.kvarme@flashjab.com>
59 * @author credits to Monte Ohrt <monte at ohrt dot com>
64 * @uses smarty_function_escape_special_chars()
66 function smarty_function_html_checkboxes($params, &$smarty)
68 require_once $smarty->_get_plugin_filepath('shared','escape_special_chars');
80 foreach($params as $_key => $_val) {
92 $$_key = (array)$_val;
97 $$_key = array_values((array)$_val);
102 $selected = array_map('strval', array_values((array)$_val));
106 $smarty->trigger_error('html_checkboxes: the use of the "checkboxes" attribute is deprecated, use "options" instead', E_USER_WARNING);
107 $options = (array)$_val;
114 if(!is_array($_val)) {
115 $extra .= ' '.$_key.'="'.smarty_function_escape_special_chars($_val).'"';
117 $smarty->trigger_error("html_checkboxes: extra attribute '$_key' cannot be an array", E_USER_NOTICE);
123 if (!isset($options) && !isset($values))
124 return ''; /* raise error here? */
126 settype($selected, 'array');
127 $_html_result = array();
129 if (isset($options)) {
131 foreach ($options as $_key=>$_val)
132 $_html_result[] = smarty_function_html_checkboxes_output($name, $_key, $_val, $selected, $extra, $separator, $labels);
136 foreach ($values as $_i=>$_key) {
137 $_val = isset($output[$_i]) ? $output[$_i] : '';
138 $_html_result[] = smarty_function_html_checkboxes_output($name, $_key, $_val, $selected, $extra, $separator, $labels);
143 if(!empty($params['assign'])) {
144 $smarty->assign($params['assign'], $_html_result);
146 return implode("\n",$_html_result);
151 function smarty_function_html_checkboxes_output($name, $value, $output, $selected, $extra, $separator, $labels) {
153 if ($labels) $_output .= '<label>';
154 $_output .= '<input type="checkbox" name="'
155 . smarty_function_escape_special_chars($name) . '[]" value="'
156 . smarty_function_escape_special_chars($value) . '"';
158 if (in_array((string)$value, $selected)) {
159 $_output .= ' checked="checked"';
161 $_output .= $extra . ' />' . $output;
162 if ($labels) $_output .= '</label>';
163 $_output .= $separator;