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