Add support for saving decimal values
[misc/kostenrechnung] / ajax / ajax.php
index 3894be2..bbef0e4 100644 (file)
@@ -53,6 +53,12 @@ function details($mask)
   return $row;
 }
 
+function format_decimal($value)
+{
+  $value = str_replace(',','.',$value);
+  return sprintf("%.2f", $value);
+}
+
 function save($mask)
 {
   if (empty($_POST['id']))
@@ -69,6 +75,11 @@ function save($mask)
         $update[] = sprintf("%s=NULL", $field);
       else
        $update[] = sprintf("%s=%d", $field, $_POST[$field]);
+    } elseif ($info['type'] == 'decimal') {
+      if (empty($_POST[$field]) && $info['null'] === true)
+        $update[] = sprintf("%s=NULL", $field);
+      else
+       $update[] = sprintf("%s=%s", $field, format_decimal($_POST[$field]));
     } elseif ($info['type'] == 'passwd') {
       if (!empty($_POST[$field]))
        $update[] = sprintf("%s='%s'", $field, pg_escape_string(passwd($_SESSION['sys']['login'],$_POST[$field])));
@@ -109,6 +120,12 @@ function insert($mask)
        $values[] = 'NULL';
       else
        $values[] = intval($_POST[$field]);
+    } elseif ($info['type'] == 'decimal') {
+      $fields[] = $field;
+      if (empty($_POST[$field]) && $info['null'] === true)
+       $values[] = 'NULL';
+      else
+       $values[] = format_decimal($_POST[$field]);
     } elseif ($info['type'] == 'passwd') {
       if (!empty($_POST[$field])) {
        $fields[] = $field;