Replaced the global variables for table styles to defined CSS classes.
[fa-stable.git] / gl / manage / gl_account_types.php
1 <?php
2 /**********************************************************************
3     Copyright (C) FrontAccounting, LLC.
4         Released under the terms of the GNU General Public License, GPL, 
5         as published by the Free Software Foundation, either version 3 
6         of the License, or (at your option) any later version.
7     This program is distributed in the hope that it will be useful,
8     but WITHOUT ANY WARRANTY; without even the implied warranty of
9     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
10     See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
11 ***********************************************************************/
12 $page_security = 'SA_GLACCOUNTGROUP';
13 $path_to_root = "../..";
14 include($path_to_root . "/includes/session.inc");
15
16 page(_($help_context = "GL Account Groups"));
17
18 include($path_to_root . "/gl/includes/gl_db.inc");
19
20 include($path_to_root . "/includes/ui.inc");
21
22 simple_page_mode(false);
23 //-----------------------------------------------------------------------------------
24
25 function can_process() 
26 {
27         if ($_POST['id'] == "")
28         {
29             display_error( _("The account group id cannot be empty."));
30             set_focus('id');
31             return false;
32         }
33         if (strlen($_POST['name']) == 0) 
34         {
35                 display_error( _("The account group name cannot be empty."));
36                 set_focus('name');
37                 return false;
38         }
39
40         //if (strcmp($_POST['id'], $_POST['parent']) == 0) 
41         if ($_POST['id'] === $_POST['parent']) 
42         {
43                 display_error(_("You cannot set an account group to be a subgroup of itself."));
44                 return false;
45         }
46
47         return true;
48 }
49
50 //-----------------------------------------------------------------------------------
51
52 if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM') 
53 {
54
55         if (can_process()) 
56         {
57
58         if ($selected_id != "") 
59         {
60                 if (update_account_type($_POST['id'], $_POST['name'], $_POST['class_id'], $_POST['parent'], $_POST['old_id']))
61                                 display_notification(_('Selected account type has been updated'));
62         } 
63         else 
64         {
65                 if (add_account_type($_POST['id'], $_POST['name'], $_POST['class_id'], $_POST['parent'])) {
66                                 display_notification(_('New account type has been added'));
67                         }
68         }
69                 $Mode = 'RESET';
70         }
71 }
72
73 //-----------------------------------------------------------------------------------
74
75 function can_delete($selected_id)
76 {
77         if ($selected_id == "")
78                 return false;
79         $type = db_escape($selected_id);
80
81         if (key_in_foreign_table($type, 'chart_master', 'account_type', true))
82         {
83                 display_error(_("Cannot delete this account group because GL accounts have been created referring to it."));
84                 return false;
85         }
86
87         if (key_in_foreign_table($type, 'chart_types', 'parent', true))
88         {
89                 display_error(_("Cannot delete this account group because GL account groups have been created referring to it."));
90                 return false;
91         }
92
93         return true;
94 }
95
96
97 //-----------------------------------------------------------------------------------
98
99 if ($Mode == 'Delete')
100 {
101
102         if (can_delete($selected_id))
103         {
104                 delete_account_type($selected_id);
105                 display_notification(_('Selected account group has been deleted'));
106         }
107         $Mode = 'RESET';
108 }
109 if ($Mode == 'RESET')
110 {
111         $selected_id = "";
112         $_POST['id']  = $_POST['name']  = '';
113         unset($_POST['parent']);
114         unset($_POST['class_id']);
115 }
116 //-----------------------------------------------------------------------------------
117
118 $result = get_account_types(check_value('show_inactive'));
119
120 start_form();
121 start_table(TABLESTYLE);
122 $th = array(_("Group ID"), _("Group Name"), _("Subgroup Of"), _("Class Type"), "", "");
123 inactive_control_column($th);
124 table_header($th);
125
126 $k = 0;
127 while ($myrow = db_fetch($result)) 
128 {
129
130         alt_table_row_color($k);
131
132         $bs_text = get_account_class_name($myrow["class_id"]);
133
134         if ($myrow["parent"] == '-1') 
135         {
136                 $parent_text = "";
137         } 
138         else 
139         {
140                 $parent_text = get_account_type_name($myrow["parent"]);
141         }
142
143         label_cell($myrow["id"]);
144         label_cell($myrow["name"]);
145         label_cell($parent_text);
146         label_cell($bs_text);
147         inactive_control_cell($myrow["id"], $myrow["inactive"], 'chart_types', 'id');
148         edit_button_cell("Edit".$myrow["id"], _("Edit"));
149         delete_button_cell("Delete".$myrow["id"], _("Delete"));
150         end_row();
151 }
152
153 inactive_control_row($th);
154 end_table(1);
155 //-----------------------------------------------------------------------------------
156
157 start_table(TABLESTYLE2);
158
159 if ($selected_id != "")
160 {
161         if ($Mode == 'Edit') 
162         {
163                 //editing an existing status code
164                 $myrow = get_account_type($selected_id);
165         
166                 $_POST['id']  = $myrow["id"];
167                 $_POST['name']  = $myrow["name"];
168                 $_POST['parent']  = $myrow["parent"];
169                 if ($_POST['parent'] == '-1')
170                         $_POST['parent'] == "";
171                 $_POST['class_id']  = $myrow["class_id"];
172                 hidden('selected_id', $myrow['id']);
173                 hidden('old_id', $myrow["id"]);
174         }
175         else
176         {
177                 hidden('selected_id', $selected_id);
178                 hidden('old_id', $_POST["old_id"]);
179         }       
180 }
181 text_row_ex(_("ID:"), 'id', 10);
182 text_row_ex(_("Name:"), 'name', 50);
183
184 gl_account_types_list_row(_("Subgroup Of:"), 'parent', null, _("None"), true);
185
186 class_list_row(_("Class Type:"), 'class_id', null);
187
188 end_table(1);
189
190 submit_add_or_update_center($selected_id == "", '', 'both');
191
192 end_form();
193
194 //------------------------------------------------------------------------------------
195
196 end_page();
197
198 ?>