38 require_once(SMARTY_PLUGINS_DIR .
'shared.escape_special_chars.php');
50 foreach ($params as $_key => $_val) {
55 $$_key = (string) $_val;
59 $options = (array) $_val;
64 $$_key = array_values((array) $_val);
68 if (is_array($_val)) {
70 foreach ($_val as $_sel) {
71 if (is_object($_sel)) {
72 if (method_exists($_sel,
"__toString")) {
73 $_sel = smarty_function_escape_special_chars((
string) $_sel->__toString());
75 trigger_error(
"html_options: selected attribute contains an object of class '" . get_class($_sel) .
"' without __toString() method", E_USER_NOTICE);
79 $_sel = smarty_function_escape_special_chars((
string) $_sel);
81 $selected[$_sel] =
true;
83 } elseif (is_object($_val)) {
84 if (method_exists($_val,
"__toString")) {
85 $selected = smarty_function_escape_special_chars((
string) $_val->__toString());
87 trigger_error(
"html_options: selected attribute is an object of class '" . get_class($_val) .
"' without __toString() method", E_USER_NOTICE);
90 $selected = smarty_function_escape_special_chars((
string) $_val);
99 if (!empty($params[
'strict'])) {
100 if (!is_scalar($_val)) {
101 trigger_error(
"html_options: $_key attribute must be a scalar, only boolean true or string '$_key' will actually add the attribute", E_USER_NOTICE);
104 if ($_val ===
true || $_val === $_key) {
105 $extra .=
' ' . $_key .
'="' . smarty_function_escape_special_chars($_key) .
'"';
113 if (!is_array($_val)) {
114 $extra .=
' ' . $_key .
'="' . smarty_function_escape_special_chars($_val) .
'"';
116 trigger_error(
"html_options: extra attribute '$_key' cannot be an array", E_USER_NOTICE);
122 if (!isset($options) && !isset($values)) {
131 if (isset($options)) {
132 foreach ($options as $_key => $_val) {
136 foreach ($values as $_i => $_key) {
137 $_val = isset($output[$_i]) ? $output[$_i] :
'';
143 $_html_class = !empty($class) ?
' class="' . $class .
'"' :
'';
144 $_html_id = !empty($id) ?
' id="' . $id .
'"' :
'';
145 $_html_result =
'<select name="' . $name .
'"' . $_html_class . $_html_id . $extra .
'>' .
"\n" . $_html_result .
'</select>' .
"\n";
148 return $_html_result;
153 if (!is_array($value)) {
154 $_key = smarty_function_escape_special_chars($key);
155 $_html_result =
'<option value="' . $_key .
'"';
156 if (is_array($selected)) {
157 if (isset($selected[$_key])) {
158 $_html_result .=
' selected="selected"';
160 } elseif ($_key === $selected) {
161 $_html_result .=
' selected="selected"';
163 $_html_class = !empty($class) ?
' class="' . $class .
' option"' :
'';
164 $_html_id = !empty($id) ?
' id="' . $id .
'-' . $idx .
'"' :
'';
165 if (is_object($value)) {
166 if (method_exists($value,
"__toString")) {
167 $value = smarty_function_escape_special_chars((
string) $value->__toString());
169 trigger_error(
"html_options: value is an object of class '" . get_class($value) .
"' without __toString() method", E_USER_NOTICE);
174 $value = smarty_function_escape_special_chars((
string) $value);
176 $_html_result .= $_html_class . $_html_id .
'>' . $value .
'</option>' .
"\n";
184 return $_html_result;
189 $optgroup_html =
'<optgroup label="' . smarty_function_escape_special_chars($key) .
'">' .
"\n";
190 foreach ($values as $key => $value) {
193 $optgroup_html .=
"</optgroup>\n";
195 return $optgroup_html;