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);
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');
$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."));
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);
//---------------------------------------------------------------------------------------------
-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;
}
// 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;
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'));
//-----------------------------------------------------------------------------------
-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;
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;
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;