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'] as $field => $info)
17 if ($info['type'] == 'boolean')
18 $row[$field] = $row[$field]?true:false;
19 elseif (array_key_exists('format', $info))
20 $row[$field] = sprintf($info['format'], $row[$field]);
25 function details($mask)
27 if (empty($_POST['id']))
28 return array('error' => 'Missing ID');
30 $sql = sprintf('SELECT id,%s FROM %s WHERE id = %d',
31 implode(',', array_keys($mask['details']['list'])),
32 $mask['table'], $_POST['id']);
34 $sth = pg_query($sql);
37 return array('error' => pg_last_error(),
40 $row = pg_fetch_assoc($sth);
42 foreach ($mask['details']['list'] as $field => $info)
43 if (array_key_exists('format', $info))
44 $row[$field] = sprintf($info['format'], $row[$field]);
49 function format_ajax($data)
51 header('Content-type: application/json; charset=UTF-8');
52 echo json_encode($data);
56 if (empty($_POST['func']))
59 if (empty($_POST['source']))
63 if (load_mask($_POST['source']) === false) exit;
65 $data = array('error' => 'Unknown function');
67 if ($_POST['func'] == 'fetch') {
69 } elseif ($_POST['func'] == 'details') {
70 $data = details($mask);
71 } elseif ($_POST['func'] == 'save') {