3 function get_post($name, $dflt='')
5 return ((!isset($_POST[$name]) || $_POST[$name] === '') ? $dflt : $_POST[$name]);
8 // Sets local POST value and adds Value to ajax posting if needed
10 /*function set_post($name, $value, $ajax_trigger=true) {
13 $_POST[$name] = $value;
14 if ($ajax_trigger) $Ajax->activate($name);
17 //------------------------------------------------------------------------------
18 // Seek for _POST variable with $prefix.
19 // If var is found returns variable name with prefix stripped,
20 // and null or -1 otherwise.
22 function find_submit($prefix, $numeric=true)
25 foreach($_POST as $postkey=>$postval )
27 if (strpos($postkey, $prefix) === 0)
29 $id = substr($postkey, strlen($prefix));
30 return $numeric ? (int)$id : $id;
33 return $numeric ? -1 : null;
35 //------------------------------------------------------------------------------
37 // Helper function for simple db table editor pages
39 function simple_page_mode($numeric_id = true)
41 global $Ajax, $Mode, $selected_id;
43 $default = $numeric_id ? -1 : '';
44 $selected_id = get_post('selected_id', $default);
45 foreach (array('ADD_ITEM', 'UPDATE_ITEM', 'RESET') as $m) {
46 if (isset($_POST[$m])) {
47 $Ajax->activate('_page_body');
49 $selected_id = $default;
53 foreach (array('Edit', 'Delete') as $m) {
54 foreach ($_POST as $p => $pvar) {
55 if (strpos($p, $m) === 0) {
56 // $selected_id = strtr(substr($p, strlen($m)), array('%2E'=>'.'));
57 unset($_POST['_focus']); // focus on first form entry
58 $selected_id = quoted_printable_decode(substr($p, strlen($m)));
59 $Ajax->activate('_page_body');
68 //------------------------------------------------------------------------------
70 // Read numeric value from user formatted input
72 function input_num($postname=null, $dflt=null)
74 if (!isset($_POST[$postname]))
77 return user_numeric($_POST[$postname]);
80 //---------------------------------------------------------------------------------
82 function hidden($name, $value=null, $echo=true)
87 $value = get_post($name);
89 $ret = "<input type=\"hidden\" name=\"$name\" value=\"$value\">";
90 $Ajax->addUpdate($name, $name, $value);
97 //---------------------------------------------------------------------------------
99 // $async parameter can have 3 values:
100 // null - fallback button not visible in js enabled mode
101 // false - normal submit via form action
102 // true - when js is on submition via ajax call
103 // 'process' - ditto with processing indicator in msgbox
105 function submit($name, $value, $echo=true, $title=false, $async=false)
108 default_focus($name);
109 $submit_str = "<input type=\"submit\" class=\""
110 .($async ? 'ajaxsubmit' : 'inputsubmit')
112 .($async === null ? (in_ajax() ? " style='display:none;'" : ' aspect="fallback"' ):
113 ($async === 'process' ? 'aspect="process"' : '') )
114 ." name=\"$name\" id=\"$name\" value=\"$value\""
115 .($title ? " title='$title'" : '')
123 function submit_center($name, $value, $echo=true, $title=false, $async=false)
126 submit($name, $value, $echo, $title, $async);
130 function submit_center_first($name, $value, $title=false, $async=false)
133 submit($name, $value, true, $title, $async);
137 function submit_center_last($name, $value, $title=false, $async=false)
140 submit($name, $value, true, $title, $async);
144 function submit_add_or_update($add=true, $title=false, $async=false)
147 submit('ADD_ITEM', _("Add new"), true, $title, $async);
149 submit('UPDATE_ITEM', _("Update"), true, $title, $async);
150 submit('RESET', _("Cancel"), true, $title, $async);
154 function submit_add_or_update_center($add=true, $title=false, $async=false)
157 submit_add_or_update($add, $title, $async);
162 function submit_add_or_update_row($add=true)
164 echo "<tr><td colspan=99 align=center>";
165 submit_add_or_update($add);
169 function submit_add_or_update_row($add=true, $right=true, $extra="", $title=false, $async=false)
173 echo "<td> </td>\n";
175 submit_add_or_update($add, $title, $async);
179 function submit_cells($name, $value, $extra="", $title=false, $async=false)
182 submit($name, $value, true, $title, $async);
186 function submit_row($name, $value, $right=true, $extra="", $title=false, $async=false)
190 echo "<td> </td>\n";
191 submit_cells($name, $value, $extra, $title, $async);
194 //---------------------------------------------------------------------------------
196 function button($name, $value, $onclick, $title=false)
198 default_focus($name);
199 echo "<input type=\"button\" class=\"inputsubmit\" name=\"$name\" value=\"$value\" onclick=\"$onclick\""
200 .($title ? " title='$title'" : '')
204 function button_cell($name, $value, $onclick, $title=false)
207 button($name, $value, $onclick, $title);
211 //-----------------------------------------------------------------------------------
213 function check_value($name)
215 if (!isset($_POST[$name]))
220 function check($label, $name, $value=null, $submit_on_change=false, $title=false)
224 default_focus($name);
229 $value = get_post($name,0);
232 .($value == 1 ? ' checked':'')
233 ." type='checkbox' name='$name' value='1'"
234 .($submit_on_change ? " onclick='JsHttpRequest.request(\"_{$name}_update\", this.form);'" : '')
235 .($title ? " title='$title'" : '')
237 $Ajax->addUpdate($name, $name, $value);
240 function check_cells($label, $name, $value, $submit_on_change=false, $title=false)
243 echo "<td>$label</td>\n";
245 check(null, $name, $value, $submit_on_change, $title);
249 function check_row($label, $name, $value, $submit_on_change=false, $title=false)
252 check_cells($label, $name, $value, $submit_on_change, $title);
256 //-----------------------------------------------------------------------------------
258 function labelheader_cell($label, $params="")
260 echo "<td class='tableheader' $params>$label</td>\n";
263 function label_cell($label, $params="", $id=null)
269 $params .= " id='$id'";
270 $Ajax->addUpdate($id, $id, $label);
272 echo "<td $params>$label</td>\n";
277 function amount_cell($label, $bold=false, $params="", $id=null)
280 label_cell("<b>".price_format($label)."</b>", "nowrap align=right ".$params, $id);
282 label_cell(price_format($label), "nowrap align=right ".$params, $id);
285 function percent_cell($label, $bold=false, $id=null)
288 label_cell("<b>".percent_format($label)."</b>", "nowrap align=right", $id);
290 label_cell(percent_format($label), "nowrap align=right", $id);
292 // 2008-06-15. Changed
293 function qty_cell($label, $bold=false, $dec=null, $id=null)
296 $dec = get_qty_dec();
298 label_cell("<b>".number_format2($label, $dec)."</b>", "nowrap align=right", $id);
300 label_cell(number_format2($label, $dec), "nowrap align=right", $id);
303 function label_cells($label, $value, $params="", $params2="")
306 echo "<td $params>$label</td>\n";
307 echo "<td $params2>$value</td>\n";
310 function label_row($label, $value, $params="", $params2="", $leftfill=0)
313 label_cells($label, $value, $params, $params2);
315 echo "<td colspan=$leftfill></td>";
319 //-----------------------------------------------------------------------------------
321 function text_cells($label, $name, $value=null, $size="", $max="", $title=false, $params="", $post_label="", $disabled="")
325 default_focus($name);
327 label_cell($label, $params);
331 $value = get_post($name);
332 echo "<input $disabled type=\"text\" name=\"$name\" size=\"$size\" maxlength=\"$max\" value=\"$value\""
333 .($title ? " title='$title'" : '')
336 if ($post_label != "")
337 echo " " . $post_label;
340 $Ajax->addUpdate($name, $name, $value);
343 function text_cells_ex($label, $name, $size, $max=null, $init=null, $title=null, $params=null, $post_label=null, $submit_on_change=false)
347 default_focus($name);
348 if (!isset($_POST[$name]) || $_POST[$name] == "")
351 $_POST[$name] = $init;
356 label_cell($label, $params);
362 $class = $submit_on_change ? 'class="searchbox"' : '';
363 echo "<input $class type=\"text\" name=\"$name\" size=\"$size\" maxlength=\"$max\" value=\"" . $_POST[$name]. "\""
364 .($title ? " title='$title'": '')." >";
367 echo " " . $post_label;
370 $Ajax->addUpdate($name, $name, $_POST[$name]);
373 function text_row($label, $name, $value, $size, $max, $title=null, $params="", $post_label="")
377 text_cells($label, $name, $value, $size, $max, $title, $params, $post_label);
382 //-----------------------------------------------------------------------------------
384 function text_row_ex($label, $name, $size, $max=null, $title=null, $value=null, $params=null, $post_label=null)
388 text_cells_ex($label, $name, $size, $max, $value, $title, $params, $post_label);
393 //-----------------------------------------------------------------------------------
395 function date_cells($label, $name, $title = null, $init=null, $inc_days=0, $inc_months=0, $inc_years=0, $params=null)
397 global $use_date_picker, $path_to_root;
398 if (!isset($_POST[$name]) || $_POST[$name] == "")
402 if ($inc_years == 1001)
403 $_POST[$name] = null;
408 $dd = add_days($dd, $inc_days);
409 if ($inc_months != 0)
410 $dd = add_months($dd, $inc_months);
412 $dd = add_years($dd, $inc_years);
417 $_POST[$name] = $init;
419 if ($use_date_picker)
420 $post_label = "<a tabindex='-1' href=\"javascript:date_picker(document.getElementsByName('$name')[0]);\">"
421 . " <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";
424 text_cells_ex($label, $name, 9, 12, $_POST[$name], $title, $params, $post_label);
427 function date_row($label, $name, $title=null, $init=null, $inc_days=0, $inc_months=0, $inc_years=0, $params=null)
430 date_cells($label, $name, $title, $init, $inc_days, $inc_months, $inc_years, $params);
434 //-----------------------------------------------------------------------------------
436 function ref_cells($label, $name, $title=null, $init=null, $params=null, $submit_on_change=false)
438 text_cells_ex($label, $name, 16, 18, $init, $title, $params, null, $submit_on_change);
441 //-----------------------------------------------------------------------------------
443 function ref_row($label, $name, $title=null, $init=null, $submit_on_change=false)
446 ref_cells($label, $name, $title, $init, null, $submit_on_change);
450 //-----------------------------------------------------------------------------------
452 function percent_row($label, $name, $init=null)
455 if (!isset($_POST[$name]) || $_POST[$name]=="")
457 $_POST[$name] = $init == null ? '' : $init;
460 small_amount_row($label, $name, $_POST[$name], null, "%", user_percent_dec());
463 function amount_cells_ex($label, $name, $size, $max=null, $init=null, $params=null, $post_label=null, $dec=null)
468 $dec = user_price_dec();
469 if (!isset($_POST[$name]) || $_POST[$name] == "")
472 $_POST[$name] = $init;
477 label_cell($label, $params);
484 echo "<input class='amount' type=\"text\" name=\"$name\" size=\"$size\" maxlength=\"$max\" dec=\"$dec\" value=\"" . $_POST[$name]. "\">";
487 echo " " . $post_label;
490 $Ajax->addUpdate($name, $name, $_POST[$name]);
491 $Ajax->addAssign($name, $name, 'dec', $dec);
495 //-----------------------------------------------------------------------------------
497 function amount_cells($label, $name, $init=null, $params=null, $post_label=null, $dec=null)
499 amount_cells_ex($label, $name, 15, 15, $init, $params, $post_label, $dec);
502 function amount_row($label, $name, $init=null, $params=null, $post_label=null, $dec=null)
505 amount_cells($label, $name, $init, $params, $post_label, $dec);
509 function small_amount_row($label, $name, $init=null, $params=null, $post_label=null, $dec=null)
512 small_amount_cells($label, $name, $init, $params, $post_label, $dec);
516 //-----------------------------------------------------------------------------------
518 function qty_cells($label, $name, $init=null, $params=null, $post_label=null, $dec=null)
521 $dec = user_qty_dec();
523 amount_cells_ex($label, $name, 15, 15, $init, $params, $post_label, $dec);
526 function qty_row($label, $name, $init=null, $params=null, $post_label=null, $dec=null)
529 $dec = user_qty_dec();
532 amount_cells($label, $name, $init, $params, $post_label, $dec);
536 function small_qty_row($label, $name, $init=null, $params=null, $post_label=null, $dec=null)
539 $dec = user_qty_dec();
542 small_amount_cells($label, $name, $init, $params, $post_label, $dec);
546 //-----------------------------------------------------------------------------------
548 function small_amount_cells($label, $name, $init=null, $params=null, $post_label=null, $dec=null)
550 amount_cells_ex($label, $name, 7, 12, $init, $params, $post_label, $dec);
553 //-----------------------------------------------------------------------------------
555 function small_qty_cells($label, $name, $init=null, $params=null, $post_label=null, $dec=null)
558 $dec = user_qty_dec();
559 amount_cells_ex($label, $name, 7, 12, $init, $params, $post_label, $dec);
562 //-----------------------------------------------------------------------------------
564 function textarea_cells($label, $name, $value, $cols, $rows, $title = null, $params="")
568 default_focus($name);
570 echo "<td $params>$label</td>\n";
572 $value = (!isset($_POST[$name]) ? "" : $_POST[$name]);
573 echo "<td><textarea name='$name' cols='$cols' rows='$rows'"
574 .($title ? " title='$title'" : '')
575 .">$value</textarea></td>\n";
576 $Ajax->addUpdate($name, $name, $value);
579 function textarea_row($label, $name, $value, $cols, $rows, $title=null, $params="")
582 textarea_cells($label, $name, $value, $cols, $rows, $title, $params);
586 //-----------------------------------------------------------------------------------
588 function text_row_with_submit($label, $name, $value, $size, $max, $input_name, $input_value)
592 default_focus($name);
593 echo "<tr><td>$label</td>\n";
597 $value = (!isset($_POST[$name]) ? "" : $_POST[$name]);
598 echo "<input type=\"text\" name=\"$name\" size=\"$size\" maxlength=\"$max\" value=\"$value\"> ";
600 submit($input_name, $input_value);
603 $Ajax->addUpdate($name, $name, $value);
606 //-----------------------------------------------------------------------------------