From 56631aa65f39f4f2471f1e31350f5b6c912cabbf Mon Sep 17 00:00:00 2001 From: Janusz Dobrowolski Date: Mon, 12 Oct 2009 22:08:03 +0000 Subject: [PATCH] Fixed broken table editor page layout on duplicate record error. --- gl/includes/db/gl_db_account_types.inc | 8 +++--- gl/includes/db/gl_db_accounts.inc | 4 +-- gl/manage/gl_account_classes.php | 11 ++++---- gl/manage/gl_account_types.php | 11 ++++---- gl/manage/gl_accounts.php | 37 +++++++++++++++----------- 5 files changed, 40 insertions(+), 31 deletions(-) diff --git a/gl/includes/db/gl_db_account_types.inc b/gl/includes/db/gl_db_account_types.inc index 25049c43..e82ee8df 100644 --- a/gl/includes/db/gl_db_account_types.inc +++ b/gl/includes/db/gl_db_account_types.inc @@ -14,7 +14,7 @@ function add_account_type($id, $name, $class_id, $parent) $sql = "INSERT INTO ".TB_PREF."chart_types (id, name, class_id, parent) VALUES ($id, ".db_escape($name).", $class_id, $parent)"; - db_query($sql, "could not add account type"); + return db_query($sql); } function update_account_type($id, $name, $class_id, $parent) @@ -22,7 +22,7 @@ function update_account_type($id, $name, $class_id, $parent) $sql = "UPDATE ".TB_PREF."chart_types SET name=".db_escape($name).", class_id=$class_id, parent=$parent WHERE id = $id"; - db_query($sql, "could not update account type"); + return db_query($sql, "could not update account type"); } function get_account_types($all=false) @@ -66,7 +66,7 @@ function add_account_class($id, $name, $ctype) $sql = "INSERT INTO ".TB_PREF."chart_class (cid, class_name, ctype) VALUES ($id, ".db_escape($name).", $ctype)"; - db_query($sql, "could not add account type"); + return db_query($sql); } function update_account_class($id, $name, $ctype) @@ -74,7 +74,7 @@ function update_account_class($id, $name, $ctype) $sql = "UPDATE ".TB_PREF."chart_class SET class_name=".db_escape($name).", ctype=$ctype WHERE cid = $id"; - db_query($sql, "could not update account type"); + return db_query($sql); } function get_account_classes($all=false) diff --git a/gl/includes/db/gl_db_accounts.inc b/gl/includes/db/gl_db_accounts.inc index ce0a3507..754e7bc4 100644 --- a/gl/includes/db/gl_db_accounts.inc +++ b/gl/includes/db/gl_db_accounts.inc @@ -15,7 +15,7 @@ function add_gl_account($account_code, $account_name, $account_type, $account_co $sql = "INSERT INTO ".TB_PREF."chart_master (account_code, account_code2, account_name, account_type) VALUES (".db_escape($account_code).", ".db_escape($account_code2).", $account_name, $account_type)"; - db_query($sql, "could not add gl account"); + return db_query($sql); } function update_gl_account($account_code, $account_name, $account_type, $account_code2) @@ -25,7 +25,7 @@ function update_gl_account($account_code, $account_name, $account_type, $account account_type=$account_type, account_code2=".db_escape($account_code2) ." WHERE account_code = '$account_code'"; - db_query($sql, "could not update gl account"); + return db_query($sql); } function delete_gl_account($code) diff --git a/gl/manage/gl_account_classes.php b/gl/manage/gl_account_classes.php index bdc6b979..70faccdb 100644 --- a/gl/manage/gl_account_classes.php +++ b/gl/manage/gl_account_classes.php @@ -52,15 +52,16 @@ if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM') if ($selected_id != -1) { - update_account_class($selected_id, $_POST['name'], $_POST['ctype']); - display_notification(_('Selected account class settings has been updated')); + if(update_account_class($selected_id, $_POST['name'], $_POST['ctype'])) + display_notification(_('Selected account class settings has been updated')); } else { - add_account_class($_POST['id'], $_POST['name'], $_POST['ctype']); - display_notification(_('New account class has been added')); + if(add_account_class($_POST['id'], $_POST['name'], $_POST['ctype'])) { + display_notification(_('New account class has been added')); + $Mode = 'RESET'; + } } - $Mode = 'RESET'; } } diff --git a/gl/manage/gl_account_types.php b/gl/manage/gl_account_types.php index 12843843..b4ca1866 100644 --- a/gl/manage/gl_account_types.php +++ b/gl/manage/gl_account_types.php @@ -58,15 +58,16 @@ if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM') if ($selected_id != -1) { - update_account_type($selected_id, $_POST['name'], $_POST['class_id'], $_POST['parent']); - display_notification(_('Selected account type has been updated')); + if (update_account_type($selected_id, $_POST['name'], $_POST['class_id'], $_POST['parent'])) + display_notification(_('Selected account type has been updated')); } else { - add_account_type($_POST['id'], $_POST['name'], $_POST['class_id'], $_POST['parent']); - display_notification(_('New account type has been added')); + if (add_account_type($_POST['id'], $_POST['name'], $_POST['class_id'], $_POST['parent'])) { + display_notification(_('New account type has been added')); + $Mode = 'RESET'; + } } - $Mode = 'RESET'; } } diff --git a/gl/manage/gl_accounts.php b/gl/manage/gl_accounts.php index 4699c549..718be9bd 100644 --- a/gl/manage/gl_accounts.php +++ b/gl/manage/gl_accounts.php @@ -26,6 +26,7 @@ check_db_has_gl_account_groups(_("There are no account groups defined. Please de if (isset($_POST['_AccountList_update'])) { $_POST['selected_account'] = $_POST['AccountList']; + unset($_POST['account_code']); } if (isset($_POST['selected_account'])) @@ -71,19 +72,22 @@ if (isset($_POST['add']) || isset($_POST['update'])) $_POST['account_code'] = strtoupper($_POST['account_code']); if ($selected_account) { - update_gl_account($_POST['account_code'], $_POST['account_name'], - $_POST['account_type'], $_POST['account_code2']); - update_record_status($_POST['account_code'], $_POST['inactive'], - 'chart_master', 'account_code'); - $Ajax->activate('account_code'); // in case of status change - display_notification(_("Account data has been updated.")); + if (update_gl_account($_POST['account_code'], $_POST['account_name'], + $_POST['account_type'], $_POST['account_code2'])) { + update_record_status($_POST['account_code'], $_POST['inactive'], + 'chart_master', 'account_code'); + $Ajax->activate('account_code'); // in case of status change + display_notification(_("Account data has been updated.")); + } } else { - add_gl_account($_POST['account_code'], $_POST['account_name'], - $_POST['account_type'], $_POST['account_code2']); - $selected_account = $_POST['AccountList'] = $_POST['account_code']; - display_notification(_("New account has been added.")); + if (add_gl_account($_POST['account_code'], $_POST['account_name'], + $_POST['account_type'], $_POST['account_code2'])) + { + display_notification(_("New account has been added.")); + $selected_account = $_POST['AccountList'] = $_POST['account_code']; + } } $Ajax->activate('_page_body'); } @@ -209,8 +213,9 @@ if (isset($_POST['delete'])) if (can_delete($selected_account)) { delete_gl_account($selected_account); - $selected_account = $_POST['account_code'] = $_POST['AccountList'] = ''; + $selected_account = $_POST['AccountList'] = ''; display_notification(_("Selected account has been deleted")); + unset($_POST['account_code']); $Ajax->activate('_page_body'); } } @@ -253,11 +258,13 @@ if ($selected_account != "") label_row(_("Account Code:"), $_POST['account_code']); } -else +else { - $_POST['account_code'] = $_POST['account_code2'] = ''; - $_POST['account_name'] = $_POST['account_type'] = ''; - $_POST['inactive'] = 0; + if (!isset($_POST['account_code'])) { + $_POST['account_code'] = $_POST['account_code2'] = ''; + $_POST['account_name'] = $_POST['account_type'] = ''; + $_POST['inactive'] = 0; + } text_row_ex(_("Account Code:"), 'account_code', 11); } -- 2.30.2