Merged changes from main CVS up to 2.1.5
[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=null)
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         echo "<center>";
158         submit($name, $value, $echo, $title, $async, $icon);
159         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('$msg');};");
245 };
246 //-----------------------------------------------------------------------------------
247
248 function set_icon($icon, $title=false)
249 {
250         global $path_to_root;
251         return "<img src='$path_to_root/themes/".user_theme()."/images/$icon' width='12' height='12' border='0'".($title ? " title='$title'" : "")." />\n";     
252 }
253
254 function button($name, $value, $title=false, $icon=false,  $aspect='')
255 {
256         // php silently changes dots,spaces,'[' and characters 128-159
257         // to underscore in POST names, to maintain compatibility with register_globals
258         $rel = '';
259         if ($aspect == 'selector') {
260                 $rel = " rel='$value'";
261                 $value = _("Select");
262         }
263         if (user_graphic_links() && $icon)
264         {
265                 if ($value == _("Delete")) // Helper during implementation
266                         $icon = ICON_DELETE;
267                 return "<button type='submit' class='editbutton' name='".
268                         htmlentities(strtr($name, array('.'=>'=2E',' '=>'=20','='=>'=3D','['=>'=5B'))).
269                         "' value='1'" . ($title ? " title='$title'":" title='$value'")
270                         . ($aspect ? " aspect='$aspect'" : '')
271                         . $rel
272                         ." />".set_icon($icon)."\n";
273         }
274         else
275                 return "<input type='submit' class='editbutton' name='"
276                         .htmlentities(strtr($name, array('.'=>'=2E',' '=>'=20','='=>'=3D','['=>'=5B')))
277                         ."' value='$value'"
278                         .($title ? " title='$title'":'')
279                         . ($aspect ? " aspect='$aspect'" : '')
280                         . $rel
281                         ." />\n";
282 }
283
284 function button_cell($name, $value, $title=false, $icon=false, $aspect='')
285 {
286         echo "<td align='center'>";
287         echo button($name, $value, $title, $icon, $aspect);
288         echo "</td>";
289 }
290
291 function delete_button_cell($name, $value, $title=false)
292 {
293         button_cell($name, $value, $title, ICON_DELETE);
294 }
295
296 function edit_button_cell($name, $value, $title=false)
297 {
298         button_cell($name, $value, $title, ICON_EDIT);
299 }
300
301 function select_button_cell($name, $value, $title=false)
302 {
303         button_cell($name, $value, $title, ICON_ADD, 'selector');
304 }
305 //-----------------------------------------------------------------------------------
306
307 function check_value($name)
308 {
309         if (!isset($_POST[$name]))
310                 return 0;
311         return 1;
312 }
313
314 function checkbox($label, $name, $value=null, $submit_on_change=false, $title=false)
315 {
316         global $Ajax;
317
318         $str = '';      
319
320         if ($label)
321                 $str .= $label . "  ";
322         if ($submit_on_change !== false) {
323                 if ($submit_on_change === true)
324                         $submit_on_change = 
325                                 "JsHttpRequest.request(\"_{$name}_update\", this.form);";
326         }
327         if ($value === null)
328                 $value = get_post($name,0);
329
330         $str .= "<input"
331             .($value == 1 ? ' checked':'')
332             ." type='checkbox' name='$name' value='1'"
333             .($submit_on_change ? " onclick='$submit_on_change'" : '')
334             .($title ? " title='$title'" : '')
335             ." >\n";
336
337         $Ajax->addUpdate($name, $name, $value);
338         return $str;
339 }
340
341 function check($label, $name, $value=null, $submit_on_change=false, $title=false)
342 {
343         echo checkbox($label, $name, $value, $submit_on_change, $title);
344 }
345
346 function check_cells($label, $name, $value=null, $submit_on_change=false, $title=false,
347         $params='')
348 {
349         if ($label != null)
350                 echo "<td>$label</td>\n";
351         echo "<td $params>";
352         echo check(null, $name, $value, $submit_on_change, $title);
353         echo "</td>";
354 }
355
356 function check_row($label, $name, $value=null, $submit_on_change=false, $title=false)
357 {
358         echo "<tr>";
359         echo check_cells($label, $name, $value, $submit_on_change, $title);
360         echo "</tr>\n";
361 }
362
363 //-----------------------------------------------------------------------------------
364
365 function labelheader_cell($label, $params="")
366 {
367         echo "<td class='tableheader' $params>$label</td>\n";
368 }
369
370 function label_cell($label, $params="", $id=null)
371 {
372     global $Ajax;
373
374         if(isset($id))
375         {
376             $params .= " id='$id'";
377             $Ajax->addUpdate($id, $id, $label);
378         }
379         echo "<td $params>$label</td>\n";
380
381         return $label;
382 }
383
384 function email_cell($label, $params="", $id=null)
385 {
386         label_cell("<a href='mailto:$label'>$label</a>", $params, $id);
387 }
388
389 function amount_decimal_cell($label, $params="", $id=null)
390 {
391         $dec = 0;
392         label_cell(price_decimal_format($label, $dec), "nowrap align=right ".$params, $id);
393 }
394
395 function amount_cell($label, $bold=false, $params="", $id=null)
396 {
397         if ($bold)
398                 label_cell("<b>".price_format($label)."</b>", "nowrap align=right ".$params, $id);
399         else
400                 label_cell(price_format($label), "nowrap align=right ".$params, $id);
401 }
402
403 //JAM  Allow entered unit prices to be fractional
404 function unit_amount_cell($label, $bold=false, $params="", $id=null)
405 {
406         if ($bold)
407                 label_cell("<b>".unit_price_format($label)."</b>", "nowrap align=right ".$params, $id);
408         else
409                 label_cell(unit_price_format($label), "nowrap align=right ".$params, $id);
410 }
411
412
413 function percent_cell($label, $bold=false, $id=null)
414 {
415         if ($bold)
416                 label_cell("<b>".percent_format($label)."</b>", "nowrap align=right", $id);
417         else
418                 label_cell(percent_format($label), "nowrap align=right", $id);
419 }
420 // 2008-06-15. Changed
421 function qty_cell($label, $bold=false, $dec=null, $id=null)
422 {
423         if (!isset($dec))
424                 $dec = get_qty_dec();
425         if ($bold)
426                 label_cell("<b>".number_format2($label, $dec)."</b>", "nowrap align=right", $id);
427         else
428                 label_cell(number_format2($label, $dec), "nowrap align=right", $id);
429 }
430
431 function label_cells($label, $value, $params="", $params2="", $id='')
432 {
433         if ($label != null)
434                 echo "<td $params>$label</td>\n";
435         label_cell($value, $params2, $id);
436 }
437
438 function label_row($label, $value, $params="", $params2="", $leftfill=0, $id='')
439 {
440         echo "<tr>";
441         label_cells($label, $value, $params, $params2, $id);
442         if ($leftfill!=0)
443                 echo "<td colspan=$leftfill></td>";
444         echo "</tr>\n";
445 }
446
447 //-----------------------------------------------------------------------------------
448
449 function text_cells($label, $name, $value=null, $size="", $max="", $title=false, 
450         $labparams="", $post_label="", $inparams="")
451 {
452         global $Ajax;
453
454         default_focus($name);
455         if ($label != null)
456                 label_cell($label, $labparams);
457         echo "<td>";
458
459         if ($value === null)
460                 $value = get_post($name);
461         echo "<input $inparams type=\"text\" name=\"$name\" size=\"$size\" maxlength=\"$max\" value=\"$value\""
462             .($title ? " title='$title'" : '')
463             .">";
464
465         if ($post_label != "")
466                 echo " " . $post_label;
467
468         echo "</td>\n";
469         $Ajax->addUpdate($name, $name, $value);
470 }
471
472 function text_cells_ex($label, $name, $size, $max=null, $init=null, $title=null,
473         $labparams=null, $post_label=null, $submit_on_change=false)
474 {
475         global $Ajax;
476
477         default_focus($name);
478         if (!isset($_POST[$name]) || $_POST[$name] == "")
479         {
480                 if ($init)
481                         $_POST[$name] = $init;
482                 else
483                         $_POST[$name] = "";
484         }
485         if ($label != null)
486                 label_cell($label, $labparams);
487
488         if (!isset($max))
489                 $max = $size;
490
491         echo "<td>";
492         $class = $submit_on_change ? 'class="searchbox"' : '';
493         echo "<input $class type=\"text\" name=\"$name\" size=\"$size\" maxlength=\"$max\" value=\"" . $_POST[$name]. "\""
494          .($title ? " title='$title'": '')." >";
495
496         if ($post_label)
497                 echo " " . $post_label;
498
499         echo "</td>\n";
500         $Ajax->addUpdate($name, $name, $_POST[$name]);
501 }
502
503 function text_row($label, $name, $value, $size, $max, $title=null, $params="", $post_label="")
504 {
505         echo "<tr>";
506
507         text_cells($label, $name, $value, $size, $max, $title, $params, $post_label);
508
509         echo "</tr>\n";
510 }
511
512 //-----------------------------------------------------------------------------------
513
514 function text_row_ex($label, $name, $size, $max=null, $title=null, $value=null, $params=null, $post_label=null)
515 {
516         echo "<tr>";
517
518         text_cells_ex($label, $name, $size, $max, $value, $title, $params, $post_label);
519
520         echo "</tr>\n";
521 }
522
523 //-----------------------------------------------------------------------------------
524 function email_row($label, $name, $value, $size, $max, $title=null, $params="", $post_label="")
525 {
526         if (get_post($name)) 
527                 $label = "<a href='Mailto:".$_POST[$name]."'>$label</a>";
528         text_row($label, $name, $value, $size, $max, $title, $params, $post_label);
529 }
530
531 function email_row_ex($label, $name, $size, $max=null, $title=null, $value=null, $params=null, $post_label=null)
532 {
533         if (get_post($name)) 
534                 $label = "<a href='Mailto:".$_POST[$name]."'>$label</a>";
535         text_row_ex($label, $name, $size, $max, $title, $value, $params, $post_label);
536 }
537
538 function link_row($label, $name, $value, $size, $max, $title=null, $params="", $post_label="")
539 {
540         $val = get_post($name);
541         if ($val) {
542                 if (strpos($val,'http://')===false)
543                         $val = 'http://'.$val;
544                 $label = "<a href='$val' target='_blank'>$label</a>";
545         }
546         text_row($label, $name, $value, $size, $max, $title, $params, $post_label);
547 }
548
549 function link_row_ex($label, $name, $size, $max=null, $title=null, $value=null, $params=null, $post_label=null)
550 {
551         $val = get_post($name);
552         if ($val) {
553                 if (strpos($val,'http://')===false)
554                         $val = 'http://'.$val;
555                 $label = "<a href='$val' target='_blank'>$label</a>";
556         }
557         text_row_ex($label, $name, $size, $max, $title, $value, $params, $post_label);
558 }
559
560 //-----------------------------------------------------------------------------------
561 //
562 //      Since FA 2.2  $init parameter is superseded by $check. 
563 //  When $check!=null current date is displayed in red when set to other 
564 //      than current date.
565 //      
566 function date_cells($label, $name, $title = null, $check=null, $inc_days=0, 
567         $inc_months=0, $inc_years=0, $params=null, $submit_on_change=false)
568 {
569         global $use_date_picker, $path_to_root, $Ajax;
570
571         if (!isset($_POST[$name]) || $_POST[$name] == "")
572         {
573                 if ($inc_years == 1001)
574                         $_POST[$name] = null;
575                 else
576                 {
577                         $dd = Today();
578                         if ($inc_days != 0)
579                                 $dd = add_days($dd, $inc_days);
580                         if ($inc_months != 0)
581                                 $dd = add_months($dd, $inc_months);
582                         if ($inc_years != 0)
583                                 $dd = add_years($dd, $inc_years);
584                         $_POST[$name] = $dd;
585                 }
586         }
587         if ($use_date_picker)
588                 $post_label = "<a tabindex='-1' href=\"javascript:date_picker(document.getElementsByName('$name')[0]);\">"
589                 . "     <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";
590         else
591                 $post_label = "";
592
593         if ($label != null)
594                 label_cell($label, $params);
595
596         echo "<td>";
597         
598         $class = $submit_on_change ? 'class="searchbox"' : '';
599
600         $aspect = $check ? 'aspect="cdate"' : '';
601         if ($check && (get_post($name) != Today()))
602                 $aspect .= ' style="color:#FF0000"';
603
604         default_focus($name);
605
606         echo "<input type=\"text\" name=\"$name\" $class $aspect size=\"9\" maxlength=\"12\" value=\"" 
607          . $_POST[$name]. "\""
608          .($title ? " title='$title'": '')." > $post_label";
609         echo "</td>\n";
610         $Ajax->addUpdate($name, $name, $_POST[$name]);
611 }
612
613 function date_row($label, $name, $title=null, $check=null, $inc_days=0, $inc_months=0, 
614         $inc_years=0, $params=null, $submit_on_change=false)
615 {
616         echo "<tr>";
617         date_cells($label, $name, $title, $check, $inc_days, $inc_months, 
618                 $inc_years, $params, $submit_on_change);
619         echo "</tr>\n";
620 }
621
622 //-----------------------------------------------------------------------------------
623
624 function ref_cells($label, $name, $title=null, $init=null, $params=null, $submit_on_change=false)
625 {
626         text_cells_ex($label, $name, 16, 18, $init, $title, $params, null, $submit_on_change);
627 }
628
629 //-----------------------------------------------------------------------------------
630
631 function ref_row($label, $name, $title=null, $init=null, $submit_on_change=false)
632 {
633         echo "<tr>";
634         ref_cells($label, $name, $title, $init, null, $submit_on_change);
635         echo "</tr>\n";
636 }
637
638 //-----------------------------------------------------------------------------------
639
640 function percent_row($label, $name, $init=null)
641 {
642
643         if (!isset($_POST[$name]) || $_POST[$name]=="")
644         {
645                 $_POST[$name] = $init == null ? '' : $init;
646         }
647
648         small_amount_row($label, $name, $_POST[$name], null, "%", user_percent_dec());
649 }
650
651 function amount_cells_ex($label, $name, $size, $max=null, $init=null, $params=null, $post_label=null, $dec=null)
652 {
653         global $Ajax;
654
655         if (!isset($dec))
656                 $dec = user_price_dec();
657         if (!isset($_POST[$name]) || $_POST[$name] == "")
658         {
659                 if ($init !== null)
660                         $_POST[$name] = $init;
661                 else
662                         $_POST[$name] = '';
663         }
664         if ($label != null)
665                 label_cell($label, $params);
666
667         if (!isset($max))
668                 $max = $size;
669
670         if ($label != null)
671                 echo "<td>";
672         else
673                 echo "<td align='right'>";
674
675         echo "<input class='amount' type=\"text\" name=\"$name\" size=\"$size\" maxlength=\"$max\" dec=\"$dec\" value=\"" . $_POST[$name]. "\">";
676
677         if ($post_label) {
678                 echo "<span id='_{$name}_label'> $post_label</span>";
679                 $Ajax->addUpdate($name, '_'.$name.'_label', $post_label);
680         }
681         echo "</td>\n";
682         $Ajax->addUpdate($name, $name, $_POST[$name]);
683         $Ajax->addAssign($name, $name, 'dec', $dec);
684 }
685
686
687 //-----------------------------------------------------------------------------------
688
689 function amount_cells($label, $name, $init=null, $params=null, $post_label=null, $dec=null)
690 {
691         amount_cells_ex($label, $name, 15, 15, $init, $params, $post_label, $dec);
692 }
693
694 //JAM  Allow entered unit prices to be fractional
695 function unit_amount_cells($label, $name, $init=null, $params=null, $post_label=null, $dec=null)
696 {
697         if (!isset($dec))
698                 $dec = user_price_dec()+2;
699
700         amount_cells_ex($label, $name, 15, 15, $init, $params, $post_label, $dec+2);
701 }
702
703 function amount_row($label, $name, $init=null, $params=null, $post_label=null, $dec=null)
704 {
705         echo "<tr>";
706         amount_cells($label, $name, $init, $params, $post_label, $dec);
707         echo "</tr>\n";
708 }
709
710 function small_amount_row($label, $name, $init=null, $params=null, $post_label=null, $dec=null)
711 {
712         echo "<tr>";
713         small_amount_cells($label, $name, $init, $params, $post_label, $dec);
714         echo "</tr>\n";
715 }
716
717 //-----------------------------------------------------------------------------------
718
719 function qty_cells($label, $name, $init=null, $params=null, $post_label=null, $dec=null)
720 {
721         if (!isset($dec))
722                 $dec = user_qty_dec();
723
724         amount_cells_ex($label, $name, 15, 15, $init, $params, $post_label, $dec);
725 }
726
727 function qty_row($label, $name, $init=null, $params=null, $post_label=null, $dec=null)
728 {
729         if (!isset($dec))
730                 $dec = user_qty_dec();
731
732         echo "<tr>";
733         amount_cells($label, $name, $init, $params, $post_label, $dec);
734         echo "</tr>\n";
735 }
736
737 function small_qty_row($label, $name, $init=null, $params=null, $post_label=null, $dec=null)
738 {
739         if (!isset($dec))
740                 $dec = user_qty_dec();
741
742         echo "<tr>";
743         small_amount_cells($label, $name, $init, $params, $post_label, $dec);
744         echo "</tr>\n";
745 }
746
747 //-----------------------------------------------------------------------------------
748
749 function small_amount_cells($label, $name, $init=null, $params=null, $post_label=null, $dec=null)
750 {
751         amount_cells_ex($label, $name, 7, 12, $init, $params, $post_label, $dec);
752 }
753
754 //-----------------------------------------------------------------------------------
755
756 function small_qty_cells($label, $name, $init=null, $params=null, $post_label=null, $dec=null)
757 {
758         if (!isset($dec))
759                 $dec = user_qty_dec();
760         amount_cells_ex($label, $name, 7, 12, $init, $params, $post_label, $dec);
761 }
762
763 //-----------------------------------------------------------------------------------
764
765 function textarea_cells($label, $name, $value, $cols, $rows, $title = null, $params="")
766 {
767         global $Ajax;
768
769         default_focus($name);
770         if ($label != null)
771                 echo "<td $params>$label</td>\n";
772         if ($value == null)
773                 $value = (!isset($_POST[$name]) ? "" : $_POST[$name]);
774         echo "<td><textarea name='$name' cols='$cols' rows='$rows'"
775         .($title ? " title='$title'" : '')
776         .">$value</textarea></td>\n";
777         $Ajax->addUpdate($name, $name, $value);
778 }
779
780 function textarea_row($label, $name, $value, $cols, $rows, $title=null, $params="")
781 {
782         echo "<tr>";
783         textarea_cells($label, $name, $value, $cols, $rows, $title, $params);
784         echo "</tr>\n";
785 }
786
787 //-----------------------------------------------------------------------------------
788 /*
789 function text_row_with_submit($label, $name, $value, $size, $max, $input_name, $input_value)
790 {
791         global $Ajax;
792
793         default_focus($name);
794         echo "<tr><td>$label</td>\n";
795         echo "<td>";
796
797         if ($value == null)
798                 $value = (!isset($_POST[$name]) ? "" : $_POST[$name]);
799         echo "<input type=\"text\" name=\"$name\" size=\"$size\" maxlength=\"$max\" value=\"$value\">   ";
800
801         submit($input_name, $input_value);
802
803         echo "</td></tr>\n";
804         $Ajax->addUpdate($name, $name, $value);
805 }
806 */
807 //-----------------------------------------------------------------------------------
808 //
809 //      When show_inactive page option is set 
810 //  displays value of inactive field as checkbox cell.
811 //  Also updates database record after status change.
812 //
813 function inactive_control_cell($id, $value, $table, $key)
814 {
815         global  $Ajax;
816
817         $name = "Inactive". $id;
818         $value = $value ? 1:0;
819
820         if (check_value('show_inactive')) {
821                 if (isset($_POST['LInact'][$id]) && (get_post('_Inactive'.$id.'_update') || 
822                         get_post('Update')) && (check_value('Inactive'.$id) != $value)) {
823                         update_record_status($id, !$value, $table, $key);
824                 }
825                 echo '<td align="center">'. checkbox(null, $name, $value, true, '', "align='center'")
826                         . hidden("LInact[$id]", $value, false) . '</td>';       
827         }
828 }
829 //
830 //      Displays controls for optional display of inactive records
831 //
832 function inactive_control_row($th) {
833         echo  "<tr><td colspan=".(count($th)).">"
834                 ."<div style='float:left;'>"
835                 . checkbox(null, 'show_inactive', null, true). _("Show also Inactive")
836                 ."</div><div style='float:right;'>"
837                 . submit('Update', _('Update'), false, '', null)
838                 ."</div></td></tr>";
839 }
840 //
841 //      Inserts additional column header when display of inactive records is on.
842 //
843 function inactive_control_column(&$th) {
844         global $Ajax;
845         
846         if (check_value('show_inactive')) 
847                 array_insert($th, count($th)-2 , _("Inactive"));
848         if (get_post('_show_inactive_update')) {
849                 $Ajax->activate('_page_body');
850         }
851 }
852 ?>