X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=includes%2Fui%2Fui_input.inc;h=1b73f1a40397d848dca2c422dbc123c4637e6a96;hb=510d6e1925c4d1621ae3efd85e117cc9bb4320f0;hp=829ff753c98391b3f94b79f23f4aca357f267a2d;hpb=bc426821d8ae6319bd9394ac275bb700e6394fc3;p=fa-stable.git
diff --git a/includes/ui/ui_input.inc b/includes/ui/ui_input.inc
index 829ff753..1b73f1a4 100644
--- a/includes/ui/ui_input.inc
+++ b/includes/ui/ui_input.inc
@@ -1,9 +1,14 @@
.
+***********************************************************************/
//
// Sets local POST value and adds Value to ajax posting if needed
//
@@ -32,24 +37,61 @@ 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', 'CLONE') as $m) {
+ if (isset($_POST[$m])) {
+ $Ajax->activate('_page_body');
+ if ($m == 'RESET' || $m == 'CLONE')
+ $selected_id = $default;
+ unset($_POST['_focus']);
+ $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;
+ if (!isset($_POST[$postname]) || $_POST[$postname] == "")
+ 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)
@@ -57,105 +99,210 @@ function hidden($name, $value, $echo=true)
else
return $ret;
}
-
-//---------------------------------------------------------------------------------
-
-function submit($name, $value, $echo=true, $async=false)
-{
- default_focus($name);
- $submit_str = "\n";
+/*
+ Universal submit form button.
+ $atype - type of submit:
+ Normal submit:
+ false - normal button; optional icon
+ null - button visible only in fallback mode; optional icon
+ Ajax submit:
+ true - standard button; optional icon
+ 'process' - displays progress bar during call; optional icon
+ 'default' - default form submit on Ctrl-Enter press; dflt ICON_OK icon
+ 'selector' - ditto with closing current popup editor window
+ 'cancel' - cancel form entry on Escape press; dflt ICON_CANCEL
+*/
+function submit($name, $value, $echo=true, $title=false, $atype=false, $icon=false)
+{
+ global $path_to_root;
+
+ $aspect='';
+ if (!is_bool($atype)) // necessary: switch uses '=='
+ switch($atype) {
+ case 'process':
+ $aspect = " aspect='process'"; break;
+ case 'selector':
+ $aspect = " aspect='selector' rel = '$value'";
+ $value = _("Select");
+ if ($icon===false) $icon=ICON_SUBMIT; break;
+ case 'default':
+ $aspect = " aspect='default'";
+ if ($icon===false) $icon=ICON_SUBMIT; break;
+ case 'cancel':
+ $aspect = " aspect='cancel'";
+ if ($icon===false) $icon=ICON_ESCAPE; break;
+ case null:
+ $aspect = fallback_mode() ?
+ " aspect='fallback'" : " style='display:none;'"; break;
+ }
+
+ $submit_str = "\n";
if ($echo)
echo $submit_str;
else
return $submit_str;
}
-function submit_center($name, $value, $echo=true, $async=false)
+function submit_center($name, $value, $echo=true, $title=false, $async=false, $icon=false)
{
echo "
";
- submit($name, $value, $echo, $async);
+ submit($name, $value, $echo, $title, $async, $icon);
echo "";
}
-function submit_center_first($name, $value, $async=false)
+function submit_center_first($name, $value, $title=false, $async=false, $icon=false)
{
echo "";
- submit($name, $value, true, $async);
+ submit($name, $value, true, $title, $async, $icon);
echo " ";
}
-function submit_center_last($name, $value, $async=false)
+function submit_center_last($name, $value, $title=false, $async=false, $icon=false)
{
echo " ";
- submit($name, $value, true, $async);
+ submit($name, $value, true, $title, $async, $icon);
echo "";
}
-
-function submit_add_or_update($add=true, $async=false)
-{
+/*
+ For following controls:
+ 'both' - use both Ctrl-Enter and Escape hotkeys
+ 'cancel' - apply to 'RESET' button
+*/
+function submit_add_or_update($add=true, $title=false, $async=false, $clone=false)
+{
+ $cancel = $async;
+
+ if ($async === 'both') {
+ $async = 'default'; $cancel = 'cancel';
+ }
+ else if ($async === 'default')
+ $cancel = true;
+ else if ($async === 'cancel')
+ $async = true;
+
if ($add)
- submit('ADD_ITEM', _("Save"), true, $async);
- else
- submit('UPDATE_ITEM', _("Update"), true, $async);
+ submit('ADD_ITEM', _("Add new"), true, $title, $async);
+ else {
+ submit('UPDATE_ITEM', _("Update"), true, _('Submit changes'), $async);
+ if ($clone) submit('CLONE', _("Clone"), true,
+ _('Edit new record with current data'), $async);
+ submit('RESET', _("Cancel"), true, _('Cancel edition'), $cancel);
+ }
}
-function submit_add_or_update_center($add=true, $async=false)
+function submit_add_or_update_center($add=true, $title=false, $async=false, $clone=false)
{
echo "";
- submit_add_or_update($add, $async);
+ submit_add_or_update($add, $title, $async, $clone);
echo "";
}
-/*
-function submit_add_or_update_row($add=true)
-{
- echo "";
- submit_add_or_update($add);
- echo " |
\n";
-}
-*/
-function submit_add_or_update_row($add=true, $right=true, $extra="", $async=false)
+function submit_add_or_update_row($add=true, $right=true, $extra="", $title=false, $async=false, $clone = false)
{
echo "";
if ($right)
echo " | \n";
echo "";
- submit_add_or_update($add, $async);
+ submit_add_or_update($add, $title, $async, $clone);
echo " |
\n";
}
-function submit_cells($name, $value, $extra="", $async=false)
+function submit_cells($name, $value, $extra="", $title=false, $async=false)
{
echo "";
- submit($name, $value, true, $async);
+ submit($name, $value, true, $title, $async);
echo " | \n";
}
-function submit_row($name, $value, $right=true, $extra="", $async=false)
+function submit_row($name, $value, $right=true, $extra="", $title=false, $async=false)
{
echo "";
if ($right)
echo " | \n";
- submit_cells($name, $value, $extra);
+ submit_cells($name, $value, $extra, $title, $async);
echo "
\n";
}
-//---------------------------------------------------------------------------------
-function button($name, $value, $onclick)
+function submit_return($name, $value, $title=false)
{
- default_focus($name);
- echo "\n";
+ if (@$_REQUEST['popup']) {
+ submit($name, $value, true, $title, 'selector');
+ }
}
-function button_cell($name, $value, $onclick)
+function submit_js_confirm($name, $msg) {
+ add_js_source(
+ "_validate.$name=function(){ return confirm('"
+ . strtr($msg, array("\n"=>'\\n')) . "');};");
+};
+//-----------------------------------------------------------------------------------
+
+function set_icon($icon, $title=false)
{
- echo "";
- button($name, $value, $onclick);
- echo " | \n";
+ global $path_to_root;
+ return "
\n";
}
+function button($name, $value, $title=false, $icon=false, $aspect='')
+{
+ // php silently changes dots,spaces,'[' and characters 128-159
+ // to underscore in POST names, to maintain compatibility with register_globals
+ $rel = '';
+ if ($aspect == 'selector') {
+ $rel = " rel='$value'";
+ $value = _("Select");
+ }
+ if (user_graphic_links() && $icon)
+ {
+ if ($value == _("Delete")) // Helper during implementation
+ $icon = ICON_DELETE;
+ return "