Add AJAX backend for fetching data and filling the edit form
authorJoey Schulze <joey@infodrom.org>
Thu, 25 Feb 2010 11:25:41 +0000 (12:25 +0100)
committerJoey Schulze <joey@infodrom.org>
Thu, 25 Feb 2010 11:25:41 +0000 (12:25 +0100)
ajax/ajax.php

index 311000e..72f226e 100644 (file)
@@ -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)