Eliminated non-static method calls and other bulk fixes to fix php5 warnings
[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(_("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(true);
23 //-----------------------------------------------------------------------------------
24
25 function can_process() 
26 {
27         global $selected_id;
28
29         if (!input_num('id'))
30         {
31             display_error( _("The account id must be an integer and cannot be empty."));
32             set_focus('id');
33             return false;
34         }
35         if (strlen($_POST['name']) == 0) 
36         {
37                 display_error( _("The account group name cannot be empty."));
38                 set_focus('name');
39                 return false;
40         }
41
42         if (isset($selected_id) && ($selected_id == $_POST['parent'])) 
43         {
44                 display_error(_("You cannot set an account group to be a subgroup of itself."));
45                 return false;
46         }
47
48         return true;
49 }
50
51 //-----------------------------------------------------------------------------------
52
53 if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM') 
54 {
55
56         if (can_process()) 
57         {
58
59         if ($selected_id != -1) 
60         {
61                 update_account_type($selected_id, $_POST['name'], $_POST['class_id'], $_POST['parent']);
62                         display_notification(_('Selected account type has been updated'));
63         } 
64         else 
65         {
66                 add_account_type($_POST['id'], $_POST['name'], $_POST['class_id'], $_POST['parent']);
67                         display_notification(_('New account type has been added'));
68         }
69                 $Mode = 'RESET';
70         }
71 }
72
73 //-----------------------------------------------------------------------------------
74
75 function can_delete($selected_id)
76 {
77         if ($selected_id == -1)
78                 return false;
79         $sql= "SELECT COUNT(*) FROM ".TB_PREF."chart_master
80                 WHERE account_type=$selected_id";
81         $result = db_query($sql, "could not query chart master");
82         $myrow = db_fetch_row($result);
83         if ($myrow[0] > 0) 
84         {
85                 display_error(_("Cannot delete this account group because GL accounts have been created referring to it."));
86                 return false;
87         }
88
89         $sql= "SELECT COUNT(*) FROM ".TB_PREF."chart_types
90                 WHERE parent=$selected_id";
91         $result = db_query($sql, "could not query chart types");
92         $myrow = db_fetch_row($result);
93         if ($myrow[0] > 0) 
94         {
95                 display_error(_("Cannot delete this account group because GL account groups have been created referring to it."));
96                 return false;
97         }
98
99         return true;
100 }
101
102
103 //-----------------------------------------------------------------------------------
104
105 if ($Mode == 'Delete')
106 {
107
108         if (can_delete($selected_id))
109         {
110                 delete_account_type($selected_id);
111                 display_notification(_('Selected currency has been deleted'));
112         }
113         $Mode = 'RESET';
114 }
115 if ($Mode == 'RESET')
116 {
117         $selected_id = -1;
118         $_POST['id']  = $_POST['name']  = '';
119         unset($_POST['parent']);
120         unset($_POST['class_id']);
121 }
122 //-----------------------------------------------------------------------------------
123
124 $result = get_account_types(check_value('show_inactive'));
125
126 start_form();
127 start_table($table_style);
128 $th = array(_("ID"), _("Name"), _("Subgroup Of"), _("Class Type"), "", "");
129 inactive_control_column($th);
130 table_header($th);
131
132 $k = 0;
133 while ($myrow = db_fetch($result)) 
134 {
135
136         alt_table_row_color($k);
137
138         $bs_text = get_account_class_name($myrow["class_id"]);
139
140         if ($myrow["parent"] == ANY_NUMERIC) 
141         {
142                 $parent_text = "";
143         } 
144         else 
145         {
146                 $parent_text = get_account_type_name($myrow["parent"]);
147         }
148
149         label_cell($myrow["id"]);
150         label_cell($myrow["name"]);
151         label_cell($parent_text);
152         label_cell($bs_text);
153         inactive_control_cell($myrow["id"], $myrow["inactive"], 'chart_types', 'id');
154         edit_button_cell("Edit".$myrow["id"], _("Edit"));
155         delete_button_cell("Delete".$myrow["id"], _("Delete"));
156         end_row();
157 }
158
159 inactive_control_row($th);
160 end_table(1);
161 //-----------------------------------------------------------------------------------
162
163 start_table($table_style2);
164
165 if ($selected_id != -1)
166 {
167         if ($Mode == 'Edit') 
168         {
169                 //editing an existing status code
170                 $myrow = get_account_type($selected_id);
171         
172                 $_POST['id']  = $myrow["id"];
173                 $_POST['name']  = $myrow["name"];
174                 $_POST['parent']  = $myrow["parent"];
175                 $_POST['class_id']  = $myrow["class_id"];
176                 hidden('selected_id', $selected_id);
177         }
178         hidden('id');
179         label_row(_("ID:"), $_POST['id']);
180 }
181 else
182         text_row_ex(_("ID:"), 'id', 4);
183 text_row_ex(_("Name:"), 'name', 50);
184
185 gl_account_types_list_row(_("Subgroup Of:"), 'parent', null, _("None"), true);
186
187 class_list_row(_("Class Type:"), 'class_id', null);
188
189 end_table(1);
190
191 submit_add_or_update_center($selected_id == -1, '', 'both');
192
193 end_form();
194
195 //------------------------------------------------------------------------------------
196
197 end_page();
198
199 ?>