From 9bb7d0742be8a96fe8152c338998bbd5b6daa0be Mon Sep 17 00:00:00 2001 From: Janusz Dobrowolski Date: Thu, 22 Sep 2011 10:52:54 +0200 Subject: [PATCH] Cleanup on key_in_foreign_table calls, removed obsolete $escaped argument. --- admin/db/company_db.inc | 4 +--- gl/manage/bank_accounts.php | 8 ++++---- gl/manage/currencies.php | 16 +++++++--------- gl/manage/gl_account_types.php | 9 ++++----- gl/manage/gl_accounts.php | 4 ++-- 5 files changed, 18 insertions(+), 23 deletions(-) diff --git a/admin/db/company_db.inc b/admin/db/company_db.inc index 5ef67982..b75251d5 100644 --- a/admin/db/company_db.inc +++ b/admin/db/company_db.inc @@ -177,10 +177,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); diff --git a/gl/manage/bank_accounts.php b/gl/manage/bank_accounts.php index c494247b..9dda5cd3 100644 --- a/gl/manage/bank_accounts.php +++ b/gl/manage/bank_accounts.php @@ -34,7 +34,7 @@ if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM') set_focus('bank_account_name'); } if ($Mode=='ADD_ITEM' && (gl_account_in_bank_accounts(get_post('account_code')) - || key_in_foreign_table(get_post('account_code'), 'gl_trans', 'account', true))) { + || key_in_foreign_table(get_post('account_code'), 'gl_trans', 'account'))) { $input_error = 1; display_error(_("The GL account selected is already in use. Select another GL account.")); set_focus('account_code'); @@ -70,13 +70,13 @@ elseif( $Mode == 'Delete') $cancel_delete = 0; // PREVENT DELETES IF DEPENDENT RECORDS IN 'bank_trans' - if (key_in_foreign_table($selected_id, 'bank_trans', 'bank_act', true) || key_in_foreign_table(get_post('account_code'), 'gl_trans', 'account', true)) + if (key_in_foreign_table($selected_id, 'bank_trans', 'bank_act') || key_in_foreign_table(get_post('account_code'), 'gl_trans', 'account')) { $cancel_delete = 1; display_error(_("Cannot delete this bank account because transactions have been created using this account.")); } - if (key_in_foreign_table($selected_id, 'sales_pos', 'pos_account', true)) + if (key_in_foreign_table($selected_id, 'sales_pos', 'pos_account')) { $cancel_delete = 1; display_error(_("Cannot delete this bank account because POS definitions have been created using this account.")); @@ -135,7 +135,7 @@ while ($myrow = db_fetch($result)) inactive_control_row($th); end_table(1); -$is_used = $selected_id != -1 && key_in_foreign_table($selected_id, 'bank_trans', 'bank_act', true); +$is_used = $selected_id != -1 && key_in_foreign_table($selected_id, 'bank_trans', 'bank_act'); start_table(TABLESTYLE2); diff --git a/gl/manage/currencies.php b/gl/manage/currencies.php index b14b79fd..363b734b 100644 --- a/gl/manage/currencies.php +++ b/gl/manage/currencies.php @@ -80,22 +80,20 @@ function handle_submit() //--------------------------------------------------------------------------------------------- -function check_can_delete() +function check_can_delete($curr) { - global $selected_id; - - if ($selected_id == "") + + if ($curr == "") return false; - $curr = db_escape($selected_id); // PREVENT DELETES IF DEPENDENT RECORDS IN debtors_master - if (key_in_foreign_table($curr, 'debtors_master', 'curr_code', true)) + if (key_in_foreign_table($curr, 'debtors_master', 'curr_code')) { display_error(_("Cannot delete this currency, because customer accounts have been created referring to this currency.")); return false; } - if (key_in_foreign_table($curr, 'suppliers', 'curr_code', true)) + if (key_in_foreign_table($curr, 'suppliers', 'curr_code')) { display_error(_("Cannot delete this currency, because supplier accounts have been created referring to this currency.")); return false; @@ -108,7 +106,7 @@ function check_can_delete() } // see if there are any bank accounts that use this currency - if (key_in_foreign_table($curr, 'bank_accounts', 'bank_curr_code', true)) + if (key_in_foreign_table($curr, 'bank_accounts', 'bank_curr_code')) { display_error(_("Cannot delete this currency, because thre are bank accounts that use this currency.")); return false; @@ -122,7 +120,7 @@ function check_can_delete() function handle_delete() { global $selected_id, $Mode; - if (check_can_delete()) { + if (check_can_delete($selcted_id)) { //only delete if used in neither customer or supplier, comp prefs, bank trans accounts delete_currency($selected_id); display_notification(_('Selected currency has been deleted')); diff --git a/gl/manage/gl_account_types.php b/gl/manage/gl_account_types.php index b3e56aca..fcea4dbf 100644 --- a/gl/manage/gl_account_types.php +++ b/gl/manage/gl_account_types.php @@ -79,19 +79,18 @@ if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM') //----------------------------------------------------------------------------------- -function can_delete($selected_id) +function can_delete($type) { - if ($selected_id == "") + if ($type == "") return false; - $type = db_escape($selected_id); - if (key_in_foreign_table($type, 'chart_master', 'account_type', true)) + if (key_in_foreign_table($type, 'chart_master', 'account_type')) { display_error(_("Cannot delete this account group because GL accounts have been created referring to it.")); return false; } - if (key_in_foreign_table($type, 'chart_types', 'parent', true)) + if (key_in_foreign_table($type, 'chart_types', 'parent')) { display_error(_("Cannot delete this account group because GL account groups have been created referring to it.")); return false; diff --git a/gl/manage/gl_accounts.php b/gl/manage/gl_accounts.php index db432dcc..221a76cd 100644 --- a/gl/manage/gl_accounts.php +++ b/gl/manage/gl_accounts.php @@ -111,7 +111,7 @@ function can_delete($selected_account) if ($selected_account == "") return false; - if (key_in_foreign_table($selected_account, 'gl_trans', 'account', true)) + if (key_in_foreign_table($selected_account, 'gl_trans', 'account')) { display_error(_("Cannot delete this account because transactions have been created using this account.")); return false; @@ -123,7 +123,7 @@ function can_delete($selected_account) return false; } - if (key_in_foreign_table($selected_account, 'bank_accounts', 'account_code', true)) + if (key_in_foreign_table($selected_account, 'bank_accounts', 'account_code')) { display_error(_("Cannot delete this account because it is used by a bank account.")); return false; -- 2.30.2