X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=includes%2Fui%2Fui_input.inc;h=f1fb3691c1d6d45914a4b602ac49e6e0f0001e99;hb=0ad69edb5561aac03a5af49286c37b3350307719;hp=6811076c427c44bd5b66d637360c9e516dea05d0;hpb=d67d5295b9342c011697ce4df325197e29898588;p=fa-stable.git
diff --git a/includes/ui/ui_input.inc b/includes/ui/ui_input.inc
index 6811076c..f1fb3691 100644
--- a/includes/ui/ui_input.inc
+++ b/includes/ui/ui_input.inc
@@ -32,24 +32,60 @@ function find_submit($prefix, $numeric=true)
}
return $numeric ? -1 : null;
}
+//------------------------------------------------------------------------------
+//
+// Helper function for simple db table editor pages
+//
+function simple_page_mode($numeric_id = true)
+{
+ global $Ajax, $Mode, $selected_id;
+
+ $default = $numeric_id ? -1 : '';
+ $selected_id = get_post('selected_id', $default);
+ foreach (array('ADD_ITEM', 'UPDATE_ITEM', 'RESET') as $m) {
+ if (isset($_POST[$m])) {
+ $Ajax->activate('_page_body');
+ if ($m == 'RESET')
+ $selected_id = $default;
+ $Mode = $m; return;
+ }
+ }
+ foreach (array('Edit', 'Delete') as $m) {
+ foreach ($_POST as $p => $pvar) {
+ if (strpos($p, $m) === 0) {
+// $selected_id = strtr(substr($p, strlen($m)), array('%2E'=>'.'));
+ unset($_POST['_focus']); // focus on first form entry
+ $selected_id = quoted_printable_decode(substr($p, strlen($m)));
+ $Ajax->activate('_page_body');
+ $Mode = $m;
+ return;
+ }
+ }
+ }
+ $Mode = '';
+}
//------------------------------------------------------------------------------
//
// Read numeric value from user formatted input
//
-function input_num($postname=null)
+function input_num($postname=null, $dflt=null)
{
if (!isset($_POST[$postname]))
- return null;
+ return $dflt;
return user_numeric($_POST[$postname]);
}
//---------------------------------------------------------------------------------
-function hidden($name, $value, $echo=true)
+function hidden($name, $value=null, $echo=true)
{
global $Ajax;
+
+ if ($value === null)
+ $value = get_post($name);
+
$ret = "";
$Ajax->addUpdate($name, $name, $value);
if ($echo)
@@ -59,13 +95,23 @@ function hidden($name, $value, $echo=true)
}
//---------------------------------------------------------------------------------
-
+// Submit button.
+// $async parameter can have 3 values:
+// null - fallback button not visible in js enabled mode
+// false - normal submit via form action
+// true - when js is on submition via ajax call
+// 'process' - ditto with processing indicator in msgbox
+//
function submit($name, $value, $echo=true, $title=false, $async=false)
{
+
default_focus($name);
$submit_str = "\n";
if ($echo)
@@ -98,9 +144,11 @@ function submit_center_last($name, $value, $title=false, $async=false)
function submit_add_or_update($add=true, $title=false, $async=false)
{
if ($add)
- submit('ADD_ITEM', _("Save"), true, $title, $async);
- else
+ submit('ADD_ITEM', _("Add new"), true, $title, $async);
+ else {
submit('UPDATE_ITEM', _("Update"), true, $title, $async);
+ submit('RESET', _("Cancel"), true, $title, $async);
+ }
}
function submit_add_or_update_center($add=true, $title=false, $async=false)
@@ -140,7 +188,7 @@ function submit_row($name, $value, $right=true, $extra="", $title=false, $async=
echo "
";
if ($right)
echo " | \n";
- submit_cells($name, $value, $extra, $title);
+ submit_cells($name, $value, $extra, $title, $async);
echo "
\n";
}
//---------------------------------------------------------------------------------
@@ -169,7 +217,7 @@ function check_value($name)
return 1;
}
-function check($label, $name, $value, $submit_on_change=false, $title=false)
+function check($label, $name, $value=null, $submit_on_change=false, $title=false)
{
global $Ajax;
@@ -177,13 +225,13 @@ function check($label, $name, $value, $submit_on_change=false, $title=false)
if ($label)
echo $label . " ";
- if ($value == null)
- $value = (!isset($_POST[$name]) ? 0 : $_POST[$name]);
-
+ if ($value === null)
+ $value = get_post($name,0);
+
echo "\n";
$Ajax->addUpdate($name, $name, $value);
@@ -241,13 +289,15 @@ function percent_cell($label, $bold=false, $id=null)
else
label_cell(percent_format($label), "nowrap align=right", $id);
}
-
+// 2008-06-15. Changed
function qty_cell($label, $bold=false, $dec=null, $id=null)
{
+ if ($dec == null)
+ $dec = get_qty_dec();
if ($bold)
- label_cell("".qty_format($label, $dec)."", "nowrap align=right", $id);
+ label_cell("".number_format2($label, $dec)."", "nowrap align=right", $id);
else
- label_cell(qty_format($label, $dec), "nowrap align=right", $id);
+ label_cell(number_format2($label, $dec), "nowrap align=right", $id);
}
function label_cells($label, $value, $params="", $params2="")
@@ -268,7 +318,7 @@ function label_row($label, $value, $params="", $params2="", $leftfill=0)
//-----------------------------------------------------------------------------------
-function text_cells($label, $name, $value, $size="", $max="", $title=false, $params="", $post_label="", $disabled="")
+function text_cells($label, $name, $value=null, $size="", $max="", $title=false, $params="", $post_label="", $disabled="")
{
global $Ajax;
@@ -277,8 +327,8 @@ function text_cells($label, $name, $value, $size="", $max="", $title=false, $par
label_cell($label, $params);
echo "";
- if ($value == null)
- $value = (!isset($_POST[$name]) ? "" : $_POST[$name]);
+ if ($value === null)
+ $value = get_post($name);
echo "";
@@ -290,7 +340,7 @@ function text_cells($label, $name, $value, $size="", $max="", $title=false, $par
$Ajax->addUpdate($name, $name, $value);
}
-function text_cells_ex($label, $name, $size, $max=null, $init=null, $title=null, $params=null, $post_label=null)
+function text_cells_ex($label, $name, $size, $max=null, $init=null, $title=null, $params=null, $post_label=null, $submit_on_change=false)
{
global $Ajax;
@@ -309,8 +359,8 @@ function text_cells_ex($label, $name, $size, $max=null, $init=null, $title=null,
$max = $size;
echo " | ";
-
- echo "";
if ($post_label)
@@ -367,7 +417,7 @@ function date_cells($label, $name, $title = null, $init=null, $inc_days=0, $inc_
$_POST[$name] = $init;
}
if ($use_date_picker)
- $post_label = ""
+ $post_label = ""
. " \n";
else
$post_label = "";
@@ -383,17 +433,17 @@ function date_row($label, $name, $title=null, $init=null, $inc_days=0, $inc_mont
//-----------------------------------------------------------------------------------
-function ref_cells($label, $name, $title=null, $init=null, $params=null)
+function ref_cells($label, $name, $title=null, $init=null, $params=null, $submit_on_change=false)
{
- text_cells_ex($label, $name, 16, 18, $init, $title, $params);
+ text_cells_ex($label, $name, 16, 18, $init, $title, $params, null, $submit_on_change);
}
//-----------------------------------------------------------------------------------
-function ref_row($label, $name, $title=null, $init=null)
+function ref_row($label, $name, $title=null, $init=null, $submit_on_change=false)
{
echo " | ";
- ref_cells($label, $name, $title, $init);
+ ref_cells($label, $name, $title, $init, null, $submit_on_change);
echo "
\n";
}
@@ -404,7 +454,7 @@ function percent_row($label, $name, $init=null)
if (!isset($_POST[$name]) || $_POST[$name]=="")
{
- $_POST[$name] = $init== null ? '' : $init;
+ $_POST[$name] = $init == null ? '' : $init;
}
small_amount_row($label, $name, $_POST[$name], null, "%", user_percent_dec());
@@ -418,7 +468,7 @@ function amount_cells_ex($label, $name, $size, $max=null, $init=null, $params=nu
$dec = user_price_dec();
if (!isset($_POST[$name]) || $_POST[$name] == "")
{
- if ($init)
+ if ($init !== null)
$_POST[$name] = $init;
else
$_POST[$name] = '';
@@ -438,6 +488,7 @@ function amount_cells_ex($label, $name, $size, $max=null, $init=null, $params=nu
echo "\n";
$Ajax->addUpdate($name, $name, $_POST[$name]);
+ $Ajax->addAssign($name, $name, 'dec', $dec);
}