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 // null - fallback button not visible in js enabled mode
99 // false - normal submit via form action
100 // true - when js is on submition via ajax call
101 // 'process' - ditto with processing indicator in msgbox
103 function submit($name, $value, $echo=true, $title=false, $async=false)
106 default_focus($name);
107 $submit_str = "<input type=\"submit\" class=\""
108 .($async ? 'ajaxsubmit' : 'inputsubmit')
110 .($async === null ? (in_ajax() ? " style='display:none;'" : ' aspect="fallback"' ):
111 ($async === 'process' ? 'aspect="process"' : '') )
112 ." name=\"$name\" id=\"$name\" value=\"$value\""
113 .($title ? " title='$title'" : '')
121 function submit_center($name, $value, $echo=true, $title=false, $async=false)
124 submit($name, $value, $echo, $title, $async);
128 function submit_center_first($name, $value, $title=false, $async=false)
131 submit($name, $value, true, $title, $async);
135 function submit_center_last($name, $value, $title=false, $async=false)
138 submit($name, $value, true, $title, $async);
142 function submit_add_or_update($add=true, $title=false, $async=false)
145 submit('ADD_ITEM', _("Add new"), true, $title, $async);
147 submit('UPDATE_ITEM', _("Update"), true, $title, $async);
148 submit('RESET', _("Cancel"), true, $title, $async);
152 function submit_add_or_update_center($add=true, $title=false, $async=false)
155 submit_add_or_update($add, $title, $async);
160 function submit_add_or_update_row($add=true)
162 echo "<tr><td colspan=99 align=center>";
163 submit_add_or_update($add);
167 function submit_add_or_update_row($add=true, $right=true, $extra="", $title=false, $async=false)
171 echo "<td> </td>\n";
173 submit_add_or_update($add, $title, $async);
177 function submit_cells($name, $value, $extra="", $title=false, $async=false)
180 submit($name, $value, true, $title, $async);
184 function submit_row($name, $value, $right=true, $extra="", $title=false, $async=false)
188 echo "<td> </td>\n";
189 submit_cells($name, $value, $extra, $title, $async);
192 //---------------------------------------------------------------------------------
194 function button($name, $value, $onclick, $title=false)
196 default_focus($name);
197 echo "<input type=\"button\" class=\"inputsubmit\" name=\"$name\" value=\"$value\" onclick=\"$onclick\""
198 .($title ? " title='$title'" : '')
202 function button_cell($name, $value, $onclick, $title=false)
205 button($name, $value, $onclick, $title);
209 //-----------------------------------------------------------------------------------
211 function check_value($name)
213 if (!isset($_POST[$name]))
218 function check($label, $name, $value=null, $submit_on_change=false, $title=false)
222 default_focus($name);
227 $value = get_post($name,0);
230 .($value == 1 ? ' checked':'')
231 ." type='checkbox' name='$name' value='1'"
232 .($submit_on_change ? " onclick='JsHttpRequest.request(\"_{$name}_update\", this.form);'" : '')
233 .($title ? " title='$title'" : '')
235 $Ajax->addUpdate($name, $name, $value);
238 function check_cells($label, $name, $value, $submit_on_change=false, $title=false)
241 echo "<td>$label</td>\n";
243 check(null, $name, $value, $submit_on_change, $title);
247 function check_row($label, $name, $value, $submit_on_change=false, $title=false)
250 check_cells($label, $name, $value, $submit_on_change, $title);
254 //-----------------------------------------------------------------------------------
256 function labelheader_cell($label, $params="")
258 echo "<td class='tableheader' $params>$label</td>\n";
261 function label_cell($label, $params="", $id=null)
267 $params .= " id='$id'";
268 $Ajax->addUpdate($id, $id, $label);
270 echo "<td $params>$label</td>\n";
275 function amount_cell($label, $bold=false, $params="", $id=null)
278 label_cell("<b>".price_format($label)."</b>", "nowrap align=right ".$params, $id);
280 label_cell(price_format($label), "nowrap align=right ".$params, $id);
283 function percent_cell($label, $bold=false, $id=null)
286 label_cell("<b>".percent_format($label)."</b>", "nowrap align=right", $id);
288 label_cell(percent_format($label), "nowrap align=right", $id);
290 // 2008-06-15. Changed
291 function qty_cell($label, $bold=false, $dec=null, $id=null)
294 $dec = get_qty_dec();
296 label_cell("<b>".number_format2($label, $dec)."</b>", "nowrap align=right", $id);
298 label_cell(number_format2($label, $dec), "nowrap align=right", $id);
301 function label_cells($label, $value, $params="", $params2="")
304 echo "<td $params>$label</td>\n";
305 echo "<td $params2>$value</td>\n";
308 function label_row($label, $value, $params="", $params2="", $leftfill=0)
311 label_cells($label, $value, $params, $params2);
313 echo "<td colspan=$leftfill></td>";
317 //-----------------------------------------------------------------------------------
319 function text_cells($label, $name, $value=null, $size="", $max="", $title=false, $params="", $post_label="", $disabled="")
323 default_focus($name);
325 label_cell($label, $params);
329 $value = get_post($name);
330 echo "<input $disabled type=\"text\" name=\"$name\" size=\"$size\" maxlength=\"$max\" value=\"$value\""
331 .($title ? " title='$title'" : '')
334 if ($post_label != "")
335 echo " " . $post_label;
338 $Ajax->addUpdate($name, $name, $value);
341 function text_cells_ex($label, $name, $size, $max=null, $init=null, $title=null, $params=null, $post_label=null, $submit_on_change=false)
345 default_focus($name);
346 if (!isset($_POST[$name]) || $_POST[$name] == "")
349 $_POST[$name] = $init;
354 label_cell($label, $params);
360 $class = $submit_on_change ? 'class="searchbox"' : '';
361 echo "<input $class type=\"text\" name=\"$name\" size=\"$size\" maxlength=\"$max\" value=\"" . $_POST[$name]. "\""
362 .($title ? " title='$title'": '')." >";
365 echo " " . $post_label;
368 $Ajax->addUpdate($name, $name, $_POST[$name]);
371 function text_row($label, $name, $value, $size, $max, $title=null, $params="", $post_label="")
375 text_cells($label, $name, $value, $size, $max, $title, $params, $post_label);
380 //-----------------------------------------------------------------------------------
382 function text_row_ex($label, $name, $size, $max=null, $title=null, $value=null, $params=null, $post_label=null)
386 text_cells_ex($label, $name, $size, $max, $value, $title, $params, $post_label);
391 //-----------------------------------------------------------------------------------
393 function date_cells($label, $name, $title = null, $init=null, $inc_days=0, $inc_months=0, $inc_years=0, $params=null)
395 global $use_date_picker, $path_to_root;
396 if (!isset($_POST[$name]) || $_POST[$name] == "")
400 if ($inc_years == 1001)
401 $_POST[$name] = null;
406 $dd = add_days($dd, $inc_days);
407 if ($inc_months != 0)
408 $dd = add_months($dd, $inc_months);
410 $dd = add_years($dd, $inc_years);
415 $_POST[$name] = $init;
417 if ($use_date_picker)
418 $post_label = "<a tabindex='-1' href=\"javascript:date_picker(document.getElementsByName('$name')[0]);\">"
419 . " <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";
422 text_cells_ex($label, $name, 9, 12, $_POST[$name], $title, $params, $post_label);
425 function date_row($label, $name, $title=null, $init=null, $inc_days=0, $inc_months=0, $inc_years=0, $params=null)
428 date_cells($label, $name, $title, $init, $inc_days, $inc_months, $inc_years, $params);
432 //-----------------------------------------------------------------------------------
434 function ref_cells($label, $name, $title=null, $init=null, $params=null, $submit_on_change=false)
436 text_cells_ex($label, $name, 16, 18, $init, $title, $params, null, $submit_on_change);
439 //-----------------------------------------------------------------------------------
441 function ref_row($label, $name, $title=null, $init=null, $submit_on_change=false)
444 ref_cells($label, $name, $title, $init, null, $submit_on_change);
448 //-----------------------------------------------------------------------------------
450 function percent_row($label, $name, $init=null)
453 if (!isset($_POST[$name]) || $_POST[$name]=="")
455 $_POST[$name] = $init == null ? '' : $init;
458 small_amount_row($label, $name, $_POST[$name], null, "%", user_percent_dec());
461 function amount_cells_ex($label, $name, $size, $max=null, $init=null, $params=null, $post_label=null, $dec=null)
466 $dec = user_price_dec();
467 if (!isset($_POST[$name]) || $_POST[$name] == "")
470 $_POST[$name] = $init;
475 label_cell($label, $params);
482 echo "<input class='amount' type=\"text\" name=\"$name\" size=\"$size\" maxlength=\"$max\" dec=\"$dec\" value=\"" . $_POST[$name]. "\">";
485 echo " " . $post_label;
488 $Ajax->addUpdate($name, $name, $_POST[$name]);
489 $Ajax->addAssign($name, $name, 'dec', $dec);
493 //-----------------------------------------------------------------------------------
495 function amount_cells($label, $name, $init=null, $params=null, $post_label=null, $dec=null)
497 amount_cells_ex($label, $name, 15, 15, $init, $params, $post_label, $dec);
500 function amount_row($label, $name, $init=null, $params=null, $post_label=null, $dec=null)
503 amount_cells($label, $name, $init, $params, $post_label, $dec);
507 function small_amount_row($label, $name, $init=null, $params=null, $post_label=null, $dec=null)
510 small_amount_cells($label, $name, $init, $params, $post_label, $dec);
514 //-----------------------------------------------------------------------------------
516 function qty_cells($label, $name, $init=null, $params=null, $post_label=null, $dec=null)
519 $dec = user_qty_dec();
521 amount_cells_ex($label, $name, 15, 15, $init, $params, $post_label, $dec);
524 function qty_row($label, $name, $init=null, $params=null, $post_label=null, $dec=null)
527 $dec = user_qty_dec();
530 amount_cells($label, $name, $init, $params, $post_label, $dec);
534 function small_qty_row($label, $name, $init=null, $params=null, $post_label=null, $dec=null)
537 $dec = user_qty_dec();
540 small_amount_cells($label, $name, $init, $params, $post_label, $dec);
544 //-----------------------------------------------------------------------------------
546 function small_amount_cells($label, $name, $init=null, $params=null, $post_label=null, $dec=null)
548 amount_cells_ex($label, $name, 7, 12, $init, $params, $post_label, $dec);
551 //-----------------------------------------------------------------------------------
553 function small_qty_cells($label, $name, $init=null, $params=null, $post_label=null, $dec=null)
556 $dec = user_qty_dec();
557 amount_cells_ex($label, $name, 7, 12, $init, $params, $post_label, $dec);
560 //-----------------------------------------------------------------------------------
562 function textarea_cells($label, $name, $value, $cols, $rows, $title = null, $params="")
566 default_focus($name);
568 echo "<td $params>$label</td>\n";
570 $value = (!isset($_POST[$name]) ? "" : $_POST[$name]);
571 echo "<td><textarea name='$name' cols='$cols' rows='$rows'"
572 .($title ? " title='$title'" : '')
573 .">$value</textarea></td>\n";
574 $Ajax->addUpdate($name, $name, $value);
577 function textarea_row($label, $name, $value, $cols, $rows, $title=null, $params="")
580 textarea_cells($label, $name, $value, $cols, $rows, $title, $params);
584 //-----------------------------------------------------------------------------------
586 function text_row_with_submit($label, $name, $value, $size, $max, $input_name, $input_value)
590 default_focus($name);
591 echo "<tr><td>$label</td>\n";
595 $value = (!isset($_POST[$name]) ? "" : $_POST[$name]);
596 echo "<input type=\"text\" name=\"$name\" size=\"$size\" maxlength=\"$max\" value=\"$value\"> ";
598 submit($input_name, $input_value);
601 $Ajax->addUpdate($name, $name, $value);
604 //-----------------------------------------------------------------------------------