Cleanup on key_in_foreign_table calls, removed obsolete $escaped argument.
authorJanusz Dobrowolski <janusz@frontaccouting.eu>
Thu, 22 Sep 2011 08:52:54 +0000 (10:52 +0200)
committerJanusz Dobrowolski <janusz@frontaccouting.eu>
Thu, 22 Sep 2011 08:52:54 +0000 (10:52 +0200)
admin/db/company_db.inc
gl/manage/bank_accounts.php
gl/manage/currencies.php
gl/manage/gl_account_types.php
gl/manage/gl_accounts.php

index 5ef679820c11ac41c9794b008ee582db81aea474..b75251d5feabc2cc0d3df5e95c29f1f061853660 100644 (file)
@@ -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);
index c494247b73446943d9e2f5d1872916dbd2b9468e..9dda5cd367a1c4e452cfc600226feebd9ff620f8 100644 (file)
@@ -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);
 
index b14b79fde4c4e7a4114a73e008a51b93fd107812..363b734bd8dfdfdee52327d1b8395b3133cb5ba7 100644 (file)
@@ -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'));
index b3e56aca8b1a82e0df8f46191bb709986f37fbd7..fcea4dbfcc32611445e8cadf679ba780db94d78f 100644 (file)
@@ -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;
index db432dcc288209332c2ed9b92f1b285385f5f7e6..221a76cd28e8d7944f1fc84157fa7c12372f8f6f 100644 (file)
@@ -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;