From 491fbb478290d8a65b2d34c9bc39de3f73bdbd85 Mon Sep 17 00:00:00 2001 From: Joey Schulze Date: Sun, 28 Feb 2010 18:14:20 +0100 Subject: [PATCH] Support select fields, add missing curley brackets --- ajax/ajax.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/ajax/ajax.php b/ajax/ajax.php index e973776..a5a8a12 100644 --- a/ajax/ajax.php +++ b/ajax/ajax.php @@ -67,14 +67,14 @@ function save($mask) $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') { if (empty($_POST[$field]) && $info['null'] === true) $update[] = sprintf("%s=NULL", $field); else @@ -93,6 +93,7 @@ function save($mask) else $update[] = sprintf("%s='%s'", $field, pg_escape_string($_POST[$field])); } + } $sql = 'UPDATE ' . $mask['table'] . ' SET '; $sql .= implode(', ', $update); @@ -114,14 +115,15 @@ function insert($mask) $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') { $fields[] = $field; if (empty($_POST[$field]) && $info['null'] === true) $values[] = 'NULL'; @@ -145,6 +147,7 @@ function insert($mask) else $values[] = sprintf("'%s'", pg_escape_string($_POST[$field])); } + } $sql = 'INSERT INTO ' . $mask['table'] . ' (' . implode(',', $fields) . ') '; $sql .= 'VALUES (' . implode(',', $values) . ')'; -- 2.20.1