-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunction.html_options.php
128 lines (118 loc) · 3.43 KB
/
function.html_options.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?php
/*
* template_lite plugin
* -------------------------------------------------------------
* Type: function
* Name: html_options
* Purpose: prints out the options for an html_select item
* Credit: Taken from the original Smarty
* http://smarty.php.net
* -------------------------------------------------------------
*/
function tpl_function_html_options($params, &$tpl)
{
require_once("shared.escape_chars.php");
$name = null;
$options = null;
$selected = array();
$extra = '';
foreach($params as $_key => $_val)
{
switch($_key)
{
case 'name':
$$_key = (string)$_val;
break;
case 'options':
$$_key = (array)$_val;
break;
case 'values':
case 'output':
$$_key = array_values((array)$_val);
break;
case 'selected':
$$_key = array_values((array)$_val);
break;
default:
if(!is_array($_key))
{
$extra .= ' ' . $_key . '="' . tpl_escape_chars($_val) . '"';
}
else
{
$tpl->trigger_error("html_select: attribute '$_key' cannot be an array");
}
break;
}
}
$_html_result = '';
if (is_array($options))
{
foreach ($options as $_key=>$_val)
{
$_html_result .= tpl_function_html_options_optoutput($tpl, $_key, $_val, $selected);
}
}
else
{
foreach ((array)$values as $_i=>$_key)
{
$_val = isset($output[$_i]) ? $output[$_i] : '';
$_html_result .= tpl_function_html_options_optoutput($tpl, $_key, $_val, $selected);
}
}
if(!empty($name))
{
$_html_result = '<select name="' . tpl_escape_chars($name) . '"' . $extra . '>' . "\n" . $_html_result . '</select>' . "\n";
}
return $_html_result;
}
function tpl_function_html_options_optoutput(&$tpl, $key, $value, $selected)
{
if(!is_array($value))
{
$_html_result = '<option label="' . tpl_escape_chars($value) . '" value="' . tpl_escape_chars($key) . '"';
if (in_array($key, $selected))
{
$_html_result .= ' selected="selected"';
}
$_html_result .= '>' . tpl_escape_chars($value) . '</option>' . "\n";
}
else
{
$_html_result = tpl_function_html_options_optgroup($tpl, $key, $value, $selected);
}
return $_html_result;
}
function tpl_function_html_options_optgroup(&$tpl, $key, $values, $selected)
{
$optgroup_html = '<optgroup label="' . tpl_escape_chars($key) . '">' . "\n";
foreach ($values as $key => $value)
{
$optgroup_html .= tpl_function_html_options_optoutput($tpl, $key, $value, $selected);
}
$optgroup_html .= "</optgroup>\n";
return $optgroup_html;
}
if(!function_exists('smarty_function_html_options')) {
function smarty_function_html_options() {
$arg_list = func_get_args();
foreach ($arg_list as $k=>$arg) eval ("\$$arg;");
return eval('tpl_function_html_options(' . (count($arg_list)>0 ? '$' . implode(', $', array_keys($arg_list)) : '') . ');');
}
}
if(!function_exists('smarty_function_html_options_optoutput')) {
function smarty_function_html_options_optoutput() {
$arg_list = func_get_args();
foreach ($arg_list as $k=>$arg) eval ("\$$arg;");
return eval('tpl_function_html_options_optoutput(' . (count($arg_list)>0 ? '$' . implode(', $', array_keys($arg_list)) : '') . ');');
}
}
if(!function_exists('smarty_function_html_options_optgroup')) {
function smarty_function_html_options_optgroup() {
$arg_list = func_get_args();
foreach ($arg_list as $k=>$arg) eval ("\$$arg;");
return eval('tpl_function_html_options_optgroup(' . (count($arg_list)>0 ? '$' . implode(', $', array_keys($arg_list)) : '') . ');');
}
}
?>