From: Joey Schulze Date: Thu, 25 Feb 2010 11:25:41 +0000 (+0100) Subject: Add AJAX backend for fetching data and filling the edit form X-Git-Tag: 2010-06-02_customer~225 X-Git-Url: https://git.infodrom.org/?p=misc%2Fkostenrechnung;a=commitdiff_plain;h=97d32b15f1699aecdb043138747396223a73fc25;ds=inline Add AJAX backend for fetching data and filling the edit form --- diff --git a/ajax/ajax.php b/ajax/ajax.php index 311000e..72f226e 100644 --- a/ajax/ajax.php +++ b/ajax/ajax.php @@ -7,8 +7,17 @@ function fetch($mask) $sql = sprintf('SELECT id,%s FROM %s WHERE id = %d', implode(',', array_keys($mask['edit'])), $mask['table'], $_POST['id']); - error_log($sql); + $sth = pg_query($sql); + if ($sth === false) return false; + + $row = pg_fetch_assoc($sth); + + foreach ($mask['edit']['list'] as $field => $info) + if (array_key_exists('format', $info)) + $row[$field] = sprintf($info['format'], $row[$field]); + + return $row; } function details($mask) @@ -19,7 +28,7 @@ function details($mask) $sql = sprintf('SELECT id,%s FROM %s WHERE id = %d', implode(',', array_keys($mask['details']['list'])), $mask['table'], $_POST['id']); - error_log($sql); + $sth = pg_query($sql); if (!$sth)