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 ***********************************************************************/
13 // Sets local POST value and adds Value to ajax posting if needed
15 /*function set_post($name, $value, $ajax_trigger=true) {
18 $_POST[$name] = $value;
19 if ($ajax_trigger) $Ajax->activate($name);
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.
27 function find_submit($prefix, $numeric=true)
30 foreach($_POST as $postkey=>$postval )
32 if (strpos($postkey, $prefix) === 0)
34 $id = substr($postkey, strlen($prefix));
35 return $numeric ? (int)$id : $id;
38 return $numeric ? -1 : null;
42 Returns true if input $name with $submit_on_change option set is subject to update.
44 function input_changed($name)
46 return isset($_POST['_'.$name.'_changed']);
49 //------------------------------------------------------------------------------
51 // Helper function for simple db table editor pages
53 function simple_page_mode($numeric_id = true)
55 global $Ajax, $Mode, $selected_id;
57 $default = $numeric_id ? -1 : '';
58 $selected_id = get_post('selected_id', $default);
59 foreach (array('ADD_ITEM', 'UPDATE_ITEM', 'RESET', 'CLONE') as $m) {
60 if (isset($_POST[$m])) {
61 $Ajax->activate('_page_body');
62 if ($m == 'RESET' || $m == 'CLONE')
63 $selected_id = $default;
64 unset($_POST['_focus']);
68 foreach (array('Edit', 'Delete') as $m) {
69 foreach ($_POST as $p => $pvar) {
70 if (strpos($p, $m) === 0) {
71 // $selected_id = strtr(substr($p, strlen($m)), array('%2E'=>'.'));
72 unset($_POST['_focus']); // focus on first form entry
73 $selected_id = quoted_printable_decode(substr($p, strlen($m)));
74 $Ajax->activate('_page_body');
83 //------------------------------------------------------------------------------
85 // Read numeric value from user formatted input
87 function input_num($postname=null, $dflt=0)
89 if (!isset($_POST[$postname]) || $_POST[$postname] == "")
92 return user_numeric($_POST[$postname]);
95 //---------------------------------------------------------------------------------
97 // Thanks to hidden fields buffering hidden() helper can be used in arbitrary places and
98 // proper html structure is still preserved. Buffered hidden fields are output on the nearest
99 // table or form closing tag (see output_hidden()).
101 $hidden_fields = array();
103 function hidden($name, $value=null, $echo=true)
105 global $Ajax, $hidden_fields;
108 $value = get_post($name);
110 $ret = "<input type=\"hidden\" name=\"$name\" value=\"$value\">";
111 $Ajax->addUpdate($name, $name, $value);
113 $hidden_fields[] = $ret;
118 Universal submit form button.
119 $atype - type of submit:
121 false - normal button; optional icon
122 null - button visible only in fallback mode; optional icon
124 true - standard button; optional icon
126 'default' - default form submit on Ctrl-Enter press; dflt ICON_OK icon
127 'selector' - ditto with closing current popup editor window
128 'cancel' - cancel form entry on Escape press; dflt ICON_CANCEL
129 'process' - displays progress bar during call; optional icon
130 'nonajax' - ditto, non-ajax submit
132 $atype can contain also multiply type selectors separated by space,
133 however make sense only combination of 'process' and one of defualt/selector/cancel
135 function submit($name, $value, $echo=true, $title=false, $atype=false, $icon=false)
137 global $path_to_root;
140 if ($atype === null) {
141 $aspect = fallback_mode() ? " aspect='fallback'" : " style='display:none;'";
143 } elseif (!is_bool($atype)) { // necessary: switch uses '=='
145 $aspect = " aspect='$atype' ";
146 $types = explode(' ', $atype);
148 foreach ($types as $type) {
151 $aspect = " aspect='selector' rel = '$value'";
152 $value = _("Select");
153 if ($icon===false) $icon=ICON_SUBMIT; break;
156 if ($icon===false) $icon=ICON_SUBMIT; break;
159 if ($icon===false) $icon=ICON_ESCAPE; break;
167 $submit_str = "<button class=\""
168 .($atype ? 'ajaxsubmit' : 'inputsubmit')
169 ."\" type=\"submit\""
171 ." name=\"$name\" id=\"$name\" value=\"$value\""
172 .($title ? " title='$title'" : '')
174 .($icon ? "<img src='$path_to_root/themes/".user_theme()."/images/$icon' height='12' alt=''>" : '')
175 ."<span>$value</span>"
183 function submit_center($name, $value, $echo=true, $title=false, $async=false, $icon=false)
185 if ($echo) echo "<center>";
186 submit($name, $value, $echo, $title, $async, $icon);
187 if ($echo) echo "</center>";
190 function submit_center_first($name, $value, $title=false, $async=false, $icon=false)
193 submit($name, $value, true, $title, $async, $icon);
197 function submit_center_last($name, $value, $title=false, $async=false, $icon=false)
200 submit($name, $value, true, $title, $async, $icon);
204 For following controls:
205 'both' - use both Ctrl-Enter and Escape hotkeys
206 'upgrade' - use Ctrl-Enter with progress ajax indicator and Escape hotkeys. Nonajax request for OK option is performed.
207 'cancel' - apply to 'RESET' button
209 function submit_add_or_update($add=true, $title=false, $async=false, $clone=false)
213 if ($async === 'both') {
214 $async = 'default'; $cancel = 'cancel';
216 elseif ($async === 'upgrade') {
217 $async = 'default nonajax process'; $cancel = 'cancel';
219 elseif ($async === 'default')
221 elseif ($async === 'cancel')
225 submit('ADD_ITEM', _("Add new"), true, $title, $async);
227 submit('UPDATE_ITEM', _("Update"), true, _('Submit changes'), $async);
228 if ($clone) submit('CLONE', _("Clone"), true,
229 _('Edit new record with current data'), $async);
230 submit('RESET', _("Cancel"), true, _('Cancel edition'), $cancel);
234 function submit_add_or_update_center($add=true, $title=false, $async=false, $clone=false)
237 submit_add_or_update($add, $title, $async, $clone);
241 function submit_add_or_update_row($add=true, $right=true, $extra="", $title=false, $async=false, $clone = false)
245 echo "<td> </td>\n";
247 submit_add_or_update($add, $title, $async, $clone);
251 function submit_cells($name, $value, $extra="", $title=false, $async=false)
254 submit($name, $value, true, $title, $async);
258 function submit_row($name, $value, $right=true, $extra="", $title=false, $async=false)
262 echo "<td> </td>\n";
263 submit_cells($name, $value, $extra, $title, $async);
267 function submit_return($name, $value, $title=false)
269 if (@$_REQUEST['popup']) {
270 submit($name, $value, true, $title, 'selector');
274 function submit_js_confirm($name, $msg, $set = true) {
276 $js = "_validate.$name=".($set ? "function(){ return confirm('"
277 . strtr($msg, array("\n"=>'\\n')) . "');};"
280 $Ajax->addScript(true, $js);
284 //-----------------------------------------------------------------------------------
286 function set_icon($icon, $title=false)
288 global $path_to_root;
289 if (basename($icon) === $icon) // standard icons does not contain path separator
290 $icon = "$path_to_root/themes/".user_theme()."/images/$icon";
291 return "<img src='$icon' style='vertical-align:middle;width:12px;height:12px;border:0;'".($title ? " title='$title'" : "")." >\n";
294 function button($name, $value, $title=false, $icon=false, $aspect='')
296 // php silently changes dots,spaces,'[' and characters 128-159
297 // to underscore in POST names, to maintain compatibility with register_globals
299 if ($aspect == 'selector') {
300 $rel = " rel='$value'";
301 $value = _("Select");
303 if (user_graphic_links() && $icon)
305 if ($value == _("Delete")) // Helper during implementation
307 return "<button type='submit' class='editbutton' name='"
308 .html_specials_encode(strtr($name, array('.'=>'=2E', '='=>'=3D',// ' '=>'=20','['=>'=5B'
310 ."' value='1'" . ($title ? " title='$title'":" title='$value'")
311 . ($aspect ? " aspect='$aspect'" : '')
313 ." >".set_icon($icon)."</button>\n";
316 return "<input type='submit' class='editbutton' name='"
317 .htmlentities(strtr($name, array('.'=>'=2E', '='=>'=3D',// ' '=>'=20','['=>'=5B'
320 .($title ? " title='$title'":'')
321 . ($aspect ? " aspect='$aspect'" : '')
326 function button_cell($name, $value, $title=false, $icon=false, $aspect='')
328 echo "<td align='center'>";
329 echo button($name, $value, $title, $icon, $aspect);
333 function delete_button_cell($name, $value, $title=false)
335 button_cell($name, $value, $title, ICON_DELETE);
338 function edit_button_cell($name, $value, $title=false)
340 button_cell($name, $value, $title, ICON_EDIT);
343 function select_button_cell($name, $value, $title=false)
345 button_cell($name, $value, $title, ICON_ADD, 'selector');
347 //-----------------------------------------------------------------------------------
349 function check_value($name)
351 return (empty($_POST[$name]) ? 0 : 1);
354 function checkbox($label, $name, $value=null, $submit_on_change=false, $title=false)
361 $str .= $label . " ";
362 if ($submit_on_change !== false) {
363 if ($submit_on_change === true)
365 "JsHttpRequest.request(\"_{$name}_update\", this.form);";
368 $value = get_post($name,0);
371 .($value == 1 ? ' checked':'')
372 ." type='checkbox' name='$name' value='1'"
373 .($submit_on_change ? " onclick='$submit_on_change'" : '')
374 .($title ? " title='$title'" : '')
377 $Ajax->addUpdate($name, $name, $value);
381 function check($label, $name, $value=null, $submit_on_change=false, $title=false)
383 echo checkbox($label, $name, $value, $submit_on_change, $title);
386 function check_cells($label, $name, $value=null, $submit_on_change=false, $title=false,
390 echo "<td>$label</td>\n";
392 echo check(null, $name, $value, $submit_on_change, $title);
396 function check_row($label, $name, $value=null, $submit_on_change=false, $title=false)
398 echo "<tr><td class='label'>$label</td>";
399 echo check_cells(NULL, $name, $value, $submit_on_change, $title);
403 //-----------------------------------------------------------------------------------
404 function radio($label, $name, $value, $selected=null, $submit_on_change=false)
406 if (!isset($selected))
407 $selected = get_post($name) === (string)$value;
409 if ($submit_on_change === true)
411 "JsHttpRequest.request(\"_{$name}_update\", this.form);";
413 return "<input type='radio' name=$name value='$value' ".($selected ? "checked":'')
414 .($submit_on_change ? " onclick='$submit_on_change'" : '')
415 .">".($label ? $label : '');
418 //-----------------------------------------------------------------------------------
419 function labelheader_cell($label, $params="")
421 echo "<td class='tableheader' $params>$label</td>\n";
424 function label_cell($label, $params="", $id=null)
430 $params .= " id='$id'";
431 $Ajax->addUpdate($id, $id, $label);
433 echo "<td $params>$label</td>\n";
438 function email_cell($label, $params="", $id=null)
440 label_cell("<a href='mailto:$label'>$label</a>", $params, $id);
443 function amount_decimal_cell($label, $params="", $id=null)
446 label_cell(price_decimal_format($label, $dec), "nowrap align=right ".$params, $id);
449 function amount_cell($label, $bold=false, $params="", $id=null)
452 label_cell("<b>".price_format($label)."</b>", "nowrap align=right ".$params, $id);
454 label_cell(price_format($label), "nowrap align=right ".$params, $id);
457 //JAM Allow entered unit prices to be fractional
458 function unit_amount_cell($label, $bold=false, $params="", $id=null)
461 label_cell("<b>".unit_price_format($label)."</b>", "nowrap align=right ".$params, $id);
463 label_cell(unit_price_format($label), "nowrap align=right ".$params, $id);
467 function percent_cell($label, $bold=false, $id=null)
470 label_cell("<b>".percent_format($label)."</b>", "nowrap align=right", $id);
472 label_cell(percent_format($label), "nowrap align=right", $id);
474 // 2008-06-15. Changed
475 function qty_cell($label, $bold=false, $dec=null, $id=null)
478 $dec = get_qty_dec();
480 label_cell("<b>".number_format2($label, $dec)."</b>", "nowrap align=right", $id);
482 label_cell(number_format2($label, $dec), "nowrap align=right", $id);
485 function label_cells($label, $value, $params="", $params2="", $id=null)
488 echo "<td $params>$label</td>\n";
489 label_cell($value, $params2, $id);
492 function label_row($label, $value, $params="", $params2="", $leftfill=0, $id=null)
497 echo "<td class='label'>$label</td>";
500 label_cells($label, $value, $params, $params2, $id);
502 echo "<td colspan=$leftfill></td>";
506 function text_input($name, $value=null, $size='', $max='', $title='', $params='')
509 $value = get_post($name);
511 return "<input $params type=\"text\" name=\"$name\" size=\"$size\" maxlength=\"$max\" value=\"$value\""
512 .($title ? " title='$title'" : '')
516 //-----------------------------------------------------------------------------------
518 function text_cells($label, $name, $value=null, $size="", $max="", $title=false,
519 $labparams="", $post_label="", $inparams="")
523 default_focus($name);
525 label_cell($label, $labparams);
528 echo text_input($name, $value, $size, $max, $title, $inparams);
530 if ($post_label != "")
531 echo " " . $post_label;
534 $Ajax->addUpdate($name, $name, $value);
537 function text_cells_ex($label, $name, $size, $max=null, $init=null, $title=null,
538 $labparams=null, $post_label=null, $submit_on_change=false)
542 default_focus($name);
543 if (!isset($_POST[$name]) || $_POST[$name] == "")
546 $_POST[$name] = $init;
551 label_cell($label, $labparams);
557 $class = $submit_on_change ? 'class="searchbox"' : '';
558 echo "<input $class type=\"text\" name=\"$name\" size=\"$size\" maxlength=\"$max\" value=\"" . $_POST[$name]. "\""
559 .($title ? " title='$title'": '')." >";
562 echo " " . $post_label;
565 $Ajax->addUpdate($name, $name, $_POST[$name]);
568 function text_row($label, $name, $value, $size, $max, $title=null, $params="", $post_label="")
570 echo "<tr><td class='label'>$label</td>";
571 text_cells(null, $name, $value, $size, $max, $title, $params, $post_label);
576 //-----------------------------------------------------------------------------------
578 function text_row_ex($label, $name, $size, $max=null, $title=null, $value=null, $params=null, $post_label=null)
580 echo "<tr><td class='label'>$label</td>";
581 text_cells_ex(null, $name, $size, $max, $value, $title, $params, $post_label);
586 //-----------------------------------------------------------------------------------
587 function email_row($label, $name, $value, $size, $max, $title=null, $params="", $post_label="")
590 $label = "<a href='Mailto:".$_POST[$name]."'>$label</a>";
591 text_row($label, $name, $value, $size, $max, $title, $params, $post_label);
594 function email_row_ex($label, $name, $size, $max=null, $title=null, $value=null, $params=null, $post_label=null)
597 $label = "<a href='Mailto:".$_POST[$name]."'>$label</a>";
598 text_row_ex($label, $name, $size, $max, $title, $value, $params, $post_label);
601 function link_row($label, $name, $value, $size, $max, $title=null, $params="", $post_label="")
603 $val = get_post($name);
605 if (strpos($val,'http://')===false)
606 $val = 'http://'.$val;
607 $label = "<a href='$val' target='_blank'>$label</a>";
609 text_row($label, $name, $value, $size, $max, $title, $params, $post_label);
612 function link_row_ex($label, $name, $size, $max=null, $title=null, $value=null, $params=null, $post_label=null)
614 $val = get_post($name);
616 if (strpos($val,'http://')===false)
617 $val = 'http://'.$val;
618 $label = "<a href='$val' target='_blank'>$label</a>";
620 text_row_ex($label, $name, $size, $max, $title, $value, $params, $post_label);
623 //-----------------------------------------------------------------------------------
625 // Since FA 2.2 $init parameter is superseded by $check.
626 // When $check!=null current date is displayed in red when set to other
627 // than current date.
629 function date_cells($label, $name, $title = null, $check=null, $inc_days=0,
630 $inc_months=0, $inc_years=0, $params=null, $submit_on_change=false)
632 global $path_to_root, $Ajax;
634 if (!isset($_POST[$name]) || $_POST[$name] == "")
636 if ($inc_years == 1001)
637 $_POST[$name] = null;
642 $dd = add_days($dd, $inc_days);
643 if ($inc_months != 0)
644 $dd = add_months($dd, $inc_months);
646 $dd = add_years($dd, $inc_years);
650 if (user_use_date_picker())
652 $calc_image = (file_exists("$path_to_root/themes/".user_theme()."/images/cal.gif")) ?
653 "$path_to_root/themes/".user_theme()."/images/cal.gif" : "$path_to_root/themes/default/images/cal.gif";
654 $post_label = "<a tabindex='-1' href=\"javascript:date_picker(document.getElementsByName('$name')[0]);\">"
655 . " <img src='$calc_image' style='vertical-align:middle;padding-bottom:4px;width:16px;height:16px;border:0;' alt='"._('Click Here to Pick up the date')."'></a>\n";
661 label_cell($label, $params);
665 $class = $submit_on_change ? 'date active' : 'date';
667 $aspect = $check ? 'aspect="cdate"' : '';
668 if ($check && (get_post($name) != Today()))
669 $aspect .= ' style="color:#FF0000"';
671 default_focus($name);
672 $size = (user_date_format()>3)?11:10;
673 echo "<input type=\"text\" name=\"$name\" class=\"$class\" $aspect size=\"$size\" maxlength=\"12\" value=\""
674 . $_POST[$name]. "\""
675 .($title ? " title='$title'": '')." > $post_label";
677 $Ajax->addUpdate($name, $name, $_POST[$name]);
680 function date_row($label, $name, $title=null, $check=null, $inc_days=0, $inc_months=0,
681 $inc_years=0, $params=null, $submit_on_change=false)
683 echo "<tr><td class='label'>$label</td>";
684 date_cells(null, $name, $title, $check, $inc_days, $inc_months,
685 $inc_years, $params, $submit_on_change);
689 //-----------------------------------------------------------------------------------
690 function password_row($label, $name, $value)
692 echo "<tr><td class='label'>$label</td>";
693 label_cell("<input type='password' name='$name' size=20 maxlength=20 value='$value' >");
697 //-----------------------------------------------------------------------------------
698 function file_cells($label, $name, $id="")
702 label_cells($label, "<input type='file' name='$name' $id >");
704 function file_row($label, $name, $id = "")
706 echo "<tr><td class='label'>$label</td>";
707 file_cells(null, $name, $id);
711 /*-----------------------------------------------------------------------------------
713 Reference number input.
715 Optional $context array contains transaction data used in number parsing:
716 'data' - data used for month/year codes
717 'location' - location code
718 'customer' - debtor_no
719 'supplier' - supplier id
720 'branch' - branch_code
722 function ref_cells($label, $name, $title=null, $init=null, $params=null, $submit_on_change=false, $type=null, $context=null)
727 if (empty($_POST[$name.'_list'])) // restore refline id
728 $_POST[$name.'_list'] = $Refs->reflines->find_refline_id(empty($_POST[$name]) ? $init : $_POST[$name], $type);
730 if (empty($_POST[$name])) // initialization
734 $_POST[$name] = $init;
736 $_POST[$name] = $Refs->get_next($type, $_POST[$name.'_list'], $context);
738 $Ajax->addUpdate(true, $name, $_POST[$name]);
741 if (check_ui_refresh($name)) { // call context changed
742 $_POST[$name] = $Refs->normalize($_POST[$name], $type, $context, $_POST[$name.'_list']);
743 $Ajax->addUpdate(true, $name, $_POST[$name]);
746 if ($Refs->reflines->count($type)>1) {
747 if (list_updated($name.'_list')) {
748 $_POST[$name] = $Refs->get_next($type, $_POST[$name.'_list'], $context);
749 $Ajax->addUpdate(true, $name, $_POST[$name]);
751 $list = refline_list($name.'_list', $type);
757 label_cell($label, $params);
759 label_cell($list."<input name='".$name."' "
760 .(check_edit_access($name) ? '' : 'disabled ')
761 ."value='".@$_POST[$name]."' size=16 maxlength=35>");
763 else // just wildcard ref field (e.g. for global inquires)
765 text_cells_ex($label, $name, 16, 35, $init, $title, $params, null, $submit_on_change);
769 //-----------------------------------------------------------------------------------
771 function ref_row($label, $name, $title=null, $init=null, $submit_on_change=false, $type=null, $context = null)
773 echo "<tr><td class='label'>$label</td>";
774 ref_cells(null, $name, $title, $init, null, $submit_on_change, $type, $context);
778 //-----------------------------------------------------------------------------------
780 function percent_row($label, $name, $init=null)
783 if (!isset($_POST[$name]) || $_POST[$name]=="")
785 $_POST[$name] = $init == null ? '' : $init;
788 small_amount_row($label, $name, $_POST[$name], null, "%", user_percent_dec());
791 function amount_cells_ex($label, $name, $size, $max=null, $init=null, $params=null, $post_label=null, $dec=null)
796 $dec = user_price_dec();
797 if (!isset($_POST[$name]) || $_POST[$name] == "")
800 $_POST[$name] = $init;
807 $params = "class='label'";
808 label_cell($label, $params);
816 echo "<td align='right'>";
818 echo "<input class='amount' type=\"text\" name=\"$name\" size=\"$size\" maxlength=\"$max\" dec=\"$dec\" value=\"" . $_POST[$name]. "\">";
821 echo "<span id='_{$name}_label'> $post_label</span>";
822 $Ajax->addUpdate($name, '_'.$name.'_label', $post_label);
825 $Ajax->addUpdate($name, $name, $_POST[$name]);
826 $Ajax->addAssign($name, $name, 'dec', $dec);
830 //-----------------------------------------------------------------------------------
832 function amount_cells($label, $name, $init=null, $params=null, $post_label=null, $dec=null)
834 amount_cells_ex($label, $name, 15, 15, $init, $params, $post_label, $dec);
837 //JAM Allow entered unit prices to be fractional
838 function unit_amount_cells($label, $name, $init=null, $params=null, $post_label=null, $dec=null)
841 $dec = user_price_dec()+2;
843 amount_cells_ex($label, $name, 15, 15, $init, $params, $post_label, $dec+2);
846 function amount_row($label, $name, $init=null, $params=null, $post_label=null, $dec=null)
849 amount_cells($label, $name, $init, $params, $post_label, $dec);
853 function small_amount_row($label, $name, $init=null, $params=null, $post_label=null, $dec=null)
856 small_amount_cells($label, $name, $init, $params, $post_label, $dec);
860 //-----------------------------------------------------------------------------------
862 function qty_cells($label, $name, $init=null, $params=null, $post_label=null, $dec=null)
865 $dec = user_qty_dec();
867 amount_cells_ex($label, $name, 15, 15, $init, $params, $post_label, $dec);
870 function qty_row($label, $name, $init=null, $params=null, $post_label=null, $dec=null)
873 $dec = user_qty_dec();
876 amount_cells($label, $name, $init, $params, $post_label, $dec);
880 function small_qty_row($label, $name, $init=null, $params=null, $post_label=null, $dec=null)
883 $dec = user_qty_dec();
886 small_amount_cells($label, $name, $init, $params, $post_label, $dec);
890 //-----------------------------------------------------------------------------------
892 function small_amount_cells($label, $name, $init=null, $params=null, $post_label=null, $dec=null)
894 amount_cells_ex($label, $name, 7, 12, $init, $params, $post_label, $dec);
897 //-----------------------------------------------------------------------------------
899 function small_qty_cells($label, $name, $init=null, $params=null, $post_label=null, $dec=null)
902 $dec = user_qty_dec();
903 amount_cells_ex($label, $name, 7, 12, $init, $params, $post_label, $dec);
906 //-----------------------------------------------------------------------------------
908 function textarea_cells($label, $name, $value, $cols, $rows, $title = null, $params="")
912 default_focus($name);
914 echo "<td $params>$label</td>\n";
916 $value = (!isset($_POST[$name]) ? "" : $_POST[$name]);
917 echo "<td><textarea name='$name' cols='$cols' rows='$rows'"
918 .($title ? " title='$title'" : '')
919 .">$value</textarea></td>\n";
920 $Ajax->addUpdate($name, $name, $value);
923 function textarea_row($label, $name, $value, $cols, $rows, $title=null, $params="")
925 echo "<tr><td class='label'>$label</td>";
926 textarea_cells(null, $name, $value, $cols, $rows, $title, $params);
930 //-----------------------------------------------------------------------------------
932 // When show_inactive page option is set
933 // displays value of inactive field as checkbox cell.
934 // Also updates database record after status change.
936 function inactive_control_cell($id, $value, $table, $key)
940 $name = "Inactive". $id;
941 $value = $value ? 1:0;
943 if (check_value('show_inactive')) {
944 if (isset($_POST['LInact'][$id]) && (get_post('_Inactive'.$id.'_update') ||
945 get_post('Update')) && (check_value('Inactive'.$id) != $value)) {
946 update_record_status($id, !$value, $table, $key);
948 echo '<td align="center">'. checkbox(null, $name, $value, true, '')
949 . hidden("LInact[$id]", $value, false) . '</td>';
953 // Displays controls for optional display of inactive records
955 function inactive_control_row($th) {
956 echo "<tr><td colspan=".(count($th)).">"
957 ."<div style='float:left;'>"
958 . checkbox(null, 'show_inactive', null, true). _("Show also Inactive")
959 ."</div><div style='float:right;'>"
960 . submit('Update', _('Update'), false, '', null)
964 // Inserts additional column header when display of inactive records is on.
966 function inactive_control_column(&$th) {
969 if (check_value('show_inactive'))
970 array_insert($th, count($th)-2 , _("Inactive"));
971 if (get_post('_show_inactive_update')) {
972 $Ajax->activate('_page_body');
976 function customer_credit_row($customer, $credit, $parms='')
978 global $path_to_root;
980 label_row( _("Current Credit:"),
981 "<a target='_blank' " . ($credit<0 ? 'class="redfg"' : '')
982 ."href='$path_to_root/sales/inquiry/customer_inquiry.php?customer_id=".$customer."'"
983 ." onclick=\"javascript:openWindow(this.href,this.target); return false;\" >"
984 . price_format($credit)
988 function supplier_credit_row($supplier, $credit, $parms='')
990 global $path_to_root;
992 label_row( _("Current Credit:"),
993 "<a target='_blank' " . ($credit<0 ? 'class="redfg"' : '')
994 ."href='$path_to_root/purchasing/inquiry/supplier_inquiry.php?supplier_id=".$supplier."'"
995 ." onclick=\"javascript:openWindow(this.href,this.target); return false;\" >"
996 . price_format($credit)
1000 function bank_balance_row($bank_acc, $parms='')
1002 global $path_to_root;
1004 $to = add_days(Today(), 1);
1005 $bal = get_balance_before_for_bank_account($bank_acc, $to);
1006 label_row( _("Bank Balance:"),
1007 "<a target='_blank' " . ($bal<0 ? 'class="redfg"' : '')
1008 ."href='$path_to_root/gl/inquiry/bank_inquiry.php?bank_account=".$bank_acc."'"
1009 ." onclick=\"javascript:openWindow(this.href,this.target); return false;\" > "
1010 . price_format($bal)
1014 function ahref($label, $href, $target="", $onclick="") {
1015 echo "<a href='$href' target='$target' onclick='$onclick'>$label</a>";
1018 function ahref_cell($label, $href, $target="", $onclick="") {
1019 echo "<td align='center'> ";
1020 ahref($label, $href, $target, $onclick);
1021 echo " </td>";