Release 1.0.1 established on SourceForge, fixing the bugs and including a Date Picker...
[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 qty_cell($label, $bold=false)
152 {
153         if ($bold)
154                 label_cell("<b>".number_format2($label,user_qty_dec())."</b>", "nowrap align=right");
155         else    
156                 label_cell(number_format2($label,user_qty_dec()), "nowrap align=right");
157 }
158
159 function label_cells($label, $value, $params="", $params2="")
160 {
161         if ($label != null)
162                 echo "<td $params>$label</td>\n";
163         echo "<td $params2>$value</td>\n";
164 }
165
166 function label_row($label, $value, $params="", $params2="")
167 {
168         echo "<tr>";
169         label_cells($label, $value, $params, $params2);
170         echo "</tr>\n";
171 }
172
173 //-----------------------------------------------------------------------------------
174
175 function text_cells($label, $name, $value, $size="", $max="", $params="", $post_label="", $disabled="")
176 {
177         if ($label != null)
178                 label_cell($label, $params);
179         echo "<td>";
180
181         if ($value == null)
182                 $value = (!isset($_POST[$name]) ? "" : $_POST[$name]);
183         echo "<input $disabled type=\"text\" name=\"$name\" size=\"$size\" maxlength=\"$max\" value=\"$value\">";
184
185         if ($post_label != "")
186                 echo " " . $post_label;
187
188         echo "</td>\n";
189 }
190
191 function text_cells_ex($label, $name, $size, $max=null, $init=null, $params=null, $post_label=null)
192 {
193         if (!isset($_POST[$name]) || $_POST[$name] == "") 
194         {
195                 if ($init)
196                         $_POST[$name] = $init;
197                 else
198                         $_POST[$name] = "";
199         }
200         if ($label != null)
201                 label_cell($label, $params);
202
203         if (!isset($max))
204                 $max = $size;
205
206         echo "<td>";
207
208         echo "<input type=\"text\" name=\"$name\" size=\"$size\" maxlength=\"$max\" value=\"" . $_POST[$name]. "\">";
209
210         if ($post_label)
211                 echo " " . $post_label;
212
213         echo "</td>\n";
214 }
215
216 function text_row($label, $name, $value, $size, $max, $params="", $post_label="")
217 {
218         echo "<tr>";
219
220         text_cells($label, $name, $value, $size, $max, $params, $post_label);
221
222         echo "</tr>\n";
223 }
224
225 //-----------------------------------------------------------------------------------
226
227 function text_row_ex($label, $name, $size, $max=null, $value=null, $params=null, $post_label=null)
228 {
229         echo "<tr>";
230
231         text_cells_ex($label, $name, $size, $max, $value, $params, $post_label);
232
233         echo "</tr>\n";
234 }
235
236 //-----------------------------------------------------------------------------------
237
238 function date_cells($label, $name, $init=null, $inc_days=0, $inc_months=0, $inc_years=0, $params=null)
239 {
240         global $use_date_picker, $path_to_root;
241         if (!isset($_POST[$name]) || $_POST[$name] == "") 
242         {
243                 if (!$init)
244                 {
245                         if ($inc_days == 1001)
246                                 $_POST[$name] = null;
247                         else    
248                                 $_POST[$name] = date(user_date_display(), Mktime(0,0,0,date("m") + $inc_months,date("d") + $inc_days,date("Y") + $inc_years));
249                 }               
250                 else
251                         $_POST[$name] = $init;
252         }
253         if ($use_date_picker)
254                 $post_label = "<a href=\"javascript:date_picker('document.forms[0].$name', document.forms[0].$name.value);\">"
255                 . "     <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";
256         else
257                 $post_label = "";
258         text_cells_ex($label, $name, 9, 12, $_POST[$name], $params, $post_label);
259 }
260
261 function date_row($label, $name, $init=null, $inc_days=0, $inc_months=0, $inc_years=0, $params=null)
262 {
263         echo "<tr>";
264         date_cells($label, $name, $init, $inc_days, $inc_months, $inc_years, $params);
265         echo "</tr>\n";
266 }
267
268 //-----------------------------------------------------------------------------------
269
270 function ref_cells($label, $name, $init=null, $params=null)
271 {
272         text_cells_ex($label, $name, 16, 18, $init, $params);
273 }
274
275 //-----------------------------------------------------------------------------------
276
277 function ref_row($label, $name, $init=null)
278 {
279         echo "<tr>";
280         ref_cells($label, $name, $init);
281         echo "</tr>\n";
282 }
283
284 //-----------------------------------------------------------------------------------
285
286 function percent_row($label, $name, $init=null)
287 {
288
289         if (!isset($_POST[$name]) || $_POST[$name]=="") 
290         {
291                 if ($init)
292                         $_POST[$name] = $init;
293         }
294
295         text_row($label, $name, $_POST[$name], 6, 6, "", "%");
296 }
297
298 //-----------------------------------------------------------------------------------
299
300 function amount_cells($label, $name, $init=null, $params=null, $post_label=null)
301 {
302         text_cells_ex($label, $name, 15, 15, $init, $params, $post_label);
303 }
304
305 function amount_row($label, $name, $init=null, $params=null, $post_label=null)
306 {
307         echo "<tr>";
308         amount_cells($label, $name, $init, $params, $post_label);
309         echo "</tr>\n";
310 }
311
312 //-----------------------------------------------------------------------------------
313
314 function small_amount_cells($label, $name, $init=null, $params=null, $post_label=null)
315 {
316         text_cells_ex($label, $name, 7, 12, $init, $params, $post_label);
317 }
318
319 //-----------------------------------------------------------------------------------
320
321 function textarea_cells($label, $name, $value, $cols, $rows, $params="")
322 {
323         if ($label != null)
324                 echo "<td $params>$label</td>\n";
325         if ($value == null)
326                 $value = (!isset($_POST[$name]) ? "" : $_POST[$name]);
327         echo "<td><textarea name='$name' cols='$cols' rows='$rows'>$value</textarea></td>\n";
328 }
329
330 function textarea_row($label, $name, $value, $cols, $rows, $params="")
331 {
332         echo "<tr>";
333         textarea_cells($label, $name, $value, $cols, $rows, $params);
334         echo "</tr>\n";
335 }
336
337 //-----------------------------------------------------------------------------------
338
339 function text_row_with_submit($label, $name, $value, $size, $max, $input_name, $input_value)
340 {
341         echo "<tr><td>$label</td>\n";
342         echo "<td>";
343
344         if ($value == null)
345                 $value = (!isset($_POST[$name]) ? "" : $_POST[$name]);
346         echo "<input type=\"text\" name=\"$name\" size=\"$size\" maxlength=\"$max\" value=\"$value\">   ";
347
348         submit($input_name, $input_value);
349
350         echo "</td></tr>\n";
351 }
352
353 //-----------------------------------------------------------------------------------
354
355
356 ?>