Adjust form to new table einsatz and co.
[misc/kostenrechnung] / ajax / ajax.php
index 6597a76..2919669 100644 (file)
@@ -90,7 +90,7 @@ function save($mask)
                  "sys_edit = now()");
 
   foreach ($mask['edit'] as $field => $info) {
-    if ($info['required'] === true && empty($_POST[$field]))
+    if ($info['required'] === true && !strlen($_POST[$field]))
       return array('error' => sprintf('Pflichtfeld %s nicht ausgefüllt', $info['name']),
                   'errormsg' => 'Pflichtfelder nicht ausgefüllt');
 
@@ -108,7 +108,9 @@ function save($mask)
        $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])));
+       $update[] = sprintf("%s='%s'", $field,
+                           pg_escape_string(passwd(empty($_POST['login'])?$_SESSION['sys']['login']:$_POST['login'],
+                                                   $_POST[$field])));
     } else {
       if (empty($_POST[$field]) && $info['null'] === true)
         $update[] = sprintf("%s=NULL", $field);
@@ -139,7 +141,7 @@ function insert($mask)
   $values = array("'".pg_escape_string($_SESSION['sys']['login'])."'", 'now()');
 
   foreach ($mask['edit'] as $field => $info) {
-    if ($info['required'] === true && empty($_POST[$field]))
+    if ($info['required'] === true && !strlen($_POST[$field]))
       return array('error' => sprintf('Pflichtfeld %s nicht ausgefüllt', $info['name']),
                   'errormsg' => 'Pflichtfelder nicht ausgefüllt');
 
@@ -161,7 +163,8 @@ function insert($mask)
     } elseif ($info['type'] == 'passwd') {
       if (!empty($_POST[$field])) {
        $fields[] = $field;
-       $values[] = sprintf("'%s'", pg_escape_string(passwd($_SESSION['sys']['login'],$_POST[$field])));
+       $values[] = sprintf("'%s'", pg_escape_string(passwd(empty($_POST['login'])?$_SESSION['sys']['login']:$_POST['login'],
+                                                           $_POST[$field])));
       }
     } else {
       $fields[] = $field;