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."));
35 if (isset($selected_id) && ($selected_id == $_POST['parent']))
37 display_error(_("You cannot set an account group to be a subgroup of itself."));
44 //-----------------------------------------------------------------------------------
46 if (isset($_POST['ADD_ITEM']) || isset($_POST['UPDATE_ITEM']))
52 if ($selected_id != "")
55 update_account_type($selected_id, $_POST['name'], $_POST['class_id'], $_POST['parent']);
61 add_account_type($_POST['name'], $_POST['class_id'], $_POST['parent']);
63 meta_forward($_SERVER['PHP_SELF']);
67 //-----------------------------------------------------------------------------------
69 function can_delete($selected_id)
71 if ($selected_id == "")
73 $sql= "SELECT COUNT(*) FROM ".TB_PREF."chart_master
74 WHERE account_type=$selected_id";
75 $result = db_query($sql, "could not query chart master");
76 $myrow = db_fetch_row($result);
79 display_error(_("Cannot delete this account group because GL accounts have been created referring to it."));
83 $sql= "SELECT COUNT(*) FROM ".TB_PREF."chart_types
84 WHERE parent=$selected_id";
85 $result = db_query($sql, "could not query chart types");
86 $myrow = db_fetch_row($result);
89 display_error(_("Cannot delete this account group because GL account groups have been created referring to it."));
97 //-----------------------------------------------------------------------------------
99 if (isset($_GET['delete']))
102 if (can_delete($selected_id))
104 delete_account_type($selected_id);
105 meta_forward($_SERVER['PHP_SELF']);
109 //-----------------------------------------------------------------------------------
111 $result = get_account_types();
113 start_table($table_style);
114 $th = array(_("Name"), _("Subgroup Of"), _("Class Type"), "", "");
118 while ($myrow = db_fetch($result))
121 alt_table_row_color($k);
123 $bs_text = get_account_class_name($myrow["class_id"]);
125 if ($myrow["parent"] == reserved_words::get_any_numeric())
131 $parent_text = get_account_type_name($myrow["parent"]);
134 label_cell($myrow["name"]);
135 label_cell($parent_text);
136 label_cell($bs_text);
137 edit_link_cell("selected_id=" . $myrow["id"]);
138 delete_link_cell("selected_id=" . $myrow["id"]. "&delete=1");
144 //-----------------------------------------------------------------------------------
146 hyperlink_no_params($_SERVER['PHP_SELF'], _("New Account Group"));
150 start_table($table_style2);
152 if ($selected_id != "")
154 //editing an existing status code
156 $myrow = get_account_type($selected_id);
158 $_POST['name'] = $myrow["name"];
159 $_POST['parent'] = $myrow["parent"];
160 $_POST['class_id'] = $myrow["class_id"];
162 hidden('selected_id', $selected_id);
165 text_row_ex(_("Name:"), 'name', 50);
167 gl_account_types_list_row(_("Subgroup Of:"), 'parent', null, true, _("None"), true);
169 class_list_row(_("Class Type:"), 'class_id', null);
173 submit_add_or_update_center($selected_id == "");
177 //------------------------------------------------------------------------------------