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