aab5fd18c5d3873ea564282878d5de6060f26b41
[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>".number_format2($label,user_price_dec())."</b>", "nowrap align=right");
168         else
169                 label_cell(number_format2($label,user_price_dec()), "nowrap align=right");
170 }
171
172 function percent_cell($label, $bold=false)
173 {
174         if ($bold)
175                 label_cell("<b>".number_format2($label,user_percent_dec())."</b>", "nowrap align=right");
176         else
177                 label_cell(number_format2($label,user_percent_dec()), "nowrap align=right");
178 }
179
180 function qty_cell($label, $bold=false)
181 {
182         if ($bold)
183                 label_cell("<b>".number_format2($label,user_qty_dec())."</b>", "nowrap align=right");
184         else
185                 label_cell(number_format2($label,user_qty_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, "%");
335 }
336
337 function amount_cells_ex($label, $name, $size, $max=null, $init=null, $params=null, $post_label=null)
338 {
339         if (!isset($_POST[$name]) || $_POST[$name] == "")
340         {
341                 if ($init)
342                         $_POST[$name] = $init;
343                 else
344                         $_POST[$name] = '';
345         }
346         if ($label != null)
347                 label_cell($label, $params);
348
349         if (!isset($max))
350                 $max = $size;
351
352         echo "<td>";
353
354         echo "<input class='amount' type=\"text\" name=\"$name\" size=\"$size\" maxlength=\"$max\" value=\"" . $_POST[$name]. "\">";
355
356         if ($post_label)
357                 echo " " . $post_label;
358
359         echo "</td>\n";
360 }
361
362
363 //-----------------------------------------------------------------------------------
364
365 function amount_cells($label, $name, $init=null, $params=null, $post_label=null)
366 {
367         amount_cells_ex($label, $name, 15, 15, $init, $params, $post_label);
368 }
369
370 function amount_row($label, $name, $init=null, $params=null, $post_label=null)
371 {
372         echo "<tr>";
373         amount_cells($label, $name, $init, $params, $post_label);
374         echo "</tr>\n";
375 }
376
377 function small_amount_row($label, $name, $init=null, $params=null, $post_label=null)
378 {
379         echo "<tr>";
380         small_amount_cells($label, $name, $init, $params, $post_label);
381         echo "</tr>\n";
382 }
383
384 //-----------------------------------------------------------------------------------
385
386 function small_amount_cells($label, $name, $init=null, $params=null, $post_label=null)
387 {
388         amount_cells_ex($label, $name, 7, 12, $init, $params, $post_label);
389 }
390
391 //-----------------------------------------------------------------------------------
392
393 function textarea_cells($label, $name, $value, $cols, $rows, $params="")
394 {
395         if ($label != null)
396                 echo "<td $params>$label</td>\n";
397         if ($value == null)
398                 $value = (!isset($_POST[$name]) ? "" : $_POST[$name]);
399         echo "<td><textarea name='$name' cols='$cols' rows='$rows'>$value</textarea></td>\n";
400 }
401
402 function textarea_row($label, $name, $value, $cols, $rows, $params="")
403 {
404         echo "<tr>";
405         textarea_cells($label, $name, $value, $cols, $rows, $params);
406         echo "</tr>\n";
407 }
408
409 //-----------------------------------------------------------------------------------
410
411 function text_row_with_submit($label, $name, $value, $size, $max, $input_name, $input_value)
412 {
413         echo "<tr><td>$label</td>\n";
414         echo "<td>";
415
416         if ($value == null)
417                 $value = (!isset($_POST[$name]) ? "" : $_POST[$name]);
418         echo "<input type=\"text\" name=\"$name\" size=\"$size\" maxlength=\"$max\" value=\"$value\">   ";
419
420         submit($input_name, $input_value);
421
422         echo "</td></tr>\n";
423 }
424
425 //-----------------------------------------------------------------------------------
426
427
428 ?>