Final rewriting of sales module
[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="", $leftfill=0)
189 {
190         echo "<tr>";
191         label_cells($label, $value, $params, $params2);
192         if($leftfill!=0)
193           echo "<td colspan=$leftfill></td>";
194         echo "</tr>\n";
195 }
196
197 //-----------------------------------------------------------------------------------
198
199 function text_cells($label, $name, $value, $size="", $max="", $params="", $post_label="", $disabled="")
200 {
201         if ($label != null)
202                 label_cell($label, $params);
203         echo "<td>";
204
205         if ($value == null)
206                 $value = (!isset($_POST[$name]) ? "" : $_POST[$name]);
207         echo "<input $disabled type=\"text\" name=\"$name\" size=\"$size\" maxlength=\"$max\" value=\"$value\">";
208
209         if ($post_label != "")
210                 echo " " . $post_label;
211
212         echo "</td>\n";
213 }
214
215 function text_cells_ex($label, $name, $size, $max=null, $init=null, $params=null, $post_label=null)
216 {
217         if (!isset($_POST[$name]) || $_POST[$name] == "")
218         {
219                 if ($init)
220                         $_POST[$name] = $init;
221                 else
222                         $_POST[$name] = "";
223         }
224         if ($label != null)
225                 label_cell($label, $params);
226
227         if (!isset($max))
228                 $max = $size;
229
230         echo "<td>";
231
232         echo "<input type=\"text\" name=\"$name\" size=\"$size\" maxlength=\"$max\" value=\"" . $_POST[$name]. "\">";
233
234         if ($post_label)
235                 echo " " . $post_label;
236
237         echo "</td>\n";
238 }
239
240 function text_row($label, $name, $value, $size, $max, $params="", $post_label="")
241 {
242         echo "<tr>";
243
244         text_cells($label, $name, $value, $size, $max, $params, $post_label);
245
246         echo "</tr>\n";
247 }
248
249 //-----------------------------------------------------------------------------------
250
251 function text_row_ex($label, $name, $size, $max=null, $value=null, $params=null, $post_label=null)
252 {
253         echo "<tr>";
254
255         text_cells_ex($label, $name, $size, $max, $value, $params, $post_label);
256
257         echo "</tr>\n";
258 }
259
260 //-----------------------------------------------------------------------------------
261
262 function date_cells($label, $name, $init=null, $inc_days=0, $inc_months=0, $inc_years=0, $params=null)
263 {
264         global $use_date_picker, $path_to_root;
265         if (!isset($_POST[$name]) || $_POST[$name] == "")
266         {
267                 if (!$init)
268                 {
269                         if ($inc_years == 1001)
270                                 $_POST[$name] = null;
271                         else
272                         {
273                                 $dd = Today();
274                                 if ($inc_days != 0)
275                                         $dd = add_days($dd, $inc_days);
276                                 if ($inc_months != 0)
277                                         $dd = add_months($dd, $inc_months);
278                                 if ($inc_years != 0)
279                                         $dd = add_years($dd, $inc_years);
280                                 $_POST[$name] = $dd;
281                         }
282                 }
283                 else
284                         $_POST[$name] = $init;
285         }
286         if ($use_date_picker)
287                 $post_label = "<a href=\"javascript:date_picker(document.forms[0].$name);\">"
288                 . "     <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";
289         else
290                 $post_label = "";
291         text_cells_ex($label, $name, 9, 12, $_POST[$name], $params, $post_label);
292 }
293
294 function date_row($label, $name, $init=null, $inc_days=0, $inc_months=0, $inc_years=0, $params=null)
295 {
296         echo "<tr>";
297         date_cells($label, $name, $init, $inc_days, $inc_months, $inc_years, $params);
298         echo "</tr>\n";
299 }
300
301 //-----------------------------------------------------------------------------------
302
303 function ref_cells($label, $name, $init=null, $params=null)
304 {
305         text_cells_ex($label, $name, 16, 18, $init, $params);
306 }
307
308 //-----------------------------------------------------------------------------------
309
310 function ref_row($label, $name, $init=null)
311 {
312         echo "<tr>";
313         ref_cells($label, $name, $init);
314         echo "</tr>\n";
315 }
316
317 //-----------------------------------------------------------------------------------
318
319 function percent_row($label, $name, $init=null)
320 {
321
322         if (!isset($_POST[$name]) || $_POST[$name]=="")
323         {
324                         $_POST[$name] = $init== null ? '' : $init;
325         }
326
327         text_row($label, $name, $_POST[$name], 6, 6, "", "%");
328 }
329
330 //-----------------------------------------------------------------------------------
331
332 function amount_cells($label, $name, $init=null, $params=null, $post_label=null)
333 {
334         text_cells_ex($label, $name, 15, 15, $init, $params, $post_label);
335 }
336
337 function amount_row($label, $name, $init=null, $params=null, $post_label=null)
338 {
339         echo "<tr>";
340         amount_cells($label, $name, $init, $params, $post_label);
341         echo "</tr>\n";
342 }
343
344 //-----------------------------------------------------------------------------------
345
346 function small_amount_cells($label, $name, $init=null, $params=null, $post_label=null)
347 {
348         text_cells_ex($label, $name, 7, 12, $init, $params, $post_label);
349 }
350
351 //-----------------------------------------------------------------------------------
352
353 function textarea_cells($label, $name, $value, $cols, $rows, $params="")
354 {
355         if ($label != null)
356                 echo "<td $params>$label</td>\n";
357         if ($value == null)
358                 $value = (!isset($_POST[$name]) ? "" : $_POST[$name]);
359         echo "<td><textarea name='$name' cols='$cols' rows='$rows'>$value</textarea></td>\n";
360 }
361
362 function textarea_row($label, $name, $value, $cols, $rows, $params="")
363 {
364         echo "<tr>";
365         textarea_cells($label, $name, $value, $cols, $rows, $params);
366         echo "</tr>\n";
367 }
368
369 //-----------------------------------------------------------------------------------
370
371 function text_row_with_submit($label, $name, $value, $size, $max, $input_name, $input_value)
372 {
373         echo "<tr><td>$label</td>\n";
374         echo "<td>";
375
376         if ($value == null)
377                 $value = (!isset($_POST[$name]) ? "" : $_POST[$name]);
378         echo "<input type=\"text\" name=\"$name\" size=\"$size\" maxlength=\"$max\" value=\"$value\">   ";
379
380         submit($input_name, $input_value);
381
382         echo "</td></tr>\n";
383 }
384
385 //-----------------------------------------------------------------------------------
386
387
388 ?>