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