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;
40 //------------------------------------------------------------------------------
42 // Helper function for simple db table editor pages
44 function simple_page_mode($numeric_id = true)
46 global $Ajax, $Mode, $selected_id;
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');
54 $selected_id = $default;
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');
73 //------------------------------------------------------------------------------
75 // Read numeric value from user formatted input
77 function input_num($postname=null, $dflt=null)
79 if (!isset($_POST[$postname]) || $_POST[$postname] == "")
82 return user_numeric($_POST[$postname]);
85 //---------------------------------------------------------------------------------
87 function hidden($name, $value=null, $echo=true)
92 $value = get_post($name);
94 $ret = "<input type=\"hidden\" name=\"$name\" value=\"$value\">";
95 $Ajax->addUpdate($name, $name, $value);
102 Universal submit form button.
103 $atype - type of submit:
105 false - normal button; optional icon
106 null - button visible only in fallback mode; optional icon
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
113 function submit($name, $value, $echo=true, $title=false, $atype=false, $icon=false)
115 global $path_to_root;
118 if (!is_bool($atype)) // necessary: switch uses '=='
121 $aspect = " aspect='process'"; break;
123 $aspect = " aspect='default'";
124 if ($icon===false) $icon=ICON_SUBMIT; break;
126 $aspect = " aspect='cancel'";
127 if ($icon===false) $icon=ICON_ESCAPE; break;
129 $aspect = fallback_mode() ?
130 " aspect='fallback'" : " style='display:none;'"; break;
133 default_focus($name);
134 $submit_str = "<button class=\""
135 .($atype ? 'ajaxsubmit' : 'inputsubmit')
136 ."\" type=\"submit\""
138 ." name=\"$name\" id=\"$name\" value=\"$value\""
139 .($title ? " title='$title'" : '')
141 .($icon ? "<img src='$path_to_root/themes/".user_theme()."/images/$icon'>" : '')
142 ."<span>$value</span>"
150 function submit_center($name, $value, $echo=true, $title=false, $async=false, $icon=false)
153 submit($name, $value, $echo, $title, $async, $icon);
157 function submit_center_first($name, $value, $title=false, $async=false, $icon=false)
160 submit($name, $value, true, $title, $async, $icon);
164 function submit_center_last($name, $value, $title=false, $async=false, $icon=false)
167 submit($name, $value, true, $title, $async, $icon);
171 function submit_add_or_update($add=true, $title=false, $async=false)
174 submit('ADD_ITEM', _("Add new"), true, $title, $async);
176 submit('UPDATE_ITEM', _("Update"), true, $title, $async);
177 submit('RESET', _("Cancel"), true, $title, $async);
181 function submit_add_or_update_center($add=true, $title=false, $async=false)
184 submit_add_or_update($add, $title, $async);
189 function submit_add_or_update_row($add=true)
191 echo "<tr><td colspan=99 align=center>";
192 submit_add_or_update($add);
196 function submit_add_or_update_row($add=true, $right=true, $extra="", $title=false, $async=false)
200 echo "<td> </td>\n";
202 submit_add_or_update($add, $title, $async);
206 function submit_cells($name, $value, $extra="", $title=false, $async=false)
209 submit($name, $value, true, $title, $async);
213 function submit_row($name, $value, $right=true, $extra="", $title=false, $async=false)
217 echo "<td> </td>\n";
218 submit_cells($name, $value, $extra, $title, $async);
222 function submit_return($name, $value, $title=false, $async=false)
224 if (count($_SESSION['Context'])) {
225 submit($name, $value, true, $title, $async);
228 //-----------------------------------------------------------------------------------
230 function set_icon($icon, $title=false)
232 global $path_to_root;
233 return "<img src='$path_to_root/themes/".user_theme()."/images/$icon' width='14' height='14' border='0'".($title ? " title='$title'" : "")." />\n";
236 function button($name, $value, $title=false, $icon=false)
238 // php silently changes dots,spaces,'[' and characters 128-159
239 // to underscore in POST names, to maintain compatibility with register_globals
240 if (user_graphic_links() && $icon)
242 if ($value == _("Delete")) // Helper during implementation
244 return "<button type='submit' class='editbutton' name='".
245 htmlentities(strtr($name, array('.'=>'=2E',' '=>'=20','='=>'=3D','['=>'=5B'))).
246 "' value='1'" . ($title ? " title='$title'":" title='$value'")." />".set_icon($icon)."\n";
249 return "<input type='submit' class='editbutton' name='"
250 .htmlentities(strtr($name, array('.'=>'=2E',' '=>'=20','='=>'=3D','['=>'=5B')))
252 .($title ? " title='$title'":'')." />\n";
255 function button_cell($name, $value, $title=false, $icon=false)
258 echo button($name, $value, $title, $icon);
262 function delete_button_cell($name, $value, $title=false)
264 button_cell($name, $value, $title, ICON_DELETE);
267 function edit_button_cell($name, $value, $title=false)
269 button_cell($name, $value, $title, ICON_EDIT);
271 //-----------------------------------------------------------------------------------
273 function check_value($name)
275 if (!isset($_POST[$name]))
280 function checkbox($label, $name, $value=null, $submit_on_change=false, $title=false)
285 default_focus($name);
287 $str .= $label . " ";
288 if ($submit_on_change !== false) {
289 if ($submit_on_change === true)
291 "JsHttpRequest.request(\"_{$name}_update\", this.form);";
294 $value = get_post($name,0);
297 .($value == 1 ? ' checked':'')
298 ." type='checkbox' name='$name' value='1'"
299 .($submit_on_change ? " onclick='$submit_on_change'" : '')
300 .($title ? " title='$title'" : '')
303 $Ajax->addUpdate($name, $name, $value);
307 function check($label, $name, $value=null, $submit_on_change=false, $title=false)
309 echo checkbox($label, $name, $value, $submit_on_change, $title);
312 function check_cells($label, $name, $value, $submit_on_change=false, $title=false)
315 echo "<td>$label</td>\n";
317 echo check(null, $name, $value, $submit_on_change, $title);
321 function check_row($label, $name, $value, $submit_on_change=false, $title=false)
324 echo check_cells($label, $name, $value, $submit_on_change, $title);
328 //-----------------------------------------------------------------------------------
330 function labelheader_cell($label, $params="")
332 echo "<td class='tableheader' $params>$label</td>\n";
335 function label_cell($label, $params="", $id=null)
341 $params .= " id='$id'";
342 $Ajax->addUpdate($id, $id, $label);
344 echo "<td $params>$label</td>\n";
349 function email_cell($label, $params="", $id=null)
351 label_cell("<a href='mailto:$label'>$label</a>", $params, $id);
354 function amount_cell($label, $bold=false, $params="", $id=null)
357 label_cell("<b>".price_format($label)."</b>", "nowrap align=right ".$params, $id);
359 label_cell(price_format($label), "nowrap align=right ".$params, $id);
362 function percent_cell($label, $bold=false, $id=null)
365 label_cell("<b>".percent_format($label)."</b>", "nowrap align=right", $id);
367 label_cell(percent_format($label), "nowrap align=right", $id);
369 // 2008-06-15. Changed
370 function qty_cell($label, $bold=false, $dec=null, $id=null)
373 $dec = get_qty_dec();
375 label_cell("<b>".number_format2($label, $dec)."</b>", "nowrap align=right", $id);
377 label_cell(number_format2($label, $dec), "nowrap align=right", $id);
380 function label_cells($label, $value, $params="", $params2="", $id='')
383 echo "<td $params>$label</td>\n";
384 label_cell($value, $params2, $id);
387 function label_row($label, $value, $params="", $params2="", $leftfill=0, $id='')
390 label_cells($label, $value, $params, $params2, $id);
392 echo "<td colspan=$leftfill></td>";
396 //-----------------------------------------------------------------------------------
398 function text_cells($label, $name, $value=null, $size="", $max="", $title=false, $params="", $post_label="", $disabled="")
402 default_focus($name);
404 label_cell($label, $params);
408 $value = get_post($name);
409 echo "<input $disabled type=\"text\" name=\"$name\" size=\"$size\" maxlength=\"$max\" value=\"$value\""
410 .($title ? " title='$title'" : '')
413 if ($post_label != "")
414 echo " " . $post_label;
417 $Ajax->addUpdate($name, $name, $value);
420 function text_cells_ex($label, $name, $size, $max=null, $init=null, $title=null, $params=null, $post_label=null, $submit_on_change=false)
424 default_focus($name);
425 if (!isset($_POST[$name]) || $_POST[$name] == "")
428 $_POST[$name] = $init;
433 label_cell($label, $params);
439 $class = $submit_on_change ? 'class="searchbox"' : '';
440 echo "<input $class type=\"text\" name=\"$name\" size=\"$size\" maxlength=\"$max\" value=\"" . $_POST[$name]. "\""
441 .($title ? " title='$title'": '')." >";
444 echo " " . $post_label;
447 $Ajax->addUpdate($name, $name, $_POST[$name]);
450 function text_row($label, $name, $value, $size, $max, $title=null, $params="", $post_label="")
454 text_cells($label, $name, $value, $size, $max, $title, $params, $post_label);
459 //-----------------------------------------------------------------------------------
461 function text_row_ex($label, $name, $size, $max=null, $title=null, $value=null, $params=null, $post_label=null)
465 text_cells_ex($label, $name, $size, $max, $value, $title, $params, $post_label);
470 //-----------------------------------------------------------------------------------
471 function email_row($label, $name, $value, $size, $max, $title=null, $params="", $post_label="")
473 text_row("<a href='Mailto:".$_POST[$name]."'>$label</a>", $name, $value, $size, $max, $title, $params, $post_label);
476 function email_row_ex($label, $name, $size, $max=null, $title=null, $value=null, $params=null, $post_label=null)
478 text_row_ex("<a href='Mailto:".$_POST[$name]."'>$label</a>", $name, $size, $max, $title, $value, $params, $post_label);
481 function link_row($label, $name, $value, $size, $max, $title=null, $params="", $post_label="")
483 text_row("<a href='".$_POST[$name]."' target='_blank'>$label</a>", $name, $value, $size, $max, $title, $params, $post_label);
486 function link_row_ex($label, $name, $size, $max=null, $title=null, $value=null, $params=null, $post_label=null)
488 text_row_ex("<a href='".$_POST[$name]."' target='_blank'>$label</a>", $name, $size, $max, $title, $value, $params, $post_label);
491 //-----------------------------------------------------------------------------------
493 function date_cells($label, $name, $title = null, $init=null, $inc_days=0,
494 $inc_months=0, $inc_years=0, $params=null, $submit_on_change=false)
496 global $use_date_picker, $path_to_root;
497 if (!isset($_POST[$name]) || $_POST[$name] == "")
501 if ($inc_years == 1001)
502 $_POST[$name] = null;
507 $dd = add_days($dd, $inc_days);
508 if ($inc_months != 0)
509 $dd = add_months($dd, $inc_months);
511 $dd = add_years($dd, $inc_years);
516 $_POST[$name] = $init;
518 if ($use_date_picker)
519 $post_label = "<a tabindex='-1' href=\"javascript:date_picker(document.getElementsByName('$name')[0]);\">"
520 . " <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";
523 text_cells_ex($label, $name, 9, 12, $_POST[$name], $title, $params, $post_label, $submit_on_change);
526 function date_row($label, $name, $title=null, $init=null, $inc_days=0, $inc_months=0,
527 $inc_years=0, $params=null, $submit_on_change=false)
530 date_cells($label, $name, $title, $init, $inc_days, $inc_months,
531 $inc_years, $params, $submit_on_change);
535 //-----------------------------------------------------------------------------------
537 function ref_cells($label, $name, $title=null, $init=null, $params=null, $submit_on_change=false)
539 text_cells_ex($label, $name, 16, 18, $init, $title, $params, null, $submit_on_change);
542 //-----------------------------------------------------------------------------------
544 function ref_row($label, $name, $title=null, $init=null, $submit_on_change=false)
547 ref_cells($label, $name, $title, $init, null, $submit_on_change);
551 //-----------------------------------------------------------------------------------
553 function percent_row($label, $name, $init=null)
556 if (!isset($_POST[$name]) || $_POST[$name]=="")
558 $_POST[$name] = $init == null ? '' : $init;
561 small_amount_row($label, $name, $_POST[$name], null, "%", user_percent_dec());
564 function amount_cells_ex($label, $name, $size, $max=null, $init=null, $params=null, $post_label=null, $dec=null)
569 $dec = user_price_dec();
570 if (!isset($_POST[$name]) || $_POST[$name] == "")
573 $_POST[$name] = $init;
578 label_cell($label, $params);
586 echo "<td align='right'>";
588 echo "<input class='amount' type=\"text\" name=\"$name\" size=\"$size\" maxlength=\"$max\" dec=\"$dec\" value=\"" . $_POST[$name]. "\">";
591 echo "<span id='_{$name}_label'> $post_label</span>";
592 $Ajax->addUpdate($name, '_'.$name.'_label', $post_label);
595 $Ajax->addUpdate($name, $name, $_POST[$name]);
596 $Ajax->addAssign($name, $name, 'dec', $dec);
600 //-----------------------------------------------------------------------------------
602 function amount_cells($label, $name, $init=null, $params=null, $post_label=null, $dec=null)
604 amount_cells_ex($label, $name, 15, 15, $init, $params, $post_label, $dec);
607 function amount_row($label, $name, $init=null, $params=null, $post_label=null, $dec=null)
610 amount_cells($label, $name, $init, $params, $post_label, $dec);
614 function small_amount_row($label, $name, $init=null, $params=null, $post_label=null, $dec=null)
617 small_amount_cells($label, $name, $init, $params, $post_label, $dec);
621 //-----------------------------------------------------------------------------------
623 function qty_cells($label, $name, $init=null, $params=null, $post_label=null, $dec=null)
626 $dec = user_qty_dec();
628 amount_cells_ex($label, $name, 15, 15, $init, $params, $post_label, $dec);
631 function qty_row($label, $name, $init=null, $params=null, $post_label=null, $dec=null)
634 $dec = user_qty_dec();
637 amount_cells($label, $name, $init, $params, $post_label, $dec);
641 function small_qty_row($label, $name, $init=null, $params=null, $post_label=null, $dec=null)
644 $dec = user_qty_dec();
647 small_amount_cells($label, $name, $init, $params, $post_label, $dec);
651 //-----------------------------------------------------------------------------------
653 function small_amount_cells($label, $name, $init=null, $params=null, $post_label=null, $dec=null)
655 amount_cells_ex($label, $name, 7, 12, $init, $params, $post_label, $dec);
658 //-----------------------------------------------------------------------------------
660 function small_qty_cells($label, $name, $init=null, $params=null, $post_label=null, $dec=null)
663 $dec = user_qty_dec();
664 amount_cells_ex($label, $name, 7, 12, $init, $params, $post_label, $dec);
667 //-----------------------------------------------------------------------------------
669 function textarea_cells($label, $name, $value, $cols, $rows, $title = null, $params="")
673 default_focus($name);
675 echo "<td $params>$label</td>\n";
677 $value = (!isset($_POST[$name]) ? "" : $_POST[$name]);
678 echo "<td><textarea name='$name' cols='$cols' rows='$rows'"
679 .($title ? " title='$title'" : '')
680 .">$value</textarea></td>\n";
681 $Ajax->addUpdate($name, $name, $value);
684 function textarea_row($label, $name, $value, $cols, $rows, $title=null, $params="")
687 textarea_cells($label, $name, $value, $cols, $rows, $title, $params);
691 //-----------------------------------------------------------------------------------
693 function text_row_with_submit($label, $name, $value, $size, $max, $input_name, $input_value)
697 default_focus($name);
698 echo "<tr><td>$label</td>\n";
702 $value = (!isset($_POST[$name]) ? "" : $_POST[$name]);
703 echo "<input type=\"text\" name=\"$name\" size=\"$size\" maxlength=\"$max\" value=\"$value\"> ";
705 submit($input_name, $input_value);
708 $Ajax->addUpdate($name, $name, $value);
711 //-----------------------------------------------------------------------------------