5 include($path_to_root . "/includes/session.inc");
7 page(_("GL Account Groups"));
9 include($path_to_root . "/gl/includes/gl_db.inc");
11 include($path_to_root . "/includes/ui.inc");
13 if (isset($_GET['selected_id']))
15 $selected_id = $_GET['selected_id'];
17 elseif(isset($_POST['selected_id']))
19 $selected_id = $_POST['selected_id'];
23 //-----------------------------------------------------------------------------------
25 function can_process()
29 if (strlen($_POST['name']) == 0)
31 display_error( _("The account group name cannot be empty."));
36 if (isset($selected_id) && ($selected_id == $_POST['parent']))
38 display_error(_("You cannot set an account group to be a subgroup of itself."));
45 //-----------------------------------------------------------------------------------
47 if (isset($_POST['ADD_ITEM']) || isset($_POST['UPDATE_ITEM']))
53 if ($selected_id != "")
56 update_account_type($selected_id, $_POST['name'], $_POST['class_id'], $_POST['parent']);
62 add_account_type($_POST['name'], $_POST['class_id'], $_POST['parent']);
64 meta_forward($_SERVER['PHP_SELF']);
68 //-----------------------------------------------------------------------------------
70 function can_delete($selected_id)
72 if ($selected_id == "")
74 $sql= "SELECT COUNT(*) FROM ".TB_PREF."chart_master
75 WHERE account_type=$selected_id";
76 $result = db_query($sql, "could not query chart master");
77 $myrow = db_fetch_row($result);
80 display_error(_("Cannot delete this account group because GL accounts have been created referring to it."));
84 $sql= "SELECT COUNT(*) FROM ".TB_PREF."chart_types
85 WHERE parent=$selected_id";
86 $result = db_query($sql, "could not query chart types");
87 $myrow = db_fetch_row($result);
90 display_error(_("Cannot delete this account group because GL account groups have been created referring to it."));
98 //-----------------------------------------------------------------------------------
100 if (isset($_GET['delete']))
103 if (can_delete($selected_id))
105 delete_account_type($selected_id);
106 meta_forward($_SERVER['PHP_SELF']);
110 //-----------------------------------------------------------------------------------
112 $result = get_account_types();
114 start_table($table_style);
115 $th = array(_("Name"), _("Subgroup Of"), _("Class Type"), "", "");
119 while ($myrow = db_fetch($result))
122 alt_table_row_color($k);
124 $bs_text = get_account_class_name($myrow["class_id"]);
126 if ($myrow["parent"] == reserved_words::get_any_numeric())
132 $parent_text = get_account_type_name($myrow["parent"]);
135 label_cell($myrow["name"]);
136 label_cell($parent_text);
137 label_cell($bs_text);
138 edit_link_cell("selected_id=" . $myrow["id"]);
139 delete_link_cell("selected_id=" . $myrow["id"]. "&delete=1");
145 //-----------------------------------------------------------------------------------
147 hyperlink_no_params($_SERVER['PHP_SELF'], _("New Account Group"));
151 start_table($table_style2);
153 if ($selected_id != "")
155 //editing an existing status code
157 $myrow = get_account_type($selected_id);
159 $_POST['name'] = $myrow["name"];
160 $_POST['parent'] = $myrow["parent"];
161 $_POST['class_id'] = $myrow["class_id"];
163 hidden('selected_id', $selected_id);
166 text_row_ex(_("Name:"), 'name', 50);
168 gl_account_types_list_row(_("Subgroup Of:"), 'parent', null, true, _("None"), true);
170 class_list_row(_("Class Type:"), 'class_id', null);
174 submit_add_or_update_center($selected_id == "");
178 //------------------------------------------------------------------------------------