Convert date from German format to ISO
authorJoey Schulze <joey@infodrom.org>
Sun, 13 Feb 2011 23:07:29 +0000 (00:07 +0100)
committerJoey Schulze <joey@infodrom.org>
Sun, 13 Feb 2011 23:07:29 +0000 (00:07 +0100)
ajax/ajax.php

index 5b52733..016612f 100644 (file)
@@ -75,6 +75,14 @@ function details($mask)
   return $row;
 }
 
+function format_date($value)
+{
+  $d = explode('.', $value);
+  if (count($d) == 3)
+    $value = sprintf('%d-%d-%d', $d[2], $d[1], $d[0]);
+  return $value;
+}
+
 function format_decimal($value)
 {
   $value = str_replace(',','.',$value);
@@ -109,6 +117,11 @@ function save($mask)
         $update[] = sprintf("%s=NULL", $field);
       else
        $update[] = sprintf("%s=%s", $field, format_decimal($_POST[$field]));
+    } elseif ($info['type'] == 'date') {
+      if (empty($_POST[$field]) && $info['null'] === true)
+        $update[] = sprintf("%s=NULL", $field);
+      else
+       $update[] = sprintf("%s='%s'", $field, format_date($_POST[$field]));
     } elseif ($info['type'] == 'passwd') {
       if (!empty($_POST[$field]))
        $update[] = sprintf("%s='%s'", $field,
@@ -166,6 +179,12 @@ function insert($mask)
        $values[] = 'NULL';
       else
        $values[] = format_decimal($_POST[$field]);
+    } elseif ($info['type'] == 'date') {
+      $fields[] = $field;
+      if (empty($_POST[$field]) && $info['null'] === true)
+       $values[] = 'NULL';
+      else
+       $values[] = "'" . format_date($_POST[$field]) . "'";
     } elseif ($info['type'] == 'passwd') {
       if (!empty($_POST[$field])) {
        $fields[] = $field;