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 r54701 - 2010-02-22 09:42:10 -0800 (Mon, 22 Feb 2010) - jmertic - Bug 35849 - Add optional option 'sortoptions' to html_options Smarty function to sort the passed options array. Then I updated that call in the Parent field template so we specify to use this newly added option.
15 r51719 - 2009-10-22 10:18:00 -0700 (Thu, 22 Oct 2009) - mitani - Converted to Build 3 tags and updated the build system
17 r51634 - 2009-10-19 13:32:22 -0700 (Mon, 19 Oct 2009) - mitani - Windex is the branch for Sugar Sales 1.0 development
19 r50375 - 2009-08-24 18:07:43 -0700 (Mon, 24 Aug 2009) - dwong - branch kobe2 from tokyo r50372
21 r42807 - 2008-12-29 11:16:59 -0800 (Mon, 29 Dec 2008) - dwong - Branch from trunk/sugarcrm r42806 to branches/tokyo/sugarcrm
23 r35784 - 2008-05-20 14:31:40 -0700 (Tue, 20 May 2008) - dwheeler - 21475: Converted multiselect DynamicField default value to be a multiselect.
25 r10971 - 2006-01-12 14:58:30 -0800 (Thu, 12 Jan 2006) - chris - Bug 4128: updating Smarty templates to 2.6.11, a version supposedly that plays better with PHP 5.1
27 r8230 - 2005-10-03 17:47:19 -0700 (Mon, 03 Oct 2005) - majed - Added Sugar_Smarty to the code tree.
41 * Smarty {html_options} function plugin
44 * Name: html_options<br>
46 * - name (optional) - string default "select"
47 * - values (required if no options supplied) - array
48 * - options (required if no values supplied) - associative array
49 * - selected (optional) - string default not set
50 * - output (required if not options supplied) - array
51 * Purpose: Prints the list of <option> tags generated from
52 * the passed parameters
53 * @link http://smarty.php.net/manual/en/language.function.html.options.php {html_image}
54 * (Smarty online manual)
55 * @author Monte Ohrt <monte at ohrt dot com>
59 * @uses smarty_function_escape_special_chars()
61 function smarty_function_html_options($params, &$smarty)
63 require_once $smarty->_get_plugin_filepath('shared','escape_special_chars');
73 foreach($params as $_key => $_val) {
76 $$_key = (string)$_val;
80 $$_key = (array)$_val;
85 $$_key = array_values((array)$_val);
89 $$_key = array_map('strval', array_values((array)$_val));
93 $extra .= ' multiple="true" size="6"';
102 if(!is_array($_val)) {
103 $extra .= ' '.$_key.'="'.smarty_function_escape_special_chars($_val).'"';
105 $smarty->trigger_error("html_options: extra attribute '$_key' cannot be an array", E_USER_NOTICE);
111 if (!isset($options) && !isset($values))
112 return ''; /* raise error here? */
116 if (isset($options)) {
118 foreach ($options as $_key=>$_val)
119 $_html_result .= smarty_function_html_options_optoutput($_key, $_val, $selected);
123 foreach ($values as $_i=>$_key) {
124 $_val = isset($output[$_i]) ? $output[$_i] : '';
125 $_html_result .= smarty_function_html_options_optoutput($_key, $_val, $selected);
131 $_html_result = '<select name="' . $name . '"' . $extra . '>' . "\n" . $_html_result . '</select>' . "\n";
134 return $_html_result;
138 function smarty_function_html_options_optoutput($key, $value, $selected) {
139 if(!is_array($value)) {
140 $_html_result = '<option label="' . smarty_function_escape_special_chars($value) . '" value="' .
141 smarty_function_escape_special_chars($key) . '"';
142 if (in_array((string)$key, $selected))
143 $_html_result .= ' selected="selected"';
144 $_html_result .= '>' . smarty_function_escape_special_chars($value) . '</option>' . "\n";
146 $_html_result = smarty_function_html_options_optgroup($key, $value, $selected);
148 return $_html_result;
151 function smarty_function_html_options_optgroup($key, $values, $selected) {
152 $optgroup_html = '<optgroup label="' . smarty_function_escape_special_chars($key) . '">' . "\n";
153 foreach ($values as $key => $value) {
154 $optgroup_html .= smarty_function_html_options_optoutput($key, $value, $selected);
156 $optgroup_html .= "</optgroup>\n";
157 return $optgroup_html;
160 /* vim: set expandtab: */