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);
195 function submit_return($name, $value, $title=false, $async=false)
197 if (count($_SESSION['Context'])) {
198 submit($name, $value, true, $title, $async);
201 //---------------------------------------------------------------------------------
203 function button($name, $value, $onclick, $title=false)
205 default_focus($name);
206 echo "<input type=\"button\" class=\"inputsubmit\" name=\"$name\" value=\"$value\" onclick=\"$onclick\""
207 .($title ? " title='$title'" : '')
211 function button_cell($name, $value, $onclick, $title=false)
214 button($name, $value, $onclick, $title);
218 //-----------------------------------------------------------------------------------
220 function check_value($name)
222 if (!isset($_POST[$name]))
227 function check($label, $name, $value=null, $submit_on_change=false, $title=false)
231 default_focus($name);
236 $value = get_post($name,0);
239 .($value == 1 ? ' checked':'')
240 ." type='checkbox' name='$name' value='1'"
241 .($submit_on_change ? " onclick='JsHttpRequest.request(\"_{$name}_update\", this.form);'" : '')
242 .($title ? " title='$title'" : '')
244 $Ajax->addUpdate($name, $name, $value);
247 function check_cells($label, $name, $value, $submit_on_change=false, $title=false)
250 echo "<td>$label</td>\n";
252 check(null, $name, $value, $submit_on_change, $title);
256 function check_row($label, $name, $value, $submit_on_change=false, $title=false)
259 check_cells($label, $name, $value, $submit_on_change, $title);
263 //-----------------------------------------------------------------------------------
265 function labelheader_cell($label, $params="")
267 echo "<td class='tableheader' $params>$label</td>\n";
270 function label_cell($label, $params="", $id=null)
276 $params .= " id='$id'";
277 $Ajax->addUpdate($id, $id, $label);
279 echo "<td $params>$label</td>\n";
284 function amount_cell($label, $bold=false, $params="", $id=null)
287 label_cell("<b>".price_format($label)."</b>", "nowrap align=right ".$params, $id);
289 label_cell(price_format($label), "nowrap align=right ".$params, $id);
292 function percent_cell($label, $bold=false, $id=null)
295 label_cell("<b>".percent_format($label)."</b>", "nowrap align=right", $id);
297 label_cell(percent_format($label), "nowrap align=right", $id);
299 // 2008-06-15. Changed
300 function qty_cell($label, $bold=false, $dec=null, $id=null)
303 $dec = get_qty_dec();
305 label_cell("<b>".number_format2($label, $dec)."</b>", "nowrap align=right", $id);
307 label_cell(number_format2($label, $dec), "nowrap align=right", $id);
310 function label_cells($label, $value, $params="", $params2="")
313 echo "<td $params>$label</td>\n";
314 echo "<td $params2>$value</td>\n";
317 function label_row($label, $value, $params="", $params2="", $leftfill=0)
320 label_cells($label, $value, $params, $params2);
322 echo "<td colspan=$leftfill></td>";
326 //-----------------------------------------------------------------------------------
328 function text_cells($label, $name, $value=null, $size="", $max="", $title=false, $params="", $post_label="", $disabled="")
332 default_focus($name);
334 label_cell($label, $params);
338 $value = get_post($name);
339 echo "<input $disabled type=\"text\" name=\"$name\" size=\"$size\" maxlength=\"$max\" value=\"$value\""
340 .($title ? " title='$title'" : '')
343 if ($post_label != "")
344 echo " " . $post_label;
347 $Ajax->addUpdate($name, $name, $value);
350 function text_cells_ex($label, $name, $size, $max=null, $init=null, $title=null, $params=null, $post_label=null, $submit_on_change=false)
354 default_focus($name);
355 if (!isset($_POST[$name]) || $_POST[$name] == "")
358 $_POST[$name] = $init;
363 label_cell($label, $params);
369 $class = $submit_on_change ? 'class="searchbox"' : '';
370 echo "<input $class type=\"text\" name=\"$name\" size=\"$size\" maxlength=\"$max\" value=\"" . $_POST[$name]. "\""
371 .($title ? " title='$title'": '')." >";
374 echo " " . $post_label;
377 $Ajax->addUpdate($name, $name, $_POST[$name]);
380 function text_row($label, $name, $value, $size, $max, $title=null, $params="", $post_label="")
384 text_cells($label, $name, $value, $size, $max, $title, $params, $post_label);
389 //-----------------------------------------------------------------------------------
391 function text_row_ex($label, $name, $size, $max=null, $title=null, $value=null, $params=null, $post_label=null)
395 text_cells_ex($label, $name, $size, $max, $value, $title, $params, $post_label);
400 //-----------------------------------------------------------------------------------
402 function date_cells($label, $name, $title = null, $init=null, $inc_days=0,
403 $inc_months=0, $inc_years=0, $params=null, $submit_on_change=false)
405 global $use_date_picker, $path_to_root;
406 if (!isset($_POST[$name]) || $_POST[$name] == "")
410 if ($inc_years == 1001)
411 $_POST[$name] = null;
416 $dd = add_days($dd, $inc_days);
417 if ($inc_months != 0)
418 $dd = add_months($dd, $inc_months);
420 $dd = add_years($dd, $inc_years);
425 $_POST[$name] = $init;
427 if ($use_date_picker)
428 $post_label = "<a tabindex='-1' href=\"javascript:date_picker(document.getElementsByName('$name')[0]);\">"
429 . " <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";
432 text_cells_ex($label, $name, 9, 12, $_POST[$name], $title, $params, $post_label, $submit_on_change);
435 function date_row($label, $name, $title=null, $init=null, $inc_days=0, $inc_months=0,
436 $inc_years=0, $params=null, $submit_on_change=false)
439 date_cells($label, $name, $title, $init, $inc_days, $inc_months,
440 $inc_years, $params, $submit_on_change);
444 //-----------------------------------------------------------------------------------
446 function ref_cells($label, $name, $title=null, $init=null, $params=null, $submit_on_change=false)
448 text_cells_ex($label, $name, 16, 18, $init, $title, $params, null, $submit_on_change);
451 //-----------------------------------------------------------------------------------
453 function ref_row($label, $name, $title=null, $init=null, $submit_on_change=false)
456 ref_cells($label, $name, $title, $init, null, $submit_on_change);
460 //-----------------------------------------------------------------------------------
462 function percent_row($label, $name, $init=null)
465 if (!isset($_POST[$name]) || $_POST[$name]=="")
467 $_POST[$name] = $init == null ? '' : $init;
470 small_amount_row($label, $name, $_POST[$name], null, "%", user_percent_dec());
473 function amount_cells_ex($label, $name, $size, $max=null, $init=null, $params=null, $post_label=null, $dec=null)
478 $dec = user_price_dec();
479 if (!isset($_POST[$name]) || $_POST[$name] == "")
482 $_POST[$name] = $init;
487 label_cell($label, $params);
494 echo "<input class='amount' type=\"text\" name=\"$name\" size=\"$size\" maxlength=\"$max\" dec=\"$dec\" value=\"" . $_POST[$name]. "\">";
497 echo " " . $post_label;
500 $Ajax->addUpdate($name, $name, $_POST[$name]);
501 $Ajax->addAssign($name, $name, 'dec', $dec);
505 //-----------------------------------------------------------------------------------
507 function amount_cells($label, $name, $init=null, $params=null, $post_label=null, $dec=null)
509 amount_cells_ex($label, $name, 15, 15, $init, $params, $post_label, $dec);
512 function amount_row($label, $name, $init=null, $params=null, $post_label=null, $dec=null)
515 amount_cells($label, $name, $init, $params, $post_label, $dec);
519 function small_amount_row($label, $name, $init=null, $params=null, $post_label=null, $dec=null)
522 small_amount_cells($label, $name, $init, $params, $post_label, $dec);
526 //-----------------------------------------------------------------------------------
528 function qty_cells($label, $name, $init=null, $params=null, $post_label=null, $dec=null)
531 $dec = user_qty_dec();
533 amount_cells_ex($label, $name, 15, 15, $init, $params, $post_label, $dec);
536 function qty_row($label, $name, $init=null, $params=null, $post_label=null, $dec=null)
539 $dec = user_qty_dec();
542 amount_cells($label, $name, $init, $params, $post_label, $dec);
546 function small_qty_row($label, $name, $init=null, $params=null, $post_label=null, $dec=null)
549 $dec = user_qty_dec();
552 small_amount_cells($label, $name, $init, $params, $post_label, $dec);
556 //-----------------------------------------------------------------------------------
558 function small_amount_cells($label, $name, $init=null, $params=null, $post_label=null, $dec=null)
560 amount_cells_ex($label, $name, 7, 12, $init, $params, $post_label, $dec);
563 //-----------------------------------------------------------------------------------
565 function small_qty_cells($label, $name, $init=null, $params=null, $post_label=null, $dec=null)
568 $dec = user_qty_dec();
569 amount_cells_ex($label, $name, 7, 12, $init, $params, $post_label, $dec);
572 //-----------------------------------------------------------------------------------
574 function textarea_cells($label, $name, $value, $cols, $rows, $title = null, $params="")
578 default_focus($name);
580 echo "<td $params>$label</td>\n";
582 $value = (!isset($_POST[$name]) ? "" : $_POST[$name]);
583 echo "<td><textarea name='$name' cols='$cols' rows='$rows'"
584 .($title ? " title='$title'" : '')
585 .">$value</textarea></td>\n";
586 $Ajax->addUpdate($name, $name, $value);
589 function textarea_row($label, $name, $value, $cols, $rows, $title=null, $params="")
592 textarea_cells($label, $name, $value, $cols, $rows, $title, $params);
596 //-----------------------------------------------------------------------------------
598 function text_row_with_submit($label, $name, $value, $size, $max, $input_name, $input_value)
602 default_focus($name);
603 echo "<tr><td>$label</td>\n";
607 $value = (!isset($_POST[$name]) ? "" : $_POST[$name]);
608 echo "<input type=\"text\" name=\"$name\" size=\"$size\" maxlength=\"$max\" value=\"$value\"> ";
610 submit($input_name, $input_value);
613 $Ajax->addUpdate($name, $name, $value);
616 //-----------------------------------------------------------------------------------