Added 2 functions in ui_input.inc, button and button_cell
[fa-stable.git] / includes / ui / ui_input.inc
1 <?php
2
3 //---------------------------------------------------------------------------------
4
5 function hidden($name, $value)
6 {
7         echo "<input type=\"hidden\" name=\"$name\" value=\"$value\">\n";
8 }
9
10 //---------------------------------------------------------------------------------
11
12 function submit($name, $value, $echo=true)
13 {
14         $submit_str = "<input type=\"submit\" class=\"inputsubmit\" name=\"$name\" value=\"$value\">\n";
15         if ($echo)
16                 echo $submit_str;
17         else
18                 return $submit_str;
19 }
20
21 function submit_center($name, $value, $echo=true)
22 {
23         echo "<center>";
24         submit($name, $value, $echo);
25         echo "</center>";
26 }
27
28 function submit_center_first($name, $value)
29 {
30         echo "<center>";
31         submit($name, $value);
32         echo "&nbsp;";
33 }
34
35 function submit_center_last($name, $value)
36 {
37         echo "&nbsp;";
38         submit($name, $value);
39         echo "</center>";
40 }
41
42 function submit_add_or_update($add=true)
43 {
44         if ($add)
45                 submit('ADD_ITEM', _("Save"));
46         else
47                 submit('UPDATE_ITEM', _("Update"));
48 }
49
50 function submit_add_or_update_center($add=true)
51 {
52         echo "<center>";
53         submit_add_or_update($add);
54         echo "</center>";
55 }
56
57 /*
58 function submit_add_or_update_row($add=true)
59 {
60         echo "<tr><td colspan=99 align=center>";
61         submit_add_or_update($add);
62         echo "</td></tr>\n";
63 }
64 */
65 function submit_add_or_update_row($add=true, $right=true, $extra="")
66 {
67         echo "<tr>";
68         if ($right)
69                 echo "<td>&nbsp;</td>\n";
70         echo "<td $extra>";
71         submit_add_or_update($add);
72         echo "</td></tr>\n";
73 }
74
75 function submit_cells($name, $value, $extra="")
76 {
77         echo "<td $extra>";
78         submit($name, $value);
79         echo "</td>\n";
80 }
81
82 function submit_row($name, $value, $right=true, $extra="")
83 {
84         echo "<tr>";
85         if ($right)
86                 echo "<td>&nbsp;</td>\n";
87         submit_cells($name, $value, $extra);
88         echo "</tr>\n";
89 }
90 //---------------------------------------------------------------------------------
91
92 function button($name, $value, $onclick)
93 {
94         echo "<input type=\"button\" class=\"inputsubmit\" name=\"$name\" value=\"$value\" onclick=\"$onclick\" />\n";
95 }
96
97 function button_cell($name, $value, $onclick)
98 {
99         echo "<td>";
100         button($name, $value, $onclick);
101         echo "</td>\n";
102 }
103
104 //-----------------------------------------------------------------------------------
105
106 function check_value($name)
107 {
108         if (!isset($_POST[$name]))
109                 return 0;
110         return 1;
111 }
112
113 function check($label, $name, $value, $submit_on_change=false)
114 {
115         if ($label)
116                 echo $label . "  ";
117
118         if ($value == null)
119                 $value = (!isset($_POST[$name]) ? 0 : $_POST[$name]);
120         if ($value == 1)
121                 echo "<input checked type='checkbox' name='$name' value='1' ";
122         else
123                 echo "<input type='checkbox' name='$name' value='1'";
124         if ($submit_on_change)
125                 echo " onclick='this.form.submit();' ";
126         echo " >\n";
127 }
128
129 function check_cells($label, $name, $value, $submit_on_change=false)
130 {
131         if ($label != null)
132                 echo "<td>$label</td>\n";
133         echo "<td>";
134         check(null, $name, $value, $submit_on_change);
135         echo "</td>";
136 }
137
138 function check_row($label, $name, $value, $submit_on_change=false)
139 {
140         echo "<tr>";
141         check_cells($label, $name, $value, $submit_on_change);
142         echo "</tr>\n";
143 }
144
145 //-----------------------------------------------------------------------------------
146
147 function labelheader_cell($label, $params="")
148 {
149         echo "<td class='tableheader' $params>$label</td>\n";
150 }
151
152 function label_cell($label, $params="")
153 {
154         echo "<td $params>$label</td>\n";
155 }
156
157 function amount_cell($label, $bold=false)
158 {
159         if ($bold)
160                 label_cell("<b>".number_format2($label,user_price_dec())."</b>", "nowrap align=right");
161         else
162                 label_cell(number_format2($label,user_price_dec()), "nowrap align=right");
163 }
164
165 function percent_cell($label, $bold=false)
166 {
167         if ($bold)
168                 label_cell("<b>".number_format2($label,user_percent_dec())." %</b>", "nowrap align=right");
169         else
170                 label_cell(number_format2($label,user_percent_dec())." %", "nowrap align=right");
171 }
172
173 function qty_cell($label, $bold=false)
174 {
175         if ($bold)
176                 label_cell("<b>".number_format2($label,user_qty_dec())."</b>", "nowrap align=right");
177         else
178                 label_cell(number_format2($label,user_qty_dec()), "nowrap align=right");
179 }
180
181 function label_cells($label, $value, $params="", $params2="")
182 {
183         if ($label != null)
184                 echo "<td $params>$label</td>\n";
185         echo "<td $params2>$value</td>\n";
186 }
187
188 function label_row($label, $value, $params="", $params2="")
189 {
190         echo "<tr>";
191         label_cells($label, $value, $params, $params2);
192         echo "</tr>\n";
193 }
194
195 //-----------------------------------------------------------------------------------
196
197 function text_cells($label, $name, $value, $size="", $max="", $params="", $post_label="", $disabled="")
198 {
199         if ($label != null)
200                 label_cell($label, $params);
201         echo "<td>";
202
203         if ($value == null)
204                 $value = (!isset($_POST[$name]) ? "" : $_POST[$name]);
205         echo "<input $disabled type=\"text\" name=\"$name\" size=\"$size\" maxlength=\"$max\" value=\"$value\">";
206
207         if ($post_label != "")
208                 echo " " . $post_label;
209
210         echo "</td>\n";
211 }
212
213 function text_cells_ex($label, $name, $size, $max=null, $init=null, $params=null, $post_label=null)
214 {
215         if (!isset($_POST[$name]) || $_POST[$name] == "")
216         {
217                 if ($init)
218                         $_POST[$name] = $init;
219                 else
220                         $_POST[$name] = "";
221         }
222         if ($label != null)
223                 label_cell($label, $params);
224
225         if (!isset($max))
226                 $max = $size;
227
228         echo "<td>";
229
230         echo "<input type=\"text\" name=\"$name\" size=\"$size\" maxlength=\"$max\" value=\"" . $_POST[$name]. "\">";
231
232         if ($post_label)
233                 echo " " . $post_label;
234
235         echo "</td>\n";
236 }
237
238 function text_row($label, $name, $value, $size, $max, $params="", $post_label="")
239 {
240         echo "<tr>";
241
242         text_cells($label, $name, $value, $size, $max, $params, $post_label);
243
244         echo "</tr>\n";
245 }
246
247 //-----------------------------------------------------------------------------------
248
249 function text_row_ex($label, $name, $size, $max=null, $value=null, $params=null, $post_label=null)
250 {
251         echo "<tr>";
252
253         text_cells_ex($label, $name, $size, $max, $value, $params, $post_label);
254
255         echo "</tr>\n";
256 }
257
258 //-----------------------------------------------------------------------------------
259
260 function date_cells($label, $name, $init=null, $inc_days=0, $inc_months=0, $inc_years=0, $params=null)
261 {
262         global $use_date_picker, $path_to_root;
263         if (!isset($_POST[$name]) || $_POST[$name] == "")
264         {
265                 if (!$init)
266                 {
267                         if ($inc_years == 1001)
268                                 $_POST[$name] = null;
269                         else
270                         {
271                                 $dd = Today();
272                                 if ($inc_days != 0)
273                                         $dd = add_days($dd, $inc_days);
274                                 if ($inc_months != 0)
275                                         $dd = add_months($dd, $inc_months);
276                                 if ($inc_years != 0)
277                                         $dd = add_years($dd, $inc_years);
278                                 $_POST[$name] = $dd;
279                         }
280                 }
281                 else
282                         $_POST[$name] = $init;
283         }
284         if ($use_date_picker)
285                 $post_label = "<a href=\"javascript:date_picker(document.forms[0].$name);\">"
286                 . "     <img src='$path_to_root/themes/default/images/cal.gif' width='16' height='16' border='0' alt='"._('Click Here to Pick up the date')."'></a>\n";
287         else
288                 $post_label = "";
289         text_cells_ex($label, $name, 9, 12, $_POST[$name], $params, $post_label);
290 }
291
292 function date_row($label, $name, $init=null, $inc_days=0, $inc_months=0, $inc_years=0, $params=null)
293 {
294         echo "<tr>";
295         date_cells($label, $name, $init, $inc_days, $inc_months, $inc_years, $params);
296         echo "</tr>\n";
297 }
298
299 //-----------------------------------------------------------------------------------
300
301 function ref_cells($label, $name, $init=null, $params=null)
302 {
303         text_cells_ex($label, $name, 16, 18, $init, $params);
304 }
305
306 //-----------------------------------------------------------------------------------
307
308 function ref_row($label, $name, $init=null)
309 {
310         echo "<tr>";
311         ref_cells($label, $name, $init);
312         echo "</tr>\n";
313 }
314
315 //-----------------------------------------------------------------------------------
316
317 function percent_row($label, $name, $init=null)
318 {
319
320         if (!isset($_POST[$name]) || $_POST[$name]=="")
321         {
322                 if ($init)
323                         $_POST[$name] = $init;
324         }
325
326         text_row($label, $name, $_POST[$name], 6, 6, "", "%");
327 }
328
329 //-----------------------------------------------------------------------------------
330
331 function amount_cells($label, $name, $init=null, $params=null, $post_label=null)
332 {
333         text_cells_ex($label, $name, 15, 15, $init, $params, $post_label);
334 }
335
336 function amount_row($label, $name, $init=null, $params=null, $post_label=null)
337 {
338         echo "<tr>";
339         amount_cells($label, $name, $init, $params, $post_label);
340         echo "</tr>\n";
341 }
342
343 //-----------------------------------------------------------------------------------
344
345 function small_amount_cells($label, $name, $init=null, $params=null, $post_label=null)
346 {
347         text_cells_ex($label, $name, 7, 12, $init, $params, $post_label);
348 }
349
350 //-----------------------------------------------------------------------------------
351
352 function textarea_cells($label, $name, $value, $cols, $rows, $params="")
353 {
354         if ($label != null)
355                 echo "<td $params>$label</td>\n";
356         if ($value == null)
357                 $value = (!isset($_POST[$name]) ? "" : $_POST[$name]);
358         echo "<td><textarea name='$name' cols='$cols' rows='$rows'>$value</textarea></td>\n";
359 }
360
361 function textarea_row($label, $name, $value, $cols, $rows, $params="")
362 {
363         echo "<tr>";
364         textarea_cells($label, $name, $value, $cols, $rows, $params);
365         echo "</tr>\n";
366 }
367
368 //-----------------------------------------------------------------------------------
369
370 function text_row_with_submit($label, $name, $value, $size, $max, $input_name, $input_value)
371 {
372         echo "<tr><td>$label</td>\n";
373         echo "<td>";
374
375         if ($value == null)
376                 $value = (!isset($_POST[$name]) ? "" : $_POST[$name]);
377         echo "<input type=\"text\" name=\"$name\" size=\"$size\" maxlength=\"$max\" value=\"$value\">   ";
378
379         submit($input_name, $input_value);
380
381         echo "</td></tr>\n";
382 }
383
384 //-----------------------------------------------------------------------------------
385
386
387 ?>