Fixed control buttons reset after record deletion.
[fa-stable.git] / gl / manage / gl_account_classes.php
1 <?php
2
3 $page_security = 3;
4 $path_to_root="../..";
5 include($path_to_root . "/includes/session.inc");
6
7 page(_("GL Account Classes"));
8
9 include($path_to_root . "/gl/includes/gl_db.inc");
10
11 include($path_to_root . "/includes/ui.inc");
12
13 simple_page_mode(true);
14 //-----------------------------------------------------------------------------------
15
16 function can_process() 
17 {
18
19         if (strlen($_POST['name']) == 0) 
20         {
21                 display_error( _("The account class name cannot be empty."));
22                 set_focus('name');
23                 return false;
24         }
25
26         return true;
27 }
28
29 //-----------------------------------------------------------------------------------
30
31 if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM') 
32 {
33
34         if (can_process()) 
35         {
36
37         if ($selected_id != -1) 
38         {
39                 update_account_class($selected_id, $_POST['name'], $_POST['Balance']);
40                         display_notification(_('Selected account class settings has been updated'));
41         } 
42         else 
43         {
44                 add_account_class($_POST['id'], $_POST['name'], $_POST['Balance']);
45                         display_notification(_('New account class has been added'));
46         }
47                 $Mode = 'RESET';
48         }
49 }
50
51 //-----------------------------------------------------------------------------------
52
53 function can_delete($selected_id)
54 {
55         if ($selected_id == -1)
56                 return false;
57         $sql= "SELECT COUNT(*) FROM ".TB_PREF."chart_types
58                 WHERE class_id=$selected_id";
59         $result = db_query($sql, "could not query chart master");
60         $myrow = db_fetch_row($result);
61         if ($myrow[0] > 0) 
62         {
63                 display_error(_("Cannot delete this account class because GL account types have been created referring to it."));
64                 return false;
65         }
66
67         return true;
68 }
69
70
71 //-----------------------------------------------------------------------------------
72
73 if ($Mode == 'Delete')
74 {
75
76         if (can_delete($selected_id))
77         {
78                 delete_account_class($selected_id);
79                 display_notification(_('Selected account class has been deleted'));
80         }
81         $Mode = 'RESET';
82 }
83
84 //-----------------------------------------------------------------------------------
85 if ($Mode == 'RESET')
86 {
87         $selected_id = -1;
88         $_POST['id']  = $_POST['name']  = $_POST['Balance'] = '';
89 }
90 //-----------------------------------------------------------------------------------
91
92 $result = get_account_classes();
93 start_form();
94 start_table($table_style);
95 $th = array(_("Class ID"), _("Class Name"), _("Balance Sheet"), "", "");
96 table_header($th);
97
98 $k = 0;
99 while ($myrow = db_fetch($result)) 
100 {
101
102         alt_table_row_color($k);
103
104         if ($myrow["balance_sheet"] == 0) 
105         {
106                 $bs_text = _("No");
107         } 
108         else 
109         {
110                 $bs_text = _("Yes");
111         }
112         label_cell($myrow["cid"]);
113         label_cell($myrow['class_name']);
114         label_cell($bs_text);
115         edit_button_cell("Edit".$myrow["cid"], _("Edit"));
116         edit_button_cell("Delete".$myrow["cid"], _("Delete"));
117         end_row();
118 }
119
120 end_table();
121 end_form();
122 echo '<br>';
123 //-----------------------------------------------------------------------------------
124
125 start_form();
126
127 start_table($table_style2);
128
129 if ($selected_id != -1) 
130 {
131  if ($Mode == 'Edit') {
132         //editing an existing status code
133         $myrow = get_account_class($selected_id);
134
135         $_POST['id']  = $myrow["cid"];
136         $_POST['name']  = $myrow["class_name"];
137         $_POST['Balance']  = $myrow["balance_sheet"];
138         hidden('selected_id', $selected_id);
139  }
140         hidden('id');
141         label_row(_("Class ID:"), $_POST['id']);
142
143
144 else 
145 {
146
147         text_row_ex(_("Class ID:"), 'id', 3);
148 }
149
150 text_row_ex(_("Class Name:"), 'name', 50, 60);
151
152 yesno_list_row(_("Balance Sheet:"), 'Balance', null, "", "", false);
153
154 end_table(1);
155
156 submit_add_or_update_center($selected_id == -1, '', true);
157
158 end_form();
159
160 //------------------------------------------------------------------------------------
161
162 end_page();
163
164 ?>