Defaults for get_post also for array submits, added confirm dialog helper.
authorJanusz Dobrowolski <janusz@frontaccounting.eu>
Sat, 23 Jan 2010 18:26:17 +0000 (18:26 +0000)
committerJanusz Dobrowolski <janusz@frontaccounting.eu>
Sat, 23 Jan 2010 18:26:17 +0000 (18:26 +0000)
includes/ui/ui_controls.inc

index 9848761e263ac7e95eed708823810caf85d75d34..f6aec6cf1f473db6aa776f6a94d975048ae233cc 100644 (file)
@@ -9,9 +9,27 @@
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
     See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
 ***********************************************************************/
+/*
+       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