Merged changes from main CVS (up to 2.2.10)
[fa-stable.git] / includes / ui / ui_input.inc
1 <?php
2 /**********************************************************************
3     Copyright (C) FrontAccounting, LLC.
4         Released under the terms of the GNU General Public License, GPL, 
5         as published by the Free Software Foundation, either version 3 
6         of the License, or (at your option) any later version.
7     This program is distributed in the hope that it will be useful,
8     but WITHOUT ANY WARRANTY; without even the implied warranty of
9     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
10     See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
11 ***********************************************************************/
12 //
13 // Sets local POST value and adds Value to ajax posting if needed
14 //
15 /*function set_post($name, $value, $ajax_trigger=true) {
16     global $Ajax;
17
18     $_POST[$name] = $value;
19     if ($ajax_trigger) $Ajax->activate($name);
20 }
21 */
22 //------------------------------------------------------------------------------
23 //    Seek for _POST variable with $prefix.
24 //    If var is found returns variable name with prefix stripped,
25 //    and null or -1 otherwise.
26 //
27 function find_submit($prefix, $numeric=true)
28 {
29
30     foreach($_POST as $postkey=>$postval )
31     {
32                 if (strpos($postkey, $prefix) === 0)
33                 {
34                         $id = substr($postkey, strlen($prefix));
35                         return $numeric ? (int)$id : $id;
36                 }
37     }
38     return $numeric ? -1 : null;
39 }
40 //------------------------------------------------------------------------------
41 //
42 // Helper function for simple db table editor pages
43 //
44 function simple_page_mode($numeric_id = true)
45 {
46         global $Ajax, $Mode, $selected_id;
47
48         $default = $numeric_id ? -1 : '';
49         $selected_id = get_post('selected_id', $default);
50         foreach (array('ADD_ITEM', 'UPDATE_ITEM', 'RESET', 'CLONE') as $m) {
51                 if (isset($_POST[$m])) {
52                         $Ajax->activate('_page_body');
53                         if ($m == 'RESET'  || $m == 'CLONE') 
54                                 $selected_id = $default;
55                         unset($_POST['_focus']);
56                         $Mode = $m; return;
57                 }
58         }
59         foreach (array('Edit', 'Delete') as $m) {
60                 foreach ($_POST as $p => $pvar) {
61                         if (strpos($p, $m) === 0) {
62 //                              $selected_id = strtr(substr($p, strlen($m)), array('%2E'=>'.'));
63                                 unset($_POST['_focus']); // focus on first form entry
64                                 $selected_id = quoted_printable_decode(substr($p, strlen($m)));
65                                 $Ajax->activate('_page_body');
66                                 $Mode = $m;
67                                 return;
68                         }
69                 }
70         }
71         $Mode = '';
72 }
73
74 //------------------------------------------------------------------------------
75 //
76 //      Read numeric value from user formatted input
77 //
78 function input_num($postname=null, $dflt=0)
79 {
80         if (!isset($_POST[$postname]) || $_POST[$postname] == "")
81                 return $dflt;
82
83     return user_numeric($_POST[$postname]);
84 }
85
86 //---------------------------------------------------------------------------------
87
88 function hidden($name, $value=null, $echo=true)
89 {
90         global $Ajax;
91         
92         if ($value === null) 
93                 $value = get_post($name);
94         
95         $ret = "<input type=\"hidden\" name=\"$name\" value=\"$value\">";
96         $Ajax->addUpdate($name, $name, $value);
97         if ($echo)
98                 echo $ret."\n";
99         else
100                 return $ret;
101 }
102 /*
103         Universal submit form button.
104         $atype - type of submit:
105          Normal submit:
106                 false - normal button; optional icon
107                 null  - button visible only in fallback mode; optional icon
108          Ajax submit:
109                 true      - standard button; optional icon
110
111                 'default' - default form submit on Ctrl-Enter press; dflt ICON_OK icon
112                 'selector' - ditto with closing current popup editor window
113                 'cancel'  - cancel form entry on Escape press; dflt ICON_CANCEL
114                 'process' - displays progress bar during call; optional icon
115
116         $atype can contain also multiply type selectors separated by space, 
117         however make sense only combination of 'process' and one of defualt/selector/cancel
118 */
119 function submit($name, $value, $echo=true, $title=false, $atype=false, $icon=false)
120 {
121         global $path_to_root;
122
123         $aspect='';
124         if ($atype === null) {
125                 $aspect = fallback_mode() ? " aspect='fallback'" : " style='display:none;'";
126
127         } elseif (!is_bool($atype)) { // necessary: switch uses '=='
128
129                 $aspect = "aspect='$atype' ";
130                 $types = explode(' ', $atype);
131
132                 foreach ($types as $type) {
133                         switch($type) {
134                                 case 'selector':
135                                         $aspect = " aspect='selector' rel = '$value'"; 
136                                         $value = _("Select");
137                                         if ($icon===false) $icon=ICON_SUBMIT; break;
138
139                                 case 'default':
140                                         if ($icon===false) $icon=ICON_SUBMIT; break;
141
142                                 case 'cancel':
143                                         if ($icon===false) $icon=ICON_ESCAPE; break;
144                         }
145                 }
146         }
147         $submit_str = "<button class=\""
148             .($atype ? 'ajaxsubmit' : 'inputsubmit')
149                 ."\" type=\"submit\""
150                 .$aspect
151             ." name=\"$name\"  id=\"$name\" value=\"$value\""
152             .($title ? " title='$title'" : '')
153             .">"
154                 .($icon ? "<img src='$path_to_root/themes/".user_theme()."/images/$icon' height='12'>" : '')
155                 ."<span>$value</span>"
156                 ."</button>\n";
157         if ($echo)
158                 echo $submit_str;
159         else
160                 return $submit_str;
161 }
162
163 function submit_center($name, $value, $echo=true, $title=false, $async=false, $icon=false)
164 {
165         if ($echo) echo "<center>";
166         submit($name, $value, $echo, $title, $async, $icon);
167         if ($echo) echo "</center>";
168 }
169
170 function submit_center_first($name, $value, $title=false, $async=false, $icon=false)
171 {
172         echo "<center>";
173         submit($name, $value, true, $title, $async, $icon);
174         echo "&nbsp;";
175 }
176
177 function submit_center_last($name, $value, $title=false, $async=false, $icon=false)
178 {
179         echo "&nbsp;";
180         submit($name, $value, true, $title, $async, $icon);
181         echo "</center>";
182 }
183 /*
184         For following controls:
185         'both' - use both Ctrl-Enter and Escape hotkeys 
186         'cancel' - apply to 'RESET' button
187 */
188 function submit_add_or_update($add=true, $title=false, $async=false, $clone=false)
189 {
190         $cancel = $async;
191
192         if ($async === 'both') {
193                 $async = 'default'; $cancel = 'cancel';
194         } 
195         else if ($async === 'default')
196                 $cancel = true;
197         else if ($async === 'cancel')
198                 $async = true;
199         
200         if ($add)
201                 submit('ADD_ITEM', _("Add new"), true, $title, $async);
202         else {
203                 submit('UPDATE_ITEM', _("Update"), true, _('Submit changes'), $async);
204                 if ($clone) submit('CLONE', _("Clone"), true, 
205                         _('Edit new record with current data'), $async);
206                 submit('RESET', _("Cancel"), true, _('Cancel edition'), $cancel);
207         }
208 }
209
210 function submit_add_or_update_center($add=true, $title=false, $async=false, $clone=false)
211 {
212         echo "<center>";
213         submit_add_or_update($add, $title, $async, $clone);
214         echo "</center>";
215 }
216
217 function submit_add_or_update_row($add=true, $right=true, $extra="", $title=false, $async=false, $clone = false)
218 {
219         echo "<tr>";
220         if ($right)
221                 echo "<td>&nbsp;</td>\n";
222         echo "<td $extra>";
223         submit_add_or_update($add, $title, $async, $clone);
224         echo "</td></tr>\n";
225 }
226
227 function submit_cells($name, $value, $extra="", $title=false, $async=false)
228 {
229         echo "<td $extra>";
230         submit($name, $value, true, $title, $async);
231         echo "</td>\n";
232 }
233
234 function submit_row($name, $value, $right=true, $extra="", $title=false, $async=false)
235 {
236         echo "<tr>";
237         if ($right)
238                 echo "<td>&nbsp;</td>\n";
239         submit_cells($name, $value, $extra, $title, $async);
240         echo "</tr>\n";
241 }
242
243 function submit_return($name, $value, $title=false)
244 {
245         if (@$_REQUEST['popup']) {
246                 submit($name, $value, true, $title, 'selector');
247         }
248 }
249
250 function submit_js_confirm($name, $msg) {
251         add_js_source(
252                 "_validate.$name=function(){ return confirm('"
253                         . strtr($msg, array("\n"=>'\\n')) . "');};");
254 };
255 //-----------------------------------------------------------------------------------
256
257 function set_icon($icon, $title=false)
258 {
259         global $path_to_root;
260         return "<img src='$path_to_root/themes/".user_theme()."/images/$icon' width='12' height='12' border='0'".($title ? " title='$title'" : "")." />\n";     
261 }
262
263 function button($name, $value, $title=false, $icon=false,  $aspect='')
264 {
265         // php silently changes dots,spaces,'[' and characters 128-159
266         // to underscore in POST names, to maintain compatibility with register_globals
267         $rel = '';
268         if ($aspect == 'selector') {
269                 $rel = " rel='$value'";
270                 $value = _("Select");
271         }
272         if (user_graphic_links() && $icon)
273         {
274                 if ($value == _("Delete")) // Helper during implementation
275                         $icon = ICON_DELETE;
276                 return "<button type='submit' class='editbutton' name='".
277                         htmlentities(strtr($name, array('.'=>'=2E',' '=>'=20','='=>'=3D','['=>'=5B'))).
278                         "' value='1'" . ($title ? " title='$title'":" title='$value'")
279                         . ($aspect ? " aspect='$aspect'" : '')
280                         . $rel
281                         ." />".set_icon($icon)."</button>\n";
282         }
283         else
284                 return "<input type='submit' class='editbutton' name='"
285                         .htmlentities(strtr($name, array('.'=>'=2E',' '=>'=20','='=>'=3D','['=>'=5B')))
286                         ."' value='$value'"
287                         .($title ? " title='$title'":'')
288                         . ($aspect ? " aspect='$aspect'" : '')
289                         . $rel
290                         ." />\n";
291 }
292
293 function button_cell($name, $value, $title=false, $icon=false, $aspect='')
294 {
295         echo "<td align='center'>";
296         echo button($name, $value, $title, $icon, $aspect);
297         echo "</td>";
298 }
299
300 function delete_button_cell($name, $value, $title=false)
301 {
302         button_cell($name, $value, $title, ICON_DELETE);
303 }
304
305 function edit_button_cell($name, $value, $title=false)
306 {
307         button_cell($name, $value, $title, ICON_EDIT);
308 }
309
310 function select_button_cell($name, $value, $title=false)
311 {
312         button_cell($name, $value, $title, ICON_ADD, 'selector');
313 }
314 //-----------------------------------------------------------------------------------
315
316 function check_value($name)
317 {
318         if (!isset($_POST[$name]))
319                 return 0;
320         return 1;
321 }
322
323 function checkbox($label, $name, $value=null, $submit_on_change=false, $title=false)
324 {
325         global $Ajax;
326
327         $str = '';      
328
329         if ($label)
330                 $str .= $label . "  ";
331         if ($submit_on_change !== false) {
332                 if ($submit_on_change === true)
333                         $submit_on_change = 
334                                 "JsHttpRequest.request(\"_{$name}_update\", this.form);";
335         }
336         if ($value === null)
337                 $value = get_post($name,0);
338
339         $str .= "<input"
340             .($value == 1 ? ' checked':'')
341             ." type='checkbox' name='$name' value='1'"
342             .($submit_on_change ? " onclick='$submit_on_change'" : '')
343             .($title ? " title='$title'" : '')
344             ." >\n";
345
346         $Ajax->addUpdate($name, $name, $value);
347         return $str;
348 }
349
350 function check($label, $name, $value=null, $submit_on_change=false, $title=false)
351 {
352         echo checkbox($label, $name, $value, $submit_on_change, $title);
353 }
354
355 function check_cells($label, $name, $value=null, $submit_on_change=false, $title=false,
356         $params='')
357 {
358         if ($label != null)
359                 echo "<td>$label</td>\n";
360         echo "<td $params>";
361         echo check(null, $name, $value, $submit_on_change, $title);
362         echo "</td>";
363 }
364
365 function check_row($label, $name, $value=null, $submit_on_change=false, $title=false)
366 {
367         echo "<tr><td class='label'>$label</td>";
368         echo check_cells(NULL, $name, $value, $submit_on_change, $title);
369         echo "</tr>\n";
370 }
371
372 //-----------------------------------------------------------------------------------
373 function radio($label, $name, $value, $selected, $submit_on_change=false) {
374
375         if ($submit_on_change === true)
376                 $submit_on_change = 
377                         "JsHttpRequest.request(\"_{$name}_update\", this.form);";
378
379         return "<input type='radio' name=$name value='$value' ".($selected ? "checked":'')
380             .($submit_on_change ? " onclick='$submit_on_change'" : '')
381                 .">".($label ? $label : '');
382 }
383
384 //-----------------------------------------------------------------------------------
385 function labelheader_cell($label, $params="")
386 {
387         echo "<td class='tableheader' $params>$label</td>\n";
388 }
389
390 function label_cell($label, $params="", $id=null)
391 {
392     global $Ajax;
393
394         if(isset($id))
395         {
396             $params .= " id='$id'";
397             $Ajax->addUpdate($id, $id, $label);
398         }
399         echo "<td $params>$label</td>\n";
400
401         return $label;
402 }
403
404 function email_cell($label, $params="", $id=null)
405 {
406         label_cell("<a href='mailto:$label'>$label</a>", $params, $id);
407 }
408
409 function amount_decimal_cell($label, $params="", $id=null)
410 {
411         $dec = 0;
412         label_cell(price_decimal_format($label, $dec), "nowrap align=right ".$params, $id);
413 }
414
415 function amount_cell($label, $bold=false, $params="", $id=null)
416 {
417         if ($bold)
418                 label_cell("<b>".price_format($label)."</b>", "nowrap align=right ".$params, $id);
419         else
420                 label_cell(price_format($label), "nowrap align=right ".$params, $id);
421 }
422
423 //JAM  Allow entered unit prices to be fractional
424 function unit_amount_cell($label, $bold=false, $params="", $id=null)
425 {
426         if ($bold)
427                 label_cell("<b>".unit_price_format($label)."</b>", "nowrap align=right ".$params, $id);
428         else
429                 label_cell(unit_price_format($label), "nowrap align=right ".$params, $id);
430 }
431
432
433 function percent_cell($label, $bold=false, $id=null)
434 {
435         if ($bold)
436                 label_cell("<b>".percent_format($label)."</b>", "nowrap align=right", $id);
437         else
438                 label_cell(percent_format($label), "nowrap align=right", $id);
439 }
440 // 2008-06-15. Changed
441 function qty_cell($label, $bold=false, $dec=null, $id=null)
442 {
443         if (!isset($dec))
444                 $dec = get_qty_dec();
445         if ($bold)
446                 label_cell("<b>".number_format2($label, $dec)."</b>", "nowrap align=right", $id);
447         else
448                 label_cell(number_format2($label, $dec), "nowrap align=right", $id);
449 }
450
451 function label_cells($label, $value, $params="", $params2="", $id='')
452 {
453         if ($label != null)
454                 echo "<td $params>$label</td>\n";
455         label_cell($value, $params2, $id);
456 }
457
458 function label_row($label, $value, $params="", $params2="", $leftfill=0, $id='')
459 {
460         echo "<tr>";
461         if ($params == "")
462         {
463                 echo "<td class='label'>$label</td>";
464                 $label = null;
465         }       
466         label_cells($label, $value, $params, $params2, $id);
467         if ($leftfill!=0)
468                 echo "<td colspan=$leftfill></td>";
469         echo "</tr>\n";
470 }
471
472 //-----------------------------------------------------------------------------------
473
474 function text_cells($label, $name, $value=null, $size="", $max="", $title=false, 
475         $labparams="", $post_label="", $inparams="")
476 {
477         global $Ajax;
478
479         default_focus($name);
480         if ($label != null)
481                 label_cell($label, $labparams);
482         echo "<td>";
483
484         if ($value === null)
485                 $value = get_post($name);
486         echo "<input $inparams type=\"text\" name=\"$name\" size=\"$size\" maxlength=\"$max\" value=\"$value\""
487             .($title ? " title='$title'" : '')
488             .">";
489
490         if ($post_label != "")
491                 echo " " . $post_label;
492
493         echo "</td>\n";
494         $Ajax->addUpdate($name, $name, $value);
495 }
496
497 function text_cells_ex($label, $name, $size, $max=null, $init=null, $title=null,
498         $labparams=null, $post_label=null, $submit_on_change=false)
499 {
500         global $Ajax;
501
502         default_focus($name);
503         if (!isset($_POST[$name]) || $_POST[$name] == "")
504         {
505                 if ($init)
506                         $_POST[$name] = $init;
507                 else
508                         $_POST[$name] = "";
509         }
510         if ($label != null)
511                 label_cell($label, $labparams);
512
513         if (!isset($max))
514                 $max = $size;
515
516         echo "<td>";
517         $class = $submit_on_change ? 'class="searchbox"' : '';
518         echo "<input $class type=\"text\" name=\"$name\" size=\"$size\" maxlength=\"$max\" value=\"" . $_POST[$name]. "\""
519          .($title ? " title='$title'": '')." >";
520
521         if ($post_label)
522                 echo " " . $post_label;
523
524         echo "</td>\n";
525         $Ajax->addUpdate($name, $name, $_POST[$name]);
526 }
527
528 function text_row($label, $name, $value, $size, $max, $title=null, $params="", $post_label="")
529 {
530         echo "<tr><td class='label'>$label</td>";
531         text_cells(null, $name, $value, $size, $max, $title, $params, $post_label);
532
533         echo "</tr>\n";
534 }
535
536 //-----------------------------------------------------------------------------------
537
538 function text_row_ex($label, $name, $size, $max=null, $title=null, $value=null, $params=null, $post_label=null)
539 {
540         echo "<tr><td class='label'>$label</td>";
541         text_cells_ex(null, $name, $size, $max, $value, $title, $params, $post_label);
542
543         echo "</tr>\n";
544 }
545
546 //-----------------------------------------------------------------------------------
547 function email_row($label, $name, $value, $size, $max, $title=null, $params="", $post_label="")
548 {
549         if (get_post($name)) 
550                 $label = "<a href='Mailto:".$_POST[$name]."'>$label</a>";
551         text_row($label, $name, $value, $size, $max, $title, $params, $post_label);
552 }
553
554 function email_row_ex($label, $name, $size, $max=null, $title=null, $value=null, $params=null, $post_label=null)
555 {
556         if (get_post($name)) 
557                 $label = "<a href='Mailto:".$_POST[$name]."'>$label</a>";
558         text_row_ex($label, $name, $size, $max, $title, $value, $params, $post_label);
559 }
560
561 function link_row($label, $name, $value, $size, $max, $title=null, $params="", $post_label="")
562 {
563         $val = get_post($name);
564         if ($val) {
565                 if (strpos($val,'http://')===false)
566                         $val = 'http://'.$val;
567                 $label = "<a href='$val' target='_blank'>$label</a>";
568         }
569         text_row($label, $name, $value, $size, $max, $title, $params, $post_label);
570 }
571
572 function link_row_ex($label, $name, $size, $max=null, $title=null, $value=null, $params=null, $post_label=null)
573 {
574         $val = get_post($name);
575         if ($val) {
576                 if (strpos($val,'http://')===false)
577                         $val = 'http://'.$val;
578                 $label = "<a href='$val' target='_blank'>$label</a>";
579         }
580         text_row_ex($label, $name, $size, $max, $title, $value, $params, $post_label);
581 }
582
583 //-----------------------------------------------------------------------------------
584 //
585 //      Since FA 2.2  $init parameter is superseded by $check. 
586 //  When $check!=null current date is displayed in red when set to other 
587 //      than current date.
588 //      
589 function date_cells($label, $name, $title = null, $check=null, $inc_days=0, 
590         $inc_months=0, $inc_years=0, $params=null, $submit_on_change=false)
591 {
592         global $use_date_picker, $path_to_root, $Ajax;
593
594         if (!isset($_POST[$name]) || $_POST[$name] == "")
595         {
596                 if ($inc_years == 1001)
597                         $_POST[$name] = null;
598                 else
599                 {
600                         $dd = Today();
601                         if ($inc_days != 0)
602                                 $dd = add_days($dd, $inc_days);
603                         if ($inc_months != 0)
604                                 $dd = add_months($dd, $inc_months);
605                         if ($inc_years != 0)
606                                 $dd = add_years($dd, $inc_years);
607                         $_POST[$name] = $dd;
608                 }
609         }
610         if ($use_date_picker)
611                 $post_label = "<a tabindex='-1' href=\"javascript:date_picker(document.getElementsByName('$name')[0]);\">"
612                 . "     <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";
613         else
614                 $post_label = "";
615
616         if ($label != null)
617                 label_cell($label, $params);
618
619         echo "<td>";
620         
621         $class = $submit_on_change ? 'class="searchbox"' : '';
622
623         $aspect = $check ? 'aspect="cdate"' : '';
624         if ($check && (get_post($name) != Today()))
625                 $aspect .= ' style="color:#FF0000"';
626
627         default_focus($name);
628
629         echo "<input type=\"text\" name=\"$name\" $class $aspect size=\"9\" maxlength=\"12\" value=\"" 
630          . $_POST[$name]. "\""
631          .($title ? " title='$title'": '')." > $post_label";
632         echo "</td>\n";
633         $Ajax->addUpdate($name, $name, $_POST[$name]);
634 }
635
636 function date_row($label, $name, $title=null, $check=null, $inc_days=0, $inc_months=0, 
637         $inc_years=0, $params=null, $submit_on_change=false)
638 {
639         echo "<tr><td class='label'>$label</td>";
640         date_cells(null, $name, $title, $check, $inc_days, $inc_months, 
641                 $inc_years, $params, $submit_on_change);
642         echo "</tr>\n";
643 }
644
645 //-----------------------------------------------------------------------------------
646 function password_row($label, $name, $value)
647 {
648         echo "<tr><td class='label'>$label</td>";
649         label_cell("<input type='password' name='$name' size=20 maxlength=20 value='$value' />");
650         echo "</tr>\n";
651 }       
652
653 //-----------------------------------------------------------------------------------
654 function file_cells($label, $name, $id="")
655 {
656         if ($id != "")
657                 $id = "id='$id'";
658         label_cells($label, "<input type='file' name='$name' $id />");
659 }               
660 function file_row($label, $name, $id = "")
661 {
662         echo "<tr><td class='label'>$label</td>";
663         file_cells(null, $name, $id);
664         echo "</tr>\n";
665 }       
666
667 //-----------------------------------------------------------------------------------
668
669 function ref_cells($label, $name, $title=null, $init=null, $params=null, $submit_on_change=false)
670 {
671         text_cells_ex($label, $name, 16, 18, $init, $title, $params, null, $submit_on_change);
672 }
673
674 //-----------------------------------------------------------------------------------
675
676 function ref_row($label, $name, $title=null, $init=null, $submit_on_change=false)
677 {
678         echo "<tr><td class='label'>$label</td>";
679         ref_cells(null, $name, $title, $init, null, $submit_on_change);
680         echo "</tr>\n";
681 }
682
683 //-----------------------------------------------------------------------------------
684
685 function percent_row($label, $name, $init=null)
686 {
687
688         if (!isset($_POST[$name]) || $_POST[$name]=="")
689         {
690                 $_POST[$name] = $init == null ? '' : $init;
691         }
692
693         small_amount_row($label, $name, $_POST[$name], null, "%", user_percent_dec());
694 }
695
696 function amount_cells_ex($label, $name, $size, $max=null, $init=null, $params=null, $post_label=null, $dec=null)
697 {
698         global $Ajax;
699
700         if (!isset($dec))
701                 $dec = user_price_dec();
702         if (!isset($_POST[$name]) || $_POST[$name] == "")
703         {
704                 if ($init !== null)
705                         $_POST[$name] = $init;
706                 else
707                         $_POST[$name] = '';
708         }
709         if ($label != null)
710         {
711                 if ($params == null)
712                         $params = "class='label'";
713                 label_cell($label, $params);
714         }
715         if (!isset($max))
716                 $max = $size;
717
718         if ($label != null)
719                 echo "<td>";
720         else
721                 echo "<td align='right'>";
722
723         echo "<input class='amount' type=\"text\" name=\"$name\" size=\"$size\" maxlength=\"$max\" dec=\"$dec\" value=\"" . $_POST[$name]. "\">";
724
725         if ($post_label) {
726                 echo "<span id='_{$name}_label'> $post_label</span>";
727                 $Ajax->addUpdate($name, '_'.$name.'_label', $post_label);
728         }
729         echo "</td>\n";
730         $Ajax->addUpdate($name, $name, $_POST[$name]);
731         $Ajax->addAssign($name, $name, 'dec', $dec);
732 }
733
734
735 //-----------------------------------------------------------------------------------
736
737 function amount_cells($label, $name, $init=null, $params=null, $post_label=null, $dec=null)
738 {
739         amount_cells_ex($label, $name, 15, 15, $init, $params, $post_label, $dec);
740 }
741
742 //JAM  Allow entered unit prices to be fractional
743 function unit_amount_cells($label, $name, $init=null, $params=null, $post_label=null, $dec=null)
744 {
745         if (!isset($dec))
746                 $dec = user_price_dec()+2;
747
748         amount_cells_ex($label, $name, 15, 15, $init, $params, $post_label, $dec+2);
749 }
750
751 function amount_row($label, $name, $init=null, $params=null, $post_label=null, $dec=null)
752 {
753         echo "<tr>";
754         amount_cells($label, $name, $init, $params, $post_label, $dec);
755         echo "</tr>\n";
756 }
757
758 function small_amount_row($label, $name, $init=null, $params=null, $post_label=null, $dec=null)
759 {
760         echo "<tr>";
761         small_amount_cells($label, $name, $init, $params, $post_label, $dec);
762         echo "</tr>\n";
763 }
764
765 //-----------------------------------------------------------------------------------
766
767 function qty_cells($label, $name, $init=null, $params=null, $post_label=null, $dec=null)
768 {
769         if (!isset($dec))
770                 $dec = user_qty_dec();
771
772         amount_cells_ex($label, $name, 15, 15, $init, $params, $post_label, $dec);
773 }
774
775 function qty_row($label, $name, $init=null, $params=null, $post_label=null, $dec=null)
776 {
777         if (!isset($dec))
778                 $dec = user_qty_dec();
779
780         echo "<tr>";
781         amount_cells($label, $name, $init, $params, $post_label, $dec);
782         echo "</tr>\n";
783 }
784
785 function small_qty_row($label, $name, $init=null, $params=null, $post_label=null, $dec=null)
786 {
787         if (!isset($dec))
788                 $dec = user_qty_dec();
789
790         echo "<tr>";
791         small_amount_cells($label, $name, $init, $params, $post_label, $dec);
792         echo "</tr>\n";
793 }
794
795 //-----------------------------------------------------------------------------------
796
797 function small_amount_cells($label, $name, $init=null, $params=null, $post_label=null, $dec=null)
798 {
799         amount_cells_ex($label, $name, 7, 12, $init, $params, $post_label, $dec);
800 }
801
802 //-----------------------------------------------------------------------------------
803
804 function small_qty_cells($label, $name, $init=null, $params=null, $post_label=null, $dec=null)
805 {
806         if (!isset($dec))
807                 $dec = user_qty_dec();
808         amount_cells_ex($label, $name, 7, 12, $init, $params, $post_label, $dec);
809 }
810
811 //-----------------------------------------------------------------------------------
812
813 function textarea_cells($label, $name, $value, $cols, $rows, $title = null, $params="")
814 {
815         global $Ajax;
816
817         default_focus($name);
818         if ($label != null)
819                 echo "<td $params>$label</td>\n";
820         if ($value == null)
821                 $value = (!isset($_POST[$name]) ? "" : $_POST[$name]);
822         echo "<td><textarea name='$name' cols='$cols' rows='$rows'"
823         .($title ? " title='$title'" : '')
824         .">$value</textarea></td>\n";
825         $Ajax->addUpdate($name, $name, $value);
826 }
827
828 function textarea_row($label, $name, $value, $cols, $rows, $title=null, $params="")
829 {
830         echo "<tr><td class='label'>$label</td>";
831         textarea_cells(null, $name, $value, $cols, $rows, $title, $params);
832         echo "</tr>\n";
833 }
834
835 //-----------------------------------------------------------------------------------
836 /*
837 function text_row_with_submit($label, $name, $value, $size, $max, $input_name, $input_value)
838 {
839         global $Ajax;
840
841         default_focus($name);
842         echo "<tr><td>$label</td>\n";
843         echo "<td>";
844
845         if ($value == null)
846                 $value = (!isset($_POST[$name]) ? "" : $_POST[$name]);
847         echo "<input type=\"text\" name=\"$name\" size=\"$size\" maxlength=\"$max\" value=\"$value\">   ";
848
849         submit($input_name, $input_value);
850
851         echo "</td></tr>\n";
852         $Ajax->addUpdate($name, $name, $value);
853 }
854 */
855 //-----------------------------------------------------------------------------------
856 //
857 //      When show_inactive page option is set 
858 //  displays value of inactive field as checkbox cell.
859 //  Also updates database record after status change.
860 //
861 function inactive_control_cell($id, $value, $table, $key)
862 {
863         global  $Ajax;
864
865         $name = "Inactive". $id;
866         $value = $value ? 1:0;
867
868         if (check_value('show_inactive')) {
869                 if (isset($_POST['LInact'][$id]) && (get_post('_Inactive'.$id.'_update') || 
870                         get_post('Update')) && (check_value('Inactive'.$id) != $value)) {
871                         update_record_status($id, !$value, $table, $key);
872                 }
873                 echo '<td align="center">'. checkbox(null, $name, $value, true, '', "align='center'")
874                         . hidden("LInact[$id]", $value, false) . '</td>';       
875         }
876 }
877 //
878 //      Displays controls for optional display of inactive records
879 //
880 function inactive_control_row($th) {
881         echo  "<tr><td colspan=".(count($th)).">"
882                 ."<div style='float:left;'>"
883                 . checkbox(null, 'show_inactive', null, true). _("Show also Inactive")
884                 ."</div><div style='float:right;'>"
885                 . submit('Update', _('Update'), false, '', null)
886                 ."</div></td></tr>";
887 }
888 //
889 //      Inserts additional column header when display of inactive records is on.
890 //
891 function inactive_control_column(&$th) {
892         global $Ajax;
893         
894         if (check_value('show_inactive')) 
895                 array_insert($th, count($th)-2 , _("Inactive"));
896         if (get_post('_show_inactive_update')) {
897                 $Ajax->activate('_page_body');
898         }
899 }
900 ?>