From: Janusz Dobrowolski Date: Thu, 9 Dec 2010 11:06:11 +0000 (+0000) Subject: Fixed sql assembly in get_account_types. X-Git-Tag: v2.4.2~19^2~417 X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=commitdiff_plain;h=563cbdf3eabfc37e36c49fb7fe250bb4107a6ca7;p=fa-stable.git Fixed sql assembly in get_account_types. --- diff --git a/gl/includes/db/gl_db_account_types.inc b/gl/includes/db/gl_db_account_types.inc index 4ff3e22c..03a3abeb 100644 --- a/gl/includes/db/gl_db_account_types.inc +++ b/gl/includes/db/gl_db_account_types.inc @@ -56,14 +56,21 @@ function get_account_types($all=false, $class_id=false, $parent=false) { $sql = "SELECT * FROM ".TB_PREF."chart_types"; - if (!$all) - $sql .= " WHERE !inactive"; - if ($class_id != false) - $sql .= " AND class_id=".db_escape($class_id); + $where = array(); + + if (!$all) + $where[] = "!inactive"; + + if ($class_id != false) + $where[] = "class_id=".db_escape($class_id); + if ($parent == -1) - $sql .= " AND (parent = '' OR parent = '-1')"; + $where[] ="(parent = '' OR parent = '-1')"; elseif ($parent !== false) - $sql .= " AND parent=".db_escape($parent); + $where[] = "parent=".db_escape($parent); + + if (count($where)) + $sql .= ' WHERE '.implode(' AND ', $where); $sql .= " ORDER BY class_id, id, parent"; return db_query($sql, "could not get account types");