48 require_once(SMARTY_PLUGINS_DIR .
'shared.escape_special_chars.php');
62 foreach ($params as $_key => $_val) {
66 $$_key = (string) $_val;
72 $$_key = (bool) $_val;
76 $$_key = (array) $_val;
81 $$_key = array_values((array) $_val);
86 if (is_array($_val)) {
88 foreach ($_val as $_sel) {
89 if (is_object($_sel)) {
90 if (method_exists($_sel,
"__toString")) {
91 $_sel = smarty_function_escape_special_chars((
string) $_sel->__toString());
93 trigger_error(
"html_checkboxes: selected attribute contains an object of class '" . get_class($_sel) .
"' without __toString() method", E_USER_NOTICE);
97 $_sel = smarty_function_escape_special_chars((
string) $_sel);
99 $selected[$_sel] =
true;
101 } elseif (is_object($_val)) {
102 if (method_exists($_val,
"__toString")) {
103 $selected = smarty_function_escape_special_chars((
string) $_val->__toString());
105 trigger_error(
"html_checkboxes: selected attribute is an object of class '" . get_class($_val) .
"' without __toString() method", E_USER_NOTICE);
108 $selected = smarty_function_escape_special_chars((
string) $_val);
113 trigger_error(
'html_checkboxes: the use of the "checkboxes" attribute is deprecated, use "options" instead', E_USER_WARNING);
114 $options = (array) $_val;
125 if (!empty($params[
'strict'])) {
126 if (!is_scalar($_val)) {
127 trigger_error(
"html_options: $_key attribute must be a scalar, only boolean true or string '$_key' will actually add the attribute", E_USER_NOTICE);
130 if ($_val ===
true || $_val === $_key) {
131 $extra .=
' ' . $_key .
'="' . smarty_function_escape_special_chars($_key) .
'"';
139 if (!is_array($_val)) {
140 $extra .=
' ' . $_key .
'="' . smarty_function_escape_special_chars($_val) .
'"';
142 trigger_error(
"html_checkboxes: extra attribute '$_key' cannot be an array", E_USER_NOTICE);
148 if (!isset($options) && !isset($values)) {
152 $_html_result = array();
154 if (isset($options)) {
155 foreach ($options as $_key => $_val) {
159 foreach ($values as $_i => $_key) {
160 $_val = isset($output[$_i]) ? $output[$_i] :
'';
165 if (!empty($params[
'assign'])) {
166 $template->assign($params[
'assign'], $_html_result);
168 return implode(
"\n", $_html_result);
176 if (is_object($value)) {
177 if (method_exists($value,
"__toString")) {
178 $value = (string) $value->__toString();
180 trigger_error(
"html_options: value is an object of class '" . get_class($value) .
"' without __toString() method", E_USER_NOTICE);
185 $value = (string) $value;
188 if (is_object($output)) {
189 if (method_exists($output,
"__toString")) {
190 $output = (string) $output->__toString();
192 trigger_error(
"html_options: output is an object of class '" . get_class($output) .
"' without __toString() method", E_USER_NOTICE);
197 $output = (string) $output;
202 $_id = smarty_function_escape_special_chars(preg_replace(
'![^\w\-\.]!' .
Smarty::$_UTF8_MODIFIER,
'_', $name .
'_' . $value));
203 $_output .=
'<label for="' . $_id .
'">';
205 $_output .=
'<label>';
209 $name = smarty_function_escape_special_chars($name);
210 $value = smarty_function_escape_special_chars($value);
212 $output = smarty_function_escape_special_chars($output);
215 $_output .=
'<input type="checkbox" name="' . $name .
'[]" value="' . $value .
'"';
217 if ($labels && $label_ids) {
218 $_output .=
' id="' . $_id .
'"';
221 if (is_array($selected)) {
222 if (isset($selected[$value])) {
223 $_output .=
' checked="checked"';
225 } elseif ($value === $selected) {
226 $_output .=
' checked="checked"';
229 $_output .= $extra .
' />' . $output;
231 $_output .=
'</label>';
234 $_output .= $separator;