Rerun. Stuff forgotten.
[fa-stable.git] / gl / manage / gl_account_classes.php
index bdc6b9790d54e3ed0c54cd0f951148180a9f533d..1ec62b88431965f4ab37d643fbcac3af19dfb1cf 100644 (file)
@@ -13,7 +13,7 @@ $page_security = 'SA_GLACCOUNTCLASS';
 $path_to_root = "../..";
 include($path_to_root . "/includes/session.inc");
 
-page(_("GL Account Classes"));
+page(_($help_context = "GL Account Classes"));
 
 include($path_to_root . "/gl/includes/gl_db.inc");
 
@@ -25,12 +25,12 @@ simple_page_mode(true);
 function can_process() 
 {
        global $use_oldstyle_convert;
-       if (!is_numeric($_POST['id'])) 
+       /*if (!is_numeric($_POST['id'])) 
        {
                display_error( _("The account class ID must be numeric."));
                set_focus('id');
                return false;
-       }
+       }*/
        if (strlen($_POST['name']) == 0) 
        {
                display_error( _("The account class name cannot be empty."));
@@ -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';
        }
 }
 
@@ -70,11 +71,7 @@ function can_delete($selected_id)
 {
        if ($selected_id == -1)
                return false;
-       $sql= "SELECT COUNT(*) FROM ".TB_PREF."chart_types
-               WHERE class_id=$selected_id";
-       $result = db_query($sql, "could not query chart master");
-       $myrow = db_fetch_row($result);
-       if ($myrow[0] > 0) 
+       if (key_in_foreign_table($selected_id, 'chart_types', 'class_id'))      
        {
                display_error(_("Cannot delete this account class because GL account types have been created referring to it."));
                return false;
@@ -143,18 +140,18 @@ start_table($table_style2);
 
 if ($selected_id != -1) 
 {
- if ($Mode == 'Edit') {
-       //editing an existing status code
-       $myrow = get_account_class($selected_id);
-
-       $_POST['id']  = $myrow["cid"];
-       $_POST['name']  = $myrow["class_name"];
-       if (isset($use_oldstyle_convert) && $use_oldstyle_convert == 1)
-               $_POST['ctype'] = ($myrow["ctype"] >= CL_ASSETS && $myrow["ctype"] < CL_INCOME ? 1 : 0);
-       else
-               $_POST['ctype']  = $myrow["ctype"];
-       hidden('selected_id', $selected_id);
- }
      if ($Mode == 'Edit') {
+               //editing an existing status code
+               $myrow = get_account_class($selected_id);
+       
+               $_POST['id']  = $myrow["cid"];
+               $_POST['name']  = $myrow["class_name"];
+               if (isset($use_oldstyle_convert) && $use_oldstyle_convert == 1)
+                       $_POST['ctype'] = ($myrow["ctype"] >= CL_ASSETS && $myrow["ctype"] < CL_INCOME ? 1 : 0);
+               else
+                       $_POST['ctype']  = $myrow["ctype"];
+               hidden('selected_id', $selected_id);
      }
        hidden('id');
        label_row(_("Class ID:"), $_POST['id']);