function fetch($mask)
{
$fields = array("to_char(sys_edit,'DD.MM.YYYY HH24:mm') AS sys_edit", 'sys_user');
- foreach ($mask['edit'] as $field => $info)
+ foreach ($mask['edit'] as $field => $info) {
+ if ($info['sql'] === false) continue;
if ($info['type'] == 'date')
- $fields[] = sprintf("to_char(%s,'DD.MM.YYYY') AS %s", $field, $field);
+ $fields[] = sprintf("to_char(%s,'DD.MM.YYYY') AS %s",
+ empty($info['sql']) ? $field : $info['sql'],
+ $field);
elseif ($info['type'] != 'passwd')
- $fields[] = $field;
+ $fields[] = empty($info['sql']) ? $field : $info['sql'] . ' AS ' . $field;
+ }
$sql = sprintf('SELECT id,%s FROM %s WHERE id = %d',
implode(',', $fields),
if ($info['type'] == 'boolean') {
$update[] = sprintf("%s=%d", $field, $_POST[$field] == 'on'?1:0);
- } elseif ($info['type'] == 'number' || ($info['type'] == 'select' && $info['options_string'] !== true)) {
+ } elseif ($info['type'] == 'number' || $info['type'] == 'hidden' || ($info['type'] == 'select' && $info['options_string'] !== true)) {
if (empty($_POST[$field]) && $info['null'] === true)
$update[] = sprintf("%s=NULL", $field);
else
if ($info['type'] == 'boolean') {
$fields[] = $field;
$values[] = $_POST[$field] == 'on'?1:0;
- } elseif ($info['type'] == 'number' || ($info['type'] == 'select' && $info['options_string'] !== true)) {
+ } elseif ($info['type'] == 'number' || $info['type'] == 'hidden' || ($info['type'] == 'select' && $info['options_string'] !== true)) {
$fields[] = $field;
if (empty($_POST[$field]) && $info['null'] === true)
$values[] = 'NULL';
return array('status' => true);
}
+function get_infos($mask)
+{
+ if (!array_key_exists('info',$mask))
+ return array('error' => 'Unknown callback ' . htmlspecialchars($_POST['name']));
+
+ if (!array_key_exists($_POST['name'],$mask['info']))
+ return array('error' => 'Unknown callback ' . htmlspecialchars($_POST['name']));
+
+ if (!array_key_exists('sql',$mask['info'][$_POST['name']]))
+ return array('error' => 'Unknown callback ' . htmlspecialchars($_POST['name']));
+
+ $sql = $mask['info'][$_POST['name']]['sql'];
+
+ while (preg_match('/\{([^\}]*)\}/', $sql, $matches))
+ $sql = str_replace('{'.$matches[1].'}', $_POST[$matches[1]], $sql);
+
+ return array('info' => query_db($sql));
+}
+
function format_ajax($data)
{
header('Content-type: application/json; charset=UTF-8');
$data = delete_or_copy($mask);
} elseif ($_POST['func'] == 'setvar') {
$data = set_variable($_POST['source'],$mask);
+} elseif ($_POST['func'] == 'info') {
+ $data = get_infos($mask);
}
format_ajax($data);