Stable merged into unstable again (due to failure on binary file during previous...
[fa-stable.git] / admin / db / company_db.inc
index fdb14a63b8590e110d5be377432a565ada94a26f..9fd2e68c27adf2931ce65aeb9bb01586bd801526 100644 (file)
@@ -38,9 +38,6 @@ function get_company_pref($prefs = null)
 
                $_SESSION['SysPrefs'] = new sys_prefs();
 
-               if (!isset($company))
-                       $company = user_company();
-
                $sql = "SELECT name, value FROM ".TB_PREF."sys_prefs";
                $result = @db_query($sql); // supress errors before 2.3 db structure upgrade
 
@@ -173,10 +170,8 @@ function get_payment_terms_all($show_inactive)
                value is name of foreign key field. For numeric keys $stdkey field name is used.
        $stdkey - standard name of foreign key.
 */
-function key_in_foreign_table($id, $tables, $stdkey, $escaped=false)
+function key_in_foreign_table($id, $tables, $stdkey)
 {
-       if (!$escaped)
-               $id = db_escape($id);
 
        if (!is_array($tables))
                $tables = array($tables);
@@ -187,7 +182,7 @@ function key_in_foreign_table($id, $tables, $stdkey, $escaped=false)
                        $tbl = $key;
                        $key = $stdkey;
                }
-               $sqls[] = "(SELECT COUNT(*) as cnt FROM ".TB_PREF."$tbl WHERE $key=$id)\n";
+               $sqls[] = "(SELECT COUNT(*) as cnt FROM `".TB_PREF."$tbl` WHERE `$key`=".db_escape($id).")\n";
        }
 
        $sql = "SELECT sum(cnt) FROM (". implode(' UNION ', $sqls).") as counts";