Automatically calculate the filesystem path of the application and use
[misc/kostenrechnung] / ajax / ajax.php
index 311000e..57f35a3 100644 (file)
@@ -7,8 +7,19 @@ 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'] as $field => $info)
+    if ($info['type'] == 'boolean')
+      $row[$field] = $row[$field]?true:false;
+    elseif (array_key_exists('format', $info))
+      $row[$field] = sprintf($info['format'], $row[$field]);
+
+  return $row;
 }
 
 function details($mask)
@@ -19,7 +30,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)
@@ -45,11 +56,11 @@ function format_ajax($data)
 if (empty($_POST['func']))
   exit;
 
-if (empty($_POST['mask']))
+if (empty($_POST['source']))
   exit;
 
 connect_db();
-if (load_mask($_POST['mask'], '../') === false) exit;
+if (load_mask($_POST['source']) === false) exit;
 
 $data = array('error' => 'Unknown function');