$update = array(sprintf("sys_user = '%s'", pg_escape_string($_SESSION['sys']['login'])),
"sys_edit = now()");
- foreach ($mask['edit'] as $field => $info)
+ foreach ($mask['edit'] as $field => $info) {
+ if ($info['required'] === true && empty($_POST[$field]))
+ return array('error' => sprintf('Pflichtfeld %s nicht ausgefüllt', $info['name']),
+ 'errormsg' => 'Pflichtfelder nicht ausgefüllt');
+
if ($info['type'] == 'boolean') {
$update[] = sprintf("%s=%d", $field, $_POST[$field] == 'on'?1:0);
- } elseif ($info['type'] == 'number') {
+ } elseif ($info['type'] == 'number' || ($info['type'] == 'select' && $info['options_string'] !== true)) {
if (empty($_POST[$field]) && $info['null'] === true)
$update[] = sprintf("%s=NULL", $field);
else
else
$update[] = sprintf("%s='%s'", $field, pg_escape_string($_POST[$field]));
}
+ }
$sql = 'UPDATE ' . $mask['table'] . ' SET ';
$sql .= implode(', ', $update);
$fields = array('sys_user','sys_edit');
$values = array("'".pg_escape_string($_SESSION['sys']['login'])."'", 'now()');
- foreach ($mask['edit'] as $field => $info)
+ foreach ($mask['edit'] as $field => $info) {
+ if ($info['required'] === true && empty($_POST[$field]))
+ return array('error' => sprintf('Pflichtfeld %s nicht ausgefüllt', $info['name']),
+ 'errormsg' => 'Pflichtfelder nicht ausgefüllt');
+
if ($info['type'] == 'boolean') {
$fields[] = $field;
$values[] = $_POST[$field] == 'on'?1:0;
- } elseif ($info['type'] == 'number') {
+ } elseif ($info['type'] == 'number' || ($info['type'] == 'select' && $info['options_string'] !== true)) {
$fields[] = $field;
if (empty($_POST[$field]) && $info['null'] === true)
$values[] = 'NULL';
else
$values[] = sprintf("'%s'", pg_escape_string($_POST[$field]));
}
+ }
$sql = 'INSERT INTO ' . $mask['table'] . ' (' . implode(',', $fields) . ') ';
$sql .= 'VALUES (' . implode(',', $values) . ')';