Password reset mail could take several hours. After fix only a couple of seconds...
[fa-stable.git] / gl / manage / gl_account_classes.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_GLACCOUNTCLASS';
13 $path_to_root = "../..";
14 include($path_to_root . "/includes/session.inc");
15
16 page(_($help_context = "GL Account Classes"));
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         global $SysPrefs;
28
29         if (strlen(trim($_POST['id'])) == 0) 
30         {
31                 display_error( _("The account class ID cannot be empty."));
32                 set_focus('id');
33                 return false;
34         }
35         if (strlen(trim($_POST['name'])) == 0) 
36         {
37                 display_error( _("The account class name cannot be empty."));
38                 set_focus('name');
39                 return false;
40         }
41         if (isset($SysPrefs->use_oldstyle_convert) && $SysPrefs->use_oldstyle_convert == 1)
42                 $_POST['Balance'] = check_value('Balance');
43         return true;
44 }
45
46 //-----------------------------------------------------------------------------------
47
48 if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM') 
49 {
50
51         if (can_process()) 
52         {
53
54         if ($selected_id != "") 
55         {
56                 if(update_account_class($selected_id, $_POST['name'], $_POST['ctype']))
57                                 display_notification(_('Selected account class settings has been updated'));
58         } 
59         else 
60         {
61                 if(add_account_class($_POST['id'], $_POST['name'], $_POST['ctype'])) {
62                                 display_notification(_('New account class has been added'));
63                                 $Mode = 'RESET';
64                         }
65         }
66         }
67 }
68
69 //-----------------------------------------------------------------------------------
70
71 function can_delete($selected_id)
72 {
73         if ($selected_id == "")
74                 return false;
75         if (key_in_foreign_table($selected_id, 'chart_types', 'class_id'))      
76         {
77                 display_error(_("Cannot delete this account class because GL account types have been created referring to it."));
78                 return false;
79         }
80
81         return true;
82 }
83
84
85 //-----------------------------------------------------------------------------------
86
87 if ($Mode == 'Delete')
88 {
89
90         if (can_delete($selected_id))
91         {
92                 delete_account_class($selected_id);
93                 display_notification(_('Selected account class has been deleted'));
94         }
95         $Mode = 'RESET';
96 }
97
98 //-----------------------------------------------------------------------------------
99 if ($Mode == 'RESET')
100 {
101         $selected_id = "";
102         $_POST['id']  = $_POST['name']  = $_POST['ctype'] =  '';
103 }
104 //-----------------------------------------------------------------------------------
105
106 $result = get_account_classes(check_value('show_inactive'));
107
108 start_form();
109 start_table(TABLESTYLE);
110 $th = array(_("Class ID"), _("Class Name"), _("Class Type"), "", "");
111 if (isset($SysPrefs->use_oldstyle_convert) && $SysPrefs->use_oldstyle_convert == 1)
112         $th[2] = _("Balance Sheet");
113 inactive_control_column($th);
114 table_header($th);
115
116 $k = 0;
117 while ($myrow = db_fetch($result)) 
118 {
119         alt_table_row_color($k);
120
121         label_cell($myrow["cid"]);
122         label_cell('<a href="./gl_account_types.php?cid='.$myrow["cid"].'">'.$myrow['class_name'].'</a>');
123         if (isset($SysPrefs->use_oldstyle_convert) && $SysPrefs->use_oldstyle_convert == 1)
124         {
125                 $myrow['ctype'] = ($myrow["ctype"] >= CL_ASSETS && $myrow["ctype"] < CL_INCOME ? 1 : 0);
126                 label_cell(($myrow['ctype'] == 1 ? _("Yes") : _("No")));
127         }       
128         else    
129                 label_cell($class_types[$myrow["ctype"]]);
130         inactive_control_cell($myrow["cid"], $myrow["inactive"], 'chart_class', 'cid');
131         edit_button_cell("Edit".$myrow["cid"], _("Edit"));
132         delete_button_cell("Delete".$myrow["cid"], _("Delete"));
133         end_row();
134 }
135 inactive_control_row($th);
136 end_table(1);
137 //-----------------------------------------------------------------------------------
138
139 start_table(TABLESTYLE2);
140
141 if ($selected_id != "") 
142 {
143         if ($Mode == 'Edit') {
144                 //editing an existing status code
145                 $myrow = get_account_class($selected_id);
146         
147                 $_POST['id']  = $myrow["cid"];
148                 $_POST['name']  = $myrow["class_name"];
149                 if (isset($SysPrefs->use_oldstyle_convert) && $SysPrefs->use_oldstyle_convert == 1)
150                         $_POST['ctype'] = ($myrow["ctype"] >= CL_ASSETS && $myrow["ctype"] < CL_INCOME ? 1 : 0);
151                 else
152                         $_POST['ctype']  = $myrow["ctype"];
153                 hidden('selected_id', $selected_id);
154         }
155         hidden('id');
156         label_row(_("Class ID:"), $_POST['id']);
157
158
159 else 
160 {
161
162         text_row_ex(_("Class ID:"), 'id', 3);
163 }
164
165 text_row_ex(_("Class Name:"), 'name', 50, 60);
166
167 if (isset($SysPrefs->use_oldstyle_convert) && $SysPrefs->use_oldstyle_convert == 1)
168         check_row(_("Balance Sheet"), 'ctype', null);
169 else
170         class_types_list_row(_("Class Type:"), 'ctype', null);
171
172 end_table(1);
173
174 submit_add_or_update_center($selected_id == "", '', 'both');
175
176 end_form();
177
178 //------------------------------------------------------------------------------------
179
180 end_page();
181