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;
36 //------------------------------------------------------------------------------
38 // Read numeric value from user formatted input
40 function input_num($postname=null)
42 if (!isset($_POST[$postname]))
45 return user_numeric($_POST[$postname]);
48 //---------------------------------------------------------------------------------
50 function hidden($name, $value, $echo=true)
53 $ret = "<input type=\"hidden\" name=\"$name\" value=\"$value\">";
54 $Ajax->addUpdate($name, $name, $value);
61 //---------------------------------------------------------------------------------
63 function submit($name, $value, $echo=true, $async=false)
66 $submit_str = "<input type=\"submit\" class=\""
67 .($async ? 'ajaxsubmit' : 'inputsubmit')
68 ."\" name=\"$name\" id=\"$name\" value=\"$value\" >\n";
75 function submit_center($name, $value, $echo=true, $async=false)
78 submit($name, $value, $echo, $async);
82 function submit_center_first($name, $value, $async=false)
85 submit($name, $value, true, $async);
89 function submit_center_last($name, $value, $async=false)
92 submit($name, $value, true, $async);
96 function submit_add_or_update($add=true, $async=false)
99 submit('ADD_ITEM', _("Save"), true, $async);
101 submit('UPDATE_ITEM', _("Update"), true, $async);
104 function submit_add_or_update_center($add=true, $async=false)
107 submit_add_or_update($add, $async);
112 function submit_add_or_update_row($add=true)
114 echo "<tr><td colspan=99 align=center>";
115 submit_add_or_update($add);
119 function submit_add_or_update_row($add=true, $right=true, $extra="", $async=false)
123 echo "<td> </td>\n";
125 submit_add_or_update($add, $async);
129 function submit_cells($name, $value, $extra="", $async=false)
132 submit($name, $value, true, $async);
136 function submit_row($name, $value, $right=true, $extra="", $async=false)
140 echo "<td> </td>\n";
141 submit_cells($name, $value, $extra);
144 //---------------------------------------------------------------------------------
146 function button($name, $value, $onclick)
148 default_focus($name);
149 echo "<input type=\"button\" class=\"inputsubmit\" name=\"$name\" value=\"$value\" onclick=\"$onclick\" />\n";
152 function button_cell($name, $value, $onclick)
155 button($name, $value, $onclick);
159 //-----------------------------------------------------------------------------------
161 function check_value($name)
163 if (!isset($_POST[$name]))
168 function check($label, $name, $value, $submit_on_change=false)
172 default_focus($name);
177 $value = (!isset($_POST[$name]) ? 0 : $_POST[$name]);
179 echo "<input checked type='checkbox' name='$name' value='1' ";
181 echo "<input type='checkbox' name='$name' value='1'";
182 if ($submit_on_change)
183 echo " onclick='this.form.submit();' ";
185 $Ajax->addUpdate($name, $name, $value);
188 function check_cells($label, $name, $value, $submit_on_change=false)
191 echo "<td>$label</td>\n";
193 check(null, $name, $value, $submit_on_change);
197 function check_row($label, $name, $value, $submit_on_change=false)
200 check_cells($label, $name, $value, $submit_on_change);
204 //-----------------------------------------------------------------------------------
206 function labelheader_cell($label, $params="")
208 echo "<td class='tableheader' $params>$label</td>\n";
211 function label_cell($label, $params="", $id=null)
217 $params .= " id='$id'";
218 $Ajax->addUpdate($id, $id, $label);
220 echo "<td $params>$label</td>\n";
225 function amount_cell($label, $bold=false, $params="", $id=null)
228 label_cell("<b>".price_format($label)."</b>", "nowrap align=right ".$params, $id);
230 label_cell(price_format($label), "nowrap align=right ".$params, $id);
233 function percent_cell($label, $bold=false, $id=null)
236 label_cell("<b>".percent_format($label)."</b>", "nowrap align=right", $id);
238 label_cell(percent_format($label), "nowrap align=right", $id);
241 function qty_cell($label, $bold=false, $dec=null, $id=null)
244 label_cell("<b>".qty_format($label, $dec)."</b>", "nowrap align=right", $id);
246 label_cell(qty_format($label, $dec), "nowrap align=right", $id);
249 function label_cells($label, $value, $params="", $params2="")
252 echo "<td $params>$label</td>\n";
253 echo "<td $params2>$value</td>\n";
256 function label_row($label, $value, $params="", $params2="", $leftfill=0)
259 label_cells($label, $value, $params, $params2);
261 echo "<td colspan=$leftfill></td>";
265 //-----------------------------------------------------------------------------------
267 function text_cells($label, $name, $value, $size="", $max="", $params="", $post_label="", $disabled="")
271 default_focus($name);
273 label_cell($label, $params);
277 $value = (!isset($_POST[$name]) ? "" : $_POST[$name]);
278 echo "<input $disabled type=\"text\" name=\"$name\" size=\"$size\" maxlength=\"$max\" value=\"$value\">";
280 if ($post_label != "")
281 echo " " . $post_label;
284 $Ajax->addUpdate($name, $name, $value);
287 function text_cells_ex($label, $name, $size, $max=null, $init=null, $params=null, $post_label=null)
291 default_focus($name);
292 if (!isset($_POST[$name]) || $_POST[$name] == "")
295 $_POST[$name] = $init;
300 label_cell($label, $params);
307 echo "<input type=\"text\" name=\"$name\" size=\"$size\" maxlength=\"$max\" value=\"" . $_POST[$name]. "\">";
310 echo " " . $post_label;
313 $Ajax->addUpdate($name, $name, $_POST[$name]);
316 function text_row($label, $name, $value, $size, $max, $params="", $post_label="")
320 text_cells($label, $name, $value, $size, $max, $params, $post_label);
325 //-----------------------------------------------------------------------------------
327 function text_row_ex($label, $name, $size, $max=null, $value=null, $params=null, $post_label=null)
331 text_cells_ex($label, $name, $size, $max, $value, $params, $post_label);
336 //-----------------------------------------------------------------------------------
338 function date_cells($label, $name, $init=null, $inc_days=0, $inc_months=0, $inc_years=0, $params=null)
340 global $use_date_picker, $path_to_root;
341 if (!isset($_POST[$name]) || $_POST[$name] == "")
345 if ($inc_years == 1001)
346 $_POST[$name] = null;
351 $dd = add_days($dd, $inc_days);
352 if ($inc_months != 0)
353 $dd = add_months($dd, $inc_months);
355 $dd = add_years($dd, $inc_years);
360 $_POST[$name] = $init;
362 if ($use_date_picker)
363 $post_label = "<a tabindex='-1' href=\"javascript:date_picker(document.forms[0].$name);\">"
364 . " <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";
367 text_cells_ex($label, $name, 9, 12, $_POST[$name], $params, $post_label);
370 function date_row($label, $name, $init=null, $inc_days=0, $inc_months=0, $inc_years=0, $params=null)
373 date_cells($label, $name, $init, $inc_days, $inc_months, $inc_years, $params);
377 //-----------------------------------------------------------------------------------
379 function ref_cells($label, $name, $init=null, $params=null)
381 text_cells_ex($label, $name, 16, 18, $init, $params);
384 //-----------------------------------------------------------------------------------
386 function ref_row($label, $name, $init=null)
389 ref_cells($label, $name, $init);
393 //-----------------------------------------------------------------------------------
395 function percent_row($label, $name, $init=null)
398 if (!isset($_POST[$name]) || $_POST[$name]=="")
400 $_POST[$name] = $init== null ? '' : $init;
403 small_amount_row($label, $name, $_POST[$name], null, "%", user_percent_dec());
406 function amount_cells_ex($label, $name, $size, $max=null, $init=null, $params=null, $post_label=null, $dec=null)
411 $dec = user_price_dec();
412 if (!isset($_POST[$name]) || $_POST[$name] == "")
415 $_POST[$name] = $init;
420 label_cell($label, $params);
427 echo "<input class='amount' type=\"text\" name=\"$name\" size=\"$size\" maxlength=\"$max\" dec=\"$dec\" value=\"" . $_POST[$name]. "\">";
430 echo " " . $post_label;
433 $Ajax->addUpdate($name, $name, $_POST[$name]);
437 //-----------------------------------------------------------------------------------
439 function amount_cells($label, $name, $init=null, $params=null, $post_label=null, $dec=null)
441 amount_cells_ex($label, $name, 15, 15, $init, $params, $post_label, $dec);
444 function amount_row($label, $name, $init=null, $params=null, $post_label=null, $dec=null)
447 amount_cells($label, $name, $init, $params, $post_label, $dec);
451 function small_amount_row($label, $name, $init=null, $params=null, $post_label=null, $dec=null)
454 small_amount_cells($label, $name, $init, $params, $post_label, $dec);
458 //-----------------------------------------------------------------------------------
460 function qty_cells($label, $name, $init=null, $params=null, $post_label=null, $dec=null)
463 $dec = user_qty_dec();
465 amount_cells_ex($label, $name, 15, 15, $init, $params, $post_label, $dec);
468 function qty_row($label, $name, $init=null, $params=null, $post_label=null, $dec=null)
471 $dec = user_qty_dec();
474 amount_cells($label, $name, $init, $params, $post_label, $dec);
478 function small_qty_row($label, $name, $init=null, $params=null, $post_label=null, $dec=null)
481 $dec = user_qty_dec();
484 small_amount_cells($label, $name, $init, $params, $post_label, $dec);
488 //-----------------------------------------------------------------------------------
490 function small_amount_cells($label, $name, $init=null, $params=null, $post_label=null, $dec=null)
492 amount_cells_ex($label, $name, 7, 12, $init, $params, $post_label, $dec);
495 //-----------------------------------------------------------------------------------
497 function small_qty_cells($label, $name, $init=null, $params=null, $post_label=null, $dec=null)
500 $dec = user_qty_dec();
501 amount_cells_ex($label, $name, 7, 12, $init, $params, $post_label, $dec);
504 //-----------------------------------------------------------------------------------
506 function textarea_cells($label, $name, $value, $cols, $rows, $params="")
510 default_focus($name);
512 echo "<td $params>$label</td>\n";
514 $value = (!isset($_POST[$name]) ? "" : $_POST[$name]);
515 echo "<td><textarea name='$name' cols='$cols' rows='$rows'>$value</textarea></td>\n";
516 $Ajax->addUpdate($name, $name, $value);
519 function textarea_row($label, $name, $value, $cols, $rows, $params="")
522 textarea_cells($label, $name, $value, $cols, $rows, $params);
526 //-----------------------------------------------------------------------------------
528 function text_row_with_submit($label, $name, $value, $size, $max, $input_name, $input_value)
532 default_focus($name);
533 echo "<tr><td>$label</td>\n";
537 $value = (!isset($_POST[$name]) ? "" : $_POST[$name]);
538 echo "<input type=\"text\" name=\"$name\" size=\"$size\" maxlength=\"$max\" value=\"$value\"> ";
540 submit($input_name, $input_value);
543 $Ajax->addUpdate($name, $name, $value);
546 //-----------------------------------------------------------------------------------