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 = substr($p, strlen($m));
57 $Ajax->activate('_page_body');
66 //------------------------------------------------------------------------------
68 // Read numeric value from user formatted input
70 function input_num($postname=null, $dflt=null)
72 if (!isset($_POST[$postname]))
75 return user_numeric($_POST[$postname]);
78 //---------------------------------------------------------------------------------
80 function hidden($name, $value=null, $echo=true)
85 $value = get_post($name);
87 $ret = "<input type=\"hidden\" name=\"$name\" value=\"$value\">";
88 $Ajax->addUpdate($name, $name, $value);
95 //---------------------------------------------------------------------------------
97 // $async parameter can have 3 values:
98 // false - normal submit via form action
99 // true - when js is on submition via ajax call
100 // null - fallback button not visible in js enabled mode
102 function submit($name, $value, $echo=true, $title=false, $async=false)
105 default_focus($name);
106 $submit_str = "<input type=\"submit\" class=\""
107 .($async ? 'ajaxsubmit' : 'inputsubmit')
109 .($async === null ? (in_ajax() ? " style='display:none;'" : ' fallback="1"' ): '')
110 ." name=\"$name\" id=\"$name\" value=\"$value\""
111 .($title ? " title='$title'" : '')
119 function submit_center($name, $value, $echo=true, $title=false, $async=false)
122 submit($name, $value, $echo, $title, $async);
126 function submit_center_first($name, $value, $title=false, $async=false)
129 submit($name, $value, true, $title, $async);
133 function submit_center_last($name, $value, $title=false, $async=false)
136 submit($name, $value, true, $title, $async);
140 function submit_add_or_update($add=true, $title=false, $async=false)
143 submit('ADD_ITEM', _("Add new"), true, $title, $async);
145 submit('UPDATE_ITEM', _("Update"), true, $title, $async);
146 submit('RESET', _("Cancel"), true, $title, $async);
150 function submit_add_or_update_center($add=true, $title=false, $async=false)
153 submit_add_or_update($add, $title, $async);
158 function submit_add_or_update_row($add=true)
160 echo "<tr><td colspan=99 align=center>";
161 submit_add_or_update($add);
165 function submit_add_or_update_row($add=true, $right=true, $extra="", $title=false, $async=false)
169 echo "<td> </td>\n";
171 submit_add_or_update($add, $title, $async);
175 function submit_cells($name, $value, $extra="", $title=false, $async=false)
178 submit($name, $value, true, $title, $async);
182 function submit_row($name, $value, $right=true, $extra="", $title=false, $async=false)
186 echo "<td> </td>\n";
187 submit_cells($name, $value, $extra, $title, $async);
190 //---------------------------------------------------------------------------------
192 function button($name, $value, $onclick, $title=false)
194 default_focus($name);
195 echo "<input type=\"button\" class=\"inputsubmit\" name=\"$name\" value=\"$value\" onclick=\"$onclick\""
196 .($title ? " title='$title'" : '')
200 function button_cell($name, $value, $onclick, $title=false)
203 button($name, $value, $onclick, $title);
207 //-----------------------------------------------------------------------------------
209 function check_value($name)
211 if (!isset($_POST[$name]))
216 function check($label, $name, $value=null, $submit_on_change=false, $title=false)
220 default_focus($name);
225 $value = get_post($name,0);
228 .($value == 1 ? ' checked':'')
229 ." type='checkbox' name='$name' value='1'"
230 .($submit_on_change ? " onclick='JsHttpRequest.request(\"_{$name}_update\", this.form);'" : '')
231 .($title ? " title='$title'" : '')
233 $Ajax->addUpdate($name, $name, $value);
236 function check_cells($label, $name, $value, $submit_on_change=false, $title=false)
239 echo "<td>$label</td>\n";
241 check(null, $name, $value, $submit_on_change, $title);
245 function check_row($label, $name, $value, $submit_on_change=false, $title=false)
248 check_cells($label, $name, $value, $submit_on_change, $title);
252 //-----------------------------------------------------------------------------------
254 function labelheader_cell($label, $params="")
256 echo "<td class='tableheader' $params>$label</td>\n";
259 function label_cell($label, $params="", $id=null)
265 $params .= " id='$id'";
266 $Ajax->addUpdate($id, $id, $label);
268 echo "<td $params>$label</td>\n";
273 function amount_cell($label, $bold=false, $params="", $id=null)
276 label_cell("<b>".price_format($label)."</b>", "nowrap align=right ".$params, $id);
278 label_cell(price_format($label), "nowrap align=right ".$params, $id);
281 function percent_cell($label, $bold=false, $id=null)
284 label_cell("<b>".percent_format($label)."</b>", "nowrap align=right", $id);
286 label_cell(percent_format($label), "nowrap align=right", $id);
288 // 2008-06-15. Changed
289 function qty_cell($label, $bold=false, $dec=null, $id=null)
292 $dec = get_qty_dec();
294 label_cell("<b>".number_format2($label, $dec)."</b>", "nowrap align=right", $id);
296 label_cell(number_format2($label, $dec), "nowrap align=right", $id);
299 function label_cells($label, $value, $params="", $params2="")
302 echo "<td $params>$label</td>\n";
303 echo "<td $params2>$value</td>\n";
306 function label_row($label, $value, $params="", $params2="", $leftfill=0)
309 label_cells($label, $value, $params, $params2);
311 echo "<td colspan=$leftfill></td>";
315 //-----------------------------------------------------------------------------------
317 function text_cells($label, $name, $value=null, $size="", $max="", $title=false, $params="", $post_label="", $disabled="")
321 default_focus($name);
323 label_cell($label, $params);
327 $value = get_post($name);
328 echo "<input $disabled type=\"text\" name=\"$name\" size=\"$size\" maxlength=\"$max\" value=\"$value\""
329 .($title ? " title='$title'" : '')
332 if ($post_label != "")
333 echo " " . $post_label;
336 $Ajax->addUpdate($name, $name, $value);
339 function text_cells_ex($label, $name, $size, $max=null, $init=null, $title=null, $params=null, $post_label=null, $submit_on_change=false)
343 default_focus($name);
344 if (!isset($_POST[$name]) || $_POST[$name] == "")
347 $_POST[$name] = $init;
352 label_cell($label, $params);
358 $class = $submit_on_change ? 'class="searchbox"' : '';
359 echo "<input $class type=\"text\" name=\"$name\" size=\"$size\" maxlength=\"$max\" value=\"" . $_POST[$name]. "\""
360 .($title ? " title='$title'": '')." >";
363 echo " " . $post_label;
366 $Ajax->addUpdate($name, $name, $_POST[$name]);
369 function text_row($label, $name, $value, $size, $max, $title=null, $params="", $post_label="")
373 text_cells($label, $name, $value, $size, $max, $title, $params, $post_label);
378 //-----------------------------------------------------------------------------------
380 function text_row_ex($label, $name, $size, $max=null, $title=null, $value=null, $params=null, $post_label=null)
384 text_cells_ex($label, $name, $size, $max, $value, $title, $params, $post_label);
389 //-----------------------------------------------------------------------------------
391 function date_cells($label, $name, $title = null, $init=null, $inc_days=0, $inc_months=0, $inc_years=0, $params=null)
393 global $use_date_picker, $path_to_root;
394 if (!isset($_POST[$name]) || $_POST[$name] == "")
398 if ($inc_years == 1001)
399 $_POST[$name] = null;
404 $dd = add_days($dd, $inc_days);
405 if ($inc_months != 0)
406 $dd = add_months($dd, $inc_months);
408 $dd = add_years($dd, $inc_years);
413 $_POST[$name] = $init;
415 if ($use_date_picker)
416 $post_label = "<a tabindex='-1' href=\"javascript:date_picker(document.getElementsByName('$name')[0]);\">"
417 . " <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";
420 text_cells_ex($label, $name, 9, 12, $_POST[$name], $title, $params, $post_label);
423 function date_row($label, $name, $title=null, $init=null, $inc_days=0, $inc_months=0, $inc_years=0, $params=null)
426 date_cells($label, $name, $title, $init, $inc_days, $inc_months, $inc_years, $params);
430 //-----------------------------------------------------------------------------------
432 function ref_cells($label, $name, $title=null, $init=null, $params=null, $submit_on_change=false)
434 text_cells_ex($label, $name, 16, 18, $init, $title, $params, null, $submit_on_change);
437 //-----------------------------------------------------------------------------------
439 function ref_row($label, $name, $title=null, $init=null, $submit_on_change=false)
442 ref_cells($label, $name, $title, $init, null, $submit_on_change);
446 //-----------------------------------------------------------------------------------
448 function percent_row($label, $name, $init=null)
451 if (!isset($_POST[$name]) || $_POST[$name]=="")
453 $_POST[$name] = $init == null ? '' : $init;
456 small_amount_row($label, $name, $_POST[$name], null, "%", user_percent_dec());
459 function amount_cells_ex($label, $name, $size, $max=null, $init=null, $params=null, $post_label=null, $dec=null)
464 $dec = user_price_dec();
465 if (!isset($_POST[$name]) || $_POST[$name] == "")
468 $_POST[$name] = $init;
473 label_cell($label, $params);
480 echo "<input class='amount' type=\"text\" name=\"$name\" size=\"$size\" maxlength=\"$max\" dec=\"$dec\" value=\"" . $_POST[$name]. "\">";
483 echo " " . $post_label;
486 $Ajax->addUpdate($name, $name, $_POST[$name]);
487 $Ajax->addAssign($name, $name, 'dec', $dec);
491 //-----------------------------------------------------------------------------------
493 function amount_cells($label, $name, $init=null, $params=null, $post_label=null, $dec=null)
495 amount_cells_ex($label, $name, 15, 15, $init, $params, $post_label, $dec);
498 function amount_row($label, $name, $init=null, $params=null, $post_label=null, $dec=null)
501 amount_cells($label, $name, $init, $params, $post_label, $dec);
505 function small_amount_row($label, $name, $init=null, $params=null, $post_label=null, $dec=null)
508 small_amount_cells($label, $name, $init, $params, $post_label, $dec);
512 //-----------------------------------------------------------------------------------
514 function qty_cells($label, $name, $init=null, $params=null, $post_label=null, $dec=null)
517 $dec = user_qty_dec();
519 amount_cells_ex($label, $name, 15, 15, $init, $params, $post_label, $dec);
522 function qty_row($label, $name, $init=null, $params=null, $post_label=null, $dec=null)
525 $dec = user_qty_dec();
528 amount_cells($label, $name, $init, $params, $post_label, $dec);
532 function small_qty_row($label, $name, $init=null, $params=null, $post_label=null, $dec=null)
535 $dec = user_qty_dec();
538 small_amount_cells($label, $name, $init, $params, $post_label, $dec);
542 //-----------------------------------------------------------------------------------
544 function small_amount_cells($label, $name, $init=null, $params=null, $post_label=null, $dec=null)
546 amount_cells_ex($label, $name, 7, 12, $init, $params, $post_label, $dec);
549 //-----------------------------------------------------------------------------------
551 function small_qty_cells($label, $name, $init=null, $params=null, $post_label=null, $dec=null)
554 $dec = user_qty_dec();
555 amount_cells_ex($label, $name, 7, 12, $init, $params, $post_label, $dec);
558 //-----------------------------------------------------------------------------------
560 function textarea_cells($label, $name, $value, $cols, $rows, $title = null, $params="")
564 default_focus($name);
566 echo "<td $params>$label</td>\n";
568 $value = (!isset($_POST[$name]) ? "" : $_POST[$name]);
569 echo "<td><textarea name='$name' cols='$cols' rows='$rows'"
570 .($title ? " title='$title'" : '')
571 .">$value</textarea></td>\n";
572 $Ajax->addUpdate($name, $name, $value);
575 function textarea_row($label, $name, $value, $cols, $rows, $title=null, $params="")
578 textarea_cells($label, $name, $value, $cols, $rows, $title, $params);
582 //-----------------------------------------------------------------------------------
584 function text_row_with_submit($label, $name, $value, $size, $max, $input_name, $input_value)
588 default_focus($name);
589 echo "<tr><td>$label</td>\n";
593 $value = (!isset($_POST[$name]) ? "" : $_POST[$name]);
594 echo "<input type=\"text\" name=\"$name\" size=\"$size\" maxlength=\"$max\" value=\"$value\"> ";
596 submit($input_name, $input_value);
599 $Ajax->addUpdate($name, $name, $value);
602 //-----------------------------------------------------------------------------------