X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=includes%2Fui%2Fui_input.inc;h=3da07206ac88c05321bf6260661bc22f5f0839c5;hb=120314d9597fde0592600a37d82a3bad431ad5af;hp=0f20919277ad65138640d96f9a08b12e3d4d5b1c;hpb=f6e1b649fc75750383b17c2ced6a5c1d6f19fe2e;p=fa-stable.git diff --git a/includes/ui/ui_input.inc b/includes/ui/ui_input.inc index 0f209192..3da07206 100644 --- a/includes/ui/ui_input.inc +++ b/includes/ui/ui_input.inc @@ -1,10 +1,21 @@ . +***********************************************************************/ + +function get_post($name, $dflt='') +{ return ((!isset($_POST[$name]) || $_POST[$name] === '') ? $dflt : $_POST[$name]); } // -// Sets local POST value and adds Value to ajax posting if needed +// Sets local POST value and adds Value to ajax posting if needed // /*function set_post($name, $value, $ajax_trigger=true) { global $Ajax; @@ -18,84 +29,137 @@ function get_post($name, $dflt='') { // If var is found returns variable name with prefix stripped, // and null or -1 otherwise. // -function find_submit($prefix, $numeric=true) { +function find_submit($prefix, $numeric=true) +{ - foreach($_POST as $postkey=>$postval ) { - if (strpos($postkey, $prefix) === 0) { - $id = substr($postkey, strlen($prefix)); - return $numeric ? (int)$id : $id; - } + foreach($_POST as $postkey=>$postval ) + { + if (strpos($postkey, $prefix) === 0) + { + $id = substr($postkey, strlen($prefix)); + return $numeric ? (int)$id : $id; + } } 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) { - if (!isset($_POST[$postname])) - return null; +function input_num($postname=null, $dflt=null) +{ + if (!isset($_POST[$postname]) || $_POST[$postname] == "") + return $dflt; return user_numeric($_POST[$postname]); } //--------------------------------------------------------------------------------- -function hidden($name, $value) +function hidden($name, $value=null, $echo=true) { - global $Ajax; - echo "\n"; + global $Ajax; + + if ($value === null) + $value = get_post($name); + + $ret = ""; $Ajax->addUpdate($name, $name, $value); + if ($echo) + echo $ret."\n"; + else + return $ret; } -//--------------------------------------------------------------------------------- - -function submit($name, $value, $echo=true, $async=false) +function submit($name, $value, $echo=true, $title=false, $async=false, $icon=false) { + global $path_to_root; + default_focus($name); - $submit_str = "\n"; + $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) +function submit_add_or_update($add=true, $title=false, $async=false) { 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, $title, $async); + submit('RESET', _("Cancel"), true, $title, $async); + } } -function submit_add_or_update_center($add=true, $async=false) +function submit_add_or_update_center($add=true, $title=false, $async=false) { echo "
"; - submit_add_or_update($add, $async); + submit_add_or_update($add, $title, $async); echo "
"; } @@ -107,46 +171,81 @@ function submit_add_or_update_row($add=true) 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) { echo ""; if ($right) echo " \n"; echo ""; - submit_add_or_update($add, $async); + submit_add_or_update($add, $title, $async); 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, $async=false) +{ + if (count($_SESSION['Context'])) { + submit($name, $value, true, $title, $async); + } +} +//----------------------------------------------------------------------------------- + +function set_icon($icon, $title=false) { - default_focus($name); - echo "\n"; + global $path_to_root; + return "\n"; +} + +function button($name, $value, $title=false, $icon=false) +{ + // php silently changes dots,spaces,'[' and characters 128-159 + // to underscore in POST names, to maintain compatibility with register_globals + if (user_graphic_links() && $icon) + { + if ($value == _("Delete")) // Helper during implementation + $icon = ICON_DELETE; + return "