1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* javascript_include_tag |
5
|
|
|
* @param string $src |
6
|
|
|
* @return string |
7
|
|
|
*/ |
8
|
|
|
function javascript_include_tag($src){ |
9
|
|
|
return "<script type='text/javascript' src='".PUBLIC_PATH."js/$src.js'></script>\r\n"; |
10
|
|
|
} |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* stylesheet_link |
14
|
|
|
* @param string $src |
15
|
|
|
* @return string |
16
|
|
|
*/ |
17
|
|
|
function stylesheet_link($src=''){ |
18
|
|
|
return "<link rel='stylesheet' type='text/css' href='".PUBLIC_PATH."css/$src.css'/>\r\n"; |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* link_to |
23
|
|
|
* @param string $action |
24
|
|
|
* @param string $text |
25
|
|
|
* @param string $attributes |
26
|
|
|
* @return string |
27
|
|
|
*/ |
28
|
|
|
function link_to($action, $text, $attributes=''){ |
29
|
|
|
return "<a href='".PUBLIC_PATH."$action' $attributes>$text</a>"; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* img_tag |
34
|
|
|
* @param string $img |
35
|
|
|
* @param string $attributes |
36
|
|
|
* @return string |
37
|
|
|
*/ |
38
|
|
|
function img_tag($img, $attributes=''){ |
39
|
|
|
return "<img src='".PUBLIC_PATH."img/$img' $attributes />\r\n"; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* form_tag |
44
|
|
|
* @param string $action |
45
|
|
|
* @param string $attributes |
46
|
|
|
* @return string |
47
|
|
|
*/ |
48
|
|
|
function form_tag($action, $attributes=''){ |
49
|
|
|
return "<form action='".PUBLIC_PATH."$action' $attributes>\r\n"; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* end_form_tag |
54
|
|
|
* @return string |
55
|
|
|
*/ |
56
|
|
|
function end_form_tag(){ |
57
|
|
|
return "</form>\r\n"; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* submit_tag |
62
|
|
|
* @param string $caption |
63
|
|
|
* @param string $attributes |
64
|
|
|
* @return string |
65
|
|
|
*/ |
66
|
|
|
function submit_tag($caption, $attributes=''){ |
67
|
|
|
return "<input type='submit' value='$caption' $attributes />\r\n"; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* button_tag |
72
|
|
|
* @param string $caption |
73
|
|
|
* @param string $type |
74
|
|
|
* @param string $attributes |
75
|
|
|
* @return string |
76
|
|
|
*/ |
77
|
|
|
function button_tag($caption, $type='button', $attributes=''){ |
78
|
|
|
return "<button type='$type' $attributes>$caption</button>\r\n"; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* get_field_name_and_id |
83
|
|
|
* @param string $name |
84
|
|
|
* @return array |
85
|
|
|
*/ |
86
|
|
|
function get_field_name_and_id($name) |
87
|
|
|
{ |
88
|
|
|
$id=""; |
89
|
|
|
if (strpos($name, ".") != false) { |
|
|
|
|
90
|
|
|
$items = explode(".", $name); |
91
|
|
|
$id=" id='{$items[0]}_{$items[1]}' "; |
92
|
|
|
$name = $items[0]."[".$items[1]."]"; |
93
|
|
|
} |
94
|
|
|
return [$id, $name]; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* text_field_tag |
99
|
|
|
* @param string $name |
100
|
|
|
* @param string $value |
101
|
|
|
* @param string $attributes |
102
|
|
|
* @return string |
103
|
|
|
*/ |
104
|
|
|
function text_field_tag($name, $value='', $attributes=''){ |
105
|
|
|
list($id, $name) = get_field_name_and_id($name); |
106
|
|
|
|
107
|
|
|
return "<input type='text' name='$name' $id value='$value' $attributes />\r\n"; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* password_field_tag |
112
|
|
|
* @param string $name |
113
|
|
|
* @param string $value |
114
|
|
|
* @param string $attributes |
115
|
|
|
* @return string |
116
|
|
|
*/ |
117
|
|
|
function password_field_tag($name, $value='', $attributes=''){ |
118
|
|
|
list($id, $name) = get_field_name_and_id($name); |
119
|
|
|
|
120
|
|
|
return "<input type='password' name='$name' $id value='$value' $attributes />\r\n"; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* text_area_tag |
125
|
|
|
* @param string $name |
126
|
|
|
* @param string $value |
127
|
|
|
* @param string $attributes |
128
|
|
|
* @return string |
129
|
|
|
*/ |
130
|
|
|
function text_area_tag($name, $value='', $attributes=''){ |
131
|
|
|
list($id, $name) = get_field_name_and_id($name); |
132
|
|
|
|
133
|
|
|
return "<textarea name='$name' $id $attributes>$value</textarea>\r\n"; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* hidden_field_tag |
138
|
|
|
* @param string $name |
139
|
|
|
* @param string $value |
140
|
|
|
* @param string $attributes |
141
|
|
|
* @return string |
142
|
|
|
*/ |
143
|
|
|
function hidden_field_tag($name, $value='', $attributes=''){ |
144
|
|
|
list($id, $name) = get_field_name_and_id($name); |
145
|
|
|
|
146
|
|
|
return "<input type='hidden' name='$name' $id value='$value' $attributes />\r\n"; |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* check_box_tag |
151
|
|
|
* @param string $name |
152
|
|
|
* @param string $value |
153
|
|
|
* @param string $text |
154
|
|
|
* @param bool $checked |
155
|
|
|
* @param string $attributes |
156
|
|
|
* @return string |
157
|
|
|
*/ |
158
|
|
|
function check_box_tag($name, $value, $text, $checked=false, $attributes=''){ |
|
|
|
|
159
|
|
|
list($id, $name) = get_field_name_and_id($name); |
160
|
|
|
$checked = $checked == true ? ' checked ' : ''; |
|
|
|
|
161
|
|
|
return "<input type='checkbox' $id name='$name' $checked $attributes value='$value'/>\r\n"; |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* radio_button_tag |
166
|
|
|
* @param string $name |
167
|
|
|
* @param string $value |
168
|
|
|
* @param bool $checked |
169
|
|
|
* @param string $attributes |
170
|
|
|
* @return string |
171
|
|
|
*/ |
172
|
|
|
function radio_button_tag($name, $value, $checked=false, $attributes=''){ |
173
|
|
|
list($id, $name) = get_field_name_and_id($name); |
174
|
|
|
$checked = $checked == true ? ' checked ' : ''; |
|
|
|
|
175
|
|
|
return "<input type='radio' $id name='$name' $checked $attributes value='$value'/>\r\n"; |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* label_tag |
180
|
|
|
* @param string $field |
181
|
|
|
* @param string $caption |
182
|
|
|
* @param string $attributes |
183
|
|
|
* @return string |
184
|
|
|
*/ |
185
|
|
|
function label_tag($field, $caption, $attributes='') { |
186
|
|
|
return "<label for='$field' $attributes>$caption</label>\r\n"; |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
/** |
190
|
|
|
* select_tag |
191
|
|
|
* @param string $name |
192
|
|
|
* @param string $options |
193
|
|
|
* @param bool $include_blank |
194
|
|
|
* @param string $attributes |
195
|
|
|
* @return string |
196
|
|
|
*/ |
197
|
|
|
function select_tag($name, $options='', $include_blank=false, $attributes=''){ |
198
|
|
|
list($id, $name) = get_field_name_and_id($name); |
199
|
|
|
|
200
|
|
|
$code = ""; |
201
|
|
|
if ($include_blank != false) { |
|
|
|
|
202
|
|
|
$code="<option value=''>$include_blank</option>\r\n"; |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
return "<select $id name='$name' $attributes>\r\n$code$options</select>\r\n"; |
206
|
|
|
|
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
/** |
210
|
|
|
* options_for_dbselect |
211
|
|
|
* @param array $data |
212
|
|
|
* @param string $show |
213
|
|
|
* @param string $value |
214
|
|
|
* @param string $selected |
215
|
|
|
* @return string |
216
|
|
|
*/ |
217
|
|
|
function options_for_dbselect($data, $show, $value, $selected='') |
218
|
|
|
{ |
219
|
|
|
$code=""; |
220
|
|
|
foreach($data as $item) { |
221
|
|
|
$selected_tag=""; |
222
|
|
|
if ($selected == $item[$value]){ |
223
|
|
|
$selected_tag = " selected='selected' "; |
224
|
|
|
} |
225
|
|
|
$code.="<option value='{$item[$value]}' $selected_tag>{$item[$show]}</option>\r\n"; |
226
|
|
|
} |
227
|
|
|
return $code; |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
/** |
231
|
|
|
* options_for_select |
232
|
|
|
* @param array $data |
233
|
|
|
* @param string $selected |
234
|
|
|
* @return string |
235
|
|
|
*/ |
236
|
|
|
function options_for_select($data, $selected='') |
237
|
|
|
{ |
238
|
|
|
$code=""; |
239
|
|
|
foreach($data as $key => $value) { |
240
|
|
|
$selected_tag=""; |
241
|
|
|
if ($selected == $value){ |
242
|
|
|
$selected_tag = " selected='selected' "; |
243
|
|
|
} |
244
|
|
|
$code.="<option value='$key' $selected_tag>$value</option>\r\n"; |
245
|
|
|
} |
246
|
|
|
return $code; |
247
|
|
|
} |
248
|
|
|
|
249
|
|
|
/** |
250
|
|
|
* js_redirect_to |
251
|
|
|
* @param string $action |
252
|
|
|
* @param float $seconds |
253
|
|
|
* @return string |
254
|
|
|
*/ |
255
|
|
|
function js_redirect_to($action, $seconds = 0.01){ |
256
|
|
|
$seconds*=1000; |
257
|
|
|
return "<script type=\"text/javascript\">setTimeout('window.location=\"?/$action\"', $seconds)</script>"; |
258
|
|
|
} |
259
|
|
|
|
260
|
|
|
/** |
261
|
|
|
* button_to_action |
262
|
|
|
* @param string $caption |
263
|
|
|
* @param string $action |
264
|
|
|
* @param string $attributes |
265
|
|
|
* @return string |
266
|
|
|
*/ |
267
|
|
|
function button_to_action($caption, $action, $attributes=''){ |
268
|
|
|
return "<button type='button' $attributes onclick='window.location=\"".PUBLIC_PATH."$action\"'>$caption</button>"; |
269
|
|
|
} |
270
|
|
|
|