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