From 162cb09efc77d87f8d05a9c3f9d8f6520bea7600 Mon Sep 17 00:00:00 2001 From: Joey Schulze Date: Sat, 27 Feb 2010 17:09:59 +0100 Subject: [PATCH 1/1] Move SQL query calculation into separate general function --- lib/general.php | 16 ++++++++++++++++ lib/mask.php | 6 ++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/lib/general.php b/lib/general.php index 9900bf6..3f82f4a 100644 --- a/lib/general.php +++ b/lib/general.php @@ -125,4 +125,20 @@ function debug_info() return $html; } +function grid_sql($name, $mask) +{ + $fields = array(); + foreach ($mask['list'] as $field => $data) { + if (array_key_exists('sql', $data)) + $fields[] = $data['sql'] . ' AS ' . $field; + else + $fields[] = $field; + } + + $_SESSION['grid_' . $name] = sprintf("SELECT %s FROM %s", + implode(',', $fields), $mask['table']); + if (array_key_exists('join', $mask)) $_SESSION['grid_' . $name] .= ' JOIN ' . join(' JOIN ', $mask['join']); + if (array_key_exists('where', $mask)) $_SESSION['grid_' . $name] .= ' WHERE ' . $mask['where']; +} + ?> diff --git a/lib/mask.php b/lib/mask.php index 03e772d..d8fda0d 100644 --- a/lib/mask.php +++ b/lib/mask.php @@ -102,10 +102,8 @@ function build_grid($name, $mask) else $fields[] = $field; } - $_SESSION['grid_' . $name] = sprintf("SELECT %s FROM %s", - implode(',', $fields), $mask['table']); - if (array_key_exists('join', $mask)) $_SESSION['grid_' . $name] .= ' JOIN ' . join(' JOIN ', $mask['join']); - if (array_key_exists('where', $mask)) $_SESSION['grid_' . $name] .= ' WHERE ' . $mask['where']; + + grid_sql($name, $mask); $ret[] = ' '; $ret[] = ''; -- 2.20.1