Asynchronous customer/supplier/item selection now use popup window.
[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') as $m) {
51                 if (isset($_POST[$m])) {
52                         $Ajax->activate('_page_body');
53                         if ($m == 'RESET') 
54                                 $selected_id = $default;
55                         $Mode = $m; return;
56                 }
57         }
58         foreach (array('Edit', 'Delete') as $m) {
59                 foreach ($_POST as $p => $pvar) {
60                         if (strpos($p, $m) === 0) {
61 //                              $selected_id = strtr(substr($p, strlen($m)), array('%2E'=>'.'));
62                                 unset($_POST['_focus']); // focus on first form entry
63                                 $selected_id = quoted_printable_decode(substr($p, strlen($m)));
64                                 $Ajax->activate('_page_body');
65                                 $Mode = $m;
66                                 return;
67                         }
68                 }
69         }
70         $Mode = '';
71 }
72
73 //------------------------------------------------------------------------------
74 //
75 //      Read numeric value from user formatted input
76 //
77 function input_num($postname=null, $dflt=null)
78 {
79         if (!isset($_POST[$postname]) || $_POST[$postname] == "")
80                 return $dflt;
81
82     return user_numeric($_POST[$postname]);
83 }
84
85 //---------------------------------------------------------------------------------
86
87 function hidden($name, $value=null, $echo=true)
88 {
89         global $Ajax;
90         
91         if ($value === null) 
92                 $value = get_post($name);
93         
94         $ret = "<input type=\"hidden\" name=\"$name\" value=\"$value\">";
95         $Ajax->addUpdate($name, $name, $value);
96         if ($echo)
97                 echo $ret."\n";
98         else
99                 return $ret;
100 }
101 /*
102         Universal submit form button.
103         $atype - type of submit:
104          Normal submit:
105                 false - normal button; optional icon
106                 null  - button visible only in fallback mode; optional icon
107          Ajax submit:
108                 true      - standard button; optional icon
109                 'process' - displays progress bar during call; optional icon
110                 'default' - default form submit on Ctrl-Enter press; dflt ICON_OK icon
111                 'selector' - ditto with closing current popup editor window
112                 'cancel'  - cancel form entry on Escape press; dflt ICON_CANCEL
113 */
114 function submit($name, $value, $echo=true, $title=false, $atype=false, $icon=false)
115 {
116         global $path_to_root;
117
118         $aspect='';
119         if (!is_bool($atype)) // necessary: switch uses '=='
120           switch($atype) {
121                 case 'process':
122                         $aspect = " aspect='process'"; break;
123                 case 'selector':
124                         $aspect = " aspect='selector' rel = '$value'"; 
125                         $value = _("Select");
126                         if ($icon===false) $icon=ICON_SUBMIT; break;
127                 case 'default':
128                         $aspect = " aspect='default'"; 
129                         if ($icon===false) $icon=ICON_SUBMIT; break;
130                 case 'cancel':
131                         $aspect = " aspect='cancel'"; 
132                         if ($icon===false) $icon=ICON_ESCAPE; break;
133                 case null: 
134                         $aspect = fallback_mode() ? 
135                                 " aspect='fallback'" : " style='display:none;'"; break;
136          }
137
138         default_focus($name);
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'>" : '')
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)
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, $title, $async);
196                 submit('RESET', _("Cancel"), true, $title, $cancel);
197         }
198 }
199
200 function submit_add_or_update_center($add=true, $title=false, $async=false)
201 {
202         echo "<center>";
203         submit_add_or_update($add, $title, $async);
204         echo "</center>";
205 }
206
207 function submit_add_or_update_row($add=true, $right=true, $extra="", $title=false, $async=false)
208 {
209         echo "<tr>";
210         if ($right)
211                 echo "<td>&nbsp;</td>\n";
212         echo "<td $extra>";
213         submit_add_or_update($add, $title, $async);
214         echo "</td></tr>\n";
215 }
216
217 function submit_cells($name, $value, $extra="", $title=false, $async=false)
218 {
219         echo "<td $extra>";
220         submit($name, $value, true, $title, $async);
221         echo "</td>\n";
222 }
223
224 function submit_row($name, $value, $right=true, $extra="", $title=false, $async=false)
225 {
226         echo "<tr>";
227         if ($right)
228                 echo "<td>&nbsp;</td>\n";
229         submit_cells($name, $value, $extra, $title, $async);
230         echo "</tr>\n";
231 }
232
233 function submit_return($name, $value, $title=false)
234 {
235         if (@$_REQUEST['popup']) {
236                 submit($name, $value, true, $title, 'selector');
237         }
238 }
239
240 function submit_js_confirm($name, $msg) {
241         add_js_source(
242                 "_validate.$name=function(){ return confirm('$msg');};");
243 };
244 //-----------------------------------------------------------------------------------
245
246 function set_icon($icon, $title=false)
247 {
248         global $path_to_root;
249         return "<img src='$path_to_root/themes/".user_theme()."/images/$icon' width='14' height='14' border='0'".($title ? " title='$title'" : "")." />\n";     
250 }
251
252 function button($name, $value, $title=false, $icon=false,  $aspect='')
253 {
254         // php silently changes dots,spaces,'[' and characters 128-159
255         // to underscore in POST names, to maintain compatibility with register_globals
256         $rel = '';
257         if ($aspect == 'selector') {
258                 $rel = " rel='$value'";
259                 $value = _("Select");
260         }
261         if (user_graphic_links() && $icon)
262         {
263                 if ($value == _("Delete")) // Helper during implementation
264                         $icon = ICON_DELETE;
265                 return "<button type='submit' class='editbutton' name='".
266                         htmlentities(strtr($name, array('.'=>'=2E',' '=>'=20','='=>'=3D','['=>'=5B'))).
267                         "' value='1'" . ($title ? " title='$title'":" title='$value'")
268                         . ($aspect ? " aspect='$aspect'" : '')
269                         . $rel
270                         ." />".set_icon($icon)."\n";
271         }
272         else
273                 return "<input type='submit' class='editbutton' name='"
274                         .htmlentities(strtr($name, array('.'=>'=2E',' '=>'=20','='=>'=3D','['=>'=5B')))
275                         ."' value='$value'"
276                         .($title ? " title='$title'":'')
277                         . ($aspect ? " aspect='$aspect'" : '')
278                         . $rel
279                         ." />\n";
280 }
281
282 function button_cell($name, $value, $title=false, $icon=false, $aspect='')
283 {
284         echo "<td align='center'>";
285         echo button($name, $value, $title, $icon, $aspect);
286         echo "</td>";
287 }
288
289 function delete_button_cell($name, $value, $title=false)
290 {
291         button_cell($name, $value, $title, ICON_DELETE);
292 }
293
294 function edit_button_cell($name, $value, $title=false)
295 {
296         button_cell($name, $value, $title, ICON_EDIT);
297 }
298
299 function select_button_cell($name, $value, $title=false)
300 {
301         button_cell($name, $value, $title, ICON_ADD, 'selector');
302 }
303 //-----------------------------------------------------------------------------------
304
305 function check_value($name)
306 {
307         if (!isset($_POST[$name]))
308                 return 0;
309         return 1;
310 }
311
312 function checkbox($label, $name, $value=null, $submit_on_change=false, $title=false)
313 {
314         global $Ajax;
315
316         $str = '';      
317         default_focus($name);
318         if ($label)
319                 $str .= $label . "  ";
320         if ($submit_on_change !== false) {
321                 if ($submit_on_change === true)
322                         $submit_on_change = 
323                                 "JsHttpRequest.request(\"_{$name}_update\", this.form);";
324         }
325         if ($value === null)
326                 $value = get_post($name,0);
327
328         $str .= "<input"
329             .($value == 1 ? ' checked':'')
330             ." type='checkbox' name='$name' value='1'"
331             .($submit_on_change ? " onclick='$submit_on_change'" : '')
332             .($title ? " title='$title'" : '')
333             ." >\n";
334
335         $Ajax->addUpdate($name, $name, $value);
336         return $str;
337 }
338
339 function check($label, $name, $value=null, $submit_on_change=false, $title=false)
340 {
341         echo checkbox($label, $name, $value, $submit_on_change, $title);
342 }
343
344 function check_cells($label, $name, $value, $submit_on_change=false, $title=false,
345         $params='')
346 {
347         if ($label != null)
348                 echo "<td>$label</td>\n";
349         echo "<td $params>";
350         echo check(null, $name, $value, $submit_on_change, $title);
351         echo "</td>";
352 }
353
354 function check_row($label, $name, $value, $submit_on_change=false, $title=false)
355 {
356         echo "<tr>";
357         echo check_cells($label, $name, $value, $submit_on_change, $title);
358         echo "</tr>\n";
359 }
360
361 //-----------------------------------------------------------------------------------
362
363 function labelheader_cell($label, $params="")
364 {
365         echo "<td class='tableheader' $params>$label</td>\n";
366 }
367
368 function label_cell($label, $params="", $id=null)
369 {
370     global $Ajax;
371
372         if(isset($id))
373         {
374             $params .= " id='$id'";
375             $Ajax->addUpdate($id, $id, $label);
376         }
377         echo "<td $params>$label</td>\n";
378
379         return $label;
380 }
381
382 function email_cell($label, $params="", $id=null)
383 {
384         label_cell("<a href='mailto:$label'>$label</a>", $params, $id);
385 }
386
387 function amount_cell($label, $bold=false, $params="", $id=null)
388 {
389         if ($bold)
390                 label_cell("<b>".price_format($label)."</b>", "nowrap align=right ".$params, $id);
391         else
392                 label_cell(price_format($label), "nowrap align=right ".$params, $id);
393 }
394
395 function percent_cell($label, $bold=false, $id=null)
396 {
397         if ($bold)
398                 label_cell("<b>".percent_format($label)."</b>", "nowrap align=right", $id);
399         else
400                 label_cell(percent_format($label), "nowrap align=right", $id);
401 }
402 // 2008-06-15. Changed
403 function qty_cell($label, $bold=false, $dec=null, $id=null)
404 {
405         if (!isset($dec))
406                 $dec = get_qty_dec();
407         if ($bold)
408                 label_cell("<b>".number_format2($label, $dec)."</b>", "nowrap align=right", $id);
409         else
410                 label_cell(number_format2($label, $dec), "nowrap align=right", $id);
411 }
412
413 function label_cells($label, $value, $params="", $params2="", $id='')
414 {
415         if ($label != null)
416                 echo "<td $params>$label</td>\n";
417         label_cell($value, $params2, $id);
418 }
419
420 function label_row($label, $value, $params="", $params2="", $leftfill=0, $id='')
421 {
422         echo "<tr>";
423         label_cells($label, $value, $params, $params2, $id);
424         if ($leftfill!=0)
425                 echo "<td colspan=$leftfill></td>";
426         echo "</tr>\n";
427 }
428
429 //-----------------------------------------------------------------------------------
430
431 function text_cells($label, $name, $value=null, $size="", $max="", $title=false, 
432         $labparams="", $post_label="", $inparams="")
433 {
434         global $Ajax;
435
436         default_focus($name);
437         if ($label != null)
438                 label_cell($label, $labparams);
439         echo "<td>";
440
441         if ($value === null)
442                 $value = get_post($name);
443         echo "<input $inparams type=\"text\" name=\"$name\" size=\"$size\" maxlength=\"$max\" value=\"$value\""
444             .($title ? " title='$title'" : '')
445             .">";
446
447         if ($post_label != "")
448                 echo " " . $post_label;
449
450         echo "</td>\n";
451         $Ajax->addUpdate($name, $name, $value);
452 }
453
454 function text_cells_ex($label, $name, $size, $max=null, $init=null, $title=null,
455         $labparams=null, $post_label=null, $submit_on_change=false)
456 {
457         global $Ajax;
458
459         default_focus($name);
460         if (!isset($_POST[$name]) || $_POST[$name] == "")
461         {
462                 if ($init)
463                         $_POST[$name] = $init;
464                 else
465                         $_POST[$name] = "";
466         }
467         if ($label != null)
468                 label_cell($label, $labparams);
469
470         if (!isset($max))
471                 $max = $size;
472
473         echo "<td>";
474         $class = $submit_on_change ? 'class="searchbox"' : '';
475         echo "<input $class type=\"text\" name=\"$name\" size=\"$size\" maxlength=\"$max\" value=\"" . $_POST[$name]. "\""
476          .($title ? " title='$title'": '')." >";
477
478         if ($post_label)
479                 echo " " . $post_label;
480
481         echo "</td>\n";
482         $Ajax->addUpdate($name, $name, $_POST[$name]);
483 }
484
485 function text_row($label, $name, $value, $size, $max, $title=null, $params="", $post_label="")
486 {
487         echo "<tr>";
488
489         text_cells($label, $name, $value, $size, $max, $title, $params, $post_label);
490
491         echo "</tr>\n";
492 }
493
494 //-----------------------------------------------------------------------------------
495
496 function text_row_ex($label, $name, $size, $max=null, $title=null, $value=null, $params=null, $post_label=null)
497 {
498         echo "<tr>";
499
500         text_cells_ex($label, $name, $size, $max, $value, $title, $params, $post_label);
501
502         echo "</tr>\n";
503 }
504
505 //-----------------------------------------------------------------------------------
506 function email_row($label, $name, $value, $size, $max, $title=null, $params="", $post_label="")
507 {
508         if (get_post($name)) 
509                 $label = "<a href='Mailto:".$_POST[$name]."'>$label</a>";
510         text_row($label, $name, $value, $size, $max, $title, $params, $post_label);
511 }
512
513 function email_row_ex($label, $name, $size, $max=null, $title=null, $value=null, $params=null, $post_label=null)
514 {
515         if (get_post($name)) 
516                 $label = "<a href='Mailto:".$_POST[$name]."'>$label</a>";
517         text_row_ex($label, $name, $size, $max, $title, $value, $params, $post_label);
518 }
519
520 function link_row($label, $name, $value, $size, $max, $title=null, $params="", $post_label="")
521 {
522         $val = get_post($name);
523         if ($val) {
524                 if (strpos($val,'http://')===false)
525                         $val = 'http://'.$val;
526                 $label = "<a href='$val' target='_blank'>$label</a>";
527         }
528         text_row($label, $name, $value, $size, $max, $title, $params, $post_label);
529 }
530
531 function link_row_ex($label, $name, $size, $max=null, $title=null, $value=null, $params=null, $post_label=null)
532 {
533         $val = get_post($name);
534         if ($val) {
535                 if (strpos($val,'http://')===false)
536                         $val = 'http://'.$val;
537                 $label = "<a href='$val' target='_blank'>$label</a>";
538         }
539         text_row_ex($label, $name, $size, $max, $title, $value, $params, $post_label);
540 }
541
542 //-----------------------------------------------------------------------------------
543 //
544 //      Since FA 2.2  $init parameter is superseded by $check. 
545 //  When $check!=null current date is displayed in red when set to other 
546 //      than current date.
547 //      
548 function date_cells($label, $name, $title = null, $check=null, $inc_days=0, 
549         $inc_months=0, $inc_years=0, $params=null, $submit_on_change=false)
550 {
551         global $use_date_picker, $path_to_root, $Ajax;
552
553         if (!isset($_POST[$name]) || $_POST[$name] == "")
554         {
555                 if ($inc_years == 1001)
556                         $_POST[$name] = null;
557                 else
558                 {
559                         $dd = Today();
560                         if ($inc_days != 0)
561                                 $dd = add_days($dd, $inc_days);
562                         if ($inc_months != 0)
563                                 $dd = add_months($dd, $inc_months);
564                         if ($inc_years != 0)
565                                 $dd = add_years($dd, $inc_years);
566                         $_POST[$name] = $dd;
567                 }
568         }
569         if ($use_date_picker)
570                 $post_label = "<a tabindex='-1' href=\"javascript:date_picker(document.getElementsByName('$name')[0]);\">"
571                 . "     <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";
572         else
573                 $post_label = "";
574
575         if ($label != null)
576                 label_cell($label, $params);
577
578         echo "<td>";
579         
580         $class = $submit_on_change ? 'class="searchbox"' : '';
581
582         $aspect = $check ? 'aspect="cdate"' : '';
583         if ($check && (get_post($name) != Today()))
584                 $aspect .= ' style="color:#FF0000"';
585
586         echo "<input type=\"text\" name=\"$name\" $class $aspect size=\"9\" maxlength=\"12\" value=\"" 
587          . $_POST[$name]. "\""
588          .($title ? " title='$title'": '')." > $post_label";
589         echo "</td>\n";
590         $Ajax->addUpdate($name, $name, $_POST[$name]);
591 }
592
593 function date_row($label, $name, $title=null, $check=null, $inc_days=0, $inc_months=0, 
594         $inc_years=0, $params=null, $submit_on_change=false)
595 {
596         echo "<tr>";
597         date_cells($label, $name, $title, $check, $inc_days, $inc_months, 
598                 $inc_years, $params, $submit_on_change);
599         echo "</tr>\n";
600 }
601
602 //-----------------------------------------------------------------------------------
603
604 function ref_cells($label, $name, $title=null, $init=null, $params=null, $submit_on_change=false)
605 {
606         text_cells_ex($label, $name, 16, 18, $init, $title, $params, null, $submit_on_change);
607 }
608
609 //-----------------------------------------------------------------------------------
610
611 function ref_row($label, $name, $title=null, $init=null, $submit_on_change=false)
612 {
613         echo "<tr>";
614         ref_cells($label, $name, $title, $init, null, $submit_on_change);
615         echo "</tr>\n";
616 }
617
618 //-----------------------------------------------------------------------------------
619
620 function percent_row($label, $name, $init=null)
621 {
622
623         if (!isset($_POST[$name]) || $_POST[$name]=="")
624         {
625                 $_POST[$name] = $init == null ? '' : $init;
626         }
627
628         small_amount_row($label, $name, $_POST[$name], null, "%", user_percent_dec());
629 }
630
631 function amount_cells_ex($label, $name, $size, $max=null, $init=null, $params=null, $post_label=null, $dec=null)
632 {
633         global $Ajax;
634
635         if (!isset($dec))
636                 $dec = user_price_dec();
637         if (!isset($_POST[$name]) || $_POST[$name] == "")
638         {
639                 if ($init !== null)
640                         $_POST[$name] = $init;
641                 else
642                         $_POST[$name] = '';
643         }
644         if ($label != null)
645                 label_cell($label, $params);
646
647         if (!isset($max))
648                 $max = $size;
649
650         if ($label != null)
651                 echo "<td>";
652         else
653                 echo "<td align='right'>";
654
655         echo "<input class='amount' type=\"text\" name=\"$name\" size=\"$size\" maxlength=\"$max\" dec=\"$dec\" value=\"" . $_POST[$name]. "\">";
656
657         if ($post_label) {
658                 echo "<span id='_{$name}_label'> $post_label</span>";
659                 $Ajax->addUpdate($name, '_'.$name.'_label', $post_label);
660         }
661         echo "</td>\n";
662         $Ajax->addUpdate($name, $name, $_POST[$name]);
663         $Ajax->addAssign($name, $name, 'dec', $dec);
664 }
665
666
667 //-----------------------------------------------------------------------------------
668
669 function amount_cells($label, $name, $init=null, $params=null, $post_label=null, $dec=null)
670 {
671         amount_cells_ex($label, $name, 15, 15, $init, $params, $post_label, $dec);
672 }
673
674 function amount_row($label, $name, $init=null, $params=null, $post_label=null, $dec=null)
675 {
676         echo "<tr>";
677         amount_cells($label, $name, $init, $params, $post_label, $dec);
678         echo "</tr>\n";
679 }
680
681 function small_amount_row($label, $name, $init=null, $params=null, $post_label=null, $dec=null)
682 {
683         echo "<tr>";
684         small_amount_cells($label, $name, $init, $params, $post_label, $dec);
685         echo "</tr>\n";
686 }
687
688 //-----------------------------------------------------------------------------------
689
690 function qty_cells($label, $name, $init=null, $params=null, $post_label=null, $dec=null)
691 {
692         if (!isset($dec))
693                 $dec = user_qty_dec();
694
695         amount_cells_ex($label, $name, 15, 15, $init, $params, $post_label, $dec);
696 }
697
698 function qty_row($label, $name, $init=null, $params=null, $post_label=null, $dec=null)
699 {
700         if (!isset($dec))
701                 $dec = user_qty_dec();
702
703         echo "<tr>";
704         amount_cells($label, $name, $init, $params, $post_label, $dec);
705         echo "</tr>\n";
706 }
707
708 function small_qty_row($label, $name, $init=null, $params=null, $post_label=null, $dec=null)
709 {
710         if (!isset($dec))
711                 $dec = user_qty_dec();
712
713         echo "<tr>";
714         small_amount_cells($label, $name, $init, $params, $post_label, $dec);
715         echo "</tr>\n";
716 }
717
718 //-----------------------------------------------------------------------------------
719
720 function small_amount_cells($label, $name, $init=null, $params=null, $post_label=null, $dec=null)
721 {
722         amount_cells_ex($label, $name, 7, 12, $init, $params, $post_label, $dec);
723 }
724
725 //-----------------------------------------------------------------------------------
726
727 function small_qty_cells($label, $name, $init=null, $params=null, $post_label=null, $dec=null)
728 {
729         if (!isset($dec))
730                 $dec = user_qty_dec();
731         amount_cells_ex($label, $name, 7, 12, $init, $params, $post_label, $dec);
732 }
733
734 //-----------------------------------------------------------------------------------
735
736 function textarea_cells($label, $name, $value, $cols, $rows, $title = null, $params="")
737 {
738         global $Ajax;
739
740         default_focus($name);
741         if ($label != null)
742                 echo "<td $params>$label</td>\n";
743         if ($value == null)
744                 $value = (!isset($_POST[$name]) ? "" : $_POST[$name]);
745         echo "<td><textarea name='$name' cols='$cols' rows='$rows'"
746         .($title ? " title='$title'" : '')
747         .">$value</textarea></td>\n";
748         $Ajax->addUpdate($name, $name, $value);
749 }
750
751 function textarea_row($label, $name, $value, $cols, $rows, $title=null, $params="")
752 {
753         echo "<tr>";
754         textarea_cells($label, $name, $value, $cols, $rows, $title, $params);
755         echo "</tr>\n";
756 }
757
758 //-----------------------------------------------------------------------------------
759 /*
760 function text_row_with_submit($label, $name, $value, $size, $max, $input_name, $input_value)
761 {
762         global $Ajax;
763
764         default_focus($name);
765         echo "<tr><td>$label</td>\n";
766         echo "<td>";
767
768         if ($value == null)
769                 $value = (!isset($_POST[$name]) ? "" : $_POST[$name]);
770         echo "<input type=\"text\" name=\"$name\" size=\"$size\" maxlength=\"$max\" value=\"$value\">   ";
771
772         submit($input_name, $input_value);
773
774         echo "</td></tr>\n";
775         $Ajax->addUpdate($name, $name, $value);
776 }
777 */
778 //-----------------------------------------------------------------------------------
779 //
780 //      When show_inactive page option is set 
781 //  displays value of inactive field as checkbox cell.
782 //  Also updates database record after status change.
783 //
784 function inactive_control_cell($id, $value, $table, $key)
785 {
786         global  $Ajax;
787
788         $name = "Inactive". $id;
789         $value = $value ? 1:0;
790
791         if (check_value('show_inactive')) {
792                 if (isset($_POST['LInact'][$id]) && (get_post('_Inactive'.$id.'_update') || 
793                         get_post('Update')) && (check_value('Inactive'.$id) != $value)) {
794                         update_record_status($id, !$value, $table, $key);
795                 }
796                 echo '<td align="center">'. checkbox(null, $name, $value, true, '', "align='center'")
797                         . hidden("LInact[$id]", $value, false) . '</td>';       
798         }
799 }
800 //
801 //      Displays controls for optional display of inactive records
802 //
803 function inactive_control_row($th) {
804         echo  "<tr><td colspan=".(count($th)).">"
805                 ."<div style='float:left;'>"
806                 . checkbox(null, 'show_inactive', null, true). _("Show also Inactive")
807                 ."</div><div style='float:right;'>"
808                 . submit('Update', _('Update'), false, '', null)
809                 ."</div></td></tr>";
810 }
811 //
812 //      Inserts additional column header when display of inactive records is on.
813 //
814 function inactive_control_column(&$th) {
815         global $Ajax;
816         
817         if (check_value('show_inactive')) 
818                 array_insert($th, count($th)-2 , _("Inactive"));
819         if (get_post('_show_inactive_update')) {
820                 $Ajax->activate('_page_body');
821         }
822 }
823 ?>