Unstable release 2.
[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 check_value($name)
93 {
94         if (!isset($_POST[$name]))
95                 return 0;
96         return 1;
97 }
98
99 function check($label, $name, $value, $submit_on_change=false)
100 {
101         if ($label)
102                 echo $label . "  ";
103
104         if ($value == null)
105                 $value = (!isset($_POST[$name]) ? 0 : $_POST[$name]);
106         if ($value == 1)
107                 echo "<input checked type='checkbox' name='$name' value='1' ";
108         else
109                 echo "<input type='checkbox' name='$name' value='1'";
110         if ($submit_on_change)
111                 echo " onclick='this.form.submit();' ";
112         echo " >\n";
113 }
114
115 function check_cells($label, $name, $value, $submit_on_change=false)
116 {
117         if ($label != null)
118                 echo "<td>$label</td>\n";
119         echo "<td>";
120         check(null, $name, $value, $submit_on_change);
121         echo "</td>";
122 }
123
124 function check_row($label, $name, $value, $submit_on_change=false)
125 {
126         echo "<tr>";
127         check_cells($label, $name, $value, $submit_on_change);
128         echo "</tr>\n";
129 }
130
131 //-----------------------------------------------------------------------------------
132
133 function labelheader_cell($label, $params="")
134 {
135         echo "<td class='tableheader' $params>$label</td>\n";
136 }
137
138 function label_cell($label, $params="")
139 {
140         echo "<td $params>$label</td>\n";
141 }
142
143 function amount_cell($label, $bold=false)
144 {
145         if ($bold)
146                 label_cell("<b>".number_format2($label,user_price_dec())."</b>", "nowrap align=right");
147         else
148                 label_cell(number_format2($label,user_price_dec()), "nowrap align=right");
149 }
150
151 function percent_cell($label, $bold=false)
152 {
153         if ($bold)
154                 label_cell("<b>".number_format2($label,user_percent_dec())." %</b>", "nowrap align=right");
155         else
156                 label_cell(number_format2($label,user_percent_dec())." %", "nowrap align=right");
157 }
158
159 function qty_cell($label, $bold=false)
160 {
161         if ($bold)
162                 label_cell("<b>".number_format2($label,user_qty_dec())."</b>", "nowrap align=right");
163         else
164                 label_cell(number_format2($label,user_qty_dec()), "nowrap align=right");
165 }
166
167 function label_cells($label, $value, $params="", $params2="")
168 {
169         if ($label != null)
170                 echo "<td $params>$label</td>\n";
171         echo "<td $params2>$value</td>\n";
172 }
173
174 function label_row($label, $value, $params="", $params2="")
175 {
176         echo "<tr>";
177         label_cells($label, $value, $params, $params2);
178         echo "</tr>\n";
179 }
180
181 //-----------------------------------------------------------------------------------
182
183 function text_cells($label, $name, $value, $size="", $max="", $params="", $post_label="", $disabled="")
184 {
185         if ($label != null)
186                 label_cell($label, $params);
187         echo "<td>";
188
189         if ($value == null)
190                 $value = (!isset($_POST[$name]) ? "" : $_POST[$name]);
191         echo "<input $disabled type=\"text\" name=\"$name\" size=\"$size\" maxlength=\"$max\" value=\"$value\">";
192
193         if ($post_label != "")
194                 echo " " . $post_label;
195
196         echo "</td>\n";
197 }
198
199 function text_cells_ex($label, $name, $size, $max=null, $init=null, $params=null, $post_label=null)
200 {
201         if (!isset($_POST[$name]) || $_POST[$name] == "")
202         {
203                 if ($init)
204                         $_POST[$name] = $init;
205                 else
206                         $_POST[$name] = "";
207         }
208         if ($label != null)
209                 label_cell($label, $params);
210
211         if (!isset($max))
212                 $max = $size;
213
214         echo "<td>";
215
216         echo "<input type=\"text\" name=\"$name\" size=\"$size\" maxlength=\"$max\" value=\"" . $_POST[$name]. "\">";
217
218         if ($post_label)
219                 echo " " . $post_label;
220
221         echo "</td>\n";
222 }
223
224 function text_row($label, $name, $value, $size, $max, $params="", $post_label="")
225 {
226         echo "<tr>";
227
228         text_cells($label, $name, $value, $size, $max, $params, $post_label);
229
230         echo "</tr>\n";
231 }
232
233 //-----------------------------------------------------------------------------------
234
235 function text_row_ex($label, $name, $size, $max=null, $value=null, $params=null, $post_label=null)
236 {
237         echo "<tr>";
238
239         text_cells_ex($label, $name, $size, $max, $value, $params, $post_label);
240
241         echo "</tr>\n";
242 }
243
244 //-----------------------------------------------------------------------------------
245
246 function date_cells($label, $name, $init=null, $inc_days=0, $inc_months=0, $inc_years=0, $params=null)
247 {
248         global $use_date_picker, $path_to_root;
249         if (!isset($_POST[$name]) || $_POST[$name] == "")
250         {
251                 if (!$init)
252                 {
253                         if ($inc_years == 1001)
254                                 $_POST[$name] = null;
255                         else
256                         {
257                                 $dd = Today();
258                                 if ($inc_days != 0)
259                                         $dd = add_days($dd, $inc_days);
260                                 if ($inc_months != 0)
261                                         $dd = add_months($dd, $inc_months);
262                                 if ($inc_years != 0)
263                                         $dd = add_years($dd, $inc_years);
264                                 $_POST[$name] = $dd;
265                         }
266                 }
267                 else
268                         $_POST[$name] = $init;
269         }
270         if ($use_date_picker)
271                 $post_label = "<a href=\"javascript:date_picker(document.forms[0].$name);\">"
272                 . "     <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";
273         else
274                 $post_label = "";
275         text_cells_ex($label, $name, 9, 12, $_POST[$name], $params, $post_label);
276 }
277
278 function date_row($label, $name, $init=null, $inc_days=0, $inc_months=0, $inc_years=0, $params=null)
279 {
280         echo "<tr>";
281         date_cells($label, $name, $init, $inc_days, $inc_months, $inc_years, $params);
282         echo "</tr>\n";
283 }
284
285 //-----------------------------------------------------------------------------------
286
287 function ref_cells($label, $name, $init=null, $params=null)
288 {
289         text_cells_ex($label, $name, 16, 18, $init, $params);
290 }
291
292 //-----------------------------------------------------------------------------------
293
294 function ref_row($label, $name, $init=null)
295 {
296         echo "<tr>";
297         ref_cells($label, $name, $init);
298         echo "</tr>\n";
299 }
300
301 //-----------------------------------------------------------------------------------
302
303 function percent_row($label, $name, $init=null)
304 {
305
306         if (!isset($_POST[$name]) || $_POST[$name]=="")
307         {
308                 if ($init)
309                         $_POST[$name] = $init;
310         }
311
312         text_row($label, $name, $_POST[$name], 6, 6, "", "%");
313 }
314
315 //-----------------------------------------------------------------------------------
316
317 function amount_cells($label, $name, $init=null, $params=null, $post_label=null)
318 {
319         text_cells_ex($label, $name, 15, 15, $init, $params, $post_label);
320 }
321
322 function amount_row($label, $name, $init=null, $params=null, $post_label=null)
323 {
324         echo "<tr>";
325         amount_cells($label, $name, $init, $params, $post_label);
326         echo "</tr>\n";
327 }
328
329 //-----------------------------------------------------------------------------------
330
331 function small_amount_cells($label, $name, $init=null, $params=null, $post_label=null)
332 {
333         text_cells_ex($label, $name, 7, 12, $init, $params, $post_label);
334 }
335
336 //-----------------------------------------------------------------------------------
337
338 function textarea_cells($label, $name, $value, $cols, $rows, $params="")
339 {
340         if ($label != null)
341                 echo "<td $params>$label</td>\n";
342         if ($value == null)
343                 $value = (!isset($_POST[$name]) ? "" : $_POST[$name]);
344         echo "<td><textarea name='$name' cols='$cols' rows='$rows'>$value</textarea></td>\n";
345 }
346
347 function textarea_row($label, $name, $value, $cols, $rows, $params="")
348 {
349         echo "<tr>";
350         textarea_cells($label, $name, $value, $cols, $rows, $params);
351         echo "</tr>\n";
352 }
353
354 //-----------------------------------------------------------------------------------
355
356 function text_row_with_submit($label, $name, $value, $size, $max, $input_name, $input_value)
357 {
358         echo "<tr><td>$label</td>\n";
359         echo "<td>";
360
361         if ($value == null)
362                 $value = (!isset($_POST[$name]) ? "" : $_POST[$name]);
363         echo "<input type=\"text\" name=\"$name\" size=\"$size\" maxlength=\"$max\" value=\"$value\">   ";
364
365         submit($input_name, $input_value);
366
367         echo "</td></tr>\n";
368 }
369
370 //-----------------------------------------------------------------------------------
371
372
373 ?>