From 31966256a900343308ce287a246fe3a52e9a613c Mon Sep 17 00:00:00 2001 From: Janusz Dobrowolski Date: Sat, 23 Jan 2010 18:26:17 +0000 Subject: [PATCH] Defaults for get_post also for array submits, added confirm dialog helper. --- includes/ui/ui_controls.inc | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/includes/ui/ui_controls.inc b/includes/ui/ui_controls.inc index 9848761e..f6aec6cf 100644 --- a/includes/ui/ui_controls.inc +++ b/includes/ui/ui_controls.inc @@ -9,9 +9,27 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the License here . ***********************************************************************/ +/* + Retrieve value of POST variable(s). + For $name passed as array $dflt is not used, + default values can be passed as values with non-numeric keys instead. + If some field have user formatted numeric value, pass float default value to + convert automatically to POSIX. +*/ function get_post($name, $dflt='') { - return ((!isset($_POST[$name]) || $_POST[$name] === '') ? $dflt : $_POST[$name]); + if (is_array($name)) { + $ret = array(); + foreach($name as $key => $dflt) + if (!is_numeric($key)) { + $ret[$key] = is_float($dflt) ? input_num($key, $dflt) : get_post($key, $dflt); + } else { + $ret[$dflt] = get_post($dflt, null); + } + return $ret; + } else + return is_float($dflt) ? input_num($name, $dflt) : + ((!isset($_POST[$name]) || $_POST[$name] === '') ? $dflt : $_POST[$name]); } //--------------------------------------------------------------------------------- @@ -460,4 +478,15 @@ function editor_return($vars, $restore_fun='') { } } +function confirm_dialog($submit, $msg) { + if (find_post($submit)) { + display_warning($msg); + br(); + submit_center_first('DialogConfirm', _("Proceed"), '', true); + submit_center_last('DialogCancel', _("Cancel"), '', 'cancel'); + return 0; + } else + return get_post('DialogConfirm', 0); +} + ?> \ No newline at end of file -- 2.30.2