3 require_once('../init.php');
7 $sql = sprintf('SELECT id,%s FROM %s WHERE id = %d',
8 implode(',', array_keys($mask['edit'])),
9 $mask['table'], $_POST['id']);
11 $sth = pg_query($sql);
12 if ($sth === false) return false;
14 $row = pg_fetch_assoc($sth);
16 foreach ($mask['edit']['list'] as $field => $info)
17 if (array_key_exists('format', $info))
18 $row[$field] = sprintf($info['format'], $row[$field]);
23 function details($mask)
25 if (empty($_POST['id']))
26 return array('error' => 'Missing ID');
28 $sql = sprintf('SELECT id,%s FROM %s WHERE id = %d',
29 implode(',', array_keys($mask['details']['list'])),
30 $mask['table'], $_POST['id']);
32 $sth = pg_query($sql);
35 return array('error' => pg_last_error(),
38 $row = pg_fetch_assoc($sth);
40 foreach ($mask['details']['list'] as $field => $info)
41 if (array_key_exists('format', $info))
42 $row[$field] = sprintf($info['format'], $row[$field]);
47 function format_ajax($data)
49 header('Content-type: application/json; charset=UTF-8');
50 echo json_encode($data);
54 if (empty($_POST['func']))
57 if (empty($_POST['source']))
61 if (load_mask($_POST['source'], '../') === false) exit;
63 $data = array('error' => 'Unknown function');
65 if ($_POST['func'] == 'fetch') {
67 } elseif ($_POST['func'] == 'details') {
68 $data = details($mask);
69 } elseif ($_POST['func'] == 'save') {