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 function submit($name, $value, $echo=true, $title=false, $async=false, $icon=false)
101 default_focus($name);
102 $submit_str = "<button class=\""
103 .($async ? 'ajaxsubmit' : 'inputsubmit')
105 .($async === null ? (in_ajax() ? " style='display:none;'" : ' aspect="fallback"' ):
106 ($async === 'process' ? 'aspect="process"' : '') )
107 ." name=\"$name\" id=\"$name\" " //value=\"$value\""
108 .($title ? " title='$title'" : '')
109 ."><span>$value</span>"
110 .($icon ? "<img src='$path_to_root/themes/default/images/$icon'>" : '')
118 function submit_center($name, $value, $echo=true, $title=false, $async=false, $icon=false)
121 submit($name, $value, $echo, $title, $async, $icon);
125 function submit_center_first($name, $value, $title=false, $async=false, $icon=false)
128 submit($name, $value, true, $title, $async, $icon);
132 function submit_center_last($name, $value, $title=false, $async=false, $icon=false)
135 submit($name, $value, true, $title, $async, $icon);
139 function submit_add_or_update($add=true, $title=false, $async=false)
142 submit('ADD_ITEM', _("Add new"), true, $title, $async);
144 submit('UPDATE_ITEM', _("Update"), true, $title, $async);
145 submit('RESET', _("Cancel"), true, $title, $async);
149 function submit_add_or_update_center($add=true, $title=false, $async=false)
152 submit_add_or_update($add, $title, $async);
157 function submit_add_or_update_row($add=true)
159 echo "<tr><td colspan=99 align=center>";
160 submit_add_or_update($add);
164 function submit_add_or_update_row($add=true, $right=true, $extra="", $title=false, $async=false)
168 echo "<td> </td>\n";
170 submit_add_or_update($add, $title, $async);
174 function submit_cells($name, $value, $extra="", $title=false, $async=false)
177 submit($name, $value, true, $title, $async);
181 function submit_row($name, $value, $right=true, $extra="", $title=false, $async=false)
185 echo "<td> </td>\n";
186 submit_cells($name, $value, $extra, $title, $async);
190 function submit_return($name, $value, $title=false, $async=false)
192 if (count($_SESSION['Context'])) {
193 submit($name, $value, true, $title, $async);
196 //---------------------------------------------------------------------------------
198 function button($name, $value, $onclick, $title=false)
200 default_focus($name);
201 echo "<input type=\"button\" class=\"inputsubmit\" name=\"$name\" value=\"$value\" onclick=\"$onclick\""
202 .($title ? " title='$title'" : '')
206 function button_cell($name, $value, $onclick, $title=false)
209 button($name, $value, $onclick, $title);
213 //-----------------------------------------------------------------------------------
215 function check_value($name)
217 if (!isset($_POST[$name]))
222 function check($label, $name, $value=null, $submit_on_change=false, $title=false)
226 default_focus($name);
231 $value = get_post($name,0);
234 .($value == 1 ? ' checked':'')
235 ." type='checkbox' name='$name' value='1'"
236 .($submit_on_change ? " onclick='JsHttpRequest.request(\"_{$name}_update\", this.form);'" : '')
237 .($title ? " title='$title'" : '')
239 $Ajax->addUpdate($name, $name, $value);
242 function check_cells($label, $name, $value, $submit_on_change=false, $title=false)
245 echo "<td>$label</td>\n";
247 check(null, $name, $value, $submit_on_change, $title);
251 function check_row($label, $name, $value, $submit_on_change=false, $title=false)
254 check_cells($label, $name, $value, $submit_on_change, $title);
258 //-----------------------------------------------------------------------------------
260 function labelheader_cell($label, $params="")
262 echo "<td class='tableheader' $params>$label</td>\n";
265 function label_cell($label, $params="", $id=null)
271 $params .= " id='$id'";
272 $Ajax->addUpdate($id, $id, $label);
274 echo "<td $params>$label</td>\n";
279 function amount_cell($label, $bold=false, $params="", $id=null)
282 label_cell("<b>".price_format($label)."</b>", "nowrap align=right ".$params, $id);
284 label_cell(price_format($label), "nowrap align=right ".$params, $id);
287 function percent_cell($label, $bold=false, $id=null)
290 label_cell("<b>".percent_format($label)."</b>", "nowrap align=right", $id);
292 label_cell(percent_format($label), "nowrap align=right", $id);
294 // 2008-06-15. Changed
295 function qty_cell($label, $bold=false, $dec=null, $id=null)
298 $dec = get_qty_dec();
300 label_cell("<b>".number_format2($label, $dec)."</b>", "nowrap align=right", $id);
302 label_cell(number_format2($label, $dec), "nowrap align=right", $id);
305 function label_cells($label, $value, $params="", $params2="")
308 echo "<td $params>$label</td>\n";
309 echo "<td $params2>$value</td>\n";
312 function label_row($label, $value, $params="", $params2="", $leftfill=0)
315 label_cells($label, $value, $params, $params2);
317 echo "<td colspan=$leftfill></td>";
321 //-----------------------------------------------------------------------------------
323 function text_cells($label, $name, $value=null, $size="", $max="", $title=false, $params="", $post_label="", $disabled="")
327 default_focus($name);
329 label_cell($label, $params);
333 $value = get_post($name);
334 echo "<input $disabled type=\"text\" name=\"$name\" size=\"$size\" maxlength=\"$max\" value=\"$value\""
335 .($title ? " title='$title'" : '')
338 if ($post_label != "")
339 echo " " . $post_label;
342 $Ajax->addUpdate($name, $name, $value);
345 function text_cells_ex($label, $name, $size, $max=null, $init=null, $title=null, $params=null, $post_label=null, $submit_on_change=false)
349 default_focus($name);
350 if (!isset($_POST[$name]) || $_POST[$name] == "")
353 $_POST[$name] = $init;
358 label_cell($label, $params);
364 $class = $submit_on_change ? 'class="searchbox"' : '';
365 echo "<input $class type=\"text\" name=\"$name\" size=\"$size\" maxlength=\"$max\" value=\"" . $_POST[$name]. "\""
366 .($title ? " title='$title'": '')." >";
369 echo " " . $post_label;
372 $Ajax->addUpdate($name, $name, $_POST[$name]);
375 function text_row($label, $name, $value, $size, $max, $title=null, $params="", $post_label="")
379 text_cells($label, $name, $value, $size, $max, $title, $params, $post_label);
384 //-----------------------------------------------------------------------------------
386 function text_row_ex($label, $name, $size, $max=null, $title=null, $value=null, $params=null, $post_label=null)
390 text_cells_ex($label, $name, $size, $max, $value, $title, $params, $post_label);
395 //-----------------------------------------------------------------------------------
397 function date_cells($label, $name, $title = null, $init=null, $inc_days=0,
398 $inc_months=0, $inc_years=0, $params=null, $submit_on_change=false)
400 global $use_date_picker, $path_to_root;
401 if (!isset($_POST[$name]) || $_POST[$name] == "")
405 if ($inc_years == 1001)
406 $_POST[$name] = null;
411 $dd = add_days($dd, $inc_days);
412 if ($inc_months != 0)
413 $dd = add_months($dd, $inc_months);
415 $dd = add_years($dd, $inc_years);
420 $_POST[$name] = $init;
422 if ($use_date_picker)
423 $post_label = "<a tabindex='-1' href=\"javascript:date_picker(document.getElementsByName('$name')[0]);\">"
424 . " <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";
427 text_cells_ex($label, $name, 9, 12, $_POST[$name], $title, $params, $post_label, $submit_on_change);
430 function date_row($label, $name, $title=null, $init=null, $inc_days=0, $inc_months=0,
431 $inc_years=0, $params=null, $submit_on_change=false)
434 date_cells($label, $name, $title, $init, $inc_days, $inc_months,
435 $inc_years, $params, $submit_on_change);
439 //-----------------------------------------------------------------------------------
441 function ref_cells($label, $name, $title=null, $init=null, $params=null, $submit_on_change=false)
443 text_cells_ex($label, $name, 16, 18, $init, $title, $params, null, $submit_on_change);
446 //-----------------------------------------------------------------------------------
448 function ref_row($label, $name, $title=null, $init=null, $submit_on_change=false)
451 ref_cells($label, $name, $title, $init, null, $submit_on_change);
455 //-----------------------------------------------------------------------------------
457 function percent_row($label, $name, $init=null)
460 if (!isset($_POST[$name]) || $_POST[$name]=="")
462 $_POST[$name] = $init == null ? '' : $init;
465 small_amount_row($label, $name, $_POST[$name], null, "%", user_percent_dec());
468 function amount_cells_ex($label, $name, $size, $max=null, $init=null, $params=null, $post_label=null, $dec=null)
473 $dec = user_price_dec();
474 if (!isset($_POST[$name]) || $_POST[$name] == "")
477 $_POST[$name] = $init;
482 label_cell($label, $params);
489 echo "<input class='amount' type=\"text\" name=\"$name\" size=\"$size\" maxlength=\"$max\" dec=\"$dec\" value=\"" . $_POST[$name]. "\">";
492 echo " " . $post_label;
495 $Ajax->addUpdate($name, $name, $_POST[$name]);
496 $Ajax->addAssign($name, $name, 'dec', $dec);
500 //-----------------------------------------------------------------------------------
502 function amount_cells($label, $name, $init=null, $params=null, $post_label=null, $dec=null)
504 amount_cells_ex($label, $name, 15, 15, $init, $params, $post_label, $dec);
507 function amount_row($label, $name, $init=null, $params=null, $post_label=null, $dec=null)
510 amount_cells($label, $name, $init, $params, $post_label, $dec);
514 function small_amount_row($label, $name, $init=null, $params=null, $post_label=null, $dec=null)
517 small_amount_cells($label, $name, $init, $params, $post_label, $dec);
521 //-----------------------------------------------------------------------------------
523 function qty_cells($label, $name, $init=null, $params=null, $post_label=null, $dec=null)
526 $dec = user_qty_dec();
528 amount_cells_ex($label, $name, 15, 15, $init, $params, $post_label, $dec);
531 function qty_row($label, $name, $init=null, $params=null, $post_label=null, $dec=null)
534 $dec = user_qty_dec();
537 amount_cells($label, $name, $init, $params, $post_label, $dec);
541 function small_qty_row($label, $name, $init=null, $params=null, $post_label=null, $dec=null)
544 $dec = user_qty_dec();
547 small_amount_cells($label, $name, $init, $params, $post_label, $dec);
551 //-----------------------------------------------------------------------------------
553 function small_amount_cells($label, $name, $init=null, $params=null, $post_label=null, $dec=null)
555 amount_cells_ex($label, $name, 7, 12, $init, $params, $post_label, $dec);
558 //-----------------------------------------------------------------------------------
560 function small_qty_cells($label, $name, $init=null, $params=null, $post_label=null, $dec=null)
563 $dec = user_qty_dec();
564 amount_cells_ex($label, $name, 7, 12, $init, $params, $post_label, $dec);
567 //-----------------------------------------------------------------------------------
569 function textarea_cells($label, $name, $value, $cols, $rows, $title = null, $params="")
573 default_focus($name);
575 echo "<td $params>$label</td>\n";
577 $value = (!isset($_POST[$name]) ? "" : $_POST[$name]);
578 echo "<td><textarea name='$name' cols='$cols' rows='$rows'"
579 .($title ? " title='$title'" : '')
580 .">$value</textarea></td>\n";
581 $Ajax->addUpdate($name, $name, $value);
584 function textarea_row($label, $name, $value, $cols, $rows, $title=null, $params="")
587 textarea_cells($label, $name, $value, $cols, $rows, $title, $params);
591 //-----------------------------------------------------------------------------------
593 function text_row_with_submit($label, $name, $value, $size, $max, $input_name, $input_value)
597 default_focus($name);
598 echo "<tr><td>$label</td>\n";
602 $value = (!isset($_POST[$name]) ? "" : $_POST[$name]);
603 echo "<input type=\"text\" name=\"$name\" size=\"$size\" maxlength=\"$max\" value=\"$value\"> ";
605 submit($input_name, $input_value);
608 $Ajax->addUpdate($name, $name, $value);
611 //-----------------------------------------------------------------------------------